From 4dfd164de75a8774409b6a9cf74eb4f826b6442c Mon Sep 17 00:00:00 2001
From: Christian Ludwig <ludwigc@mac.com>
Date: Tue, 1 Oct 2024 23:31:06 -0300
Subject: [PATCH] added update_metabolabpy

---
 metabolabpy/__init__.py       |  2 +-
 metabolabpy/nmr/nmrData.py    | 45 +++++++++++++++++++++++------------
 metabolabpy/nmr/nmrDataSet.py | 14 +++++++----
 3 files changed, 41 insertions(+), 20 deletions(-)

diff --git a/metabolabpy/__init__.py b/metabolabpy/__init__.py
index 1a6da77..f064d73 100644
--- a/metabolabpy/__init__.py
+++ b/metabolabpy/__init__.py
@@ -1,4 +1,4 @@
 __author__ = 'Christian Ludwig (C.Ludwig@bham.ac.uk)'
 __credits__ = 'Christian Ludwig (C.Ludwig@bham.ac.uk)'
-__version__ = '0.9.50'
+__version__ = '0.9.53'
 __license__ = 'GPLv3'
diff --git a/metabolabpy/nmr/nmrData.py b/metabolabpy/nmr/nmrData.py
index 4cf3f41..0b69124 100644
--- a/metabolabpy/nmr/nmrData.py
+++ b/metabolabpy/nmr/nmrData.py
@@ -1132,22 +1132,29 @@ def conv(self, fid):
         return fid
         # end conv
 
-    def create_title(self, xls=[], dataset_label='', pos_label='', rack_label='', replace_title=False, c_dict={}, excel_name=''):
-        if len(xls) == 0 or len(dataset_label) == 0 or len(pos_label) == 0 or len(rack_label) == 0 or len(c_dict) == 0 or len(excel_name) == 0:
+    def create_title(self, xls=[], dataset_label='', pos_label='', rack_label='', replace_title=False, c_dict={}, excel_name='', autosampler='SampleJet'):
+        if len(xls) == 0 or len(dataset_label) == 0 or len(pos_label) == 0 or len(c_dict) == 0 or len(excel_name) == 0:
             return
 
-        get_auto_pos = re.compile(r'[A-Z]\d+')
-        get_rack_num = re.compile(r'<\d+')
-        try:
-            pos = get_auto_pos.findall(self.acq.autopos)[0]
-            rack = get_rack_num.findall(self.acq.autopos)[0][1:]
-        except:
-            rack = str(int(int(self.acq.holder) / 100))
-            pos = int(self.acq.holder) - int(rack)*100 - 1
-            pos_char = self.nmr_col[str(pos % 8)]
-            pos_no = str(int(pos / 8) + 1)
+        if len(rack_label) == 0 and autosampler == 'SampleJet':
+            return
 
-            pos = pos_char + pos_no
+        if autosampler == 'SampleJet':
+            get_auto_pos = re.compile(r'[A-Z]\d+')
+            get_rack_num = re.compile(r'<\d+')
+            try:
+                pos = get_auto_pos.findall(self.acq.autopos)[0]
+                rack = get_rack_num.findall(self.acq.autopos)[0][1:]
+            except:
+                rack = str(int(int(self.acq.holder) / 100))
+                pos = int(self.acq.holder) - int(rack)*100 - 1
+                pos_char = self.nmr_col[str(pos % 8)]
+                pos_no = str(int(pos / 8) + 1)
+
+                pos = pos_char + pos_no
+        else:
+            pos_no = os.path.split(self.orig_data_set)[1]
+            pos = pos_no
 
         if not replace_title:
             title = self.title
@@ -1162,10 +1169,18 @@ def create_title(self, xls=[], dataset_label='', pos_label='', rack_label='', re
         if len(dsl) == 0:
             return
 
-        line_no = c_dict[dsl][rack + " " + pos]
+        if autosampler == 'SampleJet':
+            line_no = c_dict[dsl][rack + " " + pos]
+        else:
+            line_no = c_dict[dsl][str(pos)]
+
         title += f'Excel File : {excel_name}\n'
         title += f'Excel Line Number : {line_no + 2}\n'
-        title += f'acqus AUTOPOS : {rack} {pos}\n'
+        if autosampler == 'SampleJet':
+            title += f'acqus AUTOPOS : {rack} {pos}\n'
+
+        title += f'autosampler : {autosampler}\n'
+
         for col in xls.columns:
             if col == 'number':
                 title += f'{col} : {int(xls[col][line_no])}\n'
diff --git a/metabolabpy/nmr/nmrDataSet.py b/metabolabpy/nmr/nmrDataSet.py
index 02e9136..4d64c86 100644
--- a/metabolabpy/nmr/nmrDataSet.py
+++ b/metabolabpy/nmr/nmrDataSet.py
@@ -365,11 +365,14 @@ def compress_buckets(self):
 
         # end compress_buckets
 
-    def create_titles(self, xls=[], dataset_label='', pos_label='', rack_label='', replace_title=False, excel_name=''):
-        if len(xls) == 0 or len(dataset_label) == 0 or len(pos_label) == 0 or len(rack_label) == 0 or len(
+    def create_titles(self, xls=[], dataset_label='', pos_label='', rack_label='', replace_title=False, excel_name='', autosampler='SampleJet'):
+        if len(xls) == 0 or len(dataset_label) == 0 or len(pos_label) == 0 or len(
                 excel_name) == 0:
             return
 
+        if len(rack_label) == 0 and autosampler == 'SampleJet':
+            return
+
         if len(self.nmrdat[self.s]) == 0:
             return
 
@@ -379,11 +382,14 @@ def create_titles(self, xls=[], dataset_label='', pos_label='', rack_label='', r
                 if not xls[dataset_label][k] in c_dict.keys():
                     c_dict[xls[dataset_label][k]] = {}
 
-                c_dict[xls[dataset_label][k]][str(xls[rack_label][k]).replace(' ','') + " " + str(xls[pos_label][k]).replace(' ','')] = k
+                if autosampler == 'SampleJet':
+                    c_dict[xls[dataset_label][k]][str(xls[rack_label][k]).replace(' ','') + " " + str(xls[pos_label][k]).replace(' ','')] = k
+                else:
+                    c_dict[xls[dataset_label][k]][str(xls[pos_label][k]).replace(' ','')] = k
 
         for k in range(len(self.nmrdat[self.s])):
             self.nmrdat[self.s][k].create_title(xls, dataset_label, pos_label, rack_label, replace_title, c_dict,
-                                                excel_name)
+                                                excel_name, autosampler)
 
         # end create_titles