From 3f013525673d10185319542bc5e7cfdb5209e5b0 Mon Sep 17 00:00:00 2001 From: VinzentRisch <100149044+VinzentRisch@users.noreply.github.com> Date: Fri, 12 Jan 2024 10:30:01 +0100 Subject: [PATCH 1/3] MAINT: Removed "overall-mapping-stats.txt" from `CARDGeneAnnotationDirectoryFormat` (#29) --- q2_amr/card/reads.py | 7 +++++-- q2_amr/plugin_setup.py | 6 ++---- q2_amr/tests/card/test_reads.py | 5 ++++- q2_amr/types/_format.py | 7 ------- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/q2_amr/card/reads.py b/q2_amr/card/reads.py index 5a97bca..cd9c8d9 100644 --- a/q2_amr/card/reads.py +++ b/q2_amr/card/reads.py @@ -85,8 +85,11 @@ def annotate_reads_card( for map_type, des_dir in zip( ["allele", "gene"], [samp_allele_dir, samp_gene_dir] ): - files = [f"{map_type}_mapping_data.txt", "overall_mapping_stats.txt"] - + files = [f"{map_type}_mapping_data.txt"] + # mapping statistics only go to the allele directories + files.append( + "overall_mapping_stats.txt" + ) if map_type == "allele" else None for file in files: shutil.copy( os.path.join(samp_input_dir, "output." + file), diff --git a/q2_amr/plugin_setup.py b/q2_amr/plugin_setup.py index 413e850..941404d 100644 --- a/q2_amr/plugin_setup.py +++ b/q2_amr/plugin_setup.py @@ -196,11 +196,9 @@ plugin.visualizers.register_function( function=visualize_annotation_stats, - inputs={"amr_reads_annotation": CARDGeneAnnotation | CARDAlleleAnnotation}, + inputs={"amr_reads_annotation": SampleData[CARDAlleleAnnotation]}, parameters={}, - input_descriptions={ - "amr_reads_annotation": "AMR annotation mapped on alleles or genes." - }, + input_descriptions={"amr_reads_annotation": "AMR annotations on the allele level."}, parameter_descriptions={}, name="Visualize mapping statistics.", description="Visualize mapping statistics of an annotate-reads-card output.", diff --git a/q2_amr/tests/card/test_reads.py b/q2_amr/tests/card/test_reads.py index 4487edf..151b773 100644 --- a/q2_amr/tests/card/test_reads.py +++ b/q2_amr/tests/card/test_reads.py @@ -146,7 +146,10 @@ def annotate_reads_card_test_body(self, read_type): # resulting CARD annotation objects for num in [0, 1]: map_type = "allele" if num == 0 else "gene" - files = [f"{map_type}_mapping_data.txt", "overall_mapping_stats.txt"] + files = [f"{map_type}_mapping_data.txt"] + files.append( + "overall_mapping_stats.txt" + ) if map_type == "allele" else None for samp in ["sample1", "sample2"]: for file in files: self.assertTrue( diff --git a/q2_amr/types/_format.py b/q2_amr/types/_format.py index 2eb3d36..de8c44a 100644 --- a/q2_amr/types/_format.py +++ b/q2_amr/types/_format.py @@ -421,14 +421,7 @@ class CARDGeneAnnotationDirectoryFormat(MultiDirValidationMixin, model.Directory gene = model.FileCollection( r".+(gene_mapping_data.txt)$", format=CARDGeneAnnotationFormat ) - stats = model.FileCollection( - r".+(overall_mapping_stats.txt)$", format=CARDAnnotationStatsFormat - ) @gene.set_path_maker def gene_path_maker(self, sample_id): return "%s/gene_mapping_data.txt" % sample_id - - @stats.set_path_maker - def stats_path_maker(self, sample_id): - return "%s/overall_mapping_stats.txt" % sample_id From d7f131cc2fa64e67bc50b50dc71c4b8dec2fcb1f Mon Sep 17 00:00:00 2001 From: VinzentRisch <100149044+VinzentRisch@users.noreply.github.com> Date: Tue, 16 Jan 2024 15:52:44 +0100 Subject: [PATCH 2/3] DEV: Fixed Black GitHub action (#33) --- .github/workflows/black.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/black.yaml b/.github/workflows/black.yaml index 637820a..639b5af 100644 --- a/.github/workflows/black.yaml +++ b/.github/workflows/black.yaml @@ -1,13 +1,13 @@ -name: Lint +name: Black on: [push, pull_request] jobs: - lint: + black: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: psf/black@stable with: version: "23.12.1" - args: ". --check --extend-exclude '.*_version\.py$'" + options: ". --check --extend-exclude '.*_version\\.py$' --verbose" From c0ca96dac932d7986eec6b3169f737d46198e918 Mon Sep 17 00:00:00 2001 From: VinzentRisch <100149044+VinzentRisch@users.noreply.github.com> Date: Tue, 16 Jan 2024 16:35:34 +0100 Subject: [PATCH 3/3] ENH: Add aligner property to annotate-reads-card outputs (#20) --- q2_amr/plugin_setup.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/q2_amr/plugin_setup.py b/q2_amr/plugin_setup.py index 941404d..608d0b2 100644 --- a/q2_amr/plugin_setup.py +++ b/q2_amr/plugin_setup.py @@ -14,7 +14,7 @@ ) from q2_types.sample_data import SampleData from q2_types_genomics.per_sample_data import MAGs -from qiime2.core.type import Bool, Choices, Int, Range, Str +from qiime2.core.type import Bool, Choices, Int, Properties, Range, Str, TypeMap from qiime2.plugin import Citations, Plugin from q2_amr import __version__ @@ -118,6 +118,26 @@ citations=[citations["alcock_card_2023"]], ) +P_aligner, T_allele_annotation, T_gene_annotation = TypeMap( + { + Str + % Choices("kma"): ( + SampleData[CARDAlleleAnnotation % Properties("kma")], + SampleData[CARDGeneAnnotation % Properties("kma")], + ), + Str + % Choices("bowtie2"): ( + SampleData[CARDAlleleAnnotation % Properties("bowtie2")], + SampleData[CARDGeneAnnotation % Properties("bowtie2")], + ), + Str + % Choices("bwa"): ( + SampleData[CARDAlleleAnnotation % Properties("bwa")], + SampleData[CARDGeneAnnotation % Properties("bwa")], + ), + } +) + plugin.methods.register_function( function=annotate_reads_card, inputs={ @@ -125,14 +145,14 @@ "card_db": CARDDatabase, }, parameters={ - "aligner": Str % Choices(["kma", "bowtie2", "bwa"]), + "aligner": P_aligner, "threads": Int % Range(0, None, inclusive_start=False), "include_wildcard": Bool, "include_other_models": Bool, }, outputs=[ - ("amr_allele_annotation", SampleData[CARDAlleleAnnotation]), - ("amr_gene_annotation", SampleData[CARDGeneAnnotation]), + ("amr_allele_annotation", T_allele_annotation), + ("amr_gene_annotation", T_gene_annotation), ("allele_feature_table", FeatureTable[Frequency]), ("gene_feature_table", FeatureTable[Frequency]), ],