[Bioperl-l] Sorting Bio:Graphics::Glyphs

Lincoln Stein lstein at cshl.edu
Wed Dec 3 10:25:00 EST 2003


I'm confused that the POD documentation tells you to use $a and $b.  In my 
version of 1.3, the docs say this:

>>>>>>>>>>>>>>>>>>
Finally, a subroutine coderef with a $$ prototype can be provided.  It
will receive two B<glyph> as arguments and should return -1, 0 or 1
(see Perl's sort() function for more information).  For example, to
sort a set of database search hits by bits (stored in the features'
"score" fields), scaled by the log of the alignment length (with
"start" position breaking any ties):

  sort_order = sub ($$) {
    my ($glyph1,$glyph2) = @_;
    my $a = $glyph1->feature;
    my $b = $glyph2->feature;
    ( $b->score/log($b->length)
          <=>
      $a->score/log($a->length) )
          ||
    ( $a->start <=> $b->start )
  }

It is important to remember to use the $$ prototype as shown in the
example.  Otherwise Bio::Graphics will quit with an exception. The
arguments are subclasses of Bio::Graphics::Glyph, not the features
themselves.  While glyphs implement some, but not all, of the feature
methods, to be safe call the two glyphs' feature() methods in order to
convert them into the actual features.
<<<<<<<<<<<<<<<

This, of course, also explains the main problem you are having.

Lincoln


On Wednesday 03 December 2003 09:14 am, Oliver Burren wrote:
> Hi,
>
> I have a lot of transcripts that I'm rendering using the excellent
> Bio::Graphics module. I want to sort these by the last two characters in
> the display_name attribute. I used the following callback
>
> sub sort_trans($$){substr($_[0]->display_name,-2)<=>
>                   substr($_[1]->display_name,-2)}
> # the last two chars are numbers therefore using <=>
>
> I then added
> the following  track glyph
>
> my $ttrack=$panel->add_track(\@transcripts,
>                         -glyph=>'transcript',
>                         #......more options here
>                         -sort_order=>&sort_trans # should this be
> # \&sort_trans ?
>                         );
>
> If i then run this I get the following error
>
> Can't call method "display_name" on unblessed reference at gene_page.cgi
> line 93, <DATA> line 191.
>
> In the pod documentation for Glyphs it says to use $a and $b vars if I
> use these though i get an exception that tells me to use a ($$)
> prototype (which I think I'm doing by using a call back with
> prototype).
>
> I'm using Version 1.3 of bioperl.
>
> Can anyone point out what I should be doing or am doing wrong ?
>
> Thanks,
>
> Olly Burren

-- 
========================================================================
Lincoln D. Stein                           Cold Spring Harbor Laboratory
lstein at cshl.org			                  Cold Spring Harbor, NY
========================================================================




More information about the Bioperl-l mailing list