metagentools / gbintk

🌟🧬 GraphBin-Tk: assembly graph-based metagenomic binning toolkit
https://gbintk.readthedocs.io/en/latest/
GNU General Public License v3.0
8 stars 5 forks source link

TST: add tests for MetaCoAG #7

Closed Vini2 closed 20 hours ago

Vini2 commented 1 month ago

Add tests for MetaCoAG in gbintk.

MetaCoAG on spades

File name: test_cli_metacoag.py Function name: test_metacoag_spades_run

Inputs: file names in the tests/data/5G_metaSPAdes directory.

How to invoke:

gbintk metacoag --assembler spades --graph {graph} --contigs {contigs} --paths {paths} --abundance {abundance} --output {outpath}

MetaCoAG on megahit

File name: test_cli_metacoag.py Function name: test_metacoag_megahit_run

Inputs: file names in the tests/data/5G_MEGAHIT directory.

How to invoke:

gbintk metacoag --assembler megahit --graph {graph} --contigs {contigs} --abundance {abundance} --output {outpath}

MetaCoAG on flye

File name: test_cli_metacoag.py Function name: test_metacoag_flye_run

Inputs: file names in the tests/data/1Y3B_Flye directory.

How to invoke:

gbintk metacoag --assembler flye --graph {graph} --contigs {contigs} --paths {paths} --abundance {abundance} --output {outpath}
YapengLang commented 1 week ago

I'm also happy to do this issue @Vini2 !

Vini2 commented 1 week ago

Hi @YapengLang! Feel free to tackle this issue. Thanks!

YapengLang commented 1 week ago

hi @Vini2 ,

I tried to write tests for invoking MetaCoAG on spades and megahit, but I met some warnings I didn't understand very well.

I followed the instructions provided in this issue. When I ran pytest for test_cli_metacoag.py, two warning messages were raised from my tests for MetaCoAG on megahit, after the tests on spades finished. But such warnings disappeared if I ran two test functions one by one. The following is how to reproduce:

import pathlib

import pytest
from click.testing import CliRunner

from gbintk.cli import metacoag

DATADIR = pathlib.Path(__file__).parent / "data"

@pytest.fixture(scope="session")
def tmp_dir(tmpdir_factory):
    return tmpdir_factory.mktemp("tmp")

@pytest.fixture(autouse=True)
def workingdir(tmp_dir, monkeypatch):
    """set the working directory for all tests"""
    monkeypatch.chdir(tmp_dir)

@pytest.fixture(scope="session")
def runner():
    """exportrc works correctly."""
    return CliRunner()

def test_metacoag_spades_run(runner, tmp_dir):
    outpath = tmp_dir
    graph = DATADIR / "5G_metaSPAdes" / "assembly_graph_with_scaffolds.gfa"
    contigs = DATADIR / "5G_metaSPAdes" / "contigs.fasta"
    paths = DATADIR / "5G_metaSPAdes" / "contigs.paths"
    abundance = DATADIR / "5G_metaSPAdes" / "coverm_mean_coverage.tsv"
    args = f"--assembler spades --graph {graph} --contigs {contigs} --paths {paths} --abundance {abundance} --output {outpath}".split()
    r = runner.invoke(metacoag, args, catch_exceptions=False)

    assert r.exit_code == 0, r.output

def test_metacoag_megahit_run(runner, tmp_dir):
    outpath = tmp_dir
    graph = DATADIR / "5G_MEGAHIT" / "final.gfa"
    contigs = DATADIR / "5G_MEGAHIT" / "final.contigs.fa"
    abundance = DATADIR / "5G_MEGAHIT" / "abundance.tsv"
    args = f"--assembler megahit --graph {graph} --contigs {contigs} --abundance {abundance} --output {outpath}".split()
    r = runner.invoke(metacoag, args, catch_exceptions=False)

    assert r.exit_code == 0, r.output  

traceback:

tests/test_cli_metacoag.py::test_metacoag_megahit_run
  /Users/yapenglang/miniconda3/envs/gbintk/lib/python3.12/site-packages/metacoag/metacoag_utils/matching_utils.py:192: RuntimeWarning: Couldn't reach some vertices at src/paths/unweighted.c:444
    shortest_paths = assembly_graph.get_shortest_paths(

tests/test_cli_metacoag.py::test_metacoag_megahit_run
  /Users/yapenglang/miniconda3/envs/gbintk/lib/python3.12/site-packages/metacoag/metacoag_utils/matching_utils.py:286: RuntimeWarning: Couldn't reach some vertices at src/paths/unweighted.c:444
    shortest_paths = assembly_graph.get_shortest_paths(

I tried to set the scope of fixture tmp_dir as scope="function", but problem not solved.

Thank you for any suggestions!

Vini2 commented 1 week ago

Hi @YapengLang!

This warning should not be an issue. It's popping up because some of the vertices are not reachable because they have no connections. Feel free to ignore them.