Tjuh has asked for the wisdom of the Perl Monks concerning the following question:

Im following this guide: http://www.bioperl.org/wiki/HOWTO:Graphics and what Im tryin to do is create a png file for each hit in the blastoutput file. Also each png file should be named after the hit names. So forexample if there is a hit called 200134, then the resulting png file would be 200134.png etc

sub parseBlastOutput{ use Bio::Graphics; use Bio::SearchIO; use Bio::SeqFeature::Generic; my $searchio = Bio::SearchIO->new( -file => 'CAZyOutputM7.xml', -format => 'blastxml' ) or die +'parse failed'; #my $result = $searchio->next_result() or die "no result"; while (my $result = $searchio->next_result) { my $panel = Bio::Graphics::Panel->new( -length => $result-> +query_length, -width => 800, -pad_left => 10, -pad_right => 10 ); my $full_length = Bio::SeqFeature::Generic->new( -start + => 1, -end + => $result->query_length, -display_name + => $result->query_name ); $panel->add_track( $full_length, -glyph => 'arrow', -tick => 2, -fgcolor => 'black', -double => 1, -label => 1 ); my $track = $panel->add_track( -glyph => 'graded_segment +s', -label => 1, -connector => 'dashed', -bgcolor => 'blue', -font2color => 'red', -sort_order => 'high_score', -description => sub { my $featu +re = shift; return un +less $feature->has_tag('description'); my ($desc +ription) = $feature->each_tag_value('description'); my $score + = $feature->score; "$descrip +tion, score=$score"; } ); while (my $hit = $result->next_hit) { my $hitname = $hit->name; my $feature = Bio::SeqFeature::Generic->new( -score + => $hit->raw_score, -display_name + => $hit->name, -tag + => { description => $hit->description } ); while (my $hsp = $hit->next_hsp) { $feature->add_sub_SeqFeature($hsp,'EXPAND'); } $track->add_feature($feature); open my $blast, '>', $hitname or die "Failed to create $hi +tname\n"; print $blast $panel->png; close $blast or die "Failed to close $blast\n"; } } }

The way i have the script setup now, it doesnt do anything. I would appreciate some help on this.

Replies are listed 'Best First'.
Re: BioPerl Graphics problem
by ww (Archbishop) on Jun 13, 2011 at 10:42 UTC
    Just checking, but by "doesnt (sic) do anything" do you mean the larger program dies silently?

    Some of the usual questions apply:

    • Are you sure the source file is where you think it is?
      I see several dies in what look like appropriate places (given my lack of knowledge of the specific modules you're using)
    • Have you run this under debug?
      Potentially tedious, but often helpful
    • a) Are you sure your problem is in the code you posted?
      b) How do you know?
      It's very hard to help if a) is not true; it's easier to feel confident that one is not wasting time, if the answer to b) is known.

      Yes the source is where its supposed to be. The problem is creating several pngs at once. If i change the script to this:

      sub parseBlastOutput{ use Bio::Graphics; use Bio::SearchIO; use Bio::SeqFeature::Generic; my $searchio = Bio::SearchIO->new( -file => 'CAZyOutputM7.xml', -format => 'blastxml' ) or die +'parse failed'; my $result = $searchio->next_result() or die "no result"; #while (my $result = $searchio->next_result) { my $panel = Bio::Graphics::Panel->new( -length => $result-> +query_length, -width => 800, -pad_left => 10, -pad_right => 10 ); my $full_length = Bio::SeqFeature::Generic->new( -start + => 1, -end + => $result->query_length, -display_name + => $result->query_name ); $panel->add_track( $full_length, -glyph => 'arrow', -tick => 2, -fgcolor => 'black', -double => 1, -label => 1 ); my $track = $panel->add_track( -glyph => 'graded_segment +s', -label => 1, -connector => 'dashed', -bgcolor => 'blue', -font2color => 'red', -sort_order => 'high_score', -description => sub { my $featu +re = shift; return un +less $feature->has_tag('description'); my ($desc +ription) = $feature->each_tag_value('description'); my $score + = $feature->score; "$descrip +tion, score=$score"; } ); while (my $hit = $result->next_hit) { my $hitname = $hit->name; my $feature = Bio::SeqFeature::Generic->new( -score + => $hit->raw_score, -display_name + => $hit->name, -tag + => { description => $hit->description } ); while (my $hsp = $hit->next_hsp) { $feature->add_sub_SeqFeature($hsp,'EXPAND'); } $track->add_feature($feature); } open my $blast, '>', 'sumting.png' or die "Failed to create su +mting.png\n"; print $blast $panel->png; close $blast or die "Failed to close $blast\n"; #} }

      Then the script works just fine, however it only generates 1 png of the first hit in the blastoutput file

Re: BioPerl Graphics problem
by jethro (Monsignor) on Jun 13, 2011 at 12:48 UTC

    You say the original script does nothing. I suppose this means no file is generated at all. Which would mean the line wth "open my $blast..." is never executed. Otherwise there would at least be an empty file even if the png generation failed

    You can make sure of this if you just insert a line 'print "was here\n"; in that last while loop and execute the script

    Now you have 3 while loops inside each other. With the same method (inserting print statements) you can find out which is the one that never gets executed. Lets assume it is really the innermost loop that never gets executed. Put the following lines just before the start of the loop:

    use Data::Dumper; print Dumper(\$hit, $hit->next_hsp);

    Execute and check what you get and whether it makes sense. Compare with the data from the other script where you got one picture out (after you added a similar Dumper line). If you find the discrepancy, check where it came from. You'll find the bug in no time

      Sry, my bad, i should have specified some more. The first script does create a png file but it is empty. I will try to follow your instructions.