Skip to content

Commit

Permalink
Merge pull request #885 from biorack/fix_filter_polarity
Browse files Browse the repository at this point in the history
fix: correctly pass polarity per analysis
  • Loading branch information
tharwood3 authored Jul 16, 2024
2 parents b636a13 + b307b7b commit d29ee5c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions metatlas/tools/atlas_prefilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import metatlas.plots.dill2plots as dp
from metatlas.datastructures.analysis_identifiers import AnalysisIdentifiers
from metatlas.datastructures.metatlas_dataset import MetatlasDataset
from metatlas.tools.config import Analysis
from metatlas.tools.notebook import in_papermill

# Typing:
Expand Down Expand Up @@ -119,8 +120,8 @@ def score_ms2_data(ms2_data: pd.DataFrame, aligned_atlas_df: pd.DataFrame,

ms2_data_refs_merge['ref_frags'] = ms2_data_refs_merge['spectrum_y'].apply(lambda x: len(x[0]) if x.any() else 0)
ms2_data_refs_merge['data_frags'] = ms2_data_refs_merge['spectrum_x'].apply(lambda x: len(x[0]) if x.any() else 0)
ms2_data_refs_merge['reference_data_ratio'] = ms2_data_refs_merge['ref_frags']/ms2_data_refs_merge['data_frags']
ms2_data_refs_merge['match_reference_ratio'] = ms2_data_refs_merge['matches']/ms2_data_refs_merge['ref_frags']
ms2_data_refs_merge['reference_data_ratio'] = ms2_data_refs_merge['ref_frags'] / ms2_data_refs_merge['data_frags']
ms2_data_refs_merge['match_reference_ratio'] = ms2_data_refs_merge['matches'] / ms2_data_refs_merge['ref_frags']

ms2_data_refs_merge = ms2_data_refs_merge.drop(['ref_frags', 'data_frags'], axis=1)

Expand Down Expand Up @@ -148,7 +149,7 @@ def filter_atlas_labels(ms1_data: pd.DataFrame, ms2_data_scored: pd.DataFrame, p
return reduced_labels


def filter_atlas(aligned_atlas, ids: AnalysisIdentifiers, analysis, data: MetatlasDataset):
def filter_atlas(aligned_atlas, ids: AnalysisIdentifiers, analysis: Analysis, data: MetatlasDataset):

aligned_atlas_df = make_atlas_df(aligned_atlas)
sample_file_paths = get_sample_file_paths(ids)
Expand All @@ -158,14 +159,14 @@ def filter_atlas(aligned_atlas, ids: AnalysisIdentifiers, analysis, data: Metatl
else:
mz_tolerance = analysis.parameters.mz_tolerance_default

ms1_data, ms2_data = get_sample_data(aligned_atlas_df, sample_file_paths, mz_tolerance, data.extra_time, ids.polarity)
ms2_data_scored = score_ms2_data(ms2_data, aligned_atlas_df, ids.polarity,
ms1_data, ms2_data = get_sample_data(aligned_atlas_df, sample_file_paths, mz_tolerance, data.extra_time, analysis.parameters.polarity)
ms2_data_scored = score_ms2_data(ms2_data, aligned_atlas_df, analysis.parameters.polarity,
analysis.parameters.msms_refs, analysis.parameters.frag_mz_tolerance)

reduced_labels = filter_atlas_labels(ms1_data, ms2_data_scored, analysis.parameters.peak_height, analysis.parameters.num_points,
analysis.parameters.msms_score, analysis.parameters.msms_matches, analysis.parameters.msms_frag_ratio)

aligned_filtered_atlas_df = aligned_atlas_df[aligned_atlas_df['label'].isin(reduced_labels)]
aligned_filtered_atlas = dp.get_atlas(aligned_atlas.name, aligned_filtered_atlas_df, ids.polarity, mz_tolerance)
aligned_filtered_atlas = dp.get_atlas(aligned_atlas.name, aligned_filtered_atlas_df, analysis.parameters.polarity, mz_tolerance)

return aligned_filtered_atlas

0 comments on commit d29ee5c

Please sign in to comment.