modified code (__init__) to save distance matrixes in Conformations instances
parent
d77136b7f4
commit
dfe4789af2
|
|
@ -21,11 +21,23 @@ class Conformations:
|
||||||
|
|
||||||
def __init__(self, filename):
|
def __init__(self, filename):
|
||||||
"""
|
"""
|
||||||
df : pd.DataFrame object
|
filename : a .pdb file or several pdb file containing the conformations
|
||||||
|
|
||||||
|
Attribute :
|
||||||
|
- df : pd.DataFrame object
|
||||||
|
- filename : a list of str, paths to the structure files
|
||||||
|
- simple_dist : matrix distance computed with the identity method
|
||||||
|
Initiality empty, must be computed
|
||||||
|
- dissimilarity_dist : matrix distance computed with the
|
||||||
|
dissimilarity method, initialy empty because
|
||||||
|
the computation time is long
|
||||||
Each row of the dataframe is a conformation and each column a position
|
Each row of the dataframe is a conformation and each column a position
|
||||||
of the sequence.
|
of the sequence.
|
||||||
"""
|
"""
|
||||||
self.df = pd.DataFrame()
|
self.df = pd.DataFrame()
|
||||||
|
self.filename = filename
|
||||||
|
self.identity_dist = None
|
||||||
|
self.dissimilarity_dist = None
|
||||||
for chain_name, chain in pbx.chains_from_files([filename]):
|
for chain_name, chain in pbx.chains_from_files([filename]):
|
||||||
dihedrals = chain.get_phi_psi_angles()
|
dihedrals = chain.get_phi_psi_angles()
|
||||||
pb_seq = pbx.assign(dihedrals)
|
pb_seq = pbx.assign(dihedrals)
|
||||||
|
|
@ -34,7 +46,7 @@ class Conformations:
|
||||||
|
|
||||||
def identity(self):
|
def identity(self):
|
||||||
"""
|
"""
|
||||||
Returns a matrix of the distance between all conformations based on
|
Computes a distance matrix between all conformations based on
|
||||||
wether the PB at each position is identical or not.
|
wether the PB at each position is identical or not.
|
||||||
Returns the matrix as a numpy.ndarray object.
|
Returns the matrix as a numpy.ndarray object.
|
||||||
"""
|
"""
|
||||||
|
|
@ -43,8 +55,10 @@ class Conformations:
|
||||||
'o':15,'p':16} # dict to transform PB to int,
|
'o':15,'p':16} # dict to transform PB to int,
|
||||||
# necessary for the pdsit function
|
# necessary for the pdsit function
|
||||||
dfnum = self.df.replace(dict_str_to_float)
|
dfnum = self.df.replace(dict_str_to_float)
|
||||||
|
dist = squareform(pdist(dfnum, metric ='jaccard'))
|
||||||
|
self.identity_dist = dist
|
||||||
|
|
||||||
return squareform(pdist(dfnum, metric ='jaccard'))
|
return dist
|
||||||
|
|
||||||
def dissimilarity(self, matrix=None):
|
def dissimilarity(self, matrix=None):
|
||||||
"""
|
"""
|
||||||
|
|
@ -69,9 +83,9 @@ class Conformations:
|
||||||
dissimilarity[i][j] += matrix[confs.df.loc[i,k]][confs.df.loc[j,k]]
|
dissimilarity[i][j] += matrix[confs.df.loc[i,k]][confs.df.loc[j,k]]
|
||||||
dissimilarity = dissimilarity + dissimilarity.T # fills the whole matrix
|
dissimilarity = dissimilarity + dissimilarity.T # fills the whole matrix
|
||||||
|
|
||||||
return dissimilarity
|
return self.dist_from_dissimilarity(dissimilarity)
|
||||||
|
|
||||||
def dist_from_dissimilarity(diss_matrix):
|
def dist_from_dissimilarity(self, diss_matrix):
|
||||||
"""
|
"""
|
||||||
Using the substitution matrix from the PBxplore package, the obtained
|
Using the substitution matrix from the PBxplore package, the obtained
|
||||||
dissimilarity matrix has both positive and negative values. Low value
|
dissimilarity matrix has both positive and negative values. Low value
|
||||||
|
|
@ -85,14 +99,20 @@ class Conformations:
|
||||||
diss_matrix = -diss_matrix
|
diss_matrix = -diss_matrix
|
||||||
diss_matrix = (diss_matrix - np.min(diss_matrix))/np.ptp(diss_matrix)
|
diss_matrix = (diss_matrix - np.min(diss_matrix))/np.ptp(diss_matrix)
|
||||||
dist = diss_matrix * abs((np.identity(confs.df.shape[0])-1))
|
dist = diss_matrix * abs((np.identity(confs.df.shape[0])-1))
|
||||||
|
|
||||||
|
self.dissimilarity_dist = dist
|
||||||
|
|
||||||
return dist
|
return dist
|
||||||
|
|
||||||
|
#def small_kmedoid(self, ncluster):
|
||||||
|
# pass
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(sys.argv) != 2:
|
if len(sys.argv) < 2:
|
||||||
sys.exit("Error : usage '$ python3 projet8 md.pdb'")
|
sys.exit("Error : usage '$ python3 projet8 md.pdb'")
|
||||||
|
|
||||||
confs = Conformations(sys.argv[1])
|
confs = Conformations(sys.argv[1])
|
||||||
|
|
||||||
|
|
||||||
print(confs.df)
|
print(confs.df)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue