Skip to content

Commit

Permalink
Merge pull request #9 from BIONF/dev
Browse files Browse the repository at this point in the history
fix cli
  • Loading branch information
aromberg authored Aug 24, 2024
2 parents eb0c4a8 + 40d6544 commit 832f50b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "XspecT"
version = "0.2.2"
version = "0.2.3"
description = "Tool to monitor and characterize pathogens using Bloom filters."
readme = {file = "README.md", content-type = "text/markdown"}
license = {file = "LICENSE"}
Expand Down
8 changes: 6 additions & 2 deletions src/xspect/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ def classify(genus, path, meta, step):

# define pipeline
pipeline = Pipeline(genus + " classification", "Test Author", "[email protected]")
species_execution = ModelExecution(genus + "-species", sparse_sampling_step=step)
species_execution = ModelExecution(
genus.lower() + "-species", sparse_sampling_step=step
)
if meta:
species_filtering_step = PipelineStep(
StepType.FILTERING, genus, 0.7, species_execution
)
genus_execution = ModelExecution(genus + "-genus", sparse_sampling_step=step)
genus_execution = ModelExecution(
genus.lower() + "-genus", sparse_sampling_step=step
)
genus_execution.add_pipeline_step(species_filtering_step)
pipeline.add_pipeline_step(genus_execution)
else:
Expand Down
61 changes: 61 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""Test XspecT CLI"""

import json
import pytest
from click.testing import CliRunner
from src.xspect.main import cli


@pytest.mark.parametrize(
["assembly_file_path", "genus", "species"],
[
(
"GCF_000069245.1_ASM6924v1_genomic.fna",
"Acinetobacter",
"470",
),
(
"GCF_000018445.1_ASM1844v1_genomic.fna",
"Acinetobacter",
"470",
),
("GCF_000006945.2_ASM694v2_genomic.fna", "Salmonella", "28901"),
],
indirect=["assembly_file_path"],
)
def test_species_assignment(assembly_file_path, genus, species):
"""Test the species assignment"""
runner = CliRunner()
result = runner.invoke(cli, ["classify", genus, assembly_file_path])

run_path = result.output.strip().split("'")[1]
with open(run_path, encoding="utf-8") as f:
result_content = json.load(f)
assert result_content["results"][0]["prediction"] == species


@pytest.mark.parametrize(
["assembly_file_path", "genus", "species"],
[
(
"GCF_000069245.1_ASM6924v1_genomic.fna",
"Acinetobacter",
"470",
),
],
indirect=["assembly_file_path"],
)
def test_metagenome_mode(assembly_file_path, genus, species):
"""Test the metagenome mode"""
runner = CliRunner()
result = runner.invoke(cli, ["classify", "-m", genus, assembly_file_path])

run_path = result.output.strip().split("'")[1]
with open(run_path, encoding="utf-8") as f:
result_content = json.load(f)
assert (
result_content["results"][0]["subprocessing_steps"][0]["result"][
"prediction"
]
== species
)

0 comments on commit 832f50b

Please sign in to comment.