Skip to content

feat: fetch PRIDE spectra by USI via PROXI (MzSpectrum)#1099

Open
trishorts wants to merge 1 commit into
smith-chem-wisc:masterfrom
trishorts:pride-proxi-spectra
Open

feat: fetch PRIDE spectra by USI via PROXI (MzSpectrum)#1099
trishorts wants to merge 1 commit into
smith-chem-wisc:masterfrom
trishorts:pride-proxi-spectra

Conversation

@trishorts

Copy link
Copy Markdown
Contributor

The nut

Given a USI (Universal Spectrum Identifier), fetch a spectrum from PRIDE and get it back as an mzLib MzSpectrum — the next capability on the PRIDE client after the merged manifest MVP (#1088) and file download (#1093).

What's here

New API on PrideArchiveClient:

  • GetSpectrumAsync(usi)MzSpectrum — the common case: the spectrum's peaks as an mzLib spectrum.
  • GetProxiSpectrumAsync(usi)PrideProxiSpectrum — the raw PROXI object, keeping the controlled-vocabulary attributes (charge state, selected ion m/z, ms level, scan number, instrument) that an MzSpectrum cannot carry.

Supporting pieces:

  • PrideProxiSpectrum DTO (status/usi/mzs/intensities/attributes); attributes reuse MzLibUtil.CvParam, exactly as PrideArchiveFile does.
  • PrideArchiveExtensions.ToMzSpectrum() — a pure, offline peaks→MzSpectrum transform (mirrors how GetHttpsDownloadUrl is a pure extension beside the networked DownloadFileAsync).

Design notes

  • PROXI is a different path root than the v3 archive API (/pride/proxi/archive/v0.1/ vs /pride/ws/archive/v3/), so the request is issued as an absolute URI rather than resolving against the client's archive BaseAddress.
  • MzSpectrum assumes ascending m/z and validates nothing, so ToMzSpectrum defensively (a) rejects a mzs/intensities length mismatch and (b) sorts a copy of the peaks (leaving the DTO's arrays untouched), constructing with shouldCopy: false to avoid a redundant copy.
  • Adds a MassSpectrometry project reference to UsefulProteomicsDatabases (no dependency cycle — MassSpectrometry depends only on Chemistry + MzLibUtil).

Verified against the live API

Probed the real endpoint before writing the DTO: resultType=full returns a 1-element JSON array of {status, usi, mzs[], intensities[], attributes[cvParam]}; an unknown/unreadable USI returns 404 and a malformed USI 400, both surfacing as HttpRequestException through the existing non-success path.

Tests

🤖 Generated with Claude Code

Adds spectrum access to the PRIDE client (capability after the merged
manifest MVP smith-chem-wisc#1088 and file download smith-chem-wisc#1093). Given a USI, GetSpectrumAsync
returns the peaks as an mzLib MzSpectrum; GetProxiSpectrumAsync returns the
raw PROXI object, keeping the controlled-vocabulary attributes (charge,
precursor m/z, ms level, scan number, instrument).

- PrideProxiSpectrum DTO (status/usi/mzs/intensities/attributes), attributes
  reuse MzLibUtil.CvParam like PrideArchiveFile.
- PrideArchiveExtensions.ToMzSpectrum: pure, offline peaks->MzSpectrum
  transform; defensively sorts a copy by ascending m/z (MzSpectrum assumes
  sorted, does not sort itself) and rejects a mzs/intensities length mismatch.
- PROXI lives under a different path root than the v3 archive base, so the
  request uses an absolute URI (verified live: resultType=full returns a
  1-element JSON array; unknown USI 404s, malformed USI 400s -> HttpRequestException).
- Adds a MassSpectrometry project reference (no dependency cycle).
- Tests: 16 offline (fixture-based) + live canary [Category(ExternalService)]
  +[Category(Pride)] routed through ExternalServiceTestHelper (skip-on-outage).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DZiz2D6dfQ55WetZpJSey2
@codecov

codecov Bot commented Jul 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.51%. Comparing base (525cb7c) to head (048fe6d).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1099   +/-   ##
=======================================
  Coverage   91.50%   91.51%           
=======================================
  Files         439      440    +1     
  Lines       53542    53579   +37     
  Branches     6511     6519    +8     
=======================================
+ Hits        48995    49031   +36     
  Misses       3275     3275           
- Partials     1272     1273    +1     
Files with missing lines Coverage Δ
...ib/UsefulProteomicsDatabases/PrideArchiveClient.cs 100.00% <100.00%> (ø)
...sefulProteomicsDatabases/PrideArchiveExtensions.cs 95.83% <100.00%> (+0.91%) ⬆️
...ib/UsefulProteomicsDatabases/PrideProxiSpectrum.cs 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants