Skip to content

Commit

Permalink
MAINT: Removed overall-mapping-stats.txt from CARDGeneAnnotationDirec…
Browse files Browse the repository at this point in the history
…toryFormat
  • Loading branch information
VinzentRisch committed Jan 10, 2024
1 parent 1963544 commit cc386b3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
11 changes: 6 additions & 5 deletions q2_amr/card/reads.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -215,9 +218,7 @@ def extract_sample_stats(samp_dir: str):

def visualize_annotation_stats(
output_dir: str,
amr_reads_annotation: Union[
CARDGeneAnnotationDirectoryFormat, CARDAlleleAnnotationDirectoryFormat
],
amr_reads_annotation: CARDAlleleAnnotationDirectoryFormat,
):
directory = str(amr_reads_annotation)
sample_stats = {}
Expand Down
6 changes: 2 additions & 4 deletions q2_amr/plugin_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
6 changes: 4 additions & 2 deletions q2_amr/tests/card/test_reads.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,12 @@ def annotate_reads_card_test_body(self, read_type):

# Assert if the expected files are in every sample directory and in both
# 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(
Expand Down
7 changes: 0 additions & 7 deletions q2_amr/types/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cc386b3

Please sign in to comment.