[Bioperl-l] HTMLResultWriter questions

Oliver Wafzig wafzig at axaron.com
Thu Oct 9 04:21:10 EDT 2003


On Wednesday 08 October 2003 20:05, Daniel Lang wrote:
Hi Daniel,

Generating local database links:
Method 1: call your HTMLResultWriter like this

		 my $htmlwriter =  
			new Bio::SearchIO::Writer::HTMLResultWriter('foo1%s','foo2%s' );
		where 'foo1' points to your protein-db source and 'foo2' points to your
		nucleotide db.

Methode 2: write your own 'hit_link' method and pass it as a coderef to 
"hit_link_desc" like  
 	 my $htmlwriter =
		new Bio::SearchIO::Writer::HTMLResultWriter('bla1%s','bla2%s' );
 	 $htmlwriter->hit_link_desc(\&my_hit_link);

You can use Bio::SearchIO::Writer::HTMLResultWriter::default_hit_link_desc as 
a starting piont for your own method.

Here is some code, linking all 'Hits' starting with '>gnl|database|Acc' to one 
URL, while all others ('>emb|....' or '>sw|....') will be fetched with our 
local BioRS system.   

Oliver
 
######################################################

#!/usr/bin/perl -w
use strict; 
use Bio::SearchIO; 
use Bio::SearchIO::Writer::HTMLResultWriter;

my %dbsource = ();
my $biors = 
"http://pink:4700/searchtool/searchtool.cgi?start_guest_session=1&request=query_adv&file=results&out_format=fasta&query=%s";
my $fastacmd = "http://pink/blast2ncbi/dispfastaseq?%s:%s:%s:%s";
$dbsource{"emb"} = "{embl_nest,embl_est}:[([AccNumber+EQ+text:%s;])]";
$dbsource{"sw"}  = "{swissprot,swissnew}:[([AccNumber+EQ+text:%s;])]";

die "no infile" unless defined ($ARGV[0]) && (-f $ARGV[0]);
my $infile = $ARGV[0];

my $in = new Bio::SearchIO(-format => 'blast',
			   -file => $infile); 

my $result = $in->next_result;
my $htmlwriter = new Bio::SearchIO::Writer::HTMLResultWriter();
$htmlwriter->hit_link_desc(\&my_hit_link);
$htmlwriter->hit_link_align(\&my_hit_link);
my $outhtml = new Bio::SearchIO(-writer => $htmlwriter,
				-file => ">searchio.html");
$outhtml->write_result($result);


#bereitet den html-link vor#
#dient als codereferenz in $writer->hit_link_desc (\&CODE)
#                   und in $writer->hit_link_align(\&CODE)
sub my_hit_link {
  my($self, $hit, $result) = @_;
  my $urlpattern = undef;
  my $source = undef; #biors oder fastacmd
  my $database = undef;
  my @spl = split( /[|]/, $hit->name);
  if ($spl[0] eq "gnl"){
    my ($beg, $end) = $hit->hsp('best')->range('sbjct');
    $urlpattern = sprintf ($fastacmd, $spl[1] ,"%s", $beg, $end);
  }else{
    $urlpattern = sprintf ($biors, $dbsource{$spl[0]});
  }
  #print STDERR "URLPATTERN:\t$urlpattern\n";
  
  my $type = ( $result->algorithm =~ /(P|X|Y)$/i ) ? 'PROTEIN' : 'NUCLEOTIDE';
  my ($gi,$acc) = &{$self->id_parser}($hit->name);
  
  
  my $url = length($self->remote_database_url($type,)) > 0 ? 
    sprintf('<a href="%s">%s</a>',
	    sprintf($self->remote_database_url($type, $urlpattern),$gi || $acc), 
	    $hit->name()) :  $hit->name();
  
  return $url;
} 




More information about the Bioperl-l mailing list