-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd10000toSpinIDsWithPairs.py
More file actions
executable file
·92 lines (73 loc) · 3 KB
/
add10000toSpinIDsWithPairs.py
File metadata and controls
executable file
·92 lines (73 loc) · 3 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
#!/nmr/programs/python/bin/python2.5
"""
add10000toSpinIDsWithPairs.py takes a cara repository file and renumbers the
spectrum IDs by adding 10000 to each ID.
Spin IDs are also renumbered in pairs, aka NOEs.
Note that add10000toSpinIDswithPairs.py only alters the first project in a repository, and does not alter tags in peaklists.
"""
import sys
sys.path.append('/nmr/programs/python/')
import xml.etree.ElementTree as ET
# Main
def main():
if len(sys.argv) not in [3,4]:
print '=============================================================================='
print 'add1000toSpinIDsWithPairs.py renumbers the spin IDs in a cara'
print 'repository by adding 10000 to each ID.'
print 'Spin IDs are also renumbered in spin pairs, aka NOEs.'
print ''
print 'Note that add10000toSpinIDsWithPairs.py only alters the first project in a'
print 'repository by default.'
print ''
print 'Usage: add10000toSpinIDsWithPairs.py infile.cara outfile.cara'
print 'Number of arguments given: %d'%(len(sys.argv)-1)
print 'An optional third argument (integer) indicates 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()
# Select a project, the first one by default.
if len(sys.argv) == 4:
numProject = int(sys.argv[3])-1
if numProject < 0:
print '\nYou requested a negative project number. Try again.\n'
return
else:
numProject = 0
projects = root.findall('project')
try:
project = projects[numProject]
print 'Modifying project #%d, %s.'%(numProject + 1,project.get('name'))
except:
print '\nYou requested project number %d, but there are only %d projects in this repository. Try again.\n'%(numProject + 1, len(projects))
return
# Find all spins and fix IDs
spinbase = project.find('spinbase')
spins = spinbase.findall('spin')
print 'There are %d total spins.'%len(spins)
for spin in spins:
origID = int(spin.get('id'))
newID = origID + 10000
spin.set('id','%d'%newID)
# Find all pairs and fix spin IDs
pairs = spinbase.findall('pair')
print 'There are %d total pairs.'%len(pairs)
for pair in pairs:
lhs = pair.get('lhs')
newLHS = int(lhs) + 10000
pair.set('lhs','%d'%newLHS)
rhs = pair.get('rhs')
newRHS = int(rhs) + 10000
pair.set('rhs','%d'%newRHS)
tree.write(outfile)
main()
# Testing:
#print 'HEAT-2: %d'%locateStartOfUnassignedResidues(1219,1437,219)
#print '4afl: %d'%locateStartOfUnassignedResidues(1,500,719)
#print 'weird: %d'%locateStartOfUnassignedResidues(500,1050,719)