modified key
[sgn.git] / lib / CXGN / Trial / TrialLayout.pm
blob952280955ae09b6d5b8e3a4214537417c18f9e3a
1 package CXGN::Trial::TrialLayout;
3 =head1 NAME
5 CXGN::Trial::TrialLayout - Module to get layout information about a trial
7 =head1 SYNOPSIS
9 This object has been converted to a factory object that will produce different classes
10 based on the experiment_type. The usage has been kept the same for backwards compatibility,
11 but a cleaner factory object implementation should be adopted in the future.
13 my $trial_layout = CXGN::Trial::TrialLayout->new({
14 schema => $schema,
15 trial_id => $trial_id,
16 experiment_type => $experiment_type #Either 'field_layout' or 'genotyping_layout'
17 });
18 my $tl = $trial_layout->get_design();
20 This module handles both retrieval of field_layout and genotyping_layout experiments.
22 If experiment_type is field_layout, get_design returns a hash representing
23 all the plots, with their design info and plant info and samples info. The return is
24 a HashRef of HashRef where the keys are the plot_number such as:
27 '1001' => {
28 "plot_name" => "plot1",
29 "plot_number" => 1001,
30 "plot_id" => 1234,
31 "accession_name" => "accession1",
32 "accession_id" => 2345,
33 "block_number" => 1,
34 "row_number" => 2,
35 "col_number" => 3,
36 "rep_number" => 1,
37 "is_a_control" => 1,
38 "seedlot_name" => "seedlot1",
39 "seedlot_stock_id" => 3456,
40 "num_seed_per_plot" => 12,
41 "seed_transaction_operator" => "janedoe",
42 "plant_names" => ["plant1", "plant2"],
43 "plant_ids" => [3456, 3457],
44 "plot_geo_json" => {}
48 If experiment_type is genotyping_layout, get_design returns a hash representing
49 all wells in a plate, with the tissue_sample name in each well and its accession.
50 The return is a HashRef of HashRef where the keys are the well number such as:
53 'A01' => {
54 "plot_name" => "mytissuesample_A01",
55 "stock_name" => "accession1",
56 "plot_number" => "A01",
57 "row_number" => "A",
58 "col_number" => "1",
59 "is_blank" => 0,
60 "concentration" => "2",
61 "volume" => "4",
62 "dna_person" => "nmorales",
63 "acquisition_date" => "2018/01/09",
64 "tissue_type" => "leaf",
65 "extraction" => "ctab",
66 "ncbi_taxonomy_id" => "1001",
67 "source_observation_unit_name" => "plant1",
68 "source_observation_unit_id" => "9091"
72 By using get_design(), this module attempts to get the design from a
73 projectprop called 'trial_layout_json', but if it cannot be found it calls
74 generate_and_cache_layout() to generate the design, return it, and store it
75 using that projectprop.
77 --------------------------------------------------------------------------
79 This can also be used the verify that a layout has a physical map covering all
80 plots, as well as verifying that the relationships between entities are valid
81 by doing:
83 my $trial_layout = CXGN::Trial::TrialLayout->new({
84 schema => $schema,
85 trial_id => $c->stash->{trial_id},
86 experiment_type => $experiment_type, #Either 'field_layout' or 'genotyping_layout'
87 verify_layout=>1,
88 verify_physical_map=>1
89 });
90 my $trial_errors = $trial_layout->generate_and_cache_layout();
92 If there are errors, $trial_errors is a HashRef like:
95 "errors" =>
97 "layout_errors" => [ "the accession between plot 1 and seedlot 1 is out of sync", "the accession between plot 1 and plant 1 is out of sync" ],
98 "seedlot_errors" => [ "plot1 does not have a seedlot linked" ],
99 "physical_map_errors" => [ "plot 1 does not have a row_number", "plot 1 does not have a col_number"]
103 =head1 DESCRIPTION
106 =head1 AUTHORS
108 Jeremy D. Edwards (jde22@cornell.edu)
110 =cut
113 # use Moose;
114 # use MooseX::FollowPBP;
115 # use Moose::Util::TypeConstraints;
116 # use Try::Tiny;
117 # use CXGN::Stock::StockLookup;
118 # use CXGN::Location::LocationLookup;
119 # use Data::Dumper;
120 # use SGN::Model::Cvterm;
121 # use CXGN::Chado::Stock;
122 # use JSON;
124 use CXGN::Trial::TrialLayoutFactory;
127 # has 'schema' => (
128 # is => 'rw',
129 # isa => 'DBIx::Class::Schema',
130 # required => 1,
131 # );
133 # has 'trial_id' => (
134 # isa => 'Int',
135 # is => 'rw',
136 # predicate => 'has_trial_id',
137 # trigger => \&_lookup_trial_id,
138 # required => 1
139 # );
141 # has 'experiment_type' => (
142 # is => 'rw',
143 # isa => 'Str', #field_layout or genotyping_layout
144 # required => 1,
145 # );
150 sub new {
151 my $class = shift;
153 my $args = shift;
155 my $factory = CXGN::Trial::TrialLayoutFactory->new();
157 my $object = $factory->create( $args );
159 return $object;