Sequence¶
The Sequence object contains classes that represent biological sequence data. These provide generic biological sequence manipulation functions, plus functions that are critical for the evolve module calculations.
Warning
Do not import sequence classes directly! It is expected that you will access them through MolType objects. The molecular types can be accessed via the cogent3.get_moltype() function. Sequence classes depend on information from the MolType that is only available after MolType has been imported. Sequences are intended to be immutable. This is not enforced by the code for performance reasons, but don’t alter the MolType or the sequence data after creation.
DNA and RNA sequences¶
Creating a DNA sequence from a string¶
All sequence and alignment objects have a molecular type, or MolType which provides key properties for validating sequence characters. Here we use the DNA MolType to create a DNA sequence.
Creating a RNA sequence from a string¶
Converting to FASTA format¶
Convert a RNA sequence to FASTA format¶
Creating a named sequence¶
You can also use a convenience make_seq() function, providing the moltype as a string.
Setting or changing the name of a sequence¶
Complementing a DNA sequence¶
Reverse complementing a DNA sequence¶
The rc method name is easier to type
Translate a DnaSequence to protein¶
Converting a DNA sequence to RNA¶
Convert an RNA sequence to DNA¶
Testing complementarity¶
Joining two DNA sequences¶
Slicing DNA sequences¶
Getting 3rd positions from codons¶
The easiest approach is to work off the cogent3 ArrayAlignment object.
We’ll do this by specifying the position indices of interest, creating a sequence Feature and using that to extract the positions.
Getting 1st and 2nd positions from codons¶
In this instance we can use the annotatable sequence classes.
Return a randomized version of the sequence¶
print rnaseq.shuffle()
ACAACUGGCUCUGAUG