Skip to content

Commit ae72754

Browse files
adding to docker env
1 parent 84d09b3 commit ae72754

9 files changed

Lines changed: 197 additions & 146 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ __pycache__/
1414
*.so
1515
mana_workshop/
1616
data/raw_data/lc_fticr/*
17+
2025*/
18+
_LAST
1719

1820

1921
# Distribution / packaging

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ RUN pip install pycparser \
2626
WORKDIR /enviroms
2727
COPY enviroMS/ /enviroms/enviroMS/
2828
COPY README.md disclaimer.txt Makefile requirements.txt setup.py /enviroms/
29+
COPY data/raw_data/lc_fticr /enviroms/data/raw_data/lc_fticr
30+
COPY data/reference/Hawkes_neg.ref /enviroms/data/reference/Hawkes_neg.ref
31+
COPY configuration/lc_fticr /enviroms/configuration/lc_fticr
32+
2933

3034
# Install the correct version of CoreMS from github
3135
RUN pip install git+https://github.com/EMSL-Computing/CoreMS.git@v3.6.0

configuration/lc_fticr/lc_fticr_corems_mfsearch.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[MolecularFormulaSearch]
2-
url_database = "postgresql+psycopg2://coremsappdb:coremsapppnnl@localhost:5432/coremsapp"
2+
url_database = "postgresql+psycopg2://coremsappdb:coremsapppnnl@molformdb:5432/coremsapp"
33
error_method = 'None'
44
score_method = 'prob_score'
55
min_ppm_error = -1
@@ -10,7 +10,7 @@ use_isotopologue_filter = false
1010
min_abun_error = -30
1111
max_abun_error = 70
1212
use_min_peaks_filter = true
13-
min_peaks_per_class = 10
13+
min_peaks_per_class = 10
1414
adduct_atoms_neg = ['Cl']
1515
adduct_atoms_pos = ['Na']
1616
isProtonated = true

configuration/lc_fticr/lc_fticr_enviroms.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
# Time Block Parameters:
2+
full_input_file_path = "./data/raw_data/lc_fticr/20231109_60885_SRFA_50ppm_5uL_LC_PolarAdv-001262_231109183242.raw"
23
start_time = 1.5 # minutes
34
end_time = 9.5 # minutes
45
time_block = 30 #seconds
5-
# Reference mass list:
6+
# Reference mass list:
67
refmasslist_neg = "data/reference/Hawkes_neg.ref"
78
# input output paths
8-
input_file_path = "data/raw_data/..."
9+
input_file_directory = "data/raw_data/..."
910
input_file_name = "..."
1011
output_directory = "data/..."
1112
output_file_name = "..."
1213
output_file_type = ".csv"
1314
# corems and MF search settings
14-
ms_toml_path = "configuration/lc_fticr/lc_fticr_corems_massspectrum.toml"
15-
mspeak_toml_path = "configuration/lc_fticr/lc_fticr_corems_mspeak.toml"
16-
mfsearch_toml_path = "configuration/lc_fticr/lc_fticr_corems_mfsearch.toml"
15+
lc_fticr_toml_path = "./configuration/lc_fticr/lc_fticr_enviroms.toml"
16+
ms_toml_path = "./configuration/lc_fticr/lc_fticr_corems_massspectrum.toml"
17+
mspeak_toml_path = "./configuration/lc_fticr/lc_fticr_corems_mspeak.toml"
18+
mfsearch_toml_path = "./configuration/lc_fticr/lc_fticr_corems_mfsearch.toml"
1719
# plot settings
1820
plot_van_krevelen_all_ids = true
1921
plot_van_krevelen_individual = true

enviroMS/LC_FTICR_workflow.py

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import matplotlib.pyplot as plt
55
import matplotlib.patches as patches
66
sns.set_context('talk')
7-
import os
7+
import os
88
import numpy as np
9-
from tqdm import tqdm
9+
from tqdm import tqdm
1010
from dataclasses import dataclass
1111
import toml
1212

