from cogent3 import make_aligned_seqs
aln = make_aligned_seqs({"s1": "ACGACGACG", "s2": "GATGATGAT"}, moltype="dna")
aln| 0 | |
| s1 | ACGACGACG |
| s2 | GATGATGAT |
2 x 9 dna alignment
The take_codon_positions app allows you to extract all nucleotides at a given codon position from an alignment.
Let’s create a sample alignment for our example.
| 0 | |
| s1 | ACGACGACG |
| s2 | GATGATGAT |
2 x 9 dna alignment
We can achieve this by creating the take_codon_positions app with 3 as a positional argument.
We can achieve this by creating the take_codon_positions app with 1 and 2 as a positional argument.
We can achieve this by creating the take_codon_positions app with the argument fourfold_degenerate=True.
Let’s set up a data store containing all the files with the “.fasta” suffix in the data directory, limiting the data store to two members as a minimum example.
Now let’s set up a process composing the following apps: load_aligned (loads the sequences ), take_codon_positions (extracts the third codon position), and write_seqs (writes the filtered sequences to a data store).
Learn the basics of turning apps into composed processes here!
from cogent3 import get_app, open_data_store
out_dstore = open_data_store(path_to_dir, suffix="fa", mode="w")
loader = get_app("load_aligned", format_name="fasta", moltype="dna")
cpos3 = get_app("take_codon_positions", 3)
writer = get_app("write_seqs", out_dstore, format_name="fasta")
process = loader + cpos3 + writerWhen running this code on your machine, remember to replace path_to_dir with an actual directory path.
Now let’s apply process to our data store! This populates out_dstore (which is returned by the .apply_to() call) with the filtered alignments. We can index out_dstore to see individual data members. We could take a closer look using the .read() method on data members.