[Bioperl-l] Bio::Graphics sort_order

Lincoln Stein lstein at cshl.edu
Mon Oct 6 11:19:12 EDT 2003


Hi Richard,

This has now been fixed in both the live and 1.2 branches.  You will have to 
get them via CVS.

As it happens, passing an anonymous subroutine to -sort_order could never work 
in the way that was described in the documentation because the automagic 
variables $a and $b are package variables.  To illustrate, consider:

	package main;
	my $sort_sub = sub {warn "comparing $a to $b\n"; $a cmp $b};
	my @a           = sort $sort_sub qw(one two three four five);
	@a                 = Foo::package_sort($sort_sub);

	package Foo;
	sub package_sort {
		my $sort_sub = shift;
		return sort $sort_sub qw(one two three four five);
	}

The first invocation of sort will work because the anonymous sub and the call 
to sort are both in package main.  The second try will not work because the 
anonymous sub will look in package main for $a and $b, but they are defined 
in package Foo.

To work around this in Bio::Graphics, you must create an anonymous subroutine 
that has the $$ prototype:

	-sort_order => sub ($$) {
		my ($a,$b) = @_; 
		$a->feature->display_name cmp $b->feature->display_name; 
	}

When perl sees a sort sub with the $$ prototype, it passes $a and $b on the 
stack rather than as package variables.  Another issue is that the original 
documentation is wrong about what appears in $a and $b.  They are glyph 
objects, not feature objects.  To get at the feature, you must call their 
feature() method as shown above.

The documentation has now been fixed to explain this behavior correctly.

Lincoln


On Monday 06 October 2003 04:44 am, Richard Adams wrote:
> Hello,
>     I'm trying to sort the display order  of features based on values
> in  one of the features' tags using the syntax
>     described in the Bio::Graphics::Panel :doc.
>         i.e.,
> sort_order =>    sub {(  ($a->each_tag_value('Conserved'))[0]
> <=>($b->each_tag_value('Conserved'))[0]  )};
> But I get the error message
> "Can't call method "each_tag_value" on an undefined value at
> Draw_Output.pm". The code doesn't seem to be
> recognizing that $a and $b should refer to the features. I've tried
> delving into the internal workings of Bio::Graphics::Glyph::Factory
> with little enlightenment, would be grateful for any ideas.
> Cheers
> Richard
>
>
> --
> Dr Richard Adams
> Bioinformatician,
> Psychiatric Genetics Group,
> Medical Genetics,
> Molecular Medicine Centre,
> Western General Hospital,
> Crewe Rd West,
> Edinburgh UK
> EH4 2XU
>
> Tel: 44 131 651 1084
> richard.adams at ed.ac.uk
>
>
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at portal.open-bio.org
> http://portal.open-bio.org/mailman/listinfo/bioperl-l

-- 
Lincoln Stein
lstein at cshl.edu
Cold Spring Harbor Laboratory
1 Bungtown Road
Cold Spring Harbor, NY 11724
(516) 367-8380 (voice)
(516) 367-8389 (fax)


More information about the Bioperl-l mailing list