@@ -26,10 +26,11 @@ class LC_FTICR_WorkflowParameters:
2626
end_time: int # minutes
2727
time_block: int #seconds
2828
# removed original values (check if I should do that)
29-
# Reference mass list:
29+
# Reference mass list:
3030
refmasslist_neg: str = "data/referencec/Hawkes_neg.ref"
3131
# input output paths
32-
input_file_path: str = "data/raw_data/..."
32+
full_input_file_path: str = "data/raw_data/..."
33+
input_file_directory: str = "data/raw_data/..."
3334
input_file_name: str = "..."
3435
output_directory: str = "data/..."
3536
output_file_name: str = "..."
@@ -50,19 +51,20 @@ def to_toml(self):
5051

5152

5253
### function that init parser and get data
53-
def init_parser_extract_data(self) -> pd.DataFrame:
54+
def init_parser_extract_data(self) -> pd.DataFrame:
5455
# Define datafile location
55-
file_in = self.input_file_path + self.input_file_name
56+
file_in = self.full_input_file_path
5657

5758
# Start with all scans
58-
LCMSParameters.lc_ms.scans = (-1, -1) # this needs to be read in
59+
LCMSParameters.lc_ms.scans = (-1, -1) # this needs to be read in
5960
# the (-1, -1) tells software to choose all scans that exist
6061

6162
# Init parser object
63+
print(file_in)
6264
parser = ImportMassSpectraThermoMSFileReader(file_in)
63-
65+
6466
# Get the TIC data, scan ids, etc
65-
# TIC = Total Ion Chromatogram
67+
# TIC = Total Ion Chromatogram
6668
tic_data = parser.get_tic(ms_type=None, peak_detection=False, smooth=False, plot=False, trace_type='TIC')[0]
6769
tic_df = pd.DataFrame(index=tic_data.scans, columns=['scans', 'tic', 'time'])
6870
tic_df['scans'] = tic_data.scans
@@ -76,23 +78,23 @@ def init_parser_extract_data(self) -> pd.DataFrame:
7678
# Process the time block mass spectrum
7779
def proc_time_block_inner(self, msreader, datafile, block):
7880
# scans = list(subset_df['scan'])
79-
81+
8082
# load_and_set_toml_parameters_ms(MSParameters, self.corems_toml_path)
8183
with open(self.ms_toml_path, "r") as infile:
8284
MSParameters.mass_spectrum = MassSpectrumSetting(**toml.load(infile))
8385
with open(self.mspeak_toml_path, "r") as infile:
8486
MSParameters.ms_peak = MassSpecPeakSetting(**toml.load(infile))
8587
msobj = msreader.get_average_mass_spectrum(spectrum_mode = 'profile',auto_process=True)
86-
88+
8789
#msobj.clear_molecular_formulas()
8890
MzDomainCalibration(msobj, self.refmasslist_neg).run()
8991

9092
#set_mf_settings(msobj)
9193
load_and_set_toml_parameters_class("MolecularFormulaSearch", msobj.molecular_search_settings, parameters_path=self.mfsearch_toml_path)
9294

9395
SearchMolecularFormulas(msobj).run_worker_mass_spectrum()
94-
95-
96+
97+
9698
msdf = msobj.to_dataframe()
9799
msdf['datafile'] = datafile
98100
msdf['block'] = block
@@ -116,7 +118,7 @@ def proc_time_block_inner(self, msreader, datafile, block):
116118

117119
def process_with_time_block(self, tic_df):
118120
# Strip out the time where there's no useful data
119-
file_in = self.input_file_path + self.input_file_name
121+
file_in = self.full_input_file_path
120122
tic_df = tic_df[(tic_df['time'] > self.start_time) & (tic_df['time'] < self.end_time)]
121123

122124
# Block the scans into 30-second blocks, for signal averaging.
@@ -138,7 +140,7 @@ def process_with_time_block(self, tic_df):
138140
LCMSParameters.lc_ms.scans = (scan_tuple)
139141
# Init parser object
140142
parser = ImportMassSpectraThermoMSFileReader(file_in)
141-
143+
142144
msdf, statdict = self.proc_time_block_inner(parser, file_in, block) ### i'm not sure about this self.function()
143145
all_msdfs_in_file.append(msdf)
144146
all_statdics.append(statdict)
@@ -155,7 +157,7 @@ def create_summary(self, all_statdics):
155157
# Create a DataFrame
156158
summary_df = pd.DataFrame(flat_list)
157159
summary_df.to_csv(self.output_directory + self.output_file_name +"-statdicts.csv")
158-
return(summary_df)
160+
return(summary_df)
159161

