diff --git a/ms2rescore/core.py b/ms2rescore/core.py index 725a1d58..d1dfe405 100644 --- a/ms2rescore/core.py +++ b/ms2rescore/core.py @@ -157,7 +157,7 @@ def rescore(configuration: Dict, psm_list: Optional[PSMList] = None) -> None: output_file_root, psm_list=psm_list, feature_names=feature_names, use_txt_log=True ) except exceptions.ReportGenerationError as e: - logger.error(e) + logger.exception(e) def _write_feature_names(feature_names, output_file_root): diff --git a/ms2rescore/feature_generators/ms2pip.py b/ms2rescore/feature_generators/ms2pip.py index 89603237..243bd794 100644 --- a/ms2rescore/feature_generators/ms2pip.py +++ b/ms2rescore/feature_generators/ms2pip.py @@ -53,6 +53,7 @@ def __init__( ms2_tolerance: float = 0.02, spectrum_path: Optional[str] = None, spectrum_id_pattern: str = "(.*)", + model_dir: Optional[str] = None, processes: 1, **kwargs, ) -> None: @@ -71,6 +72,8 @@ def __init__( spectrum_id_pattern : str, optional Regular expression pattern to extract spectrum ID from spectrum file. Defaults to :py:const:`.*`. + model_dir + Directory containing MS²PIP models. Defaults to :py:const:`None` (use MS²PIP default). processes : int, optional Number of processes to use. Defaults to 1. @@ -85,6 +88,7 @@ def __init__( self.ms2_tolerance = ms2_tolerance self.spectrum_path = spectrum_path self.spectrum_id_pattern = spectrum_id_pattern + self.model_dir = model_dir self.processes = processes @property @@ -194,6 +198,7 @@ def add_features(self, psm_list: PSMList) -> None: model=self.model, ms2_tolerance=self.ms2_tolerance, compute_correlations=False, + model_dir=self.model_dir, processes=self.processes, ) except NoMatchingSpectraFound as e: diff --git a/ms2rescore/report/charts.py b/ms2rescore/report/charts.py index e601d826..48d543a7 100644 --- a/ms2rescore/report/charts.py +++ b/ms2rescore/report/charts.py @@ -214,6 +214,14 @@ def score_scatter_plot( Column with index for each PSM, peptide, or protein to use for merging data frames. """ + if not before or not after: + figure = go.Figure() + figure.add_annotation( + text="No data available for comparison.", + showarrow=False, + ) + return figure + # Restructure data merge_columns = [indexer, "mokapot score", "mokapot q-value", "mokapot PEP"] ce_psms_targets = pd.merge( @@ -288,6 +296,14 @@ def fdr_plot_comparison( Column with index for each PSM, peptide, or protein to use for merging dataframes. """ + if not before or not after: + figure = go.Figure() + figure.add_annotation( + text="No data available for comparison.", + showarrow=False, + ) + return figure + # Prepare data ce_psms_targets_melted = ( pd.merge( @@ -336,7 +352,7 @@ def fdr_plot_comparison( def identification_overlap( before: mokapot.LinearConfidence, after: mokapot.LinearConfidence, -) -> go.Figure(): +) -> go.Figure: """ Plot stacked bar charts of removed, retained, and gained PSMs, peptides, and proteins. @@ -348,6 +364,14 @@ def identification_overlap( Mokapot linear confidence results after rescoring. """ + if not before or not after: + figure = go.Figure() + figure.add_annotation( + text="No data available for comparison.", + showarrow=False, + ) + return figure + levels = before.levels # ["psms", "peptides", "proteins"] if all available indexers = ["index", "index", "mokapot protein group"] diff --git a/ms2rescore/report/generate.py b/ms2rescore/report/generate.py index 090db873..cc4b8aa9 100644 --- a/ms2rescore/report/generate.py +++ b/ms2rescore/report/generate.py @@ -164,6 +164,11 @@ def _get_stats_context(confidence_before, confidence_after): levels = ["psms", "peptides", "proteins"] level_names = ["PSMs", "Peptides", "Protein groups"] card_colors = ["card-bg-blue", "card-bg-green", "card-bg-red"] + + # Cannot report stats if confidence estimates are not present + if not confidence_before or not confidence_after: + return stats + for level, level_name, card_color in zip(levels, level_names, card_colors): try: before = confidence_before.accepted[level.lower()] diff --git a/ms2rescore/report/utils.py b/ms2rescore/report/utils.py index e8568e59..272bdb8b 100644 --- a/ms2rescore/report/utils.py +++ b/ms2rescore/report/utils.py @@ -80,10 +80,7 @@ def get_confidence_estimates( try: confidence[when] = lin_psm_dataset.assign_confidence() - except RuntimeError as e: - raise ReportGenerationError( - f"Error while assigning confidence estimates to PSMs ({when} rescoring). " - "Could not generate report." - ) from e + except RuntimeError: + confidence[when] = None return confidence["before"], confidence["after"]