-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddNoesyILV15NlabelingScheme.py
More file actions
executable file
·124 lines (109 loc) · 5.08 KB
/
AddNoesyILV15NlabelingScheme.py
File metadata and controls
executable file
·124 lines (109 loc) · 5.08 KB
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
#!/nmr/programs/python/bin/python2.5
"""
AddUnlabeledSchemeToResidueType.py reads in a cara repository file and modifies
the residue-type definitions to include a labeling scheme with N14 and C12.
A labeling scheme called 'unlabeled' is added for this purpose.
"""
import sys
sys.path.append('/nmr/programs/python/')
import xml.etree.ElementTree as ET
from xml.etree.ElementTree import Element, SubElement
import string
def main():
if len(sys.argv) not in [3,4]:
print '==============================================================================='
print 'AddILVlabelingScheme.py reads in a cara repository file and modifies the'
print 'residue-type definitions to include a labeling scheme with 12C and 2H'
print 'except at methyl groups of I, L, and V.'
print ''
print 'A labeling scheme called \'ILVnoesy\' is added for this purpose.'
print ''
print 'Usage: AddILVlabelingScheme.py infile.cara outfile.cara'
print 'Number of arguments given: %d'%(len(sys.argv)-1)
print 'An optional third argument names which project to modify, if'
print 'there is more than one project in a repository. '
print '=============================================================================='
return
infile = sys.argv[1]
outfile = sys.argv[2]
if infile == outfile:
print '\nPlease do not overwrite your original file. Try again.\n'
return
tree = ET.parse(infile)
root = tree.getroot()
projects = root.findall('project')
# Select a project according to command-line input, defaulting to the first project
if len(sys.argv) == 4:
projectName = sys.argv[3]
project = getProject(projectName,projects)
if not project:
print 'No project found with name \"%s\".'%projectName
return
else:
project = projects[0]
if not project:
print 'No project found.'
return
# Find existing schemes & make a new one by incrementing the highest existing ID number
library = root.find('library')
schemes = library.findall('scheme')
numSchemes = len(schemes)
if numSchemes > 0:
schemeIDs = [int(scheme.get('id')) for scheme in schemes]
schemeIDs.sort()
newIDnum = schemeIDs[numSchemes-1]+1
newID = '%d'%newIDnum
else:
newID = '1'
newscheme = SubElement(library,'scheme')
newscheme.attrib['id'] = newID
newscheme.attrib['name'] = 'ILVnoesy15N-%s'%newID
# Modify residue-type
residueTypes = library.findall('residue-type')
for residueType in residueTypes:
if residueType.get('letter') not in ('I','L','V'):
atoms = residueType.findall('atom')
for atom in atoms:
if atom.get('name')[0]=='C':
newscheme = SubElement(atom,'scheme')
newscheme.attrib['id'] = newID
newscheme.attrib['type'] = 'C12'
elif atom.get('name')[0]=='H' and atom.get('name')!='H':
newscheme = SubElement(atom,'scheme')
newscheme.attrib['id'] = newID
newscheme.attrib['type'] = 'H2'
elif residueType.get('letter')=='L':
atoms = residueType.findall('atom')
for atom in atoms:
if atom.get('name')[0]=='C' and atom.get('name')[0:2]!='CD':
newscheme = SubElement(atom,'scheme')
newscheme.attrib['id'] = newID
newscheme.attrib['type'] = 'C12'
elif atom.get('name')[0]=='H' and atom.get('name')[0:2]!='HD' and atom.get('name')!='H':
newscheme = SubElement(atom,'scheme')
newscheme.attrib['id'] = newID
newscheme.attrib['type'] = 'H2'
elif residueType.get('letter')=='V':
atoms = residueType.findall('atom')
for atom in atoms:
if atom.get('name')[0]=='C' and atom.get('name')[0:2]!='CG':
newscheme = SubElement(atom,'scheme')
newscheme.attrib['id'] = newID
newscheme.attrib['type'] = 'C12'
elif atom.get('name')[0]=='H' and atom.get('name')[0:2]!='HG' and atom.get('name')!='H':
newscheme = SubElement(atom,'scheme')
newscheme.attrib['id'] = newID
newscheme.attrib['type'] = 'H2'
elif residueType.get('letter')=='I':
atoms = residueType.findall('atom')
for atom in atoms:
if atom.get('name')[0]=='C' and atom.get('name')[0:2]!='CD':
newscheme = SubElement(atom,'scheme')
newscheme.attrib['id'] = newID
newscheme.attrib['type'] = 'C12'
elif atom.get('name')[0]=='H' and atom.get('name')[0:2]!='HD' and atom.get('name')!='H':
newscheme = SubElement(atom,'scheme')
newscheme.attrib['id'] = newID
newscheme.attrib['type'] = 'H2'
tree.write(outfile)
main()