160162

161163
################################### LC-FTICR PLOTS ###################################
@@ -164,22 +166,22 @@ def create_summary(self, all_statdics):
164166
## for creating plots
165167
def filter_out_common_background(df):
166168
formula_block_counts = df.pivot_table(index='Molecular Formula', columns='block', aggfunc='size', fill_value=0)
167-
169+
168170
# Filter to get 'Molecular Formula' entries that appear in all blocks
169171
common_formulas = formula_block_counts[formula_block_counts.gt(0).sum(axis=1) == len(df['block'].unique())].index
170-
172+
171173
# Step 2: Further filter based on similar 'Peak Height' values (using a threshold)
172174
# Create a function to check if 'Peak Height' values are within a tolerance
173175
def peak_height_similar(df, tolerance=0.99): # 10% tolerance
174176
peak_heights = df['Peak Height']
175177
return peak_heights.max() - peak_heights.min() <= tolerance * peak_heights.mean()
176-
178+
177179
# Group the dataframe by 'Molecular Formula' and apply the peak height similarity check
178180
similar_peak_height_formulas = df.groupby('Molecular Formula').filter(lambda x: peak_height_similar(x))['Molecular Formula'].unique()
179-
181+
180182
# Combine both conditions
181183
formulas_to_remove = set(common_formulas).intersection(similar_peak_height_formulas)
182-
184+
183185
# Step 3: Remove these entries from the dataframe
184186
filtered_df = df[~df['Molecular Formula'].isin(formulas_to_remove)]
185187
return filtered_df
@@ -271,7 +273,7 @@ def plot_properties(summary_df_path,output_dir):
271273
axes[i, 0].set_title(f'Trend of {prop} by Block')
272274
axes[i, 0].set_xlabel('Block')
273275
axes[i, 0].set_ylabel(prop)
274-
276+
275277
# Distribution plot
276278
sns.histplot(summary_df[prop], kde=True, ax=axes[i, 1], bins=10, color='skyblue')
277279
axes[i, 1].set_title(f'Distribution of {prop}')
@@ -301,9 +303,43 @@ def run_LC_FTICR_workflow(lc_fticr_workflow_paramaters_toml_file):
301303
plot_properties(summary_df, lc_object.output_directory)
302304
return()
303305

304-
def run_LC_FTICR_workflow_wdl(*args, **kwargs):
305-
# read in LC_WorkflowParameters from toml file
306-
lc_object = LC_FTICR_WorkflowParameters(**kwargs)
306+
def run_LC_FTICR_workflow_wdl(
307+
start_time,
308+
end_time,
309+
time_block,
310+
refmasslist_neg,
311+
full_input_file_path,
312+
input_file_directory,
313+
input_file_name,
314+
output_directory,
315+
output_file_name,
316+
output_file_type,
317+
lc_fticr_toml_path,
318+
ms_toml_path,
319+
mspeak_toml_path,
320+
mfsearch_toml_path,
321+
plot_van_krevelen_all_ids,
322+
plot_van_krevelen_individual,
323+
plot_properties,
324+
):
325+
# read in LC_WorkflowParameters from wdl inputs
326+
lc_object = LC_FTICR_WorkflowParameters(start_time = start_time,
327+
end_time = end_time,
328+
time_block = time_block,
329+
refmasslist_neg = refmasslist_neg,
330+
full_input_file_path = full_input_file_path,
331+
input_file_directory = input_file_directory,
332+
input_file_name = input_file_name,
333+
output_directory = output_directory,
334+
output_file_name = output_file_name,
335+
output_file_type = output_file_type,
336+
lc_fticr_toml_path = lc_fticr_toml_path,
337+
ms_toml_path = ms_toml_path,
338+
mspeak_toml_path = mspeak_toml_path,
339+
mfsearch_toml_path = mfsearch_toml_path,
340+
plot_van_krevelen_all_ids = plot_van_krevelen_all_ids,
341+
plot_van_krevelen_individual = plot_van_krevelen_individual,
342+
plot_properties = plot_properties)
307343
# call functions
308344
tic_df = lc_object.init_parser_extract_data()
309345
all_msdfs_df, all_statdics_df = lc_object.process_with_time_block(tic_df)

0 commit comments

Comments
 (0)