pychemstation 0.8.6__py3-none-any.whl → 0.8.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,6 +15,7 @@ from aghplctools.ingestion.text import (
15
15
  _signal_table_re,
16
16
  chunk_string,
17
17
  )
18
+ from pandas._libs.parsers import EmptyDataError
18
19
  from result import Err, Ok, Result
19
20
 
20
21
  from ..analysis.chromatogram import AgilentHPLCChromatogram
@@ -69,6 +70,37 @@ class CSVProcessor(ReportProcessor):
69
70
  """
70
71
  super().__init__(path)
71
72
 
73
+ def find_csv_prefix(self) -> str:
74
+ files = [
75
+ f
76
+ for f in os.listdir(self.path)
77
+ if os.path.isfile(os.path.join(self.path, f))
78
+ ]
79
+ for file in files:
80
+ if "00" in file:
81
+ name, _, file_extension = file.partition(".")
82
+ if "00" in name and file_extension.lower() == "csv":
83
+ prefix, _, _ = name.partition("00")
84
+ return prefix
85
+ raise FileNotFoundError("Couldn't find the prefix for CSV")
86
+
87
+ def report_contains(self, labels: List[str], want: List[str]):
88
+ for label in labels:
89
+ if label in want:
90
+ want.remove(label)
91
+
92
+ all_labels_seen = False
93
+ if len(want) != 0:
94
+ for want_label in want:
95
+ label_seen = False
96
+ for label in labels:
97
+ if want_label in label or want_label == label:
98
+ label_seen = True
99
+ all_labels_seen = label_seen
100
+ else:
101
+ return True
102
+ return all_labels_seen
103
+
72
104
  def process_report(self) -> Result[AgilentReport, AnyStr]:
73
105
  """
74
106
  Method to parse details from CSV report.
@@ -76,15 +108,30 @@ class CSVProcessor(ReportProcessor):
76
108
  :return: subset of complete report details, specifically the sample location, solvents in pumps,
77
109
  and list of peaks at each wavelength channel.
