Skip to content

Commit

Permalink
FIX smaller bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgWa committed Oct 24, 2023
1 parent 8d837d5 commit 83a29b1
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
21 changes: 19 additions & 2 deletions alphadia/data/thermo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# native imports
import math
import os
import logging
logger = logging.getLogger()

# alphadia imports
from alphadia import utils
Expand Down Expand Up @@ -114,6 +116,7 @@ def __init__(
self,
path,
astral_ms1=False,
cv=None,
**kwargs
):
super().__init__(**kwargs)
Expand All @@ -122,6 +125,7 @@ def __init__(
self.sample_name = os.path.basename(self.raw_file_path)

self.astral_ms1 = astral_ms1
self.cv = cv
self.filter_spectra()

self.cycle = calculate_cycle(self.spectrum_df)
Expand All @@ -145,16 +149,29 @@ def __init__(
self.frame_max_index = len(self.rt_values)-1

def filter_spectra(self):

print(self.cv, 'cv' in self.spectrum_df.columns)

# filter for astral MS1
if self.astral_ms1:
self.spectrum_df = self.spectrum_df[self.spectrum_df['nce'] > 0.1]
self.spectrum_df.loc[self.spectrum_df['nce'] < 1.1, 'ms_level'] = 1
self.spectrum_df.loc[self.spectrum_df['nce'] < 1.1, 'precursor_mz'] = -1.0
self.spectrum_df.loc[self.spectrum_df['nce'] < 1.1, 'isolation_lower_mz'] = -1.0
self.spectrum_df.loc[self.spectrum_df['nce'] < 1.1, 'isolation_upper_mz'] = -1.0
self.spectrum_df['spec_idx'] = np.arange(len(self.spectrum_df))
else:
self.spectrum_df = self.spectrum_df[(self.spectrum_df['nce'] < 0.1) | (self.spectrum_df['nce'] > 1.1)]
self.spectrum_df['spec_idx'] = np.arange(len(self.spectrum_df))

# filter for cv
if self.cv is not None:
if 'cv' in self.spectrum_df.columns:
# use np.isclose to account for floating point errors
logger.info(f"Filtering for CV {self.cv}")
logger.info(f"Before: {len(self.spectrum_df)}")
self.spectrum_df = self.spectrum_df[np.isclose(self.spectrum_df['cv'], self.cv, atol=0.1)]
logger.info(f"After: {len(self.spectrum_df)}")

self.spectrum_df['spec_idx'] = np.arange(len(self.spectrum_df))

def jitclass(self):
return ThermoJIT(
Expand Down
2 changes: 1 addition & 1 deletion alphadia/hybridselection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1591,7 +1591,7 @@ def plot_candidates(
has_mobility = height_px > 2

if has_mobility:
fig_size = (max(width_px/500 * 8,5), height_px/500 * 5 )
fig_size = (max(width_px/500 * 8,5), height_px/100 * 5 )
gridspec_kw = {'height_ratios': [1,9]}
else:
fig_size = (max(width_px/500 * 8,5), 5)
Expand Down
9 changes: 9 additions & 0 deletions alphadia/libtransform.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,15 @@ def forward(self, input: SpecLibBase) -> SpecLibBase:
if len(input.precursor_df) == 0:
logger.warning(f'Input library has no precursor information. Skipping RT normalization')
return input

if 'rt' not in input.precursor_df.columns:
if 'rt_norm' in input.precursor_df.columns:
logger.warning(f'Input library already contains normalized RT information. Skipping RT normalization')
return input
else:
logger.warning(f'Input library has no RT information. Skipping RT normalization')
return input

percentiles = np.percentile(input.precursor_df['rt'], [0.1,99.9])
input._precursor_df['rt'] = np.clip(input._precursor_df['rt'], percentiles[0], percentiles[1])

Expand Down
4 changes: 4 additions & 0 deletions alphadia/planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ def run(self,
del workflow

except Exception as e:
# get full traceback
import traceback
traceback.print_exc()

print(e)
logger.error(f'Workflow failed for {raw_name} with error {e}')
continue
Expand Down
7 changes: 7 additions & 0 deletions alphadia/workflow/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,17 @@ def _get_dia_data_object(
)
elif file_extension == '.raw':
self.reporter.log_metric('raw_data_type', 'thermo')
# check if cv selection exists
cv = None
if 'raw_data_loading' in self.config:
if 'cv' in self.config['raw_data_loading']:
cv = self.config['raw_data_loading']['cv']

return thermo.Thermo(
dia_data_path,
astral_ms1= self.config['general']['astral_ms1'],
process_count = self.config['general']['thread_count'],
cv=cv,
)
else:
raise ValueError(f'Unknown file extension {file_extension} for file at {dia_data_path}')
Expand Down

0 comments on commit 83a29b1

Please sign in to comment.