2 package CXGN
::Trial
::TrialDesignStore
::SamplingTrial
;
7 BEGIN { extends
'CXGN::Trial::TrialDesignStore::AbstractTrial';}
13 print STDERR
"BUILD CXGN::Trial::TrialDesignStore::AbstractTrial\n";
14 $self->set_nd_experiment_type_id(SGN
::Model
::Cvterm
->get_cvterm_row($self->get_bcs_schema(), 'sampling_layout', 'experiment_type')->cvterm_id());
15 $self->set_stock_type_id($self->get_tissue_sample_cvterm_id);
16 $self->set_stock_relationship_type_id($self->get_tissue_sample_of_cvterm_id);
18 $self->set_source_stock_types([
19 $self->get_accession_cvterm_id,
20 $self->get_plot_cvterm_id,
21 $self->get_plant_cvterm_id,
22 $self->get_tissue_sample_cvterm_id
25 $self->set_valid_properties([
48 print STDERR
"validating design\n";
50 my $chado_schema = $self->get_bcs_schema();
51 my $design_type = $self->get_design_type();
52 my %design = %{$self->get_design};
55 if ($design_type ne 'sampling_trial') {
56 $error .= "design_type not equal to 'sampling_trial'";
60 my @valid_properties = @
{$self->get_valid_properties()};
62 my %allowed_properties = map {$_ => 1} @valid_properties;
65 my %seen_accession_names;
66 foreach my $stock (keys %design){
67 foreach my $property (keys %{$design{$stock}}){
68 if (!exists($allowed_properties{$property})) {
69 $error .= "Property: $property not allowed! ";
71 if ($property eq 'stock_name') {
72 my $stock_name = $design{$stock}->{$property};
73 $seen_accession_names{$stock_name}++;
75 if ($property eq 'plot_name') {
76 my $plot_name = $design{$stock}->{$property};
77 $seen_stock_names{$plot_name}++;
82 my @stock_names = keys %seen_stock_names;
83 my @accession_names = keys %seen_accession_names;
84 if(scalar(@stock_names)<1){
85 $error .= "You cannot create a trial with less than one sample.";
87 if(scalar(@accession_names)<1){
88 $error .= "You cannot create a trial with less than one accession.";
90 my $subplot_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($chado_schema, 'subplot', 'stock_type')->cvterm_id();
91 my $accession_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($chado_schema, 'accession', 'stock_type')->cvterm_id();
92 my $plot_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($chado_schema, 'plot', 'stock_type')->cvterm_id();
93 my $plant_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($chado_schema, 'plant', 'stock_type')->cvterm_id();
94 my $tissue_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($chado_schema, 'tissue_sample', 'stock_type')->cvterm_id();
95 my $stocks = $chado_schema->resultset('Stock::Stock')->search({
96 type_id
=>$tissue_type_id,
97 uniquename
=>{-in=>\
@stock_names}
99 while (my $s = $stocks->next()) {
100 $error .= "Name $s->uniquename already exists in the database.";
103 my @source_stock_types = ($accession_type_id, $plot_type_id, $plant_type_id, $tissue_type_id);
105 my $rs = $chado_schema->resultset('Stock::Stock')->search({
106 'is_obsolete' => { '!=' => 't' },
107 'type_id' => {-in=>\
@source_stock_types},
108 'uniquename' => {-in=>\
@accession_names}
111 while (my $s = $rs->next()) {
112 $found_data{$s->uniquename} = 1;
114 foreach (@accession_names){
115 if (!$found_data{$_}){
116 $error .= "The following name is not in the database: $_ .";