Package: biodatatypes
biodatatypesPure-Python package for handling biological sequence datatypes as Enum objects.InstallationpipinstallbiodatatypesBasic usagefrombiodatatypesimportNucleotide,AminoAcid,CodonfrombiodatatypesimportNucleotideSequence,AminoAcidSequence,CodonSequence# Nucleotidenucleotide_a=Nucleotide['A']nucleotide_c=Nucleotide.Cnucleotide_g=Nucleotide.from_str('G')nucleotide_t=Nucleotide(4)gap=Nucleotide.from_str('-')also_gap=Nucleotide.Gap# AminoAcidamino_acid_ala=AminoAcid['Ala']amino_acid_arg=AminoAcid.Argamino_acid_asn=AminoAcid.from_str('N')amino_acid_gly=AminoAcid.from_str('Gly')amino_acid_asp=AminoAcid(4)stop=AminoAcid['Stop']also_stop=AminoAcid.from_str('Ter')also_also_stop=AminoAcid.from_str('*')# Codoncodon_gca=Codon['GCA']codon_gcg=Codon.GCGcodon_gct=Codon.from_str('GCT')codon_aat=Codon(4)codon_atg=Codon.start_codon()# NucleotideSequencenucleotide_sequence=NucleotideSequence.from_str('ATGAAACGATAG')gapped_nucleotide_sequence=NucleotideSequence.from_str('ATG-AACGA--AG')masked_nucleotide_sequence=NucleotideSequence.from_str('ATG#AA##ATAG')print(nucleotide_sequence)# ATGAAACGATAGprint(repr(nucleotide_sequence))# ATGAAACGATAGprint(gapped_nucleotide_sequence)# ATG-AACGA--AGprint(masked_nucleotide_sequence)# ATG#AA##ATAG# AminoAcidSequenceamino_acid_sequence=AminoAcidSequence.from_str('ACDE')gapped_amino_acid_sequence=AminoAcidSequence.from_str('A-C-E')masked_amino_acid_sequence=AminoAcidSequence.from_str('A#DE')print(amino_acid_sequence)# ACDEprint(gapped_amino_acid_sequence)# A-C-Eprint(masked_amino_acid_sequence)# A#DE# CodonSequencecodon_sequence=CodonSequence.from_str('ATGAAACGATAG')gapped_codon_sequence=CodonSequence.from_str('ATGAAA---CGATAG')masked_codon_sequence=CodonSequence.from_str('ATG###CGATAG')print(codon_sequence)# ATGAAACGATAGprint(repr(codon_sequence))# ATG AAA CGA TAGprint(gapped_codon_sequence)# ATGAAA---CGATAGprint(masked_codon_sequence)# ATG###CGATAGMaking custom datatypesWhile default datatypesNucleotide,AminoAcid, andCodonare provided, it is possible to create custom nucleotide, amino acid, and codon datatypes by subclassingNucleotideEnum,AminoAcidEnum, andCodonEnumrespectively.Custom nucleotide enumfrombiodatatypes.unit.baseimportNucleotideEnum,AminoAcidEnum,CodonEnumfrombiodatatypes.unit.mixinsimportGapTokenMixin,MaskTokenMixin# Create a custom nucleotide enumclassMyNucleotide(GapTokenMixin,NucleotideEnum):A=1C=2G=3T=4Gap=5my_a=MyNucleotide['A']my_c=MyNucleotide.Cmy_g=MyNucleotide.from_str('G')my_t=MyNucleotide(4)my_gap=MyNucleotide.from_str('-')# Use methods inherited from NucleotideEnumprint(my_a.is_purine())# Trueprint(my_c.is_purine())# Falseprint(my_a.is_gap())# Falseprint(my_gap.is_gap())# Trueprint(my_a.is_standard())# Trueprint(my_t.to_onehot())# [0, 0, 0, 0, 1]print(my_c.to_complement())# GNucleotideEnumcontains methods for handling standard nucleotides.To extend functionality to handle gaps, useGapTokenMixintogether with the corresponding enum class (e.g.NucleotideEnumfor nucleotides).GapTokenMixinaddsis_gap()method to check if a token is a gap.
It expects that the gap token enum is namedGap(case-sensitive).To extend functionality to handle masks, useMaskTokenMixintogether with the corresponding enum class.MaskTokenMixinaddsis_mask()method to check if a token is a mask.
It expects that the mask token enum is namedMask(case-sensitive).To extend functionality to handle unspecified "other" nucleotides, useOtherTokenMixintogether with the corresponding enum class.OtherTokenMixinaddsis_other()method to check if a token is an unspecified "other" nucleotide.
It expects that the "other" token enum is namedOther(case-sensitive).To extend functionality to handle gaps, masks, and unspecified "other" nucleotides, useSpecialTokenMixintogether with the corresponding enum class.SpecialTokenMixinaddsis_special()method to check if a token is a gap, mask, or other.
The same enum name requirements apply as above.Custom amino acid enumSimilarly, custom amino acid enums can be created by subclassingAminoAcidEnum.
Amino acid enums are expected to use the the IUPAC three-letter amino acid codes as enum names.If the termination signal token is included, it is expected to be namedStop(case-sensitive).
The termination token has a one-letter code of*and a three-letter code ofTer.frombiodatatypes.unit.baseimportAminoAcidEnumfrombiodatatypes.unit.mixinsimportGapTokenMixin,MaskTokenMixin# Create a custom amino acid enum# Add mixins to extend functionality when non-standard amino acid tokens (gap, mask) are expectedclassMyAminoAcid(MaskTokenMixin,GapTokenMixin,AminoAcidEnum):Ala=1Arg=2Asn=3Asp=4Gap=5Mask=6Stop=7my_ala=MyAminoAcid['Ala']my_arg=MyAminoAcid.Argmy_asn=MyAminoAcid.from_str('N')my_gap=MyAminoAcid.from_str('-')my_mask=MyAminoAcid.Maskmy_stop=MyAminoAcid['Stop']print(my_asn.is_polar())# Trueprint(my_ala.is_polar())# Falseprint(my_gap.is_gap())# Trueprint(my_ala.is_gap())# Falseprint(my_mask.is_mask())# Trueprint(my_asn.has_amide())# Trueprint(my_asn.to_one_letter())# NThe same mixins used forNucleotideEnumcan be used forAminoAcidEnumto extend functionality to handle gaps, masks, and unspecified "other" amino acids.
The same enum name requirements apply as previously mentioned for making custom nucleotide enums.Custom codon enumWhen creating a custom codon enum, aside from specifying the enumerations using the IUPAC three-letter codon codes, it is also necessary to specify associated nucleotide and amino acid enums by overriding thenucleotide_classandaminoacid_classgetter methods.Thenucleotide_classproperty is used when callingfrom_nucleotidesandto_nucleotides()methods to convert the codon to and from a triplet nucleotide sequence.
Theaminoacid_classproperty is used when calling thetranslate()method to translate the codon to an amino acid based on the standard genetic code.
It is not necessary to create custom nucleotide and amino acid enums for this purpose as the includedNucleotideandAminoAcidcan be used, but it is necessary to specify the corresponding enum classes.frombiodatatypesimportNucleotide,AminoAcidfrombiodatatypes.unit.baseimportCodonEnumfrombiodatatypes.unit.mixinsimportGapTokenMixin,MaskTokenMixin# Create a custom codon enum# Add mixins to extend functionality when non-standard codon tokens (gap, mask) are expectedclassMyCodon(MaskTokenMixin,GapTokenMixin,CodonEnum):GCA=1GCG=2GCT=3TAG=4Gap=5Mask=6ATG=7@propertydefnucleotide_class(self):returnNucleotide@propertydefaminoacid_class(self):returnMyAminoAcidmy_gca=MyCodon['GCA']my_gcg=MyCodon.GCGmy_gct=MyCodon.from_str('GCT')my_gap=MyCodon.from_str('---')my_mask=MyCodon.Maskmy_atg=MyCodon.start_codon()print(my_gca.is_fourfold_degenerate())# True, GCA, GCC, GCG, GCT encode Alaprint(my_atg.is_start_codon())# Trueprint(my_atg.is_stop_codon())# Falseprint(my_gap.is_gap())# Trueprint(my_mask.is_mask())# Trueprint(my_gca.translate())# AThe same mixins can be used forCodonEnumto extend functionality to handle gaps, masks, and unspecified "other" codons. The same enum name requirements apply as previously mentioned for making custom nucleotide and amino acid enums.LicenseMIT LicenseAuthorKent Kawashima