From 8ada4ac4244ec3602cbd3fae459fdf79d01300af Mon Sep 17 00:00:00 2001 From: SebastianDall Date: Tue, 21 Jan 2025 15:08:28 +0100 Subject: [PATCH 1/5] removed invalid argument in bin_consensus --- nanomotif/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nanomotif/main.py b/nanomotif/main.py index ea443ee..6ea5bb6 100644 --- a/nanomotif/main.py +++ b/nanomotif/main.py @@ -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) if assembly is None: log.info("Loading assembly") assembly = nm.load_assembly(args.assembly) From cdf0b7a8cbf7b1b8449da39082ebbb108843f8e5 Mon Sep 17 00:00:00 2001 From: SebastianDall Date: Wed, 22 Jan 2025 09:16:04 +0100 Subject: [PATCH 2/5] added min_coverage argument --- nanomotif/argparser.py | 2 ++ nanomotif/main.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/nanomotif/argparser.py b/nanomotif/argparser.py index 931a81a..c783738 100644 --- a/nanomotif/argparser.py +++ b/nanomotif/argparser.py @@ -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 @@ -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 diff --git a/nanomotif/main.py b/nanomotif/main.py index 6ea5bb6..f0e1b3c 100644 --- a/nanomotif/main.py +++ b/nanomotif/main.py @@ -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) @@ -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, 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) From 883e86b591b22fab4bca7bc7749d27586f51bae2 Mon Sep 17 00:00:00 2001 From: SebastianDall Date: Wed, 22 Jan 2025 09:16:33 +0100 Subject: [PATCH 3/5] added test files --- .../datasets/geobacillus-plasmids.motifs-scored.tsv | 9 +++++++++ nanomotif/datasets/geobacillus-plasmids.motifs.tsv | 9 +++++++++ 2 files changed, 18 insertions(+) create mode 100644 nanomotif/datasets/geobacillus-plasmids.motifs-scored.tsv create mode 100644 nanomotif/datasets/geobacillus-plasmids.motifs.tsv diff --git a/nanomotif/datasets/geobacillus-plasmids.motifs-scored.tsv b/nanomotif/datasets/geobacillus-plasmids.motifs-scored.tsv new file mode 100644 index 0000000..a834f11 --- /dev/null +++ b/nanomotif/datasets/geobacillus-plasmids.motifs-scored.tsv @@ -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 diff --git a/nanomotif/datasets/geobacillus-plasmids.motifs.tsv b/nanomotif/datasets/geobacillus-plasmids.motifs.tsv new file mode 100644 index 0000000..cdd7b4d --- /dev/null +++ b/nanomotif/datasets/geobacillus-plasmids.motifs.tsv @@ -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 From c3461ee1c741000d6fead9eeecbef1ca735d4f44 Mon Sep 17 00:00:00 2001 From: SebastianDall Date: Wed, 22 Jan 2025 09:17:22 +0100 Subject: [PATCH 4/5] added cli tests --- .gitignore | 1 + tests/test_cli_commands.py | 54 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 tests/test_cli_commands.py diff --git a/.gitignore b/.gitignore index 0f92b86..e38f7b8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ data +tests/cli/ nanomotif/flamegraph* austin results diff --git a/tests/test_cli_commands.py b/tests/test_cli_commands.py new file mode 100644 index 0000000..6a43873 --- /dev/null +++ b/tests/test_cli_commands.py @@ -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 + From 81fa2f0766e9f809ab6d4b5af584d3210ffd1ab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Heidelbach?= <42008781+SorenHeidelbach@users.noreply.github.com> Date: Wed, 22 Jan 2025 09:28:15 +0100 Subject: [PATCH 5/5] Update _version.py --- nanomotif/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nanomotif/_version.py b/nanomotif/_version.py index 7225152..43a1e95 100644 --- a/nanomotif/_version.py +++ b/nanomotif/_version.py @@ -1 +1 @@ -__version__ = "0.5.2" +__version__ = "0.5.3"