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();
20 my $tl = CXGN::Trial::TrialLayout->new({ schema => $f->bcs_schema(), trial_id => $trial_id });
22 my $d = $tl->get_design();
23 #print STDERR Dumper($d);
30 foreach my $plot_num (keys %$d) {
31 push @plot_nums, $plot_num;
32 push @accessions, $d->{$plot_num}->{'accession_name'};
33 push @plant_names, $d->{$plot_num}->{'plant_names'};
34 push @rep_nums, $d->{$plot_num}->{'rep_number'};
35 push @plot_names, $d->{$plot_num}->{'plot_name'};
37 @plot_nums = sort @plot_nums;
38 @accessions = sort @accessions;
39 @plant_names = sort @plant_names;
40 @rep_nums = sort @rep_nums;
41 @plot_names = sort @plot_names;
43 #print STDERR Dumper \@plot_nums;
44 #print STDERR Dumper \@accessions;
45 #print STDERR Dumper \@plant_names;
46 #print STDERR Dumper \@rep_nums;
47 #print STDERR Dumper \@plot_names;
49 is_deeply(\@plot_nums, [
65 ], 'check design plot_nums');
67 is_deeply(\@accessions, [
83 ], 'check design accessions');
85 is_deeply(\@plant_names, [
101 ], "check design plant_names");
103 is_deeply(\@rep_nums, [
119 ], "check design rep_nums");
121 is_deeply(\@plot_names, [
137 ], "check design plot_names");
140 my $trial = CXGN::Trial->new({ bcs_schema => $f->bcs_schema(), trial_id => $trial_id });
141 $trial->create_plant_entities('2');
143 my $tl = CXGN::Trial::TrialLayout->new({ schema => $f->bcs_schema(), trial_id => $trial_id });
144 $d = $tl->get_design();
145 #print STDERR Dumper($d);
152 my @plant_names_flat;
153 foreach my $plot_num (keys %$d) {
154 push @plot_nums, $plot_num;
155 push @accessions, $d->{$plot_num}->{'accession_name'};
156 push @plant_names, $d->{$plot_num}->{'plant_names'};
157 push @rep_nums, $d->{$plot_num}->{'rep_number'};
158 push @plot_names, $d->{$plot_num}->{'plot_name'};
160 @plot_nums = sort @plot_nums;
161 @accessions = sort @accessions;
162 @rep_nums = sort @rep_nums;
163 @plot_names = sort @plot_names;
165 foreach my $plant_name_arr_ref (@plant_names) {
166 foreach (@$plant_name_arr_ref) {
167 push @plant_names_flat, $_;
170 @plant_names_flat = sort @plant_names_flat;
172 #print STDERR Dumper \@plot_nums;
173 #print STDERR Dumper \@accessions;
174 #print STDERR Dumper \@plant_names_flat;
175 #print STDERR Dumper \@rep_nums;
176 #print STDERR Dumper \@plot_names;
178 is_deeply(\@plot_nums, [
194 ], "check plot_nums after plant addition");
196 is_deeply(\@accessions, [
212 ], "check accessions after plant addition");
214 is_deeply(\@plant_names_flat, [
215 'test_trial210_plant_1',
216 'test_trial210_plant_2',
217 'test_trial211_plant_1',
218 'test_trial211_plant_2',
219 'test_trial212_plant_1',
220 'test_trial212_plant_2',
221 'test_trial213_plant_1',
222 'test_trial213_plant_2',
223 'test_trial214_plant_1',
224 'test_trial214_plant_2',
225 'test_trial215_plant_1',
226 'test_trial215_plant_2',
227 'test_trial21_plant_1',
228 'test_trial21_plant_2',
229 'test_trial22_plant_1',
230 'test_trial22_plant_2',
231 'test_trial23_plant_1',
232 'test_trial23_plant_2',
233 'test_trial24_plant_1',
234 'test_trial24_plant_2',
235 'test_trial25_plant_1',
236 'test_trial25_plant_2',
237 'test_trial26_plant_1',
238 'test_trial26_plant_2',
239 'test_trial27_plant_1',
240 'test_trial27_plant_2',
241 'test_trial28_plant_1',
242 'test_trial28_plant_2',
243 'test_trial29_plant_1',
244 'test_trial29_plant_2'
245 ], "check plant names");
247 is_deeply(\@rep_nums, [
263 ],"check rep nums after plant addition");
265 is_deeply(\@plot_names, [
281 ],"check plot_names after plant addition");
286 my $tempfile = "/tmp/test_create_trial_fieldbook_plots.xls";
288 my $create_fieldbook = CXGN::Fieldbook::DownloadTrial->new({
289 bcs_schema => $f->bcs_schema,
290 metadata_schema => $f->metadata_schema,
291 phenome_schema => $f->phenome_schema,
292 trial_id => $trial_id,
293 tempfile => $tempfile,
294 archive_path => $f->config->{archive_path},
296 user_name => "janedoe",
297 data_level => 'plots',
300 my $create_fieldbook_return = $create_fieldbook->download();
301 ok($create_fieldbook_return, "check that download trial fieldbook returns something.");
303 my @contents = ReadData ($create_fieldbook_return->{'file'});
305 #print STDERR Dumper @contents->[0]->[0];
306 is(@contents->[0]->[0]->{'type'}, 'xls', "check that type of file is correct");
307 is(@contents->[0]->[0]->{'sheets'}, '1', "check that type of file is correct");
309 my $columns = @contents->[0]->[1]->{'cell'};
310 #print STDERR Dumper scalar(@$columns);
311 ok(scalar(@$columns) == 9, "check number of col in created file.");
313 #print STDERR Dumper $columns;
314 is_deeply($columns, [
423 ], "check fieldbook creation of plots after plants created");
428 my $tempfile = "/tmp/test_create_trial_fieldbook_plants.xls";
430 my $create_fieldbook = CXGN::Fieldbook::DownloadTrial->new({
431 bcs_schema => $f->bcs_schema,
432 metadata_schema => $f->metadata_schema,
433 phenome_schema => $f->phenome_schema,
434 trial_id => $trial_id,
435 tempfile => $tempfile,
436 archive_path => $f->config->{archive_path},
438 user_name => "janedoe",
439 data_level => 'plants',
442 my $create_fieldbook_return = $create_fieldbook->download();
443 ok($create_fieldbook_return, "check that download trial fieldbook returns something.");
445 my @contents = ReadData ($create_fieldbook_return->{'file'});
447 #print STDERR Dumper @contents->[0]->[0];
448 is(@contents->[0]->[0]->{'type'}, 'xls', "check that type of file is correct");
449 is(@contents->[0]->[0]->{'sheets'}, '1', "check that type of file is correct");
451 my $columns = @contents->[0]->[1]->{'cell'};
452 #print STDERR Dumper scalar(@$columns);
453 ok(scalar(@$columns) == 11, "check number of col in created file.");
455 #print STDERR Dumper $columns;
457 is_deeply($columns->[1], [
460 'test_trial21_plant_1',
461 'test_trial21_plant_2',
462 'test_trial22_plant_1',
463 'test_trial22_plant_2',
464 'test_trial23_plant_1',
465 'test_trial23_plant_2',
466 'test_trial24_plant_1',
467 'test_trial24_plant_2',
468 'test_trial25_plant_1',
469 'test_trial25_plant_2',
470 'test_trial26_plant_1',
471 'test_trial26_plant_2',
472 'test_trial27_plant_1',
473 'test_trial27_plant_2',
474 'test_trial28_plant_1',
475 'test_trial28_plant_2',
476 'test_trial29_plant_1',
477 'test_trial29_plant_2',
478 'test_trial210_plant_1',
479 'test_trial210_plant_2',
480 'test_trial211_plant_1',
481 'test_trial211_plant_2',
482 'test_trial212_plant_1',
483 'test_trial212_plant_2',
484 'test_trial213_plant_1',
485 'test_trial213_plant_2',
486 'test_trial214_plant_1',
487 'test_trial214_plant_2',
488 'test_trial215_plant_1',
489 'test_trial215_plant_2'
490 ], "check contents of first col");
492 is_deeply($columns->[2], [
527 is_deeply($columns->[3], [
560 ], "check contents of second col");
562 is_deeply($columns->[4],[
595 ], "check contents of third col");
597 is_deeply($columns->[5], [
630 ], "check contents of fourth col");
632 is_deeply($columns->[6], [
665 ], "check contents of fifth col");
667 is_deeply($columns->[7], [
670 ], "check contents");
672 is_deeply($columns->[8], [
675 ], "check contents");
677 is_deeply($columns->[9],[
710 ], "check contents of sixth col");
712 is_deeply($columns->[10],[
715 ], "check contents of 7th col");
718 my @trait_list = ("dry matter content percentage|CO_334:0000092", "fresh root weight|CO_334:0000012");
719 my $tempfile = "/tmp/test_create_pheno_spreadsheet_plots_after_plants.xls";
720 my $format = 'ExcelBasic';
721 my $create_spreadsheet = CXGN::Trial::Download->new(
723 bcs_schema => $f->bcs_schema,
724 trial_id => $trial_id,
725 trait_list => \@trait_list,
726 filename => $tempfile,
728 data_level => 'plots',
731 $create_spreadsheet->download();
732 my @contents = ReadData ($tempfile);
734 my $columns = @contents->[0]->[1]->{'cell'};
735 #print STDERR Dumper scalar(@$columns);
736 ok(scalar(@$columns) == 9, "check number of col in created file.");
738 #print STDERR Dumper @contents->[0]->[0];
739 is(@contents->[0]->[0]->{'type'}, 'xls', "check that type of file is correct");
740 is(@contents->[0]->[0]->{'sheets'}, '1', "check that type of file is correct");
742 #print STDERR Dumper @contents->[0]->[1]->{'cell'}->[1];
743 is_deeply(@contents->[0]->[1]->{'cell'}->[1], [
749 'Predefined Columns',
769 my $contents_col_2 = @contents->[0]->[1]->{'cell'}->[2];
770 #remove unique ID number from test...
771 splice @$contents_col_2, 0, 2;
772 #print STDERR Dumper $contents_col_2;
773 is_deeply($contents_col_2, ['test_trial',
796 is_deeply(@contents->[0]->[1]->{'cell'}->[3], [
798 'Spreadsheet format',
820 ], "check thrid col");
822 is_deeply(@contents->[0]->[1]->{'cell'}->[4], [
825 'Enter operator here',
848 is_deeply(@contents->[0]->[1]->{'cell'}->[5], [
859 is_deeply(@contents->[0]->[1]->{'cell'}->[6], [
885 is_deeply(@contents->[0]->[1]->{'cell'}->[7], [
893 'dry matter content percentage|CO_334:0000092'
896 is_deeply(@contents->[0]->[1]->{'cell'}->[8], [
904 'fresh root weight|CO_334:0000012'
908 my @trait_list = ("dry matter content percentage|CO_334:0000092", "fresh root weight|CO_334:0000012");
909 my $tempfile = "/tmp/test_create_pheno_spreadsheet_plots_after_plants.xls";
910 my $format = 'ExcelBasic';
911 my $create_spreadsheet = CXGN::Trial::Download->new(
913 bcs_schema => $f->bcs_schema,
914 trial_id => $trial_id,
915 trait_list => \@trait_list,
916 filename => $tempfile,
918 data_level => 'plants',
919 sample_number => '2',
920 predefined_columns => [{'plant_age' => '2 weeks'}],
923 $create_spreadsheet->download();
924 my @contents = ReadData ($tempfile);
926 my $columns = @contents->[0]->[1]->{'cell'};
927 #print STDERR Dumper scalar(@$columns);
928 ok(scalar(@$columns) == 11, "check number of col in created file.");
930 #print STDERR Dumper @contents->[0];
931 is(@contents->[0]->[0]->{'type'}, 'xls', "check that type of file is correct");
932 is(@contents->[0]->[0]->{'sheets'}, '1', "check that type of file is correct");
934 #print STDERR Dumper @contents->[0]->[1]->{'cell'}->[1];
935 is_deeply(@contents->[0]->[1]->{'cell'}->[1], [
941 'Predefined Columns',
944 'test_trial21_plant_1',
945 'test_trial21_plant_2',
946 'test_trial22_plant_1',
947 'test_trial22_plant_2',
948 'test_trial23_plant_1',
949 'test_trial23_plant_2',
950 'test_trial24_plant_1',
951 'test_trial24_plant_2',
952 'test_trial25_plant_1',
953 'test_trial25_plant_2',
954 'test_trial26_plant_1',
955 'test_trial26_plant_2',
956 'test_trial27_plant_1',
957 'test_trial27_plant_2',
958 'test_trial28_plant_1',
959 'test_trial28_plant_2',
960 'test_trial29_plant_1',
961 'test_trial29_plant_2',
962 'test_trial210_plant_1',
963 'test_trial210_plant_2',
964 'test_trial211_plant_1',
965 'test_trial211_plant_2',
966 'test_trial212_plant_1',
967 'test_trial212_plant_2',
968 'test_trial213_plant_1',
969 'test_trial213_plant_2',
970 'test_trial214_plant_1',
971 'test_trial214_plant_2',
972 'test_trial215_plant_1',
973 'test_trial215_plant_2'
976 my $contents_col_2 = @contents->[0]->[1]->{'cell'}->[2];
977 #remove unique ID number from test...
978 splice @$contents_col_2, 0, 2;
979 #print STDERR Dumper $contents_col_2;
980 is_deeply($contents_col_2, ['test_trial',
1018 is_deeply(@contents->[0]->[1]->{'cell'}->[3], [
1020 'Spreadsheet format',
1059 is_deeply(@contents->[0]->[1]->{'cell'}->[4], [
1062 'Enter operator here',
1100 is_deeply(@contents->[0]->[1]->{'cell'}->[5], [
1141 is_deeply(@contents->[0]->[1]->{'cell'}->[6], [
1152 is_deeply(@contents->[0]->[1]->{'cell'}->[7], [
1193 is_deeply(@contents->[0]->[1]->{'cell'}->[8], [
1234 is_deeply(@contents->[0]->[1]->{'cell'}->[9], [
1242 'dry matter content percentage|CO_334:0000092'
1245 is_deeply(@contents->[0]->[1]->{'cell'}->[10], [
1253 'fresh root weight|CO_334:0000012'