Conversation
Co-authored-by: poshul <146827+poshul@users.noreply.github.com>
Co-authored-by: poshul <146827+poshul@users.noreply.github.com>
Co-authored-by: poshul <146827+poshul@users.noreply.github.com>
Co-authored-by: poshul <146827+poshul@users.noreply.github.com>
Co-authored-by: poshul <146827+poshul@users.noreply.github.com>
Co-authored-by: poshul <146827+poshul@users.noreply.github.com>
Co-authored-by: timosachsenberg <5803621+timosachsenberg@users.noreply.github.com>
Adds human-readable string representations to pyOpenMS classes for better debugging and Jupyter notebook display. Implements __repr__ and __str__ for: - AASequence (sequence, length, mono_mass, modified) - PeptideHit (score, sequence, charge, num_evidences) - PeptideIdentification (rt, mz, score_type, num_hits, top_hit) - Feature (rt, mz, intensity, charge, quality, subordinates, peptide_ids) - IsotopeDistribution (num_isotopes, mass_range, most_abundant) - MRMFeature (rt, mz, intensity, charge, num_transitions) - MSSpectrum (ms_level, rt, num_peaks, mz_range, drift_time) - MSChromatogram (name, num_peaks, rt_range) - MSExperiment (num_spectra, num_chromatograms, ms_levels, rt_range) - ReactionMonitoringTransition (id, precursor_mz, product_mz, peptide_ref) - ConsensusFeature, EmpiricalFormula, Peak1D, Peak2D, MobilityPeak1D, ChromatogramPeak, ResidueModification, ProteinHit Also adds __len__ to PeptideIdentificationList for Pythonic interface. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
WalkthroughAdds Python string representations ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (7)
src/pyOpenMS/addons/MobilityPeak1D.pyx (1)
4-21: Align intensity type with other peak classes for consistency
intensityis currently declared asfloatwhile other peak-like wrappers (e.g.,ChromatogramPeak) usedoublefor intensity. This works but introduces unnecessary narrowing and inconsistency.Consider changing to:
- cdef double mobility = self.getMobility() - cdef float intensity = self.getIntensity() + cdef double mobility = self.getMobility() + cdef double intensity = self.getIntensity()This avoids any precision loss and keeps the representation consistent across peak types.
src/pyOpenMS/addons/AASequence.pyx (1)
28-60: Use!rfor sequence to avoid quoting/escaping issues and simplify truncationThe overall logic (truncation, mono mass formatting,
modifiedflag) looks good. The only fragile part is manually embedding the sequence inside single quotes, which can misbehave if the sequence string ever contains quotes or unusual characters.You can both simplify and harden this block by using a display variable plus
!r:- parts = [] - if seq_decoded: - # Truncate very long sequences - if len(seq_decoded) > 50: - parts.append(f"sequence='{seq_decoded[:47]}...'") - else: - parts.append(f"sequence='{seq_decoded}'") + parts = [] + if seq_decoded: + # Truncate very long sequences + if len(seq_decoded) > 50: + seq_display = seq_decoded[:47] + "..." + else: + seq_display = seq_decoded + parts.append(f"sequence={seq_display!r}")This avoids manual quoting/escaping and keeps the example representation unchanged for typical inputs. The same
!rpattern could be applied to other string/ID fields in this PR (e.g.,EmpiricalFormula.formula,ResidueModification.id/name) if you want fully robust string handling.src/pyOpenMS/addons/ResidueModification.pyx (1)
4-36: ResidueModification repr logic is solid; consider!rfor robust ID/name renderingThe selection of fields (id, non-redundant name, non-zero mass_diff, non-default origin) is well thought out and the guards around
originare safe.If you want to harden the string rendering against unusual characters in IDs/names, you could switch to
!rinstead of manual single quotes:- if mod_id_str: - parts.append(f"id='{mod_id_str}'") - if name_str and name_str != mod_id_str: - parts.append(f"name='{name_str}'") + if mod_id_str: + parts.append(f"id={mod_id_str!r}") + if name_str and name_str != mod_id_str: + parts.append(f"name={name_str!r}")Not required for correctness, but slightly more robust and consistent with Python repr conventions.
src/pyOpenMS/addons/ReactionMonitoringTransition.pyx (1)
4-36: Use!rfor string fields to avoid broken/ambiguous repr outputIf
native_idorpeptide_refcontain quotes or special characters, the current formatting (id='...') can produce misleading or syntactically broken representations. Using!rmakes the output more robust and closer to typical Python__repr__semantics.Suggested change:
- parts = [] - if native_id_str: - parts.append(f"id='{native_id_str}'") + parts = [] + if native_id_str: + parts.append(f"id={native_id_str!r}") parts.append(f"precursor_mz={precursor_mz:.4f}") parts.append(f"product_mz={product_mz:.4f}") - if peptide_ref_str: - parts.append(f"peptide_ref='{peptide_ref_str}'") + if peptide_ref_str: + parts.append(f"peptide_ref={peptide_ref_str!r}") if lib_intensity > 0: parts.append(f"library_intensity={lib_intensity:.1f}")src/pyOpenMS/addons/ProteinHit.pyx (1)
3-39: Escape string fields in ProteinHit repr using!rThe core logic (decoding, truncation, conditional coverage) looks good, but directly interpolating strings inside single quotes can yield confusing output if values contain
'or other special characters. Using!rproduces safer, more conventional reprs.Recommended diff:
- parts = [] - if acc_str: - parts.append(f"accession='{acc_str}'") - parts.append(f"score={score}") + parts = [] + if acc_str: + parts.append(f"accession={acc_str!r}") + parts.append(f"score={score}") @@ - if desc_str: - # Truncate description if too long - if len(desc_str) > 50: - desc_str = desc_str[:47] + "..." - parts.append(f"description='{desc_str}'") + if desc_str: + # Truncate description if too long + if len(desc_str) > 50: + desc_str = desc_str[:47] + "..." + parts.append(f"description={desc_str!r}")If you want full consistency with other classes, you could also consider formatting
score/coveragewith a fixed precision (e.g.score={score:.3f},coverage={coverage:.1f}), but that’s purely cosmetic.src/pyOpenMS/addons/MSSpectrum.pyx (1)
203-237: Consider avoiding full mz array allocation for mz_range in reprThe representation logic is correct and nicely formatted, but computing
mz_rangeviaget_mz_array()means allocating and filling an array of sizenum_peaksjust to access the first and last entries. For large spectra this can makerepr(spectrum)unexpectedly expensive.If
_MSSpectrumexposes min/max m/z accessors (e.g.getMinMZ()/getMaxMZ()or equivalent), or if there’s a cheaper way in the bindings to read just the first/last peak, consider switching to that instead of materializing the full numpy array. This keeps the repr usable even for very large spectra.src/pyOpenMS/addons/MSChromatogram.pyx (1)
121-153: Escape chromatogram name and consider a cheaper rt_range computationTwo minor points here:
- String quoting for
name
Embedding the name as"name='...'"can produce confusing reprs if the name contains quotes or special characters. Using!ris safer and matches typical__repr__style:- # Add name if set - name = self.getName() - if name: - name_str = name.decode('utf-8') if isinstance(name, bytes) else str(name) - if name_str: - parts.append(f"name='{name_str}'") + # Add name if set + name = self.getName() + if name: + name_str = name.decode('utf-8') if isinstance(name, bytes) else str(name) + if name_str: + parts.append(f"name={name_str!r}")
- Performance of rt_range
rt_rangeis currently derived viaget_peaks(), which allocates and fills two numpy arrays of lengthnum_peaksjust to readrts[0]andrts[-1]. For large chromatograms this can makerepr(chrom)relatively expensive. If the underlying C++ API or bindings expose direct access to the first/last RT (or min/max RT), consider using that instead of materializing the full arrays for the repr.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (21)
src/pyOpenMS/addons/AASequence.pyx(2 hunks)src/pyOpenMS/addons/ChromatogramPeak.pyx(1 hunks)src/pyOpenMS/addons/ConsensusFeature.pyx(1 hunks)src/pyOpenMS/addons/EmpiricalFormula.pyx(1 hunks)src/pyOpenMS/addons/Feature.pyx(1 hunks)src/pyOpenMS/addons/IsotopeDistribution.pyx(1 hunks)src/pyOpenMS/addons/MRMFeature.pyx(1 hunks)src/pyOpenMS/addons/MSChromatogram.pyx(1 hunks)src/pyOpenMS/addons/MSExperiment.pyx(1 hunks)src/pyOpenMS/addons/MSSpectrum.pyx(1 hunks)src/pyOpenMS/addons/MobilityPeak1D.pyx(1 hunks)src/pyOpenMS/addons/Peak1D.pyx(1 hunks)src/pyOpenMS/addons/Peak2D.pyx(1 hunks)src/pyOpenMS/addons/PeptideEvidence.pyx(1 hunks)src/pyOpenMS/addons/PeptideHit.pyx(1 hunks)src/pyOpenMS/addons/PeptideIdentification.pyx(1 hunks)src/pyOpenMS/addons/PeptideIdentificationList.pyx(1 hunks)src/pyOpenMS/addons/ProteinHit.pyx(1 hunks)src/pyOpenMS/addons/ReactionMonitoringTransition.pyx(1 hunks)src/pyOpenMS/addons/ResidueModification.pyx(1 hunks)src/pyOpenMS/tests/unittests/test000.py(17 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/pyOpenMS/tests/**/*.py
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Write pyOpenMS tests for new Python bindings
Files:
src/pyOpenMS/tests/unittests/test000.py
🧠 Learnings (4)
📓 Common learnings
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/**/*.h : Add Doxygen comments for new public methods and classes in pyOpenMS bindings
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/**/*.h : Add Doxygen comments for new public methods and classes in pyOpenMS bindings
Applied to files:
src/pyOpenMS/addons/MobilityPeak1D.pyxsrc/pyOpenMS/addons/MSSpectrum.pyxsrc/pyOpenMS/addons/ResidueModification.pyxsrc/pyOpenMS/addons/ChromatogramPeak.pyxsrc/pyOpenMS/addons/ProteinHit.pyxsrc/pyOpenMS/addons/Peak1D.pyxsrc/pyOpenMS/addons/PeptideEvidence.pyxsrc/pyOpenMS/tests/unittests/test000.pysrc/pyOpenMS/addons/PeptideHit.pyxsrc/pyOpenMS/addons/IsotopeDistribution.pyx
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/tests/**/*.py : Write pyOpenMS tests for new Python bindings
Applied to files:
src/pyOpenMS/tests/unittests/test000.py
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/tests/class_tests/openms/**/*.cpp : Write unit tests for new functionality
Applied to files:
src/pyOpenMS/tests/unittests/test000.py
🧬 Code graph analysis (1)
src/pyOpenMS/tests/unittests/test000.py (1)
src/openms/source/CHEMISTRY/AASequence.cpp (8)
AASequence(110-113)AASequence(115-118)AASequence(120-123)AASequence(125-128)fromString(1691-1696)fromString(1691-1691)fromString(1698-1703)fromString(1698-1698)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
- GitHub Check: build-and-test (windows-2022, cl.exe, 14.36)
- GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
- GitHub Check: build-and-test (ubuntu-22.04-arm, g++, 11)
- GitHub Check: build-lnx-arm
- GitHub Check: build-lnx
🔇 Additional comments (11)
src/pyOpenMS/addons/MSExperiment.pyx (1)
136-169: MSExperiment repr is safe, concise, and correctly guardedThe representation correctly aggregates only cheap, global properties and guards
getMinRT/getMaxRTbehindnum_spectra > 0, avoiding invalid access on empty experiments.__str__delegating to__repr__keeps the API consistent.src/pyOpenMS/addons/ChromatogramPeak.pyx (1)
4-21: ChromatogramPeak string representation looks correct and idiomaticUsing
getRT()/getIntensity()with fixed decimal formatting is straightforward and safe, and delegating__str__to__repr__matches the pattern used across the PR.src/pyOpenMS/addons/PeptideIdentificationList.pyx (1)
4-22: PeptideIdentificationList length and representation are appropriate
__len__correctly forwards tosize(), and the minimalistPeptideIdentificationList(size=...)repr is cheap and predictable while still useful in debugging.__str__delegating to__repr__keeps the interface consistent with other classes in this PR.src/pyOpenMS/addons/Feature.pyx (1)
4-46: Feature string representations look solid and consistent
__str__delegating to__repr__and the selected fields/precisions make sense; optional attributes are handled cleanly and safely.src/pyOpenMS/addons/ConsensusFeature.pyx (1)
4-32: ConsensusFeature str/repr are straightforward and correctField selection and formatting are consistent with other peak/feature types, and the implementation is safe and cheap.
src/pyOpenMS/addons/Peak2D.pyx (1)
4-22: Peak2D str/repr are clean and idiomaticImplementation is minimal, uses appropriate formatting for rt/mz/intensity, and safely delegates
__str__to__repr__.src/pyOpenMS/addons/Peak1D.pyx (1)
4-21: Peak1D representations are simple and correctDelegation pattern and numeric formatting are consistent with the rest of the API; no issues spotted.
src/pyOpenMS/addons/MRMFeature.pyx (1)
4-35: LGTM! Clean implementation of string representations.The
__repr__method provides a comprehensive view of the MRMFeature with appropriate precision for each field type. The conditional inclusion of charge (only when non-zero) keeps the output clean.src/pyOpenMS/addons/PeptideHit.pyx (1)
4-37: LGTM! Well-structured representation.The implementation correctly uses
toString()for sequence conversion and conditionally includes num_evidences only when present. Good use of cdef declarations for type safety.src/pyOpenMS/addons/PeptideIdentification.pyx (1)
4-47: LGTM! Excellent use of conditional field inclusion.The implementation properly checks for RT/MZ availability using
hasRT()andhasMZ()before including them in the representation. The top hit information is a nice addition that provides context without overwhelming the output.src/pyOpenMS/tests/unittests/test000.py (1)
281-297: LGTM! Comprehensive test coverage for new representations.The tests appropriately verify that:
__repr__output contains the class name and expected fields__str__delegates to__repr__(str_str == repr_str)- Tests populate objects with data before checking representations
The pattern of checking for presence of key strings rather than exact formats is appropriate, as it allows flexibility in formatting details while ensuring essential information is included.
Also applies to: 3845-3864, 4818-4849, 4876-4896, 4966-4991
- Fix __str__ to return just the formula string for backwards compatibility with existing code that uses str(formula) in expressions/assertions - Fix __repr__ to not use .decode() since toString() already returns Python string - Now str(EmpiricalFormula) returns "C6H12O6" (formula string) - And repr(EmpiricalFormula) returns detailed format for debugging 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Update example to match actual implementation: - most_abundant -> most_abundant_mass - Use correct decimal formatting (.2f for mass_range, .4f for most_abundant_mass) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
fixing tests right now |
autowrap methods return Python types (str, int), not C++ types (String, char). Removed cdef String/char declarations that caused TypeError when accessing return values from wrapped methods. Also fixed test assertions: - EmpiricalFormula: __str__ now returns formula only, __repr__ returns details - PeptideEvidence: setAABefore/setAAAfter expect bytes, not int - PeptideHit: __repr__ now includes full evidence details 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/pyOpenMS/addons/EmpiricalFormula.pyx (1)
11-32:__repr__formatting is clear; consider using!rfor the formula fieldThe overall structure is good: you collect key properties, conditionally include charge, and the docstring example now matches the actual output (4-decimal mono mass, charge omitted when zero).
If you want
__repr__to be a bit more robust for “odd” formula strings (e.g., containing quotes or whitespace), you could render the formula viarepr()instead of manually adding single quotes:- if formula_str: - parts.append(f"formula='{formula_str}'") + if formula_str: + parts.append(f"formula={formula_str!r}")This keeps normal cases readable while avoiding edge cases where the embedded quotes could make the repr ambiguous.
src/pyOpenMS/addons/ResidueModification.pyx (1)
4-35: ResidueModification__repr__/__str__are clear and match intended semanticsLogic for including
id,name,mass_diff, andoriginis straightforward and robust; delegating__str__to__repr__keeps behavior consistent. One minor improvement would be to use!rwhen formatting string fields (e.g.id={mod_id_str!r}) so values containing quotes or special characters are always represented unambiguously.src/pyOpenMS/tests/unittests/test000.py (1)
5000-5069: Consider adding explicit tests forPeptideIdentificationList.__repr__/__str__This block thoroughly exercises construction, push_back, indexing, iteration, and clear behavior of
PeptideIdentificationList, but doesn’t currently assert anything about its new__repr__/__str__implementations mentioned in the PR summary. Adding a small check thatrepr(pil)includes the class name and size, and thatstr(pil)behaves as intended, would make the tests fully cover the new binding.As per coding guidelines for pyOpenMS tests, I can help sketch a concise repr/str test here if you’d like.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
src/pyOpenMS/addons/EmpiricalFormula.pyx(1 hunks)src/pyOpenMS/addons/PeptideEvidence.pyx(1 hunks)src/pyOpenMS/addons/PeptideHit.pyx(1 hunks)src/pyOpenMS/addons/ProteinHit.pyx(1 hunks)src/pyOpenMS/addons/ResidueModification.pyx(1 hunks)src/pyOpenMS/tests/unittests/test000.py(18 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
- src/pyOpenMS/addons/PeptideHit.pyx
- src/pyOpenMS/addons/ProteinHit.pyx
- src/pyOpenMS/addons/PeptideEvidence.pyx
🧰 Additional context used
📓 Path-based instructions (1)
src/pyOpenMS/tests/**/*.py
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Write pyOpenMS tests for new Python bindings
Files:
src/pyOpenMS/tests/unittests/test000.py
🧠 Learnings (4)
📓 Common learnings
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/tests/**/*.py : Write pyOpenMS tests for new Python bindings
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/**/*.h : Add Doxygen comments for new public methods and classes in pyOpenMS bindings
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/tests/**/*.py : Write pyOpenMS tests for new Python bindings
Applied to files:
src/pyOpenMS/tests/unittests/test000.py
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/**/*.h : Add Doxygen comments for new public methods and classes in pyOpenMS bindings
Applied to files:
src/pyOpenMS/tests/unittests/test000.pysrc/pyOpenMS/addons/ResidueModification.pyx
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/tests/class_tests/openms/**/*.cpp : Write unit tests for new functionality
Applied to files:
src/pyOpenMS/tests/unittests/test000.py
🧬 Code graph analysis (1)
src/pyOpenMS/tests/unittests/test000.py (1)
src/openms/source/KERNEL/MSSpectrum.cpp (9)
setRT(585-588)setRT(585-585)MSSpectrum(515-515)MSSpectrum(517-520)MSSpectrum(522-522)setMSLevel(620-623)setMSLevel(620-620)setName(630-633)setName(630-630)
🔇 Additional comments (19)
src/pyOpenMS/addons/EmpiricalFormula.pyx (1)
4-9:__str__implementation and docstring look consistent and idiomaticReturning
self.toString()here matches the documented intent of giving just the bare formula string, and keeps__str__nicely focused on the “equation-friendly” view. No issues from my side.src/pyOpenMS/tests/unittests/test000.py (18)
72-76: MetaInfoInterface test strengthens key/value round‑trip checksThe extra assertions on presence and values of
b"key"/b"key2"before and after removal solidify the MetaInfoInterface contract without changing behavior.Also applies to: 83-84
286-303: AASequence__repr__/__str__tests exercise key fields and modified flagThe new checks validate that the representation includes the class name, sequence, length, mono mass, and the
modifiedflag for modified vs unmodified sequences, plusstr(aas) == repr(aas). This is good, focused coverage for the new bindings.
392-407: ResidueModification representation test covers the new binding minimally but sufficientlyUsing
ModificationsDB.getModificationand asserting the prefixResidueModification(plusstr(mod) == repr(mod)is a reasonable smoke test for the new repr/str without hard‑coding UniMod‑specific content.
409-425: MobilityPeak1D__repr__/__str__test is aligned with the new summary formatAsserting presence of
MobilityPeak1D(,mobility=, andintensity=, and checkingstr(p) == repr(p)gives good coverage of the new representation.
452-463: IsotopeDistribution repr test validates structural summary rather than raw containerThe test builds a small distribution and checks for
IsotopeDistribution(,num_isotopes=, andmass_range=, withstr == repr, which matches the typical summary style and avoids over‑specifying internal details.
573-583: EmpiricalFormula test clearly differentiates__str__(formula) from__repr__(detailed)Checking that
reprcontainsEmpiricalFormula(,formula=,mono_mass=, whilestr(ef)is just the bare formula and not equal torepr(ef)accurately encodes the intended API contract.
718-724: ChromatogramPeak representation test covers RT and intensity summaryThe test ensures
ChromatogramPeak(plusrt=andintensity=appear and thatstr(p) == repr(p), which is exactly what you want for an interactive summary.
811-827: ConsensusFeature__repr__/__str__tests validate all important dimensionsUsing a populated
ConsensusFeatureand checking forrt=,mz=,intensity=, andnum_features=inrepr(andstr == repr) gives strong coverage for the new representation.
1358-1376: Feature representation test matches typical RT/mz/intensity/charge/quality summaryThe test builds a realistic
Featureand asserts thatreprcontains the main quantitative fields and thatstrmatchesrepr. This is solid coverage of the new binding behavior.
3196-3215: MSExperiment repr test checks core structural fieldsBy creating an experiment with two spectra and asserting that
reprcontainsMSExperiment(,num_spectra=, andnum_chromatograms=, plusstr == repr, the test nicely guards the high‑level summary format.
3544-3556: MSSpectrum representation test validates ms_level/rt/num_peaks reportingThe new test ensures
MSSpectrum(,ms_level=,rt=, andnum_peaks=appear in the repr and thatstrdelegates torepr, which aligns with the corresponding addon implementation.
3805-3814: MSChromatogram__repr__/__str__test focuses on peak count summaryChecking for
MSChromatogram(andnum_peaks=and enforcingstr(chrom) == repr(chrom)is the right level of assertion for this binding.
3852-3870: MRMFeature repr test captures RT/mz/intensity and transition countPopulating an
MRMFeaturewith RT, m/z, intensity, charge, and two transitions, then asserting presence ofnum_transitions=and thatstr == repr, provides meaningful coverage for the new human‑readable summary.
4174-4187: ReactionMonitoringTransition representation test validates core numeric fieldsThe test sets native ID, precursor/product m/z, peptide ref, and library intensity, then asserts that
reprincludesReactionMonitoringTransition(,precursor_mz=, andproduct_mz=, withstrmatchingrepr. This is appropriate and stable coverage.
4825-4855: PeptideHit__repr__/__str__tests cover both basic and evidence‑rich casesYou first assert presence of
score=,sequence=, andcharge=in the base repr, then add aPeptideEvidenceand check thatevidences=and nestedPeptideEvidence(with the accession show up, plusstr == repr. This thoroughly exercises the new representation.
4883-4902: PeptideEvidence representation test validates all positional and flanking infoThe repr checks for
PeptideEvidence(,protein=,start=,end=,aa_before=, andaa_after=, and ensuresstrmatches, which directly reflects the added binding behavior.
4973-4997: PeptideIdentification repr test asserts summary of RT/mz/score type and top hitBy setting RT, m/z, score type, and a single top hit, then checking for
rt=,mz=,score_type=,num_hits=,top_hit=, and the peptide sequence inrepr, plusstr == repr, you get excellent coverage of the new textual summary.
5306-5324: ProteinHit representation test verifies accession/score/coverage in reprThe test builds a realistic
ProteinHit, then asserts thatreprcontainsProteinHit(,accession=, the accession string,score=, andcoverage=, and thatstrequalsrepr. This nicely validates the new string representation.
This pull request adds custom string representations (
__str__and__repr__methods) to a wide range of core pyOpenMS data classes. These representations provide concise, readable summaries of key properties for each object, making debugging and interactive exploration much easier. The changes ensure that printing or inspecting these objects gives meaningful information about their contents, such as sequence, mass, intensity, charge, and other relevant attributes.Object string representation improvements
__str__and__repr__methods toAASequence,EmpiricalFormula,IsotopeDistribution,MSChromatogram,MSExperiment,MSSpectrum,Peak1D,Peak2D,MobilityPeak1D,ChromatogramPeak,Feature,ConsensusFeature,MRMFeature,PeptideEvidence,PeptideHit,PeptideIdentification,PeptideIdentificationList, andProteinHit, each returning a formatted string summarizing key properties. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18]API consistency
__str__delegates to__repr__for all affected classes, so bothprint(obj)andrepr(obj)yield the same informative output. (All references above)Enhanced usability for interactive analysis
These changes significantly improve the developer experience when working with pyOpenMS objects by providing clear, context-rich summaries of their state.## Description
Checklist
How can I get additional information on failed tests during CI
Click to expand
If your PR is failing you can check outIf you click in the column that lists the failed tests you will get detailed error messages.
Advanced commands (admins / reviewer only)
Click to expand
/reformat(experimental) applies the clang-format style changes as additional commit. Note: your branch must have a different name (e.g., yourrepo:feature/XYZ) than the receiving branch (e.g., OpenMS:develop). Otherwise, reformat fails to push.rebuild jenkinswill retrigger Jenkins-based CI buildsSummary by CodeRabbit
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.