Skip to content

Commit

Permalink
fix: allow zero subtractions in nuvs
Browse files Browse the repository at this point in the history
  • Loading branch information
SwovelandM authored Oct 13, 2023
1 parent 65bb984 commit e551612
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ __pycache__
.idea
.pytest_cache
/target/
.vscode
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 21 additions & 1 deletion tests/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from virtool_workflow.data_model.indexes import WFIndex
from virtool_workflow.data_model.samples import WFSample
from virtool_workflow.data_model.subtractions import WFSubtraction
from virtool_workflow.runtime.run_subprocess import RunSubprocess

from workflow import (
eliminate_otus,
Expand Down Expand Up @@ -227,13 +228,32 @@ async def test_eliminate_otus(
assert actual == expected


@pytest.mark.parametrize("no_subtractions", [True, False])
async def test_eliminate_subtraction(
run_subprocess, subtractions: list[WFSubtraction], work_path: Path
no_subtractions: bool,
run_subprocess: RunSubprocess,
subtractions: list[WFSubtraction],
work_path,
):
if no_subtractions:
subtractions = []

shutil.copy(TEST_DATA_PATH / "unmapped_otus.fq", work_path / "unmapped_otus.fq")
await eliminate_subtraction(2, run_subprocess, subtractions, work_path)

assert Path(work_path / "unmapped_subtraction.fq").is_file()

if no_subtractions:
with open(work_path / "unmapped_subtraction.fq") as subtracted_file, open(
work_path / "unmapped_otus.fq"
) as otu_file:
subtracted_lines = [line.strip() for line in subtracted_file]
otu_lines = [line.strip() for line in otu_file]
for subtracted, otu in zip(subtracted_lines, otu_lines):
assert subtracted == otu


@pytest.mark.flaky(reruns=3)
@pytest.mark.parametrize("paired", [False, True], ids=["unpaired", "paired"])
async def test_reunite_pairs(paired: bool, reads: Reads, sample: WFSample, work_path):
if paired:
Expand Down
10 changes: 7 additions & 3 deletions workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ async def eliminate_subtraction(
"""

if len(subtractions) == 0:
return
await asyncio.to_thread(
shutil.copyfile,
work_path / "unmapped_otus.fq",
work_path / "unmapped_subtraction.fq",
)

await asyncio.to_thread(
shutil.copyfile, work_path / "unmapped_otus.fq", work_path / "working_otus.fq"
Expand All @@ -105,7 +109,7 @@ async def eliminate_subtraction(
"-x",
shlex.quote(str(subtraction.bowtie2_index_path)),
"--un",
str(work_path / "unmapped_subtractions.fq"),
str(work_path / "unmapped_subtraction.fq"),
"-U",
str(work_path / "working_otus.fq"),
]
Expand All @@ -114,7 +118,7 @@ async def eliminate_subtraction(

await asyncio.to_thread(
shutil.copyfile,
work_path / "unmapped_subtractions.fq",
work_path / "unmapped_subtraction.fq",
work_path / "working_otus.fq",
)

Expand Down

0 comments on commit e551612

Please sign in to comment.