4 CXGN::Genotype::GenotypingProject - an object representing a genotyping project in the database
8 my $genotyping_project = CXGN::Genotype::GenotypingProject->new( { schema => $schema, trial_id => 37347 });
18 package CXGN
::Genotype
::GenotypingProject
;
21 use SGN
::Model
::Cvterm
;
24 use CXGN
::Trial
::Search
;
27 use CXGN
::Trial
::TrialLayout
;
30 isa
=> 'Bio::Chado::Schema',
41 has
'project_facility' => (isa
=> 'Str',
46 has
'project_and_plate_relationship_cvterm_id' => (
51 has
'genotyping_plate_list' => (
52 isa
=> 'ArrayRef[Int]|Undef',
56 has
'new_genotyping_plate_list' => (
57 isa
=> 'ArrayRef[Int]|Undef',
64 my $schema = $self->bcs_schema();
65 my $genotyping_project_id = $self->project_id();
67 my $genotyping_project = CXGN
::Trial
->new( { bcs_schema
=> $schema, trial_id
=> $genotyping_project_id });
68 my $project_facility = $genotyping_project->get_genotyping_facility();
70 my $genotyping_project_relationship_cvterm = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'genotyping_project_and_plate_relationship', 'project_relationship');
71 my $project_and_plate_relationship_cvterm_id = $genotyping_project_relationship_cvterm->cvterm_id();
72 my $relationships_rs = $schema->resultset("Project::ProjectRelationship")->search ({
73 object_project_id
=> $genotyping_project_id,
74 type_id
=> $project_and_plate_relationship_cvterm_id
78 if ($relationships_rs) {
79 while (my $each_relationship = $relationships_rs->next()) {
80 push @plate_list, $each_relationship->subject_project_id();
83 $self->project_facility($project_facility);
84 $self->project_and_plate_relationship_cvterm_id($project_and_plate_relationship_cvterm_id);
85 $self->genotyping_plate_list(\
@plate_list);
90 sub get_genotyping_plate_ids
{
92 my $plate_list = $self->genotyping_plate_list();
97 sub validate_relationship
{
99 my $schema = $self->bcs_schema();
100 my $new_plate_ids = $self->new_genotyping_plate_list();
101 my $genotyping_project_id = $self->project_id();
102 my $project_facility = $self->project_facility();
103 my @plate_ids = @
$new_plate_ids;
104 my @genotyping_plate_errors;
106 foreach my $plate_id (@plate_ids) {
107 my $genotyping_plate = CXGN
::Trial
->new( { bcs_schema
=> $schema, trial_id
=> $plate_id });
108 my $plate_facility = $genotyping_plate->get_genotyping_facility();
110 if (($plate_facility ne 'None') && ($project_facility ne 'None')) {
111 if ($plate_facility ne $project_facility) {
112 my $genotyping_plate_name = $genotyping_plate->get_name();
113 push @genotyping_plate_errors, $genotyping_plate_name;
118 return {error_messages
=> \
@genotyping_plate_errors}
122 sub set_project_for_genotyping_plate
{
124 my $schema = $self->bcs_schema();
125 my $genotyping_project_id = $self->project_id();
126 my $new_genotyping_plate_list = $self->new_genotyping_plate_list();
127 my @new_genotyping_plates = @
$new_genotyping_plate_list;
128 my $transaction_error;
132 foreach my $plate_id (@new_genotyping_plates) {
133 my $relationship_rs = $schema->resultset("Project::ProjectRelationship")->find ({
134 subject_project_id
=> $plate_id,
135 type_id
=> $self->project_and_plate_relationship_cvterm_id()
138 if($relationship_rs){
139 print STDERR
"UPDATING...."."\n";
140 $relationship_rs->object_project_id($genotyping_project_id);
141 $relationship_rs->update();
143 $relationship_rs = $schema->resultset('Project::ProjectRelationship')->create({
144 object_project_id
=> $genotyping_project_id,
145 subject_project_id
=> $plate_id,
146 type_id
=> $self->project_and_plate_relationship_cvterm_id()
148 $relationship_rs->insert();
154 $schema->txn_do($coderef);
156 $transaction_error = $_;
159 if ($transaction_error) {
160 print STDERR
"Transaction error associating genotyping plate: $transaction_error\n";
171 my $schema = $self->bcs_schema();
172 my $plate_list = $self->genotyping_plate_list();
173 my $number_of_plates = scalar (@
$plate_list);
177 my $number_of_samples;
178 if ($number_of_plates > 0) {
179 my $trial_search = CXGN
::Trial
::Search
->new({
180 bcs_schema
=> $schema,
181 trial_design_list
=> ['genotyping_plate'],
182 trial_id_list
=> $plate_list
184 ($data, $total_count) = $trial_search->search();
186 foreach my $plate (@
$data){
187 my $plate_layout = CXGN
::Trial
::TrialLayout
->new({schema
=> $schema, trial_id
=> $plate->{trial_id
}, experiment_type
=> 'genotyping_layout'});
188 my $sample_names = $plate_layout->get_plot_names();
189 my $number_of_samples = '';
191 $number_of_samples = scalar(@
{$sample_names});
195 plate_id
=> $plate->{trial_id
},
196 plate_name
=> $plate->{trial_name
},
197 plate_description
=> $plate->{description
},
198 plate_format
=> $plate->{genotyping_plate_format
},
199 sample_type
=> $plate->{genotyping_plate_sample_type
},
200 number_of_samples
=> $number_of_samples,
205 return (\
@all_plates, $number_of_plates);
210 sub get_associated_protocol
{
212 my $schema = $self->bcs_schema();
213 my $genotyping_project_id = $self->project_id();
215 my $q = "SELECT DISTINCT nd_protocol.nd_protocol_id, nd_protocol.name
216 FROM nd_experiment_project
217 JOIN nd_experiment_genotype ON (nd_experiment_project.nd_experiment_id = nd_experiment_genotype.nd_experiment_id)
218 JOIN nd_experiment_protocol ON (nd_experiment_project.nd_experiment_id = nd_experiment_protocol.nd_experiment_id)
219 JOIN nd_protocol ON (nd_experiment_protocol.nd_protocol_id = nd_protocol.nd_protocol_id)
220 WHERE nd_experiment_project.project_id = ?";
222 my $h = $schema->storage->dbh()->prepare($q);
223 $h->execute($genotyping_project_id);
225 my @associated_protocol = ();
226 while (my ($protocol_id, $protocol_name) = $h->fetchrow_array()){
227 push @associated_protocol, [$protocol_id, $protocol_name]
230 return \
@associated_protocol;