7 UpdateSnpGenotypeCvterm
11 mx-run ThisPackageName [options] -H hostname -D dbname -u username [-F]
13 this is a subclass of L<CXGN::Metadata::Dbpatch>
14 see the perldoc of parent class for more details.
18 This patch moves all genotypes and genotypeprops of cvterm type "snp genotype" and cv name 'local' , to a "snp genotype" cvterm and genotype_property cv .
19 This is done to eliminate duplicates of snp genotype cvterms loaded previously in the different databases using different cv terms (null, local, genotype_property), making the cvterm name for snp genotype more explicit.
20 This also solves a potential conflict with the unique constraint in the dbxref table, since using the cvterm name "snp genotype" causes creating a dbxref.snp genotype of "autocreated:snp genotype" when creating properties using bio chado schema create_stock function.
21 The same snp genotyping will be attempted to be created when autocreating another property with the name "snp genotype".
23 This subclass uses L<Moose>. The parent class uses L<MooseX::Runnable>
27 Guillaume Bauchet<gjb99@cornell.edu>
29 =head1 COPYRIGHT & LICENSE
31 Copyright 2010 Boyce Thompson Institute for Plant Research
33 This program is free software; you can redistribute it and/or modify
34 it under the same terms as Perl itself.
39 package UpdateSnpGenotypeCvterm
;
42 use Bio
::Chado
::Schema
;
45 extends
'CXGN::Metadata::Dbpatch';
48 has
'+description' => ( default => <<'' );
49 This patch will find_or_create a snp genotyping cvterm
50 with cv of genotype_property
51 Then all genotypes
and genotypeprops of type_id matching the word snp genotyping will be associated with the snp genotyping cvterm
52 this is important
for making the snp genotyping cvterm unified across the different databases
and eliminating redundancy
63 print STDOUT
"Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
65 print STDOUT
"\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
67 print STDOUT
"\nExecuting the SQL commands.\n";
68 my $schema = Bio
::Chado
::Schema
->connect( sub { $self->dbh->clone } );
71 #find or create cvterm with snp genotyping name and genotype_property cv
72 ##there might be an existing dbxref with snp genotyping = autocreated:snp genotyping
76 my $snp_genotyping_cvterm = $schema->resultset("Cv::Cvterm")->create_with(
77 { name
=> 'snp genotyping',
78 cv
=> 'genotype_property',
81 my $snp_genotyping_cvterm_id = $snp_genotyping_cvterm->cvterm_id;
82 print "***snp_genotyping_cvterm_id is $snp_genotyping_cvterm_id \n";
85 #find all genotypes and genotypeprops that have a type_id ilike %snp_genotyping%' and change it to the
86 #genotype_property "snp genotyping" cvterm
87 # delete the old cvterm
89 my $genotypeprop_rs = $schema->resultset("Genetic::Genotypeprop")->search(
91 'type.name' => { ilike
=> 'snp%genotyping' },
95 join => {'type' => 'cv' },
99 print "** found " . $genotypeprop_rs->count . " genotypeprops with type_id of 'snp genotyping' and cv.name = 'local' \n\n";
100 print "**Changing genotypeprop.type_id to cvterm.name = 'snp genotyping' , cv= genotype_property ";
101 $genotypeprop_rs->update( { type_id
=> $snp_genotyping_cvterm_id});
104 my $genotype_rs = $schema->resultset("Genetic::Genotype")->search(
106 'type.name' => { ilike
=> 'snp%genotyping' },
110 join => { 'type' => 'cv' },
114 print "** found " . $genotype_rs->count . " genotypes with type_id of 'snp genotyping' and cv.name = 'local' \n\n";
115 print "**Changing genotype.type_id to cvterm.name = 'snp genotyping' , cv= genotype_property ";
116 $genotype_rs->update( { type_id
=> $snp_genotyping_cvterm_id });
120 my $old_cvterm = $schema->resultset("Cv::Cvterm")->search(
122 'me.name' => 'snp genotyping',
123 'cv.name' => 'local' ,
130 $old_cvterm->delete();
134 print "Trial mode! Rolling back transaction\n\n";
135 $schema->txn_rollback;
142 $schema->txn_do($coderef);
145 die "Load failed! " . $_ . "\n" ;
149 print "You're done!\n";