Merge pull request #5248 from solgenomics/topic/batch_update_trials
[sgn.git] / cgi-bin / phenome / locus_page / get_locus_cvterms.pl
blob19eb04e5ad05382313b34f4f68a743ad0b7f8d63
1 use strict;
2 use warnings;
4 use CXGN::Scrap::AjaxPage;
5 use CXGN::DB::Connection;
6 use CXGN::Login;
7 use CXGN::Contact;
8 use CXGN::People::Person;
11 use CXGN::Phenome::Locus;
12 use CXGN::Chado::Cvterm;
13 use CXGN::Feed;
15 use JSON;
18 my $doc = CXGN::Scrap::AjaxPage->new();
19 $doc->send_http_header();
20 my %response = ();
21 my $json = JSON->new();
23 my ($locus_id) = $doc->get_encoded_arguments("locus_id");
25 my $dbh = CXGN::DB::Connection->new();
26 my ($login_person_id, $login_user_type)=CXGN::Login->new($dbh)->verify_session();
28 if ($login_user_type eq 'curator' || $login_user_type eq 'submitter' || $login_user_type eq 'sequencer') {
31 if ($locus_id) {
32 my $jobj;
33 my $available_cvterms;
34 eval{
35 my $locus = CXGN::Phenome::Locus->new($dbh, $locus_id);
37 my $locus_pub_ranks=$locus->get_locus_pub(); # this sets cvterm_ranks
38 my $cvterm_total_ranks=$locus->get_cvterm_ranks();
40 my @sorted_cvterms = sort{$cvterm_total_ranks->{$b} <=> $cvterm_total_ranks->{$a}} keys %$cvterm_total_ranks;
41 foreach my $cvterm_id (@sorted_cvterms) {
42 my $rank= $cvterm_total_ranks->{$cvterm_id};
43 my $cvterm=CXGN::Chado::Cvterm->new($dbh, $cvterm_id);
44 my $dbxref_id=$cvterm->get_dbxref_id();
45 my $db_name=$cvterm->get_db_name();
46 my $cv_name=$cvterm->get_cv_name();
47 my $accession= $cvterm->get_accession();
48 my $cvterm_name= $cvterm->get_cvterm_name();
50 $available_cvterms .="$dbxref_id*$cv_name:$db_name:$accession--$cvterm_name ($rank)|";
51 $response{$dbxref_id}= "$cv_name:$db_name:$accession--$cvterm_name ($rank)";
55 if ($@) {
56 $response{"error"} = "get_locus_cvterms failed! " . $@;
58 $jobj = $json->objToJson(\%response); # replaced by 'encode' but not on the old version of JSON in Rubisco!
59 #print STDERR $jobj;
60 print $jobj;