Skip to content

Commit

Permalink
removed nested structure of annotaion type
Browse files Browse the repository at this point in the history
  • Loading branch information
VinzentRisch committed Jul 5, 2024
1 parent 78c4329 commit 34a34b8
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 50 deletions.
19 changes: 4 additions & 15 deletions q2_amr/amrfinderplus/types/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------
import os

import pandas as pd
from q2_types.feature_data import MixedCaseDNAFASTAFormat, ProteinFASTAFormat
from q2_types.per_sample_sequences._format import MultiDirValidationMixin
Expand Down Expand Up @@ -116,22 +114,13 @@ def _validate_(self, level):


class ARMFinderPlusAnnotationsDirFmt(MultiDirValidationMixin, model.DirectoryFormat):
annotation = model.FileCollection(r".+\.tsv$", format=ARMFinderPlusAnnotationFormat)
annotation = model.FileCollection(
r".+_amr_(annotations|mutations)\.tsv$", format=ARMFinderPlusAnnotationFormat
)

@annotation.set_path_maker
def annotation_path_maker(self, sample_id, mag_id):
return rf"{sample_id}/{mag_id}/.+\.tsv"

def sample_dict(self):
sample_dict = {}
for sample in self.path.iterdir():
mag_dict = {}
for mag in sample.iterdir():
mag_dict[mag.name] = [
os.path.join(mag, "amr_annotation.tsv"),
]
sample_dict[sample.name] = mag_dict
return sample_dict
return rf"{sample_id}/{mag_id}_amr_(annotations|mutations)\.tsv$"


ARMFinderPlusAnnotationDirFmt = model.SingleFileDirectoryFormat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------
import os

from qiime2.core.exceptions import ValidationError
from qiime2.plugin.testing import TestPluginBase

Expand All @@ -27,8 +25,8 @@ def test_amrfinderplus_database_directory_format_validate_positive(self):

def test_amrfinderplus_annotation_format_validate_positive(self):
filepath = self.get_data_path(
"annotation/no_coordinates/aa447c99-ecd9-4c4a-a53b-4df6999815dd"
"/amr_annotation.tsv"
"annotation/no_coordinates/"
"aa447c99-ecd9-4c4a-a53b-4df6999815dd_amr_annotations.tsv"
)

format = ARMFinderPlusAnnotationFormat(filepath, mode="r")
Expand All @@ -37,7 +35,7 @@ def test_amrfinderplus_annotation_format_validate_positive(self):
def test_amrfinderplus_annotation_format_validate_positive_coordinates(self):
filepath = self.get_data_path(
"annotation/coordinates/e026af61-d911-4de3-a957-7e8bf837f30d"
"/amr_annotation.tsv"
"_amr_annotations.tsv"
)
format = ARMFinderPlusAnnotationFormat(filepath, mode="r")
format.validate()
Expand Down Expand Up @@ -83,36 +81,6 @@ def test_amrfinderplus_annotation_format_validation_error(self):

self.assertEqual(str(context.exception), expected_message)

def test_amrfinderplus_annotations_directory_format_sample_dict(self):
dirpath = self.get_data_path("annotation")
annotations = ARMFinderPlusAnnotationsDirFmt(dirpath, mode="r")

obs = annotations.sample_dict()

exp = {
"coordinates": {
"e026af61-d911-4de3-a957-7e8bf837f30d": [
os.path.join(
annotations.path,
"coordinates",
"e026af61-d911-4de3-a957-7e8bf837f30d",
"amr_annotation.tsv",
),
]
},
"no_coordinates": {
"aa447c99-ecd9-4c4a-a53b-4df6999815dd": [
os.path.join(
annotations.path,
"no_coordinates",
"aa447c99-ecd9-4c4a-a53b-4df6999815dd",
"amr_annotation.tsv",
),
],
},
}
self.assertEqual(obs, exp)

def test_amrfinderplus_annotation_directory_format(self):
dirpath = self.get_data_path(
"annotation/coordinates/e026af61-d911-4de3-a957-7e8bf837f30d"
Expand Down

0 comments on commit 34a34b8

Please sign in to comment.