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
29
30 from lib.errors import RelaxError
31 from lib.io import open_write_file, strip
32
33
35 """Extract the intensity information from the NMRPipe SeriesTab peak intensity file.
36
37 @keyword peak_list: The peak list object to place all data into.
38 @type peak_list: lib.spectrum.objects.Peak_list instance
39 @keyword file_data: The data extracted from the file converted into a list of lists.
40 @type file_data: list of lists of str
41 @keyword int_col: The column which to multiply the peak intensity data (used by the SeriesTab intensity file format).
42 @type int_col: int
43 @raises RelaxError: When the expected peak intensity is not a float.
44 """
45
46
47 modeline = False
48 mode = False
49 varsline = False
50 header = False
51
52
53 line_nr = 0
54 for line in file_data:
55 if len(line) > 0:
56 if line[0] == 'REMARK' and line[1] == 'Mode:':
57 modeline = line[2:]
58 mode = modeline[0]
59 elif line[0] == 'VARS':
60 varsline = line[1:]
61 elif line[0] == '1':
62 header = line_nr
63 break
64 line_nr += 1
65
66
67 if not (modeline and mode):
68 raise RelaxError("MODE not detected. Expecting line 2:\nREMARK Mode: Summation")
69
70
71 if not (varsline):
72 raise RelaxError("VARS not detected. Expecting line 8:\nVARS INDEX X_AXIS Y_AXIS X_PPM Y_PPM VOL ASS Z_A0")
73
74
75 if not header:
76 raise RelaxError("'1' not detected in start of line. Cannot determine header size.")
77
78
79 ass_i = varsline.index('ASS')
80
81
82 Z_A = re.compile("Z_A*")
83 spectra = list(filter(Z_A.search, varsline))
84
85
86 spectra_i = []
87 for y in spectra:
88 spectra_i.append(varsline.index(y))
89
90
91 file_data = file_data[header:]
92
93
94 for line in file_data:
95
96 if line[ass_i] == '?-?':
97 continue
98
99
100 assign1, assign2 = re.split('-', line[ass_i])
101
102
103 row1 = re.split('([a-zA-Z]+)', assign1)
104 name1 = row1[-2] + row1[-1]
105
106
107 row2 = re.split('([a-zA-Z]+)', assign2)
108 name2 = row2[-2] + row2[-1]
109
110
111 try:
112 res_num = int(row1[-3])
113 except:
114 raise RelaxError("Improperly formatted NMRPipe SeriesTab file., cannot process the assignment '%s'." % line[0])
115
116
117 try:
118
119 intensities = []
120 for i in range(len(spectra)):
121
122 intensities.append(float(line[spectra_i[i]])*float(line[5]))
123
124
125 except ValueError:
126 raise RelaxError("The peak intensity value %s from the line %s is invalid." % (intensity, line))
127
128
129 peak_list.add(res_nums=[res_num, res_num], spin_names=[name1, name2], intensity=intensities, intensity_name=spectra)
130