start fixing test for multi cat phenotype upload.
[sgn.git] / t / unit_fixture / CXGN / Trial / AddPlantsandTissueSamplesToTrial.t
blobc4cf969fd8fd9bfb72d39ee1c7a131bcb3f7e2cb
2 use strict;
4 use lib 't/lib';
6 use Test::More;
7 use Data::Dumper;
8 use SGN::Test::Fixture;
9 use CXGN::Trial::TrialLayout;
10 use CXGN::Trial;
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") {
20     my $trial_id = 137;
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);
27     my @plot_nums;
28     my @accessions;
29     my @plant_names;
30     my @rep_nums;
31     my @plot_names;
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'};
38     }
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, [
52         '1',
53         '10',
54         '11',
55         '12',
56         '13',
57         '14',
58         '15',
59         '2',
60         '3',
61         '4',
62         '5',
63         '6',
64         '7',
65         '8',
66         '9'
67     ], 'check design plot_nums');
69     is_deeply(\@accessions, [
70         'test_accession1',
71         'test_accession1',
72         'test_accession1',
73         'test_accession2',
74         'test_accession2',
75         'test_accession2',
76         'test_accession3',
77         'test_accession3',
78         'test_accession3',
79         'test_accession4',
80         'test_accession4',
81         'test_accession4',
82         'test_accession5',
83         'test_accession5',
84         'test_accession5'
85     ], 'check design accessions');
87     is_deeply(\@plant_names, [
88         [],
89         [],
90         [],
91         [],
92         [],
93         [],
94         [],
95         [],
96         [],
97         [],
98         [],
99         [],
100         [],
101         [],
102         []
103     ], "check design plant_names");
105     is_deeply(\@rep_nums, [
106         '1',
107         '1',
108         '1',
109         '1',
110         '1',
111         '2',
112         '2',
113         '2',
114         '2',
115         '2',
116         '3',
117         '3',
118         '3',
119         '3',
120         '3'
121     ], "check design rep_nums");
123     is_deeply(\@plot_names, [
124         'test_trial21',
125         'test_trial210',
126         'test_trial211',
127         'test_trial212',
128         'test_trial213',
129         'test_trial214',
130         'test_trial215',
131         'test_trial22',
132         'test_trial23',
133         'test_trial24',
134         'test_trial25',
135         'test_trial26',
136         'test_trial27',
137         'test_trial28',
138         'test_trial29'
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);
148     @plot_nums = ();
149     @accessions = ();
150     @plant_names = ();
151     @rep_nums = ();
152     @plot_names = ();
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'};
160     }
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, $_;
169         }
170     }
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, [
180         '1',
181         '10',
182         '11',
183         '12',
184         '13',
185         '14',
186         '15',
187         '2',
188         '3',
189         '4',
190         '5',
191         '6',
192         '7',
193         '8',
194         '9'
195     ], "check plot_nums after plant addition");
197     is_deeply(\@accessions, [
198         'test_accession1',
199         'test_accession1',
200         'test_accession1',
201         'test_accession2',
202         'test_accession2',
203         'test_accession2',
204         'test_accession3',
205         'test_accession3',
206         'test_accession3',
207         'test_accession4',
208         'test_accession4',
209         'test_accession4',
210         'test_accession5',
211         'test_accession5',
212         'test_accession5'
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, [
249         '1',
250         '1',
251         '1',
252         '1',
253         '1',
254         '2',
255         '2',
256         '2',
257         '2',
258         '2',
259         '3',
260         '3',
261         '3',
262         '3',
263         '3'
264     ], "check rep nums after plant addition");
266     is_deeply(\@plot_names, [
267         'test_trial21',
268         'test_trial210',
269         'test_trial211',
270         'test_trial212',
271         'test_trial213',
272         'test_trial214',
273         'test_trial215',
274         'test_trial22',
275         'test_trial23',
276         'test_trial24',
277         'test_trial25',
278         'test_trial26',
279         'test_trial27',
280         'test_trial28',
281         'test_trial29'
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},
293         user_id          => 41,
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 }
297     });
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, [
314         [],
315         [
316             undef,
317             'plot_name',
318             'test_trial21',
319             'test_trial22',
320             'test_trial23',
321             'test_trial24',
322             'test_trial25',
323             'test_trial26',
324             'test_trial27',
325             'test_trial28',
326             'test_trial29',
327             'test_trial210',
328             'test_trial211',
329             'test_trial212',
330             'test_trial213',
331             'test_trial214',
332             'test_trial215'
333         ],
334         [
335             undef,
336             'accession_name',
337             'test_accession4',
338             'test_accession5',
339             'test_accession3',
340             'test_accession3',
341             'test_accession1',
342             'test_accession4',
343             'test_accession5',
344             'test_accession1',
345             'test_accession2',
346             'test_accession3',
347             'test_accession1',
348             'test_accession5',
349             'test_accession2',
350             'test_accession4',
351             'test_accession2'
352         ],
353         [
354             undef,
355             'plot_number',
356             '1',
357             '2',
358             '3',
359             '4',
360             '5',
361             '6',
362             '7',
363             '8',
364             '9',
365             '10',
366             '11',
367             '12',
368             '13',
369             '14',
370             '15'
371         ],
372         [
373             undef,
374             'block_number',
375             '1',
376             '1',
377             '1',
378             '1',
379             '1',
380             '1',
381             '1',
382             '1',
383             '1',
384             '1',
385             '1',
386             '1',
387             '1',
388             '1',
389             '1'
390         ],
391         [
392             undef,
393             'is_a_control'
394         ],
395         [
396             undef,
397             'rep_number',
398             '1',
399             '1',
400             '1',
401             '2',
402             '1',
403             '2',
404             '2',
405             '2',
406             '1',
407             '3',
408             '3',
409             '3',
410             '2',
411             '3',
412             '3'
413         ],
414         [
415             undef,
416             'row_number'
417         ],
418         [
419             undef,
420             'col_number'
421         ]
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},
433         user_id          => 41,
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 }
437     });
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, [
454         [],
455         [
456             undef,
457             'plant_name',
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'
488         ],
489         [
490             undef,
491             'plot_name',
492             'test_trial21',
493             'test_trial21',
494             'test_trial22',
495             'test_trial22',
496             'test_trial23',
497             'test_trial23',
498             'test_trial24',
499             'test_trial24',
500             'test_trial25',
501             'test_trial25',
502             'test_trial26',
503             'test_trial26',
504             'test_trial27',
505             'test_trial27',
506             'test_trial28',
507             'test_trial28',
508             'test_trial29',
509             'test_trial29',
510             'test_trial210',
511             'test_trial210',
512             'test_trial211',
513             'test_trial211',
514             'test_trial212',
515             'test_trial212',
516             'test_trial213',
517             'test_trial213',
518             'test_trial214',
519             'test_trial214',
520             'test_trial215',
521             'test_trial215'
522         ],
523         [
524             undef,
525             'accession_name',
526             'test_accession4',
527             'test_accession4',
528             'test_accession5',
529             'test_accession5',
530             'test_accession3',
531             'test_accession3',
532             'test_accession3',
533             'test_accession3',
534             'test_accession1',
535             'test_accession1',
536             'test_accession4',
537             'test_accession4',
538             'test_accession5',
539             'test_accession5',
540             'test_accession1',
541             'test_accession1',
542             'test_accession2',
543             'test_accession2',
544             'test_accession3',
545             'test_accession3',
546             'test_accession1',
547             'test_accession1',
548             'test_accession5',
549             'test_accession5',
550             'test_accession2',
551             'test_accession2',
552             'test_accession4',
553             'test_accession4',
554             'test_accession2',
555             'test_accession2'
556         ],
557         [
558             undef,
559             'plot_number',
560             '1',
561             '1',
562             '2',
563             '2',
564             '3',
565             '3',
566             '4',
567             '4',
568             '5',
569             '5',
570             '6',
571             '6',
572             '7',
573             '7',
574             '8',
575             '8',
576             '9',
577             '9',
578             '10',
579             '10',
580             '11',
581             '11',
582             '12',
583             '12',
584             '13',
585             '13',
586             '14',
587             '14',
588             '15',
589             '15'
590         ],
591         [
592             undef,
593             'block_number',
594             '1',
595             '1',
596             '1',
597             '1',
598             '1',
599             '1',
600             '1',
601             '1',
602             '1',
603             '1',
604             '1',
605             '1',
606             '1',
607             '1',
608             '1',
609             '1',
610             '1',
611             '1',
612             '1',
613             '1',
614             '1',
615             '1',
616             '1',
617             '1',
618             '1',
619             '1',
620             '1',
621             '1',
622             '1',
623             '1'
624         ],
625         [
626             undef,
627             'is_a_control'
628         ],
629         [
630             undef,
631             'rep_number',
632             '1',
633             '1',
634             '1',
635             '1',
636             '1',
637             '1',
638             '2',
639             '2',
640             '1',
641             '1',
642             '2',
643             '2',
644             '2',
645             '2',
646             '2',
647             '2',
648             '1',
649             '1',
650             '3',
651             '3',
652             '3',
653             '3',
654             '3',
655             '3',
656             '2',
657             '2',
658             '3',
659             '3',
660             '3',
661             '3'
662         ],
663         [
664             undef,
665             'row_number'
666         ],
667         [
668             undef,
669             'col_number'
670         ],
671         [
672             undef,
673             'plant_number',
674             '1',
675             '2',
676             '1',
677             '2',
678             '1',
679             '2',
680             '1',
681             '2',
682             '1',
683             '2',
684             '1',
685             '2',
686             '1',
687             '2',
688             '1',
689             '2',
690             '1',
691             '2',
692             '1',
693             '2',
694             '1',
695             '2',
696             '1',
697             '2',
698             '1',
699             '2',
700             '1',
701             '2',
702             '1',
703             '2'
704         ]
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(
711         {
712             bcs_schema => $f->bcs_schema,
713             trial_list => [ $trial_id ],
714             trait_list => \@trait_list,
715             filename   => $tempfile,
716             format     => $format,
717             data_level => 'plots',
718         });
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], [
733         undef,
734         'Spreadsheet ID',
735         'Trial name(s)',
736         'Description(s)',
737         'Trial location(s)',
738         'Predefined Columns',
739         undef,
740         'plot_name',
741         'test_trial21',
742         'test_trial22',
743         'test_trial23',
744         'test_trial24',
745         'test_trial25',
746         'test_trial26',
747         'test_trial27',
748         'test_trial28',
749         'test_trial29',
750         'test_trial210',
751         'test_trial211',
752         'test_trial212',
753         'test_trial213',
754         'test_trial214',
755         'test_trial215'
756     ], "check 1st col");
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',
765         '[]',
766         undef,
767         'accession_name',
768         'test_accession4',
769         'test_accession5',
770         'test_accession3',
771         'test_accession3',
772         'test_accession1',
773         'test_accession4',
774         'test_accession5',
775         'test_accession1',
776         'test_accession2',
777         'test_accession3',
778         'test_accession1',
779         'test_accession5',
780         'test_accession2',
781         'test_accession4',
782         'test_accession2'
783     ], "check 2nd col");
785     #print STDERR Dumper $contents->[1]->{'cell'}->[3];
786     is_deeply($contents->[1]->{'cell'}->[3], [
787         undef,
788         'Spreadsheet format',
789         'Operator',
790         'Date',
791         'Design Type(s)',
792         undef,
793         undef,
794         'plot_number',
795         '1',
796         '2',
797         '3',
798         '4',
799         '5',
800         '6',
801         '7',
802         '8',
803         '9',
804         '10',
805         '11',
806         '12',
807         '13',
808         '14',
809         '15'
810     ], "check thrid col");
812     #print STDERR Dumper $contents->[1]->{'cell'}->[4];
813     is_deeply($contents->[1]->{'cell'}->[4], [
814         undef,
815         'BasicExcel',
816         'Enter operator here',
817         'Enter date here',
818         'test_trial: CRD',
819         undef,
820         undef,
821         'block_number',
822         '1',
823         '1',
824         '1',
825         '1',
826         '1',
827         '1',
828         '1',
829         '1',
830         '1',
831         '1',
832         '1',
833         '1',
834         '1',
835         '1',
836         '1'
837     ], "check 4th col");
839     is_deeply($contents->[1]->{'cell'}->[5], [
840         undef,
841         undef,
842         undef,
843         undef,
844         undef,
845         undef,
846         undef,
847         'is_a_control'
848     ], "check 5th col");
850     is_deeply($contents->[1]->{'cell'}->[6], [
851         undef,
852         undef,
853         undef,
854         undef,
855         undef,
856         undef,
857         undef,
858         'rep_number',
859         '1',
860         '1',
861         '1',
862         '2',
863         '1',
864         '2',
865         '2',
866         '2',
867         '1',
868         '3',
869         '3',
870         '3',
871         '2',
872         '3',
873         '3'
874     ], "check 6th col");
876     #print STDERR Dumper $contents->[1]->{'cell'}->[7];
877     is_deeply($contents->[1]->{'cell'}->[7], [
878         undef,
879         undef,
880         undef,
881         undef,
882         undef,
883         undef,
884         undef,
885         'planting_date',
886         '2017-July-04',
887         '2017-July-04',
888         '2017-July-04',
889         '2017-July-04',
890         '2017-July-04',
891         '2017-July-04',
892         '2017-July-04',
893         '2017-July-04',
894         '2017-July-04',
895         '2017-July-04',
896         '2017-July-04',
897         '2017-July-04',
898         '2017-July-04',
899         '2017-July-04',
900         '2017-July-04'
901     ], "check 7th col");
903     #print STDERR Dumper $contents->[1]->{'cell'}->[8];
904     is_deeply($contents->[1]->{'cell'}->[8], [
905         undef,
906         undef,
907         undef,
908         undef,
909         undef,
910         undef,
911         undef,
912         'harvest_date',
913         '2017-July-21',
914         '2017-July-21',
915         '2017-July-21',
916         '2017-July-21',
917         '2017-July-21',
918         '2017-July-21',
919         '2017-July-21',
920         '2017-July-21',
921         '2017-July-21',
922         '2017-July-21',
923         '2017-July-21',
924         '2017-July-21',
925         '2017-July-21',
926         '2017-July-21',
927         '2017-July-21'
928     ], "check 8th col");
930     #print STDERR Dumper $contents->[1]->{'cell'}->[9];
931     is_deeply($contents->[1]->{'cell'}->[9], [
932         undef,
933         undef,
934         undef,
935         undef,
936         undef,
937         undef,
938         undef,
939         'trial_name',
940         'test_trial',
941         'test_trial',
942         'test_trial',
943         'test_trial',
944         'test_trial',
945         'test_trial',
946         'test_trial',
947         'test_trial',
948         'test_trial',
949         'test_trial',
950         'test_trial',
951         'test_trial',
952         'test_trial',
953         'test_trial',
954         'test_trial'
955     ], "check 9th col");
957     is_deeply($contents->[1]->{'cell'}->[10], [
958         undef,
959         undef,
960         undef,
961         undef,
962         undef,
963         undef,
964         undef,
965         'dry matter content percentage|CO_334:0000092'
966     ], "check 10th col");
968     is_deeply($contents->[1]->{'cell'}->[11], [
969         undef,
970         undef,
971         undef,
972         undef,
973         undef,
974         undef,
975         undef,
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(
983         {
984             bcs_schema         => $f->bcs_schema,
985             trial_list         => [ $trial_id ],
986             trait_list         => \@trait_list,
987             filename           => $tempfile,
988             format             => $format,
989             data_level         => 'plants',
990             sample_number      => '2',
991             predefined_columns => [ { 'plant_age' => '2 weeks' } ],
992         });
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], [
1007         undef,
1008         'Spreadsheet ID',
1009         'Trial name(s)',
1010         'Description(s)',
1011         'Trial location(s)',
1012         'Predefined Columns',
1013         undef,
1014         'plant_name',
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'
1045     ], "check col1");
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',
1054         '["plant_age"]',
1055         undef,
1056         'plot_name',
1057         'test_trial21',
1058         'test_trial21',
1059         'test_trial22',
1060         'test_trial22',
1061         'test_trial23',
1062         'test_trial23',
1063         'test_trial24',
1064         'test_trial24',
1065         'test_trial25',
1066         'test_trial25',
1067         'test_trial26',
1068         'test_trial26',
1069         'test_trial27',
1070         'test_trial27',
1071         'test_trial28',
1072         'test_trial28',
1073         'test_trial29',
1074         'test_trial29',
1075         'test_trial210',
1076         'test_trial210',
1077         'test_trial211',
1078         'test_trial211',
1079         'test_trial212',
1080         'test_trial212',
1081         'test_trial213',
1082         'test_trial213',
1083         'test_trial214',
1084         'test_trial214',
1085         'test_trial215',
1086         'test_trial215'
1087     ], "check col2");
1089     #print STDERR Dumper $contents->[1]->{'cell'}->[3];
1090     is_deeply($contents->[1]->{'cell'}->[3], [
1091         undef,
1092         'Spreadsheet format',
1093         'Operator',
1094         'Date',
1095         'Design Type(s)',
1096         undef,
1097         undef,
1098         'accession_name',
1099         'test_accession4',
1100         'test_accession4',
1101         'test_accession5',
1102         'test_accession5',
1103         'test_accession3',
1104         'test_accession3',
1105         'test_accession3',
1106         'test_accession3',
1107         'test_accession1',
1108         'test_accession1',
1109         'test_accession4',
1110         'test_accession4',
1111         'test_accession5',
1112         'test_accession5',
1113         'test_accession1',
1114         'test_accession1',
1115         'test_accession2',
1116         'test_accession2',
1117         'test_accession3',
1118         'test_accession3',
1119         'test_accession1',
1120         'test_accession1',
1121         'test_accession5',
1122         'test_accession5',
1123         'test_accession2',
1124         'test_accession2',
1125         'test_accession4',
1126         'test_accession4',
1127         'test_accession2',
1128         'test_accession2'
1129     ], "check col3");
1131     #print STDERR Dumper $contents->[1]->{'cell'}->[4];
1132     is_deeply($contents->[1]->{'cell'}->[4], [
1133         undef,
1134         'BasicExcel',
1135         'Enter operator here',
1136         'Enter date here',
1137         'test_trial: CRD',
1138         undef,
1139         undef,
1140         'plot_number',
1141         '1',
1142         '1',
1143         '2',
1144         '2',
1145         '3',
1146         '3',
1147         '4',
1148         '4',
1149         '5',
1150         '5',
1151         '6',
1152         '6',
1153         '7',
1154         '7',
1155         '8',
1156         '8',
1157         '9',
1158         '9',
1159         '10',
1160         '10',
1161         '11',
1162         '11',
1163         '12',
1164         '12',
1165         '13',
1166         '13',
1167         '14',
1168         '14',
1169         '15',
1170         '15'
1171     ], "check col4");
1173     is_deeply($contents->[1]->{'cell'}->[5], [
1174         undef,
1175         undef,
1176         undef,
1177         undef,
1178         undef,
1179         undef,
1180         undef,
1181         'block_number',
1182         '1',
1183         '1',
1184         '1',
1185         '1',
1186         '1',
1187         '1',
1188         '1',
1189         '1',
1190         '1',
1191         '1',
1192         '1',
1193         '1',
1194         '1',
1195         '1',
1196         '1',
1197         '1',
1198         '1',
1199         '1',
1200         '1',
1201         '1',
1202         '1',
1203         '1',
1204         '1',
1205         '1',
1206         '1',
1207         '1',
1208         '1',
1209         '1',
1210         '1',
1211         '1'
1212     ], "check col5");
1214     is_deeply($contents->[1]->{'cell'}->[6], [
1215         undef,
1216         undef,
1217         undef,
1218         undef,
1219         undef,
1220         undef,
1221         undef,
1222         'is_a_control'
1223     ], "check col6");
1225     is_deeply($contents->[1]->{'cell'}->[7], [
1226         undef,
1227         undef,
1228         undef,
1229         undef,
1230         undef,
1231         undef,
1232         undef,
1233         'rep_number',
1234         '1',
1235         '1',
1236         '1',
1237         '1',
1238         '1',
1239         '1',
1240         '2',
1241         '2',
1242         '1',
1243         '1',
1244         '2',
1245         '2',
1246         '2',
1247         '2',
1248         '2',
1249         '2',
1250         '1',
1251         '1',
1252         '3',
1253         '3',
1254         '3',
1255         '3',
1256         '3',
1257         '3',
1258         '2',
1259         '2',
1260         '3',
1261         '3',
1262         '3',
1263         '3'
1264     ], "check col7");
1266     #print STDERR Dumper $contents->[1]->{'cell'}->[8];
1267     is_deeply($contents->[1]->{'cell'}->[8], [
1268         undef,
1269         undef,
1270         undef,
1271         undef,
1272         undef,
1273         undef,
1274         undef,
1275         'planting_date',
1276         '2017-July-04',
1277         '2017-July-04',
1278         '2017-July-04',
1279         '2017-July-04',
1280         '2017-July-04',
1281         '2017-July-04',
1282         '2017-July-04',
1283         '2017-July-04',
1284         '2017-July-04',
1285         '2017-July-04',
1286         '2017-July-04',
1287         '2017-July-04',
1288         '2017-July-04',
1289         '2017-July-04',
1290         '2017-July-04',
1291         '2017-July-04',
1292         '2017-July-04',
1293         '2017-July-04',
1294         '2017-July-04',
1295         '2017-July-04',
1296         '2017-July-04',
1297         '2017-July-04',
1298         '2017-July-04',
1299         '2017-July-04',
1300         '2017-July-04',
1301         '2017-July-04',
1302         '2017-July-04',
1303         '2017-July-04',
1304         '2017-July-04',
1305         '2017-July-04'
1306     ], "check col8");
1308     #print STDERR Dumper $contents->[1]->{'cell'}->[9];
1309     is_deeply($contents->[1]->{'cell'}->[9], [
1310         undef,
1311         undef,
1312         undef,
1313         undef,
1314         undef,
1315         undef,
1316         undef,
1317         'harvest_date',
1318         '2017-July-21',
1319         '2017-July-21',
1320         '2017-July-21',
1321         '2017-July-21',
1322         '2017-July-21',
1323         '2017-July-21',
1324         '2017-July-21',
1325         '2017-July-21',
1326         '2017-July-21',
1327         '2017-July-21',
1328         '2017-July-21',
1329         '2017-July-21',
1330         '2017-July-21',
1331         '2017-July-21',
1332         '2017-July-21',
1333         '2017-July-21',
1334         '2017-July-21',
1335         '2017-July-21',
1336         '2017-July-21',
1337         '2017-July-21',
1338         '2017-July-21',
1339         '2017-July-21',
1340         '2017-July-21',
1341         '2017-July-21',
1342         '2017-July-21',
1343         '2017-July-21',
1344         '2017-July-21',
1345         '2017-July-21',
1346         '2017-July-21',
1347         '2017-July-21'
1348     ], "check col9");
1350     #print STDERR Dumper $contents->[1]->{'cell'}->[10];
1351     is_deeply($contents->[1]->{'cell'}->[10], [
1352         undef,
1353         undef,
1354         undef,
1355         undef,
1356         undef,
1357         undef,
1358         undef,
1359         'trial_name',
1360         'test_trial',
1361         'test_trial',
1362         'test_trial',
1363         'test_trial',
1364         'test_trial',
1365         'test_trial',
1366         'test_trial',
1367         'test_trial',
1368         'test_trial',
1369         'test_trial',
1370         'test_trial',
1371         'test_trial',
1372         'test_trial',
1373         'test_trial',
1374         'test_trial',
1375         'test_trial',
1376         'test_trial',
1377         'test_trial',
1378         'test_trial',
1379         'test_trial',
1380         'test_trial',
1381         'test_trial',
1382         'test_trial',
1383         'test_trial',
1384         'test_trial',
1385         'test_trial',
1386         'test_trial',
1387         'test_trial',
1388         'test_trial',
1389         'test_trial'
1390     ], "check col10");
1392     is_deeply($contents->[1]->{'cell'}->[11], [
1393         undef,
1394         undef,
1395         undef,
1396         undef,
1397         undef,
1398         undef,
1399         undef,
1400         'plant_age',
1401         '2 weeks',
1402         '2 weeks',
1403         '2 weeks',
1404         '2 weeks',
1405         '2 weeks',
1406         '2 weeks',
1407         '2 weeks',
1408         '2 weeks',
1409         '2 weeks',
1410         '2 weeks',
1411         '2 weeks',
1412         '2 weeks',
1413         '2 weeks',
1414         '2 weeks',
1415         '2 weeks',
1416         '2 weeks',
1417         '2 weeks',
1418         '2 weeks',
1419         '2 weeks',
1420         '2 weeks',
1421         '2 weeks',
1422         '2 weeks',
1423         '2 weeks',
1424         '2 weeks',
1425         '2 weeks',
1426         '2 weeks',
1427         '2 weeks',
1428         '2 weeks',
1429         '2 weeks',
1430         '2 weeks'
1431     ], "check col11");
1433     is_deeply($contents->[1]->{'cell'}->[12], [
1434         undef,
1435         undef,
1436         undef,
1437         undef,
1438         undef,
1439         undef,
1440         undef,
1441         'dry matter content percentage|CO_334:0000092'
1442     ], "check col12");
1444     is_deeply($contents->[1]->{'cell'}->[13], [
1445         undef,
1446         undef,
1447         undef,
1448         undef,
1449         undef,
1450         undef,
1451         undef,
1452         'fresh root weight|CO_334:0000012'
1453     ], "check col13");
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
1477         ],
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
1482         ]
1483     }, 'test layout with tissues samples');
1484     $f->clean_up_db();
1487 done_testing();