1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """Module containing functions for handling NMRPipe SeriesTab files."""
24
25
26
27 import re
28 from warnings import warn
29
30
31 from lib.errors import RelaxError
32 from lib.warnings import RelaxWarning
33
34
36 """Extract the intensity information from the NMRPipe SeriesTab peak intensity file.
37
38 @keyword peak_list: The peak list object to place all data into.
39 @type peak_list: lib.spectrum.objects.Peak_list instance
40 @keyword file_data: The data extracted from the file converted into a list of lists.
41 @type file_data: list of lists of str
42 @keyword int_col: The column which to multiply the peak intensity data (used by the SeriesTab intensity file format).
43 @type int_col: int
44 @raises RelaxError: When the expected peak intensity is not a float.
45 """
46
47
48 modeline = False
49 mode = False
50 varsline = False
51 header = False
52
53
54 line_nr = 0
55 for line in file_data:
56 if len(line) > 0:
57 if line[0] == 'REMARK' and line[1] == 'Mode:':
58 modeline = line[2:]
59 mode = modeline[0]
60 elif line[0] == 'VARS':
61 varsline = line[1:]
62 elif line[0] == '1':
63 header = line_nr
64 break
65 line_nr += 1
66
67
68 if not (modeline and mode):
69 raise RelaxError("MODE not detected. Expecting line 2:\nREMARK Mode: Summation")
70
71
72 if not (varsline):
73 raise RelaxError("VARS not detected. Expecting line 8:\nVARS INDEX X_AXIS Y_AXIS X_PPM Y_PPM VOL ASS Z_A0")
74
75
76 if not header:
77 raise RelaxError("'1' not detected in start of line. Cannot determine header size.")
78
79
80 ass_i = varsline.index('ASS')
81
82
83 w1_col = None
84 w2_col = None
85
86
87 w1_col = varsline.index('Y_PPM')
88
89
90 w2_col = varsline.index('X_PPM')
91
92
93 Z_A = re.compile("Z_A*")
94 spectra = list(filter(Z_A.search, varsline))
95
96
97 spectra_i = []
98 for y in spectra:
99 spectra_i.append(varsline.index(y))
100
101
102 file_data = file_data[header:]
103
104
105 for line in file_data:
106
107 if line[ass_i] == '?-?':
108 continue
109
110
111 assign1, assign2 = re.split('-', line[ass_i])
112
113
114 row1 = re.split('([a-zA-Z]+)', assign1)
115 name1 = row1[-2] + row1[-1]
116
117
118 row2 = re.split('([a-zA-Z]+)', assign2)
119 name2 = row2[-2] + row2[-1]
120
121
122 got_res_num1 = True
123 try:
124 res_num1 = int(row1[-3])
125 except:
126 got_res_num1 = False
127 raise RelaxError("Improperly formatted NMRPipe SeriesTab file, cannot process the residue number for dimension 1 in assignment: %s." % line[0])
128
129
130 try:
131 res_num2 = int(row2[-3])
132 except:
133
134 if got_res_num1:
135 res_num2 = res_num1
136 else:
137 res_num2 = None
138 warn(RelaxWarning("Improperly formatted NMRPipe SeriesTab file, cannot process the residue number for dimension 2 in assignment: %s. Setting residue number to %s." % (line[0], res_num2)))
139
140
141 got_res_name1 = True
142 try:
143 res_name1 = row1[-4]
144 except:
145 got_res_name1 = False
146 res_name1 = None
147 warn(RelaxWarning("Improperly formatted NMRPipe SeriesTab file, cannot process the residue name for dimension 1 in assignment: %s. Setting residue name to %s." % (line[0], res_name1)))
148
149
150 try:
151 res_name2 = row2[-4]
152 except:
153
154 if got_res_name1:
155 res_name2 = res_name1
156 else:
157 res_name2 = None
158 warn(RelaxWarning("Improperly formatted NMRPipe SeriesTab file, cannot process the residue name for dimension 2 in assignment: %s. Setting residue name to %s." % (line[0], res_name2)))
159
160
161 try:
162
163 intensities = []
164 for i in range(len(spectra)):
165
166 intensities.append(float(line[spectra_i[i]])*float(line[5]))
167
168
169 except ValueError:
170 raise RelaxError("The peak intensity value %s from the line %s is invalid." % (intensity, line))
171
172
173 w1 = None
174 w2 = None
175 if w1_col != None:
176 try:
177 w1 = float(line[w1_col])
178 except ValueError:
179 raise RelaxError("The chemical shift from the line %s is invalid." % line)
180 if w2_col != None:
181 try:
182 w2 = float(line[w2_col])
183 except ValueError:
184 raise RelaxError("The chemical shift from the line %s is invalid." % line)
185
186
187 peak_list.add(res_nums=[res_num1, res_num2], res_names=[res_name1, res_name2], spin_names=[name1, name2], shifts=[w1, w2], intensity=intensities, intensity_name=spectra)
188