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

Use geometric mean to calculate peptide score #280

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Changed

- Instead of having to specify `train_from_scratch` in the config file, training will proceed from an existing model weights file if this is given as an argument to `casanovo train`.
- Use geometric mean instead of arithmetic mean to calculate peptide score.

## [4.0.0] - 2023-12-22

Expand Down
10 changes: 7 additions & 3 deletions casanovo/denovo/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import depthcharge.masses
import einops
import scipy.stats.mstats
import torch
import numpy as np
import lightning.pytorch as pl
Expand Down Expand Up @@ -1032,8 +1033,11 @@ def _aa_pep_score(
Calculate amino acid and peptide-level confidence score from the raw amino
acid scores.

The peptide score is the mean of the raw amino acid scores. The amino acid
scores are the mean of the raw amino acid scores and the peptide score.
The peptide score is the geometric mean of the raw amino acid scores.
Peptide scores that don't fit the precursor m/z tolerance are penalized by
subtracting 1.
The amino acid scores are the arithmetic mean of the raw amino acid scores
and the peptide score.

Parameters
----------
Expand All @@ -1049,7 +1053,7 @@ def _aa_pep_score(
peptide_score : float
The peptide score.
"""
peptide_score = np.mean(aa_scores)
peptide_score = scipy.stats.mstats.gmean(aa_scores)
aa_scores = (aa_scores + peptide_score) / 2
if not fits_precursor_mz:
peptide_score -= 1
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies = [
"requests",
"rich-click>=1.6.1",
"scikit-learn",
"scipy",
"spectrum_utils",
"tensorboard",
"torch>=2.1",
Expand Down
Loading