Skip to content

Commit

Permalink
Merge pull request #138 from compomics/ms2pip-fgen-improvements
Browse files Browse the repository at this point in the history
Various minor improvements
  • Loading branch information
RalfG authored Apr 7, 2024
2 parents 4f1ff2e + 77f3f0b commit 1fe9d9e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ms2rescore/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 5 additions & 0 deletions ms2rescore/feature_generators/ms2pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
26 changes: 25 additions & 1 deletion ms2rescore/report/charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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.
Expand All @@ -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"]

Expand Down
5 changes: 5 additions & 0 deletions ms2rescore/report/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand Down
7 changes: 2 additions & 5 deletions ms2rescore/report/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

0 comments on commit 1fe9d9e

Please sign in to comment.