catch error when trial has no phenotype data. closes #407
[sgn.git] / cgi-bin / phenome / organism_browser.pl
blob4a4ab2a2192d840a99f5828bc0f083916e213524
2 #!/usr/bin/perl -wT
5 =head1 SYNOPSIS
6 A simple script that retrieves common names and their ids, and
7 writes out id of the selected organism into a file.
8 It is used to work with the Ajax form for the QTL webform.
12 =head1 AUTHOR
14 Isaak Y Tecle iyt2@cornell.edu
16 =cut
20 use strict;
21 use warnings;
23 use Path::Class;
25 use CXGN::Scrap::AjaxPage;
26 use CXGN::DB::Connection;
27 use CXGN::Login;
28 use CXGN::Phenome::Qtl;
30 use CatalystX::GlobalContext qw( $c );
32 my $doc = CXGN::Scrap::AjaxPage->new();
33 $doc->send_http_header();
36 my ($common_name, $common_name_id, $type, $sp_person_id) = $doc->get_encoded_arguments("organism", "organism_id", "type", "sp_person_id");
38 my $dbh = CXGN::DB::Connection->new();
39 my ($login_person_id, $login_user_type)=CXGN::Login->new($dbh)->verify_session();
41 if ($login_user_type eq 'curator' || $login_user_type eq 'submitter' || $login_user_type eq 'sequencer') {
43 if ($type eq 'browse') {
44 &browse_organisms($dbh, $type, $common_name);
46 elsif ($type eq 'associate') {
47 &associate_organism($dbh, $type, $common_name_id, $login_person_id);
52 sub browse_organisms {
53 my ($dbh, $type, $common_name) = @_;
54 my $organisms;
56 if ($type eq 'browse')
58 if ($common_name)
60 my $sth = $dbh->prepare ("SELECT common_name_id, common_name
61 FROM sgn.common_name WHERE common_name ILIKE '$common_name%'"
63 $sth->execute();
65 while (my ($common_name_id, $common_name) = $sth->fetchrow_array())
67 $organisms .= "$common_name_id*$common_name_id -- $common_name |";
69 print $organisms;
74 sub associate_organism {
75 my ($dbh, $type, $common_name_id, $sp_person_id) = @_;
77 my $qtl = CXGN::Phenome::Qtl->new($sp_person_id);
78 my ($temp_qtl_dir, $temp_user_dir) = $qtl->create_user_qtl_dir($c);
80 my $f = file( $temp_user_dir, 'organism.txt' )->openw
81 or die "Can't create file: $! \n";
82 $f->print( "common_name_id\t$common_name_id" );