8 use SGN::Test::Fixture;
9 use CXGN::Trial::TrialLayout;
11 use CXGN::Trial::Download;
12 use Spreadsheet::WriteExcel;
13 use Spreadsheet::Read;
14 use CXGN::Fieldbook::DownloadTrial;
16 my $f = SGN::Test::Fixture->new();
18 for my $extension ("xls", "xlsx") {
22 my $tl = CXGN::Trial::TrialLayout->new({ schema => $f->bcs_schema(), trial_id => $trial_id, experiment_type => 'field_layout' });
24 my $d = $tl->get_design();
25 print STDERR Dumper($d);
32 foreach my $plot_num (keys %$d) {
33 push @plot_nums, $plot_num;
34 push @accessions, $d->{$plot_num}->{'accession_name'};
35 push @plant_names, $d->{$plot_num}->{'plant_names'};
36 push @rep_nums, $d->{$plot_num}->{'rep_number'};
37 push @plot_names, $d->{$plot_num}->{'plot_name'};
39 @plot_nums = sort @plot_nums;
40 @accessions = sort @accessions;
41 @plant_names = sort @plant_names;
42 @rep_nums = sort @rep_nums;
43 @plot_names = sort @plot_names;
45 #print STDERR Dumper \@plot_nums;
46 #print STDERR Dumper \@accessions;
47 #print STDERR Dumper \@plant_names;
48 #print STDERR Dumper \@rep_nums;
49 #print STDERR Dumper \@plot_names;
51 is_deeply(\@plot_nums, [
67 ], 'check design plot_nums');
69 is_deeply(\@accessions, [
85 ], 'check design accessions');
87 is_deeply(\@plant_names, [
103 ], "check design plant_names");
105 is_deeply(\@rep_nums, [
121 ], "check design rep_nums");
123 is_deeply(\@plot_names, [
139 ], "check design plot_names");
141 my $trial = CXGN::Trial->new({ bcs_schema => $f->bcs_schema(), trial_id => $trial_id });
142 $trial->create_plant_entities('2');
144 my $tl = CXGN::Trial::TrialLayout->new({ schema => $f->bcs_schema(), trial_id => $trial_id, experiment_type => 'field_layout' });
145 $d = $tl->get_design();
146 print STDERR Dumper($d);
153 my @plant_names_flat;
154 foreach my $plot_num (keys %$d) {
155 push @plot_nums, $plot_num;
156 push @accessions, $d->{$plot_num}->{'accession_name'};
157 push @plant_names, $d->{$plot_num}->{'plant_names'};
158 push @rep_nums, $d->{$plot_num}->{'rep_number'};
159 push @plot_names, $d->{$plot_num}->{'plot_name'};
161 @plot_nums = sort @plot_nums;
162 @accessions = sort @accessions;
163 @rep_nums = sort @rep_nums;
164 @plot_names = sort @plot_names;
166 foreach my $plant_name_arr_ref (@plant_names) {
167 foreach (@$plant_name_arr_ref) {
168 push @plant_names_flat, $_;
171 @plant_names_flat = sort @plant_names_flat;
173 #print STDERR Dumper \@plot_nums;
174 #print STDERR Dumper \@accessions;
175 #print STDERR Dumper \@plant_names_flat;
176 #print STDERR Dumper \@rep_nums;
177 #print STDERR Dumper \@plot_names;
179 is_deeply(\@plot_nums, [
195 ], "check plot_nums after plant addition");
197 is_deeply(\@accessions, [
213 ], "check accessions after plant addition");
215 is_deeply(\@plant_names_flat, [
216 'test_trial210_plant_1',
217 'test_trial210_plant_2',
218 'test_trial211_plant_1',
219 'test_trial211_plant_2',
220 'test_trial212_plant_1',
221 'test_trial212_plant_2',
222 'test_trial213_plant_1',
223 'test_trial213_plant_2',
224 'test_trial214_plant_1',
225 'test_trial214_plant_2',
226 'test_trial215_plant_1',
227 'test_trial215_plant_2',
228 'test_trial21_plant_1',
229 'test_trial21_plant_2',
230 'test_trial22_plant_1',
231 'test_trial22_plant_2',
232 'test_trial23_plant_1',
233 'test_trial23_plant_2',
234 'test_trial24_plant_1',
235 'test_trial24_plant_2',
236 'test_trial25_plant_1',
237 'test_trial25_plant_2',
238 'test_trial26_plant_1',
239 'test_trial26_plant_2',
240 'test_trial27_plant_1',
241 'test_trial27_plant_2',
242 'test_trial28_plant_1',
243 'test_trial28_plant_2',
244 'test_trial29_plant_1',
245 'test_trial29_plant_2'
246 ], "check plant names");
248 is_deeply(\@rep_nums, [
264 ], "check rep nums after plant addition");
266 is_deeply(\@plot_names, [
282 ], "check plot_names after plant addition");
284 my $tempfile = "/tmp/test_create_trial_fieldbook_plots.$extension";
286 my $create_fieldbook = CXGN::Fieldbook::DownloadTrial->new({
287 bcs_schema => $f->bcs_schema,
288 metadata_schema => $f->metadata_schema,
289 phenome_schema => $f->phenome_schema,
290 trial_id => $trial_id,
291 tempfile => $tempfile,
292 archive_path => $f->config->{archive_path},
294 user_name => "janedoe",
295 data_level => 'plots',
296 selected_columns => { 'plot_name' => 1, 'block_number' => 1, 'plot_number' => 1, 'rep_number' => 1, 'row_number' => 1, 'col_number' => 1, 'accession_name' => 1, 'is_a_control' => 1 }
299 my $create_fieldbook_return = $create_fieldbook->download();
300 ok($create_fieldbook_return, "check that download trial fieldbook returns something.");
302 my $contents = ReadData $create_fieldbook_return->{'file'};
304 #print STDERR Dumper @contents->[0]->[0];
305 is($contents->[0]->{'type'}, $extension, "check that type of file is correct");
306 is($contents->[0]->{'sheets'}, '1', "check that type of file is correct");
308 my $columns = $contents->[1]->{'cell'};
309 #print STDERR Dumper scalar(@$columns);
310 ok(scalar(@$columns) == 9, "check number of col in created file.");
312 #print STDERR Dumper $columns;
313 is_deeply($columns, [
422 ], "check fieldbook creation of plots after plants created");
424 my $tempfile = "/tmp/test_create_trial_fieldbook_plants.$extension";
426 my $create_fieldbook = CXGN::Fieldbook::DownloadTrial->new({
427 bcs_schema => $f->bcs_schema,
428 metadata_schema => $f->metadata_schema,
429 phenome_schema => $f->phenome_schema,
430 trial_id => $trial_id,
431 tempfile => $tempfile,
432 archive_path => $f->config->{archive_path},
434 user_name => "janedoe",
435 data_level => 'plants',
436 selected_columns => { 'plant_name' => 1, 'plot_name' => 1, 'block_number' => 1, 'plant_number' => 1, 'plot_number' => 1, 'rep_number' => 1, 'row_number' => 1, 'col_number' => 1, 'accession_name' => 1, 'is_a_control' => 1 }
439 my $create_fieldbook_return = $create_fieldbook->download();
440 ok($create_fieldbook_return, "check that download trial fieldbook returns something.");
442 my $contents = ReadData $create_fieldbook_return->{'file'};
444 #print STDERR Dumper @contents->[0]->[0];
445 is($contents->[0]->{'type'}, $extension, "check that type of file is correct");
446 is($contents->[0]->{'sheets'}, '1', "check that type of file is correct");
448 my $columns = $contents->[1]->{'cell'};
449 #print STDERR Dumper scalar(@$columns);
450 ok(scalar(@$columns) == 11, "check number of col in created file.");
452 #print STDERR Dumper $columns;
453 is_deeply($columns, [
458 'test_trial21_plant_1',
459 'test_trial21_plant_2',
460 'test_trial22_plant_1',
461 'test_trial22_plant_2',
462 'test_trial23_plant_1',
463 'test_trial23_plant_2',
464 'test_trial24_plant_1',
465 'test_trial24_plant_2',
466 'test_trial25_plant_1',
467 'test_trial25_plant_2',
468 'test_trial26_plant_1',
469 'test_trial26_plant_2',
470 'test_trial27_plant_1',
471 'test_trial27_plant_2',
472 'test_trial28_plant_1',
473 'test_trial28_plant_2',
474 'test_trial29_plant_1',
475 'test_trial29_plant_2',
476 'test_trial210_plant_1',
477 'test_trial210_plant_2',
478 'test_trial211_plant_1',
479 'test_trial211_plant_2',
480 'test_trial212_plant_1',
481 'test_trial212_plant_2',
482 'test_trial213_plant_1',
483 'test_trial213_plant_2',
484 'test_trial214_plant_1',
485 'test_trial214_plant_2',
486 'test_trial215_plant_1',
487 'test_trial215_plant_2'
705 ], 'test file contents');
707 my @trait_list = ("dry matter content percentage|CO_334:0000092", "fresh root weight|CO_334:0000012");
708 my $tempfile = "/tmp/test_create_pheno_spreadsheet_plots_after_plants.$extension";
709 my $format = 'ExcelBasic';
710 my $create_spreadsheet = CXGN::Trial::Download->new(
712 bcs_schema => $f->bcs_schema,
713 trial_list => [ $trial_id ],
714 trait_list => \@trait_list,
715 filename => $tempfile,
717 data_level => 'plots',
720 $create_spreadsheet->download();
721 my $contents = ReadData $tempfile;
723 my $columns = $contents->[1]->{'cell'};
724 #print STDERR Dumper scalar(@$columns);
725 ok(scalar(@$columns) == 12, "check number of col in created file.");
727 #print STDERR Dumper $contents->[0];
728 is($contents->[0]->{'type'}, $extension, "check that type of file is correct");
729 is($contents->[0]->{'sheets'}, '1', "check that type of file is correct");
731 #print STDERR Dumper $contents->[1]->{'cell'}->[1];
732 is_deeply($contents->[1]->{'cell'}->[1], [
738 'Predefined Columns',
758 my $contents_col_2 = $contents->[1]->{'cell'}->[2];
759 #remove unique ID number from test...
760 splice @$contents_col_2, 0, 2;
761 #print STDERR Dumper $contents_col_2;
762 is_deeply($contents_col_2, [ 'test_trial',
763 'test_trial: test trial',
764 'test_trial: test_location',
785 #print STDERR Dumper $contents->[1]->{'cell'}->[3];
786 is_deeply($contents->[1]->{'cell'}->[3], [
788 'Spreadsheet format',
810 ], "check thrid col");
812 #print STDERR Dumper $contents->[1]->{'cell'}->[4];
813 is_deeply($contents->[1]->{'cell'}->[4], [
816 'Enter operator here',
839 is_deeply($contents->[1]->{'cell'}->[5], [
850 is_deeply($contents->[1]->{'cell'}->[6], [
876 #print STDERR Dumper $contents->[1]->{'cell'}->[7];
877 is_deeply($contents->[1]->{'cell'}->[7], [
903 #print STDERR Dumper $contents->[1]->{'cell'}->[8];
904 is_deeply($contents->[1]->{'cell'}->[8], [
930 #print STDERR Dumper $contents->[1]->{'cell'}->[9];
931 is_deeply($contents->[1]->{'cell'}->[9], [
957 is_deeply($contents->[1]->{'cell'}->[10], [
965 'dry matter content percentage|CO_334:0000092'
966 ], "check 10th col");
968 is_deeply($contents->[1]->{'cell'}->[11], [
976 'fresh root weight|CO_334:0000012'
977 ], "check 11th col");
979 my @trait_list = ("dry matter content percentage|CO_334:0000092", "fresh root weight|CO_334:0000012");
980 my $tempfile = "/tmp/test_create_pheno_spreadsheet_plots_after_plants.$extension";
981 my $format = 'ExcelBasic';
982 my $create_spreadsheet = CXGN::Trial::Download->new(
984 bcs_schema => $f->bcs_schema,
985 trial_list => [ $trial_id ],
986 trait_list => \@trait_list,
987 filename => $tempfile,
989 data_level => 'plants',
990 sample_number => '2',
991 predefined_columns => [ { 'plant_age' => '2 weeks' } ],
994 $create_spreadsheet->download();
995 my $contents = ReadData $tempfile;
997 my $columns = $contents->[1]->{'cell'};
998 #print STDERR Dumper scalar(@$columns);
999 ok(scalar(@$columns) == 14, "check number of col in created file.");
1001 #print STDERR Dumper @contents->[0];
1002 is($contents->[0]->{'type'}, $extension, "check that type of file is correct");
1003 is($contents->[0]->{'sheets'}, '1', "check that type of file is correct");
1005 #print STDERR Dumper $contents->[1]->{'cell'}->[1];
1006 is_deeply($contents->[1]->{'cell'}->[1], [
1011 'Trial location(s)',
1012 'Predefined Columns',
1015 'test_trial21_plant_1',
1016 'test_trial21_plant_2',
1017 'test_trial22_plant_1',
1018 'test_trial22_plant_2',
1019 'test_trial23_plant_1',
1020 'test_trial23_plant_2',
1021 'test_trial24_plant_1',
1022 'test_trial24_plant_2',
1023 'test_trial25_plant_1',
1024 'test_trial25_plant_2',
1025 'test_trial26_plant_1',
1026 'test_trial26_plant_2',
1027 'test_trial27_plant_1',
1028 'test_trial27_plant_2',
1029 'test_trial28_plant_1',
1030 'test_trial28_plant_2',
1031 'test_trial29_plant_1',
1032 'test_trial29_plant_2',
1033 'test_trial210_plant_1',
1034 'test_trial210_plant_2',
1035 'test_trial211_plant_1',
1036 'test_trial211_plant_2',
1037 'test_trial212_plant_1',
1038 'test_trial212_plant_2',
1039 'test_trial213_plant_1',
1040 'test_trial213_plant_2',
1041 'test_trial214_plant_1',
1042 'test_trial214_plant_2',
1043 'test_trial215_plant_1',
1044 'test_trial215_plant_2'
1047 my $contents_col_2 = $contents->[1]->{'cell'}->[2];
1048 #remove unique ID number from test...
1049 splice @$contents_col_2, 0, 2;
1050 #print STDERR Dumper $contents_col_2;
1051 is_deeply($contents_col_2, [ 'test_trial',
1052 'test_trial: test trial',
1053 'test_trial: test_location',
1089 #print STDERR Dumper $contents->[1]->{'cell'}->[3];
1090 is_deeply($contents->[1]->{'cell'}->[3], [
1092 'Spreadsheet format',
1131 #print STDERR Dumper $contents->[1]->{'cell'}->[4];
1132 is_deeply($contents->[1]->{'cell'}->[4], [
1135 'Enter operator here',
1173 is_deeply($contents->[1]->{'cell'}->[5], [
1214 is_deeply($contents->[1]->{'cell'}->[6], [
1225 is_deeply($contents->[1]->{'cell'}->[7], [
1266 #print STDERR Dumper $contents->[1]->{'cell'}->[8];
1267 is_deeply($contents->[1]->{'cell'}->[8], [
1308 #print STDERR Dumper $contents->[1]->{'cell'}->[9];
1309 is_deeply($contents->[1]->{'cell'}->[9], [
1350 #print STDERR Dumper $contents->[1]->{'cell'}->[10];
1351 is_deeply($contents->[1]->{'cell'}->[10], [
1392 is_deeply($contents->[1]->{'cell'}->[11], [
1433 is_deeply($contents->[1]->{'cell'}->[12], [
1441 'dry matter content percentage|CO_334:0000092'
1444 is_deeply($contents->[1]->{'cell'}->[13], [
1452 'fresh root weight|CO_334:0000012'
1455 $trial = CXGN::Trial->new({ bcs_schema => $f->bcs_schema(), trial_id => $trial_id });
1456 is($trial->create_tissue_samples(['leaf', ], 1, 0), 1, 'test create tissue samples without tissue numbers');
1457 is($trial->create_tissue_samples(['root', 'fruit' ], 1, 1), 1, 'test create tissue samples with tissue numbers');
1459 my $trial_with_tissues_layout = CXGN::Trial::TrialLayout->new({ schema => $f->bcs_schema(), trial_id => $trial_id, experiment_type => 'field_layout' })->get_design();
1460 print STDERR Dumper $trial_with_tissues_layout;
1461 print STDERR scalar(keys %$trial_with_tissues_layout) . "\n";
1462 is(scalar(keys(%$trial_with_tissues_layout)), 15, 'test trial layout count');
1463 is_deeply($trial_with_tissues_layout->{5}->{tissue_sample_names}, [
1464 'test_trial25_plant_1_leaf', # sample without tissue number
1465 'test_trial25_plant_2_leaf', # sample without tissue number
1466 'test_trial25_plant_1_root1', # sample with tissue number
1467 'test_trial25_plant_1_fruit2', # sample with tissue number
1468 'test_trial25_plant_2_root1', # sample with tissue number
1469 'test_trial25_plant_2_fruit2' # sample with tissue number
1470 ], 'test layout with tissue samples');
1472 is_deeply($trial_with_tissues_layout->{5}->{plants_tissue_sample_names}, {
1473 'test_trial25_plant_2' => [
1474 'test_trial25_plant_2_leaf', # sample without tissue number
1475 'test_trial25_plant_2_root1', # sample with tissue number
1476 'test_trial25_plant_2_fruit2' # sample with tissue number
1478 'test_trial25_plant_1' => [
1479 'test_trial25_plant_1_leaf', # sample without tissue number
1480 'test_trial25_plant_1_root1', # sample with tissue number
1481 'test_trial25_plant_1_fruit2' # sample with tissue number
1483 }, 'test layout with tissues samples');