Пример #1
0
def revtrans(
    input, output, codon_table, codon_usage, sampler, codon_freq_threshold, amber_only
):
    """Reverse translate amino acid sequences into DNA

    This operation randomly samples codons for each amino acid, so multiple runs
    of this tool on the same input can produce different results

    Note: only the Standard codon table is currently implemented.
    Note: only the E. coli codon usage is currently implemented.

    INPUT and OUTPUT are paths to fasta files or "-" to specify STDIN/STDOUT.

    """
    if sampler == "weighted":
        usage = ecoli_codon_usage
        if codon_freq_threshold is not None:
            # TODO: this is hardcoded in and there's a leaky abstraction here
            table = standard_dna_table
            usage = zero_low_freq_codons(usage, table, codon_freq_threshold)
        if amber_only:
            usage = zero_non_amber_stops(usage)
        codon_sampler = FreqWeightedCodonSampler(usage=usage)
    elif sampler == "uniform":
        codon_sampler = UniformCodonSampler()
    for seqrecord in tqdm(SeqIO.parse(input, "fasta"), desc="revtrans", unit="seq"):
        dna_id = seqrecord.id
        dna_seq = reverse_translate(seqrecord.seq, codon_sampler)
        print_fasta(SeqRecord(dna_seq, dna_id, description=""), output)
Пример #2
0
 def test_freq_weighted_sampler(self):
     with warnings.catch_warnings():  # biopython Seq.__hash__
         warnings.simplefilter("ignore")
         codon_sampler = FreqWeightedCodonSampler(usage=ecoli_codon_usage)
     dna_seq = reverse_translate(all_aa_protein_seq, codon_sampler)
     assert dna_seq.translate(
         table=codon_sampler.table) == all_aa_protein_seq
Пример #3
0
 def test_uniform_sampler(self):
     codon_sampler = UniformCodonSampler()
     dna_seq = reverse_translate(all_aa_protein_seq, codon_sampler)
     assert dna_seq.translate(
         table=codon_sampler.table) == all_aa_protein_seq
Пример #4
0
 def test_freq_weighted_sampler(self):
     codon_sampler = FreqWeightedCodonSampler(usage=ecoli_codon_usage)
     dna_seq = reverse_translate(all_aa_protein_seq, codon_sampler)
     assert dna_seq.translate(
         table=codon_sampler.table) == all_aa_protein_seq