[Bioperl-l] RE: Passing extra arguments to method references inBio::Graphics::Panel::add_track

michael watson (IAH-C) michael.watson at bbsrc.ac.uk
Wed May 11 10:54:59 EDT 2005


OK, thank you very much for the information which was absolutely correct
but wasn't useful for what I want to do.

So I'm drawing images of genes.  I don't want "bumped" images, and what
this means is that the labels begin to overwrite one another and it
looks awful.  So what I want to do is ONLY draw a label and a
description if the glyph is the FIRST glyph in a particular track.
Maybe I'm being stupid, but I can't figure out how to do it - I can't
see how I can make each new glyph figure out if a glyph has been drawn
before it on the same track.

On a different note, I want an overall title for each track (not each
glyph in a track, a title for the entire track) - and I don't want to
have a key.  Is that possible?

Many thanks

Mick

-----Original Message-----
From: Crabtree, Jonathan [mailto:crabtree at tigr.org] 
Sent: 09 May 2005 16:54
To: michael watson (IAH-C)
Cc: Bioperl
Subject: RE: [Bioperl-l] RE: Passing extra arguments to method
references inBio::Graphics::Panel::add_track



Michael-

What you're trying to do is known as "currying" in functional
programming parlance.  Perl (5, at least) doesn't support currying
directly, but you can implement it yourself using a simple closure.  For
example, instead of this:

> -label      => \&gene_description($start)

you could use something like the following (assuming that
&gene_description expects the $start argument, followed by the usual
arguments to a Bioperl track callback subroutine):

  -label  => sub { my @args = @_;  return &gene_description($start,
@args); }

Or if you need to repeat this trick a number of times, with different
$start values, you could create yourself a subroutine-generating
subroutine, like so (in this example I've made the outer subroutine
anonymous, but you don't have to):

my $funMaker = sub {
	my $start = shift;
	return sub {
		my @args = @_;
		return &gene_description($start, @args);
 	}
};

and then in the add_track method you'd say:

  -label => &$funMaker($my_start_value),

If you google some combination of "currying", "perl", and "closure"
you'll find a bunch of pages that discuss these and similar techniques.
Hope this helps,

Jonathan

> -----Original Message-----
> From: bioperl-l-bounces at portal.open-bio.org
> [mailto:bioperl-l-bounces at portal.open-bio.org] On Behalf Of 
> michael watson (IAH-C)
> Sent: Monday, May 09, 2005 11:31 AM
> To: Bioperl
> Subject: [Bioperl-l] RE: Passing extra arguments to method 
> references inBio::Graphics::Panel::add_track
> 
> 
> Hi
> 
> Sorry, a bit hasty on the trigger....
> 
> I am on bioperl-1.5.
> 
> I'm using the following code to create some rather tasty images:
> 
> $panel->add_track(transcript2  => \@includeCDS,
> 		  -bgcolor    =>  'blue',
> 		  -fgcolor    =>  'black',
> 		  -key        => 'CDS',
> 		  -bump       =>  0,
> 		  -height     =>  10,
> 		  -label      => \&gene_description,
> 		  -description=> \&gene_label,
> 		 );
> 
> This is fairly standard, and @includeCDS is a bunch of
> feature objects.
> 
> What I want to do is pass extra arguments to
> &gene_description, and then within &gene_description check to 
> see if the feature start is greater than a certain value (the 
> extra argument).  If it is, then I want to return an empty 
> string, if it isn't I want to return the gene description.  
> Something like:
> 
> -label      => \&gene_description($start)
> 
> But when I tried that it didn't work ;-(.
> 
> So is it possible to pass extra arguments to those functions
> I am referencing above?
> 
> Many thanks
> 
> Mick
> 
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at portal.open-bio.org
> http://portal.open-> bio.org/mailman/listinfo/bioperl-l
> 



More information about the Bioperl-l mailing list