1 use CatalystX
::GlobalContext
qw( $c );
5 show_match_seq.pl - a simple script to show the entire sequence of a
6 match in a blast database with optional highlighting of the matched
11 This script shows a webpage with the sequence from a blast database
12 for a specific id, using CXGN::BlastDB. This is the script that should
13 be called if the CXGN::Tools::Identifiers cannot determine an
14 appropriate link, so that the users still can get at the matched
15 sequence, instead of uselessly defaulting to Genbank.
23 The id of the sequence [string], as it appears in the database (best
24 retrieved from a blast report).
28 The id [int] of the blast database file for CXGN::BlastDB.
32 a list of start and end coordinates, of the form:
34 start1-end1,start2-end2,start3-end3
38 either "text" or "html" to output fasta text or a nicely ;-) formatted
45 Lukas Mueller <lam87@cornell.edu>
47 Robert Buels <rmb32@cornelle.edu>
57 use CXGN::Tools::Text qw/ sanitize_string /;
58 use CXGN::MasonFactory;
60 use CXGN::Page::FormattingHelpers qw | info_section_html html_break_string html_string_linebreak_and_highlight | ;
65 my ( $id ) = $cgi->param( 'id' );
66 my ( $blast_db_id ) = $cgi->param( 'blast_db_id' );
67 my ( $format ) = $cgi->param( 'format' );
68 my ( $hilite_coords ) = $cgi->param( 'hilite_coords' );
73 $id = sanitize_string( $id );
75 $c->forward_to_mason_view('/blast/show_seq/input.mas') unless $blast_db_id && defined $id;
77 # parse the coords param
80 my ($s, $e) = split "-", $_;
81 defined $_ or die 'parse error' for $s, $e;
86 ( $hilite_coords || '' );
88 #die("hilite_coords $hilite_coords. ".(join ",", @coords)."\n");
91 my $bdbo = CXGN::BlastDB->from_id( $blast_db_id )
92 or $c->throw( is_error => 0,
93 message => "The blast database with id $blast_db_id could not be found (please set the blast_db_id parameter).");
95 my $seq = $bdbo->get_sequence( $id ) # returns a Bio::Seq object.
96 or $c->throw( is_error => 0,
97 message => "The sequence could not be found in the blast database with id $blast_db_id.");
99 # dispatch to the proper view
100 if ( $format eq 'html' ) {
101 my $view_link = do { $cgi->param( format => 'fasta_text'); '?'.$cgi->query_string };
102 my $download_link = do { $cgi->param( format => 'fasta_file'); '?'.$cgi->query_string };
104 $c->forward_to_mason_view(
105 '/blast/show_seq/html.mas',
107 highlight_coords => \@coords,
108 source => '"'.$bdbo->title.'" BLAST dataset ',
110 ( $seq->length > 500_000 ? () : [ 'View as FASTA' => $view_link ] ),
111 [ 'Download as FASTA' => $download_link ],
113 blast_url => '/tools/blast/index.pl',
116 } elsif( $format eq 'fasta_file' || $format eq 'fasta_text' ) {
120 print "Content-Type: text/plain\n";
121 my $attachment = $format eq 'fasta_file' ? 'attachment;' : '';
122 print "Content-Disposition: $attachment filename=$id.fa\n";
124 Bio::SeqIO->new( -fh => \*STDOUT, -format => 'fasta' )