The GBrowse2 documentation provides instructions for dynamically computing certain track configurations. I am trying to take advantage of this feature with some data I have, but so far I've been unsuccessful.
I'm looking at a 25kb region in Arabidopsis at Phytozome. I uploaded the following data file...
##gff-version 3
Chr2 MyData locus 5588218 5588322 . . . attr5=0;attr4=0;attr3=0;attr2=0;attr1=1
Chr2 MyData locus 5590052 5591422 . . . attr5=1;attr4=0;attr3=0;attr2=1;attr1=0
Chr2 MyData locus 5593060 5598296 . . . attr5=1;attr4=0;attr3=1;attr2=0;attr1=0
Chr2 MyData locus 5598421 5599923 . . . attr5=1;attr4=0;attr3=0;attr2=0;attr1=0
...and then edited the configuration to dynamically calculate feature color--specifically, I added this callback routine to the bgcolor and fgcolor.
sub
{
my $feature = shift(@_);
my($attr1) = $feature->get_tag_values("attr1");
return "red" if($attr1 > 0);
my($attr2) = $feature->get_tag_values("attr2");
return "orange" if($attr2 > 0);
my($attr3) = $feature->get_tag_values("attr3");
return "gold" if($attr3 > 0);
my($attr4) = $feature->get_tag_values("attr4");
return "green" if($attr4 > 0);
return "blue";
}
After saving this configuration, all of my features show up as black, so something I am doing is not right. I tested this approach on the command line with the following script...
use strict;
use Bio::Tools::GFF;
my $loader = Bio::Tools::GFF->new( -fh => \*STDIN, -gff_version => 3 );
while(my $feat = $loader->next_feature)
{
printf("color: %s\n", mycolor($feat));
}
sub mycolor
{
my $feature = shift(@_);
my($attr1) = $feature->get_tag_values("attr1");
return "red" if($attr1 > 0);
my($attr2) = $feature->get_tag_values("attr2");
return "orange" if($attr2 > 0);
my($attr3) = $feature->get_tag_values("attr3");
return "gold" if($attr3 > 0);
my($attr4) = $feature->get_tag_values("attr4");
return "green" if($attr4 > 0);
return "blue";
}
...and it seemed to work fine. What am I doing wrong here?
Scott's answer is correct. However, there is a way to accomplish this without using Perl callbacks in the configuration. The "heatmap" glyph gives you quite a bit of flexibility with colors. If your start color and end color have good separation on the spectrum (such as red and green), then you will be able to blend these colors to create quite a lot of intermediates. The "heatmap" glyph uses the score field to select the feature's color, so that's essentially what I ended up doing--set my start color to red, my end color to green, and modulated the feature score on discrete intervals between 0 and 1 to get red, orange, yellow, light green, and dark green.