6 UpdateOrganismSynonymCvterms
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.
17 This patch moves all organismprops of cvterm type "synonym" to a "organism_synonym" cvterm, "orgnaism_property" cv,
18 and "autocreated:organism_synonym" dbxref.
19 This is done to eliminate redundant usage of synonym-like cvterms loaded in the different databases
20 using different cv terms (null, local, stock_property), making the cvterm name for organism synonyms more explicit:
21 "orgnaism_synonym" instead of "synonym"
22 This also solves a potential conflict with the unique constraint in the dbxref table, since using the cvterm name "synonym"
23 causes creating a dbxref.accession of "autocreated:synonym" when creating properties using BCS create_stockprops function.
24 The same accession will be attempted to be created when autocreating another property with the name "synonym", e.g.
25 create_stockprops (stock_synonym is take care of in db_patch UpdateStockSynonymCvterms )
27 This subclass uses L<Moose>. The parent class uses L<MooseX::Runnable>
31 Naama Menda<nm249@cornell.edu>
33 =head1 COPYRIGHT & LICENSE
35 Copyright 2010 Boyce Thompson Institute for Plant Research
37 This program is free software; you can redistribute it and/or modify
38 it under the same terms as Perl itself.
43 package UpdateOrganismSynonymCvterms
;
46 use Bio
::Chado
::Schema
;
49 extends
'CXGN::Metadata::Dbpatch';
52 has
'+description' => ( default => <<'' );
53 This patch will find_or_create a cvterm name organism_synonym
54 with cv of organism_property
and dbxref of autocreated
:organism_synonym
55 Then all organismprops of type_id matching the word synonym will be associated with
56 the organism_synonym cvterm
57 this is important
for making organism synonyms unified across the different databases
and eliminating redundancy of cvterms with name
= synonym
68 print STDOUT
"Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
70 print STDOUT
"\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
72 print STDOUT
"\nExecuting the SQL commands.\n";
73 my $schema = Bio
::Chado
::Schema
->connect( sub { $self->dbh->clone } );
76 #find or create cvterm with name organism_synonym
77 #make sure it has a dbxref of autocreated:organism_synonym and db = null
78 ##there might be an existing dbxref with accession = autocreated:synonym
79 #we will not be using that one anymore for distincting between synonyms of different entities.
82 my $organism_synonym_cvterm = $schema->resultset("Cv::Cvterm")->create_with( {
83 name
=> 'organism_synonym',
84 cv
=> 'organism_property', }
87 my $organism_synonym_cvterm_id = $organism_synonym_cvterm->cvterm_id;
88 print "***organism_synonym_cvterm_id is $organism_synonym_cvterm_id \n";
89 #find all organismprops that have a type_id ilike %synonym%' and change it to the
90 #organism_synonym cvterm
91 # delete the cvterm of name = synonym and cv name = "local" or "null"
93 my $organismprops = $schema->resultset("Organism::Organismprop")->search(
95 'type.name' => { ilike
=> '%synonym%' },
102 print "** found " . $organismprops->count . " organismprops \n\n";
103 print "**Changing cvterm name of organism synonyms to organism_synonym , cv= organism_property ";
104 $organismprops->update( { type_id
=> $organism_synonym_cvterm_id } ) ;
107 print "Trial mode! Rolling back transaction\n\n";
108 $schema->txn_rollback;
115 $schema->txn_do($coderef);
118 die "Load failed! " . $_ . "\n" ;
122 print "You're done!\n";