-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmethylSimulateSpectrum.py
executable file
·65 lines (60 loc) · 1.89 KB
/
methylSimulateSpectrum.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
#!/usr/bin/env python
"""
Read in a sparky peaklist file, and output a scatterplot showing
peak positions, with the area of each marker proportional to the
height of the peak.
"""
import sys
import pylab
from math import sqrt
def main():
if len(sys.argv) != 3:
print "Usage:"
print "methylSimulateSpectrum.py spectrum.list chart.pdf"
return
infile = sys.argv[1]
outfile = sys.argv[2]
openfile = open(infile,'r')
listDict = {}
heights = True
for line in openfile.readlines():
if '-' in line:
columns = line.split()
res = columns[0].split('-')[0]
Cppm = float(columns[1])
Hppm = float(columns[2])
try:
height = float(columns[3])
except IndexError, e:
heights = False
if heights:
listDict[res]=(Cppm,Hppm,height)
else:
listDict[res]=(Cppm,Hppm)
openfile.close()
residues = listDict.keys()
Clist = [listDict[res][0] for res in residues]
Hlist = [listDict[res][1] for res in residues]
if heights:
sizes = [listDict[res][2] for res in residues]
maxsize = max(sizes)
scaledsizes = [100*x/maxsize for x in sizes]
pylab.figure()
pylab.scatter(Hlist,Clist,marker='o',s=scaledsizes)
else:
pylab.figure()
pylab.scatter(Hlist,Clist,marker='o')
pylab.xlabel("$\omega$ H (ppm)")
pylab.ylabel("$\omega$ C (ppm)")
axes = pylab.gca()
axes.invert_xaxis()
axes.invert_yaxis()
for label, x, y in zip(residues, Hlist, Clist):
pylab.annotate(
label,
xy = (x, y), xytext = (-2, 3),
textcoords = 'offset points', ha = 'right', va = 'bottom',
size=5,
arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3,rad=0'))
pylab.savefig(outfile)
main()