Merge pull request #5205 from solgenomics/topic/generic_trial_upload
[sgn.git] / lib / SGN / Controller / Ontology.pm
blob1ea670407f082941bb269fa7afce0b92120dc0ca
2 package SGN::Controller::Ontology;
4 use CXGN::Chado::Cvterm;
5 use CXGN::People::Roles;
6 use URI::FromHash 'uri';
7 use CXGN::Page::FormattingHelpers qw | simple_selectbox_html |;
8 use CXGN::Onto;
9 use Data::Dumper;
11 use Moose;
13 BEGIN { extends 'Catalyst::Controller' };
14 with 'Catalyst::Component::ApplicationAttribute';
17 sub onto_browser : Path('/tools/onto') :Args(0) {
18 my $self = shift;
19 my $c = shift;
21 my $root_nodes = $c->config->{onto_root_namespaces};
22 my @namespaces = split ",", $root_nodes;
23 foreach my $n (@namespaces) {
24 $n =~ s/\s*(\w+)\s*\(.*\)/$1/g;
25 print STDERR "Adding node $n\n";
27 #$c->stash->{root_nodes} = $c->req->param("root_nodes");
28 $c->stash->{root_nodes} = join " ", @namespaces;
29 $c->stash->{db_name} = $c->req->param("db_name");
30 $c->stash->{expand} = $c->req->param("expand");
32 $c->stash->{template} = '/ontology/standalone.mas';
36 sub compose_trait : Path('/tools/compose') :Args(0) {
37 my $self = shift;
38 my $c = shift;
40 if (!$c->user()) {
41 # redirect to login page
42 $c->res->redirect( uri( path => '/user/login', query => { goto_url => $c->req->uri->path_query } ) );
43 return;
46 my @composable_cvs = split ",", $c->config->{composable_cvs};
47 my $dbh = $c->dbc->dbh();
48 my $sp_person_id = $c->user() ? $c->user->get_object()->get_sp_person_id() : undef;
49 my $onto = CXGN::Onto->new( { schema => $c->dbic_schema('Bio::Chado::Schema', 'sgn_chado', $sp_person_id) } );
50 my %html_hash;
51 foreach my $name (@composable_cvs) {
52 $name =~ s/^\s+|\s+$//g; # remove whitespace
53 if ($name eq 'time' || $name eq 'tod' || $name eq 'toy' || $name eq 'gen' || $name eq 'evt' ) {
54 print STDERR "Skipping time-related cv\n";
55 next;
57 my $cv_type = $name."_ontology";
58 #print STDERR "cv_type = $cv_type\n";
61 my @root_nodes = $onto->get_root_nodes($cv_type);
62 #print STDERR Dumper \@root_nodes;
63 if (scalar @root_nodes > 1) {
64 #create simple selectbox of root_nodes
65 my $id = $name."_root_select";
66 my $name = $name."_root_select";
67 my $html = simple_selectbox_html(
68 name => $name,
69 id => $id,
70 choices => \@root_nodes,
71 size => '10',
72 default => 'Pick an Ontology'
74 #put html in hash
75 $html_hash{$cv_type} = $html;
77 else {
78 my $cv_id = $root_nodes[0][0];
79 my @components = $onto->get_terms($cv_id);
81 my $id = $name."_select";
82 my $name = $name."_select";
83 my $default = 0;
84 if ($default) { unshift @components, [ '', $default ]; }
86 my $html = simple_selectbox_html(
87 name => $name,
88 multiple => 1,
89 id => $id,
90 choices => \@components,
91 size => '10'
93 #put html in hash
94 $html_hash{$cv_type} = $html;
98 $c->stash->{object_select} = $html_hash{'object_ontology'};
99 $c->stash->{attribute_select} = $html_hash{'attribute_ontology'};
100 $c->stash->{method_select} = $html_hash{'method_ontology'};
101 $c->stash->{unit_select} = $html_hash{'unit_ontology'};
102 $c->stash->{trait_select} = $html_hash{'trait_ontology'};
104 $c->stash->{composable_cvs} = $c->config->{composable_cvs};
105 $c->stash->{composable_cvs_allowed_combinations} = $c->config->{composable_cvs_allowed_combinations};
106 $c->stash->{composable_tod_root_cvterm} = $c->config->{composable_tod_root_cvterm};
107 $c->stash->{composable_toy_root_cvterm} = $c->config->{composable_toy_root_cvterm};
108 $c->stash->{composable_gen_root_cvterm} = $c->config->{composable_gen_root_cvterm};
109 $c->stash->{composable_evt_root_cvterm} = $c->config->{composable_evt_root_cvterm};
111 $c->stash->{user} = $c->user();
112 $c->stash->{template} = '/ontology/compose_trait.mas';