add legend
[sgn.git] / db / 00087 / UpdateNdExperimentProperty.pm
blobc1125e18215dcc22a0f55ea258778e1432e1e98b
1 #!/usr/bin/env perl
4 =head1 NAME
6 UpdateNdExperimentProperty.pm
8 =head1 SYNOPSIS
10 mx-run ThisPackageName [options] -H hostname -D dbname -u username [-F]
12 this is a subclass of L<CXGN::Metadata::Dbpatch>
13 see the perldoc of parent class for more details.
15 =head1 DESCRIPTION
16 This patch updates the cvterm "crossing_metadata_json" by changing from cv = "nd_experiment_property" to cv = "stock_property" and removes unused cvterms related to crossing experiments.
17 This subclass uses L<Moose>. The parent class uses L<MooseX::Runnable>
19 =head1 AUTHOR
21 Titima Tantikanjana<tt15@cornell.edu>
23 =head1 COPYRIGHT & LICENSE
25 Copyright 2010 Boyce Thompson Institute for Plant Research
27 This program is free software; you can redistribute it and/or modify
28 it under the same terms as Perl itself.
30 =cut
33 package UpdateNdExperimentProperty;
35 use Moose;
36 use Bio::Chado::Schema;
37 use SGN::Model::Cvterm;
38 use Try::Tiny;
39 extends 'CXGN::Metadata::Dbpatch';
43 has '+description' => ( default => <<'' );
44 This patch updates the cvterm "crossing_metadata_json" by changing from cv = "nd_experiment_property" to cv = "stock_property" and removes unused cvterms related to crossing experiments.
46 has '+prereq' => (
47 default => sub {
48 ['AddCrossingExperimentCvterms', 'AddNewCrossCvterms', 'AddSystemCvterms'],
53 sub patch {
54 my $self=shift;
56 print STDOUT "Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
58 print STDOUT "\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
60 print STDOUT "\nExecuting the SQL commands.\n";
61 my $schema = Bio::Chado::Schema->connect( sub { $self->dbh->clone } );
63 # update crossing_metadata_json cvterm
65 my $crossing_metadata_json_cvterm = $schema->resultset("Cv::Cvterm")->find(
66 { name => 'crossing_metadata_json'});
68 my $stock_property_cv = $schema->resultset("Cv::Cv")->find(
69 { name => 'stock_property'});
71 $crossing_metadata_json_cvterm->update({cv_id => $stock_property_cv->cv_id});
73 # delete unused cvterms related to crossing experiment
75 my $nd_experiment_property_id = $schema->resultset("Cv::Cv")->find(
76 { name => 'nd_experiment_property'})->cv_id();
78 my $cvterm_rs = $schema->resultset("Cv::Cvterm")->search(
79 { cv_id => $nd_experiment_property_id,
81 name => ['date_of_embryo_rescue',
82 'date_of_harvest',
83 'date_of_pollination',
84 'date_of_seed_extraction',
85 'days_from_extraction_to_embryo_rescue',
86 'days_from_harvest_to_extraction',
87 'days_to_maturity',
88 'number_of_embryos_contaminated',
89 'number_of_embryos_germinated',
90 'number_of_embryos_rescued',
91 'number_of_flowers',
92 'number_of_fruits',
93 'number_of_nonviable_seeds',
94 'number_of_seedlings_transplanted',
95 'number_of_seeds',
96 'number_of_seeds_extracted',
97 'number_of_seeds_germinated',
98 'number_of_seeds_planted',
99 'number_of_viable_seeds'],
102 $cvterm_rs->delete_all;
104 print "You're done!\n";
108 ####
109 1; #
110 ####