seedlot upload with accession synonyms. seedlot upload works to update existing seedlots
[sgn.git] / lib / SGN / Controller / AJAX / HTMLSelect.pm
blob722589401898ab420afc59ca4d398d798f295074
2 =head1 SGN::Controller::AJAX::HTMLSelect - a resource to dynamically obtain html selects for a number of widely used data types
4 =head1 SYNOPSYS
6 get_location_select()
8 get_breeding_program_select()
10 get_year_select()
14 =head1 AUTHOR
16 Lukas Mueller <lam87@cornell.edu>
18 =cut
20 package SGN::Controller::AJAX::HTMLSelect;
22 use Moose;
24 use Data::Dumper;
25 use CXGN::BreedersToolbox::Projects;
26 use CXGN::Page::FormattingHelpers qw | simple_selectbox_html |;
27 use Scalar::Util qw | looks_like_number |;
28 use CXGN::Trial;
29 use CXGN::Onto;
30 use CXGN::List;
31 use CXGN::Trial::Folder;
32 use SGN::Model::Cvterm;
33 use CXGN::Chado::Stock;
34 use CXGN::Stock::Search;
35 use CXGN::Stock::Seedlot;
36 use CXGN::Dataset;
38 BEGIN { extends 'Catalyst::Controller::REST' };
40 __PACKAGE__->config(
41 default => 'application/json',
42 stash_key => 'rest',
43 map => { 'application/json' => 'JSON', 'text/html' => 'JSON' },
47 sub get_location_select : Path('/ajax/html/select/locations') Args(0) {
48 my $self = shift;
49 my $c = shift;
51 my $id = $c->req->param("id") || "location_select";
52 my $name = $c->req->param("name") || "location_select";
53 my $empty = $c->req->param("empty") || "";
55 my $locations = CXGN::BreedersToolbox::Projects->new( { schema => $c->dbic_schema("Bio::Chado::Schema") } )->get_all_locations();
57 if ($empty) { unshift @$locations, [ "", "Select Location" ] }
59 my $default = $c->req->param("default") || @$locations[0]->[0];
61 my $html = simple_selectbox_html(
62 name => $name,
63 id => $id,
64 choices => $locations,
65 selected => $default
67 $c->stash->{rest} = { select => $html };
70 sub get_breeding_program_select : Path('/ajax/html/select/breeding_programs') Args(0) {
71 my $self = shift;
72 my $c = shift;
74 my $id = $c->req->param("id") || "breeding_program_select";
75 my $name = $c->req->param("name") || "breeding_program_select";
76 my $empty = $c->req->param("empty") || "";
78 my $breeding_programs = CXGN::BreedersToolbox::Projects->new( { schema => $c->dbic_schema("Bio::Chado::Schema") } )->get_breeding_programs();
80 my $default = $c->req->param("default") || @$breeding_programs[0]->[0];
81 if ($empty) { unshift @$breeding_programs, [ "", "please select" ]; }
83 my $html = simple_selectbox_html(
84 name => $name,
85 id => $id,
86 choices => $breeding_programs,
87 selected => $default
89 $c->stash->{rest} = { select => $html };
92 sub get_year_select : Path('/ajax/html/select/years') Args(0) {
93 my $self = shift;
94 my $c = shift;
96 my $id = $c->req->param("id") || "year_select";
97 my $name = $c->req->param("name") || "year_select";
98 my $empty = $c->req->param("empty") || "";
99 my $auto_generate = $c->req->param("auto_generate") || "";
101 my @years;
102 if ($auto_generate) {
103 my $next_year = 1901 + (localtime)[5];
104 my $oldest_year = $next_year - 30;
105 @years = sort { $b <=> $a } ($oldest_year..$next_year);
107 else {
108 @years = sort { $b <=> $a } CXGN::BreedersToolbox::Projects->new( { schema => $c->dbic_schema("Bio::Chado::Schema") } )->get_all_years();
111 my $default = $c->req->param("default") || $years[1];
113 my $html = simple_selectbox_html(
114 name => $name,
115 id => $id,
116 choices => \@years,
117 selected => $default
119 $c->stash->{rest} = { select => $html };
122 sub get_trial_folder_select : Path('/ajax/html/select/folders') Args(0) {
123 my $self = shift;
124 my $c = shift;
126 my $breeding_program_id = $c->req->param("breeding_program_id");
127 my $folder_for_trials = 1 ? $c->req->param("folder_for_trials") eq 'true' : 0;
128 my $folder_for_crosses = 1 ? $c->req->param("folder_for_crosses") eq 'true' : 0;
130 my $id = $c->req->param("id") || "folder_select";
131 my $name = $c->req->param("name") || "folder_select";
132 my $empty = $c->req->param("empty") || ""; # set if an empty selection should be present
135 my @folders = CXGN::Trial::Folder->list({
136 bcs_schema => $c->dbic_schema("Bio::Chado::Schema"),
137 breeding_program_id => $breeding_program_id,
138 folder_for_trials => $folder_for_trials,
139 folder_for_crosses => $folder_for_crosses
142 if ($empty) {
143 unshift @folders, [ 0, "None" ];
146 my $html = simple_selectbox_html(
147 name => $name,
148 id => $id,
149 choices => \@folders,
151 $c->stash->{rest} = { select => $html };
154 sub get_trial_type_select : Path('/ajax/html/select/trial_types') Args(0) {
155 my $self = shift;
156 my $c = shift;
158 my $id = $c->req->param("id") || "trial_type_select";
159 my $name = $c->req->param("name") || "trial_type_select";
160 my $empty = $c->req->param("empty") || ""; # set if an empty selection should be present
162 my @types = CXGN::Trial::get_all_project_types($c->dbic_schema("Bio::Chado::Schema"));
164 if ($empty) {
165 unshift @types, [ '', "None" ];
168 my $default = $c->req->param("default") || $types[0]->[0];
170 my $html = simple_selectbox_html(
171 name => $name,
172 id => $id,
173 choices => \@types,
174 selected => $default
176 $c->stash->{rest} = { select => $html };
179 sub get_treatments_select : Path('/ajax/html/select/treatments') Args(0) {
180 my $self = shift;
181 my $c = shift;
182 my $schema = $c->dbic_schema("Bio::Chado::Schema");
183 my $trial_id = $c->req->param("trial_id");
185 my $id = $c->req->param("id") || "treatment_select";
186 my $name = $c->req->param("name") || "treatment_select";
187 my $empty = $c->req->param("empty") || ""; # set if an empty selection should be present
189 my $trial = CXGN::Trial->new({ bcs_schema => $schema, trial_id => $trial_id });
190 my $data = $trial->get_treatments();
192 if ($empty) {
193 unshift @$data, [ 0, "None" ];
195 my $html = simple_selectbox_html(
196 name => $name,
197 id => $id,
198 choices => $data,
200 $c->stash->{rest} = { select => $html };
203 sub get_trials_select : Path('/ajax/html/select/trials') Args(0) {
204 my $self = shift;
205 my $c = shift;
206 my $p = CXGN::BreedersToolbox::Projects->new( { schema => $c->dbic_schema("Bio::Chado::Schema") } );
207 my $breeding_program_id = $c->req->param("breeding_program_id");
209 my $projects;
210 if (!$breeding_program_id) {
211 $projects = $p->get_breeding_programs();
212 } else {
213 push @$projects, [$breeding_program_id];
216 my $id = $c->req->param("id") || "html_trial_select";
217 my $name = $c->req->param("name") || "html_trial_select";
218 my $size = $c->req->param("size");
219 my $empty = $c->req->param("empty") || "";
220 my $multiple = $c->req->param("multiple") || 0;
221 my $live_search = $c->req->param("live_search") || 0;
223 my @trials;
224 foreach my $project (@$projects) {
225 my ($field_trials, $cross_trials, $genotyping_trials) = $p->get_trials_by_breeding_program($project->[0]);
226 foreach (@$field_trials) {
227 push @trials, $_;
230 @trials = sort { $a->[1] cmp $b->[1] } @trials;
232 if ($empty) { unshift @trials, [ "", "Please select a trial" ]; }
234 my $html = simple_selectbox_html(
235 multiple => $multiple,
236 live_search => $live_search,
237 name => $name,
238 id => $id,
239 size => $size,
240 choices => \@trials,
242 $c->stash->{rest} = { select => $html };
246 sub get_label_data_source_select : Path('/ajax/html/select/label_data_sources') Args(0) {
247 my $self = shift;
248 my $c = shift;
249 print STDERR "Retrieving list items . . .\n";
251 my $id = $c->req->param("id") || "label_data_sources_select";
252 my $name = $c->req->param("name") || "label_data_sources_select";
253 my $empty = $c->req->param("empty") || "";
254 my $live_search = $c->req->param("live_search") ? 'data-live-search="true"' : '';
255 my $default = $c->req->param("default") || 0;
257 my $user_id = $c->user()->get_sp_person_id();
258 my $lists = CXGN::List::available_lists($c->dbc->dbh(), $user_id, 'plots');
259 my $public_lists = CXGN::List::available_public_lists($c->dbc->dbh(), 'plots');
261 my $p = CXGN::BreedersToolbox::Projects->new( { schema => $c->dbic_schema("Bio::Chado::Schema") } );
262 my $projects = $p->get_breeding_programs();
264 my (@field_trials, @cross_trials, @genotyping_trials) = [];
265 foreach my $project (@$projects) {
266 my ($field_trials, $cross_trials, $genotyping_trials) = $p->get_trials_by_breeding_program($project->[0]);
267 foreach (@$field_trials) {
268 push @field_trials, $_;
270 foreach (@$cross_trials) {
271 push @cross_trials, $_;
273 foreach (@$genotyping_trials) {
274 push @genotyping_trials, $_;
278 my @choices = [];
279 push @choices, '__Your Plot Lists';
280 foreach my $item (@$lists) {
281 push @choices, [@$item[0], @$item[1]];
283 push @choices, '__Public Plot Lists';
284 foreach my $item (@$public_lists) {
285 push @choices, [@$item[0], @$item[1]];
287 push @choices, '__Field Trials';
288 @field_trials = sort { $a->[1] cmp $b->[1] } @field_trials;
289 foreach my $trial (@field_trials) {
290 push @choices, $trial;
292 push @choices, '__Genotyping Trials';
293 @genotyping_trials = sort { $a->[1] cmp $b->[1] } @genotyping_trials;
294 foreach my $trial (@genotyping_trials) {
295 push @choices, $trial;
297 push @choices, '__Cross Trials';
298 @cross_trials = sort { $a->[1] cmp $b->[1] } @cross_trials;
299 foreach my $trial (@cross_trials) {
300 push @choices, $trial;
303 print STDERR "Choices are:\n".Dumper(@choices);
305 if ($default) { unshift @choices, [ '', $default ]; }
307 my $html = simple_selectbox_html(
308 name => $name,
309 id => $id,
310 choices => \@choices,
311 params => $live_search,
312 selected_params => 'hidden'
315 $c->stash->{rest} = { select => $html };
317 # sub get_trials_select : Path('/ajax/html/select/trials') Args(0) {
318 # my $self = shift;
319 # my $c = shift;
321 # my $id = $c->req->param("id") || "label_data_sources_select";
322 # my $name = $c->req->param("name") || "label_data_sources_select";
323 # my $empty = $c->req->param("empty") || "";
324 # my $live_search = $c->req->param("live_search") ? 'data-live-search="true"' : '';
325 # my $default = $c->req->param("default") || 0;
327 # my $lists = CXGN::List::available_lists($c->dbc->dbh(), $c->user(), 'plots');
328 # my $public_lists = CXGN::List::available_public_lists($c->dbc->dbh(), 'plots');
330 # my $projects = CXGN::BreedersToolbox::Projects->new( { schema => $c->dbic_schema("Bio::Chado::Schema") } )->get_breeding_programs();
331 # my @trials = [];
332 # foreach my $project (@$projects) {
333 # my ($field_trials, $cross_trials, $genotyping_trials) = $projects->get_trials_by_breeding_program($project->[0]);
334 # foreach (@$field_trials) {
335 # push @trials, $_;
338 # @trials = sort { $a->[1] cmp $b->[1] } @trials;
340 # my @choices = [];
341 # push @choices, '__Your Plot Lists';
342 # foreach my $item (@$lists) {
343 # push @choices, $item;
345 # push @choices, '__Public Plot Lists';
346 # foreach my $item (@$public_lists) {
347 # push @choices, $item;
349 # push @choices, '__Trials';
350 # foreach my $trial (@trials) {
351 # push @choices, $trial;
354 # print STDERR "Choices are:\n".Dumper(@choices);
356 # if ($default) { unshift @trials, [ '', $default ]; }
358 # my $html = simple_selectbox_html(
359 # name => $name,
360 # id => $id,
361 # choices => \@choices,
362 # params => $live_search
363 # );
365 # $c->stash->{rest} = { select => $html };
368 sub get_stocks_select : Path('/ajax/html/select/stocks') Args(0) {
369 my $self = shift;
370 my $c = shift;
371 my $params = _clean_inputs($c->req->params);
372 my $names_as_select = $params->{names_as_select}->[0] || 0;
374 my %stockprops_values;
375 if ($params->{organization_list} && scalar(@{$params->{organization_list}})>0){
376 $stockprops_values{'organization'} = $params->{organization_list};
378 if ($params->{pui_list} && scalar(@{$params->{pui_list}})>0){
379 $stockprops_values{'PUI'} = $params->{pui_list};
381 if ($params->{accession_number_list} && scalar(@{$params->{accession_number_list}})>0){
382 $stockprops_values{'accession number'} = $params->{accession_number_list};
385 my $stock_search = CXGN::Stock::Search->new({
386 bcs_schema=>$c->dbic_schema("Bio::Chado::Schema", "sgn_chado"),
387 people_schema=>$c->dbic_schema("CXGN::People::Schema"),
388 phenome_schema=>$c->dbic_schema("CXGN::Phenome::Schema"),
389 match_type=>$params->{match_type}->[0],
390 match_name=>$params->{match_type}->[0],
391 uniquename_list=>$params->{uniquename_list},
392 genus_list=>$params->{genus_list},
393 species_list=>$params->{species_list},
394 stock_id_list=>$params->{stock_id_list},
395 organism_id=>$params->{organism_id}->[0],
396 stock_type_name=>$params->{stock_type_name}->[0],
397 stock_type_id=>$params->{stock_type_id}->[0],
398 owner_first_name=>$params->{owner_first_name}->[0],
399 owner_last_name=>$params->{owner_last_name}->[0],
400 trait_cvterm_name_list=>$params->{trait_cvterm_name_list},
401 minimum_phenotype_value=>$params->{minimum_phenotype_value}->[0],
402 maximum_phenotype_value=>$params->{maximum_phenotype_value}->[0],
403 trial_name_list=>$params->{trial_name_list},
404 trial_id_list=>$params->{trial_id_list},
405 breeding_program_id_list=>$params->{breeding_program_id_list},
406 location_name_list=>$params->{location_name_list},
407 year_list=>$params->{year_list},
408 stockprops_values=>\%stockprops_values,
409 limit=>$params->{limit}->[0],
410 offset=>$params->{offset}->[0],
411 minimal_info=>1,
412 display_pedigree=>0
414 my ($result, $records_total) = $stock_search->search();
415 #print STDERR Dumper $result;
416 my $id = $c->req->param("id") || "html_trial_select";
417 my $name = $c->req->param("name") || "html_trial_select";
418 my $multiple = defined($c->req->param("multiple")) ? $c->req->param("multiple") : 1;
419 my $size = $c->req->param("size");
420 my $empty = $c->req->param("empty") || "";
421 my $data_related = $c->req->param("data-related") || "";
422 my @stocks;
423 foreach my $r (@$result) {
424 if ($names_as_select) {
425 push @stocks, [ $r->{uniquename}, $r->{uniquename} ];
426 } else {
427 push @stocks, [ $r->{stock_id}, $r->{uniquename} ];
430 @stocks = sort { $a->[1] cmp $b->[1] } @stocks;
432 if ($empty) { unshift @stocks, [ "", "Please select a stock" ]; }
434 my $html = simple_selectbox_html(
435 multiple => $multiple,
436 name => $name,
437 id => $id,
438 size => $size,
439 choices => \@stocks,
440 data_related => $data_related
442 $c->stash->{rest} = { select => $html };
445 sub get_seedlots_select : Path('/ajax/html/select/seedlots') Args(0) {
446 my $self = shift;
447 my $c = shift;
448 my $accessions = $c->req->param('seedlot_content_accession_name') ? [$c->req->param('seedlot_content_accession_name')] : [];
449 my $crosses = $c->req->param('seedlot_content_cross_name') ? [$c->req->param('seedlot_content_cross_name')] : [];
450 my ($list, $records_total) = CXGN::Stock::Seedlot->list_seedlots(
451 $c->dbic_schema("Bio::Chado::Schema", "sgn_chado"),
452 $c->dbic_schema("CXGN::People::Schema"),
453 $c->dbic_schema("CXGN::Phenome::Schema"),
454 $c->req->param('seedlot_offset'),
455 $c->req->param('seedlot_limit'),
456 $c->req->param('seedlot_name'),
457 $c->req->param('seedlot_breeding_program_name'),
458 $c->req->param('seedlot_location'),
459 $c->req->param('seedlot_amount'),
460 $accessions,
461 $crosses,
464 my @seedlots;
465 foreach my $sl (@$list) {
466 push @seedlots, {
467 breeding_program_id => $sl->{breeding_program_id},
468 breeding_program_name => $sl->{breeding_program_name},
469 seedlot_stock_id => $sl->{seedlot_stock_id},
470 seedlot_stock_uniquename => $sl->{seedlot_stock_uniquename},
471 location => $sl->{location},
472 location_id => $sl->{location_id},
473 count => $sl->{current_count}
476 #print STDERR Dumper \@seedlots;
477 my $id = $c->req->param("id") || "html_trial_select";
478 my $name = $c->req->param("name") || "html_trial_select";
479 my $multiple = defined($c->req->param("multiple")) ? $c->req->param("multiple") : 1;
480 my $size = $c->req->param("size");
481 my $empty = $c->req->param("empty") || "";
482 my $data_related = $c->req->param("data-related") || "";
483 my @stocks;
484 foreach my $r (@seedlots) {
485 push @stocks, [ $r->{seedlot_stock_id}, $r->{seedlot_stock_uniquename} ];
487 @stocks = sort { $a->[1] cmp $b->[1] } @stocks;
489 if ($empty) { unshift @stocks, [ "", "Please select a stock" ]; }
491 my $html = simple_selectbox_html(
492 multiple => $multiple,
493 name => $name,
494 id => $id,
495 size => $size,
496 choices => \@stocks,
497 data_related => $data_related
499 $c->stash->{rest} = { select => $html };
502 sub get_traits_select : Path('/ajax/html/select/traits') Args(0) {
503 my $self = shift;
504 my $c = shift;
505 my $trial_ids = $c->req->param('trial_ids') || 'all';
506 my $stock_id = $c->req->param('stock_id') || 'all';
507 my $stock_type = $c->req->param('stock_type') ? $c->req->param('stock_type') . 's' : 'none';
508 my $data_level = $c->req->param('data_level') || 'all';
509 my $schema = $c->dbic_schema("Bio::Chado::Schema");
511 if ($data_level eq 'all') {
512 $data_level = '';
515 my @traits;
516 if (($trial_ids eq 'all') && ($stock_id eq 'all')) {
517 my $bs = CXGN::BreederSearch->new( { dbh=> $c->dbc->dbh() } );
518 my $status = $bs->test_matviews($c->config->{dbhost}, $c->config->{dbname}, $c->config->{dbuser}, $c->config->{dbpass});
519 unless ($status->{'success'}) {
520 $c->stash->{rest} = { select => '<center><p>Direct trait select is not currently available</p></center>'};
521 return;
523 my $query = $bs->metadata_query([ 'traits' ], {}, {});
524 @traits = @{$query->{results}};
525 #print STDERR "Traits: ".Dumper(@traits)."\n";
526 } elsif (looks_like_number($stock_id)) {
527 my $stock = CXGN::Chado::Stock->new($schema, $stock_id);
528 my @trait_list = $stock->get_trait_list();
529 foreach (@trait_list){
530 my @val = ($_->[0], $_->[2]."|".$_->[1]);
531 push @traits, \@val;
533 } elsif ($trial_ids ne 'all') {
534 my @trial_ids = split ',', $trial_ids;
535 my %unique_traits_ids;
536 foreach (@trial_ids){
537 my $trial = CXGN::Trial->new({bcs_schema=>$schema, trial_id=>$_});
538 my $traits_assayed = $trial->get_traits_assayed($data_level);
539 foreach (@$traits_assayed) {
540 $unique_traits_ids{$_->[0]} = [$_->[0], $_->[1]];
543 while ( my ($key, $value) = each %unique_traits_ids ){
544 push @traits, $value;
548 @traits = sort { $a->[1] cmp $b->[1] } @traits;
550 my $id = $c->req->param("id") || "html_trial_select";
551 my $name = $c->req->param("name") || "html_trial_select";
552 my $size = $c->req->param("size");
554 my $html = simple_selectbox_html(
555 multiple => 1,
556 name => $name,
557 id => $id,
558 choices => \@traits,
559 size => $size
561 $c->stash->{rest} = { select => $html };
564 sub get_phenotyped_trait_components_select : Path('/ajax/html/select/phenotyped_trait_components') Args(0) {
565 my $self = shift;
566 my $c = shift;
567 my $trial_ids = $c->req->param('trial_ids');
568 #my $stock_id = $c->req->param('stock_id') || 'all';
569 #my $stock_type = $c->req->param('stock_type') . 's' || 'none';
570 my $data_level = $c->req->param('data_level') || 'all';
571 my $schema = $c->dbic_schema("Bio::Chado::Schema");
572 my $composable_cvterm_format = $c->config->{composable_cvterm_format};
574 if ($data_level eq 'all') {
575 $data_level = '';
578 my @trial_ids = split ',', $trial_ids;
580 my @trait_components;
581 foreach (@trial_ids){
582 my $trial = CXGN::Trial->new({bcs_schema=>$schema, trial_id=>$_});
583 push @trait_components, @{$trial->get_trait_components_assayed($data_level, $composable_cvterm_format)};
585 #print STDERR Dumper \@trait_components;
586 my %unique_trait_components = map {$_->[0] => $_->[1]} @trait_components;
587 my @unique_components;
588 foreach my $id (keys %unique_trait_components){
589 push @unique_components, [$id, $unique_trait_components{$id}];
591 #print STDERR Dumper \@unique_components;
593 my $id = $c->req->param("id") || "html_trait_component_select";
594 my $name = $c->req->param("name") || "html_trait_component_select";
596 my $html = simple_selectbox_html(
597 multiple => 1,
598 name => $name,
599 id => $id,
600 choices => \@unique_components,
602 $c->stash->{rest} = { select => $html };
605 sub get_composable_cvs_allowed_combinations_select : Path('/ajax/html/select/composable_cvs_allowed_combinations') Args(0) {
606 my $self = shift;
607 my $c = shift;
608 my $id = $c->req->param("id") || "html_composable_cvs_combinations_select";
609 my $name = $c->req->param("name") || "html_composable_cvs_combinations_select";
610 my $composable_cvs_allowed_combinations = $c->config->{composable_cvs_allowed_combinations};
611 my @combinations = split ',', $composable_cvs_allowed_combinations;
612 my @select;
613 foreach (@combinations){
614 my @parts = split /\|/, $_; #/#
615 push @select, [$parts[1], $parts[0]];
617 my $html = simple_selectbox_html(
618 name => $name,
619 id => $id,
620 choices => \@select,
622 $c->stash->{rest} = { select => $html };
625 sub get_crosses_select : Path('/ajax/html/select/crosses') Args(0) {
626 my $self = shift;
627 my $c = shift;
629 my $p = CXGN::BreedersToolbox::Projects->new( { schema => $c->dbic_schema("Bio::Chado::Schema") } );
631 my $breeding_program_id = $c->req->param("breeding_program_id");
632 my $projects;
633 if (!$breeding_program_id) {
634 $projects = $p->get_breeding_programs();
635 } else {
636 push @$projects, [$breeding_program_id];
639 my $id = $c->req->param("id") || "html_trial_select";
640 my $name = $c->req->param("name") || "html_trial_select";
641 my $size = $c->req->param("size");
642 my @crosses;
643 foreach my $project (@$projects) {
644 my ($field_trials, $cross_trials, $genotyping_trials) = $p->get_trials_by_breeding_program($project->[0]);
645 foreach (@$cross_trials) {
646 push @crosses, $_;
649 @crosses = sort @crosses;
651 my $html = simple_selectbox_html(
652 multiple => 1,
653 name => $name,
654 id => $id,
655 size => $size,
656 choices => \@crosses,
658 $c->stash->{rest} = { select => $html };
661 sub get_genotyping_protocols_select : Path('/ajax/html/select/genotyping_protocols') Args(0) {
662 my $self = shift;
663 my $c = shift;
665 my $id = $c->req->param("id") || "gtp_select";
666 my $name = $c->req->param("name") || "genotyping_protocol_select";
667 my $empty = $c->req->param("empty") || "";
668 my $default_gtp;
669 my %gtps;
671 my $gt_protocols = CXGN::BreedersToolbox::Projects->new( { schema => $c->dbic_schema("Bio::Chado::Schema") } )->get_gt_protocols();
673 if (@$gt_protocols) {
674 $default_gtp = $c->config->{default_genotyping_protocol};
675 %gtps = map { @$_[1] => @$_[0] } @$gt_protocols;
677 if(!exists($gtps{$default_gtp}) && !($default_gtp =~ /^none$/)) {
678 die "The conf variable default_genotyping_protocol: \"$default_gtp\" does not match any protocols in the database. Set it in sgn_local.conf using a protocol name from the nd_protocol table, or set it to 'none' to silence this error.";
680 } else {
681 $gt_protocols = ["No genotyping protocols found"];
683 my $html = simple_selectbox_html(
684 name => $name,
685 id => $id,
686 choices => $gt_protocols,
687 selected => $gtps{$default_gtp}
689 $c->stash->{rest} = { select => $html };
692 sub get_trait_components_select : Path('/ajax/html/select/trait_components') Args(0) {
694 my $self = shift;
695 my $c = shift;
697 my $cv_id = $c->req->param('cv_id');
698 #print STDERR "cv_id = $cv_id\n";
699 my $id = $c->req->param("id") || "component_select";
700 my $name = $c->req->param("name") || "component_select";
701 my $default = $c->req->param("default") || 0;
702 my $multiple = $c->req->param("multiple") || 0;
703 my $size = $c->req->param('size') || '5';
705 my $dbh = $c->dbc->dbh();
706 my $onto = CXGN::Onto->new( { schema => $c->dbic_schema('Bio::Chado::Schema', 'sgn_chado') } );
707 my @components = $onto->get_terms($cv_id);
708 #print STDERR Dumper \@components;
709 if ($default) { unshift @components, [ '', $default ]; }
711 my $html = simple_selectbox_html(
712 name => $name,
713 multiple => $multiple,
714 id => $id,
715 choices => \@components,
716 size => $size
719 $c->stash->{rest} = { select => $html };
724 sub ontology_children_select : Path('/ajax/html/select/ontology_children') Args(0) {
725 my ($self, $c) = @_;
726 my $parent_node_cvterm = $c->request->param("parent_node_cvterm");
727 my $rel_cvterm = $c->request->param("rel_cvterm");
728 my $rel_cv = $c->request->param("rel_cv");
729 my $size = $c->req->param('size') || '5';
730 my $value_format = $c->req->param('value_format') || 'ids';
731 print STDERR "Parent Node $parent_node_cvterm\n";
733 my $select_name = $c->request->param("selectbox_name");
734 my $select_id = $c->request->param("selectbox_id");
736 my $empty = $c->request->param("empty") || '';
737 my $multiple = $c->req->param("multiple") || 0;
739 my $schema = $c->dbic_schema('Bio::Chado::Schema', 'sgn_chado');
740 my $parent_node_cvterm_row = SGN::Model::Cvterm->get_cvterm_row_from_trait_name($schema, $parent_node_cvterm);
741 my $parent_node_cvterm_id;
742 if ($parent_node_cvterm_row){
743 $parent_node_cvterm_id = $parent_node_cvterm_row->cvterm_id();
745 my $rel_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, $rel_cvterm, $rel_cv)->cvterm_id();
747 my $ontology_children_ref = $schema->resultset("Cv::CvtermRelationship")->search({type_id => $rel_cvterm_id, object_id => $parent_node_cvterm_id})->search_related('subject');
748 my @ontology_children;
749 while (my $child = $ontology_children_ref->next() ) {
750 my $cvterm_id = $child->cvterm_id();
751 my $dbxref_info = $child->search_related('dbxref');
752 my $accession = $dbxref_info->first()->accession();
753 my $db_info = $dbxref_info->search_related('db');
754 my $db_name = $db_info->first()->name();
755 if ($value_format eq 'ids'){
756 push @ontology_children, [$cvterm_id, $child->name."|".$db_name.":".$accession];
758 if ($value_format eq 'names'){
759 push @ontology_children, [$child->name."|".$db_name.":".$accession, $child->name."|".$db_name.":".$accession];
763 @ontology_children = sort { $a->[1] cmp $b->[1] } @ontology_children;
764 if ($empty) {
765 unshift @ontology_children, [ 0, "None" ];
767 #print STDERR Dumper \@ontology_children;
768 my $html = simple_selectbox_html(
769 name => $select_name,
770 id => $select_id,
771 multiple => $multiple,
772 choices => \@ontology_children,
774 $c->stash->{rest} = { select => $html };
777 sub get_datasets_select :Path('/ajax/html/select/datasets') Args(0) {
778 my $self = shift;
779 my $c = shift;
781 my $html = '<select><option disabled="1">None</option></select>';
782 my $user_id;
783 if ($c->user()) {
784 if ($user_id = $c->user->get_object()->get_sp_person_id()) {
786 my $datasets = CXGN::Dataset->get_datasets_by_user(
787 $c->dbic_schema("CXGN::People::Schema"),
788 $user_id);
790 print STDERR "Retrieved datasets: ".Dumper($datasets);
792 $html = simple_selectbox_html(
793 name => 'available_datasets',
794 id => 'available_datasets',
795 choices => $datasets,
800 $c->stash->{rest} = { select => $html };
803 sub _clean_inputs {
804 no warnings 'uninitialized';
805 my $params = shift;
806 foreach (keys %$params){
807 my $values = $params->{$_};
808 my $ret_val;
809 if (ref \$values eq 'SCALAR'){
810 push @$ret_val, $values;
811 } elsif (ref $values eq 'ARRAY'){
812 $ret_val = $values;
813 } else {
814 die "Input is not a scalar or an arrayref\n";
816 @$ret_val = grep {$_ ne undef} @$ret_val;
817 @$ret_val = grep {$_ ne ''} @$ret_val;
818 $_ =~ s/\[\]$//; #ajax POST with arrays adds [] to the end of the name e.g. germplasmName[]. since all inputs are arrays now we can remove the [].
819 $params->{$_} = $ret_val;
821 return $params;