4 SGN::Controller::AJAX::Transcript - a REST controller class to provide the
5 backend for objects linked with transcripts (AKA unigenes)
9 Browse the unigene database for selecting unigenes to be linked with other objects
13 Naama Menda <nm249@cornell.edu>
17 package SGN
::Controller
::AJAX
::Transcript
;
21 use List
::MoreUtils qw
/any /;
23 use Scalar
::Util
qw(looks_like_number);
26 BEGIN { extends
'Catalyst::Controller::REST' }
29 default => 'application/json',
31 map => { 'application/json' => 'JSON', 'text/html' => 'JSON' },
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.
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);
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;