2 package CXGN
::PhenotypingTrial
;
6 extends
'CXGN::Project';
8 use SGN
::Model
::Cvterm
;
10 =head2 function set_field_trials_source_field_trials()
13 Desc: sets associated source field trials for the current field trial
14 Ret: returns an arrayref [ id, name ] of arrayrefs
15 Args: an arrayref [source_trial_id1, source_trial_id2]
21 sub set_field_trials_source_field_trials
{
23 my $source_field_trial_ids = shift;
24 my $schema = $self->bcs_schema;
25 my $field_trial_from_field_trial_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'field_trial_from_field_trial', 'project_relationship')->cvterm_id();
27 foreach (@
$source_field_trial_ids){
29 my $trial_rs= $self->bcs_schema->resultset('Project::ProjectRelationship')->create({
30 'subject_project_id' => $self->get_trial_id(),
31 'object_project_id' => $_,
32 'type_id' => $field_trial_from_field_trial_cvterm_id
36 my $projects = $self->get_field_trials_source_field_trials();
40 =head2 function get_field_trials_source_field_trials()
43 Desc: return associated source field trials for the current field trial
44 Ret: returns an arrayref [ id, name ] of arrayrefs
51 sub get_field_trials_source_field_trials
{
53 my $schema = $self->bcs_schema;
54 my $field_trial_from_field_trial_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'field_trial_from_field_trial', 'project_relationship')->cvterm_id();
56 my $trial_rs= $self->bcs_schema->resultset('Project::ProjectRelationship')->search({
57 'me.subject_project_id' => $self->get_trial_id(),
58 'me.type_id' => $field_trial_from_field_trial_cvterm_id
60 join => 'object_project', '+select' => ['object_project.name'], '+as' => ['source_trial_name']
64 while (my $r = $trial_rs->next) {
65 push @projects, [ $r->object_project_id, $r->get_column('source_trial_name') ];
70 =head2 function get_field_trials_sourced_from_field_trials()
73 Desc: return associated source field trials for the current field trial
74 Ret: returns an arrayref [ id, name ] of arrayrefs
81 sub get_field_trials_sourced_from_field_trials
{
83 my $schema = $self->bcs_schema;
84 my $field_trial_from_field_trial_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'field_trial_from_field_trial', 'project_relationship')->cvterm_id();
86 my $trial_rs= $self->bcs_schema->resultset('Project::ProjectRelationship')->search({
87 'me.object_project_id' => $self->get_trial_id(),
88 'me.type_id' => $field_trial_from_field_trial_cvterm_id
90 join => 'subject_project', '+select' => ['subject_project.name'], '+as' => ['trial_name']
94 while (my $r = $trial_rs->next) {
95 push @projects, [ $r->subject_project_id, $r->get_column('trial_name') ];
100 =head2 function get_drone_run_bands_from_field_trial()
103 Desc: return associated drone_run_band projects for the current field trial
104 Ret: returns an arrayref [ id, name ] of arrayrefs
111 sub get_drone_run_bands_from_field_trial
{
113 my $bcs_schema = $self->bcs_schema;
115 my $project_start_date_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($bcs_schema, 'project_start_date', 'project_property')->cvterm_id();
116 my $design_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($bcs_schema, 'design', 'project_property')->cvterm_id();
117 my $drone_run_band_type_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($bcs_schema, 'drone_run_band_project_type', 'project_property')->cvterm_id();
118 my $project_relationship_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($bcs_schema, 'drone_run_on_field_trial', 'project_relationship')->cvterm_id();
119 my $drone_run_band_relationship_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($bcs_schema, 'drone_run_band_on_drone_run', 'project_relationship')->cvterm_id();
121 my $q = "SELECT drone_run_band.project_id, drone_run_band.name, drone_run_band.description, drone_run_band_type.value, project.project_id, project.name, project.description, project_start_date.value, field_trial.project_id, field_trial.name, field_trial.description
122 FROM project AS drone_run_band
123 JOIN projectprop AS drone_run_band_type ON(drone_run_band.project_id=drone_run_band_type.project_id AND drone_run_band_type.type_id=$drone_run_band_type_cvterm_id)
124 JOIN project_relationship AS drone_run_band_rel ON(drone_run_band.project_id=drone_run_band_rel.subject_project_id AND drone_run_band_rel.type_id=$drone_run_band_relationship_type_id)
125 JOIN project ON (drone_run_band_rel.object_project_id = project.project_id)
126 JOIN projectprop AS project_start_date ON (project.project_id=project_start_date.project_id AND project_start_date.type_id=$project_start_date_type_id)
127 JOIN project_relationship ON (project.project_id = project_relationship.subject_project_id AND project_relationship.type_id=$project_relationship_type_id)
128 JOIN project AS field_trial ON (field_trial.project_id=project_relationship.object_project_id)
129 WHERE field_trial.project_id = ?
130 ORDER BY project.project_id;";
132 my $calendar_funcs = CXGN
::Calendar
->new({});
134 my $h = $bcs_schema->storage->dbh()->prepare($q);
135 $h->execute($self->get_trial_id());
137 while (my ($drone_run_band_project_id, $drone_run_band_name, $drone_run_band_description, $drone_run_band_type, $drone_run_project_id, $drone_run_project_name, $drone_run_project_description, $drone_run_date, $field_trial_project_id, $field_trial_project_name, $field_trial_project_description) = $h->fetchrow_array()) {
138 my $drone_run_date_display = $drone_run_date ?
$calendar_funcs->display_start_date($drone_run_date) : '';
139 push @result, [$drone_run_band_project_id, $drone_run_band_name, $drone_run_band_description, $drone_run_band_type, $drone_run_project_id, $drone_run_project_name, $drone_run_project_description, $drone_run_date_display, $field_trial_project_id, $field_trial_project_name, $field_trial_project_description];
144 =head2 function get_trial_stock_type()
147 Desc: Get stock type used in trial
155 sub get_trial_stock_type
{
157 my $trial_stock_type_cvterm = SGN
::Model
::Cvterm
->get_cvterm_row($self->bcs_schema, 'trial_stock_type', 'project_property');
158 my $type_id = $trial_stock_type_cvterm->cvterm_id();
160 my $stock_type_rs = $self->bcs_schema->resultset('Project::Project')->search( { 'me.project_id' => $self->get_trial_id() })->search_related('projectprops', { type_id
=> $type_id } );
162 if ($stock_type_rs->count() == 0) {
165 return $stock_type_rs->first()->value();