1 package CXGN
::Trial
::TrialDesign
;
5 CXGN::Trial::TrialDesign - a module to create a trial design using the R CRAN package Agricolae.
10 my $trial_design = CXGN::Trial::TrialDesign->new({schema => $schema} );
15 This module uses the the R CRAN package "Agricolae" to calculate experimental designs for field layouts.
19 Jeremy D. Edwards (jde22@cornell.edu)
20 Aimin Yan (ay247@cornell.edu)
24 use MooseX
::FollowPBP
;
25 use Moose
::Util
::TypeConstraints
;
28 use R
::YapRI
::Data
::Matrix
;
32 has
'trial_name' => (isa
=> 'Str', is
=> 'rw', predicate
=> 'has_trial_name', clearer
=> 'clear_trial_name');
33 has
'stock_list' => (isa
=> 'ArrayRef[Str]', is
=> 'rw', predicate
=> 'has_stock_list', clearer
=> 'clear_stock_list');
34 has
'seedlot_hash' => (isa
=> 'HashRef', is
=> 'rw', predicate
=> 'has_seedlot_hash', clearer
=> 'clear_seedlot_hash');
35 has
'control_list' => (isa
=> 'ArrayRef[Str]', is
=> 'rw', predicate
=> 'has_control_list', clearer
=> 'clear_control_list');
36 has
'control_list_crbd' => (isa
=> 'ArrayRef[Str]', is
=> 'rw', predicate
=> 'has_control_list_crbd', clearer
=> 'clear_control_list_crbd');
37 has
'number_of_blocks' => (isa
=> 'Int', is
=> 'rw', predicate
=> 'has_number_of_blocks', clearer
=> 'clear_number_of_blocks');
38 has
'block_row_numbers' => (isa
=> 'Int', is
=> 'rw', predicate
=> 'has_block_row_numbers', clearer
=> 'clear_block_row_numbers');
39 has
'block_col_numbers' => (isa
=> 'Int', is
=> 'rw', predicate
=> 'has_block_col_numbers', clearer
=> 'clear_block_col_numbers');
40 has
'number_of_rows' => (isa
=> 'Int',is
=> 'rw',predicate
=> 'has_number_of_rows',clearer
=> 'clear_number_of_rows');
41 has
'number_of_cols' => (isa
=> 'Int',is
=> 'rw',predicate
=> 'has_number_of_cols',clearer
=> 'clear_number_of_cols');
42 has
'number_of_reps' => (isa
=> 'Int', is
=> 'rw', predicate
=> 'has_number_of_reps', clearer
=> 'clear_number_of_reps');
43 has
'block_size' => (isa
=> 'Int', is
=> 'rw', predicate
=> 'has_block_size', clearer
=> 'clear_block_size');
44 has
'greenhouse_num_plants' => (isa
=> 'ArrayRef[Int]', is
=> 'rw', predicate
=> 'has_greenhouse_num_plants', clearer
=> 'clear_greenhouse_num_plants');
45 has
'maximum_block_size' => (isa
=> 'Int', is
=> 'rw', predicate
=> 'has_maximum_block_size', clearer
=> 'clear_maximum_block_size');
46 has
'plot_name_prefix' => (isa
=> 'Str', is
=> 'rw', predicate
=> 'has_plot_name_prefix', clearer
=> 'clear_plot_name_prefix');
47 has
'plot_name_suffix' => (isa
=> 'Str', is
=> 'rw', predicate
=> 'has_plot_name_suffix', clearer
=> 'clear_plot_name_suffix');
48 has
'plot_start_number' => (isa
=> 'Int', is
=> 'rw', predicate
=> 'has_plot_start_number', clearer
=> 'clear_plot_start_number', default => 1);
49 has
'plot_number_increment' => (isa
=> 'Int', is
=> 'rw', predicate
=> 'has_plot_number_increment', clearer
=> 'clear_plot_number_increment', default => 1);
50 has
'randomization_seed' => (isa
=> 'Int', is
=> 'rw', predicate
=> 'has_randomization_seed', clearer
=> 'clear_randomization_seed');
51 has
'blank' => ( isa
=> 'Str', is
=> 'rw', predicate
=> 'has_blank' );
52 has
'fieldmap_col_number' => (isa
=> 'Int',is
=> 'rw',predicate
=> 'has_fieldmap_col_number',clearer
=> 'clear_fieldmap_col_number');
53 has
'fieldmap_row_number' => (isa
=> 'Int',is
=> 'rw',predicate
=> 'has_fieldmap_row_number',clearer
=> 'clear_fieldmap_row_number');
54 has
'plot_layout_format' => (isa
=> 'Str', is
=> 'rw', predicate
=> 'has_plot_layout_format', clearer
=> 'clear_plot_layout_format');
55 has
'treatments' => (isa
=> 'ArrayRef', is
=> 'rw', predicate
=> 'has_treatments', clearer
=> 'clear_treatments');
56 has
'num_plants_per_plot' => (isa
=> 'Int',is
=> 'rw',predicate
=> 'has_num_plants_per_plot',clearer
=> 'clear_num_plants_per_plot');
57 has
'num_seed_per_plot' => (isa
=> 'Int',is
=> 'rw',predicate
=> 'has_num_seed_per_plot',clearer
=> 'clear_num_seed_per_plot');
58 has
'replicated_accession_no' => (isa
=> 'Int',is
=> 'rw',predicate
=> 'has_replicated_accession_no',clearer
=> 'clear_replicated_accession_no');
59 has
'unreplicated_accession_no' => (isa
=> 'Int',is
=> 'rw',predicate
=> 'has_unreplicated_accession_no',clearer
=> 'clear_unreplicated_accession_no');
60 has
'num_of_replicated_times' => (isa
=> 'Int',is
=> 'rw',predicate
=> 'has_num_of_replicated_times',clearer
=> 'clear_num_of_replicated_times');
61 has
'sub_block_sequence' => (isa
=> 'Str', is
=> 'rw', predicate
=> 'has_sub_block_sequence', clearer
=> 'clear_sub_block_sequence');
62 has
'block_sequence' => (isa
=> 'Str', is
=> 'rw', predicate
=> 'has_block_sequence', clearer
=> 'clear_block_sequence');
63 has
'col_in_design_number' => (isa
=> 'Int',is
=> 'rw',predicate
=> 'has_col_in_design_number',clearer
=> 'clear_col_in_design_number');
64 has
'row_in_design_number' => (isa
=> 'Int',is
=> 'rw',predicate
=> 'has_row_in_design_number',clearer
=> 'clear_row_in_design_number');
66 subtype
'RandomizationMethodType',
68 where
{ $_ eq "Wichmann-Hill" || $_ eq "Marsaglia-Multicarry" || $_ eq "Super-Duper" || $_ eq "Mersenne-Twister" || $_ eq "Knuth-
69 TAOCP" || $_ eq "Knuth-TAOCP-2002"},
70 message
{ "The string, $_, was not a valid randomization method"};
72 has
'randomization_method' => (isa
=> 'RandomizationMethodType', is
=> 'rw', default=> "Mersenne-Twister");
76 where
{ $_ eq "CRD" || $_ eq "RCBD" || $_ eq "Alpha" || $_ eq "Lattice" || $_ eq "Augmented" || $_ eq "MAD" || $_ eq "genotyping_plate" || $_ eq "greenhouse" || $_ eq "p-rep" || $_ eq "splitplot" },
77 message
{ "The string, $_, was not a valid design type" };
79 has
'design_type' => (isa
=> 'DesignType', is
=> 'rw', predicate
=> 'has_design_type', clearer
=> 'clear_design_type');
87 sub calculate_design
{
89 if (!$self->has_design_type()) {
93 if ($self->get_design_type() eq "CRD") {
94 $design = _get_crd_design
($self);
96 elsif ($self->get_design_type() eq "RCBD") {
97 $design = _get_rcbd_design
($self);
99 elsif ($self->get_design_type() eq "Alpha") {
100 $design = _get_alpha_lattice_design
($self);
102 elsif ($self->get_design_type() eq "Lattice") {
103 $design = _get_lattice_design
($self);
105 elsif ($self->get_design_type() eq "Augmented") {
106 $design = _get_augmented_design
($self);
107 # $design = _get_alpha_lattice_design($self);
109 elsif ($self->get_design_type() eq "p-rep") {
110 $design = _get_p_rep_design
($self);
113 # elsif ($self->get_design_type() eq "MADII") {
114 # $design = _get_madii_design($self);
117 elsif($self->get_design_type() eq "MAD") {
118 $design = _get_madiii_design
($self);
120 elsif ($self->get_design_type() eq "genotyping_plate") {
121 $design = $self->_get_genotyping_plate();
123 # elsif($self->get_design_type() eq "MADIV") {
124 # $design = _get_madiv_design($self);
126 elsif($self->get_design_type() eq "greenhouse") {
127 $design = _get_greenhouse_design
($self);
129 elsif($self->get_design_type() eq "splitplot") {
130 $design = _get_splitplot_design
($self);
133 die "Trial design" . $self->get_design_type() ." not supported\n";
143 sub _get_genotyping_plate
{
147 my $number_of_stocks;
148 if ($self->has_stock_list()) {
149 @stock_list = @
{$self->get_stock_list()};
150 $number_of_stocks = scalar(@stock_list);
151 if ($number_of_stocks > 95) {
152 die "Need fewer than 96 stocks per plate (at least one blank!)";
156 die "No stock list specified\n";
160 if ($self->has_blank()) {
161 $blank = $self->get_blank();
162 print STDERR
"Using previously set blank $blank\n";
165 my $well_no = int(rand() * $number_of_stocks)+1;
166 my $well_row = chr(int(($well_no-1) / 12) + 65);
167 my $well_col = ($well_no -1) % 12 +1;
168 $blank = sprintf "%s%02d", $well_row, $well_col;
169 print STDERR
"Using randomly assigned blank $blank\n";
174 foreach my $row ("A".."H") {
175 foreach my $col (1..12) {
177 my $well= sprintf "%s%02d", $row, $col;
178 #my $well = $row.$col;
180 if ($well eq $blank) {
181 $gt_design{$well} = {
182 plot_name
=> $self->get_trial_name()."_".$well."_BLANK",
183 stock_name
=> "BLANK",
186 elsif (@stock_list) {
188 { plot_name
=> $self->get_trial_name()."_".$well,
189 stock_name
=> shift(@stock_list),
192 #print STDERR Dumper(\%gt_design);
201 return ($val =~ m/^\d+$/);
204 sub _validate_field_colNumber
{
209 die "Choose a different row number for field map generation. The product of number of accessions and rep when divided by row number should give an integer\n";
215 sub _get_crd_design
{
218 #$self->set_number_of_blocks(1);
219 #%crd_design=%{_get_rcbd_design($self)};
220 my $rbase = R
::YapRI
::Base
->new();
222 my $number_of_blocks;
224 my $stock_data_matrix;
231 my @converted_plot_numbers;
232 my $number_of_stocks;
233 my @control_list_crbd;
234 my %control_names_lookup;
236 my $fieldmap_row_number;
237 my @fieldmap_row_numbers;
238 my $fieldmap_col_number;
239 my $plot_layout_format;
240 my @col_number_fieldmaps;
241 if ($self->has_stock_list()) {
242 @stock_list = @
{$self->get_stock_list()};
243 $number_of_stocks = scalar(@stock_list);
245 die "No stock list specified\n";
247 if ($self->has_control_list_crbd()) {
248 @control_list_crbd = @
{$self->get_control_list_crbd()};
249 %control_names_lookup = map { $_ => 1 } @control_list_crbd;
250 foreach $stock_name_iter (@stock_names) {
251 if (exists($control_names_lookup{$stock_name_iter})) {
252 die "Names in stock list cannot be used also as controls\n";
256 if ($self->has_number_of_reps()) {
257 $number_of_reps = $self->get_number_of_reps();
259 die "Number of reps not specified\n";
262 if ($self->has_fieldmap_col_number()) {
263 $fieldmap_col_number = $self->get_fieldmap_col_number();
265 if ($self->has_fieldmap_row_number()) {
266 $fieldmap_row_number = $self->get_fieldmap_row_number();
267 my $colNumber = ((scalar(@stock_list) * $number_of_reps)/$fieldmap_row_number);
268 $fieldmap_col_number = _validate_field_colNumber
($colNumber);
270 #if (isint($colNumber)){
271 #$fieldmap_col_number = $colNumber;
273 # die "Choose a different row number for field map generation. The product of number of accessions and rep when divided by row number should give an integer\n";
277 if ($self->has_plot_layout_format()) {
278 $plot_layout_format = $self->get_plot_layout_format();
281 if (scalar(@stock_list)>1) {
283 $stock_data_matrix = R
::YapRI
::Data
::Matrix
->new({
284 name
=> 'stock_data_matrix',
286 coln
=> scalar(@stock_list),
287 data
=> \
@stock_list,
289 #print STDERR Dumper $stock_data_matrix;
291 $r_block = $rbase->create_block('r_block');
292 $stock_data_matrix->send_rbase($rbase, 'r_block');
294 $r_block->add_command('library(agricolae)');
295 $r_block->add_command('trt <- stock_data_matrix[1,]');
296 $r_block->add_command('rep_vector <- rep('.$number_of_reps.',each='.$number_of_stocks.')');
297 $r_block->add_command('randomization_method <- "'.$self->get_randomization_method().'"');
299 if ($self->has_randomization_seed()){
300 $r_block->add_command('randomization_seed <- '.$self->get_randomization_seed());
301 $r_block->add_command('crd<-design.crd(trt,rep_vector,serie=3,kinds=randomization_method, seed=randomization_seed)');
304 $r_block->add_command('crd<-design.crd(trt,rep_vector,serie=3,kinds=randomization_method)');
306 $r_block->add_command('crd<-crd$book'); #added for agricolae 1.1-8 changes in output
307 $r_block->add_command('crd<-as.matrix(crd)');
308 $r_block->run_block();
309 $result_matrix = R
::YapRI
::Data
::Matrix
->read_rbase( $rbase,'r_block','crd');
310 #print STDERR Dumper $result_matrix;
312 @plot_numbers = $result_matrix->get_column("plots");
313 #print STDERR Dumper \@plot_numbers;
315 @rep_numbers = $result_matrix->get_column("r");
316 @stock_names = $result_matrix->get_column("trt");
317 @converted_plot_numbers=@
{_convert_plot_numbers
($self,\
@plot_numbers)};
318 #print STDERR Dumper \@converted_plot_numbers;
321 if ($plot_layout_format eq "zigzag") {
322 if (!$fieldmap_col_number){
323 @col_number_fieldmaps = ((1..(scalar(@stock_list))) x
$number_of_reps);
325 @col_number_fieldmaps = ((1..$fieldmap_col_number) x
$fieldmap_row_number);
327 #print STDERR Dumper(\@col_number_fieldmaps);
329 elsif ($plot_layout_format eq "serpentine") {
330 if (!$fieldmap_row_number) {
331 for my $rep (1 .. $number_of_reps){
333 push @col_number_fieldmaps, (1..(scalar(@stock_list)));
335 push @col_number_fieldmaps, (reverse 1..(scalar(@stock_list)));
339 for my $rep (1 .. $fieldmap_row_number){
341 push @col_number_fieldmaps, (1..$fieldmap_col_number);
343 push @col_number_fieldmaps, (reverse 1..$fieldmap_col_number);
347 #@col_number_fieldmaps = (my @cols, (1..(scalar(@stock_list))) x $number_of_reps);
350 } else { #only a single stock was given, so no randomization can occur.
351 @converted_plot_numbers = (1...$number_of_reps);
352 @rep_numbers = (1...$number_of_reps);
353 @stock_names = ($stock_list[0]) x
$number_of_reps;
356 if ($plot_layout_format && !$fieldmap_col_number && !$fieldmap_row_number){
357 @fieldmap_row_numbers = sort(@rep_numbers);
359 elsif ($plot_layout_format && $fieldmap_row_number){
360 @fieldmap_row_numbers = ((1..$fieldmap_row_number) x
$fieldmap_col_number);
361 @fieldmap_row_numbers = sort {$a <=> $b} @fieldmap_row_numbers;
364 my %seedlot_hash = %{$self->get_seedlot_hash};
365 for (my $i = 0; $i < scalar(@converted_plot_numbers); $i++) {
368 $plot_info{'stock_name'} = $stock_names[$i];
369 $plot_info{'seedlot_name'} = $seedlot_hash{$stock_names[$i]};
370 $plot_info{'num_seed_per_plot'} = $self->get_num_seed_per_plot;
371 $plot_info{'block_number'} = 1;
372 $plot_info{'rep_number'} = $rep_numbers[$i];
373 $plot_info{'plot_name'} = $converted_plot_numbers[$i];
374 $plot_info{'is_a_control'} = exists($control_names_lookup{$stock_names[$i]});
375 if ($fieldmap_row_numbers[$i]){
376 $plot_info{'row_number'} = $fieldmap_row_numbers[$i];
377 $plot_info{'col_number'} = $col_number_fieldmaps[$i];
379 $crd_design{$converted_plot_numbers[$i]} = \
%plot_info;
382 #print STDERR Dumper \%crd_design;
384 %crd_design = %{_build_plot_names
($self,\
%crd_design)};
388 sub _get_p_rep_design
{
391 my $rbase = R
::YapRI
::Base
->new();
393 my $stock_data_matrix;
399 my @converted_plot_numbers;
400 my $number_of_replicated_accession;
401 my $number_of_unreplicated_accession;
402 my $num_of_replicated_times;
403 my $sub_block_sequence;
405 my $col_in_design_number;
406 my $row_in_design_number;
408 if ($self->has_stock_list()) {
409 @stock_list = @
{$self->get_stock_list()};
411 die "No stock list specified\n";
413 if ($self->has_replicated_accession_no()) {
414 $number_of_replicated_accession = $self->get_replicated_accession_no();
416 if ($self->has_unreplicated_accession_no()) {
417 $number_of_unreplicated_accession = $self->get_unreplicated_accession_no();
419 if ($self->has_num_of_replicated_times()) {
420 $num_of_replicated_times = $self->get_num_of_replicated_times();
422 if ($self->has_sub_block_sequence()) {
423 $sub_block_sequence = $self->get_sub_block_sequence();
425 if ($self->has_block_sequence()) {
426 $block_sequence = $self->get_block_sequence();
428 if ($self->has_col_in_design_number()) {
429 $col_in_design_number = $self->get_col_in_design_number();
431 if ($self->has_row_in_design_number()) {
432 $row_in_design_number = $self->get_row_in_design_number();
435 $stock_data_matrix = R
::YapRI
::Data
::Matrix
->new(
437 name
=> 'stock_data_matrix',
439 coln
=> scalar(@stock_list),
440 data
=> \
@stock_list,
447 foreach my $x (@stock_list){
449 push @counts, $count;
451 for (my $n=0; $n<scalar(@stock_list); $n++) {
452 $stock_data_hash{$counts[$n]} = $stock_list[$n];
454 my ($no_row_in_block,$no_block_in_design) = split(',', $block_sequence);
455 $no_row_in_block = $no_row_in_block * $col_in_design_number;
457 $r_block = $rbase->create_block('r_block');
458 $stock_data_matrix->send_rbase($rbase, 'r_block');
459 $r_block->add_command('library(DiGGer)');
460 $r_block->add_command('library(R.methodsS3)');
461 $r_block->add_command('library(reshape)');
462 $r_block->add_command('library(R.oo)');
463 $r_block->add_command('numberOfTreatments <- ' .$stock_data_matrix->{coln
});
464 $r_block->add_command('rowsInDesign <- '.$row_in_design_number);
465 $r_block->add_command('columnsInDesign <- '.$col_in_design_number);
466 $r_block->add_command('blockSequence <- list(c('.$block_sequence.'), c('.$sub_block_sequence.'))');
467 $r_block->add_command('treatRepPerRep <- rep(c(1,'.$num_of_replicated_times.'), c('.$number_of_unreplicated_accession.', '.$number_of_replicated_accession.'))');
468 $r_block->add_command('treatGroup <- rep(c(1, 2), c('.$number_of_unreplicated_accession.', '.$number_of_replicated_accession.'))');
469 $r_block->add_command('rngSeeds <- c(156, 444)');
470 $r_block->add_command('runSearch <- TRUE');
471 $r_block->add_command('pRepDesign <- prDiGGer(numberOfTreatments = numberOfTreatments,
472 rowsInDesign = rowsInDesign,
473 columnsInDesign = columnsInDesign,
474 blockSequence = blockSequence,
475 treatRepPerRep = treatRepPerRep,
476 treatGroup = treatGroup,
478 runSearch = runSearch )');
479 #$r_block->add_command('pRepDesign <- run(pRepDesign)');
480 #$r_block->add_command('designBlock <- desTab(getDesign(pRepDesign), '.$block_sequence.')'); print "PARAMETER: 13\n";
481 $r_block->add_command('field_map <- getDesign(pRepDesign)');
482 $r_block->add_command('field_map_t <- t(field_map)');
483 $r_block->add_command('field_map_melt <- melt(field_map_t)');
484 $r_block->add_command('colnames(field_map_melt) <- c("col_number","row_number","trt")');
485 $r_block->add_command('rownames(field_map_melt) <- rownames(field_map_melt, do.NULL = FALSE, prefix = "Obs.")');
486 $r_block->add_command('dim_trt <- dim(field_map_melt)[1]');
487 $r_block->add_command('blockNo <- rep(1:'.$no_block_in_design.', each='.$no_row_in_block.')');
488 $r_block->add_command('blockNo <- melt(blockNo)');
489 $r_block->add_command('colnames(blockNo) <- c("block")');
490 $r_block->add_command('rownames(blockNo) <- rownames(blockNo, do.NULL = FALSE, prefix = "Obs.")');
491 $r_block->add_command('blockNo_merge <- match(rownames(field_map_melt), rownames(blockNo) )');
492 $r_block->add_command('blockNo_merge <- cbind( field_map_melt, blockNo[blockNo_merge,] )');
493 $r_block->add_command('colnames(blockNo_merge) <- c("col_number","row_number","trt","block")');
494 $r_block->add_command('rownames(blockNo_merge) <- rownames(blockNo_merge, do.NULL = FALSE, prefix = "Obs.")');
495 $r_block->add_command('plot_num <- c(1:dim_trt)');
496 $r_block->add_command('plot_num <- t(plot_num)');
497 $r_block->add_command('plot_num <- melt(plot_num)');
498 $r_block->add_command('colnames(plot_num) <- c("p2","p1","plots")');
499 $r_block->add_command('rownames(plot_num) <- rownames(plot_num, do.NULL = FALSE, prefix = "Obs.")');
500 #$r_block->add_command('layout_merge <- match(rownames(field_map_melt), rownames(plot_num) )');
501 #$r_block->add_command('layout_merge <- cbind( field_map_melt, plot_num[layout_merge,] )');
502 $r_block->add_command('layout_merge <- match(rownames(blockNo_merge), rownames(plot_num) )');
503 $r_block->add_command('layout_merge <- cbind( blockNo_merge, plot_num[layout_merge,] )');
504 $r_block->add_command('layout <- subset(layout_merge, select = c(plots, block, row_number, col_number, trt))');
505 $r_block->add_command('pRepDesign <- as.matrix(layout)');
506 #$r_block->run_block();
508 $result_matrix = R
::YapRI
::Data
::Matrix
->read_rbase( $rbase,'r_block','pRepDesign');
509 @plot_numbers = $result_matrix->get_column("plots");
510 @stock_names = $result_matrix->get_column("trt");
511 my @row_numbers = $result_matrix->get_column("row_number");
512 my @col_numbers = $result_matrix->get_column("col_number");
513 @block_numbers = $result_matrix->get_column("block");
514 @converted_plot_numbers=@
{_convert_plot_numbers
($self,\
@plot_numbers)};
517 my %seedlot_hash = %{$self->get_seedlot_hash};
518 for (my $i = 0; $i < scalar(@converted_plot_numbers); $i++) {
521 foreach my $key (keys %stock_data_hash){
522 if ($stock_names[$i] == $key && $plot_numbers[$i] eq $counting){
523 $plot_info{'stock_name'} = $stock_data_hash{$key};
526 $plot_info{'seedlot_name'} = $seedlot_hash{$plot_info{'stock_name'}};
527 $plot_info{'num_seed_per_plot'} = $self->get_num_seed_per_plot;
528 $plot_info{'block_number'} = $block_numbers[$i];
529 $plot_info{'plot_name'} = $converted_plot_numbers[$i];
530 $plot_info{'row_number'} = $row_numbers[$i];
531 $plot_info{'col_number'} = $col_numbers[$i];
533 $prep_design{$converted_plot_numbers[$i]} = \
%plot_info;
535 %prep_design = %{_build_plot_names
($self,\
%prep_design)};
536 return \
%prep_design;
540 sub _get_rcbd_design
{
543 my $rbase = R
::YapRI
::Base
->new();
545 my $number_of_blocks;
546 my $stock_data_matrix;
551 my @control_names_crbd;
553 my @converted_plot_numbers;
554 my @control_list_crbd;
555 my %control_names_lookup;
557 my $fieldmap_row_number;
558 my @fieldmap_row_numbers;
559 my $fieldmap_col_number;
560 my $plot_layout_format;
561 my @col_number_fieldmaps;
563 if ($self->has_stock_list()) {
564 @stock_list = @
{$self->get_stock_list()};
566 die "No stock list specified\n";
568 if ($self->has_control_list_crbd()) {
569 @control_list_crbd = @
{$self->get_control_list_crbd()};
570 %control_names_lookup = map { $_ => 1 } @control_list_crbd;
571 foreach $stock_name_iter (@stock_names) {
572 if (exists($control_names_lookup{$stock_name_iter})) {
573 die "Names in stock list cannot be used also as controls\n";
577 if ($self->has_number_of_blocks()) {
578 $number_of_blocks = $self->get_number_of_blocks();
580 die "Number of blocks not specified\n";
583 if ($self->has_fieldmap_col_number()) {
584 $fieldmap_col_number = $self->get_fieldmap_col_number();
586 if ($self->has_fieldmap_row_number()) {
587 $fieldmap_row_number = $self->get_fieldmap_row_number();
588 my $colNumber = ((scalar(@stock_list) * $number_of_blocks)/$fieldmap_row_number);
589 $fieldmap_col_number = _validate_field_colNumber
($colNumber);
591 if ($self->has_plot_layout_format()) {
592 $plot_layout_format = $self->get_plot_layout_format();
595 $stock_data_matrix = R
::YapRI
::Data
::Matrix
->new(
597 name
=> 'stock_data_matrix',
599 coln
=> scalar(@stock_list),
600 data
=> \
@stock_list,
604 $r_block = $rbase->create_block('r_block');
605 $stock_data_matrix->send_rbase($rbase, 'r_block');
606 $r_block->add_command('library(agricolae)');
607 $r_block->add_command('trt <- stock_data_matrix[1,]');
608 $r_block->add_command('number_of_blocks <- '.$number_of_blocks);
609 $r_block->add_command('randomization_method <- "'.$self->get_randomization_method().'"');
610 if ($self->has_randomization_seed()){
611 $r_block->add_command('randomization_seed <- '.$self->get_randomization_seed());
612 $r_block->add_command('rcbd<-design.rcbd(trt,number_of_blocks,serie=3,kinds=randomization_method, seed=randomization_seed)');
615 $r_block->add_command('rcbd<-design.rcbd(trt,number_of_blocks,serie=3,kinds=randomization_method)');
617 $r_block->add_command('rcbd<-rcbd$book'); #added for agricolae 1.1-8 changes in output
618 $r_block->add_command('rcbd<-as.matrix(rcbd)');
619 $r_block->run_block();
620 $result_matrix = R
::YapRI
::Data
::Matrix
->read_rbase( $rbase,'r_block','rcbd');
621 #print STDERR Dumper $result_matrix;
622 @plot_numbers = $result_matrix->get_column("plots");
623 #print STDERR Dumper \@plot_numbers;
624 @block_numbers = $result_matrix->get_column("block");
625 @stock_names = $result_matrix->get_column("trt");
626 @converted_plot_numbers=@
{_convert_plot_numbers
($self,\
@plot_numbers)};
630 if ($plot_layout_format eq "zigzag") {
631 if (!$fieldmap_col_number){
632 @col_number_fieldmaps = ((1..(scalar(@stock_list))) x
$number_of_blocks);
634 @col_number_fieldmaps = ((1..$fieldmap_col_number) x
$fieldmap_row_number);
637 elsif ($plot_layout_format eq "serpentine") {
638 if (!$fieldmap_row_number) {
639 for my $rep (1 .. $number_of_blocks){
641 push @col_number_fieldmaps, (1..(scalar(@stock_list)));
643 push @col_number_fieldmaps, (reverse 1..(scalar(@stock_list)));
647 for my $rep (1 .. $fieldmap_row_number){
649 push @col_number_fieldmaps, (1..$fieldmap_col_number);
651 push @col_number_fieldmaps, (reverse 1..$fieldmap_col_number);
657 if ($plot_layout_format && !$fieldmap_col_number && !$fieldmap_row_number){
658 @fieldmap_row_numbers = (@block_numbers);
660 elsif ($plot_layout_format && $fieldmap_row_number){
661 @fieldmap_row_numbers = ((1..$fieldmap_row_number) x
$fieldmap_col_number);
662 @fieldmap_row_numbers = sort {$a <=> $b} @fieldmap_row_numbers;
665 my %seedlot_hash = %{$self->get_seedlot_hash};
666 for (my $i = 0; $i < scalar(@converted_plot_numbers); $i++) {
668 $plot_info{'stock_name'} = $stock_names[$i];
669 $plot_info{'seedlot_name'} = $seedlot_hash{$stock_names[$i]};
670 $plot_info{'num_seed_per_plot'} = $self->get_num_seed_per_plot;
671 $plot_info{'block_number'} = $block_numbers[$i];
672 $plot_info{'plot_name'} = $converted_plot_numbers[$i];
673 $plot_info{'rep_number'} = $block_numbers[$i];
674 $plot_info{'plot_num_per_block'} = $plot_numbers[$i];
675 $plot_info{'is_a_control'} = exists($control_names_lookup{$stock_names[$i]});
676 #$plot_info_per_block{}
677 if ($fieldmap_row_numbers[$i]){
678 $plot_info{'row_number'} = $fieldmap_row_numbers[$i];
679 $plot_info{'col_number'} = $col_number_fieldmaps[$i];
681 $rcbd_design{$converted_plot_numbers[$i]} = \
%plot_info;
683 %rcbd_design = %{_build_plot_names
($self,\
%rcbd_design)};
684 return \
%rcbd_design;
687 sub _get_alpha_lattice_design
{
690 my $rbase = R
::YapRI
::Base
->new();
693 my $number_of_blocks;
695 my $stock_data_matrix;
702 my @converted_plot_numbers;
703 my @control_list_crbd;
704 my %control_names_lookup;
706 my $fieldmap_row_number;
707 my @fieldmap_row_numbers;
708 my $fieldmap_col_number;
709 my $plot_layout_format;
710 my @col_number_fieldmaps;
711 if ($self->has_stock_list()) {
712 @stock_list = @
{$self->get_stock_list()};
714 die "No stock list specified\n";
716 if ($self->has_control_list_crbd()) {
717 @control_list_crbd = @
{$self->get_control_list_crbd()};
718 %control_names_lookup = map { $_ => 1 } @control_list_crbd;
719 foreach $stock_name_iter (@stock_names) {
720 if (exists($control_names_lookup{$stock_name_iter})) {
721 die "Names in stock list cannot be used also as controls\n";
726 if ($self->has_number_of_reps()) {
727 $number_of_reps = $self->get_number_of_reps();
728 if ($number_of_reps < 2) {
729 die "Number of reps for alpha lattice design must be 2 or greater\n";
732 die "Number of reps not specified\n";
735 if ($self->has_fieldmap_col_number()) {
736 $fieldmap_col_number = $self->get_fieldmap_col_number();
739 if ($self->has_block_size()) {
740 $block_size = $self->get_block_size();
741 print STDERR
"block size = $block_size\n";
742 if ($block_size < 3) {
743 die "Block size must be greater than 2 for alpha lattice design\n";
745 # print "stock_list: ".scalar(@stock_list)."block_size: $block_size\n";
746 if (scalar(@stock_list) % $block_size != 0) {
747 die "Number of stocks (".scalar(@stock_list).") for alpha lattice design is not divisible by the block size ($block_size)\n";
750 # my $dummy_var = scalar(@stock_list) % $block_size;
751 # my $stocks_to_add = $block_size - $dummy_var;
752 # # print "$stock_list\n";
753 # foreach my $stock_list_rep(1..$stocks_to_add) {
754 # push(@stock_list, $stock_list[0]);
756 # print STDERR Dumper(\@stock_list);
757 # $self->set_stock_list(\@stock_list);
760 $number_of_blocks = scalar(@stock_list)/$block_size;
761 if ($number_of_blocks < $block_size) {
762 die "The number of blocks ($number_of_blocks) for alpha lattice design must not be less than the block size ($block_size)\n";
765 die "No block size specified\n";
768 if ($self->has_fieldmap_row_number()) {
769 $fieldmap_row_number = $self->get_fieldmap_row_number();
770 my $colNumber = ((scalar(@stock_list) * $number_of_reps)/$fieldmap_row_number);
771 $fieldmap_col_number = _validate_field_colNumber
($colNumber);
773 if ($self->has_plot_layout_format()) {
774 $plot_layout_format = $self->get_plot_layout_format();
777 $stock_data_matrix = R
::YapRI
::Data
::Matrix
->new(
779 name
=> 'stock_data_matrix',
781 coln
=> scalar(@stock_list),
782 data
=> \
@stock_list,
785 $r_block = $rbase->create_block('r_block');
786 $stock_data_matrix->send_rbase($rbase, 'r_block');
788 $r_block->add_command('library(agricolae)');
789 $r_block->add_command('trt <- stock_data_matrix[1,]');
790 $r_block->add_command('block_size <- '.$block_size);
791 $r_block->add_command('number_of_reps <- '.$number_of_reps);
792 $r_block->add_command('randomization_method <- "'.$self->get_randomization_method().'"');
793 if ($self->has_randomization_seed()){
794 $r_block->add_command('randomization_seed <- '.$self->get_randomization_seed());
795 $r_block->add_command('alpha<-design.alpha(trt,block_size,number_of_reps,serie=3,kinds=randomization_method, seed=randomization_seed)');
798 $r_block->add_command('alpha<-design.alpha(trt,block_size,number_of_reps,serie=3,kinds=randomization_method)');
800 $r_block->add_command('alpha_book<-alpha$book');
801 $r_block->add_command('alpha_book<-as.matrix(alpha_book)');
803 my @commands = $r_block->read_commands();
804 print STDERR
join "\n", @commands;
808 $r_block->run_block();
810 $result_matrix = R
::YapRI
::Data
::Matrix
->read_rbase( $rbase,'r_block','alpha_book');
811 @plot_numbers = $result_matrix->get_column("plots");
812 @block_numbers = $result_matrix->get_column("block");
813 @rep_numbers = $result_matrix->get_column("replication");
814 @stock_names = $result_matrix->get_column("trt");
815 @converted_plot_numbers=@
{_convert_plot_numbers
($self,\
@plot_numbers)};
817 if ($plot_layout_format eq "zigzag") {
818 if (!$fieldmap_col_number){
819 @col_number_fieldmaps = ((1..$number_of_blocks) x
($number_of_blocks * $number_of_reps));
820 #print STDERR Dumper(\@col_number_fieldmaps);
822 @col_number_fieldmaps = ((1..$fieldmap_col_number) x
$fieldmap_row_number);
825 elsif ($plot_layout_format eq "serpentine") {
826 if (!$fieldmap_row_number) {
827 for my $rep (1 .. ($number_of_blocks * $number_of_reps)){
829 push @col_number_fieldmaps, (1..$number_of_blocks);
831 push @col_number_fieldmaps, (reverse 1..$number_of_blocks);
835 for my $rep (1 .. $fieldmap_row_number){
837 push @col_number_fieldmaps, (1..$fieldmap_col_number);
839 push @col_number_fieldmaps, (reverse 1..$fieldmap_col_number);
845 if ($plot_layout_format && !$fieldmap_col_number && !$fieldmap_row_number){
846 @fieldmap_row_numbers = (@block_numbers);
848 elsif ($plot_layout_format && $fieldmap_row_number){
849 @fieldmap_row_numbers = ((1..$fieldmap_row_number) x
$fieldmap_col_number);
850 @fieldmap_row_numbers = sort {$a <=> $b} @fieldmap_row_numbers;
853 my %seedlot_hash = %{$self->get_seedlot_hash};
854 for (my $i = 0; $i < scalar(@converted_plot_numbers); $i++) {
856 $plot_info{'stock_name'} = $stock_names[$i];
857 $plot_info{'seedlot_name'} = $seedlot_hash{$stock_names[$i]};
858 $plot_info{'num_seed_per_plot'} = $self->get_num_seed_per_plot;
859 $plot_info{'block_number'} = $block_numbers[$i];
860 $plot_info{'plot_name'} = $converted_plot_numbers[$i];
861 $plot_info{'rep_number'} = $rep_numbers[$i];
862 $plot_info{'is_a_control'} = exists($control_names_lookup{$stock_names[$i]});
863 if ($fieldmap_row_numbers[$i]){
864 $plot_info{'row_number'} = $fieldmap_row_numbers[$i];
865 $plot_info{'col_number'} = $col_number_fieldmaps[$i];
867 $alpha_design{$converted_plot_numbers[$i]} = \
%plot_info;
869 %alpha_design = %{_build_plot_names
($self,\
%alpha_design)};
870 return \
%alpha_design;
873 sub _get_lattice_design
{
876 my $rbase = R
::YapRI
::Base
->new();
878 my $number_of_blocks;
880 my $stock_data_matrix;
887 my @converted_plot_numbers;
888 my @control_list_crbd;
889 my %control_names_lookup;
891 my $fieldmap_row_number;
892 my @fieldmap_row_numbers;
893 my $fieldmap_col_number;
894 my $plot_layout_format;
895 my @col_number_fieldmaps;
896 if ($self->has_stock_list()) {
897 @stock_list = @
{$self->get_stock_list()};
899 die "No stock list specified\n";
902 my $block_number_calculated = sqrt(scalar(@stock_list));
903 if ($block_number_calculated =~ /^\d+$/ ){
904 $number_of_blocks = $block_number_calculated;
906 die "Square root of Number of stocks (".scalar(@stock_list).") for lattice design should give a whole number.\n";
909 if ($self->has_control_list_crbd()) {
910 @control_list_crbd = @
{$self->get_control_list_crbd()};
911 %control_names_lookup = map { $_ => 1 } @control_list_crbd;
912 foreach $stock_name_iter (@stock_names) {
913 if (exists($control_names_lookup{$stock_name_iter})) {
914 die "Names in stock list cannot be used also as controls\n";
919 if ($self->has_number_of_reps()) {
920 $number_of_reps = $self->get_number_of_reps();
921 if ($number_of_reps == 2 || $number_of_reps == 3){
923 die "Number of reps should be 2 for SIMPLE and 3 for TRIPLE lattice design.\n";
926 die "Number of reps not specified\n";
929 if ($self->has_fieldmap_col_number()) {
930 $fieldmap_col_number = $self->get_fieldmap_col_number();
933 if ($self->has_fieldmap_row_number()) {
934 $fieldmap_row_number = $self->get_fieldmap_row_number();
935 my $colNumber = ((scalar(@stock_list) * $number_of_reps)/$fieldmap_row_number);
936 $fieldmap_col_number = _validate_field_colNumber
($colNumber);
938 if ($self->has_plot_layout_format()) {
939 $plot_layout_format = $self->get_plot_layout_format();
942 $stock_data_matrix = R
::YapRI
::Data
::Matrix
->new(
944 name
=> 'stock_data_matrix',
946 coln
=> scalar(@stock_list),
947 data
=> \
@stock_list,
950 $r_block = $rbase->create_block('r_block');
951 $stock_data_matrix->send_rbase($rbase, 'r_block');
952 $r_block->add_command('library(agricolae)');
953 $r_block->add_command('trt <- stock_data_matrix[1,]');
954 #$r_block->add_command('block_size <- '.$block_size);
955 $r_block->add_command('number_of_reps <- '.$number_of_reps);
956 #$r_block->add_command('randomization_method <- "'.$self->get_randomization_method().'"');
957 if ($self->has_randomization_seed()){
958 $r_block->add_command('randomization_seed <- '.$self->get_randomization_seed());
959 $r_block->add_command('lattice<-design.lattice(trt,r=number_of_reps,serie=3,kinds="Super-Duper", seed=randomization_seed)');
962 $r_block->add_command('lattice<-design.lattice(trt,r=number_of_reps,serie=3,kinds="Super-Duper")');
964 $r_block->add_command('lattice_book<-lattice$book');
965 $r_block->add_command('lattice_book<-as.matrix(lattice_book)');
967 my @commands = $r_block->read_commands();
968 print STDERR
join "\n", @commands;
972 $r_block->run_block();
974 $result_matrix = R
::YapRI
::Data
::Matrix
->read_rbase( $rbase,'r_block','lattice_book');
975 @plot_numbers = $result_matrix->get_column("plots");
976 #print STDERR Dumper(@plot_numbers);
977 @block_numbers = $result_matrix->get_column("block");
978 my $max = max
( @block_numbers );
979 @rep_numbers = $result_matrix->get_column("r");
980 @stock_names = $result_matrix->get_column("trt");
981 @converted_plot_numbers=@
{_convert_plot_numbers
($self,\
@plot_numbers)};
983 if ($plot_layout_format eq "zigzag") {
984 if (!$fieldmap_col_number){
985 @col_number_fieldmaps = ((1..$number_of_blocks) x
($number_of_blocks * $number_of_reps));
986 #print STDERR Dumper(\@col_number_fieldmaps);
988 @col_number_fieldmaps = ((1..$fieldmap_col_number) x
$fieldmap_row_number);
991 elsif ($plot_layout_format eq "serpentine") {
992 if (!$fieldmap_row_number) {
993 for my $rep (1 .. ($number_of_blocks * $number_of_reps)){
995 push @col_number_fieldmaps, (1..$number_of_blocks);
997 push @col_number_fieldmaps, (reverse 1..$number_of_blocks);
1001 for my $rep (1 .. $fieldmap_row_number){
1003 push @col_number_fieldmaps, (1..$fieldmap_col_number);
1005 push @col_number_fieldmaps, (reverse 1..$fieldmap_col_number);
1011 if ($plot_layout_format && !$fieldmap_col_number && !$fieldmap_row_number){
1012 @fieldmap_row_numbers = (@block_numbers);
1014 elsif ($plot_layout_format && $fieldmap_row_number){
1015 @fieldmap_row_numbers = ((1..$fieldmap_row_number) x
$fieldmap_col_number);
1016 @fieldmap_row_numbers = sort {$a <=> $b} @fieldmap_row_numbers;
1019 my %seedlot_hash = %{$self->get_seedlot_hash};
1020 for (my $i = 0; $i < scalar(@converted_plot_numbers); $i++) {
1022 $plot_info{'stock_name'} = $stock_names[$i];
1023 $plot_info{'seedlot_name'} = $seedlot_hash{$stock_names[$i]};
1024 $plot_info{'num_seed_per_plot'} = $self->get_num_seed_per_plot;
1025 $plot_info{'block_number'} = $block_numbers[$i];
1026 $plot_info{'plot_name'} = $converted_plot_numbers[$i];
1027 $plot_info{'rep_number'} = $rep_numbers[$i];
1028 $plot_info{'is_a_control'} = exists($control_names_lookup{$stock_names[$i]});
1029 if ($fieldmap_row_numbers[$i]){
1030 $plot_info{'row_number'} = $fieldmap_row_numbers[$i];
1031 $plot_info{'col_number'} = $col_number_fieldmaps[$i];
1033 $lattice_design{$converted_plot_numbers[$i]} = \
%plot_info;
1035 %lattice_design = %{_build_plot_names
($self,\
%lattice_design)};
1036 return \
%lattice_design;
1039 sub _get_augmented_design
{
1041 my %augmented_design;
1042 my $rbase = R
::YapRI
::Base
->new();
1045 my $maximum_block_size;
1046 my $number_of_blocks;
1047 my $stock_data_matrix;
1048 my $control_stock_data_matrix;
1054 my @converted_plot_numbers;
1055 my %control_names_lookup;
1056 my $stock_name_iter;
1058 if ($self->has_stock_list()) {
1059 @stock_list = @
{$self->get_stock_list()};
1061 die "No stock list specified\n";
1064 if ($self->has_control_list()) {
1065 @control_list = @
{$self->get_control_list()};
1066 %control_names_lookup = map { $_ => 1 } @control_list;
1067 foreach $stock_name_iter (@stock_names) {
1068 if (exists($control_names_lookup{$stock_name_iter})) {
1069 die "Names in stock list cannot be used also as controls\n";
1073 die "No list of control stocks specified. Required for augmented design.\n";
1076 if ($self->has_maximum_block_size()) {
1077 $maximum_block_size = $self->get_maximum_block_size();
1078 if ($maximum_block_size <= scalar(@control_list)) {
1079 die "Maximum block size must be greater the number of control stocks for augmented design\n";
1081 if ($maximum_block_size >= scalar(@control_list)+scalar(@stock_list)) {
1082 die "Maximum block size must be less than the number of stocks plus the number of controls for augmented design\n";
1084 $number_of_blocks = ceil
(scalar(@stock_list)/($maximum_block_size-scalar(@control_list)));
1086 die "No block size specified\n";
1089 $stock_data_matrix = R
::YapRI
::Data
::Matrix
->new(
1091 name
=> 'stock_data_matrix',
1093 coln
=> scalar(@stock_list),
1094 data
=> \
@stock_list,
1098 $control_stock_data_matrix = R
::YapRI
::Data
::Matrix
->new(
1100 name
=> 'control_stock_data_matrix',
1102 coln
=> scalar(@control_list),
1103 data
=> \
@control_list,
1106 $r_block = $rbase->create_block('r_block');
1107 $stock_data_matrix->send_rbase($rbase, 'r_block');
1108 $control_stock_data_matrix->send_rbase($rbase, 'r_block');
1109 $r_block->add_command('library(agricolae)');
1110 $r_block->add_command('trt <- stock_data_matrix[1,]');
1111 $r_block->add_command('control_trt <- control_stock_data_matrix[1,]');
1112 $r_block->add_command('number_of_blocks <- '.$number_of_blocks);
1113 $r_block->add_command('randomization_method <- "'.$self->get_randomization_method().'"');
1114 if ($self->has_randomization_seed()){
1115 $r_block->add_command('randomization_seed <- '.$self->get_randomization_seed());
1116 $r_block->add_command('augmented<-design.dau(control_trt,trt,number_of_blocks,serie=3,kinds=randomization_method, seed=randomization_seed)');
1119 $r_block->add_command('augmented<-design.dau(control_trt,trt,number_of_blocks,serie=3,kinds=randomization_method)');
1121 $r_block->add_command('augmented<-augmented$book'); #added for agricolae 1.1-8 changes in output
1122 $r_block->add_command('augmented<-as.matrix(augmented)');
1124 $r_block->run_block();
1125 $result_matrix = R
::YapRI
::Data
::Matrix
->read_rbase( $rbase,'r_block','augmented');
1126 @plot_numbers = $result_matrix->get_column("plots");
1127 @block_numbers = $result_matrix->get_column("block");
1128 @stock_names = $result_matrix->get_column("trt");
1129 @converted_plot_numbers=@
{_convert_plot_numbers
($self,\
@plot_numbers)};
1131 my %seedlot_hash = %{$self->get_seedlot_hash};
1132 for (my $i = 0; $i < scalar(@converted_plot_numbers); $i++) {
1134 $plot_info{'stock_name'} = $stock_names[$i];
1135 $plot_info{'seedlot_name'} = $seedlot_hash{$stock_names[$i]};
1136 $plot_info{'num_seed_per_plot'} = $self->get_num_seed_per_plot;
1137 $plot_info{'block_number'} = $block_numbers[$i];
1138 $plot_info{'plot_name'} = $converted_plot_numbers[$i];
1139 $plot_info{'is_a_control'} = exists($control_names_lookup{$stock_names[$i]});
1140 $augmented_design{$converted_plot_numbers[$i]} = \
%plot_info;
1142 %augmented_design = %{_build_plot_names
($self,\
%augmented_design)};
1143 return \
%augmented_design;
1147 sub _get_madii_design
{
1151 my $rbase = R
::YapRI
::Base
->new();
1155 my $maximum_block_size;
1156 my $number_of_blocks;
1158 my $stock_data_matrix;
1159 my $control_stock_data_matrix;
1165 my @converted_plot_numbers;
1166 my %control_names_lookup;
1167 my $stock_name_iter;
1172 my $block_row_number;
1173 my $block_col_number;
1174 my @block_row_numbers;
1175 my @block_col_numbers;
1178 if ($self->has_stock_list()) {
1179 @stock_list = @
{$self->get_stock_list()};
1181 die "No stock list specified\n";
1184 if ($self->has_control_list()) {
1185 @control_list = @
{$self->get_control_list()};
1186 %control_names_lookup = map { $_ => 1 } @control_list;
1187 foreach $stock_name_iter (@stock_names) {
1188 if (exists($control_names_lookup{$stock_name_iter})) {
1189 die "Names in stock list cannot be used also as controls\n";
1193 die "No list of control stocks specified. Required for augmented design.\n";
1196 # if ($self->has_number_of_blocks()) {
1197 # $number_of_blocks = $self->get_number_of_blocks();
1199 # die "Number of blocks not specified\n";
1202 if ($self->has_number_of_rows()) {
1203 $number_of_rows = $self->get_number_of_rows();
1205 die "Number of rows not specified\n";
1208 #system("R --slave --args $tempfile $tempfile_out < R/MADII_layout_function.R");
1209 # system("R --slave < R/MADII_layout_function.R");
1212 # if ($self->has_maximum_row_number()) {
1213 # $maximum_row_number = $self->get_maximum_row_number();
1214 # if ($maximum_block_size <= scalar(@control_list)) {
1215 # die "Maximum block size must be greater the number of control stocks for augmented design\n";
1217 # if ($maximum_block_size >= scalar(@control_list)+scalar(@stock_list)) {
1218 # die "Maximum block size must be less than the number of stocks plus the number of controls for augmented design\n";
1220 # $number_of_blocks = ceil(scalar(@stock_list)/($maximum_block_size-scalar(@control_list)));
1223 # die "No block size specified\n";
1227 # if ($self->has_maximum_block_size()) {
1228 # $maximum_block_size = $self->get_maximum_block_size();
1229 # if ($maximum_block_size <= scalar(@control_list)) {
1230 # die "Maximum block size must be greater the number of control stocks for augmented design\n";
1232 # if ($maximum_block_size >= scalar(@control_list)+scalar(@stock_list)) {
1233 # die "Maximum block size must be less than the number of stocks plus the number of controls for augmented design\n";
1235 # $number_of_blocks = ceil(scalar(@stock_list)/($maximum_block_size-scalar(@control_list)));
1237 # die "No block size specified\n";
1242 print STDERR
join "\n", "@stock_list\n";
1244 print STDERR
join "\n", "$number_of_rows\n";
1246 $stock_data_matrix = R
::YapRI
::Data
::Matrix
->new(
1248 name
=> 'stock_data_matrix',
1250 coln
=> scalar(@stock_list),
1251 data
=> \
@stock_list,
1254 $control_stock_data_matrix = R
::YapRI
::Data
::Matrix
->new(
1256 name
=> 'control_stock_data_matrix',
1258 coln
=> scalar(@control_list),
1259 data
=> \
@control_list,
1264 $r_block = $rbase->create_block('r_block');
1265 $stock_data_matrix->send_rbase($rbase, 'r_block');
1266 $control_stock_data_matrix->send_rbase($rbase, 'r_block');
1268 #$r_block->add_command('library(agricolae)');
1270 $r_block->add_command('library(MAD)');
1273 $r_block->add_command('trt <- as.array(stock_data_matrix[1,])');
1274 $r_block->add_command('control_trt <- as.array(control_stock_data_matrix[1,])');
1277 # $r_block->add_command('trt <- stock_data_matrix[1,]');
1278 # $r_block->add_command('control_trt <- control_stock_data_matrix[1,]');
1282 # $r_block->add_command('acc<-c(seq(1,330,1))');
1283 # $r_block<-add_command('chk<-c(seq(1,4,1))');
1285 # $r_block->add_command('trt <- acc');
1286 # $r_block->add_command('control_trt <- chk');
1287 # $r_block->add_command('number_of_blocks <- '.$number_of_blocks);
1289 $r_block->add_command('number_of_rows <- '.$number_of_rows);
1291 # $r_block->add_command('randomization_method <- "'.$self->get_randomization_method().'"');
1293 # if ($self->has_randomization_seed()){
1294 # $r_block->add_command('randomization_seed <- '.$self->get_randomization_seed());
1295 # $r_block->add_command('augmented<-design.dau(control_trt,trt,number_of_blocks,serie=1,kinds=randomization_method, seed=randomization_seed)');
1298 # $r_block->add_command('augmented<-design.dau(control_trt,trt,number_of_blocks,serie=1,kinds=randomization_method)');
1301 #$r_block->add_command('test.ma<-design.dma(entries=c(seq(1,330,1)),chk.names=c(seq(1,4,1)),num.rows=9, num.cols=NULL, num.sec.chk=3)');
1303 # $r_block->add_command('test.ma<-design.dma(entries=trt,chk.names=control_trt,num.rows=number_of_rows, num.cols=NULL, num.sec.chk=3)');
1305 # $r_block->add_command('test.ma<-design.dma.0(entries=trt,chk.names=control_trt, nFieldRow=number_of_rows)');
1307 $r_block->add_command('test.ma<-design.dma(entries=trt,chk.names=control_trt, nFieldRow=number_of_rows)');
1309 # design.dma.0(entries=c(seq(1,300,1)),chk.names= c(seq(1,4,1)),nFieldRow=10)
1311 # $r_block->add_command('augmented<-design.dau(control_trt,trt,number_of_blocks,serie=1,kinds=randomization_method)');
1313 # $r_block->add_command('augmented<-augmented$book'); #added for agricolae 1.1-8 changes in output
1315 $r_block->add_command('augmented<-test.ma[[2]]'); #added for agricolae 1.1-8 changes in output
1316 # $r_block->add_command('print(augmented)');
1317 $r_block->add_command('augmented<-as.matrix(augmented)');
1318 # $r_block->add_command('augmented<-as.data.frame(augmented)');
1320 # $r_block<-add_command('colnames(augmented)[2]<-"plots"');
1321 # $r_block<-add_command('colnames(augmented)[3]<-"trt"');
1322 # $r_block<-add_command('colnames(augmented)[7]<-"block"');
1324 my @commands = $r_block->read_commands();
1325 print STDERR
join "\n", @commands;
1328 $r_block->run_block();
1330 $result_matrix = R
::YapRI
::Data
::Matrix
->read_rbase( $rbase,'r_block','augmented');
1332 @plot_numbers = $result_matrix->get_column("Plot");
1333 @row_numbers = $result_matrix->get_column("Row");
1334 @col_numbers = $result_matrix->get_column("Col");
1335 @block_row_numbers=$result_matrix->get_column("Row.Blk");
1336 @block_col_numbers=$result_matrix->get_column("Col.Blk");
1337 @block_numbers = $result_matrix->get_column("Blk");
1338 @stock_names = $result_matrix->get_column("Entry");
1339 @check_names=$result_matrix->get_column("Check");
1343 @converted_plot_numbers=@
{_convert_plot_numbers
($self,\
@plot_numbers)};
1345 my %seedlot_hash = %{$self->get_seedlot_hash};
1346 for (my $i = 0; $i < scalar(@converted_plot_numbers); $i++) {
1349 $plot_info{'row_number'} =$row_numbers[$i];
1350 $plot_info{'col_number'} =$col_numbers[$i];
1351 $plot_info{'check_name'} =$check_names[$i];
1352 $plot_info{'stock_name'} = $stock_names[$i];
1353 $plot_info{'seedlot_name'} = $seedlot_hash{$stock_names[$i]};
1354 $plot_info{'num_seed_per_plot'} = $self->get_num_seed_per_plot;
1355 $plot_info{'block_number'} = $block_numbers[$i];
1356 $plot_info{'block_row_number'}=$block_row_numbers[$i];
1357 $plot_info{'block_col_number'}=$block_col_numbers[$i];
1358 $plot_info{'plot_name'} = $converted_plot_numbers[$i];
1359 $plot_info{'is_a_control'} = exists($control_names_lookup{$stock_names[$i]});
1360 $madii_design{$converted_plot_numbers[$i]} = \
%plot_info;
1363 %madii_design = %{_build_plot_names
($self,\
%madii_design)};
1365 # return \%augmented_design;
1367 #call R code and create design data structure
1369 return \
%madii_design;
1375 sub _get_madiii_design
{
1380 my $rbase = R
::YapRI
::Base
->new();
1384 my $maximum_block_size;
1385 my $number_of_blocks;
1388 my $number_of_rows_per_block;
1389 my $number_of_cols_per_block;
1393 my $stock_data_matrix;
1394 my $control_stock_data_matrix;
1400 my @converted_plot_numbers;
1401 my %control_names_lookup;
1402 my $stock_name_iter;
1407 my @block_row_numbers;
1408 my @block_col_numbers;
1411 if ($self->has_stock_list()) {
1412 @stock_list = @
{$self->get_stock_list()};
1414 die "No stock list specified\n";
1417 if ($self->has_control_list()) {
1418 @control_list = @
{$self->get_control_list()};
1419 %control_names_lookup = map { $_ => 1 } @control_list;
1420 foreach $stock_name_iter (@stock_names) {
1421 if (exists($control_names_lookup{$stock_name_iter})) {
1422 die "Names in stock list cannot be used also as controls\n";
1426 die "No list of control stocks specified. Required for augmented design.\n";
1430 if ($self->has_number_of_rows()) {
1431 $number_of_rows = $self->get_number_of_rows();
1433 die "Number of rows not specified\n";
1436 if ($self->has_block_row_numbers()) {
1437 $number_of_rows_per_block = $self->get_block_row_numbers();
1439 die "Number of block row not specified\n";
1442 if ($self->has_block_col_numbers()) {
1443 $number_of_cols_per_block = $self->get_block_col_numbers();
1445 die "Number of block col not specified\n";
1448 if ($self->has_number_of_cols()) {
1449 $number_of_cols = $self->get_number_of_cols();
1451 die "Number of blocks not specified\n";
1454 #system("R --slave --args $tempfile $tempfile_out < R/MADII_layout_function.R");
1455 # system("R --slave < R/MADII_layout_function.R");
1458 # if ($self->has_maximum_row_number()) {
1459 # $maximum_row_number = $self->get_maximum_row_number();
1460 # if ($maximum_block_size <= scalar(@control_list)) {
1461 # die "Maximum block size must be greater the number of control stocks for augmented design\n";
1463 # if ($maximum_block_size >= scalar(@control_list)+scalar(@stock_list)) {
1464 # die "Maximum block size must be less than the number of stocks plus the number of controls for augmented design\n";
1466 # $number_of_blocks = ceil(scalar(@stock_list)/($maximum_block_size-scalar(@control_list)));
1469 # die "No block size specified\n";
1473 # if ($self->has_maximum_block_size()) {
1474 # $maximum_block_size = $self->get_maximum_block_size();
1475 # if ($maximum_block_size <= scalar(@control_list)) {
1476 # die "Maximum block size must be greater the number of control stocks for augmented design\n";
1478 # if ($maximum_block_size >= scalar(@control_list)+scalar(@stock_list)) {
1479 # die "Maximum block size must be less than the number of stocks plus the number of controls for augmented design\n";
1481 # $number_of_blocks = ceil(scalar(@stock_list)/($maximum_block_size-scalar(@control_list)));
1483 # die "No block size specified\n";
1488 print "@stock_list\n";
1491 $stock_data_matrix = R
::YapRI
::Data
::Matrix
->new(
1493 name
=> 'stock_data_matrix',
1495 coln
=> scalar(@stock_list),
1496 data
=> \
@stock_list,
1499 $control_stock_data_matrix = R
::YapRI
::Data
::Matrix
->new(
1501 name
=> 'control_stock_data_matrix',
1503 coln
=> scalar(@control_list),
1504 data
=> \
@control_list,
1509 $r_block = $rbase->create_block('r_block');
1510 $stock_data_matrix->send_rbase($rbase, 'r_block');
1511 $control_stock_data_matrix->send_rbase($rbase, 'r_block');
1513 #$r_block->add_command('library(agricolae)');
1515 $r_block->add_command('library(MAD)');
1517 $r_block->add_command('trt <- as.array(stock_data_matrix[1,])');
1518 $r_block->add_command('control_trt <- as.array(control_stock_data_matrix[1,])');
1520 # $r_block->add_command('acc<-c(seq(1,330,1))');
1521 # $r_block<-add_command('chk<-c(seq(1,4,1))');
1523 # $r_block->add_command('trt <- acc');
1524 # $r_block->add_command('control_trt <- chk');
1525 # $r_block->add_command('number_of_blocks <- '.$number_of_blocks);
1527 # $r_block->add_command('randomization_method <- "'.$self->get_randomization_method().'"');
1529 # if ($self->has_randomization_seed()){
1530 # $r_block->add_command('randomization_seed <- '.$self->get_randomization_seed());
1531 # $r_block->add_command('augmented<-design.dau(control_trt,trt,number_of_blocks,serie=1,kinds=randomization_method, seed=randomization_seed)');
1534 # $r_block->add_command('augmented<-design.dau(control_trt,trt,number_of_blocks,serie=1,kinds=randomization_method)');
1537 #$r_block->add_command('test.ma<-design.dma(entries=c(seq(1,330,1)),chk.names=c(seq(1,4,1)),num.rows=9, num.cols=NULL, num.sec.chk=3)');
1539 $r_block->add_command('number_of_rows <- '.$number_of_rows);
1540 $r_block->add_command('number_of_cols <- '.$number_of_cols);
1541 $r_block->add_command('number_of_rows_per_block <- '.$number_of_rows_per_block);
1542 $r_block->add_command('number_of_cols_per_block <- '.$number_of_cols_per_block);
1544 $r_block->add_command('test.ma<-design.dma(entries=trt,chk.names=control_trt,nFieldRow=number_of_rows,nFieldCols=number_of_cols,nRowsPerBlk=number_of_rows_per_block, nColsPerBlk=number_of_cols_per_block)');
1547 # $r_block->add_command('test.ma<-design.dma(entries=trt,chk.names=control_trt,num.rows=9, num.cols=NULL, num.sec.chk=3)');
1549 #$r_block->add_command('test.ma<-design.dma(entries=trt,chk.names=control_trt,num.rows=9, num.cols=NULL, num.sec.chk=3)');
1551 # $r_block->add_command('augmented<-design.dau(control_trt,trt,number_of_blocks,serie=1,kinds=randomization_method)');
1553 # $r_block->add_command('augmented<-augmented$book'); #added for agricolae 1.1-8 changes in output
1555 $r_block->add_command('augmented<-test.ma[[2]]'); #added for agricolae 1.1-8 changes in output
1556 $r_block->add_command('augmented<-as.matrix(augmented)');
1558 # $r_block<-add_command('colnames(augmented)[2]<-"plots"');
1559 # $r_block<-add_command('colnames(augmented)[3]<-"trt"');
1560 # $r_block<-add_command('colnames(augmented)[7]<-"block"');
1563 my @commands = $r_block->read_commands();
1564 print STDERR
join "\n", @commands;
1568 $r_block->run_block();
1570 $result_matrix = R
::YapRI
::Data
::Matrix
->read_rbase( $rbase,'r_block','augmented');
1572 @plot_numbers = $result_matrix->get_column("Plot");
1573 @row_numbers = $result_matrix->get_column("Row");
1574 @col_numbers = $result_matrix->get_column("Col");
1575 @block_row_numbers=$result_matrix->get_column("Row.Blk");
1576 @block_col_numbers=$result_matrix->get_column("Col.Blk");
1577 @block_numbers = $result_matrix->get_column("Blk");
1578 @stock_names = $result_matrix->get_column("Entry");
1579 @check_names=$result_matrix->get_column("Check");
1586 @converted_plot_numbers=@
{_convert_plot_numbers
($self,\
@plot_numbers)};
1588 my %seedlot_hash = %{$self->get_seedlot_hash};
1589 for (my $i = 0; $i < scalar(@converted_plot_numbers); $i++) {
1592 $plot_info{'row_number'} =$row_numbers[$i];
1593 $plot_info{'col_number'} =$col_numbers[$i];
1594 $plot_info{'check_name'} =$check_names[$i];
1595 $plot_info{'stock_name'} = $stock_names[$i];
1596 $plot_info{'seedlot_name'} = $seedlot_hash{$stock_names[$i]};
1597 $plot_info{'num_seed_per_plot'} = $self->get_num_seed_per_plot;
1598 $plot_info{'block_number'} = $block_numbers[$i];
1599 $plot_info{'block_row_number'}=$block_row_numbers[$i];
1600 $plot_info{'block_col_number'}=$block_col_numbers[$i];
1601 $plot_info{'plot_name'} = $converted_plot_numbers[$i];
1602 $plot_info{'is_a_control'} = exists($control_names_lookup{$stock_names[$i]});
1603 $madiii_design{$converted_plot_numbers[$i]} = \
%plot_info;
1606 %madiii_design = %{_build_plot_names
($self,\
%madiii_design)};
1608 # return \%augmented_design;
1610 #call R code and create design data structure
1612 return \
%madiii_design;
1618 sub _get_madiv_design
{
1623 my $rbase = R
::YapRI
::Base
->new();
1627 my $maximum_block_size;
1628 my $number_of_blocks;
1631 my $number_of_rows_per_block;
1632 my $number_of_cols_per_block;
1636 my $stock_data_matrix;
1637 my $control_stock_data_matrix;
1643 my @converted_plot_numbers;
1644 my %control_names_lookup;
1645 my $stock_name_iter;
1650 my @block_row_numbers;
1651 my @block_col_numbers;
1654 if ($self->has_stock_list()) {
1655 @stock_list = @
{$self->get_stock_list()};
1657 die "No stock list specified\n";
1660 if ($self->has_control_list()) {
1661 @control_list = @
{$self->get_control_list()};
1662 %control_names_lookup = map { $_ => 1 } @control_list;
1663 foreach $stock_name_iter (@stock_names) {
1664 if (exists($control_names_lookup{$stock_name_iter})) {
1665 die "Names in stock list cannot be used also as controls\n";
1669 die "No list of control stocks specified. Required for augmented design.\n";
1673 if ($self->has_number_of_rows()) {
1674 $number_of_rows = $self->get_number_of_rows();
1676 die "Number of rows not specified\n";
1679 if ($self->has_block_row_numbers()) {
1680 $number_of_rows_per_block = $self->get_block_row_numbers();
1682 die "Number of block row not specified\n";
1685 # if ($self->has_block_col_numbers()) {
1686 # $number_of_cols_per_block = $self->get_block_col_numbers();
1688 # die "Number of block col not specified\n";
1691 # if ($self->has_number_of_cols()) {
1692 # $number_of_cols = $self->get_number_of_cols();
1694 # die "Number of blocks not specified\n";
1697 #system("R --slave --args $tempfile $tempfile_out < R/MADII_layout_function.R");
1698 # system("R --slave < R/MADII_layout_function.R");
1701 # if ($self->has_maximum_row_number()) {
1702 # $maximum_row_number = $self->get_maximum_row_number();
1703 # if ($maximum_block_size <= scalar(@control_list)) {
1704 # die "Maximum block size must be greater the number of control stocks for augmented design\n";
1706 # if ($maximum_block_size >= scalar(@control_list)+scalar(@stock_list)) {
1707 # die "Maximum block size must be less than the number of stocks plus the number of controls for augmented design\n";
1709 # $number_of_blocks = ceil(scalar(@stock_list)/($maximum_block_size-scalar(@control_list)));
1712 # die "No block size specified\n";
1716 # if ($self->has_maximum_block_size()) {
1717 # $maximum_block_size = $self->get_maximum_block_size();
1718 # if ($maximum_block_size <= scalar(@control_list)) {
1719 # die "Maximum block size must be greater the number of control stocks for augmented design\n";
1721 # if ($maximum_block_size >= scalar(@control_list)+scalar(@stock_list)) {
1722 # die "Maximum block size must be less than the number of stocks plus the number of controls for augmented design\n";
1724 # $number_of_blocks = ceil(scalar(@stock_list)/($maximum_block_size-scalar(@control_list)));
1726 # die "No block size specified\n";
1731 print "@stock_list\n";
1734 $stock_data_matrix = R
::YapRI
::Data
::Matrix
->new(
1736 name
=> 'stock_data_matrix',
1738 coln
=> scalar(@stock_list),
1739 data
=> \
@stock_list,
1742 $control_stock_data_matrix = R
::YapRI
::Data
::Matrix
->new(
1744 name
=> 'control_stock_data_matrix',
1746 coln
=> scalar(@control_list),
1747 data
=> \
@control_list,
1752 $r_block = $rbase->create_block('r_block');
1753 $stock_data_matrix->send_rbase($rbase, 'r_block');
1754 $control_stock_data_matrix->send_rbase($rbase, 'r_block');
1756 #$r_block->add_command('library(agricolae)');
1758 $r_block->add_command('library(MAD)');
1760 $r_block->add_command('trt <- as.array(stock_data_matrix[1,])');
1761 $r_block->add_command('control_trt <- as.array(control_stock_data_matrix[1,])');
1763 # $r_block->add_command('acc<-c(seq(1,330,1))');
1764 # $r_block<-add_command('chk<-c(seq(1,4,1))');
1766 # $r_block->add_command('trt <- acc');
1767 # $r_block->add_command('control_trt <- chk');
1768 # $r_block->add_command('number_of_blocks <- '.$number_of_blocks);
1770 # $r_block->add_command('randomization_method <- "'.$self->get_randomization_method().'"');
1772 # if ($self->has_randomization_seed()){
1773 # $r_block->add_command('randomization_seed <- '.$self->get_randomization_seed());
1774 # $r_block->add_command('augmented<-design.dau(control_trt,trt,number_of_blocks,serie=1,kinds=randomization_method, seed=randomization_seed)');
1777 # $r_block->add_command('augmented<-design.dau(control_trt,trt,number_of_blocks,serie=1,kinds=randomization_method)');
1780 #$r_block->add_command('test.ma<-design.dma(entries=c(seq(1,330,1)),chk.names=c(seq(1,4,1)),num.rows=9, num.cols=NULL, num.sec.chk=3)');
1782 $r_block->add_command('number_of_rows <- '.$number_of_rows);
1783 # $r_block->add_command('number_of_cols <- '.$number_of_cols);
1784 $r_block->add_command('number_of_rows_per_block <- '.$number_of_rows_per_block);
1785 # $r_block->add_command('number_of_cols_per_block <- '.$number_of_cols_per_block);
1787 #$r_block->add_command('test.ma<-design.dma(entries=trt,chk.names=control_trt,nFieldRow=number_of_rows,nFieldCols=number_of_cols,nRowsPerBlk=number_of_rows_per_block, nColsPerBlk=number_of_cols_per_block)');
1789 $r_block->add_command('test.ma<-design.dma(entries=trt,chk.names=control_trt,nFieldRow=number_of_rows,nRowsPerBlk=number_of_rows_per_block)');
1790 # $r_block->add_command('test.ma<-design.dma(entries=trt,chk.names=control_trt,num.rows=9, num.cols=NULL, num.sec.chk=3)');
1792 #$r_block->add_command('test.ma<-design.dma(entries=trt,chk.names=control_trt,num.rows=9, num.cols=NULL, num.sec.chk=3)');
1794 # $r_block->add_command('augmented<-design.dau(control_trt,trt,number_of_blocks,serie=1,kinds=randomization_method)');
1796 # $r_block->add_command('augmented<-augmented$book'); #added for agricolae 1.1-8 changes in output
1798 $r_block->add_command('augmented<-test.ma[[2]]'); #added for agricolae 1.1-8 changes in output
1799 $r_block->add_command('augmented<-as.matrix(augmented)');
1801 # $r_block<-add_command('colnames(augmented)[2]<-"plots"');
1802 # $r_block<-add_command('colnames(augmented)[3]<-"trt"');
1803 # $r_block<-add_command('colnames(augmented)[7]<-"block"');
1806 my @commands = $r_block->read_commands();
1807 print STDERR
join "\n", @commands;
1811 $r_block->run_block();
1813 $result_matrix = R
::YapRI
::Data
::Matrix
->read_rbase( $rbase,'r_block','augmented');
1815 @plot_numbers = $result_matrix->get_column("Plot");
1816 @row_numbers = $result_matrix->get_column("Row");
1817 @col_numbers = $result_matrix->get_column("Col");
1818 @block_row_numbers=$result_matrix->get_column("Row.Blk");
1819 @block_col_numbers=$result_matrix->get_column("Col.Blk");
1820 @block_numbers = $result_matrix->get_column("Blk");
1821 @stock_names = $result_matrix->get_column("Entry");
1822 @check_names=$result_matrix->get_column("Check");
1829 @converted_plot_numbers=@
{_convert_plot_numbers
($self,\
@plot_numbers)};
1831 my %seedlot_hash = %{$self->get_seedlot_hash};
1832 for (my $i = 0; $i < scalar(@converted_plot_numbers); $i++) {
1835 $plot_info{'row_number'} =$row_numbers[$i];
1836 $plot_info{'col_number'} =$col_numbers[$i];
1837 $plot_info{'check_name'} =$check_names[$i];
1838 $plot_info{'stock_name'} = $stock_names[$i];
1839 $plot_info{'seedlot_name'} = $seedlot_hash{$stock_names[$i]};
1840 $plot_info{'num_seed_per_plot'} = $self->get_num_seed_per_plot;
1841 $plot_info{'block_number'} = $block_numbers[$i];
1842 $plot_info{'block_row_number'}=$block_row_numbers[$i];
1843 $plot_info{'block_col_number'}=$block_col_numbers[$i];
1844 $plot_info{'plot_name'} = $converted_plot_numbers[$i];
1845 $plot_info{'is_a_control'} = exists($control_names_lookup{$stock_names[$i]});
1846 $madiv_design{$converted_plot_numbers[$i]} = \
%plot_info;
1849 %madiv_design = %{_build_plot_names
($self,\
%madiv_design)};
1851 # return \%augmented_design;
1853 #call R code and create design data structure
1855 return \
%madiv_design;
1861 sub _convert_plot_numbers
{
1863 my $plot_numbers_ref = shift;
1864 my @plot_numbers = @
{$plot_numbers_ref};
1865 for (my $i = 0; $i < scalar(@plot_numbers); $i++) {
1867 my $first_plot_number;
1868 if($self->has_plot_start_number || $self->has_plot_number_increment){
1869 if ($self->has_plot_start_number()){
1870 $first_plot_number = $self->get_plot_start_number();
1872 $first_plot_number = 1;
1874 if ($self->has_plot_number_increment()){
1875 $plot_number = $first_plot_number + ($i * $self->get_plot_number_increment());
1878 $plot_number = $first_plot_number + $i;
1882 $plot_number = $plot_numbers[$i];
1884 $plot_numbers[$i] = $plot_number;
1886 return \
@plot_numbers;
1889 sub _build_plot_names
{
1891 my $design_ref = shift;
1892 my %design = %{$design_ref};
1895 my $trial_name = $self->get_trial_name;
1897 if ($self->has_plot_name_prefix()) {
1898 $prefix = $self->get_plot_name_prefix()."_";
1900 if ($self->has_plot_name_suffix()) {
1901 $suffix = $self->get_plot_name_suffix();
1904 foreach my $key (keys %design) {
1906 my $block_number = $design{$key}->{block_number
};
1907 my $stock_name = $design{$key}->{stock_name
};
1908 my $rep_number = $design{$key}->{rep_number
};
1909 $design{$key}->{plot_number
} = $key;
1911 if ($self->get_design_type() eq "RCBD") { # as requested by IITA (Prasad)
1912 my $plot_num_per_block = $design{$key}->{plot_num_per_block
};
1913 $design{$key}->{plot_number
} = $design{$key}->{plot_num_per_block
};
1914 #$design{$key}->{plot_name} = $prefix.$trial_name."_rep_".$rep_number."_".$stock_name."_".$block_number."_".$plot_num_per_block."".$suffix;
1915 $design{$key}->{plot_name
} = $prefix.$trial_name."_rep".$rep_number."_".$stock_name."_".$plot_num_per_block."".$suffix;
1917 elsif ($self->get_design_type() eq "Augmented") {
1918 $design{$key}->{plot_name
} = $prefix.$trial_name."_plotno".$key."_".$stock_name."_".$suffix;
1921 $design{$key}->{plot_name
} = $prefix.$trial_name."_".$key.$suffix;
1924 if($design{$key}->{subplots_names
}){
1925 my $nums = $design{$key}->{subplots_names
};
1928 push @named_subplots, $design{$key}->{plot_name
}."_subplot_".$_;
1930 $design{$key}->{subplots_names
} = \
@named_subplots;
1934 #print STDERR Dumper(\%design);
1939 sub _get_greenhouse_design
{
1942 my %greenhouse_design;
1943 my @num_plants = @
{ $self->get_greenhouse_num_plants() };
1944 my @accession_list = sort @
{ $self->get_stock_list() };
1945 my $trial_name = $self->get_trial_name;
1946 my %num_accession_hash;
1947 @num_accession_hash{@accession_list} = @num_plants;
1949 my @plot_numbers = (1..scalar(@accession_list));
1950 my %seedlot_hash = %{$self->get_seedlot_hash};
1951 for (my $i = 0; $i < scalar(@plot_numbers); $i++) {
1953 $plot_info{'stock_name'} = $accession_list[$i];
1954 $plot_info{'seedlot_name'} = $seedlot_hash{$accession_list[$i]};
1955 $plot_info{'num_seed_per_plot'} = $self->get_num_seed_per_plot;
1956 $plot_info{'block_number'} = 1;
1957 $plot_info{'rep_number'} = 1;
1958 $plot_info{'plot_name'} = $plot_numbers[$i];
1959 $greenhouse_design{$plot_numbers[$i]} = \
%plot_info;
1961 %greenhouse_design = %{_build_plot_names
($self,\
%greenhouse_design)};
1963 foreach my $plot_num (keys %greenhouse_design) {
1965 my $plot_name = $greenhouse_design{$plot_num}->{'plot_name'};
1966 my $stock_name = $greenhouse_design{$plot_num}->{'stock_name'};
1967 for my $n (1..$num_accession_hash{$stock_name}) {
1968 my $plant_name = $plot_name."_plant_$n";
1969 push @plant_names, $plant_name;
1971 $greenhouse_design{$plot_num}->{'plant_names'} = \
@plant_names;
1974 #print STDERR Dumper \%greenhouse_design;
1975 return \
%greenhouse_design;
1978 sub _get_splitplot_design
{
1980 my %splitplot_design;
1981 my $rbase = R
::YapRI
::Base
->new();
1983 my $number_of_blocks;
1985 my $stock_data_matrix;
1989 my @subplots_numbers;
1994 my @converted_plot_numbers;
1995 my $number_of_stocks;
1996 my $stock_name_iter;
1997 my $fieldmap_row_number;
1998 my @fieldmap_row_numbers;
1999 my $fieldmap_col_number;
2000 my $plot_layout_format;
2001 my @col_number_fieldmaps;
2003 my $num_plants_per_plot;
2004 if ($self->has_stock_list()) {
2005 @stock_list = @
{$self->get_stock_list()};
2006 $number_of_stocks = scalar(@stock_list);
2008 die "No stock list specified\n";
2010 if ($self->has_treatments()) {
2011 $treatments = $self->get_treatments();
2013 die "treatments not specified\n";
2015 if ($self->has_number_of_blocks()) {
2016 $number_of_blocks = $self->get_number_of_blocks();
2017 $number_of_reps = $number_of_blocks;
2019 die "Number of blocks not specified\n";
2022 if ($self->has_fieldmap_col_number()) {
2023 $fieldmap_col_number = $self->get_fieldmap_col_number();
2025 if ($self->has_fieldmap_row_number()) {
2026 $fieldmap_row_number = $self->get_fieldmap_row_number();
2027 my $colNumber = ((scalar(@stock_list) * $number_of_reps)/$fieldmap_row_number);
2028 $fieldmap_col_number = _validate_field_colNumber
($colNumber);
2031 if ($self->has_plot_layout_format()) {
2032 $plot_layout_format = $self->get_plot_layout_format();
2034 if($self->has_num_plants_per_plot()){
2035 $num_plants_per_plot = $self->get_num_plants_per_plot();
2038 $stock_data_matrix = R
::YapRI
::Data
::Matrix
->new({
2039 name
=> 'stock_data_matrix',
2041 coln
=> scalar(@stock_list),
2042 data
=> \
@stock_list,
2044 #print STDERR Dumper $stock_data_matrix;
2045 my $treatment_data_matrix = R
::YapRI
::Data
::Matrix
->new({
2046 name
=> 'treatment_data_matrix',
2048 coln
=> scalar(@
$treatments),
2049 data
=> $treatments,
2051 #print STDERR Dumper $treatment_data_matrix;
2053 $r_block = $rbase->create_block('r_block');
2054 $stock_data_matrix->send_rbase($rbase, 'r_block');
2055 $treatment_data_matrix->send_rbase($rbase, 'r_block');
2057 $r_block->add_command('library(agricolae)');
2058 $r_block->add_command('accessions <- stock_data_matrix[1,]');
2059 $r_block->add_command('treatments <- treatment_data_matrix[1,]');
2060 $r_block->add_command('r <- '.$number_of_reps);
2061 $r_block->add_command('randomization_method <- "'.$self->get_randomization_method().'"');
2063 if ($self->has_randomization_seed()){
2064 $r_block->add_command('randomization_seed <- '.$self->get_randomization_seed());
2065 $r_block->add_command('splitplot<-design.split(accessions,treatments,r=r,serie=3,kinds=randomization_method, seed=randomization_seed)');
2068 $r_block->add_command('splitplot<-design.split(accessions,treatments,r=r,serie=3,kinds=randomization_method)');
2070 $r_block->add_command('split<-splitplot$book'); #added for agricolae 1.1-8 changes in output
2071 $r_block->add_command('split<-as.matrix(split)');
2072 $r_block->run_block();
2073 $result_matrix = R
::YapRI
::Data
::Matrix
->read_rbase( $rbase,'r_block','split');
2074 #print STDERR Dumper $result_matrix;
2076 @plot_numbers = $result_matrix->get_column("plots");
2077 @subplots_numbers = $result_matrix->get_column("splots");
2078 @rep_numbers = $result_matrix->get_column("block");
2079 @stock_names = $result_matrix->get_column("accessions");
2080 @treatments = $result_matrix->get_column("treatments");
2081 @converted_plot_numbers=@
{_convert_plot_numbers
($self,\
@plot_numbers)};
2082 #print STDERR Dumper \@converted_plot_numbers;
2084 if ($plot_layout_format eq "zigzag") {
2085 if (!$fieldmap_col_number){
2086 for (1..$number_of_reps){
2087 for my $s (1..(scalar(@stock_list))){
2088 for (1..scalar(@
$treatments)){
2089 push @col_number_fieldmaps, $s;
2094 for (1..$fieldmap_row_number){
2095 for my $s (1..$fieldmap_col_number){
2096 for (1..scalar(@
$treatments)){
2097 push @col_number_fieldmaps, $s;
2103 elsif ($plot_layout_format eq "serpentine") {
2104 if (!$fieldmap_row_number) {
2105 for my $rep (1 .. $number_of_reps){
2107 for my $s (1..(scalar(@stock_list))){
2108 for (1..scalar(@
$treatments)){
2109 push @col_number_fieldmaps, $s;
2113 for my $s (reverse 1..(scalar(@stock_list))){
2114 for (1..scalar(@
$treatments)){
2115 push @col_number_fieldmaps, $s;
2121 for my $rep (1 .. $fieldmap_row_number){
2123 for my $s (1..$fieldmap_col_number){
2124 for (1..scalar(@
$treatments)){
2125 push @col_number_fieldmaps, $s;
2129 for my $s (reverse 1..$fieldmap_col_number){
2130 for (1..scalar(@
$treatments)){
2131 push @col_number_fieldmaps, $s;
2139 if ($plot_layout_format && !$fieldmap_col_number && !$fieldmap_row_number){
2140 @fieldmap_row_numbers = sort(@rep_numbers);
2142 elsif ($plot_layout_format && $fieldmap_row_number){
2143 @fieldmap_row_numbers = ((1..$fieldmap_row_number) x
$fieldmap_col_number);
2144 @fieldmap_row_numbers = sort {$a <=> $b} @fieldmap_row_numbers;
2146 #print STDERR Dumper \@fieldmap_row_numbers;
2147 #print STDERR Dumper \@col_number_fieldmaps;
2150 my %treatment_plots;
2151 my %treatment_subplot_hash;
2152 my %seedlot_hash = %{$self->get_seedlot_hash};
2153 for (my $i = 0; $i < scalar(@converted_plot_numbers); $i++) {
2156 $plot_info{'stock_name'} = $stock_names[$i];
2157 $plot_info{'seedlot_name'} = $seedlot_hash{$stock_names[$i]};
2158 $plot_info{'num_seed_per_plot'} = $self->get_num_seed_per_plot;
2159 $plot_info{'block_number'} = 1;
2160 $plot_info{'rep_number'} = $rep_numbers[$i];
2161 $plot_info{'plot_name'} = $converted_plot_numbers[$i];
2162 $plot_info{'plot_number'} = $converted_plot_numbers[$i];
2163 if ($fieldmap_row_numbers[$i]){
2164 $plot_info{'row_number'} = $fieldmap_row_numbers[$i];
2165 $plot_info{'col_number'} = $col_number_fieldmaps[$i];
2167 push @
{$subplot_plots{$converted_plot_numbers[$i]}}, $subplots_numbers[$i];
2168 $plot_info{'subplots_names'} = $subplot_plots{$converted_plot_numbers[$i]};
2169 push @
{$treatment_plots{$converted_plot_numbers[$i]}}, $treatments[$i];
2170 $plot_info{'treatments'} = $treatment_plots{$converted_plot_numbers[$i]};
2171 $splitplot_design{$converted_plot_numbers[$i]} = \
%plot_info;
2173 #print STDERR Dumper \%splitplot_design;
2174 %splitplot_design = %{_build_plot_names
($self,\
%splitplot_design)};
2176 while(my($plot,$val) = each(%splitplot_design)){
2177 my $subplots = $val->{'subplots_names'};
2178 my $treatments = $val->{'treatments'};
2179 my $num_plants_per_subplot = $num_plants_per_plot/scalar(@
$subplots);
2180 my %subplot_plants_hash;
2182 my $plant_index = 1;
2183 for(my $i=0; $i<scalar(@
$subplots); $i++){
2184 push @
{$treatment_subplot_hash{$treatments->[$i]}}, $subplots->[$i];
2185 for(my $j=0; $j<$num_plants_per_subplot; $j++){
2186 my $plant_name = $subplots->[$i]."_plant_$plant_index";
2187 push @
{$subplot_plants_hash{$subplots->[$i]}}, $plant_name;
2188 push @
{$treatment_subplot_hash{$treatments->[$i]}}, $plant_name;
2189 push @plant_names, $plant_name;
2193 $val->{plant_names
} = \
@plant_names;
2194 $val->{subplots_plant_names
} = \
%subplot_plants_hash;
2196 $splitplot_design{'treatments'} = \
%treatment_subplot_hash;
2197 #print STDERR Dumper \%splitplot_design;
2198 return \
%splitplot_design;