Skip to content

Commit

Permalink
dirformat with filecollections
Browse files Browse the repository at this point in the history
  • Loading branch information
VinzentRisch committed Jul 1, 2024
1 parent d33e0cb commit 32e8b7c
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
11 changes: 10 additions & 1 deletion q2_amr/amrfinderplus/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,14 @@
#
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------
from q2_amr.amrfinderplus.types._format import (
AMRFinderPlusDatabaseDirectoryFormat,
BinaryFormat,
TextFormat,
)

__all__ = []
__all__ = [
"AMRFinderPlusDatabaseDirectoryFormat",
"TextFormat",
"BinaryFormat",
]
35 changes: 35 additions & 0 deletions q2_amr/amrfinderplus/types/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,38 @@
#
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------
from q2_types.feature_data import MixedCaseDNAFASTAFormat, ProteinFASTAFormat
from qiime2.plugin import model


class TextFormat(model.TextFileFormat):
def _validate_(self, level):
pass


class BinaryFormat(model.BinaryFileFormat):
def _validate_(self, level):
pass


class AMRFinderPlusDatabaseDirectoryFormat(model.DirectoryFormat):
AMR_LIB = model.File("AMR.LIB", format=TextFormat)
AMR_LIB_comp = model.FileCollection(r"AMR\.LIB\.h3.$", format=BinaryFormat)
AMRProt = model.File("AMRProt", format=ProteinFASTAFormat)
AMRProt_blast = model.FileCollection(r"AMRProt\.p..$", format=BinaryFormat)
AMRProt_mutation = model.File("AMRProt-mutation.tab", format=TextFormat)
AMRProt_suppress = model.File("AMRProt-suppress", format=TextFormat)
AMRProt_susceptible = model.File("AMRProt-susceptible.tab", format=TextFormat)
changes = model.File("changes.txt", format=TextFormat)
db_version = model.File("database_format_version.txt", format=TextFormat)
fam = model.File("fam.tab", format=TextFormat)
taxgroup = model.File("taxgroup.tab", format=TextFormat)
version = model.File("version.txt", format=TextFormat)
AMR_DNA = model.FileCollection(
r"^AMR_DNA-[a-zA-Z_]+$", format=MixedCaseDNAFASTAFormat
)
AMR_DNA_comp = model.FileCollection(
r"^AMR_DNA-[a-zA-Z_]+\.n..$", format=BinaryFormat
)
AMR_CDS_comp = model.FileCollection(r"^AMR_CDS\.n..$", format=BinaryFormat)
AMR_CDS = model.File("AMR_CDS", format=MixedCaseDNAFASTAFormat)
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,16 @@
#
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------
from qiime2.plugin.testing import TestPluginBase

from q2_amr.amrfinderplus.types._format import AMRFinderPlusDatabaseDirectoryFormat


class TestAMRFinderPlusDatabaseTypesAndFormats(TestPluginBase):
package = "q2_amr.amrfinderplus.types.tests"

def test_amrfinderplus_database_directory_format_validate_positive(self):
format = AMRFinderPlusDatabaseDirectoryFormat(
"/Users/rischv/Documents/data/amrfinder/database", mode="r"
)
format.validate()
14 changes: 14 additions & 0 deletions q2_amr/plugin_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
from qiime2.plugin import Citations, Plugin

from q2_amr import __version__
from q2_amr.amrfinderplus.types._format import (
AMRFinderPlusDatabaseDirectoryFormat,
BinaryFormat,
TextFormat,
)
from q2_amr.amrfinderplus.types._type import AMRFinderPlusDatabase
from q2_amr.card.database import fetch_card_db
from q2_amr.card.heatmap import heatmap
from q2_amr.card.mags import annotate_mags_card
Expand Down Expand Up @@ -468,6 +474,7 @@
CARDReadsGeneKmerAnalysis,
CARDReadsAlleleKmerAnalysis,
CARDMAGsKmerAnalysis,
AMRFinderPlusDatabase,
)

plugin.register_semantic_type_to_format(
Expand Down Expand Up @@ -498,6 +505,10 @@
SampleData[CARDMAGsKmerAnalysis],
artifact_format=CARDMAGsKmerAnalysisDirectoryFormat,
)
plugin.register_semantic_type_to_format(
AMRFinderPlusDatabase,
artifact_format=AMRFinderPlusDatabaseDirectoryFormat,
)
plugin.register_formats(
CARDKmerDatabaseDirectoryFormat,
CARDKmerJSONFormat,
Expand All @@ -522,6 +533,9 @@
CARDReadsKmerAnalysisJSONFormat,
CARDReadsGeneKmerAnalysisDirectoryFormat,
CARDReadsAlleleKmerAnalysisDirectoryFormat,
AMRFinderPlusDatabaseDirectoryFormat,
TextFormat,
BinaryFormat,
)

importlib.import_module("q2_amr.card.types._transformer")

0 comments on commit 32e8b7c

Please sign in to comment.