Knowee
Questions
Features
Study Tools

WAP to plot codon frequency in a given sequence

Question

WAP to plot codon frequency in a given sequence

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a simple Python script using Biopython and matplotlib to plot codon frequency in a given sequence:

from Bio import SeqIO
from Bio.SeqUtils import CodonUsage
import matplotlib.pyplot as plt

# Read the sequence
sequence = SeqIO.read("sequence.fasta", "fasta")

# Create a CodonUsage object
codon_usage = CodonUsage.CodonsDict

# Count codon usage in the sequence
for i in range(0, len(sequence.seq), 3):
    codon = sequence.seq[i:i+3]
    if codon in codon_usage:
        codon_usage[codon] += 1

# Plot codon frequency
plt.bar(codon_usage.keys(), codon_usage.values())
plt.show()

This script reads a sequence from a fasta file, counts the usage of each codon in the sequence, and plots the frequency of each codon.

Please replace "sequence.fasta" with your actual fasta file. Also, this script assumes that the sequence is divisible by 3. If it's not, you might want to add some error checking code to handle the last 1 or 2 bases.

Note: You need to have Biopython and matplotlib installed in your Python environment to run this script. You can install them using pip:

pip install biopython matplotlib

This problem has been solved

Similar Questions

WAP for searching a pattern in a string motif finding

WAP a program to generate a list of elements of Fibonacci Series.

WAP to print the prime numbers between 1 – 100

Compute the frequencycount of the following code fragment.for(i=0;i<n; i++)for(j=0;j<n; j++)printf(“%d”,a[i][j]);

Hint: Create your own frequency table and use the formula from the reference sheet!

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.