[BioPython] named tuples for biopython?

Leighton Pritchard lpritc at scri.ac.uk
Fri Oct 17 06:52:33 EDT 2008


On 17/10/2008 11:03, "Giovanni Marco Dall'Olio" <dalloliogm at gmail.com>
wrote:

> Hi,
> python 2.6 is going to implement a new kind of data (like lists, strings,
> etc..) called 'named_tuple'.
> It is intended to be a better data format to be used when parsing record
> files and databases.
> 
> You can download the recipe from here (it should be included experimentally
> in python 2.6):
> - http://code.activestate.com/recipes/500261/

The explanation here was pretty clear, to me:

http://docs.python.org/dev/library/collections.html#collections.namedtuple

> Has any of you heard about this new data type?

Not until you mentioned it - thanks for the heads-up.

> Do you think it could be
> useful for biopython? There is a lot of file parsing / database interfacing
> in bioinformatics :)

I can see it being a useful collection type.  It reminds me of C structs,
and looks like a near-perfect fit to many db table entries, and to
csv/ATF-format files for which the column headers can be used to define
attributes.  

I guess that one disadvantage of namedtuples, compared to, e.g. a dictionary
in which each value is itself a dictionary of attributes (with attribute
names for keys), is that there's a restricted character/word set available
for attribute names in the namedtuple, but this is not important for
dictionary keys, so some additional tally of header to attribute name may be
necessary.  This has a real use-case in, say, parsing ATF format files...

http://www.moleculardevices.com/pages/software/gn_genepix_file_formats.html

... where on-the-fly creation of attributes with the same name as in the
parsed file or table row may not be possible with a namedtuple.  If you know
of the column/field names in advance though, it shouldn't be an issue.

L.

-- 
Dr Leighton Pritchard MRSC
D131, Plant Pathology Programme, SCRI
Errol Road, Invergowrie, Perth and Kinross, Scotland, DD2 5DA
e:lpritc at scri.ac.uk       w:http://www.scri.ac.uk/staff/leightonpritchard
gpg/pgp: 0xFEFC205C       tel:+44(0)1382 562731 x2405


______________________________________________________________________
SCRI, Invergowrie, Dundee, DD2 5DA.  
The Scottish Crop Research Institute is a charitable company limited by
guarantee. 
Registered in Scotland No: SC 29367.
Recognised by the Inland Revenue as a Scottish Charity No: SC 006662.


DISCLAIMER:

This email is from the Scottish Crop Research Institute, but the views 
expressed by the sender are not necessarily the views of SCRI and its 
subsidiaries.  This email and any files transmitted with it are
confidential

to the intended recipient at the e-mail address to which it has been 
addressed.  It may not be disclosed or used by any other than that
addressee.
If you are not the intended recipient you are requested to preserve this

confidentiality and you must not use, disclose, copy, print or rely on
this 
e-mail in any way. Please notify postmaster at scri.ac.uk quoting the 
name of the sender and delete the email from your system.

Although SCRI has taken reasonable precautions to ensure no viruses are 
present in this email, neither the Institute nor the sender accepts any 
responsibility for any viruses, and it is your responsibility to scan
the email and the attachments (if any).
______________________________________________________________________


More information about the BioPython mailing list