When trying out the examples from chapter 2.3 of the biopython 1.54b tutorial I keep running into this very annoying problem: When I use:
from Bio import SeqIO for seq_record in SeqIO.parse("ls_orchid.fasta", "fasta"): print seq_record.id print repr(seq_record.seq) print len(seq_record)
The Python interpreter tells me I should use a handle in stead of filenames. I use biopython 1.53 and not 1.54b for which this tutorial was meant. I can't find an older archived version of the tutorial I could use to help me learn how to use a handle in stead of the simple filename method (ls_orchid.fasta in this case.). I know that in older versions of biopython you have to do everything in handlers but not in the newer versions.
The new tutorial now on-line has an obscure last chapter on how to use handlers but that's hardly helpfull.
I think the tutorial is great, I just havent got the right version installed. I use Ubuntu and downloaded biopython via ubuntu software center.
Can anyone help me use a handler and get the above parsing example working in 1.53?
It worked! So this is how handlers work. I remember somewhere I read that you always have to close the handler too, so I know why u use the last statement too. You wrap it and then you unwrap it.
Thanks Gurado :D
Closing handles is particularly important for output, but good practice on input too. When the handle goes out of scope and gets garbage collected it will be closed automatically.