From 5719cdcd4df55f113b55a4a656d27dee4372b2f0 Mon Sep 17 00:00:00 2001 From: Lilferrit Date: Wed, 18 Sep 2024 15:16:04 -0700 Subject: [PATCH] circular import bug --- casanovo/data/ms_io.py | 38 +----------------------------- casanovo/data/pep_spec_match.py | 41 +++++++++++++++++++++++++++++++++ casanovo/denovo/model.py | 4 ++-- casanovo/utils.py | 2 +- 4 files changed, 45 insertions(+), 40 deletions(-) create mode 100644 casanovo/data/pep_spec_match.py diff --git a/casanovo/data/ms_io.py b/casanovo/data/ms_io.py index 56d25cd1..a40515ee 100644 --- a/casanovo/data/ms_io.py +++ b/casanovo/data/ms_io.py @@ -13,43 +13,7 @@ from .. import __version__ from ..config import Config - - -@dataclasses.dataclass -class PepSpecMatch: - """ - Peptide Spectrum Match (PSM) dataclass - - Parameters - ---------- - sequence : str - The amino acid sequence of the peptide. - spectrum_id : Tuple[str, str] - A tuple containing the spectrum identifier in the form - (spectrum file name, spectrum file idx) - peptide_score : float - Score of the match between the full peptide sequence and the - spectrum. - charge : int - The precursor charge state of the peptide ion observed in the spectrum. - calc_mz : float - The calculated mass-to-charge ratio (m/z) of the peptide based on its - sequence and charge state. - exp_mz : float - The observed (experimental) precursor mass-to-charge ratio (m/z) of the - peptide as detected in the spectrum. - aa_scores : Iterable[float] - A list of scores for individual amino acids in the peptide - sequence, where len(aa_scores) == len(sequence) - """ - - sequence: str - spectrum_id: Tuple[str, str] - peptide_score: float - charge: int - calc_mz: float - exp_mz: float - aa_scores: Iterable[float] +from .pep_spec_match import PepSpecMatch class MztabWriter: diff --git a/casanovo/data/pep_spec_match.py b/casanovo/data/pep_spec_match.py new file mode 100644 index 00000000..0dc3c48b --- /dev/null +++ b/casanovo/data/pep_spec_match.py @@ -0,0 +1,41 @@ +"""Peptide spectrum match dataclass""" + +import dataclasses +from typing import Tuple, Iterable + + +@dataclasses.dataclass +class PepSpecMatch: + """ + Peptide Spectrum Match (PSM) dataclass + + Parameters + ---------- + sequence : str + The amino acid sequence of the peptide. + spectrum_id : Tuple[str, str] + A tuple containing the spectrum identifier in the form + (spectrum file name, spectrum file idx) + peptide_score : float + Score of the match between the full peptide sequence and the + spectrum. + charge : int + The precursor charge state of the peptide ion observed in the spectrum. + calc_mz : float + The calculated mass-to-charge ratio (m/z) of the peptide based on its + sequence and charge state. + exp_mz : float + The observed (experimental) precursor mass-to-charge ratio (m/z) of the + peptide as detected in the spectrum. + aa_scores : Iterable[float] + A list of scores for individual amino acids in the peptide + sequence, where len(aa_scores) == len(sequence) + """ + + sequence: str + spectrum_id: Tuple[str, str] + peptide_score: float + charge: int + calc_mz: float + exp_mz: float + aa_scores: Iterable[float] diff --git a/casanovo/denovo/model.py b/casanovo/denovo/model.py index 89bfaa48..020abbea 100644 --- a/casanovo/denovo/model.py +++ b/casanovo/denovo/model.py @@ -15,7 +15,7 @@ from . import evaluate from .. import config -from ..data import ms_io +from ..data import ms_io, pep_spec_match from ..denovo.transformers import SpectrumEncoder, PeptideDecoder logger = logging.getLogger("casanovo") @@ -1035,7 +1035,7 @@ def on_predict_batch_end( ) self.out_writer.psms.append( - ms_io.PepSpecMatch( + pep_spec_match.PepSpecMatch( sequence=peptide, spectrum_id=tuple(spectrum_i), peptide_score=peptide_score, diff --git a/casanovo/utils.py b/casanovo/utils.py index 1161b5eb..1646c5cc 100644 --- a/casanovo/utils.py +++ b/casanovo/utils.py @@ -15,7 +15,7 @@ import psutil import torch -from .data.ms_io import PepSpecMatch +from .data.pep_spec_match import PepSpecMatch SCORE_BINS = [0.0, 0.5, 0.9, 0.95, 0.99]