Skip to content

Alphabets

SeqLike catalog of alphabets.

parse_alphabet(alphabet)

This function parses and validates the 'alphabet' parameter of a SeqLike.

:param alphabet: str specifying 'NT', 'DNA', 'RNA', or 'AA', case insensitive. :returns: either the NT or AA alphabet string.

Source code in seqlike/alphabets.py
def parse_alphabet(alphabet: str) -> str:
    """
    This function parses and validates the 'alphabet' parameter of a SeqLike.

    :param alphabet: str specifying 'NT', 'DNA', 'RNA', or 'AA', case insensitive.
    :returns: either the NT or AA alphabet string.
    """
    # parse string designation to desired alphabet
    if isinstance(alphabet, str):
        alphabet = alphabet.upper()
        assert alphabet in ["NT", "DNA", "RNA", "AA"], "Invalid alphabet!"
    if alphabet in ["DNA", "NT", "RNA"]:
        return NT
    else:
        return AA