2 package SGN
::Controller
::BreedersToolbox
::Trial
;
5 use CXGN
::Trial
::TrialLayout
;
6 use CXGN
::BreedersToolbox
::Projects
;
8 BEGIN { extends
'Catalyst::Controller'; }
11 sub trial_info
: Path
('/breeders_toolbox/trial') Args
(1) {
15 my $schema = $c->dbic_schema('Bio::Chado::Schema', 'sgn_chado');
16 my $trial_layout = CXGN
::Trial
::TrialLayout
->new({schema
=> $schema, trial_id
=> $trial_id} );
17 my $program_object = CXGN
::BreedersToolbox
::Projects
->new( { schema
=> $schema });
18 my $breeding_program = $program_object->get_breeding_program_with_trial($trial_id);
19 my $trial_name = $trial_layout->get_trial_name();
20 my $trial_description = $trial_layout->get_trial_description();
21 my $trial_year = $trial_layout->get_trial_year();
22 my $design_type = $trial_layout->get_design_type();
23 my $plot_names_ref = $trial_layout->get_plot_names();
24 my $accession_names_ref = $trial_layout->get_accession_names();
25 my $control_names_ref = $trial_layout->get_control_names();
26 my $block_numbers = $trial_layout->get_block_numbers();
27 my $replicate_numbers = $trial_layout->get_replicate_numbers();
31 if ($plot_names_ref) {
32 @plot_names = @
{$trial_layout->get_plot_names()};
35 $c->stash->{design_type
} = $design_type;
36 $c->stash->{accession_names
} = $accession_names_ref;
37 $c->stash->{control_names
} = $control_names_ref;
38 $c->stash->{plot_names
} = $plot_names_ref;
39 $c->stash->{design_type
} = $design_type;
40 $c->stash->{trial_description
} = $trial_description;
41 $c->stash->{trial_id
} = $trial_id;
44 $number_of_blocks = scalar(@
{$block_numbers});
46 $c->stash->{number_of_blocks
} = $number_of_blocks;
47 my $number_of_replicates;
48 if ($replicate_numbers) {
49 $number_of_replicates = scalar(@
{$replicate_numbers});
51 $c->stash->{number_of_replicates
} = $number_of_replicates;
53 my $user = $c->user();
55 $c->stash->{template
} = '/generic_message.mas';
56 $c->stash->{message
} = 'You must be logged in to access this page.';
59 my $dbh = $c->dbc->dbh();
61 my $h = $dbh->prepare("SELECT project.name FROM project WHERE project_id=?");
62 $h->execute($trial_id);
64 my ($name) = $h->fetchrow_array();
66 $c->stash->{trial_name
} = $name;
68 $h = $dbh->prepare("SELECT distinct(nd_geolocation.nd_geolocation_id), nd_geolocation.description, count(*) FROM nd_geolocation JOIN nd_experiment USING(nd_geolocation_id) JOIN nd_experiment_project USING (nd_experiment_id) JOIN project USING (project_id) WHERE project_id=? GROUP BY nd_geolocation_id, nd_geolocation.description");
69 $h->execute($trial_id);
71 my @location_data = ();
72 while (my ($id, $desc, $count) = $h->fetchrow_array()) {
73 push @location_data, [$id, $desc, $count];
76 $c->stash->{location_data
} = \
@location_data;
78 $h = $dbh->prepare("SELECT distinct(cvterm.name), count(*) FROM cvterm JOIN phenotype ON (cvterm_id=cvalue_id) JOIN nd_experiment_phenotype USING(phenotype_id) JOIN nd_experiment_project USING(nd_experiment_id) WHERE project_id=? GROUP BY cvterm.name");
80 $h->execute($trial_id);
83 while (my ($trait, $count) = $h->fetchrow_array()) {
84 push @phenotype_data, [$trait, $count];
86 $c->stash->{phenotype_data
} = \
@phenotype_data;
88 $h = $dbh->prepare("SELECT distinct(projectprop.value) FROM projectprop WHERE project_id=? AND type_id=(SELECT cvterm_id FROM cvterm WHERE name='project year')");
89 $h->execute($trial_id);
92 while (my ($year) = $h->fetchrow_array()) {
96 $c->stash->{user_can_modify
} = $user->check_roles("submitter");
98 $c->stash->{breeding_program
} = $breeding_program;
100 $c->stash->{years
} = \
@years;
102 $c->stash->{plot_data
} = [];
104 $c->stash->{trial_id
} = $trial_id;
106 $c->stash->{template
} = '/breeders_toolbox/trial.mas';