Merge pull request #5134 from solgenomics/topic/fix_seedlot_search
[sgn.git] / cgi-bin / search / unigene.pl
blob0444b819871e3221ce7c1986af26379cbbeb30a0
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 $sp_person_id = $c->user() ? $c->user->get_object()->get_sp_person_id() : undef;
45 my $schema = $c->dbic_schema( 'CXGN::GEM::Schema', 'sgn_chado', $sp_person_id );
46 my $sgn_schema = $c->dbic_schema( 'SGN::Schema', undef, $sp_person_id );
48 my $dbh = CXGN::DB::Connection->new();
50 ## To do more flexible how the unigene can be called
52 if (defined $args{'unigene_id'}) {
53 $args{'id'} = $args{'unigene_id'} ;
54 $args{'id'} =~ s/^SGN-U//;
56 # convert CGN-U to SGN-U
57 if( $args{unigene_id} =~ s/^CGN-?U//i ) {
58 my ($sgnid) = $dbh->selectrow_array(<<EOS,undef, $args{unigene_id}, 'CGN');
59 SELECT unigene_id FROM unigene WHERE sequence_name = ? AND database_name=?
60 EOS
61 if( $sgnid ) {
62 $args{'id'} = $sgnid;
69 ## Random function will get at random unigene from the latest unigene build
71 if (defined $args{'random'}) {
72 if ($args{'random'} =~ m/^yes$/i) {
73 my $last_unigene_build_id = $sgn_schema->resultset('UnigeneBuild')
74 ->search(
75 undef,
77 order_by => 'unigene_build_id DESC',
78 limit => 1
81 ->first()
82 ->get_column('unigene_build_id');
84 ## Now get all the unigene_id for this unigene_build_id
86 my $random_unigene_id = $sgn_schema->resultset('Unigene')
87 ->search(
89 unigene_build_id => $last_unigene_build_id
92 order_by => 'random()',
93 limit => 1
96 ->first()
97 ->get_column('unigene_id');
99 ## It will replace $args{'id'}
101 $args{'id'} = $random_unigene_id;
105 ## Now it will take the unigene object based in the unigene_id (it will create an empty object by default)
107 my $unigene = CXGN::Transcript::Unigene->new($dbh);
109 if (defined $args{'id'} && $args{'id'} =~ m/^\d+$/) {
111 $unigene = CXGN::Transcript::Unigene->new($dbh, $args{'id'});
115 ## Now depending if there are enought condition, it will call a mason unigen page ($unigene object has an id)
116 ## or an error page
118 if (defined $unigene && defined $unigene->get_unigene_id() ) {
120 $c->forward_to_mason_view(
121 '/transcript/unigene_detail.mas',
122 dbh => $dbh,
123 schema => $schema,
124 sgn_schema => $sgn_schema,
125 unigene => $unigene,
126 highlight => $args{'highlight'},
127 force_image => $args{'force_image'},
128 basepath => $c->config->{basepath},
129 temp_dir => $c->tempfiles_subdir('unigene_images'),
131 } else {
132 $c->forward_to_mason_view(
133 '/transcript/transcript_page_error.mas',
134 object => $unigene );