Mercurial > repos > chemteam > mdanalysis_rdf
annotate pca_cosine.py @ 6:fb2b84481239 draft default tip
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 7a25958195ccc8f448dd64ddcc36e8f5e5979d8b"
| author | chemteam | 
|---|---|
| date | Wed, 20 May 2020 16:56:07 +0000 | 
| parents | aabf6858f293 | 
| children | 
| rev | line source | 
|---|---|
| 
3
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
1 #!/usr/bin/env python | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
2 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
3 import argparse | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
4 import csv | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
5 import sys | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
6 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
7 import MDAnalysis as mda | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
8 import MDAnalysis.analysis.pca as pca | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
9 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
10 import numpy as np | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
11 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
12 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
13 def parse_command_line(argv): | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
14 parser = argparse.ArgumentParser() | 
| 
4
 
aabf6858f293
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
 
chemteam 
parents: 
3 
diff
changeset
 | 
15 parser.add_argument('--itraj', help='input traj') | 
| 
 
aabf6858f293
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
 
chemteam 
parents: 
3 
diff
changeset
 | 
16 parser.add_argument('--istr', help='input str') | 
| 
 
aabf6858f293
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
 
chemteam 
parents: 
3 
diff
changeset
 | 
17 parser.add_argument('--itrajext', help='input traj ext') | 
| 
 
aabf6858f293
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
 
chemteam 
parents: 
3 
diff
changeset
 | 
18 parser.add_argument('--istrext', help='input str ext') | 
| 
3
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
19 parser.add_argument('--icomponents', help='number of principle components') | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
20 parser.add_argument('--iindex', help='index of the PC') | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
21 parser.add_argument('--output', help='output') | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
22 parser.add_argument('--cosout', help='cosine output') | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
23 return parser.parse_args() | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
24 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
25 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
26 args = parse_command_line(sys.argv) | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
27 | 
| 
4
 
aabf6858f293
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
 
chemteam 
parents: 
3 
diff
changeset
 | 
28 u = mda.Universe(args.istr, args.itraj, | 
| 
 
aabf6858f293
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
 
chemteam 
parents: 
3 
diff
changeset
 | 
29 topology_format=args.istrext, format=args.itrajext) | 
| 
3
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
30 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
31 components = int(args.icomponents) | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
32 pca_index = int(args.iindex) | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
33 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
34 PSF_pca = pca.PCA(u, select='backbone') | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
35 PSF_pca.run() | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
36 n_pcs = np.where(PSF_pca.cumulated_variance > 0.95)[0][0] | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
37 atomgroup = u.select_atoms('backbone') | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
38 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
39 pca_space = PSF_pca.transform(atomgroup, n_components=components) | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
40 cosine = mda.analysis.pca.cosine_content(pca_space, pca_index) | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
41 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
42 PCA = list(pca_space) | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
43 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
44 with open(args.output, 'w') as f: | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
45 writer = csv.writer(f, delimiter='\t') | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
46 writer.writerows(PCA) | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
47 | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
48 with open(args.cosout, 'w') as f1: | 
| 
 
fdc0c1615372
planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 3ff06e3182c3a1546ea0a3b29e0d4383e12169e1
 
chemteam 
parents:  
diff
changeset
 | 
49 f1.write(str(cosine)) | 
