Files
PlantAI-dev/tests/unit/test_identify_hmm_models.py
T
2026-08-03 18:42:47 +08:00

54 lines
1.7 KiB
Python
Executable File

from pathlib import Path
import pytest
from apps.cli.run_identify import hmm_model_audit, python_fetch_models
FAKE_PFAM = """HMMER3/f [3.3.2 | Nov 2020]
NAME NAC
ACC PF01849.24
LENG 10
//
HMMER3/f [3.3.2 | Nov 2020]
NAME NAM
ACC PF02365.21
LENG 10
//
"""
def test_python_fetch_models_matches_accessions_not_alias_names(tmp_path: Path):
pfam_db = tmp_path / "Pfam-A.hmm"
out_hmm = tmp_path / "PF02365.hmm"
pfam_db.write_text(FAKE_PFAM, encoding="latin-1")
fetch_map = python_fetch_models(pfam_db, "PF02365", out_hmm)
audit = hmm_model_audit(out_hmm, ["PF02365"], fetch_map)
assert audit["loaded_accessions"] == ["PF02365"]
assert audit["missing_requested_pfams"] == []
assert [(m["name"], m["accession"]) for m in audit["models"]] == [("NAM", "PF02365")]
def test_python_fetch_models_loads_all_requested_accessions(tmp_path: Path):
pfam_db = tmp_path / "Pfam-A.hmm"
out_hmm = tmp_path / "PF01849_PF02365.hmm"
pfam_db.write_text(FAKE_PFAM, encoding="latin-1")
fetch_map = python_fetch_models(pfam_db, "PF01849,PF02365", out_hmm)
audit = hmm_model_audit(out_hmm, ["PF01849", "PF02365"], fetch_map)
assert audit["loaded_accessions"] == ["PF01849", "PF02365"]
assert audit["missing_requested_pfams"] == []
assert audit["query_name_to_accession"] == {"NAC": "PF01849", "NAM": "PF02365"}
def test_python_fetch_models_fails_when_requested_accession_missing(tmp_path: Path):
pfam_db = tmp_path / "Pfam-A.hmm"
out_hmm = tmp_path / "PF99999.hmm"
pfam_db.write_text(FAKE_PFAM, encoding="latin-1")
with pytest.raises(RuntimeError, match="missing: PF99999"):
python_fetch_models(pfam_db, "PF99999", out_hmm)