biotite.sequence.AlphabetMapper

class biotite.sequence.AlphabetMapper(source_alphabet, target_alphabet)[source]

Bases: object

This class is used for symbol code conversion from a source alphabet into a target alphabet.

This means that the symbol codes are converted from one to another alphabet so that the symbol itself is preserved. This class works for single symbol codes or an entire sequence code likewise.

Parameters
source_alphabet, target_alphabetAlphabet

The codes are converted from the source alphabet into the target alphabet. The target alphabet must contain at least all symbols of the source alphabet, but it is not required that the shared symbols are in the same order.

Examples

>>> source_alph = Alphabet(["A","C","G","T"])
>>> target_alph = Alphabet(["T","U","A","G","C"])
>>> mapper = AlphabetMapper(source_alph, target_alph)
>>> print(mapper[0])
2
>>> print(mapper[1])
4
>>> print(mapper[[1,1,3]])
[4 4 0]
>>> in_sequence = GeneralSequence(source_alph, "GCCTAT")
>>> print(in_sequence.code)
[2 1 1 3 0 3]
>>> print(in_sequence)
GCCTAT
>>> out_sequence = GeneralSequence(target_alph)
>>> out_sequence.code = mapper[in_sequence.code]
>>> print(out_sequence.code)
[3 4 4 0 2 0]
>>> print(out_sequence)
GCCTAT