Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Bio::Graphics - Howto Enable Neg Start-End, Connector, Create Legend

by monkfan (Curate)
on Apr 19, 2007 at 09:32 UTC ( [id://610919]=perlquestion: print w/replies, xml ) Need Help??

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

This figure is created with the following script:
#!/usr/bin/perl -w use strict; use Data::Dumper; use Bio::Graphics; use Bio::SeqFeature::Generic; use List::Compare; use List::Util qw(max); my %nofseq = ( 0 => 300, 1 => 300, 2 => 300, 3 => 300, 4 => 300, 5 => +300 ); my @seqid = keys %nofseq; my @lenlist = values %nofseq; #Sequence length my $maxlen = max (@lenlist); #print Dumper \@seqid ; my $panel = Bio::Graphics::Panel->new( -length => 300, -width => 500, -pad_left => 70, -pad_right => 70, -key_style => 'left', -connector => 'solid', ); my $flen = Bio::SeqFeature::Generic->new( -start => 1, -end => 300, ); my $track1 = $panel->add_track( $flen, -glyph => 'arrow', -tick => 2, -fgcolor => 'black', -double => 1, ); my %nlist; while ( <DATA> ) { chomp; next if /^\#/; my ($sqi,$pos,$str,$progname) = split /\,/; my $start = $pos + $nofseq{$sqi}; my $end = $start + length($str) + 1; push @{$nlist{$sqi}}, $start." ".$end." ".$progname; } # Check which sequence has no motifs; my @bssi = keys %nlist; my $lc = List::Compare->new(\@seqid, \@bssi); my @comp = $lc->get_unique; foreach my $comp ( @comp ) { push @{$nlist{$comp}}, '0'." ".'0'." "."NONE"; } my %prog_color = ( "WEEDER" => 3000, "MEME" => 200, "NONE" => 0 ); foreach my $seqid ( sort keys %nlist ) { my $track = $panel->add_track( -glyph => 'graded_segments', -key => "SEQ ". $seqid, -connector => "solid" -label => 1, -bgcolor => 'blue', -bump => +1, -height => 8, -min_score => 0, -max_score => 5000 ); foreach my $range ( @{$nlist{$seqid}} ) { my ($st,$en,$progname) = split(" ", $range); my $dname = " "; if ( $st != 0 and $en !=0 ) { $dname = "Seq ". $seqid; } my $score; if ( $progname eq "WEEDER" ) { $score = $prog_color{$progname}; } elsif ($progname eq "MEME" ) { $score = $prog_color{$progname}; } my $feature = Bio::SeqFeature::Generic->new( -display_name => $dname, -start => $st, -end => $en, -score => $score ); $track->add_feature($feature); } } print $panel->png; __DATA__ # sequence number,pos,binding sites,program 4,-63,AGCTTTCTCT,MEME 0,-22,AACTTTGTAC,WEEDER 1,-13,AAGTTTCTCT,WEEDER 5,-228,ACCTTTGCCA,MEME 5,-121,AAGTTTGTCT,WEEDER 5,-88,AAGTTTTTCC,SPACE 3,-148,AACTTAGTCA,MEME 0,-184,AACTTTGTCT,MEME
The DATA is simply just list of string and its location in their respective sequence. The figure is just the plot of it out.

As you can see from the figure, there are some misgivings of my script above.
  • The arrow track need to be represented in negative form. I.e. instead of 1 to 300, we use -300 to 0. I tried this, but won't do:
    my $flen = Bio::SeqFeature::Generic->new( -start => -300, -end => 0, );
  • And how can I make these number to appear for every gridpoints (not just two as I have now).
  • The "connector" doesn't seem to work.
  • It needs a LEGEND to describe the color of each block (WEEDER = purple, MEME=white).
I was thinking to mimic this figure.
Does anybody has experience in dealing with such issues with Bio::Graphics? Any idea how to achieve that?

Regards,
Edward

Replies are listed 'Best First'.
Re: Bio::Graphics - Howto Enable Neg Start-End, Connector, Create Legend
by lbragg (Initiate) on Sep 09, 2008 at 00:55 UTC
    I know this reply is too late to help you, but for anyone wanting to do a negative scale, I think the following example should work. However, the coordinate system will continue to be positive, so you'll just have to convert your positions to positive values (ie. abs(minimum value on scale - feature pos) + 1). For example, the -63 relative to the TSS will be need to be converted to:
    abs(-300 - - 63) + 1 = 238
    The following code creates the feature and the panel:
    my $full_length = Bio::SeqFeature::Generic->new( -start => 1, -end => 300 ); my $panel = Bio::Graphics::Panel->new( -length => $length, -width => 1000, -pad_left => 10, -pad_right => 10, );
    This next statement adds the arrow track to the panel, the relative coords needs to be set to true and the relative coords offset is set to the minimum value you want represented on arrow track (in this example it is -300).
    $panel->add_track($full_length, -glyph => 'arrow', -tick => 2, -fgcolor => 'black', -double => 1, -relative_coords => 1, -relative_coords_offset => -300 );
    Hope that helps someone,
    Lauren

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://610919]
Approved by Corion
Front-paged by neversaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-24 17:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found