mailr7958 - /branches/spectral_errors/generic_fns/spectrum.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on October 23, 2008 - 18:23:
Author: bugman
Date: Thu Oct 23 18:23:42 2008
New Revision: 7958

URL: http://svn.gna.org/viewcvs/relax?rev=7958&view=rev
Log:
The peak list type is now automatically determined.

The new autodetect_format() function was written, and the top half of the 
read() function was
modified to handle the auto-detection.


Modified:
    branches/spectral_errors/generic_fns/spectrum.py

Modified: branches/spectral_errors/generic_fns/spectrum.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/spectral_errors/generic_fns/spectrum.py?rev=7958&r1=7957&r2=7958&view=diff
==============================================================================
--- branches/spectral_errors/generic_fns/spectrum.py (original)
+++ branches/spectral_errors/generic_fns/spectrum.py Thu Oct 23 18:23:42 2008
@@ -37,6 +37,38 @@
 from relax_errors import RelaxError, RelaxArgNotInListError, 
RelaxNoSequenceError
 from relax_io import extract_data, strip
 from relax_warnings import RelaxWarning, RelaxNoSpinWarning
+
+
+def autodetect_format(file_data):
+    """Automatically detect the format of the peak list.
+
+    @param file_data:   The processed results file data.
+    @type file_data:    list of lists of str
+    """
+
+    # The first header line.
+    for line in file_data:
+        if line != []:
+            break
+
+    # Generic format.
+    if line[0] in ['mol_name', 'res_num', 'res_name', 'spin_num', 
'spin_name']:
+        return 'generic'
+
+    # Sparky format.
+    if line[0] == 'Assignment':
+        return 'sparky'
+
+    # NMRView format.
+    if line == ['label', 'dataset', 'sw', 'sf']:
+        return 'nmrview'
+
+    # XEasy format.
+    if line == ['No.', 'Color', 'w1', 'w2', 'ass.', 'in', 'w1', 'ass.', 
'in', 'w2', 'Volume', 'Vol.', 'Err.', 'Method', 'Comment']:
+        return 'xeasy'
+
+    # Unsupported format.
+    raise RelaxError, "The format of the peak list file cannot be 
determined.  Either the file is of a non-standard format or the format is 
unsupported."
 
 
 def det_dimensions(file_data, proton, heteronuc, int_col):
@@ -340,10 +372,18 @@
     @type sep:              str or None
     """
 
-    # Format argument.
-    format_list = ['generic', 'nmrview', 'sparky', 'xeasy']
-    if format not in format_list:
-        raise RelaxArgNotInListError, ('format', format, format_list)
+    # Test if the current data pipe exists.
+    pipes.test()
+
+    # Test if sequence data is loaded.
+    if not exists_mol_res_spin_data():
+        raise RelaxNoSequenceError
+
+    # Extract the data from the file.
+    file_data = extract_data(file, dir)
+
+    # Automatic format detection.
+    format = autodetect_format(file_data)
 
     # Generic.
     if format == 'generic':
@@ -379,16 +419,6 @@
 
         # Set the intensity reading function.
         intensity_fn = intensity_xeasy
-
-    # Test if the current data pipe exists.
-    pipes.test()
-
-    # Test if sequence data is loaded.
-    if not exists_mol_res_spin_data():
-        raise RelaxNoSequenceError
-
-    # Extract the data from the file.
-    file_data = extract_data(file, dir)
 
     # Determine the number of header lines.
     num = number_of_header_lines(file_data, format, int_col, intensity_fn)




Related Messages


Powered by MHonArc, Updated Thu Oct 23 18:40:03 2008