seedlot upload with accession synonyms. seedlot upload works to update existing seedlots
[sgn.git] / lib / SGN / Controller / AJAX / Transcript.pm
blob4126e325a7203b51817eec587e7d4e4b50278f4c
2 =head1 NAME
4 SGN::Controller::AJAX::Transcript - a REST controller class to provide the
5 backend for objects linked with transcripts (AKA unigenes)
7 =head1 DESCRIPTION
9 Browse the unigene database for selecting unigenes to be linked with other objects
11 =head1 AUTHOR
13 Naama Menda <nm249@cornell.edu>
15 =cut
17 package SGN::Controller::AJAX::Transcript;
19 use Moose;
21 use List::MoreUtils qw /any /;
22 use Try::Tiny;
23 use Scalar::Util qw(looks_like_number);
26 BEGIN { extends 'Catalyst::Controller::REST' }
28 __PACKAGE__->config(
29 default => 'application/json',
30 stash_key => 'rest',
31 map => { 'application/json' => 'JSON', 'text/html' => 'JSON' },
35 =head2 autocomplete
37 Public Path: /ajax/transcript/autocomplete
39 Autocomplete a unigene name. Takes a single GET param,
40 C<term>, responds with a JSON array of completions for that term.
42 =cut
44 sub autocomplete : Local : ActionClass('REST') { }
46 sub autocomplete_GET :Args(0) {
47 my ( $self, $c ) = @_;
48 my $unigene_name = $c->request->param("term");
49 my $current = $c->request->param('current') ; #pass this param for printing only current unigenes
50 my $organism = $c->request->param('organism');
51 my ($organism_c, $status_c);
52 my $dbh = $c->dbc->dbh;
53 my $query = "SELECT unigene_id, unigene_build_id, nr_members, build_nr, database_name, sequence_name, status FROM sgn.unigene LEFT JOIN sgn.unigene_build using(unigene_build_id) WHERE unigene_id = ? ";
55 my $sth= $dbh->prepare($query);
56 my @response_list;
57 $unigene_name =~ s/SGN.?U?//i;
58 if (looks_like_number($unigene_name) ) {
59 $sth->execute($unigene_name);
60 while (my ($unigene_id, $build_id, $nr_members, $build_nr, $db_name, $seq_name, $build_status) = $sth->fetchrow_array() ) {
61 my $unigene = CXGN::Transcript::Unigene->new($dbh, $unigene_id);
62 my $unigene_build = $unigene->get_unigene_build;
63 my $unigene_organism = $unigene_build->get_common_name();
64 if ($organism && $unigene_organism ne $organism) { $organism_c = 1; }
65 if ($current && $build_status ne "C") { $status_c = 1; }
66 if (!$organism_c && !$status_c) {
67 push @response_list, "SGN-U$unigene_id--build $build_id--$nr_members members";
71 $c->stash->{rest} = \@response_list;
74 ###
75 1;#
76 ###