forked from vitzwitz/matching-functions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParser.py
138 lines (112 loc) · 5.54 KB
/
Parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
"""
Parser : Inputs and parses pdb files individually
"""
from Classes import *
import urllib, urllib2
def Constructor(classifier, subfield, line):
Class = "%s(line)" % classifier
print classifier
obj = eval(Class)
print "Works!"
print obj
if classifier not in subfield:
subfield[classifier] = [obj]
else:
subfield[classifier].append(obj)
return subfield
def readFile(file):
description = {}
primaryStruct = {}
heterogen = {}
secondaryStruct = {}
sites = {}
coordTransf = {}
AtomsNModels = {}
connectivity = {}
bookskeeping = {}
i = 1
for line in open(file).readlines():
line = str(line.rstrip())
if line == "": pass
classifier = line[0:6]
#if i == 19: break
if line[0:6] == "SPRSDE":
pass
else:
classifier = classifier[0] + classifier[1:].lower()
classifier = classifier.strip()
print i, classifier # line piece
if classifier == 'Header' or classifier == "Title" or classifier == 'Source' \
or classifier == 'Author' or classifier == 'Remark' or classifier == "Obslte" \
or classifier == "Caveat" or classifier == "Split" or classifier == "SPRSDE" \
or classifier == "Expdta" or classifier == "Revdat" or classifier == 'Keywds' \
or classifier == 'Jrnl':
description = Constructor(classifier, description, line)
elif classifier == 'Compnd':
description = Constructor("Compound", description, line)
elif classifier == 'Nummdl':
description = Constructor("NumModels", description, line)
elif classifier == 'Modltyp':
description = Constructor("ModelType", description, line)
elif classifier == 'Dbref':
primaryStruct = Constructor((classifier[0] + classifier[1:3].upper() + classifier[4:6]),
primaryStruct, line)
elif classifier == 'Seqres' or classifier == "Modres" or classifier == "Seqadv":
primaryStruct = Constructor((classifier[0:3] + classifier[3].upper() + classifier[4:6]),
primaryStruct, line)
elif classifier == 'Het' or classifier == 'Formul':
heterogen = Constructor(classifier, heterogen, line)
elif classifier == 'Hetnam':
heterogen = Constructor("HetCompound", heterogen, line)
elif classifier == 'Hetsyn':
heterogen = Constructor("HetSynon", heterogen, line)
elif classifier == 'Helix' or classifier == 'Sheet' or \
classifier == "Turn":
secondaryStruct = Constructor(classifier, secondaryStruct, line)
elif classifier == 'Ssbond':
connectivity = Constructor("S2Bond", connectivity, line)
elif classifier == 'Link':
connectivity = Constructor(classifier, connectivity, line)
elif classifier == "Cispep":
connectivity = Constructor("CisPep", connectivity, line)
elif classifier == 'Site':
sites = Constructor(classifier, sites, line)
elif classifier == 'Cryst1' or classifier == 'Scale1' or \
classifier == Scale2 or classifier == Scale3:
coordTransf = Constructor(classifier, coordTransf, line)
elif classifier == 'ORIGX1' or classifier == 'ORIGX2' or \
classifier == 'ORIGX3':
coordTransf = Constructor(classifier[0:4] + classifier[4].upper()+classifier[5], coordTransf, line)
elif classifier == 'Mtrix1' or classifier == 'Mtrix2' or classifier == 'Mtrix3':
coordTransf = Constructor(classifier[0]+"a"+classifier[1:], coordTransf, line)
elif classifier == "Tvect":
coordTransf = Constructor("TVector", coordTransf, line)
elif classifier == 'Atom' or classifier == "Anisou" or classifier == 'Ter' \
or classifier == Model:
AtomsNModels= Constructor(classifier, AtomsNModels, line)
elif classifier == 'Hetatm':
AtomsNModels= Constructor("HetAtom", AtomsNModels, line)
elif classifier == "Hydbnd":
AtomsNModels= Constructor("HydroBond", AtomsNModels, line)
elif classifier == "Sltbdg":
AtomsNModels= Constructor("SaltBridge", AtomsNModels, line)
elif classifier == "Endmdl":
AtomsNModels= Constructor("EndModel", AtomsNModels, line)
elif classifier == 'Conect':
connectivity = Constructor("Connects", connectivity, line)
elif classifier == 'Master' or classifier == "End":
bookskeeping = Constructor(classifier, bookskeeping, line)
else:
print "other =", classifier
i += 1
pdb = (description, primaryStruct, heterogen, secondaryStruct, sites, coordTransf, AtomsNModels, connectivity, bookskeeping)
return pdb
def main():
# For Testing:
pdbID = raw_input("Enter a pdb code: ")
directory = "C:/Users/blm7643/Downloads/proteinDATA/"
path = urllib.urlretrieve('http://files.rcsb.org/download/%s.pdb' % pdbID, 'C:/Users/blm7643/Downloads/proteinDATA/%s.pdb' % pdbID)
file = 'C:/Users/blm7643/Downloads/proteinDATA/%s.pdb' % pdbID
pdb = readFile(file)
if __name__ == '__main__':
main()