-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranslators.py
291 lines (254 loc) · 8.88 KB
/
translators.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
from sys import stdout
from miscfunctions import approxmatch, approxmatchb, removesolvs
full='no'
from numpy import arange, ravel, array, where
def hformatter(sigs,ints,solvs,connect,broadlist=None,groupedsigs=[]):
solvlesssigs, solvlessints, DMSOpeak, removedsigs, solvlessconnect = removesolvs(sigs, ints, solvs, connect)
solvlesssigs, solvlessints, DMSOpeak, removedsigs, solvlessconnect = sigs, ints, 2.5, {}, connect
array(sigs).tolist()
list(sigs)
#states where the DMSO peak is
if full == 'yes':
print('\nThe DMSO peak is seen at ', '%.4f' %DMSOpeak,'and should be at 2.50\n', '%.4f' %float(2.5-DMSOpeak), 'has been subtracted from all peaks\n')
print('Uncalibrated\tCalibrated')
calsigs=[]
#makes a list of calibrated signals with referance to the DMSO peak
i=0
while i<len(solvlesssigs):
calsigs.append(solvlesssigs[i]-DMSOpeak+2.5)
if full =='yes':
print(solvlesssigs[i],'\t\t', '%.4f' %calsigs[i])
i=i+1
#creates an list of lists of the peaks within each integral, and the number of peaks per integral
#displays a table of the data used
if groupedsigs == []:
q=0
sigsperint=[]
summedints=[]
while q<len(ints):
r=0
sigsinint=[]
intsum=0
while r<len(calsigs):
if connect[r]==q:
sigsinint.append(float('%.4f' %calsigs[r]))
intsum=intsum+solvlessints[r]
r=r+1
groupedsigs.append(sigsinint)
sigsperint.append(len(sigsinint))
summedints.append(intsum)
q=q+1
else:
print(groupedsigs)
q=0
sigsperint=[]
summedints=[]
while q<len(groupedsigs):
sigsperint.append(len(groupedsigs[q]))
r = 0
intsum=0
while r < len(groupedsigs[q]):
intsum=intsum+ints[where(sigs == groupedsigs[q][r])]
r=r+1
summedints.append(intsum)
q=q+1
#creates lists of integral values, peaks per integral and signals without including integral ranges with no peaks in them
#displays a table of the data used, without the integral ranges with no peaks in them
t=0
newints=[]
newsigsperint=[]
newsigs=[]
if full == 'yes':
stdout.write('\nIntegral Value\tSignals per Integral\tSignals\n')
while t<len(sigsperint):
if sigsperint[t]>0:
newints.append(summedints[t])
newsigsperint.append(sigsperint[t])
newsigs.append(groupedsigs[t])
if full == 'yes':
stdout.write(str('%.5f' %summedints[t]).rjust(len(str(max(ints))))+ ' \t'+ str(sigsperint[t])+ '\t\t\t'+str(groupedsigs[t]).strip('[]')+'\n')
t=t+1
#divides the integral values by the smallest to create a list of calibrated integrals
u=0
smallest=min(newints)
calints=[]
while u<len(newints):
#calints.append(round(newints[u]/smallest))
calints.append(newints[u]/smallest)
u=u+1
#creates a list of peak centres
i=0
peaksums=[]
peakavs=[]
while i<len(newsigs):
peaksum=0
for num in newsigs[i]:
peaksum = peaksum + num
peaksums.append(peaksum)
peakavs.append(peaksums[i]/newsigsperint[i])
i=i+1
#creates a list of coupling constants
b=0
couplings=[]
couplingsums=[]
couplingavs=[]
if full == 'yes':
stdout.write('\nSignals\t\t\t\tCouplings\n')
while b<len(newsigs):
k=0
while k<len(newsigs[b]):
if full == 'yes':
stdout.write(str('%.4f' %newsigs[b][k]))
if k<len(newsigs[b])-1:
if full == 'yes':
stdout.write(', ')
k=k+1
if full == 'yes':
stdout.write((5-len(newsigs[b]))*'\t')
j=0
coupling=[]
while j<len(newsigs[b])-1:
coupling.append((newsigs[b][j]-newsigs[b][j+1])*400)
if full == 'yes':
stdout.write(str('%.2f' %((newsigs[b][j]-newsigs[b][j+1])*400)))
if j<len(newsigs[b])-2:
if full == 'yes':
stdout.write(', ')
j=j+1
if full == 'yes':
stdout.write('\n')
if j>0:
diffs=[]
x=0
while x<len(coupling):
y=0
while y<len(coupling):
diffs.append(coupling[x]-coupling[y])
y=y+1
x=x+1
couplingsum=0
if max(diffs)<0.1 and min(diffs)>-0.1:
for num in coupling:
couplingsum = couplingsum + num
couplingsums.append(couplingsum)
couplingavs.append(couplingsum/(newsigsperint[b]-1))
else:
couplingsums.append(0)
couplingavs.append(0)
else:
couplingavs.append(500.0)
b=b+1
#averages the couplings of pairs and creates a list of them, and a list of them with formatting and spaces
avcouplings=[]
avcouplingstext=[]
c=0
while c<len(couplingavs):
a=0
couplingdiffs=[]
while a<len(couplingavs):
couplingdiffs.append(abs(couplingavs[c]-couplingavs[a]))
a=a+1
couplingdiffs[c]=500
if min(couplingdiffs)<0.2:
matchindex=couplingdiffs.index(min(couplingdiffs))
avcouplings.append((couplingavs[c]+couplingavs[matchindex])/2)
else:
avcouplings.append(couplingavs[c])
if 0<couplingavs[c]<500:
avcouplingstext.append(', J = '+str(round(avcouplings[c],1))+' Hz')
else:
avcouplingstext.append('')
c=c+1
#creates a list of peak multiplicities
h=0
mults=[]
while h<len(newsigsperint):
if newsigsperint[h] == 1:
mults.append('s')
elif newsigsperint[h] == 2:
mults.append('d')
elif newsigsperint[h] == 3 and avcouplings[h] !=0:
mults.append('t')
elif newsigsperint[h] == 4 and avcouplings[h] !=0:
mults.append('q')
else:
mults.append('m')
h=h+1
## if broadlist == None:
## stdout.write('\nSignal No.\tSignal Value\n')
## x=0
## while x<len(peakavs):
## stdout.write(str(x+1)+'\t\t'+'%.2f' %peakavs[x]+'\n')
## x=x+1
#writes the data in the correct format
g=0
textout = ''
while g<len(peakavs):
if broadlist==None:
textout = textout + str('%.2f' %peakavs[g])+ ' (' + str('%.0f' %calints[g])+ 'H, '+ str(mults[g])+str(avcouplingstext[g])+')'
if g<len(peakavs)-1:
textout = textout + ', '
else:
textout = textout + str('%.2f' %peakavs[g])+ ' (' + str('%.0f' %calints[g])+ 'H, '+ str(mults[g])+str(avcouplingstext[g])
if broadlist[g]=='br':
textout = textout + ', br'
textout = textout + ')'
if g<len(peakavs)-1:
textout = textout + ', '
g=g+1
h={'textout':textout, 'sigs':sigs, 'ints':ints, 'solvs':solvs, 'solvlesssigs':solvlesssigs,
'solvlessints':solvlessints, 'removedsigs':removedsigs, 'DMSOpeak':DMSOpeak, 'solvlessconnect' : solvlessconnect}
return h
def cformatter(peaks, connect, broadlist=None):
## #creates a list of the DMSO peaks
##
## DMSOpeaks=[]
## y=0
## while y<len(peaks):
## if 39<peaks[y]<41:
## DMSOpeaks.append(peaks[y])
## y=y+1
##
## if full == "yes":
## stdout.write("\nDMSO peaks: "+listrounder(DMSOpeaks, 4)+"\n")
##
## if len(DMSOpeaks) != 7:
## stdout.write("!!!Incorrect number of DMSO peaks!!!")
##
## #calibrates the list of peaks to the middle DMSO peak
##
## calpeaks=[]
## f=0
## while f<len(peaks):
## if peaks[f] not in DMSOpeaks:
## calpeaks.append(peaks[f]+39.5-DMSOpeaks[3])
## f=f+1
##
## if full == "yes":
## stdout.write("\nCalibrated peaks: "+listrounder(calpeaks,4)+"\n")
##
## peakavs=calpeaks
##
## #makes a list of the peaks for output
##
## g=0
## textout = ""
## while g<len(peakavs):
## textout = textout + str("%.2f" %peakavs[g])
## if g<len(peakavs)-1:
## textout = textout + ", "
## g=g+1
g=0
textout = ""
while g<len(peaks):
textout = textout + str("%.2f" %peaks[g])
if g<len(peaks)-1:
textout = textout + ", "
g=g+1
solvlessconnect = connect
processdic = dict()
processdic['textout'] = textout
processdic['sigs'] = peaks
processdic['solvlessconnect'] = solvlessconnect
return processdic
## return (textout, peakavs, DMSOpeaks[3], len(peakavs))