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