-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenumberProtFile.py
More file actions
executable file
·63 lines (53 loc) · 2.13 KB
/
renumberProtFile.py
File metadata and controls
executable file
·63 lines (53 loc) · 2.13 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
#!/usr/bin/python
"""
renumberProtFile.py reads a prot file from XEASY and changes the spin numbers
in the first column so that it can be imported into CARA without overwriting
existing spins. The user must supply a starting spin ID number, and all other
spins will be numbered from there, in no particular order.
"""
import sys
sys.path.append('/nmr/programs/python/')
import string
def main():
if len(sys.argv) != 4:
print '=============================================================================='
print 'renumberProtFile.py reads a prot file from XEASY and changes the spin numbers'
print 'in the first column so that it can be imported into CARA without overwriting'
print 'existing spins. The user must supply a starting spin ID number, and all other'
print 'spins will be numbered from there, in no particular order.'
print ''
print 'Usage: renumberProtFile.py infile.prot outfile.prot startIndex'
print 'Number of arguments given: %d'%(len(sys.argv)-1)
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
startIndex = int(sys.argv[3])
if startIndex <= 9999:
numDigits = 6
else:
numDigits = len(sys.argv[3]) + 2
openfile = open(infile)
lines = openfile.readlines()
openfile.close()
# How many characters do we need to reserve for the spin IDs?
numSpins = len(lines)
maxSpin = startIndex + numSpins
numChars = len('%d'%maxSpin)
print maxSpin, numChars
outputfile = open(outfile,'w')
spinIDnum = startIndex - 1
for line in lines:
spinIDnum = spinIDnum + 1
spinIDstr = str(spinIDnum).rjust(numDigits)
fields = line.split()
atomType = fields[3].ljust(5)
resNum = fields[4]
chemShift = float(fields[1])
newline = '%s %7.3f %s %s %s\n'%(spinIDstr,chemShift,fields[2],atomType,resNum)
outputfile.write(newline)
outputfile.close()
main()