5 use SGN::Test::Fixture;
8 my $fix = SGN::Test::Fixture->new();
10 is(ref($fix->config()), "HASH", 'hashref check');
12 BEGIN {use_ok('CXGN::Trial::TrialCreate');}
13 BEGIN {use_ok('CXGN::Trial::TrialLayout');}
14 BEGIN {use_ok('CXGN::Trial::TrialDesign');}
15 BEGIN {use_ok('CXGN::Trial::TrialLookup');}
16 ok(my $chado_schema = $fix->bcs_schema);
17 ok(my $phenome_schema = $fix->phenome_schema);
18 ok(my $dbh = $fix->dbh);
20 # create locations for the trial
22 for (my $i = 1; $i <= 2; $i++) {
23 ok(my $trial_location = "test_location_for_multi_trial".$i);
24 push @multi_location, $trial_location;
27 foreach my $multi_trial_loc (@multi_location) {
28 ok(my $location = $chado_schema->resultset('NaturalDiversity::NdGeolocation')
30 description => $multi_trial_loc,
32 ok($location->insert());
35 # create stocks for the trial
36 ok(my $accession_cvterm = $chado_schema->resultset("Cv::Cvterm")
44 for (my $i = 1; $i <= 10; $i++) {
45 push(@stock_names, "test_stock_for_multi_trial".$i);
48 ok(my $organism = $chado_schema->resultset("Organism::Organism")
50 genus => 'Test_genus',
51 species => 'Test_genus test_species',
54 # create some test stocks
55 foreach my $stock_name (@stock_names) {
56 my $accession_stock = $chado_schema->resultset('Stock::Stock')
58 organism_id => $organism->organism_id,
60 uniquename => $stock_name,
61 type_id => $accession_cvterm->cvterm_id,
65 #create multilocation trial
68 foreach my $trial_location (@multi_location) {
69 ok(my $trial_design = CXGN::Trial::TrialDesign->new(), "create trial design object");
70 ok($trial_design->set_trial_name("test_multi_trial_name".$trial_location), "set trial name");
71 ok($trial_design->set_stock_list(\@stock_names), "set stock list");
72 ok($trial_design->set_plot_start_number(1), "set plot start number");
73 ok($trial_design->set_plot_number_increment(1), "set plot increment");
74 ok($trial_design->set_number_of_blocks(2), "set block number");
75 ok($trial_design->set_design_type("RCBD"), "set design type");
76 ok($trial_design->calculate_design(), "calculate design");
77 ok(my $design = $trial_design->get_design(), "retrieve design");
78 push @multi_design, $design;
80 ok(my $trial_create = CXGN::Trial::TrialCreate->new({
81 chado_schema => $chado_schema,
84 design => $multi_design[$design_index],
87 trial_description => "multilocation test description",
88 #trial_location => "test_location_for_trial",
89 trial_location => $trial_location,
90 trial_name => "test_multi_trial_name".$trial_location,
91 design_type => "RCBD",
93 }), "create trial object");
95 my $save = $trial_create->save_trial();
96 ok($save->{'trial_id'}, "save trial");
100 ok(my $trial_lookup = CXGN::Trial::TrialLookup->new({
101 schema => $chado_schema,
102 trial_name => "test_multi_trial_name".$trial_location,
103 }), "create trial lookup object");
104 ok(my $trial = $trial_lookup->get_trial());
105 ok(my $trial_id = $trial->project_id());
106 ok(my $trial_layout = CXGN::Trial::TrialLayout->new({
107 schema => $chado_schema,
108 trial_id => $trial_id,
109 experiment_type => 'field_layout'
110 }), "create trial layout object");
111 print STDERR Dumper($trial_layout->get_design());
113 ok(my $accession_names = $trial_layout->get_accession_names(), "retrieve accession names2");
115 my %stocks = map { $_ => 1 } @stock_names;
117 foreach my $acc (@$accession_names) {
118 ok(exists($stocks{$acc->{accession_name}}), "check accession names $acc->{accession_name}");