Author: bugman Date: Fri Aug 2 13:51:50 2013 New Revision: 20503 URL: http://svn.gna.org/viewcvs/relax?rev=20503&view=rev Log: Modfied the intensity list to handle intensities for all spectra per spin. Progress sr #3043: (https://gna.org/support/index.php?3043) - support for NMRPipe seriesTab format *.ser. Troels E. Linnet provided this patch. Commit by: tlinset _aaattt_ gmail_dot_com Signed-off-by: Edward d'Auvergne <edward _att_ nmr-relax _dott_ com> Modified: trunk/lib/software/nmrpipe.py Modified: trunk/lib/software/nmrpipe.py URL: http://svn.gna.org/viewcvs/relax/trunk/lib/software/nmrpipe.py?rev=20503&r1=20502&r2=20503&view=diff ============================================================================== --- trunk/lib/software/nmrpipe.py (original) +++ trunk/lib/software/nmrpipe.py Fri Aug 2 13:51:50 2013 @@ -46,13 +46,13 @@ @rtype: list of lists of str, str, int, float, str """ - # Set start variables + # Set start variables. modeline = False mode = False varsline = False header = False - # Loop over lines, to extract variables and find header size + # Loop over lines, to extract variables and find header size. line_nr = 0 for line in file_data: if len(line) > 0: @@ -66,44 +66,53 @@ break line_nr += 1 - # Raise RelaxError, if the MODE is not found + # Raise RelaxError, if the MODE is not found. if not (modeline and mode): raise RelaxError("MODE not detected. Expecting line 2:\nREMARK Mode: Summation") - # Raise RelaxError, if the VARS line is not found + # Raise RelaxError, if the VARS line is not found. if not (varsline): raise RelaxError("VARS not detected. Expecting line 8:\nVARS INDEX X_AXIS Y_AXIS X_PPM Y_PPM VOL ASS Z_A0") - # Raise RelaxError, if the header size is not found + # Raise RelaxError, if the header size is not found. if not header: raise RelaxError("'1' not detected in start of line. Cannot determine header size.") - # Find index of assignment ASS + # Find index of assignment ASS. ass_i = varsline.index('ASS') - # Make a regular search for Z_A entries + # Make a regular search for Z_A entries. Z_A = re.compile("Z_A*") spectra = filter(Z_A.search, varsline) - # Find index of Z_A entries - spectra_i = [[x for x in varsline].index(y) for y in spectra] + # Find index of Z_A entries. + spectra_i = [] + for y in spectra: + spectra_i.append(varsline.index(y)) # Remove the header. file_data = file_data[header:] - # Define a list, for storing all the data - data_all = [] + # Create an empty intensity list. + intensity_list = [None]*len(spectra) - # Define a current counter + # Create an empty data list. + # Format: H_name, X_name, spin_id, intensity, line. + data = [None, None, None, intensity_list, None] + + # Create the whole data_all list, where entries will be replaced later. + data_all = [data]*len(file_data) + + # Define a current spectrum counter. i = 0 - # Loop over the spectra + # Loop over the spectra. for spectrum in spectra: - # Define a list, for storing the current spectrum data - data = [] + # Current intensity index. + int_i = spectra_i[i] - # Current intensity index - int_i = spectra_i[i] + # Define a current line counter. + j = 0 for line in file_data: # Skip non-assigned peaks. @@ -121,25 +130,35 @@ x_row = re.split('([A-Z]+)', x_assign) x_name = x_row[-2] + x_row[-1] - # The residue number. + # Get the residue number. try: res_num = int(x_row[-3]) except: raise RelaxError("Improperly formatted NMRPipe SeriesTab file.") - # Intensity. + # Get the intensity. try: + # The intensity is given by column multiplication. intensity = float(line[int_i])*float(line[5]) + + # Extract the intensity_list + intensity_list = data_all[j][3] + + # Replace the intensity. + intensity_list[i] = intensity + except ValueError: raise RelaxError("The peak intensity value %s from the line %s is invalid."%(intensity,line)) - # Append the data. - data.append([h_name, x_name, res_num, intensity]) + # Replace the data. + # Format: H_name, X_name, spin_id, intensity, line. + data_all[j] = [h_name, x_name, res_num, list(intensity_list), line] - # Append to all data - data_all.append([data,spectrum]) + # Add 1 to current line counter. + j += 1 - # Add 1 to counter + # Add 1 to current spectrum counter. i += 1 + # Return the data. return data_all