Skip to content

Commit 414688e

Browse files
authored
Merge pull request #107 from compomics/feature/optional-pyopenms
make pyOpenMS optional
2 parents 133559a + e014823 commit 414688e

File tree

6 files changed

+32
-32
lines changed

6 files changed

+32
-32
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
run: ruff check --output-format=github .
2828

2929
- name: Install package and its dependencies
30-
run: pip install --editable .[dev]
30+
run: pip install --editable .[dev,idxml]
3131

3232
- name: Test with pytest and codecov
3333
run: |
@@ -58,7 +58,7 @@ jobs:
5858
- name: Install package and its dependencies
5959
run: |
6060
python -m pip install --upgrade pip
61-
pip install .[dev]
61+
pip install .[dev,idxml]
6262
6363
- name: Test imports
6464
run: python -c "import psm_utils"

README.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ Goals and non-goals
8686
Supported file formats
8787
**********************
8888

89-
===================================================================================================================== ======================== =============== ===============
90-
File format psm_utils tag Read support Write support
91-
===================================================================================================================== ======================== =============== ===============
89+
===================================================================================================================== ======================== =============== =============== ==========
90+
File format psm_utils tag Read support Write support Comments
91+
===================================================================================================================== ======================== =============== =============== ==========
9292
`AlphaDIA precursors TSV <https://alphadia.readthedocs.io/en/latest/quickstart.html#output-files>`_ ``alphadia`` ✅ ❌
9393
`DIA-NN TSV <https://github.com/vdemichev/DiaNN#output>`_ ``diann`` ✅ ❌
9494
`FlashLFQ generic TSV <https://github.com/smith-chem-wisc/FlashLFQ/wiki/Identification-Input-Formats>`_ ``flashlfq`` ✅ ✅
9595
`FragPipe PSM TSV <https://fragpipe.nesvilab.org/docs/tutorial_fragpipe_outputs.html#psmtsv/>`_ ``fragpipe`` ✅ ❌
9696
`ionbot CSV <https://ionbot.cloud/>`_ ``ionbot`` ✅ ❌
97-
`OpenMS idXML <https://www.openms.de/>`_ ``idxml`` ✅ ✅
97+
`OpenMS idXML <https://www.openms.de/>`_ ``idxml`` ✅ ✅ Requires the optional ``openms`` dependency (``pip install psm-utils[idxml]``)
9898
`MaxQuant msms.txt <https://www.maxquant.org/>`_ ``msms`` ✅ ❌
9999
`MS Amanda CSV <https://ms.imp.ac.at/?goto=msamanda>`_ ``msamanda`` ✅ ❌
100100
`mzIdentML <https://psidev.info/mzidentml>`_ ``mzid`` ✅ ✅
@@ -108,7 +108,7 @@ Supported file formats
108108
`ProteoScape Parquet <#>`_ ``proteoscape`` ✅ ❌
109109
`TSV <https://psm-utils.readthedocs.io/en/stable/api/psm_utils.io/#module-psm_utils.io.tsv>`_ ``tsv`` ✅ ✅
110110
`X!Tandem XML <https://www.thegpm.org/tandem/>`_ ``xtandem`` ✅ ❌
111-
===================================================================================================================== ======================== =============== ===============
111+
===================================================================================================================== ======================== =============== =============== ==========
112112

113113
Legend: ✅ Supported, ❌ Unsupported
114114

psm_utils/io/idxml.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@
3030
module="pyopenms",
3131
)
3232

33-
import pyopenms as oms #noqa: E402
33+
try:
34+
import pyopenms as oms #noqa: E402
35+
except ImportError:
36+
_has_openms = False
37+
else:
38+
_has_openms = True
3439

3540
logger = logging.getLogger(__name__)
3641

