4 CXGN::Trial - factory object for project entries (phenotyping trials, genotyping trials, crossing trials, and analyses
8 my $trial = CXGN::Trial->new( { bcs_schema => $schema, ... , trial_id => $trial_id });
10 If $trial_id is a phenotyping trial, the type of object returned will be CXGN::PhenotypingTrial.
14 Lukas Mueller <lam87@cornell.edu>
26 use CXGN
::Trial
::Folder
;
27 use CXGN
::Trial
::TrialLayout
;
28 use CXGN
::Trial
::TrialLayoutDownload
;
29 use SGN
::Model
::Cvterm
;
34 use File
::Basename qw
| basename dirname
|;
41 If $trial_id is a genotyping trial, the type of object returned will be CXGN::GenotypingTrial.
43 If $trial_id is a crossing trial, the type of object returned will be CXGN::CrossingTrial.
45 If $trial_id is an analysis, the type of object returned will be CXGN::Analysis.
49 Inheritance structure of Trial objects:
51 CXGN::Trial - Factory object (for backwards compatibility)
55 ---CXGN::PhenotypingTrial
57 | ---CXGN::GenotypingTrial
59 | ---CXGN::CrossingTrial
65 Lukas Mueller <lam87@cornell.edu>
67 Based on work by the entire group :-)
73 use CXGN
::PhenotypingTrial
;
74 use CXGN
::GenotypingTrial
;
75 use CXGN
::CrossingTrial
;
77 use CXGN
::SamplingTrial
;
78 use CXGN
::ManagementFactor
;
79 use CXGN
::GenotypeDataProject
;
80 use CXGN
::AerialImagingEventBandProject
;
81 use CXGN
::AerialImagingEventProject
;
87 my $schema = $args->{bcs_schema
};
88 my $trial_id = $args->{trial_id
};
90 my $trial_rs = $schema->resultset("Project::Projectprop")->search( { project_id
=> $trial_id },{ join => 'type' });
92 if ($trial_id && $trial_rs->count() == 0) {
93 return CXGN
::PhenotypingTrial
->new($args);
97 while (my $trial_row = $trial_rs->next()) {
98 my $name = $trial_row->type()->name();
99 my $val = $trial_row->value();
100 # print STDERR Dumper [$name, $val];
101 if ($val eq "genotyping_plate") {
102 return CXGN
::GenotypingTrial
->new($args);
104 elsif ($name eq "crossing_trial") {
105 return CXGN
::CrossingTrial
->new($args);
107 elsif ($name eq "analysis") {
108 return CXGN
::Analysis
->new($args);
110 elsif ($val eq "treatment") {
111 return CXGN
::ManagementFactor
->new($args);
113 elsif ($val eq "sampling_trial") {
114 return CXGN
::SamplingTrial
->new($args);
116 elsif (($val eq "genotype_data_project") || ($val eq "pcr_genotype_data_project")) {
117 return CXGN
::GenotypeDataProject
->new($args);
119 elsif ($val eq "drone_run") {
120 return CXGN
::AerialImagingEventProject
->new($args);
122 elsif ($val eq "drone_run_band") {
123 return CXGN
::AerialImagingEventBandProject
->new($args);
126 $object = CXGN
::PhenotypingTrial
->new($args);
132 =head2 class method get_all_locations()
134 Usage: my $locations = CXGN::Trial::get_all_locations($schema)
143 sub get_all_locations
{
145 my $location_id = shift;
150 $search_params{'nd_geolocation_id'} = $location_id;
153 my $loc = $schema->resultset('NaturalDiversity::NdGeolocation')->search( \
%search_params, {order_by
=> { -asc
=> 'nd_geolocation_id' }} );
154 while (my $s = $loc->next()) {
155 my $loc_props = $schema->resultset('NaturalDiversity::NdGeolocationprop')->search( { nd_geolocation_id
=> $s->nd_geolocation_id() }, {join=>'type', '+select'=>['me.value', 'type.name'], '+as'=>['value', 'cvterm_name'] } );
158 $attr{'geodetic datum'} = $s->geodetic_datum();
161 my $country_code = '';
162 my $location_type = '';
163 my $abbreviation = '';
166 while (my $sp = $loc_props->next()) {
167 if ($sp->get_column('cvterm_name') eq 'country_name') {
168 $country = $sp->get_column('value');
169 } elsif ($sp->get_column('cvterm_name') eq 'country_code') {
170 $country_code = $sp->get_column('value');
171 } elsif ($sp->get_column('cvterm_name') eq 'location_type') {
172 $location_type = $sp->get_column('value');
173 } elsif ($sp->get_column('cvterm_name') eq 'abbreviation') {
174 $abbreviation = $sp->get_column('value');
175 } elsif ($sp->get_column('cvterm_name') eq 'geolocation address') {
176 $address = $sp->get_column('value');
178 $attr{$sp->get_column('cvterm_name')} = $sp->get_column('value') ;
182 push @locations, [$s->nd_geolocation_id(), $s->description(), $s->latitude(), $s->longitude(), $s->altitude(), $country, $country_code, \
%attr, $location_type, $abbreviation, $address],
190 =head2 class method get_all_project_types()
192 Usage: my @cvterm_ids = CXGN::Trial::get_all_project_types($schema)
201 sub get_all_project_types
{
204 my $project_type_cv_id = $schema->resultset('Cv::Cv')->find( { name
=> 'project_type' } )->cv_id();
205 my $rs = $schema->resultset('Cv::Cvterm')->search( { cv_id
=> $project_type_cv_id }, {order_by
=>'me.cvterm_id'} );
207 if ($rs->count() > 0) {
208 @cvterm_ids = map { [ $_->cvterm_id(), $_->name(), $_->definition ] } ($rs->all());
214 =head2 function get_all_phenotype_metadata($schema, $n)
217 Usage: CXGN::Trial->get_phenotype_metadata($schema, 100);
218 Desc: retrieves maximally $n metadata.md_file entries for the any trial . These entries are created during StorePhenotypes.
226 sub get_all_phenotype_metadata
{
229 my $n = shift || 200;
232 my $q = "SELECT file_id, m.create_date, p.sp_person_id, p.username, basename, dirname, filetype FROM nd_experiment_project JOIN nd_experiment_phenotype USING(nd_experiment_id) JOIN phenome.nd_experiment_md_files ON (nd_experiment_phenotype.nd_experiment_id=nd_experiment_md_files.nd_experiment_id) LEFT JOIN metadata.md_files using(file_id) LEFT JOIN metadata.md_metadata as m using(metadata_id) LEFT JOIN sgn_people.sp_person as p ON (p.sp_person_id=m.create_person_id) WHERE m.obsolete = 0 and NOT (metadata.md_files.filetype='generated from plot from plant phenotypes') and NOT (metadata.md_files.filetype='direct phenotyping') ORDER BY file_id ASC LIMIT $n";
233 my $h = $schema->storage()->dbh()->prepare($q);
236 while (my ($file_id, $create_date, $person_id, $username, $basename, $dirname, $filetype) = $h->fetchrow_array()) {
237 $file_info{$file_id} = [$file_id, $create_date, $person_id, $username, $basename, $dirname, $filetype];
239 foreach (keys %file_info){
240 push @file_array, $file_info{$_};