[BioPython] Tweaking GenomeDiagram

Peter (BioPython List) biopython at maubp.freeserve.co.uk
Mon Mar 27 14:48:52 UTC 2006


Thanks Leighton',

I've included most of your reply for the benefit of the BioPython 
mailing list and its archive...

>>> First Query
>>> -----------
>>> I would like to attach labels to (selected) features.
>>> 
>>> For example, I am drawing a circular genome diagram with a selection of 
>>> colour coded genes - some of which I would like to have individually 
>>> labelled.  This might be done in a similar way to the genome size tick 
>>> captions (i.e. horizontal text) or perhaps rotated text (radially aligned).
>>> 
>>> However, as far as I can tell from the documentation and the source 
>>> code, this is not built in.

I clearly didn't read the right bit of the source code.

Leighton wrote:
> Each individual GDFeature has a label attribute, taking a Boolean, that
> allows you to set whether its label is displayed or not.  You could set
> this on feature creation, ...

e.g.

for feature in genbank_entry.features:
     if feature.type == 'CDS':
         gdfs.add_feature(feature, label=False, colour=colors.lightgreen)
     elif feature.type == 'tRNA' :
         gdfs.add_feature(feature, label=True, colour=colors.red)

(This can easily be used with the examples in the documentation)

Leighton wrote:
 > ... or at some later stage with a filter.  If you're working with
 > N.equitans, and your GDFeatureSet is called `gdfs1', for example, this
 > code:
> 
>     gdfs1.set_all_features('label', 0)
>     for feature in gdfs1.features.values():
>         print feature.name, feature.label
>         if feature.name.startswith('NEQ016'):
>             feature.label = 1

Maybe that should be gdfs._features rather than gdfs.features?

> will label only features whose names begin with NEQ016.  You'll probably
> already see how flexible this can be if you add your own attributes to
> GDFeature objects when they're created (BLAST scores, expression
> leveles, membership of functional classes, etc.).  You can set the
> label_font, label_size, label_colour and label_angle attributes in the
> same kind of way.

By default, when using the add_feature method with a SeqFeature 
extracted from a GenBank file, GenomeDiagram will look at the 'gene', 
'label', 'locus_tag' and 'product' qualifiers for potential labels (in 
that order).  (See code in GDFeature.py class GDFeature.)

It might be usefull to be able to supply the prefered label caption as 
part of the add_feature command.

Thanks

Peter





More information about the Biopython mailing list