[Biopython-dev] Handles and/or filenames in Bio.SeqIO etc?

Brad Chapman chapmanb at 50mail.com
Tue Jul 28 22:17:26 UTC 2009


Hey all;

> Eric just reopened an old debate - should Bio.SeqIO (and similar)
> support filenames as well has handles?
> 
> In fact, this something we originally discussed way back when planning
> SeqIO way back in Nov 2006. Michiel and I were at the time generally
> in favour of allowing filename/handles, but Iddo Friedberg (who at that
> time was basically in charge) and Chris Lasher didn't like this. It would
> have broken with the existing Biopython parsers which were all handle
> only. After a little debate, we opted to support just handles, knowing we
> could if need be later allow filenames instead.

I am for file and handle support. Only dealing with handles is like
so totally 2006.

I did this in the GFF parser by necessity since Disco MapReduce
needed files and the standard Biopython way is handles. Essentially,
it checks for a read attribute and keeps track of needing to close
the handle:

if hasattr(gff_file, "read"):
    need_close = False
    in_handle = gff_file
else:
    need_close = True
    in_handle = open(gff_file)

> There is a minor downside
> that Python beginners won't necessarily get to gripes with handles so quickly.

Yes, that is the downside I see as well. The plus side of the same
issue is that the learning curve is less steep.

Brad



More information about the Biopython-dev mailing list