Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST: add tests for MetaCoAG #7

Closed
5 tasks done
Vini2 opened this issue Aug 13, 2024 · 4 comments
Closed
5 tasks done

TST: add tests for MetaCoAG #7

Vini2 opened this issue Aug 13, 2024 · 4 comments
Labels
good first issue Good for newcomers

Comments

@Vini2
Copy link
Collaborator

Vini2 commented Aug 13, 2024

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.

  • graph: assembly_graph_with_scaffolds.gfa
  • contigs: contigs.fasta
  • paths: contigs.paths
  • abundance: coverm_mean_coverage.tsv
  • outpath: tmp_dir

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.

  • graph: final.gfa
  • contigs: final.contigs.fa
  • abundance: abundance.tsv
  • outpath: tmp_dir

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.

  • graph: assembly_graph.gfa
  • contigs: assembly.fasta
  • paths: assembly_info.txt
  • abundance: abundance.tsv
  • outpath: tmp_dir

How to invoke:

gbintk metacoag --assembler flye --graph {graph} --contigs {contigs} --paths {paths} --abundance {abundance} --output {outpath}
@Vini2 Vini2 added the good first issue Good for newcomers label Aug 13, 2024
@YapengLang
Copy link
Contributor

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

@Vini2
Copy link
Collaborator Author

Vini2 commented Sep 8, 2024

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

@YapengLang
Copy link
Contributor

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
Copy link
Collaborator Author

Vini2 commented Sep 9, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants