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 stock_relationship rows with type_id of "members of" to a "member_of" cvterm, cv , and name dbxref.
19 This is done to eliminate duplicates of members of cvterms loaded previously in the different databases from the load_genotypes.pl loading script.
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 UpdateMembersOf
;
42 use Bio
::Chado
::Schema
;
45 extends
'CXGN::Metadata::Dbpatch';
48 has
'+description' => ( default => <<'' );
49 This patch will find_or_create a member_of cvterm
50 with cv of stock_relationship
51 Then all stock_relationship rows of type_id matching the word members of will be associated with the member_of cvterm
52 this is important
for making stock_relationship member_of term unified across the different databases
and eliminating redundancy
56 [ 'UnderlineCvNames' ],
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 members of name and cv
72 #make sure it has db = null
73 ##there might be an existing dbxref with members of = autocreated:members of
77 my $member_of_cvterm = $schema->resultset("Cv::Cvterm")->create_with(
78 { name
=> 'member_of',
79 cv
=> 'stock_relationship',
82 my $member_of_cvterm_id = $member_of_cvterm->cvterm_id;
83 print "***member_of_cvterm_id is $member_of_cvterm_id \n";
86 #find all stock_relationship rows that have a type_id ilike %members of%' and change it to the
87 #stock_relationship member of cvterm
88 # delete the old cvterm 'members of' that was created by the load_genotypes.pl script
90 my $stock_rel_rs = $schema->resultset("Stock::StockRelationship")->search(
92 'type.name' => { ilike
=> 'members of%' },
99 print "** found " . $stock_rel_rs->count . " stock_relationship rows \n\n";
100 print "**Changing type_id to cvterm_id of member_of, cv= stock_relationship \n";
101 $stock_rel_rs->update( { type_id
=> $member_of_cvterm_id});
103 my $old_cvterm_rs = $schema->resultset("Cv::Cvterm")->search(
105 'me.name' => 'members of',
106 'cv.name' => 'stock_relationship' ,
112 print "Found . " . $old_cvterm_rs->count . " cvterm(s) with name = 'members of' \n\n";
113 if ($old_cvterm_rs->count ) {
114 print "Found cvterm_id for term 'members of' = " . $old_cvterm_rs->first->cvterm_id . "\n DELETING...\n";
115 $old_cvterm_rs->delete();
117 print "nothing to delete here \n\n";
121 print "Trial mode! Rolling back transaction\n\n";
122 $schema->txn_rollback;
130 $schema->txn_do($coderef);
133 die "Load failed! " . $_ . "\n" ;
137 print "You're done!\n";