search stocks by location
[sgn.git] / cgi-bin / search / unigene.pl
blob166bd52bf52bf564cfea4191926625369f6e4c5a
1 #!/usr/bin/perl
3 =head1 NAME
5 unigene_mason.pl
6 Controller to show the web_page for unigene using MASON.
8 =cut
10 =head1 SYNOPSIS
13 =head1 DESCRIPTION
15 This is the script to show the web_page using MASON
17 =cut
19 =head1 AUTHORS
21 Aureliano Bombarely Gomez
22 (ab782@cornell.edu)
24 =cut
27 use strict;
28 use warnings;
30 use CGI ();
32 use CXGN::DB::Connection;
34 use CXGN::Transcript::Unigene;
36 use CatalystX::GlobalContext '$c';
38 ## Use of CXGN::Page to take the arguments from the URL
40 my $q = CGI->new;
42 my %args = $q->Vars;
44 my $schema = $c->dbic_schema( 'CXGN::GEM::Schema', 'sgn_chado' );
45 my $sgn_schema = $c->dbic_schema( 'SGN::Schema' );
47 my $dbh = CXGN::DB::Connection->new();
49 ## To do more flexible how the unigene can be called
51 if (defined $args{'unigene_id'}) {
52 $args{'id'} = $args{'unigene_id'} ;
53 $args{'id'} =~ s/^SGN-U//;
55 # convert CGN-U to SGN-U
56 if( $args{unigene_id} =~ s/^CGN-?U//i ) {
57 my ($sgnid) = $dbh->selectrow_array(<<EOS,undef, $args{unigene_id}, 'CGN');
58 SELECT unigene_id FROM unigene WHERE sequence_name = ? AND database_name=?
59 EOS
60 if( $sgnid ) {
61 $args{'id'} = $sgnid;
68 ## Random function will get at random unigene from the latest unigene build
70 if (defined $args{'random'}) {
71 if ($args{'random'} =~ m/^yes$/i) {
72 my $last_unigene_build_id = $sgn_schema->resultset('UnigeneBuild')
73 ->search(
74 undef,
76 order_by => 'unigene_build_id DESC',
77 limit => 1
80 ->first()
81 ->get_column('unigene_build_id');
83 ## Now get all the unigene_id for this unigene_build_id
85 my $random_unigene_id = $sgn_schema->resultset('Unigene')
86 ->search(
88 unigene_build_id => $last_unigene_build_id
91 order_by => 'random()',
92 limit => 1
95 ->first()
96 ->get_column('unigene_id');
98 ## It will replace $args{'id'}
100 $args{'id'} = $random_unigene_id;
104 ## Now it will take the unigene object based in the unigene_id (it will create an empty object by default)
106 my $unigene = CXGN::Transcript::Unigene->new($dbh);
108 if (defined $args{'id'} && $args{'id'} =~ m/^\d+$/) {
110 $unigene = CXGN::Transcript::Unigene->new($dbh, $args{'id'});
114 ## Now depending if there are enought condition, it will call a mason unigen page ($unigene object has an id)
115 ## or an error page
117 if (defined $unigene && defined $unigene->get_unigene_id() ) {
119 $c->forward_to_mason_view(
120 '/transcript/unigene_detail.mas',
121 dbh => $dbh,
122 schema => $schema,
123 sgn_schema => $sgn_schema,
124 unigene => $unigene,
125 highlight => $args{'highlight'},
126 force_image => $args{'force_image'},
127 basepath => $c->config->{basepath},
128 temp_dir => $c->tempfiles_subdir('unigene_images'),
130 } else {
131 $c->forward_to_mason_view(
132 '/transcript/transcript_page_error.mas',
133 object => $unigene );