This is a test version of Biostars. For the public version, visit https://www.biostars.org.
BioGraphics doesn't outputs for a tab delimited data

Hi all,

I am new to BioGraphics. I have a text file with three columns: Protein name, start position, end position.

I want to map them based on their locations. I modified the code from the BioGraphics tutorial. My code looks something like this:

#!/usr/bin/perl

use strict;
use Bio::Graphics;
use Bio::SeqFeature::Generic;

my $panel = Bio::Graphics::Panel->new(
                                      -length => 10000,
                                      -width  => 8000
                                     );
my $track = $panel->add_track(
                              -glyph => 'generic',
                              -label => 1
                             );

while (<>) {
  chomp;
  my($name,$start,$end) = split /\t+/;
  my $feature = Bio::SeqFeature::Generic->new(
                                              -display_name => $name,
                                              -start        => $start,
                                              -end          => $end
                                             );
  $track->add_feature($feature);
}
binmode(STDOUT);
print $panel->png;
perl test_image.pl map_final.txt > 12.png.

My result is a blank image. Can someone help me with what is happening here?

Many thanks
Nik

bioperl biographics

That's how I would debug such a program:

  • Try with fixed coordinates, without reading and parsing a file, plotting only one or two features, does it work?
  • Give an example of map_final.txt, check that the file is in fact multi-tab separated (\t+ = at least one tab), try split without argument, should work on most files
  • Add debug output for each iteration

Hi Michael, I got the output using fixed coordinates.

Coming back to my file input, I got some kind of output with this code:

#!/usr/bin/perl

#use strict;
use Bio::Graphics;
use Bio::SeqFeature::Generic;

my $panel = Bio::Graphics::Panel->new(
                                      -length    => 10000,
                                      -width     => 800,
                                      -pad_left  => 10,
                                      -pad_right => 10,
                                     );


my $track = $panel->add_track(
                              -glyph     => 'generic',
                              -label     => 1,
                              -bgcolor   => 'blue'
                             );

while (<>) {
  chomp;
  my($name,$score,$start,$end) = split /\t/;
  #print $start."\t".$end;
  my $feature = Bio::SeqFeature::Generic->new(
                                              -display_name => $name,
                                              -score        => $score,
                                              -end          => $end
                                             );
  $track->add_feature($feature);
}
binmode(STDOUT);
print $panel->png;

The difference here is -score => $score rather than -start => $start. If I replace it back to -start => $start, I get no output. Could it be my coordinates are too big? I tried with higher length but didn't help.

Example of map_final.txt:

Temp161    23    1343816    1343986
B    34    1340702    1343791

Here, I added an extra column which I don't really care about. Reason being that the tutorial script was written with BLAST output in mind. My data is 1st column as name, 3rd as start and 4th as end.

Tabs don't seem to be the issue.

It worked finally. Thanks for the help Michael. I think the length and the file was an issue. My new code looks like this:

#!/usr/bin/perl

#use strict;
use Bio::Graphics;
use Bio::SeqFeature::Generic;
$i=0;
my $panel = Bio::Graphics::Panel->new(
                                      -length    => 6000000,
                                      -width     => 1200,
                                      -pad_left  => 10,
                                      -pad_right => 10,
                                     );


my $track = $panel->add_track(
                              -glyph     => 'generic',
                              -label     => 1,
                              -bgcolor   => 'blue'
                             );
my $full_length = Bio::SeqFeature::Generic->new(
                                                -start => 1,
                                                -end   => 6000000,
                                               );
$panel->add_track($full_length,
                  -glyph   => 'arrow',
                  -tick    => 2,
                  -fgcolor => 'black',
                  -double  => 1,
                 );

while (<>) {
  chomp;
  @data=split("\t");
  $name[$i]=$data[0];
  $start[$i]=$data[1];
  $end[$i]=$data[2];
  $i++;
}

for($j=0;$j<$i;$j++)
{
  my $feature = Bio::SeqFeature::Generic->new(
                                              -display_name => $name[$j],
                                              -start        => $start[$j],
                                              -end          => $end[$j]
                                             );
  $track->add_feature($feature);
}
binmode(STDOUT);
print $panel->png;
perl test_image.pl map_final.txt > 123.png

map_final.txt has data such as:

Temp161    1343816    1343986
B    1340702    1343791
C    1339488    1340705

It is a crude image but I can work on it now.

Thanks again.

nice it worked, but please always have

use strict; use warnings; if it doesn't work with use strict it is possibly broken.

Yes I will, sometimes I miss it when I am in a rush.

0 answers

No answers yet.

Log in to answer this question.