5 LinkPlantEntriesToProject.pm
9 mx-run FixTrialTypes [options] -H hostname -D dbname -u username [-F]
11 this is a subclass of L<CXGN::Metadata::Dbpatch>
12 see the perldoc of parent class for more details.
16 This patch updates the way that plant entries were being created and stored. Previously, plant entries were not linked directly to the project they are in. This made uploading of phenotypes slow because of additional searches to go from plant to plot to project. Now the connnection of plant to project is available.
20 Nicolas Morales<nm529@cornell.edu>
22 =head1 COPYRIGHT & LICENSE
24 Copyright 2010 Boyce Thompson Institute for Plant Research
26 This program is free software; you can redistribute it and/or modify
27 it under the same terms as Perl itself.
32 package LinkPlantEntriesToProject
;
35 use Bio
::Chado
::Schema
;
37 extends
'CXGN::Metadata::Dbpatch';
38 use SGN
::Model
::Cvterm
;
40 has
'+description' => ( default => <<'' );
41 This patch updates the way that plant entries were being created
and stored
. Previously
, plant entries were
not linked directly to the project they are
in. This made uploading of phenotypes slow because of additional searches to go from plant to plot to project
. Now the connnection of plant to project is available
.
46 print STDOUT
"Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
48 print STDOUT
"\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
50 print STDOUT
"\nExecuting the SQL commands.\n";
52 my $schema = Bio
::Chado
::Schema
->connect( sub { $self->dbh->clone } );
56 my $field_layout_cvterm = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'field_layout', 'experiment_type')->cvterm_id();
57 my $plot_of_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'plant_of', 'stock_relationship')->cvterm_id();
59 my $plots_of_plants = $schema->resultset("Stock::StockRelationship")->search({ type_id
=>$plot_of_cvterm_id });
61 while (my $p = $plots_of_plants->next() ) {
62 #Get project of plant from plot
63 my $plant = $p->object();
64 my $plot_of_plant = $p->subject();
65 my $field_layout_experiment = $plot_of_plant
66 ->search_related('nd_experiment_stocks')
67 ->search_related('nd_experiment')
68 ->find({'type.cvterm_id' => $field_layout_cvterm },
70 my $project = $field_layout_experiment->nd_experiment_projects->single ; #there should be one project linked with the field experiment
71 my $project_id = $project->project_id;
73 #store nd_experiment_stock entry in same way as it is done when plant entries are created now.
74 $field_layout_experiment = $schema->resultset("Project::Project")->search( { 'me.project_id' => $project_id }, {select=>['nd_experiment.nd_experiment_id']})->search_related('nd_experiment_projects')->search_related('nd_experiment', { type_id
=> $field_layout_cvterm })->single();
75 my $plant_nd_experiment_stock = $schema->resultset("NaturalDiversity::NdExperimentStock")->create({
76 nd_experiment_id
=> $field_layout_experiment->nd_experiment_id(),
77 type_id
=> $field_layout_cvterm,
78 stock_id
=> $plant->stock_id(),
84 $schema->txn_do($coderef);
86 die "Patch failed! Transaction exited." . $_ . "\n" ;
89 print "You're done!\n";