Skip to content

Commit

Permalink
Merge pull request #93 from MicrobialDarkMatter/bugfix/pileup-in-binc…
Browse files Browse the repository at this point in the history
…onsensus-invalid-argument

Argparser argument fixes
  • Loading branch information
SorenHeidelbach authored Jan 22, 2025
2 parents 652b997 + 81fa2f0 commit 9c03fd8
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
data
tests/cli/
nanomotif/flamegraph*
austin
results
Expand Down
2 changes: 1 addition & 1 deletion nanomotif/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.2"
__version__ = "0.5.3"
2 changes: 2 additions & 0 deletions nanomotif/argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def create_parser():
)
parser_score_motifs.add_argument("motifs", type=str, help="path to the motifs file.")
parser_score_motifs.add_argument("--save-motif-positions", action="store_true", help="save motif positions in the output folder")
parser_score_motifs.add_argument("--threshold_valid_coverage", type=int, default=5, help="minimum valid base coverage for a position to be considered. Default: %(default)s")

###########################################################################
# Bin consensus
Expand All @@ -60,6 +61,7 @@ def create_parser():
parser_bin_consensus.add_argument("motifs", type=str, help="path to the motifs file.")
parser_bin_consensus.add_argument("bins", type=str, help="tsv file specifying which bin contigs belong.")
parser_bin_consensus.add_argument("motifs_scored", metavar="motifs-scored", type=str, help="path to the motif-scored file.")
parser_bin_consensus.add_argument("--threshold_valid_coverage", type=int, default=5, help="minimum valid base coverage for a position to be considered. Default: %(default)s")

###########################################################################
# Complete workflow
Expand Down
9 changes: 9 additions & 0 deletions nanomotif/datasets/geobacillus-plasmids.motifs-scored.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
contig mod_type motif mod_position n_mod n_nomod motif_type motif_complement mod_position_complement n_mod_complement n_nomod_complement
contig_2 a ACCCA 4 75 17 non-palindrome
contig_2 a CCAAAT 4 71 5 non-palindrome
contig_2 a GATC 1 679 74 palindrome GATC 1 679 74
contig_2 a GRNGAAGY 5 85 6 non-palindrome
contig_3 a ACCCA 4 58 8 non-palindrome
contig_3 a CCAAAT 4 80 1 non-palindrome
contig_3 a GATC 1 680 29 palindrome GATC 1 680 29
contig_3 a GRNGAAGY 5 83 2 non-palindrome
9 changes: 9 additions & 0 deletions nanomotif/datasets/geobacillus-plasmids.motifs.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
contig motif mod_position mod_type n_mod n_nomod motif_type motif_complement mod_position_complement n_mod_complement n_nomod_complement
contig_2 ACCCA 4 a 75 17 non-palindrome
contig_2 CCAAAT 4 a 71 5 non-palindrome
contig_2 GATC 1 a 679 74 palindrome GATC 1 679 74
contig_2 GRNGAAGY 5 a 85 8 non-palindrome
contig_3 ACCCA 4 a 58 8 non-palindrome
contig_3 CCAAAT 4 a 80 1 non-palindrome
contig_3 GATC 1 a 680 29 palindrome GATC 1 680 29
contig_3 GRNGAAGY 5 a 83 2 non-palindrome
4 changes: 2 additions & 2 deletions nanomotif/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def score_motifs(args, pl, pileup = None, assembly = None, motifs = None, min_mo
log.info("Starting nanomotif motif scorer")
if pileup is None:
log.info("Loading pileup")
pileup = nm.load_pileup(args.pileup, min_fraction = args.threshold_methylation_general)
pileup = nm.load_pileup(args.pileup, min_fraction = args.threshold_methylation_general, min_coverage = args.threshold_valid_coverage)
if assembly is None:
log.info("Loading assembly")
assembly = nm.load_assembly(args.assembly)
Expand Down Expand Up @@ -299,7 +299,7 @@ def bin_consensus(args, pl, pileup = None, assembly = None, motifs = None, motif
motifs_scored = pl.read_csv(args.motifs_scored, separator="\t")
if pileup is None:
log.info("Loading pileup")
pileup = nm.load_pileup(args.pileup, threads = args.threads, min_fraction = args.threshold_methylation_general)
pileup = nm.load_pileup(args.pileup, min_fraction = args.threshold_methylation_general, min_coverage = args.threshold_valid_coverage)
if assembly is None:
log.info("Loading assembly")
assembly = nm.load_assembly(args.assembly)
Expand Down
54 changes: 54 additions & 0 deletions tests/test_cli_commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import pytest
import subprocess
import pandas as pd
import os
import glob
import shutil


def test_bin_consensus():
"""
"""
outdir = "tests/cli/test_bin_consensus"

cmd = [
"nanomotif", "bin_consensus",
"-t", "1",
"nanomotif/datasets/geobacillus-plasmids.assembly.fasta",
"nanomotif/datasets/geobacillus-plasmids.pileup.bed",
"nanomotif/datasets/geobacillus-plasmids.motifs.tsv",
"nanomotif/datasets/geobacillus-contig-bin.tsv",
"nanomotif/datasets/geobacillus-plasmids.motifs-scored.tsv",
"--out", outdir
]

result = subprocess.run(cmd)

# Check that the CLI tool executed successfully
assert result.returncode == 0, "CLI tool did not exit successfully"

#TODO: remove outputdir
#


def test_score_motifs():
"""
"""
outdir = "tests/cli/test_score_motifs"

cmd = [
"nanomotif", "score_motifs",
"-t", "1",
"nanomotif/datasets/geobacillus-plasmids.assembly.fasta",
"nanomotif/datasets/geobacillus-plasmids.pileup.bed",
"nanomotif/datasets/geobacillus-plasmids.motifs.tsv",
"--out", outdir
]

result = subprocess.run(cmd)

# Check that the CLI tool executed successfully
assert result.returncode == 0, "CLI tool did not exit successfully"

#TODO: remove outputdir

0 comments on commit 9c03fd8

Please sign in to comment.