mailr26817 - /branches/nmrglue/pipe_control/nmrglue.py


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

Header


Content

Posted by tlinnet on November 29, 2014 - 01:36:
Author: tlinnet
Date: Sat Nov 29 01:36:51 2014
New Revision: 26817

URL: http://svn.gna.org/viewcvs/relax?rev=26817&view=rev
Log:
Expanded the reading of files with nmrglue, to work with several files.

Task #7873 (https://gna.org/task/index.php?7873): Write wrapper function to 
nmrglue, to read .ft2 files and process them.
Homepage: http://www.nmrglue.com/
Link to nmrglue discussion: 
https://groups.google.com/forum/#!forum/nmrglue-discuss
The code is develop at Github: https://github.com/jjhelmus/nmrglue/
Google code: https://code.google.com/p/nmrglue/
Documentation: http://nmrglue.readthedocs.org/en/latest/index.html

Modified:
    branches/nmrglue/pipe_control/nmrglue.py

Modified: branches/nmrglue/pipe_control/nmrglue.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/nmrglue/pipe_control/nmrglue.py?rev=26817&r1=26816&r2=26817&view=diff
==============================================================================
--- branches/nmrglue/pipe_control/nmrglue.py    (original)
+++ branches/nmrglue/pipe_control/nmrglue.py    Sat Nov 29 01:36:51 2014
@@ -64,14 +64,51 @@
     if file == None:
         raise RelaxError("The file name must be supplied.")
 
-    # Add spectrum ID.
-    add_spectrum_id(spectrum_id)
+    # Multiple ID flags.
+    flag_multi = False
+    flag_multi_file = False
+    if isinstance(spectrum_id, list):
+        flag_multi = True
+    if isinstance(file, list):
+        flag_multi_file = True
 
-    # Read the spectrum, and get it back as a class instance object.
-    nmrglue_data = read_spectrum(file=file, dir=dir)
+    # List argument checks.
+    if flag_multi:
+        # Both of list type,
+        if not flag_multi_file:
+            raise RelaxError("The file and spectrum ID  must both be of list 
type.")
 
-    # Store the data.
-    add_nmrglue_data(spectrum_id=spectrum_id, nmrglue_data=nmrglue_data)
+        # List lengths for multiple files.
+        if flag_multi_file and len(spectrum_id) != len(file):
+            raise RelaxError("The file list %s and spectrum ID list %s do 
not have the same number of elements." % (file, spectrum_id))
+
+    # More list argument checks (when only one spectrum ID is supplied).
+    else:
+        # Multiple files.
+        if flag_multi_file:
+            raise RelaxError("If multiple files are supplied, then multiple 
spectrum IDs must also be supplied.")
+
+    # Convert the file argument to a list if necessary.
+    if not isinstance(file, list):
+        file = [file]
+
+    # Convert the spectrum_id argument to a list if necessary.
+    if not isinstance(spectrum_id, list):
+        spectrum_id = [spectrum_id]
+
+    # Loop over the files.
+    for i, file_i in enumerate(file):
+        # Assign spectrum id.
+        spectrum_id_i = spectrum_id[i]
+
+        # Add spectrum ID.
+        add_spectrum_id(spectrum_id_i)
+
+        # Read the spectrum, and get it back as a class instance object.
+        nmrglue_data = read_spectrum(file=file_i, dir=dir)
+
+        # Store the data.
+        add_nmrglue_data(spectrum_id=spectrum_id_i, 
nmrglue_data=nmrglue_data)
 
 
 def plot_contour(spectrum_id=None, contour_start=30000., contour_num=20, 
contour_factor=1.20, ppm=True, show=False):




Related Messages


Powered by MHonArc, Updated Sat Nov 29 01:40:02 2014