[Biopython-dev] An iterator for Align.Generic

Marc Colosimo mcolosimo at mitre.org
Fri Feb 10 11:48:10 EST 2006


Peter wrote:

> Marc Colosimo wrote:
>
>> Last week I sent in a patch to Align.Generic to make it an iterator 
>> [Bug 1944]. Has anyone looked at this? I've found this to be very 
>> useful to me and I really don't want to keep a patch file around to 
>> add this functionality each time I checkout biopython.
>>
>> Marc
>
>
> Hi Mark,
>
> I haven't looked at your code, but I do use Clustal alignments quite 
> often in BioPython.  Could you put together a short example showing 
> how this would work?  If this was added to BioPython then we could use 
> this to update the cook book.
>
> Peter
>
Peter,

First, I think I need to make one change in the code so that one can 
re-iterate (basically reset the _iter_pos to 0(

Now, here is some code (I think this will work), which shows that you 
can make one function to handle sequences from different file types.

from Bio import Clustalw
from Bio import Fasta

def doSomethingInteresting(recIter):
    for seqRec in recIter:
       print seqRec.description
       print seqRec.seq.tostring()

#main

fasta_iter = Fasta.Iterator( open("my.fasta"), Fasta.SequenceParser() )  
# where my.fasta is the unaligned sequences
aln_iter = Clustalw.parse_file("my.aln")   # where my.aln is the aligned 
sequences

doSomethingInteresting(fasta_iter)
doSomethingInteresting(aln_iter)





More information about the Biopython-dev mailing list