Skip to content

Commit

Permalink
change to name an classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sann5 committed Jun 10, 2024
1 parent c6e61af commit 9ae98e1
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 139 deletions.
36 changes: 16 additions & 20 deletions q2_types/profile_hmms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------
from ._format import (
ProteinHmmMultipleProfilesFileFmt,
DnaHmmMultipleProfilesFileFmt,
RnaHmmMultipleProfilesFileFmt,
ProteinHmmMultipleProfilesDirectoryFormat,
DnaHmmMultipleProfilesDirectoryFormat,
RnaHmmMultipleProfilesDirectoryFormat,
ProteinHmmFileFmt, DnaHmmFileFmt, RnaHmmFileFmt,
ProteinHmmDirectoryFormat, DnaHmmDirectoryFormat, RnaHmmDirectoryFormat,
BaseHmmPressedDirFmt
PressedProfileHmmsDirectoryFmt,
ProteinSingleProfileHmmDirectoryFmt,
ProteinMultipleProfileHmmDirectoryFmt,
DnaSingleProfileHmmDirectoryFmt,
DnaMultipleProfileHmmDirectoryFmt,
RnaSingleProfileHmmDirectoryFmt,
RnaMultipleProfileHmmDirectoryFmt
)
from ._type import (
ProfileHMM,
Expand All @@ -24,17 +22,15 @@
)

