Merge pull request #5069 from solgenomics/topic/accession_upload_file
[sgn.git] / cgi-bin / tools / blast / show_match_seq.pl
blob20d6c96c3e4f96c06cdc7d28a842d4bb7cecb447
1 use CatalystX::GlobalContext qw( $c );
3 =head1 NAME
5 NOTE: This script has been deprecated. The functionality was moved
6 to SGN::Controller::Blast.
8 show_match_seq.pl - a simple script to show the entire sequence of a
9 match in a blast database with optional highlighting of the matched
10 region
12 =head1 DESCRIPTION
14 This script shows a webpage with the sequence from a blast database
15 for a specific id, using CXGN::BlastDB. This is the script that should
16 be called if the CXGN::Tools::Identifiers cannot determine an
17 appropriate link, so that the users still can get at the matched
18 sequence, instead of uselessly defaulting to Genbank.
20 Page arguments:
22 =over 10
24 =item id
26 The id of the sequence [string], as it appears in the database (best
27 retrieved from a blast report).
29 =item blast_db_id
31 The id [int] of the blast database file for CXGN::BlastDB.
33 =item hilite_coords
35 a list of start and end coordinates, of the form:
37 start1-end1,start2-end2,start3-end3
39 =item format
41 either "text" or "html" to output fasta text or a nicely ;-) formatted
42 html page.
44 =back
46 =head1 AUTHOR
48 Lukas Mueller <lam87@cornell.edu>
50 Robert Buels <rmb32@cornelle.edu>
52 =cut
54 use strict;
55 use warnings;
57 use CGI ();
59 use CXGN::BlastDB;
60 use CXGN::Tools::Text qw/ sanitize_string /;
61 use CXGN::MasonFactory;
63 use CXGN::Page::FormattingHelpers qw | info_section_html html_break_string html_string_linebreak_and_highlight | ;
65 my $cgi = CGI->new;
67 #get params
68 my ( $id ) = $cgi->param( 'id' );
69 my ( $blast_db_id ) = $cgi->param( 'blast_db_id' );
70 my ( $format ) = $cgi->param( 'format' );
71 my ( $hilite_coords ) = $cgi->param( 'hilite_coords' );
73 #sanitize params
74 $format ||= 'html';
75 $blast_db_id += 0;
76 $id = sanitize_string( $id );
78 $c->forward_to_mason_view('/blast/show_seq/input.mas') unless $blast_db_id && defined $id;
80 # parse the coords param
81 my @coords =
82 map {
83 my ($s, $e) = split "-", $_;
84 defined $_ or die 'parse error' for $s, $e;
85 [ $s, $e ]
87 grep length,
88 split ',',
89 ( $hilite_coords || '' );
91 #die("hilite_coords $hilite_coords. ".(join ",", @coords)."\n");
93 # look up our blastdb
94 my $bdbo = CXGN::BlastDB->from_id( $blast_db_id )
95 or $c->throw( is_error => 0,
96 message => "The blast database with id $blast_db_id could not be found (please set the blast_db_id parameter).");
98 my $seq = $bdbo->get_sequence( $id ) # returns a Bio::Seq object.
99 or $c->throw( is_error => 0,
100 message => "The sequence could not be found in the blast database with id $blast_db_id.");
102 # dispatch to the proper view
103 if ( $format eq 'html' ) {
104 my $view_link = do { $cgi->param( format => 'fasta_text'); '?'.$cgi->query_string };
105 my $download_link = do { $cgi->param( format => 'fasta_file'); '?'.$cgi->query_string };
107 $c->forward_to_mason_view(
108 '/blast/show_seq/html.mas',
109 seq => $seq,
110 highlight_coords => \@coords,
111 source => '"'.$bdbo->title.'" BLAST dataset ',
112 format_links => [
113 ( $seq->length > 500_000 ? () : [ 'View as FASTA' => $view_link ] ),
114 [ 'Download as FASTA' => $download_link ],
116 blast_url => '/tools/blast/index.pl',
119 } elsif( $format eq 'fasta_file' || $format eq 'fasta_text' ) {
121 require Bio::SeqIO;
123 print "Content-Type: text/plain\n";
124 my $attachment = $format eq 'fasta_file' ? 'attachment;' : '';
125 print "Content-Disposition: $attachment filename=$id.fa\n";
126 print "\n";
127 Bio::SeqIO->new( -fh => \*STDOUT, -format => 'fasta' )
128 ->write_seq( $seq )