78
110
  """
79
- labels = os.path.join(self.path, "REPORT00.CSV")
80
- if os.path.exists(labels):
81
- df_labels: Dict[int, Dict[int:AnyStr]] = pd.read_csv(
111
+ prefix = self.find_csv_prefix()
112
+ labels = os.path.join(self.path, f"{prefix}00.CSV")
113
+ if not os.path.exists(labels):
114
+ raise ValueError(
115
+ "CSV reports do not exist, make sure to turn on the post run CSV report option!"
116
+ )
117
+ elif os.path.exists(labels):
118
+ LOCATION = "Location"
119
+ NUM_SIGNALS = "Number of Signals"
120
+ SOLVENT = "Solvent"
121
+ df_labels: Dict[int, Dict[int, str]] = pd.read_csv(
82
122
  labels, encoding="utf-16", header=None
83
123
  ).to_dict()
84
- vial_location = []
85
- signals = {}
86
- solvents = {}
87
- for pos, val in df_labels[0].items():
124
+ vial_location: str = ""
125
+ signals: Dict[int, list[AgilentPeak]] = {}
126
+ solvents: Dict[str, str] = {}
127
+ report_labels: Dict[int, str] = df_labels[0]
128
+
129
+ if not self.report_contains(
130
+ list(report_labels.values()), [LOCATION, NUM_SIGNALS, SOLVENT]
131
+ ):
132
+ return Err(f"Missing one of: {LOCATION}, {NUM_SIGNALS}, {SOLVENT}")
133
+
134
+ for pos, val in report_labels.items():
88
135
  if val == "Location":
89
136
  vial_location = df_labels[1][pos]
90
137
  elif "Solvent" in val:
@@ -93,18 +140,20 @@ class CSVProcessor(ReportProcessor):
93
140
  elif val == "Number of Signals":
94
141
  num_signals = int(df_labels[1][pos])
95
142
  for s in range(1, num_signals + 1):
96
- df = pd.read_csv(
97
- os.path.join(self.path, f"REPORT0{s}.CSV"),
98
- encoding="utf-16",
99
- header=None,
100
- )
101
- peaks = df.apply(lambda row: AgilentPeak(*row), axis=1)
143
+ try:
144
+ df = pd.read_csv(
145
+ os.path.join(self.path, f"{prefix}0{s}.CSV"),
146
+ encoding="utf-16",
147
+ header=None,
148
+ )
149
+ peaks = df.apply(lambda row: AgilentPeak(*row), axis=1)
150
+ except EmptyDataError:
151
+ peaks = []
102
152
  try:
103
153
  wavelength = df_labels[1][pos + s].partition(",4 Ref=off")[
104
- 0
105
- ][-3:]
106
- wavelength = int(wavelength)
107
- signals[wavelength] = list(peaks)
154
+ 0
155
+ ][-3:]
156
+ signals[int(wavelength)] = list(peaks)
108
157
  except (IndexError, ValueError):
109
158
  # TODO: Ask about the MS signals
110
159
  pass
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pychemstation
3
- Version: 0.8.6
3
+ Version: 0.8.7
4
4
  Summary: Library to interact with Chemstation software, primarily used in Hein lab.
5
5
  Project-URL: Documentation, https://pychemstation-e5a086.gitlab.io/pychemstation.html
6
6
  Project-URL: Repository, https://gitlab.com/heingroup/device-api/pychemstation
@@ -2,7 +2,7 @@ pychemstation/__init__.py,sha256=Sc4z8LRVFMwJUoc_DPVUriSXTZ6PO9MaJ80PhRbKyB8,34
2
2
  pychemstation/analysis/__init__.py,sha256=dcX7OeHoKdyrECHRCSXgKZN81nOXSAmZRxXzRT0jpDc,126
3
3
  pychemstation/analysis/base_spectrum.py,sha256=t_VoxAtBph1V7S4fOsziERHiOBkYP0_nH7LTwbTEvcE,16529
4
4
  pychemstation/analysis/chromatogram.py,sha256=cBfLh58PrBZMg9-u5o_Q-FCuu3MlB0q0ZFm9_2uaciU,3270
5
- pychemstation/analysis/process_report.py,sha256=9QTIyml4hmyCBd5QaylO9WzBCnQtatMcFRPerOpP90o,12498
5
+ pychemstation/analysis/process_report.py,sha256=UvDhz90OprP9GLgYotfVsKrFiPOtP1BBL-R6cV71JVk,14410
6
6
  pychemstation/control/README.md,sha256=_7ITj4hD17YIwci6UY6xBebC9gPCBpzBFTB_Gx0eJBc,3124
7
7
  pychemstation/control/__init__.py,sha256=uzfsVAGDhMP6SyV10KAH264ytDLMsMRZXRK5XhWS-rc,102
8
8
  pychemstation/control/hplc.py,sha256=mV-IO-6wdzB7MuV5LcZYwb4yZibBgEKX2LtbJ9WiKNw,12304
@@ -31,7 +31,7 @@ pychemstation/utils/sequence_types.py,sha256=T0IP2iMqorUrdzH4at9Vsmmb3SCAEmN4z1c
31
31
  pychemstation/utils/spec_utils.py,sha256=lS27Xi4mFNDWBfmBqOoxTcVchPAkLK2mSdoaWDOfaPI,10211
32
32
  pychemstation/utils/table_types.py,sha256=inOVpwSsic31VdVdJkfuq35QfKd7PoNoXY1QnOxZ6Sw,3235
33
33
  pychemstation/utils/tray_types.py,sha256=9yLRIBn3IPVMbhrFqJQJ5gCQJI7H9DD2cdIFQDp2-8k,5184
34
- pychemstation-0.8.6.dist-info/METADATA,sha256=UO8aoaIh7ntSKC6vFLYGlFhIqijy-Nal55pnPePuQ0Y,6032
35
- pychemstation-0.8.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
36
- pychemstation-0.8.6.dist-info/licenses/LICENSE,sha256=9bdF75gIf1MecZ7oymqWgJREVz7McXPG-mjqrTmzzD8,18658
37
- pychemstation-0.8.6.dist-info/RECORD,,
34
+ pychemstation-0.8.7.dist-info/METADATA,sha256=gUIv5hJpPnqyuVsfq91lDL_deVNU2BM1klYuW7BE_KI,6032
35
+ pychemstation-0.8.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
36
+ pychemstation-0.8.7.dist-info/licenses/LICENSE,sha256=9bdF75gIf1MecZ7oymqWgJREVz7McXPG-mjqrTmzzD8,18658
37
+ pychemstation-0.8.7.dist-info/RECORD,,