__all__ = [
"ProteinHmmMultipleProfilesFileFmt",
"DnaHmmMultipleProfilesFileFmt",
"RnaHmmMultipleProfilesFileFmt",
"ProteinHmmMultipleProfilesDirectoryFormat",
"DnaHmmMultipleProfilesDirectoryFormat",
"RnaHmmMultipleProfilesDirectoryFormat",
"ProteinHmmFileFmt", "DnaHmmFileFmt", "RnaHmmFileFmt",
"ProteinHmmDirectoryFormat",
"DnaHmmDirectoryFormat",
"RnaHmmDirectoryFormat",
"BaseHmmPressedDirFmt",
"ProfileHmmBinaryFileFmt",
"PressedProfileHmmsDirectoryFmt",
"ProfileHmmFileFmt",
"ProteinSingleProfileHmmDirectoryFmt",
"ProteinMultipleProfileHmmDirectoryFmt",
"DnaSingleProfileHmmDirectoryFmt",
"DnaMultipleProfileHmmDirectoryFmt",
"RnaSingleProfileHmmDirectoryFmt",
"RnaMultipleProfileHmmDirectoryFmt",
"ProfileHMM",
"SingleProtein", "SingleDNA", "SingleRNA",
"MultipleProtein", "MultipleDNA", "MultipleRNA",
Expand Down
112 changes: 53 additions & 59 deletions q2_types/profile_hmms/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
from q2_types.plugin_setup import plugin


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


class BaseHmmPressedDirFmt(model.DirectoryFormat):
class PressedProfileHmmsDirectoryFmt(model.DirectoryFormat):
"""
The <hmmfile>.h3m file contains the profile HMMs
and their annotation in a binary format. The <hmmfile>.h3i file is an
Expand All @@ -25,16 +25,14 @@ class BaseHmmPressedDirFmt(model.DirectoryFormat):
(the MSV filter). The <hmmfile>.h3p file contains precomputed data
structures for the rest of each profile.
"""
h3m = model.File(r'.*\.hmm\.h3m', format=HmmBinaryFileFmt)
h3i = model.File(r'.*\.hmm\.h3i', format=HmmBinaryFileFmt)
h3f = model.File(r'.*\.hmm\.h3f', format=HmmBinaryFileFmt)
h3p = model.File(r'.*\.hmm\.h3p', format=HmmBinaryFileFmt)
h3m = model.File(r'.*\.hmm\.h3m', format=ProfileHmmBinaryFileFmt)
h3i = model.File(r'.*\.hmm\.h3i', format=ProfileHmmBinaryFileFmt)
h3f = model.File(r'.*\.hmm\.h3f', format=ProfileHmmBinaryFileFmt)
h3p = model.File(r'.*\.hmm\.h3p', format=ProfileHmmBinaryFileFmt)


class HmmBaseFileFmt(model.TextFileFormat):
def _validate_file_fmt(
self, level: str, alphabet: str, single_profile: bool
):
class ProfileHmmFileFmt(model.TextFileFormat):
def _validate_(self, level: str):
"""
Check http://eddylab.org/software/hmmer/Userguide.pdf
section "HMMER profile HMM files" for full description of
Expand All @@ -52,92 +50,88 @@ def _validate_file_fmt(
f"{e}"
)

if len(hmm_profiles) > 1 and single_profile:
if len(hmm_profiles) > 1 and self.single_profile:
raise ValidationError(
f"Expected 1 profile, found {len(hmm_profiles)}."
)

for hmm_profile in hmm_profiles[:parse_n_profiles]:
hmm_profile.validate(tolerance=tolerance)

if hmm_profile.alphabet.type.lower() != alphabet:
if hmm_profile.alphabet.type.lower() != self.alphabet:
raise ValidationError(
"Found profile with alphabet "
f"{hmm_profile.alphabet.type.lower()}\n"
f"{self.__class__} only accepts {alphabet} profiles."
f"Expected alphabet: {self.alphabet}."
)


class ProteinHmmFileFmt(HmmBaseFileFmt):
class ProteinProfileHmmFileFmt(ProfileHmmFileFmt):
alphabet = "amino"

def _validate_(self, level):
self._validate_file_fmt(level, self.alphabet, True)

class ProteinSingleProfileHmmFileFmt(ProteinProfileHmmFileFmt):
single_profile = True


class ProteinMultipleProfileHmmFileFmt(ProteinProfileHmmFileFmt):
single_profile = False

class DnaHmmFileFmt(HmmBaseFileFmt):

class DnaProfileHmmFileFmt(ProfileHmmFileFmt):
alphabet = "dna"

def _validate_(self, level):
self._validate_file_fmt(level, self.alphabet, True)

class DnaSingleProfileHmmFileFmt(DnaProfileHmmFileFmt):
single_profile = True

class RnaHmmFileFmt(HmmBaseFileFmt):

class DnaMultipleProfileHmmFileFmt(DnaProfileHmmFileFmt):
single_profile = False


class RnaProfileHmmFileFmt(ProfileHmmFileFmt):
alphabet = "rna"

def _validate_(self, level):
self._validate_file_fmt(level, self.alphabet, True)

class RnaSingleProfileHmmFileFmt(RnaProfileHmmFileFmt):
single_profile = True

ProteinHmmDirectoryFormat = model.SingleFileDirectoryFormat(
'AminoHmmFileFmt', r'.*\..hmm', ProteinHmmFileFmt)

DnaHmmDirectoryFormat = model.SingleFileDirectoryFormat(
'DnaHmmFileFmt', r'.*\..hmm', DnaHmmFileFmt)
class RnaMultipleProfileHmmFileFmt(RnaProfileHmmFileFmt):
single_profile = False

RnaHmmDirectoryFormat = model.SingleFileDirectoryFormat(
'RnaHmmFileFmt', r'.*\..hmm', RnaHmmFileFmt)

class ProteinSingleProfileHmmDirectoryFmt(model.DirectoryFormat):
profile = model.File(r'.*\.hmm', format=ProteinSingleProfileHmmFileFmt)

class ProteinHmmMultipleProfilesFileFmt(ProteinHmmFileFmt):
def _validate_(self, level):
self._validate_file_fmt(level, self.alphabet, False)

class ProteinMultipleProfileHmmDirectoryFmt(model.DirectoryFormat):
profiles = model.File(r'.*\.hmm', format=ProteinMultipleProfileHmmFileFmt)

class DnaHmmMultipleProfilesFileFmt(DnaHmmFileFmt):
def _validate_(self, level):
self._validate_file_fmt(level, self.alphabet, False)

class DnaSingleProfileHmmDirectoryFmt(model.DirectoryFormat):
profile = model.File(r'.*\.hmm', format=DnaSingleProfileHmmFileFmt)

class RnaHmmMultipleProfilesFileFmt(RnaHmmFileFmt):
def _validate_(self, level):
self._validate_file_fmt(level, self.alphabet, False)

class DnaMultipleProfileHmmDirectoryFmt(model.DirectoryFormat):
profiles = model.File(r'.*\.hmm', format=DnaMultipleProfileHmmFileFmt)

ProteinHmmMultipleProfilesDirectoryFormat = model.SingleFileDirectoryFormat(
'AminoHmmMultipleProfilesDirectoryFormat',
r'.*\..hmm',
ProteinHmmMultipleProfilesFileFmt
)

DnaHmmMultipleProfilesDirectoryFormat = model.SingleFileDirectoryFormat(
'DnaHmmMultipleProfilesDirectoryFormat',
r'.*\..hmm',
DnaHmmMultipleProfilesFileFmt,
)
class RnaSingleProfileHmmDirectoryFmt(model.DirectoryFormat):
profile = model.File(r'.*\.hmm', format=RnaSingleProfileHmmFileFmt)


class RnaMultipleProfileHmmDirectoryFmt(model.DirectoryFormat):
profiles = model.File(r'.*\.hmm', format=RnaMultipleProfileHmmFileFmt)

RnaHmmMultipleProfilesDirectoryFormat = model.SingleFileDirectoryFormat(
'RnaHmmMultipleProfilesDirectoryFormat',
r'.*\..hmm',
RnaHmmMultipleProfilesFileFmt,
)

plugin.register_formats(
ProteinHmmMultipleProfilesFileFmt,
DnaHmmMultipleProfilesFileFmt,
RnaHmmMultipleProfilesFileFmt,
ProteinHmmMultipleProfilesDirectoryFormat,
DnaHmmMultipleProfilesDirectoryFormat,
RnaHmmMultipleProfilesDirectoryFormat,
ProteinHmmDirectoryFormat, DnaHmmDirectoryFormat, RnaHmmDirectoryFormat
PressedProfileHmmsDirectoryFmt,
ProteinSingleProfileHmmDirectoryFmt,
ProteinMultipleProfileHmmDirectoryFmt,
DnaSingleProfileHmmDirectoryFmt,
DnaMultipleProfileHmmDirectoryFmt,
RnaSingleProfileHmmDirectoryFmt,
RnaMultipleProfileHmmDirectoryFmt
)
30 changes: 16 additions & 14 deletions q2_types/profile_hmms/_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
from qiime2.plugin import SemanticType
from q2_types.plugin_setup import plugin
from q2_types.profile_hmms._format import (
ProteinHmmMultipleProfilesDirectoryFormat,
DnaHmmMultipleProfilesDirectoryFormat,
RnaHmmMultipleProfilesDirectoryFormat,
ProteinHmmDirectoryFormat, DnaHmmDirectoryFormat, RnaHmmDirectoryFormat,
BaseHmmPressedDirFmt
PressedProfileHmmsDirectoryFmt,
DnaSingleProfileHmmDirectoryFmt,
DnaMultipleProfileHmmDirectoryFmt,
RnaSingleProfileHmmDirectoryFmt,
RnaMultipleProfileHmmDirectoryFmt,
ProteinSingleProfileHmmDirectoryFmt,
ProteinMultipleProfileHmmDirectoryFmt
)


Expand Down Expand Up @@ -54,7 +56,7 @@

plugin.register_artifact_class(
ProfileHMM[PressedProtein],
directory_format=BaseHmmPressedDirFmt,
directory_format=PressedProfileHmmsDirectoryFmt,
description=(
"A collection of profile Hidden Markov Models for amino acid "
"sequences in binary format and indexed."
Expand All @@ -63,7 +65,7 @@

plugin.register_artifact_class(
ProfileHMM[PressedDNA],
directory_format=BaseHmmPressedDirFmt,
directory_format=PressedProfileHmmsDirectoryFmt,
description=(
"A collection of profile Hidden Markov Models for DNA "
"sequences in binary format and indexed."
Expand All @@ -72,7 +74,7 @@

plugin.register_artifact_class(
ProfileHMM[PressedRNA],
directory_format=BaseHmmPressedDirFmt,
directory_format=PressedProfileHmmsDirectoryFmt,
description=(
"A collection of profile Hidden Markov Models for RNA "
"sequences in binary format and indexed."
Expand All @@ -81,7 +83,7 @@

plugin.register_artifact_class(
ProfileHMM[SingleProtein],
directory_format=ProteinHmmDirectoryFormat,
directory_format=ProteinSingleProfileHmmDirectoryFmt,
description=(
"One single profile Hidden Markov Model representing a group "
"of related proteins."
Expand All @@ -90,7 +92,7 @@

plugin.register_artifact_class(
ProfileHMM[SingleDNA],
directory_format=DnaHmmDirectoryFormat,
directory_format=DnaSingleProfileHmmDirectoryFmt,
description=(
"One single profile Hidden Markov Model representing a group "
"of related DNA sequences."
Expand All @@ -99,7 +101,7 @@

plugin.register_artifact_class(
ProfileHMM[SingleRNA],
directory_format=RnaHmmDirectoryFormat,
directory_format=RnaSingleProfileHmmDirectoryFmt,
description=(
"One single profile Hidden Markov Model representing a group "
"of related RNA sequences."
Expand All @@ -108,7 +110,7 @@

plugin.register_artifact_class(
ProfileHMM[MultipleProtein],
directory_format=ProteinHmmMultipleProfilesDirectoryFormat,
directory_format=ProteinMultipleProfileHmmDirectoryFmt,
description=(
"A collection of profile Hidden Markov Models, "
"each representing a group of related proteins."
Expand All @@ -117,7 +119,7 @@

plugin.register_artifact_class(
ProfileHMM[MultipleDNA],
directory_format=DnaHmmMultipleProfilesDirectoryFormat,
directory_format=DnaMultipleProfileHmmDirectoryFmt,
description=(
"A collection of profile Hidden Markov Models, "
"each representing a group of related DNA sequences."
Expand All @@ -126,7 +128,7 @@

plugin.register_artifact_class(
ProfileHMM[MultipleRNA],
directory_format=RnaHmmMultipleProfilesDirectoryFormat,
directory_format=RnaMultipleProfileHmmDirectoryFmt,
description=(
"A collection of profile Hidden Markov Models, "
"each representing a group of related RNA sequences."
Expand Down
Loading

0 comments on commit 9ae98e1

Please sign in to comment.