This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Digesting contig sequence with multiple enzymes

I was trying get a length of each fragment produce by restriction enzyme for each contig present in my contigs.fasta. In my following example enzyme is AflII. So basically, I am digesting each contig with AflII enzyme. So my code for that is as follows

for record in Bio.SeqIO.parse(open("contigs.fasta"), "fasta"):
   printrecord.id, [len(fragment) for fragment in Bio.Restriction.AflII.catalyze(record.seq)])

Now, I have more than one enzyme and I have to generate digestion for that. How can I do it using BioPython?

Please let me know, If you are unclear about the question. PS: I am new to the topic and BioPython as well.

restriction enzymes digestion python biopython

1 answer

Can you better explain your desiderata?

My code for what I understand is the following, but I'm not sure of what you want.

from Bio import SeqIO
from Bio.Restriction import *


multi = (BamHI, EcoRI, PstI) # just a few enzymes

for record in SeqIO.parse("contigs.fasta", "fasta"):
    for enz in range(len(multi)):
        coords = multi[enz].search(record.seq)
        for site in range(len(coords)):
            print  "%s    %d    %s" % (record.id, coords[site], multi[enz])

Log in to answer this question.