Skip to content
Draft
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
7 changes: 3 additions & 4 deletions spectrum_utils/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ def __init__(self, **kwargs):
super(GnpsBackend, self).__init__("GNPS", self._url_template, **kwargs)


# Register GNPS backend with Pyteomics PROXI aggregator.
pyteomics.usi.AGGREGATOR = pyteomics.usi.PROXIAggregator(
backends={"gnps": GnpsBackend()}
)
# PROXIAggregator() with no explicit backends uses every entry in `_proxies`.
pyteomics.usi._proxies["gnps"] = GnpsBackend
pyteomics.usi.AGGREGATOR = pyteomics.usi.PROXIAggregator()


@nb.experimental.jitclass
Expand Down
23 changes: 20 additions & 3 deletions tests/spectrum_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import numpy as np
import pytest
import pyteomics.usi
from pyteomics import mass

from spectrum_utils import fragment_annotation as fa, proforma, spectrum
Expand Down Expand Up @@ -67,6 +68,22 @@ def test_intensity_array():
spec.intensity = np.random.lognormal(0, 1, num_peaks)


def test_usi_aggregator_backends():
# from_usi()'s default "aggregator" backend should query every source.
backend_names = set(pyteomics.usi.AGGREGATOR.backends.keys())
assert backend_names == {
"gnps",
"massive",
"peptide_atlas",
"pride",
"jpost",
"proteome_exchange",
}
assert isinstance(
pyteomics.usi.AGGREGATOR.backends["gnps"], spectrum.GnpsBackend
)


def test_from_usi():
# Test USI that should work (no ProForma annotations)
working_usis = [
Expand Down Expand Up @@ -101,9 +118,9 @@ def test_from_usi():
continue

# Ensure at least one USI was successfully parsed
assert len(successful_parses) > 0, (
"All USIs failed to parse. This may indicate a problem with the code or external APIs."
)
assert (
len(successful_parses) > 0
), "All USIs failed to parse. This may indicate a problem with the code or external APIs."

# Test USI with ProForma annotations (should work now that pyteomics backend is fixed)
proforma_usis = [
Expand Down
Loading