Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly pass polarity per analysis #885

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading