Skip to content

Commit

Permalink
chnages in annotation action
Browse files Browse the repository at this point in the history
  • Loading branch information
VinzentRisch committed Jul 23, 2024
1 parent 16b413f commit 869e03c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 23 deletions.
24 changes: 13 additions & 11 deletions q2_amr/amrfinderplus/sample_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ def annotate_sample_data_amrfinderplus(
GenesDirectoryFormat,
pd.DataFrame,
):
annotations = AMRFinderPlusAnnotationsDirFmt()
mutations = AMRFinderPlusAnnotationsDirFmt()
genes = GenesDirectoryFormat()
amr_annotations = AMRFinderPlusAnnotationsDirFmt()
amr_all_mutations = AMRFinderPlusAnnotationsDirFmt()
amr_genes = GenesDirectoryFormat()
frequency_list = []

# Create list of paths to all mags or contigs
Expand Down Expand Up @@ -86,20 +86,22 @@ def annotate_sample_data_amrfinderplus(

# Move mutations file. If it is not created, create an empty mutations file
des_path_mutations = os.path.join(
str(mutations),
str(amr_all_mutations),
sample_id,
f"{mag_id + '_' if mag_id else ''}amr_mutations.tsv",
f"{mag_id + '_' if mag_id else ''}amr_all_mutations.tsv",
)
os.makedirs(os.path.dirname(des_path_mutations), exist_ok=True)
if organism:
shutil.move(os.path.join(tmp, "amr_mutations.tsv"), des_path_mutations)
shutil.move(
os.path.join(tmp, "amr_all_mutations.tsv"), des_path_mutations
)
else:
with open(des_path_mutations, "w"):
pass

# Move annotations file
des_path_annotations = os.path.join(
str(annotations),
str(amr_annotations),
sample_id,
f"{mag_id + '_' if mag_id else ''}amr_annotations.tsv",
)
Expand All @@ -110,14 +112,14 @@ def annotate_sample_data_amrfinderplus(
shutil.move(
os.path.join(tmp, "amr_genes.fasta"),
os.path.join(
str(genes), f"{mag_id if mag_id else sample_id}_amr_genes.fasta"
str(amr_genes), f"{mag_id if mag_id else sample_id}_amr_genes.fasta"
),
)

feature_table = create_count_table(df_list=frequency_list)
return (
annotations,
mutations,
genes,
amr_annotations,
amr_all_mutations,
amr_genes,
feature_table,
)
6 changes: 3 additions & 3 deletions q2_amr/amrfinderplus/tests/test_sample_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ def mock_run_amrfinderplus_n(
with open(os.path.join(working_dir, "amr_annotations.tsv"), "w"):
pass
if organism:
with open(os.path.join(working_dir, "amr_mutations.tsv"), "w"):
with open(os.path.join(working_dir, "amr_all_mutations.tsv"), "w"):
pass
if dna_sequences:
with open(os.path.join(working_dir, "amr_genes.fasta"), "w"):
pass

files_contigs = [
"amr_annotations.tsv",
"amr_mutations.tsv",
"amr_all_mutations.tsv",
"sample1_amr_genes.fasta",
]

files_mags = [
"mag1_amr_annotations.tsv",
"mag1_amr_mutations.tsv",
"mag1_amr_all_mutations.tsv",
"mag1_amr_genes.fasta",
]

Expand Down
2 changes: 1 addition & 1 deletion q2_amr/amrfinderplus/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_run_amrfinderplus_n(self, mock_run_command):
"--organism",
"Escherichia",
"--mutation_all",
"path_dir/amr_mutations.tsv",
"path_dir/amr_all_mutations.tsv",
"--plus",
"--report_all_equal",
"--ident_min",
Expand Down
2 changes: 1 addition & 1 deletion q2_amr/amrfinderplus/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def run_amrfinderplus_n(
"--organism",
organism,
"--mutation_all",
f"{working_dir}/amr_mutations.tsv",
f"{working_dir}/amr_all_mutations.tsv",
]
)
if plus:
Expand Down
14 changes: 7 additions & 7 deletions q2_amr/plugin_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1173,9 +1173,9 @@
"threads": Int % Range(0, None, inclusive_start=False),
},
outputs=[
("annotations", SampleData[AMRFinderPlusAnnotations]),
("mutations", SampleData[AMRFinderPlusAnnotations]),
("genes", GenomeData[Genes]),
("amr_annotations", SampleData[AMRFinderPlusAnnotations]),
("amr_all_mutations", SampleData[AMRFinderPlusAnnotations]),
("amr_genes", GenomeData[Genes]),
("feature_table", FeatureTable[Frequency]),
],
input_descriptions={
Expand Down Expand Up @@ -1210,8 +1210,8 @@
"fail. Using more than 4 threads may speed up searches.",
},
output_descriptions={
"annotations": "Annotated AMR genes and mutations.",
"mutations": "Report of genotypes at all locations screened for point "
"amr_annotations": "Annotated AMR genes and mutations.",
"amr_all_mutations": "Report of genotypes at all locations screened for point "
"mutations. These files allow you to distinguish between called "
"point mutations that were the sensitive variant and the point "
"mutations that could not be called because the sequence was not "
Expand All @@ -1224,8 +1224,8 @@
"'Gene symbols' from known point-mutation sites have gene symbols "
"that match the Pathogen Detection Reference Gene Catalog "
"standardized nomenclature for point mutations.",
"genes": "Sequences that were identified by AMRFinderPlus as AMR genes. This "
"will include the entire region that aligns to the references for "
"amr_genes": "Sequences that were identified by AMRFinderPlus as AMR genes. "
"This will include the entire region that aligns to the references for "
"point mutations.",
"feature_table": "Presence/Absence table of ARGs in all samples.",
},
Expand Down

0 comments on commit 869e03c

Please sign in to comment.