Skip to content

Commit 35d5df6

Browse files
authored
Merge pull request #8 from PopovIILab/dev
Add pytests!
2 parents 535f127 + a7a25e9 commit 35d5df6

3 files changed

Lines changed: 81 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: pytest
2+
on:
3+
push:
4+
branches: [ dev ]
5+
pull_request:
6+
branches: [ dev ]
7+
8+
jobs:
9+
build-test:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
python-version: [3.12]
14+
steps:
15+
- uses: actions/checkout@v3
16+
- uses: actions/setup-python@v4
17+
with:
18+
python-version: ${{ matrix.python-version }}
19+
- run: |
20+
python -m pip install --upgrade pip
21+
pip install krakenparser
22+
pip install pytest
23+
- run: pytest -q

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# KrakenParser: Convert Kraken2 Reports to CSV
22

3+
![License](https://img.shields.io/badge/License-MIT-steelblue)
4+
[![Downloads](https://static.pepy.tech/badge/krakenparser)](https://pepy.tech/project/krakenparser)
5+
![CI](https://github.com/PopovIILab/KrakenParser/actions/workflows/ci.yml/badge.svg)
6+
37
<img src="https://github.com/PopovIILab/KrakenParser/blob/main/imgs/KrakenParser_logo_light.png#gh-light-mode-only" align="left"/>
48
<img src="https://github.com/PopovIILab/KrakenParser/blob/main/imgs/KrakenParser_logo_dark.png#gh-dark-mode-only" align="left"/>
59

@@ -218,15 +222,15 @@ data/
218222
│ ├─ counts_family.csv
219223
│ ├─ ...
220224
└─ csv_relabund/ # Relative abundance CSV output
221-
├─ counts_species.csv
222-
├─ counts_genus.csv
223-
├─ counts_family.csv
224-
├─ ...
225+
├─ counts_species.csv
226+
├─ counts_genus.csv
227+
├─ counts_family.csv
228+
├─ ...
225229
```
226230

227231
## Conclusion
228232
KrakenParser provides a **simple and automated** way to convert Kraken2 reports into usable CSV files for downstream analysis. You can run the **full pipeline** with a single command or use **individual scripts** as needed.
229233

230234
For any issues or feature requests, feel free to open an issue on GitHub!
231235

232-
🚀 Happy analyzing!
236+
🚀 Happy analyzing!

tests/test_full_pipeline.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import zipfile
2+
import shutil
3+
import subprocess
4+
import pytest
5+
from pathlib import Path
6+
7+
8+
@pytest.fixture
9+
def demo_run(tmp_path):
10+
repo_root = Path(__file__).parent.parent.resolve()
11+
zip_src = repo_root / "demo_data.zip"
12+
if not zip_src.exists():
13+
pytest.skip("demo_data.zip not found")
14+
15+
local_zip = tmp_path / "demo_data.zip"
16+
shutil.copy(zip_src, local_zip)
17+
with zipfile.ZipFile(local_zip, "r") as z:
18+
z.extractall(tmp_path)
19+
20+
demo_data_dir = tmp_path / "demo_data"
21+
run_dir = tmp_path / "demo_run"
22+
run_dir.mkdir()
23+
(demo_data_dir / "kreports").rename(run_dir / "kreports")
24+
25+
return {"run_dir": run_dir}
26+
27+
28+
def test_full_pipeline_end_to_end(demo_run):
29+
run_dir = demo_run["run_dir"]
30+
kreports_path = run_dir / "kreports"
31+
32+
# 1. Run KrakenParser
33+
cmd = ["KrakenParser", "--complete", "-i", str(kreports_path)]
34+
result = subprocess.run(cmd, capture_output=True, text=True)
35+
assert result.returncode == 0, f"Pipeline failed:\n{result.stderr}"
36+
37+
# 2. Assert each rank‐level CSV exists and is non‐empty
38+
ranks = ["phylum", "class", "order", "family", "genus", "species"]
39+
for rank in ranks:
40+
csv_path = run_dir / "counts" / "csv" / f"counts_{rank}.csv"
41+
assert csv_path.exists(), f"Missing counts_{rank}.csv"
42+
assert csv_path.stat().st_size > 0, f"counts_{rank}.csv is empty"
43+
44+
# 3. Assert relative‐abundance CSVs exist and are non‐empty
45+
rel_dir = run_dir / "counts" / "csv_relabund"
46+
assert rel_dir.exists(), "csv_relabund directory is missing"
47+
rel_species = rel_dir / "counts_species.csv"
48+
assert rel_species.exists(), "Missing counts_species.csv in csv_relabund"
49+
assert rel_species.stat().st_size > 0, "counts_species.csv is empty"

0 commit comments

Comments
 (0)