1
0
Fork 0

changed 'Conformation.dissimilarity' method to 'Conformation.identity' method

master
Nicolas Zimmermann 2019-09-16 23:22:35 +02:00
parent 3662e3a099
commit 4144a2a093
1 changed files with 19 additions and 8 deletions

View File

@ -4,6 +4,7 @@ import pandas as pd
import numpy as np import numpy as np
import pbxplore as pbx import pbxplore as pbx
import sys import sys
from scipy.spatial.distance import squareform, pdist, jaccard
class Conformations: class Conformations:
""" """
@ -18,21 +19,31 @@ class Conformations:
df : pd.DataFrame object df : pd.DataFrame object
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.
dfnum : to compute dissimilarity with the function pdist, elements of
the DataFrame must be float
""" """
self.df = pd.DataFrame() self.df = pd.DataFrame()
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)
self.df = self.df.append(pd.Series(list(pb_seq)), ignore_index=True) self.df = self.df.append(pd.Series(list(pb_seq)),
ignore_index=True)
def dissimilarity(self):
def identity(self):
""" """
computes the dissimilarity matrix of the intance's df Returns a matrix of the distance between all conformations based on
wether the PB at each position is identical or not.
Returns the matrix as a numpy.ndarray object.
""" """
matrix = pd.DataFrame(index=np.arange(self.df.shape[0]), dict_str_to_float = {'Z':0,'a':1,'b':2,'c':3,'d':4,'e':5,'f':6,'g':7,
columns=np.arange(self.df.shape[0])) 'h':8,'i':9,'j':10,'k':11,'l':12,'m':13,'n':14,
matrix = matrix.fillna(0) 'o':15,'p':16} # dict to transform PB to int,
return matrix # necessary for the pdsit function
dfnum = self.df.replace(dict_str_to_float)
return squareform(pdist(dfnum, metric ='jaccard'))
if __name__ == "__main__": if __name__ == "__main__":
if len(sys.argv) != 2: if len(sys.argv) != 2: