Skip to content

Commit

Permalink
Remove extra atlas return in rt_alignment run() function
Browse files Browse the repository at this point in the history
  • Loading branch information
bkieft-usa committed Feb 7, 2025
2 parents f03bcae + 7436448 commit 64e5dbb
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 27 deletions.
4 changes: 2 additions & 2 deletions metatlas/datastructures/metatlas_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ class MetatlasDataset(HasTraits):
keep_nonmatches: bool = Bool(default_value=True)
ids: analysis_ids.AnalysisIdentifiers = Instance(klass=analysis_ids.AnalysisIdentifiers)
atlas: metob.Atlas = Instance(klass=metob.Atlas)
rt_min_delta = Int(allow_none=True, default_value=None)
rt_max_delta = Int(allow_none=True, default_value=None)
rt_min_delta = Float(allow_none=True, default_value=None)
rt_max_delta = Float(allow_none=True, default_value=None)
_atlas_df: Optional[pd.DataFrame] = Instance(klass=pd.DataFrame, allow_none=True, default_value=None)
# _all_data contanis all data in experiement before any filtering
_all_data: Optional[SampleSet] = traitlets.Tuple(allow_none=True, default_value=None)
Expand Down
2 changes: 1 addition & 1 deletion metatlas/datastructures/metatlas_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def clone(self, recursive=False):
obj: MetatlasObject
Cloned object.
"""
#logger.debug('Cloning instance of %s with recursive=%s', self.__class__.__name__, recursive)
logger.debug('Cloning instance of %s with recursive=%s', self.__class__.__name__, recursive)
obj = self.__class__()
for (tname, trait) in self.traits().items():
if tname.startswith('_') or trait.metadata.get('readonly', False):
Expand Down
40 changes: 25 additions & 15 deletions metatlas/plots/dill2plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ class adjust_rt_for_selected_compound(object):
def __init__(self,
data,
msms_sorting_method=None,
msms_radio_buttons=None,
include_lcmsruns=None,
exclude_lcmsruns=None,
include_groups=None,
Expand Down Expand Up @@ -308,6 +309,7 @@ def __init__(self,
logger.debug("Initializing new instance of %s.", self.__class__.__name__)
self.data = data
self.msms_hits, _ = sp.sort_msms_hits(msms_hits, sorting_method=msms_sorting_method)
self.msms_radio_buttons = msms_radio_buttons
self.color_me = or_default(color_me, [('black', '')])
self.compound_idx = compound_idx
self.width = width
Expand Down Expand Up @@ -509,24 +511,32 @@ def display_eic_data(self):
picker=True, pickradius=5, color=color, label=label)

def configure_flags(self):
default_peak = ['keep',
'remove',
'keep, unresolvable isomers',
'keep, poor peak shape']

default_msms = ['no selection',
if self.msms_radio_buttons is None or self.msms_radio_buttons == 'new':
default_peak = ['keep','remove','keep, unresolvable isomers','keep, poor peak shape']

'-1.0, poor match, should remove',
'0.0, no match or no MSMS collected',
'0.5, partial or putative match of fragments',
'1.0, good match',

'0.5, co-isolated precursor, partial match',
'1.0, co-isolated precursor, good match',
default_msms = ['no selection',
'-1.0, poor match, should remove',
'0.0, no match or no MSMS collected',
'0.5, partial or putative match of fragments',
'1.0, good match',
'0.5, co-isolated precursor, partial match',
'1.0, co-isolated precursor, good match',
'0.5, single ion match, no evidence',
'1.0, single ion match, ISTD/ref evidence']
elif self.msms_radio_buttons == 'old':
default_peak = ['keep','remove','unresolvable isomers','poor peak shape']

'0.5, single ion match, no evidence',
'1.0, single ion match, ISTD/ref evidence']

default_msms = ['no selection',
'-1, bad match - should remove compound',
'0, no ref match available or no MSMS collected',
'0.5, partial match of fragments',
'1, perfect match to internal reference library',
'1, perfect match to external reference library',
'1, co-isolated precursor but all reference ions are in sample spectrum']
else:
logger.warning('Unknown value for msms_radio_buttons: %s. Must use "old" or "new" or remove.', self.msms_radio_buttons)

if self.peak_flags is None or self.peak_flags == '':
self.peak_flags = default_peak
if self.msms_flags is None or self.msms_flags == '':
Expand Down
2 changes: 2 additions & 0 deletions metatlas/targeted/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def annotation_gui(
peak_flags=None,
msms_flags=None,
msms_sorting_method: str = None,
msms_radio_buttons: str = None,
) -> Optional[dp.adjust_rt_for_selected_compound]:
"""
Opens the interactive GUI for setting RT bounds and annotating peaks
Expand All @@ -96,6 +97,7 @@ def annotation_gui(
return dp.adjust_rt_for_selected_compound(
data,
msms_sorting_method=msms_sorting_method,
msms_radio_buttons=msms_radio_buttons,
msms_hits=data.hits,
color_me=colors,
compound_idx=compound_idx,
Expand Down
11 changes: 6 additions & 5 deletions metatlas/targeted/rt_alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def generate_rt_alignment_models(
Returns a tuple with linear, polynomial and offset models
"""
params = workflow.rt_alignment.parameters
logger.info("Generating RT alignment models with QC atlas %s and RT expansion of %s and %s", workflow.rt_alignment.atlas.name, params.rt_min_delta, params.rt_max_delta)
rts_df = get_rts(data)
actual, pred = subset_data_for_model_input(
params.dependent_data_source, rts_df, data.atlas_df, params.inchi_keys_not_in_model
Expand Down Expand Up @@ -447,7 +448,7 @@ def write_notebooks(
before processing of the config file
Returns a list of Paths to notebooks
"""
parameters_not_to_forward = ["rt_min_delta", "rt_max_delta"]
parameters_not_to_forward = []
out = []
for atlas, analysis in zip(atlases, workflow.analyses):
source = repo_path() / "notebooks" / "reference" / "Targeted.ipynb"
Expand All @@ -474,7 +475,7 @@ def run(
configuration: Config,
workflow: Workflow,
set_parameters: dict,
) -> tuple[MetatlasDataset, list]:
) -> MetatlasDataset:
"""Generates RT alignment model, applies to atlases, and generates all outputs"""
params = workflow.rt_alignment.parameters
ids = AnalysisIdentifiers(
Expand All @@ -488,6 +489,6 @@ def run(
)
shutil.copy2(params.config_file_name, ids.output_dir)
ids.set_output_state(params, "rt_alignment")
metatlas_dataset = MetatlasDataset(ids=ids, max_cpus=params.max_cpus)
atlases = generate_outputs(metatlas_dataset, workflow, set_parameters)
return metatlas_dataset, atlases
metatlas_dataset = MetatlasDataset(ids=ids, max_cpus=params.max_cpus, rt_min_delta=params.rt_min_delta, rt_max_delta=params.rt_max_delta)
generate_outputs(metatlas_dataset, workflow, set_parameters)
return metatlas_dataset
6 changes: 3 additions & 3 deletions metatlas/tools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ class BaseNotebookParameters(BaseModel):
include_lcmsruns: OutputLists = OutputLists()
exclude_lcmsruns: OutputLists = OutputLists()
groups_controlled_vocab: List[str] = []
rt_min_delta: Optional[float] = None
rt_max_delta: Optional[float] = None
mz_tolerance_default: float = 10 # units of ppm
mz_tolerance_override: Optional[float] = None # units of ppm
frag_mz_tolerance: Optional[float] = 0.02 # units of Daltons
Expand Down Expand Up @@ -120,6 +118,7 @@ class AnalysisNotebookParameters(BaseNotebookParameters):
slurm_execute: bool = False
clear_cache: bool = False
msms_sorting_method: Optional[str] = None
msms_radio_buttons: Optional[str] = None
# these are populated from the workflow's RTAlignment if None
google_folder: Optional[str] = None
msms_refs: Optional[Path] = None
Expand All @@ -135,7 +134,8 @@ class RTAlignmentNotebookParameters(BaseNotebookParameters):
stop_before: Optional[str] = None
google_folder: str
msms_refs: Path

rt_min_delta: Optional[float] = None
rt_max_delta: Optional[float] = None

class Atlas(BaseModel):
"""Atlas specification"""
Expand Down
11 changes: 10 additions & 1 deletion notebooks/reference/Targeted.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@
"# If True, then include MSMS fragment ions in the output documents\n",
"export_msms_fragment_ions = None\n",
"\n",
"# One of 'old', 'new', or None. If 'old', use the old version of the\n",
"# MSMS (and MS) radio button selections in the GUI. If 'new' or None, use the \n",
"# new version of the MSMS (and MS) radio button selections in the GUI.\n",
"msms_radio_buttons = None\n",
"\n",
"# Setting this to True will remove the cache of MSMS hits\n",
"# if you don't see MSMS data for any of your compounds in RT adjuster GUI,\n",
"# then you might want to try settings this to True. However, it will\n",
Expand Down Expand Up @@ -318,7 +323,11 @@
"metadata": {},
"outputs": [],
"source": [
"agui = annotation_gui(data=metatlas_dataset, compound_idx=0, width=15, height=3, colors=analysis.parameters.line_colors, msms_sorting_method=analysis.parameters.msms_sorting_method)"
"agui = annotation_gui(data=metatlas_dataset, \n",
" compound_idx=0, width=15, height=3, \n",
" colors=analysis.parameters.line_colors, \n",
" msms_sorting_method=analysis.parameters.msms_sorting_method, \n",
" msms_radio_buttons=analysis.parameters.msms_radio_buttons)"
]
},
{
Expand Down

0 comments on commit 64e5dbb

Please sign in to comment.