chromaquant 0.3.1__py3-none-any.whl → 0.4.0__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.
@@ -9,4 +9,5 @@ Created 10-19-2024
9
9
 
10
10
  """
11
11
 
12
- from .handleDirectories import *
12
+ from .handleDirectories import *
13
+ from .fileChecks import *
@@ -0,0 +1,172 @@
1
+ """
2
+
3
+ COPYRIGHT STATEMENT:
4
+
5
+ ChromaQuant – A quantification software for complex gas chromatographic data
6
+
7
+ Copyright (c) 2024, by Julia Hancock
8
+ Affiliation: Dr. Julie Elaine Rorrer
9
+ URL: https://www.rorrerlab.com/
10
+
11
+ License: BSD 3-Clause License
12
+
13
+ ---
14
+
15
+ SUBPACKAGE FOR FILE NAMING AND HANDLING PROTOCOLS
16
+
17
+ Julia Hancock
18
+ Started 12/10/2024
19
+
20
+ """
21
+
22
+ """ PACKAGES """
23
+ import os
24
+ import numpy as np
25
+ import pandas as pd
26
+
27
+ """ FUNCTIONS """
28
+
29
+ #Function for checking if file exists and adding number if so, used for new breakdowns
30
+ def fileCheck(path):
31
+ #Inspired by https://stackoverflow.com/questions/13852700/create-file-but-if-name-exists-add-number
32
+ filename, extension = os.path.splitext(path)
33
+ i = 1
34
+
35
+ while os.path.exists(path):
36
+ path = filename + " ("+str(i)+")" + extension
37
+ i += 1
38
+
39
+ return path
40
+
41
+ #Function for selecting FID peak, MS peak, and FIDpMS pathnames according to sample name and phase
42
+ def fileNamer(sname,sphase,sub_Dict,pathData):
43
+ """
44
+ Parameters
45
+ ----------
46
+ sname : STR
47
+ The name of the sample.
48
+ sphase : STR
49
+ A string that describes whether sample is gas ("G") or liquid ("L").
50
+ sub_Dict : Dict
51
+ A dictionary of substrings to add to sample name to create file names
52
+ pathData : STR
53
+ A string containing the pathname to the datafiles directory
54
+
55
+ Returns
56
+ -------
57
+ paths : List
58
+ A list of pathnames to return.
59
+
60
+ """
61
+
62
+ #If sample phase is liquid, set pathnames accordingly
63
+ if sphase == "L":
64
+
65
+ pathFID = os.path.join(pathData,sname+sub_Dict['Liquid FID'][0])
66
+ pathMS = os.path.join(pathData,sname+sub_Dict['Liquid Labelled MS Peaks'][0])
67
+ pathFIDpMS = os.path.join(pathData,sname+sub_Dict['Liquid FID+MS'][0])
68
+
69
+ #Else if sample phase is gas, set pathnames accordingly
70
+ elif sphase == "G":
71
+
72
+ pathFID = os.path.join(pathData,sname+sub_Dict['Gas TCD+FID'][0])
73
+ pathMS = os.path.join(pathData,sname+sub_Dict['Gas Labelled MS Peaks'][0])
74
+ pathFIDpMS = os.path.join(pathData,sname+sub_Dict['Gas FID+MS'][0])
75
+
76
+ #Otherwise, set all paths to None
77
+ else:
78
+
79
+ pathFID = None
80
+ pathMS = None
81
+ pathFIDpMS = None
82
+
83
+ paths = [pathFID,pathMS,pathFIDpMS]
84
+
85
+ return paths
86
+
87
+ #Function for checking if FIDpMS file exists – creates it if necessary and imports/returns the data
88
+ def checkFile(fpmDir,fDir):
89
+ """
90
+ Parameters
91
+ ----------
92
+ fpmDir : STR
93
+ A string containing the pathname of the FIDpMS file in question.
94
+ fDir : STR
95
+ A string containing the pathname of the FID file of the same sample/phase as the FIDpMS file.
96
+
97
+ Returns
98
+ -------
99
+ fpmDF : DataFrame
100
+ A DataFrame containing the contents of the FIDpMS file.
101
+ exists : BOOL
102
+ A boolean describing whether or not the relevant file exists and has manually added peaks.
103
+
104
+ """
105
+
106
+ #If FIDpMS file does not exist in data file directory, create it and return False
107
+ if not os.path.exists(fpmDir):
108
+
109
+ #print that file wasn't found and a new one is being created
110
+ print('[fileChecks] FIDpMS file not found for sample and phase, creating new...')
111
+
112
+ #Read FID dataframe
113
+ fDF = pd.read_csv(fDir)
114
+
115
+ #Filter FID dataframe to only include FID rows, as gas samples may have TCD rows, and set to fpmDF
116
+ fpmDF = fDF.loc[fDF['Signal Name'] == 'FID1A'].copy()
117
+
118
+ #Rename FID RT and FID Area columns, as well as rename the Height column to MS RT
119
+ fpmDF = fpmDF.rename(columns={'RT':'FID RT','Area':'FID Area','Height':'MS RT'})
120
+
121
+ #Clear the contents of the MS RT column
122
+ fpmDF['MS RT'] = np.nan
123
+
124
+ #Create list of new columns to create
125
+ lnc = ['Formula','Match Factor','Compound Source','Compound Type Abbreviation']
126
+
127
+ #Loop through lnc, adding nan columns for each entry
128
+ for i in lnc:
129
+ fpmDF[i] = np.nan
130
+
131
+ #Remove the Injection Data File Name and Signal Name columns
132
+ fpmDF = fpmDF.drop(['Injection Data File Name','Signal Name'],axis=1).copy()
133
+
134
+ #Save fpmDF to provided pathname
135
+ fpmDF.to_csv(fpmDir, index=False)
136
+
137
+ return fpmDF, False
138
+
139
+ #Otherwise..
140
+ else:
141
+
142
+ fpmDF = pd.read_csv(fpmDir)
143
+
144
+ #If the FIDpMS exists and there exist any peaks..
145
+ if fpmDF['Compound Name'].any():
146
+
147
+ #Define a new dataframe which includes all rows with labelled peaks
148
+ fpmDF_labelled = fpmDF.loc[~fpmDF['Compound Name'].isna()]['Compound Source']
149
+
150
+ #If those peaks are manually assigned or have a blank source, return the dataframe and True
151
+ if 'Manual' in fpmDF_labelled.values.tolist() or pd.isna(fpmDF_labelled.values).any():
152
+
153
+ #Print
154
+ print('[fileChecks] FIDpMS file exists and contains manual and/or blank sourced entries')
155
+
156
+ return fpmDF, True
157
+
158
+ #Otherwise, if there exist no manually assigned peaks or labelled peaks with a blank source, return False
159
+ else:
160
+
161
+ #Print
162
+ print('[fileChecks] FIDpMS file exists but does not contains manual or blank sourced entries')
163
+
164
+ return fpmDF, False
165
+
166
+ #If the FIDpMS file exists but has no peaks, return False
167
+ else:
168
+
169
+ #Print
170
+ print('[fileChecks] FIDpMS file exists but contains no labelled peaks')
171
+
172
+ return fpmDF, False
@@ -30,7 +30,7 @@ import getpass
30
30
  def handle(fileDir):
31
31
  #fileDir is the passed absolute directory of the currently running file
32
32
 
33
- #Import sample information from json file
33
+ #Import file information from json file
34
34
  with open(os.path.join(fileDir,'properties.json'),'r') as props_f:
35
35
  props = json.load(props_f)
36
36
 
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ ChromaQuant package initialization
6
+
7
+ Julia Hancock
8
+ Created 12-05-2024
9
+
10
+ """
11
+
12
+ from .hydroMain import mainHydro