4 merge_stocks.pl - merge stocks using a file with stocks to merge
8 merge_stocks.pl -H [database host] -D [database name] [ -x ] mergefile.txt
14 -x flag; if present, delete the empty remaining accession
16 mergefile.txt: A file with three columns: bad name, good name.
18 All the metadata of bad name will be transferred to good name.
19 If -x is used, stock with name bad name will be deleted.
23 Lukas Mueller <lam87@cornell.edu>
30 use CXGN
::DB
::InsertDBH
;
31 use CXGN
::DB
::Schemas
;
32 use CXGN
::Chado
::Stock
;
34 our($opt_H, $opt_D, $opt_x);
37 my $dbh = CXGN
::DB
::InsertDBH
->new(
44 limit_dialect
=> 'LimitOffset',
48 my $delete_merged_stock = $opt_x;
50 print STDERR
"Note: -x: Deleting stocks that have been merged into other stocks.\n";
52 my $s = CXGN
::DB
::Schemas
->new({ dbh
=> $dbh });
53 my $schema = $s->bcs_schema();
56 open(my $F, "<", $file) || die "Can't open file $file.\n";
63 my ($merge_stock_name, $good_stock_name) = split /\t/;
65 my $stock_row = $schema->resultset("Stock::Stock")->find( { uniquename
=> { ilike
=> $good_stock_name } });
67 print STDERR
"Stock $good_stock_name not found. Skipping...\n";
72 my $merge_row = $schema->resultset("Stock::Stock")->find( { uniquename
=> { ilike
=> $merge_stock_name } });
74 print STDERR
"Stock $merge_stock_name not available for merging. Skipping\n";
78 my $good_stock = CXGN
::Chado
::Stock
->new($schema, $stock_row->stock_id);
79 my $merge_stock = CXGN
::Chado
::Stock
->new($schema, $merge_row->stock_id);
81 print STDERR
"Merging stock $merge_stock_name into $good_stock_name... ";
82 $good_stock->merge($merge_stock->get_stock_id(), $delete_merged_stock);
83 print STDERR
"Done.\n";
88 print STDERR
"An ERROR occurred ($@). Rolling back changes...\n";
92 print STDERR
"Script is done. Committing... ";
94 print STDERR
"Done.\n";