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 """Module containing functions for the handling of peak intensities."""
26
27
28
29 import sys
30 from warnings import warn
31
32
33 from lib.errors import RelaxError
34 from lib.io import extract_data, read_spin_data, strip, write_data
35 from lib.spectrum import nmrpipe, nmrview, sparky, xeasy
36 from lib.spectrum.objects import Peak_list
37 from lib.warnings import RelaxWarning, RelaxNoSpinWarning
38 from pipe_control.mol_res_spin import generate_spin_id_unique, return_spin
39
40
71
72
73 -def intensity_generic(peak_list=None, file_data=None, spin_id_col=None, mol_name_col=None, res_num_col=None, res_name_col=None, spin_num_col=None, spin_name_col=None, data_col=None, sep=None, spin_id=None):
74 """Extract the peak intensity information from the generic column formatted peak list.
75
76 @keyword peak_list: The peak list object to place all data into.
77 @type peak_list: lib.spectrum.objects.Peak_list instance
78 @keyword file_data: The data extracted from the file converted into a list of lists.
79 @type file_data: list of lists of str
80 @keyword spin_id_col: The column containing the spin ID strings (used by the generic intensity file format). If supplied, the mol_name_col, res_name_col, res_num_col, spin_name_col, and spin_num_col arguments must be none. @type spin_id_col: int or None @keyword mol_name_col: The column containing the molecule name information (used by the generic intensity file format). If supplied, spin_id_col must be None.
81 @type mol_name_col: int or None
82 @keyword res_name_col: The column containing the residue name information (used by the generic intensity file format). If supplied, spin_id_col must be None.
83 @type res_name_col: int or None
84 @keyword res_num_col: The column containing the residue number information (used by the generic intensity file format). If supplied, spin_id_col must be None.
85 @type res_num_col: int or None
86 @keyword spin_name_col: The column containing the spin name information (used by the generic intensity file format). If supplied, spin_id_col must be None.
87 @type spin_name_col: int or None
88 @keyword spin_num_col: The column containing the spin number information (used by the generic intensity file format). If supplied, spin_id_col must be None.
89 @type spin_num_col: int or None
90 @keyword data_col: The column containing the peak intensities.
91 @type data_col: int or list of int
92 @keyword sep: The column separator which, if None, defaults to whitespace.
93 @type sep: str or None
94 @keyword spin_id: The spin ID string used to restrict data loading to a subset of all spins.
95 @type spin_id: None or str
96 @raises RelaxError: When the expected peak intensity is not a float.
97 """
98
99
100 if data_col == None:
101 raise RelaxError("The data column argument has not been supplied.")
102
103
104 file_data = strip(file_data)
105
106
107 if not isinstance(data_col, list):
108 data_col = [data_col]
109
110
111 for line in file_data:
112
113 intensity = []
114 for i in range(len(data_col)):
115
116 for values in read_spin_data(file_data=[line], spin_id_col=spin_id_col, mol_name_col=mol_name_col, res_num_col=res_num_col, res_name_col=res_name_col, spin_num_col=spin_num_col, spin_name_col=spin_name_col, data_col=data_col[i], sep=sep, spin_id=spin_id):
117
118 if len(values) != 6:
119 raise RelaxError("The molecule name, residue number and name, spin number and name, and value columns could not be found in the data %s." % repr(values))
120
121
122 mol_name, res_num, res_name, spin_num, spin_name, value = values
123
124
125 intensity.append(value)
126
127
128 peak_list.add(mol_names=[mol_name, mol_name], res_nums=[res_num, res_num], res_names=[res_name, res_name], spin_nums=[spin_num, spin_num], spin_names=[spin_name, spin_name], intensity=intensity)
129
130
131 -def read_peak_list(file=None, dir=None, int_col=None, spin_id_col=None, mol_name_col=None, res_num_col=None, res_name_col=None, spin_num_col=None, spin_name_col=None, sep=None, spin_id=None):
132 """Read the peak intensity data.
133
134 @keyword file: The name of the file containing the peak intensities.
135 @type file: str
136 @keyword dir: The directory where the file is located.
137 @type dir: str
138 @keyword int_col: The column containing the peak intensity data. If set to None, the auto-detection of intensity data will be attempted.
139 @type int_col: None or int
140 @keyword spin_id_col: The column containing the spin ID strings (used by the generic intensity file format). If supplied, the mol_name_col, res_name_col, res_num_col, spin_name_col, and spin_num_col arguments must be none.
141 @type spin_id_col: int or None
142 @keyword mol_name_col: The column containing the molecule name information (used by the generic intensity file format). If supplied, spin_id_col must be None.
143 @type mol_name_col: int or None
144 @keyword res_name_col: The column containing the residue name information (used by the generic intensity file format). If supplied, spin_id_col must be None.
145 @type res_name_col: int or None
146 @keyword res_num_col: The column containing the residue number information (used by the generic intensity file format). If supplied, spin_id_col must be None.
147 @type res_num_col: int or None
148 @keyword spin_name_col: The column containing the spin name information (used by the generic intensity file format). If supplied, spin_id_col must be None.
149 @type spin_name_col: int or None
150 @keyword spin_num_col: The column containing the spin number information (used by the generic intensity file format). If supplied, spin_id_col must be None.
151 @type spin_num_col: int or None
152 @keyword sep: The column separator which, if None, defaults to whitespace.
153 @type sep: str or None
154 @keyword spin_id: The spin ID string used to restrict data loading to a subset of all spins.
155 @type spin_id: None or str
156 @return: The peak list object containing all relevant data in the peak list.
157 @rtype: lib.spectrum.objects.Peak_list instance
158 """
159
160
161 file_data = extract_data(file, dir, sep=sep)
162
163
164 peak_list = Peak_list()
165
166
167 format = autodetect_format(file_data)
168
169
170 if format == 'generic':
171
172 print("Generic formatted data file.\n")
173
174
175 intensity_generic(peak_list=peak_list, file_data=file_data, spin_id_col=spin_id_col, mol_name_col=mol_name_col, res_num_col=res_num_col, res_name_col=res_name_col, spin_num_col=spin_num_col, spin_name_col=spin_name_col, data_col=int_col, sep=sep, spin_id=spin_id)
176
177
178 elif format == 'nmrview':
179
180 print("NMRView formatted data file.\n")
181
182
183 nmrview.read_list(peak_list=peak_list, file_data=file_data)
184
185
186 elif format == 'seriestab':
187
188 print("NMRPipe SeriesTab formatted data file.\n")
189
190
191 nmrpipe.read_seriestab(peak_list=peak_list, file_data=file_data, int_col=int_col)
192
193
194 elif format == 'sparky':
195
196 print("Sparky formatted data file.\n")
197
198
199 sparky.read_list(peak_list=peak_list, file_data=file_data)
200
201
202 elif format == 'xeasy':
203
204 print("XEasy formatted data file.\n")
205
206
207 xeasy.read_list(peak_list=peak_list, file_data=file_data, int_col=int_col)
208
209
210 return peak_list
211