6 use SGN::Test::Fixture;
10 my $fix = SGN::Test::Fixture->new();
12 is(ref($fix->config()), "HASH", 'hashref check');
14 BEGIN {use_ok('CXGN::Trial::TrialCreate');}
15 BEGIN {use_ok('CXGN::Trial::TrialLayout');}
16 BEGIN {use_ok('CXGN::Trial::TrialDesign');}
17 BEGIN {use_ok('CXGN::Trial::TrialLookup');}
18 ok(my $chado_schema = $fix->bcs_schema);
19 ok(my $phenome_schema = $fix->phenome_schema);
20 ok(my $dbh = $fix->dbh);
22 # create a location for the trial
23 ok(my $trial_location = "test_location_for_trial");
24 ok(my $location = $chado_schema->resultset('NaturalDiversity::NdGeolocation')
26 description => $trial_location,
28 ok($location->insert());
30 # create stocks for the trial
31 ok(my $accession_cvterm = $chado_schema->resultset("Cv::Cvterm")
38 for (my $i = 1; $i <= 10; $i++) {
39 push(@stock_names, "test_stock_for_trial".$i);
42 #create stocks for genotyping trial
43 my @genotyping_stock_names;
44 for (my $i = 1; $i <= 10; $i++) {
45 push(@genotyping_stock_names, "test_stock_for_genotyping_trial".$i);
49 ok(my $organism = $chado_schema->resultset("Organism::Organism")
51 genus => 'Test_genus',
52 species => 'Test_genus test_species',
55 # create some test stocks
56 foreach my $stock_name (@stock_names) {
57 my $accession_stock = $chado_schema->resultset('Stock::Stock')
59 organism_id => $organism->organism_id,
61 uniquename => $stock_name,
62 type_id => $accession_cvterm->cvterm_id,
66 # create some genotyping test stocks
67 foreach my $stock_name (@genotyping_stock_names) {
68 my $accession_stock = $chado_schema->resultset('Stock::Stock')
70 organism_id => $organism->organism_id,
72 uniquename => $stock_name,
73 type_id => $accession_cvterm->cvterm_id,
78 ok(my $trial_design = CXGN::Trial::TrialDesign->new(), "create trial design object");
79 ok($trial_design->set_trial_name("test_trial"), "set trial name");
80 ok($trial_design->set_stock_list(\@stock_names), "set stock list");
81 ok($trial_design->set_plot_start_number(1), "set plot start number");
82 ok($trial_design->set_plot_number_increment(1), "set plot increment");
83 ok($trial_design->set_number_of_blocks(2), "set block number");
84 ok($trial_design->set_design_type("RCBD"), "set design type");
85 ok($trial_design->calculate_design(), "calculate design");
86 ok(my $design = $trial_design->get_design(), "retrieve design");
88 my $ayt_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($chado_schema, 'Advanced Yield Trial', 'project_type')->cvterm_id();
90 ok(my $trial_create = CXGN::Trial::TrialCreate->new({
91 chado_schema => $chado_schema,
93 user_name => "johndoe", #not implemented
97 trial_description => "test description",
98 trial_location => "test_location_for_trial",
99 trial_name => "new_test_trial_name",
100 trial_type=>$ayt_cvterm_id,
101 design_type => "RCBD",
102 operator => "janedoe"
103 }), "create trial object");
105 my $save = $trial_create->save_trial();
106 ok($save->{'trial_id'}, "save trial");
108 ok(my $trial_lookup = CXGN::Trial::TrialLookup->new({
109 schema => $chado_schema,
110 trial_name => "new_test_trial_name",
111 }), "create trial lookup object");
112 ok(my $trial = $trial_lookup->get_trial());
113 ok(my $trial_id = $trial->project_id());
114 ok(my $trial_layout = CXGN::Trial::TrialLayout->new({
115 schema => $chado_schema,
116 trial_id => $trial_id,
117 experiment_type => 'field_layout'
118 }), "create trial layout object");
120 ok(my $accession_names = $trial_layout->get_accession_names(), "retrieve accession names1");
122 my %stocks = map { $_ => 1 } @stock_names;
124 foreach my $acc (@$accession_names) {
125 ok(exists($stocks{$acc->{accession_name}}), "check accession names $acc->{accession_name}");
130 #create RCBD trial with one accession
133 push @stock_names, "test_stock_for_trial1";
135 ok(my $trial_design = CXGN::Trial::TrialDesign->new(), "create trial design object");
136 ok($trial_design->set_trial_name("new_test_trial_name_single"), "set trial name");
137 ok($trial_design->set_stock_list(\@stock_names), "set stock list");
138 ok($trial_design->set_plot_start_number(1), "set plot start number");
139 ok($trial_design->set_plot_number_increment(1), "set plot increment");
140 ok($trial_design->set_number_of_reps(2), "set rep number");
141 ok($trial_design->set_design_type("CRD"), "set design type");
142 ok($trial_design->calculate_design(), "calculate design");
143 ok(my $design = $trial_design->get_design(), "retrieve design");
145 ok(my $trial_create = CXGN::Trial::TrialCreate->new({
146 chado_schema => $chado_schema,
148 user_name => "johndoe", #not implemented
151 trial_year => "2015",
152 trial_description => "test description",
153 trial_location => "test_location_for_trial",
154 trial_name => "new_test_trial_name_single",
155 design_type => "RCBD",
156 operator => "janedoe"
157 }), "create trial object");
159 my $save = $trial_create->save_trial();
160 ok($save->{'trial_id'}, "save trial");
162 ok(my $trial_lookup = CXGN::Trial::TrialLookup->new({
163 schema => $chado_schema,
164 trial_name => "new_test_trial_name_single",
165 }), "create trial lookup object");
166 ok(my $trial = $trial_lookup->get_trial());
167 ok(my $trial_id = $trial->project_id());
168 ok(my $trial_layout = CXGN::Trial::TrialLayout->new({
169 schema => $chado_schema,
170 trial_id => $trial_id,
171 experiment_type => 'field_layout'
172 }), "create trial layout object");
174 ok(my $accession_names = $trial_layout->get_accession_names(), "retrieve accession names2");
176 my %stocks = map { $_ => 1 } @stock_names;
178 foreach my $acc (@$accession_names) {
179 ok(exists($stocks{$acc->{accession_name}}), "check accession names $acc->{accession_name}");
183 # layout for genotyping experiment
184 # use data structure returned by brapi call for GDF:
185 # plates:[ { 'project_id' : 'project x',
186 # 'plate_name' : 'required',
187 # 'plate_format': 'Plate_96' | 'tubes',
188 # 'sample_type' : 'DNA' | 'RNA' | 'Tissue'
191 # 'name': 'sample_name1',
201 elements => \@genotyping_stock_names,
204 name => 'test_genotyping_trial_name',
205 description => "test description",
207 project_name => 'NextGenCassava',
208 genotyping_facility_submit => 'no',
209 genotyping_facility => 'igd',
213 my $gd = CXGN::Trial::TrialDesign->new( { schema => $chado_schema } );
214 $gd->set_stock_list($plate_info->{elements});
215 $gd->set_block_size($plate_info->{plate_format});
216 $gd->set_blank($plate_info->{blank_well});
217 $gd->set_trial_name($plate_info->{name});
218 $gd->set_design_type("genotyping_plate");
219 $gd->calculate_design();
220 my $geno_design = $gd->get_design();
222 print STDERR Dumper $geno_design;
223 is_deeply($geno_design, {
226 'plot_name' => 'test_genotyping_trial_name_A09',
227 'stock_name' => 'test_stock_for_genotyping_trial8',
230 'plot_number' => 'A09'
234 'plot_number' => 'A07',
235 'plot_name' => 'test_genotyping_trial_name_A07',
238 'stock_name' => 'test_stock_for_genotyping_trial6'
242 'plot_number' => 'A02',
244 'plot_name' => 'test_genotyping_trial_name_A02_BLANK',
245 'stock_name' => 'BLANK',
250 'plot_number' => 'A05',
252 'plot_name' => 'test_genotyping_trial_name_A05',
253 'stock_name' => 'test_stock_for_genotyping_trial4',
257 'plot_name' => 'test_genotyping_trial_name_A08',
260 'stock_name' => 'test_stock_for_genotyping_trial7',
262 'plot_number' => 'A08'
265 'plot_name' => 'test_genotyping_trial_name_A04',
267 'stock_name' => 'test_stock_for_genotyping_trial3',
270 'plot_number' => 'A04'
274 'plot_number' => 'A01',
275 'plot_name' => 'test_genotyping_trial_name_A01',
277 'stock_name' => 'test_stock_for_genotyping_trial1',
281 'plot_name' => 'test_genotyping_trial_name_A11',
283 'stock_name' => 'test_stock_for_genotyping_trial10',
286 'plot_number' => 'A11'
289 'plot_number' => 'A06',
291 'stock_name' => 'test_stock_for_genotyping_trial5',
294 'plot_name' => 'test_genotyping_trial_name_A06'
298 'plot_number' => 'A10',
299 'plot_name' => 'test_genotyping_trial_name_A10',
302 'stock_name' => 'test_stock_for_genotyping_trial9'
305 'plot_name' => 'test_genotyping_trial_name_A03',
307 'stock_name' => 'test_stock_for_genotyping_trial2',
310 'plot_number' => 'A03'
312 }, 'check genotyping trial design');
314 my $genotyping_trial_create;
315 ok($genotyping_trial_create = CXGN::Trial::TrialCreate->new({
316 chado_schema => $chado_schema,
318 user_name => "johndoe", #not implemented
320 trial_location => "test_location_for_trial",
321 operator => "janedoe",
322 trial_year => $plate_info->{year},
323 trial_description => $plate_info->{description},
324 design_type => 'genotyping_plate',
325 design => $geno_design,
326 trial_name => $plate_info->{name},
328 genotyping_user_id => 41,
329 genotyping_project_name => $plate_info->{project_name},
330 genotyping_facility_submitted => $plate_info->{genotyping_facility_submit},
331 genotyping_facility => $plate_info->{genotyping_facility},
332 genotyping_plate_format => $plate_info->{plate_format},
333 genotyping_plate_sample_type => $plate_info->{sample_type},
334 }), "create genotyping trial");
336 my $save = $genotyping_trial_create->save_trial();
337 ok($save->{'trial_id'}, "save genotyping trial");
339 ok(my $genotyping_trial_lookup = CXGN::Trial::TrialLookup->new({
340 schema => $chado_schema,
341 trial_name => "test_genotyping_trial_name",
342 }), "lookup genotyping trial");
343 ok(my $genotyping_trial = $genotyping_trial_lookup->get_trial(), "retrieve genotyping trial");
344 ok(my $genotyping_trial_id = $genotyping_trial->project_id(), "retrive genotyping trial id");
345 ok(my $genotyping_trial_layout = CXGN::Trial::TrialLayout->new({
346 schema => $chado_schema,
347 trial_id => $genotyping_trial_id,
348 experiment_type => 'genotyping_layout'
349 }), "create trial layout object for genotyping trial");
350 ok(my $genotyping_accession_names = $genotyping_trial_layout->get_accession_names(), "retrieve accession names3");
351 my %genotyping_stocks = map { $_ => 1 } @genotyping_stock_names;
352 $genotyping_stocks{'BLANK'} = 1;
353 foreach my $acc (@$genotyping_accession_names) {
354 ok(exists($genotyping_stocks{$acc->{accession_name}}), "check existence of accession names $acc->{accession_name}");