6 UpdateStockSynonymCvterms
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 stockprops of cvterm type "synonym" to a "stock_synonym" cvterm, "stock_property" cv , and "autocreated:stock_synonym" dbxref.
18 This is done to eliminate redundant usage of synonym-like cvterms loaded in the different databases using different cv terms (null, local, stock_property), making the cvterm name for stock synonyms more explicit: "stock_synonym" instead of "synonym" which may be used for other CVs such as organism_property.
19 This also solves a potential conflict with the unique constraint in the dbxref table, since using the cvterm name "synonym" causes creating a dbxref.accession of "autocreated:synonym" when creating properties using BCS create_stockprops function. The same accession will be attempted to be created when autocreating another property with the name "synonym", e.g. create_organismprop (organism_synonym will be taken care of in another db_patch)
21 This subclass uses L<Moose>. The parent class uses L<MooseX::Runnable>
25 Naama Menda<nm249@cornell.edu>
27 =head1 COPYRIGHT & LICENSE
29 Copyright 2010 Boyce Thompson Institute for Plant Research
31 This program is free software; you can redistribute it and/or modify
32 it under the same terms as Perl itself.
37 package UpdateStockSynonymCvterms
;
40 use Bio
::Chado
::Schema
;
43 extends
'CXGN::Metadata::Dbpatch';
46 has
'+description' => ( default => <<'' );
47 This patch will find_or_create a cvterm name stock_synonym
48 with cv of stock_property
and dbxref of autocreated
:stock_synonym
49 Then all stockprop of type_id matching the word synonym will be associated with
50 the stock_synonym cvterm
51 this is important
for making stock synonyms unified across the different databases
and eliminating redundancy of cvterms with name
= synonym
62 print STDOUT
"Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
64 print STDOUT
"\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
66 print STDOUT
"\nExecuting the SQL commands.\n";
67 my $schema = Bio
::Chado
::Schema
->connect( sub { $self->dbh->clone } );
70 #find or create cvterm with name stock_synonym
71 #make sure it has a dbxref of autocreated:stock_synonym and db = null
72 ##there might be an existing dbxref with accession = autocreated:synonym
73 #we will not be using that one anymore for distincting between synonyms of different entities.
76 my $stock_synonym_cvterm = $schema->resultset("Cv::Cvterm")->create_with( {
77 name
=> 'stock_synonym',
78 cv
=> 'stock_property', }
81 my $stock_synonym_cvterm_id = $stock_synonym_cvterm->cvterm_id;
82 print "***stock_synonym_cvterm_id is $stock_synonym_cvterm_id \n";
83 #find all stockprops that have a type_id ilike %synonym%' and change it to the
85 # delete the cvterm of name = synonym and cv name = "local" or "null"
87 my $stockprops = $schema->resultset("Stock::Stockprop")->search(
89 'type.name' => { ilike
=> 'synonym%' },
96 print "** found " . $stockprops->count . " stockprops \n\n";
97 print "**Changing cvterm name of stock synonyms to stock_synonym , cv= stock_property ";
98 $stockprops->update( { type_id
=> $stock_synonym_cvterm_id } ) ;
101 print "Trial mode! Rolling back transaction\n\n";
102 $schema->txn_rollback;
109 $schema->txn_do($coderef);
112 die "Load failed! " . $_ . "\n" ;
116 print "You're done!\n";