Merge branch 'master' of https://github.com/solgenomics/sgn
[sgn.git] / cgi-bin / tools / intron_detection / display_introns.pl
blob1421e7e927dd8c1a04c1b1f9c84fdbb10c3bc5e4
2 use strict;
3 use warnings;
5 use IO::Scalar;
6 use File::Temp;
7 use File::Spec;
8 use CXGN::Debug;
9 use CXGN::BlastDB;
10 use CXGN::Page;
11 use CXGN::Page::FormattingHelpers qw/page_title_html/;
12 use SGN::IntronFinder::Homology;
14 my $d = CXGN::Debug->new();
16 my $page = CXGN::Page->new( "Intron Finder Results", "Emil" );
18 my $temp_file_path = $page->path_to($page->tempfiles_subdir('intron_detection'));
20 $page->add_style( text => <<EOS );
21 a[href^="http:"] {
22 padding-right: 0;
23 background: none;
25 EOS
27 my ( $input, $blast_e_val ) = $page->get_arguments( "genes", "blast_e_value" );
28 $input =~ s/\r//g; #remove weird line endings
29 $input =~ s/^\s+|\s+$//g; #< trim whitespace
30 $input = ">web_sequence\n$input" unless $input =~ /^>/;
32 $blast_e_val =~ s/(^\s*|\s*)//g;
33 if ( $blast_e_val !~ m/^\d+(e-\d+)?$/ ) {
34 show_error(
35 $page,
36 'e_bad' => 1,
37 'seq_bad' => 0,
38 'seq_notindb' => 0,
39 'unfound_seq_id' => ''
41 return 1;
44 my $out_file = File::Temp->new(
45 TEMPLATE => 'intron-finder-output-XXXXXX',
46 DIR => $temp_file_path,
48 $out_file->close; #< can't use this filehandle
50 $page->header();
51 print page_title_html("Intron Finder Results");
53 $d->d("Runninge the intron finder command...\n");
55 my ($protein_db) = CXGN::BlastDB->search( file_base => 'ath/ATH_pep' ) or die "could not find ath/ATH_pep BLAST database";
57 my $gene_feature_file =
58 ( $page->get_conf('intron_finder_database')
59 || die 'no conf var intron_finder_database defined!' )
60 . "/SV_gene_feature.data";
62 -f $gene_feature_file or die "gene feature file '$gene_feature_file' not found";
64 print '<pre>';
65 my $output;
66 open my $input_fh, '<', \$input or die $!;
67 open my $output_fh, '>', \$output or die $!;
69 SGN::IntronFinder::Homology::find_introns_txt
70 ( $input_fh,
71 $output_fh,
72 $blast_e_val,
73 $gene_feature_file,
74 $temp_file_path,
75 $protein_db->full_file_basename,
77 print $output;
78 print '</pre>';
79 print qq|<a href="find_introns.pl">Return to search page</a><br /><br />|;
81 $page->footer();
83 # show there was an error and link back to the entry page
84 # possible arguments: e_bad => 0|1, seq_bad => 0|1, seq_notindb => 0|1,
85 # unfound_seq_id => seq_id
87 sub show_error {
88 my ( $page, %errors ) = @_;
90 $page->add_style( text => "p.error {font-weight: bold}" );
91 $page->header();
92 print page_title_html("Bad Input");
93 if ( $errors{e_bad} ) {
94 print
95 "<p class=\"error\">E-value for blast should be an integer or in xe-xx format.</p>";
97 if ( $errors{seq_bad} ) {
98 print "<p class=\"error\">Please enter your query in FASTA format.</p>";
100 elsif ( $errors{seq_notindb} ) {
101 print
102 "<p class=\"error\">EST identifier $errors{unfound_seq_id} could not be found in the database. Please enter a DNA sequence for it.</p>";
105 print "<p><a href=\"find_introns.pl\">Go back</a> and try again.</p>";
106 $page->footer();