annotate PDAUG_Peptide_Structure_Builder/PDAUG_Peptide_Structure_Builder.py @ 2:79b1b090990b draft

"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 8b18552f6d2b2261efebe1075ff4c18a295b94dd"
author jay
date Tue, 29 Dec 2020 18:07:32 +0000
parents e59674e3a391
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
1 import tempfile
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
2 import pandas as pd
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
3 import shutil
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
4 import sys
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
5 import glob
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
6 import fragbuilder
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
7 import openbabel
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
8 from fragbuilder import peptide
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
9
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
10 import os
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
11
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
12
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
13 def read_pep_file(pep_infile):
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
14
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
15 file = open(pep_infile)
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
16 lines = file.readlines()
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
17
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
18 Index = []
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
19 list_pep_name = []
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
20
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
21 for line in lines:
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
22 if '>' in line:
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
23 Index.append(line.strip('\n'))
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
24 else:
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
25 line = line.strip('\n')
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
26 line = line.strip('\r')
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
27 list_pep_name.append(line.strip('\n'))
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
28
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
29 return list_pep_name
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
30
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
31 def structure_gen(pep_seq, out_dir):
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
32
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
33 if not os.path.exists(os.path.join(out_dir, 'DataFile')):
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
34 os.makedirs(os.path.join(out_dir, 'DataFile'))
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
35
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
36 b = len(pep_seq)
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
37
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
38 for seq in pep_seq:
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
39
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
40 pep = peptide.Peptide(seq, nterm = "charged", cterm = "neutral")
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
41 pep.regularize()
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
42 pep.write_pdb(os.path.join(out_dir, 'DataFile', seq+".pdb"))
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
43
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
44 obConversion = openbabel.OBConversion()
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
45 obConversion.SetInAndOutFormats("pdb", "sdf")
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
46 mol = openbabel.OBMol()
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
47 obConversion.ReadFile(mol, os.path.join(out_dir, 'DataFile', seq+".pdb"))
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
48
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
49 mol.AddHydrogens()
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
50
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
51
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
52 def main_process(str_pep_file, out_dir):
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
53
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
54 my_pep = read_pep_file(str_pep_file)
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
55 structure_gen(my_pep, out_dir)
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
56
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
57
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
58 if __name__=="__main__":
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
59
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
60
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
61 import argparse
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
62 parser = argparse.ArgumentParser()
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
63
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
64 parser.add_argument("-p", "--pep", required=True, default=None, help="pep file")
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
65 parser.add_argument("-o", "--OutDir", required=None, default=os.getcwd(), help="Path to out file")
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
66
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
67 args = parser.parse_args()
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
68 main_process(args.pep, args.OutDir)
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
69
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
70
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
71
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
72
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
73