Create Ascore.py#1
Conversation
WalkthroughA new file, Ascore.py, has been added to implement the AScore algorithm for phosphorylation site localization in peptides using MS/MS spectra. The file introduces the Changes
Sequence Diagram(s)sequenceDiagram
participant C as Client
participant A as AScore
C->>A: compute(hit, real_spectrum)
A->>A: Validate input & identify phosphorylation sites
A->>A: Count phospho events and generate site permutations
A->>A: Create theoretical spectra and pick spectral peaks
A->>A: Calculate and rank permutation scores
A->>A: Format results into ProForma string
A-->>C: Return modified PeptideHit with AScore values and metadata
Poem
Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||||
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (6)
Ascore.py (6)
1-1: Avoid wildcard imports for maintainability.Wildcard imports (
from pyopenms import *) make it unclear which symbols are actually used and can lead to name collisions or confusion around undefined names. Consider importing only the specific classes and functions needed (e.g.,from pyopenms import AASequence, MSSpectrum, TheoreticalSpectrumGenerator, PeptideHit).-from pyopenms import * +from pyopenms import AASequence, MSSpectrum, TheoreticalSpectrumGenerator, PeptideHit🧰 Tools
🪛 Ruff (0.8.2)
1-1:
from pyopenms import *used; unable to detect undefined names(F403)
3-3: Remove unused importnumpy.The import statement for
numpyis never referenced in this file. Consider removing it to keep the code clean.-import numpy as np🧰 Tools
🪛 Ruff (0.8.2)
3-3:
numpyimported but unusedRemove unused import:
numpy(F401)
4-4: Remove unused importdefaultdict.
collections.defaultdictis not referenced anywhere in this file. Consider removing it.-from collections import defaultdict🧰 Tools
🪛 Ruff (0.8.2)
4-4:
collections.defaultdictimported but unusedRemove unused import:
collections.defaultdict(F401)
78-79: Use logging instead of print statements for debug and warnings.Multiple debugging and warning prints are scattered throughout the code. Using the
loggingmodule allows for flexible log levels, better formatting, and easier maintenance.-print(f"Debug: Found {regular_phospho_count} regular phosphorylation events ...") -... -print("Warning: PhosphoDecoy sites found in sequence ...") -... -print(f"Debug: Calculation aborted: peptide too long: {seq_without_phospho.toString()}") -... -print("Debug: Calculation aborted: number of permutations exceeded ...") +import logging +logger = logging.getLogger(__name__) +... +logger.debug(f"Found {regular_phospho_count} regular phosphorylation events ...") +... +logger.warning("PhosphoDecoy sites found in sequence ...") +... +logger.debug(f"Calculation aborted: peptide too long: {seq_without_phospho.toString()}") +... +logger.debug("Calculation aborted: number of permutations exceeded ...")Also applies to: 93-99, 103-104, 146-147
135-137: Rename unused loop variablesite.In this loop,
siteis never referenced within the body. Consider renaming it to_siteor removing it entirely to avoid confusion.-for i, site in enumerate(sites): +for i, _site in enumerate(sites): phospho.setMetaValue(f"AScore_{i+1}", self.unambiguous_score_)🧰 Tools
🪛 Ruff (0.8.2)
135-135: Loop control variable
sitenot used within loop body(B007)
181-181: Rename unused loop variablescore.The loop extracts
(score, idx)but never usesscore. Consider renaming it to_scorefor clarity.-for i, (score, idx) in enumerate(best_permutations): +for i, (_score, idx) in enumerate(best_permutations):🧰 Tools
🪛 Ruff (0.8.2)
181-181: Loop control variable
scorenot used within loop bodyRename unused
scoreto_score(B007)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
Ascore.py(1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
Ascore.py
1-1: from pyopenms import * used; unable to detect undefined names
(F403)
3-3: numpy imported but unused
Remove unused import: numpy
(F401)
4-4: collections.defaultdict imported but unused
Remove unused import: collections.defaultdict
(F401)
31-31: TheoreticalSpectrumGenerator may be undefined, or defined from star imports
(F405)
71-71: PeptideHit may be undefined, or defined from star imports
(F405)
135-135: Loop control variable site not used within loop body
(B007)
181-181: Loop control variable score not used within loop body
Rename unused score to _score
(B007)
191-191: AASequence may be undefined, or defined from star imports
(F405)
409-409: MSSpectrum may be undefined, or defined from star imports
(F405)
409-409: MSSpectrum may be undefined, or defined from star imports
(F405)
415-415: MSSpectrum may be undefined, or defined from star imports
(F405)
419-419: MSSpectrum may be undefined, or defined from star imports
(F405)
482-482: MSSpectrum may be undefined, or defined from star imports
(F405)
485-485: MSSpectrum may be undefined, or defined from star imports
(F405)
775-775: AASequence may be undefined, or defined from star imports
(F405)
802-802: MSSpectrum may be undefined, or defined from star imports
(F405)
808-808: AASequence may be undefined, or defined from star imports
(F405)
862-862: MSSpectrum may be undefined, or defined from star imports
(F405)
868-868: MSSpectrum may be undefined, or defined from star imports
(F405)
Create Ascore.py
Create Ascore.py
…s_decoy/protein restore, score-recovery, extensionless idparquet, debug logger order #6 (CRITICAL) lucxor/cli.py: when posterior_error_probability is NaN for all rows, fall back to df's score_type/higher_score_better and use row['score'] instead of NaN for hit.setScore(); skip 'Posterior Error Probability' metavalue. #5 (Major) idparquet.py save_psms_from_scratch: bool columns (is_decoy, higher_score_better) now filled with False before astype(bool) to prevent NaN→True coercion. Uses map-based approach to avoid pandas FutureWarning. #4 (Major) id_io.py _psms_df_to_peptide_ids: restore is_decoy as target_decoy metavalue and rebuild PeptideEvidence objects from protein_accessions dicts on the save path. Also register all referenced protein accessions as ProteinHit entries in ProteinIdentification (required by idXML format). #3 (Major) id_io.py score-recovery: removed the fallback loop scanning arbitrary numeric metavalues. Only the score_type-named metavalue lookup is kept. Save path now explicitly stores score under score_type name as a metavalue to enable recovery after mzIdentML round-trip (where score_type is renamed). Updated two pre-existing mzid score tests accordingly. #2 (Major) id_io.py save_identifications: wrap detect_format() in try/except; on ValueError with no file extension, treat as idparquet. load side unchanged. #1 (Major) ascore/cli.py: moved logger = log_debug(...) above load_spectra() and load_identifications() calls so the except block can reference logger when either load raises. Tests: 82 passed (test_id_io.py +7 new tests, test_lucxor/ascore/phosphors all green)
…lidation Fix/phosphors fragment charge validation
PR Type
Enhancement
Description
Implemented the
AScoreclass for phosphorylation site localization.Added methods for computing AScore, handling permutations, and generating theoretical spectra.
Integrated support for decoy phosphorylation sites and ProForma string generation.
Included detailed debugging and error handling for edge cases.
Changes walkthrough 📝
Ascore.py
Implement AScore algorithm for phosphorylation analysisAscore.py
AScoreclass for phosphorylation site localization.Summary by CodeRabbit