1 package CXGN
::Phenotypes
::CreateSpreadsheet
;
5 CXGN::Phenotypes::CreateSpreadsheet - an object to create a spreadsheet for collecting phenotypes
9 my $phenotype_spreadsheet = CXGN::Phenotypes::CreateSpreadsheet->new({schema => $schema, trial_id => $trial_id, trait_list => \$trait_list} );
10 $create_spreadsheet->create();
17 Jeremy D. Edwards (jde22@cornell.edu)
24 use MooseX
::FollowPBP
;
25 use Moose
::Util
::TypeConstraints
;
27 use File
::Basename qw
| basename dirname
|;
29 use CXGN
::List
::Validate
;
31 use CXGN
::Trial
::TrialLayout
;
32 use Spreadsheet
::WriteExcel
;
34 use CXGN
::List
::Transform
;
38 isa
=> 'DBIx::Class::Schema',
41 has
'trial_id' => (isa
=> 'Int', is
=> 'rw', predicate
=> 'has_trial_id', required
=> 1);
42 has
'trait_list' => (isa
=> 'ArrayRef', is
=> 'rw', predicate
=> 'has_trait_list', required
=> 1);
43 has
'filename' => (isa
=> 'Str', is
=> 'ro',
44 predicate
=> 'has_filename',
45 reader
=> 'get_filename',
46 writer
=> 'set_filename',
49 has
'file_metadata' => (isa
=> 'Str', is
=> 'rw', predicate
=> 'has_file_metadata');
55 my $trial_id = $self->get_trial_id();
56 my @trait_list = @
{$self->get_trait_list()};
64 my $schema = $self->get_schema();
65 my $trial_id = $self->get_trial_id();
66 my @trait_list = @
{$self->get_trait_list()};
67 my $spreadsheet_metadata = $self->get_file_metadata();
68 my $trial_layout = CXGN
::Trial
::TrialLayout
->new({schema
=> $schema, trial_id
=> $trial_id, experiment_type
=>'field_layout'} );
69 my %design = %{$trial_layout->get_design()};
70 my @plot_names = @
{$trial_layout->get_plot_names};
72 my $workbook = Spreadsheet
::WriteExcel
->new($self->get_filename());
73 my $ws = $workbook->add_worksheet();
75 # generate worksheet headers
77 my $trial = CXGN
::Trial
->new( { bcs_schema
=> $schema, trial_id
=> $trial_id });
78 #$ws->write(0, '0', 'Spreadsheet ID'); $ws->write('0', '1', );#$unique_id);
79 $ws->write(1, 0, 'Trial name'); $ws->write(1, 1, $trial->get_name());
80 $ws->write(2, 0, 'Description'); $ws->write(2, 1, $trial->get_description());
81 #$ws->write(3, 0, "Plants per plot"); $ws->write(3, 1, "unknown");
82 $ws->write(4, 0, 'Operator'); $ws->write(4, '1', "");
83 $ws->write(5, 0, 'Date'); $ws->write(5, '1', "");
85 my @ordered_plots = sort { $a cmp $b} keys(%design);
86 for(my $n=0; $n<@ordered_plots; $n++) {
87 my %design_info = %{$design{$ordered_plots[$n]}};
89 $ws->write($n+6, 0, $ordered_plots[$n]);
90 $ws->write($n+6, 1, $design_info{accession_name
});
91 $ws->write($n+6, 2, $design_info{plot_number
});
92 $ws->write($n+6, 3, $design_info{block_number
});
93 $ws->write($n+6, 4, $design_info{is_a_control
});
94 $ws->write($n+6, 5, $design_info{rep_number
});
97 # write traits and format trait columns
99 my $lt = CXGN
::List
::Transform
->new();
101 my $transform = $lt->transform($schema, "traits_2_trait_ids", \
@trait_list);
103 if (@
{$transform->{missing
}}>0) {
104 print STDERR
"Warning: Some traits could not be found. ".join(",",@
{$transform->{missing
}})."\n";
106 my @trait_ids = @
{$transform->{transform
}};
109 foreach my $t (@trait_ids) {
110 my $trait = CXGN
::Trait
->new( { bcs_schema
=> $schema, cvterm_id
=> $t });
111 $cvinfo{$trait->display_name()} = $trait;
114 for (my $i = 0; $i < @trait_list; $i++) {
115 if (exists($cvinfo{$trait_list[$i]})) {
116 $ws->write(6, $i+6, $cvinfo{$trait_list[$i]}->display_name());
119 print STDERR
"Skipping output of trait $trait_list[$i] because it does not exist\n";
122 my $plot_count = scalar(keys(%design));
124 for (my $n = 0; $n < $plot_count; $n++) {
125 my $format = $cvinfo{$trait_list[$i]}->format();
126 if ($format eq "numeric") {
127 $ws->data_validation($n+6, $i+6, { validate
=> "any" });
130 $ws->data_validation($n+6, $i+6,
133 value
=> [ split ",", $format ]