1 package SGN
::View
::Trial
;
3 use List
::MoreUtils
':all';
11 trial_detail_design_view
12 design_layout_map_view
16 sub trial_detail_design_view
{
17 my $design_ref = shift;
18 my %design = %{$design_ref};
19 my $design_result_html;
21 $design_result_html .= '<table border="1">';
22 $design_result_html .= qq{<tr
><th
>Plot Name
</th><th>Accession Name</th
><th
>Check Name
</th><th>Row number</th
><th
>Col number
</th><th>Block Number</th
><th
>Block Row Number
</th><th>Block Col Number</th
><th
>Rep Number
</th></tr
>};
24 foreach my $key (sort { $a <=> $b} keys %design) {
25 $design_result_html .= "<tr>";
26 if ($design{$key}->{plot_name
}) {
27 $design_result_html .= "<td>".$design{$key}->{plot_name
}."</td>";
29 $design_result_html .= "<td></td>";
31 if ($design{key
}->{accession_name
}) {
32 $design_result_html .= "<td>".$design{$key}->{accession_name
}."</td>";
34 $design_result_html .= "<td></td>";
36 if ($design{key
}->{check_name
}) {
37 $design_result_html .= "<td>".$design{$key}->{check_name
}."</td>";
39 $design_result_html .= "<td></td>";
41 if ($design{key
}->{row_number
}) {
42 $design_result_html .= "<td>".$design{$key}->{row_number
}."</td>";
44 $design_result_html .= "<td></td>";
46 if ($design{key
}->{col_number
}) {
47 $design_result_html .= "<td>".$design{$key}->{col_number
}."</td>";
49 $design_result_html .= "<td></td>";
51 if ($design{key
}->{block_number
}) {
52 $design_result_html .= "<td>".$design{$key}->{block_number
}."</td>";
54 $design_result_html .= "<td></td>";
56 if ($design{key
}->{block_row_number
}) {
57 $design_result_html .= "<td>".$design{$key}->{block_row_number
}."</td>";
59 $design_result_html .= "<td></td>";
61 if ($design{key
}->{block_col_number
}) {
62 $design_result_html .= "<td>".$design{$key}->{block_col_number
}."</td>";
64 $design_result_html .= "<td></td>";
66 if ($design{key
}->{rep_number
}) {
67 $design_result_html .= "<td>".$design{$key}->{rep_number
}."</td>";
69 $design_result_html .= "<td></td>";
71 $design_result_html .= "</tr>";
73 $design_result_html .= "</table>";
74 return "$design_result_html";
78 sub design_layout_map_view
{
79 my $design_ref = shift;
80 my $design_type = shift;
82 my %design = %{$design_ref};
87 my @block_numbers = ();
90 foreach my $key (sort { $a <=> $b} keys %design) {
91 my $plot_name = $design{$key}->{plot_name
} || '';
92 my $stock_name = $design{$key}->{stock_name
} || '';
93 my $check_name = $design{$key}->{is_a_control
} || '';
94 my $row_number = $design{$key}->{row_number
} || '';
95 my $col_number = $design{$key}->{col_number
} || '';
96 my $block_number = $design{$key}->{block_number
} || '';
97 my $rep_number = $design{$key}->{rep_number
} || '';
98 my $plot_number = $key;
101 push @col_numbers, $col_number;
104 push @row_numbers, $row_number;
105 }elsif (!$row_number){
106 if ($block_number && $design_type ne 'splitplot'){
107 $row_number = $block_number;
108 push @row_numbers, $row_number;
109 }elsif ($rep_number && !$block_number && $design_type ne 'splitplot'){
110 $row_number = $rep_number;
111 push @row_numbers, $row_number;
112 }elsif ($design_type eq 'splitplot'){
113 $row_number = $rep_number;
114 push @row_numbers, $row_number;
118 push @rep_numbers, $rep_number;
121 push @block_numbers, $block_number;
124 push @check_names, $stock_name;
128 plot_number
=> $plot_number,
129 row_number
=> $row_number,
130 col_number
=> $col_number,
131 block_number
=> $block_number,
132 rep_number
=> $rep_number,
133 plot_name
=> $plot_name,
134 accession_name
=> $stock_name,
138 @layout_info = sort { $a->{plot_number
} <=> $b->{plot_number
}} @layout_info;
140 if (scalar(@col_numbers) < 1){
142 $false_coord = 'false_coord';
143 my @row_instances = uniq
@row_numbers;
144 my %unique_row_counts;
145 $unique_row_counts{$_}++ for @row_numbers;
147 for my $key (keys %unique_row_counts){
148 push @col_number2, (1..$unique_row_counts{$key});
150 for (my $i=0; $i < scalar(@layout_info); $i++){
151 $layout_info[$i]->{'col_number'} = $col_number2[$i];
152 push @col_numbers, $col_number2[$i];
157 foreach my $hash (@layout_info){
158 $plot_popUp = $hash->{'plot_name'}."\nplot_No:".$hash->{'plot_number'}."\nblock_No:".$hash->{'block_number'}."\nrep_No:".$hash->{'rep_number'}."\nstock:".$hash->{'accession_name'};
159 push @
$result, {plotname
=> $hash->{'plot_name'}, stock
=> $hash->{'accession_name'}, plotn
=> $hash->{'plot_number'}, blkn
=>$hash->{'block_number'}, rep
=>$hash->{'rep_number'}, row
=>$hash->{'row_number'}, col
=>$hash->{'col_number'}, plot_msg
=>$plot_popUp} ;
162 my @sorted_block = sort@block_numbers;
163 my @uniq_block = uniq
(@sorted_block);
164 @check_names = uniq
(@check_names);
165 #print STDERR Dumper(\@check_names);
166 my ($min_rep, $max_rep) = minmax
@rep_numbers;
167 my ($min_block, $max_block) = minmax
@block_numbers;
168 my ($min_col, $max_col) = minmax
@col_numbers;
169 my ($min_row, $max_row) = minmax
@row_numbers;
170 my (@unique_col,@unique_row);
171 for my $x (1..$max_col){
172 push @unique_col, $x;
174 for my $y (1..$max_row){
175 push @unique_row, $y;
179 coord_row
=> \
@row_numbers,
180 coord_col
=> \
@col_numbers,
184 max_block
=> $max_block,
185 controls
=> \
@check_names,
186 unique_col
=> \
@unique_col,
187 unique_row
=> \
@unique_row,
188 false_coord
=> $false_coord,
196 sub design_layout_view
{
197 my $design_ref = shift;
198 my $design_info_ref = shift;
199 my $design_level = shift;
200 my %design = %{$design_ref};
201 my %design_info = %{$design_info_ref};
202 my $design_result_html;
204 $design_result_html .= '<table class="table table-bordered table-hover">';
206 if ($design_level eq 'plants') {
207 $design_result_html .= qq{<tr
><th
>Plant Name
</th><th>Plot Name</th
><th
>Accession Name
</th><th>Check Name</th
><th
>Plot Number
</th><th>Row number</th
><th
>Col number
</th><th>Block Number</th
><th
>Block Row Number
</th><th>Block Col Number</th
><th
>Rep Number
</th><th>Seedlot Name</th
><th
>Num Seeds Per Plot
</th></tr
>};
208 } elsif ($design_level eq 'subplots') {
209 $design_result_html .= qq{<tr
><th
>Plant Name
</th><th>Subplot Name</th
><th
>Plot Name
</th><th>Accession Name</th
><th
>Check Name
</th><th>Plot Number</th
><th
>Row number
</th><th>Col number</th
><th
>Block Number
</th><th>Block Row Number</th
><th
>Block Col Number
</th><th>Rep Number</th
><th
>Seedlot Name
</th><th>Num Seeds Per Plot</th
></tr
>};
211 $design_result_html .= qq{<tr
><th
>Plot Name
</th><th>Accession Name</th
><th
>Check Name
</th><th>Plot Number</th
><th
>Row number
</th><th>Col number</th
><th
>Block Number
</th><th>Block Row Number</th
><th
>Block Col Number
</th><th>Rep Number</th
><th
>Seedlot Name
</th><th>Num Seeds Per Plot</th
></tr
>};
214 foreach my $key (sort { $a <=> $b} keys %design) {
215 if ($key eq 'treatments'){
218 my $plot_name = $design{$key}->{plot_name
} || '';
219 my $stock_name = $design{$key}->{stock_name
} || '';
220 my $seedlot_name = $design{$key}->{seedlot_name
} || '';
221 my $num_seed_per_plot = $design{$key}->{num_seed_per_plot
} || '';
222 my $check_name = $design{$key}->{is_a_control
} || '';
223 my $row_number = $design{$key}->{row_number
} || '';
224 my $col_number = $design{$key}->{col_number
} || '';
225 my $block_number = $design{$key}->{block_number
} || '';
226 my $block_row_number = $design{$key}->{block_row_number
} || '';
227 my $block_col_number = $design{$key}->{block_col_number
} || '';
228 my $rep_number = $design{$key}->{rep_number
} || '';
229 my $plot_number = $key;
231 if ($design{$key}->{subplots_plant_names
}) {
232 foreach my $subplot_name (sort keys %{$design{$key}->{subplots_plant_names
}}) {
233 my $plant_names = $design{$key}->{subplots_plant_names
}->{$subplot_name};
234 foreach my $plant_name (@
$plant_names){
235 $design_result_html .= "<tr><td>".$plant_name."</td><td>".$subplot_name."</td><td>".$plot_name."</td><td>".$stock_name."</td><td>".$check_name."</td><td>".$plot_number."</td><td>".$row_number."</td><td>".$col_number."</td><td>".$block_number."</td><td>".$block_row_number."</td><td>".$block_col_number."</td><td>".$rep_number."</td><td>".$seedlot_name."</td><td>".$num_seed_per_plot."</td></tr>";
238 } elsif ($design{$key}->{plant_names
}) {
239 foreach my $plant_name (@
{$design{$key}->{plant_names
}}) {
240 $design_result_html .= "<tr><td>".$plant_name."</td><td>".$plot_name."</td><td>".$stock_name."</td><td>".$check_name."</td><td>".$plot_number."</td><td>".$row_number."</td><td>".$col_number."</td><td>".$block_number."</td><td>".$block_row_number."</td><td>".$block_col_number."</td><td>".$rep_number."</td><td>".$seedlot_name."</td><td>".$num_seed_per_plot."</td></tr>";
243 $design_result_html .= "<tr><td>".$plot_name."</td><td>".$stock_name."</td><td>".$check_name."</td><td>".$plot_number."</td><td>".$row_number."</td><td>".$col_number."</td><td>".$block_number."</td><td>".$block_row_number."</td><td>".$block_col_number."</td><td>".$rep_number."</td><td>".$seedlot_name."</td><td>".$num_seed_per_plot."</td></tr>";
247 $design_result_html .= "</table>";
248 return "$design_result_html";
251 sub design_info_view
{
252 my $design_ref = shift;
253 my $design_info_ref = shift;
254 my %design = %{$design_ref};
255 my %design_info = %{$design_info_ref};
258 my $design_info_html;
259 my $design_description;
262 $design_info_html .= "<dl>";
264 if ($design_info{'design_type'}) {
265 $design_description = $design_info{'design_type'};
266 if ($design_info{'design_type'} eq "CRD") {
267 $design_description = "Completely Randomized Design";
269 if ($design_info{'design_type'} eq "RCBD") {
270 $design_description = "Randomized Complete Block Design";
272 if ($design_info{'design_type'} eq "Alpha") {
273 $design_description = "Alpha Lattice Incomplete Block Design";
275 if ($design_info{'design_type'} eq "Augmented") {
276 $design_description = "Augmented Incomplete Block Design";
278 if ($design_info{'design_type'} eq "MAD") {
279 $design_description = "Modified Augmented Design";
281 if ($design_info{'design_type'} eq "greenhouse") {
282 $design_description = "Greenhouse Design";
284 # if ($design_info{'design_type'} eq "MADII") {
285 # $design_description = "Modified Augmented Design II";
287 # if ($design_info{'design_type'} eq "MADIII") {
288 # $design_description = "Modified Augmented Design III";
290 # if ($design_info{'design_type'} eq "MADIV") {
291 # $design_description = "Modified Augmented Design IV";
293 $design_info_html .= "<dt>Design type</dt><dd>".$design_description."</dd>";
295 if ($design_info{'number_of_locations'}) {
296 $design_info_html .= "<dt>Number of locations</dt><dd>".$design_info{'number_of_locations'}."</dd>";
298 if ($design_info{'number_of_stocks'}) {
299 $design_info_html .= "<dt>Number of accessions</dt><dd>".$design_info{'number_of_stocks'}."</dd>";
301 if ($design_info{'number_of_checks'}) {
302 $design_info_html .= "<dt>Number of checks</dt><dd>".$design_info{'number_of_checks'}."</dd>";
304 if ($design_info{'number_of_controls'}) {
305 $design_info_html .= "<dt>Number of controls</dt><dd>".$design_info{'number_of_controls'}."</dd>";
308 my $treatment_info_string = "";
309 foreach my $key (sort { $a <=> $b} keys %design) {
310 my $current_block_number = $design{$key}->{block_number
};
311 my $current_rep_number;
312 if ($current_block_number) {
313 if ($block_hash{$current_block_number}) {
314 $block_hash{$current_block_number} += 1;
316 $block_hash{$current_block_number} = 1;
319 if ($design{$key}->{rep_number
}) {
320 $current_rep_number = $design{$key}->{rep_number
};
321 if ($rep_hash{$current_rep_number}) {
322 $rep_hash{$current_rep_number} += 1;
324 $rep_hash{$current_rep_number} = 1;
328 if($key eq 'treatments'){
329 while(my($k,$v) = each %{$design{$key}}){
330 my $treatment_units = join ',', @
{$v};
331 $treatment_info_string .= "<b>$k:</b> $treatment_units<br/>";
337 $design_info_html .= "<dt>Number of blocks</dt><dd>".scalar(keys %block_hash)."</dd>";
338 $design_info_html .= "<dt>Number of accessions per block</dt><dd>";
339 foreach my $key (sort { $a <=> $b} keys %block_hash) {
340 $design_info_html .= "Block ".$key.": ".$block_hash{$key}." accessions <br>";
342 $design_info_html .= "</dt>";
347 $design_info_html .= "<dt>Number of reps</dt><dd>".scalar(keys %rep_hash)."</dd>";
350 $design_info_html .= "<dt>Treatments:</dt><dd><div id='trial_design_confirm_treatments' >$treatment_info_string</div></dd>";
352 $design_info_html .= "</dl>";
354 return $design_info_html;