@@ -99,6 +104,8 @@ def __init__(self, filename: Union[Path, str], *args, **kwargs) -> None:
99104
>>> psm_list = [psm for psm in reader]
100105
"""
101106
super().__init__(filename, *args, **kwargs)
107+
if not _has_openms:
108+
raise ImportError("pyOpenMS is required to read idXML files")
102109
self.protein_ids, self.peptide_ids = self._parse_idxml()
103110
self.user_params_metadata = self._get_userparams_metadata(self.peptide_ids[0].getHits()[0])
104111
self.rescoring_features = self._get_rescoring_features(self.peptide_ids[0].getHits()[0])
@@ -326,6 +333,8 @@ def __init__(
326333
327334
"""
328335
super().__init__(filename, *args, **kwargs)
336+
if not _has_openms:
337+
raise ImportError("pyOpenMS is required to write idXML files")
329338
self.protein_ids = protein_ids
330339
self.peptide_ids = peptide_ids
331340
self._writer = None

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ dependencies = [
2727
"psims",
2828
"pyarrow",
2929
"pydantic >= 2",
30-
"pyopenms",
3130
"pyteomics >= 4",
3231
"rich",
3332
"sqlalchemy",
@@ -46,6 +45,7 @@ docs = [
4645
"toml",
4746
]
4847
online = ["streamlit", "plotly"]
48+
idxml = ["pyopenms"]
4949

5050
[project.urls]
5151
GitHub = "https://github.com/compomics/psm_utils"

tests/test_data/test.pq

5.05 KB
Binary file not shown.

tests/test_io/test_parquet.py

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Tests for psm_utils.io.tsv."""
22

3-
import hashlib
43
import os
54

65
from psm_utils.io.parquet import ParquetReader, ParquetWriter
@@ -32,40 +31,32 @@
3231
]
3332

3433

35-
def compute_checksum(filename):
36-
hash_func = hashlib.sha256()
37-
with open(filename, "rb") as f:
38-
for chunk in iter(lambda: f.read(4096), b""):
39-
hash_func.update(chunk)
40-
return hash_func.hexdigest()
41-
42-
4334
class TestParquetWriter:
44-
expected_checksum = "1e5ee7afc5d4131bce8f1d0908136b8c559303abb7bbd7d052afa111d5e64f0c"
45-
4635
def test_write_psm(self):
4736
with ParquetWriter("test.pq") as writer:
4837
for test_case in test_cases:
4938
writer.write_psm(PSM(**test_case))
50-
actual_checksum = compute_checksum("test.pq")
51-
assert actual_checksum == self.expected_checksum, "Checksums do not match"
39+
40+
with ParquetReader("test.pq") as reader:
41+
for i, psm in enumerate(reader):
42+
assert psm == PSM(**test_cases[i])
43+
5244
os.remove("test.pq")
5345

5446
def test_write_file(self):
5547
with ParquetWriter("test.pq") as writer:
5648
writer.write_file(PSMList(psm_list=[PSM(**t) for t in test_cases]))
57-
actual_checksum = compute_checksum("test.pq")
58-
assert actual_checksum == self.expected_checksum, "Checksums do not match"
59-
# os.remove("test.pq")
49+
50+
with ParquetReader("test.pq") as reader:
51+
for i, psm in enumerate(reader):
52+
assert psm == PSM(**test_cases[i])
53+
54+
os.remove("test.pq")
6055

6156

6257
class TestParquetReader:
6358
def test_iter(self):
64-
# Write test cases to file
65-
ParquetWriter("test.pq").write_file(PSMList(psm_list=[PSM(**t) for t in test_cases]))
66-
6759
# Read test cases from file
68-
for i, psm in enumerate(ParquetReader("test.pq")):
69-
assert psm == PSM(**test_cases[i])
70-
71-
os.remove("test.pq")
60+
with ParquetReader("tests/test_data/test.pq") as reader:
61+
for i, psm in enumerate(reader):
62+
assert psm == PSM(**test_cases[i])

0 commit comments

Comments
 (0)