Merge branch 'master' into topic/upload_fieldbook_images
[sgn.git] / db / 00052 / AddSystemCvterms.pm
blob799b9c9aa085d96bdd006d90dcea81a554325b0e
1 #!/usr/bin/env perl
4 =head1 NAME
6 AddSystemCvterms
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
17 This patch creates the system cvterms that are needed for the cxgn databases.
18 Without these many pages and functions would not work since we are not using anymore the create_with BCS function for auto-creating new cvterms.
19 Instead all the needed cvterms need to be predefined in the databases.
20 This is important for the functionality and integrity of the databases, and for preventing overloading with redundant or obscure cvterms.
22 This subclass uses L<Moose>. The parent class uses L<MooseX::Runnable>
24 =head1 AUTHOR
26 Naama Menda<nm249@cornell.edu>
28 =head1 COPYRIGHT & LICENSE
30 Copyright 2010 Boyce Thompson Institute for Plant Research
32 This program is free software; you can redistribute it and/or modify
33 it under the same terms as Perl itself.
35 =cut
38 package AddSystemCvterms;
40 use Moose;
41 use Try::Tiny;
42 use Bio::Chado::Schema;
44 extends 'CXGN::Metadata::Dbpatch';
47 has '+description' => ( default => <<'' );
48 This patch will add system cvterms required for the functionality of the cxgn databases
50 has '+prereq' => (
51 default => sub {
52 [],
56 sub patch {
57 my $self=shift;
59 print STDOUT "Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
61 print STDOUT "\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
63 print STDOUT "\nExecuting the SQL commands.\n";
66 my %cvterms =
68 'calendar' => ['Planning Event',
69 'Fertilizer Event',
70 'Genotyping Event',
71 'Harvest Event',
72 'Meeting Event',
73 'Phenotyping Event',
74 'Planting Event',
75 'Presentation Event' ],
77 'experiment_type' => [ 'cross_experiment',
78 'field_layout',
79 'genotyping_experiment',
80 'genotyping_layout',
81 'phenotyping_experiment' ],
82 'genotype_property' => ['igd number',
83 'snp genotyping' ],
85 'local' => ['sp_person_id',
86 'visible_to_role' ],
88 'nd_experiment_property' => [ 'cross_name',
89 'cross_type',
90 'genotyping_project_name',
91 'genotyping_user_id',
92 'number_of_flowers',
93 'number_of_seeds' ],
95 'organism_property' => [ 'organism_synonym' ],
97 'project_property' => [ 'breeding_program',
98 'harvest_date',
99 'planting_date',
100 'trial_folder' ],
102 'project_relationship' => [ 'breeding_program_trial_relationship' ] ,
104 'project_type' => ['Advance Yield Trial',
105 'Preliminary Yield Trial',
106 'Uniform Yield Trial' ],
108 'stock_property' => ['block',
109 'col_number',
110 'igd_synonym',
111 'is a control',
112 'location_code',
113 'organization',
114 'plot number',
115 'range',
116 'replicate',
117 'row_number',
118 'stock_synonym',
119 'T1',
120 'T2',
121 'transgenic' ],
123 'stock_relationship' => [ 'cross_relationship',
124 'female_parent',
125 'male_parent',
126 'member_of',
127 'offspring_of',
128 'plant_of',
129 'plot_of',
130 'tissue_sample_of' ],
132 'stock_type' => ['accession',
133 'backcross population',
134 'cross',
135 'f2 population',
136 'mutant population',
137 'plant',
138 'plot',
139 'population',
140 'tissue_sample',
141 'training population',
142 'vector_construct' ],
144 'trait_property' => [ 'trait_categories',
145 'trait_default_value',
146 'trait_details',
147 'trait_format',
148 'trait_maximum',
149 'trait_minimum' ]
154 my $schema = Bio::Chado::Schema->connect( sub { $self->dbh->clone } );
157 my $coderef = sub {
160 foreach my $cv_name ( keys %cvterms ) {
161 print "\nKEY = $cv_name \n\n";
162 my @cvterm_names = @{$cvterms{ $cv_name } } ;
164 foreach my $cvterm_name ( @cvterm_names ) {
165 print "cvterm= $cvterm_name \n";
166 my $new_cvterm = $schema->resultset("Cv::Cvterm")->create_with(
168 name => $cvterm_name,
169 cv => $cv_name,
175 try {
176 $schema->txn_do($coderef);
178 } catch {
179 die "Load failed! " . $_ . "\n" ;
182 print "You're done!\n";
186 ####
187 1; #
188 ####