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: first column is ignored, 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 ($line_count, $merge_stock_name, $good_stock_name) = split /\t/;
65 my $stock_row = $schema->resultset("Stock::Stock")->find( { uniquename
=> $good_stock_name });
67 print STDERR
"Stock $good_stock_name not found. Skipping..\n";
71 my $merge_row = $schema->resultset("Stock::Stock")->find( { uniquename
=> $merge_stock_name });
73 print STDERR
"Stock $merge_stock_name not available for merging. Skipping\n";
77 my $good_stock = CXGN
::Chado
::Stock
->new($schema, $stock_row->stock_id);
78 my $merge_stock = CXGN
::Chado
::Stock
->new($schema, $merge_row->stock_id);
80 print STDERR
"Merging stock $merge_stock_name into $good_stock_name... ";
81 $good_stock->merge($merge_stock->get_stock_id(), $delete_merged_stock);
82 print STDERR
"Done.\n";
87 print STDERR
"An ERROR occurred ($@). Rolling back changes...\n";
91 print STDERR
"Script is done. Committing... ";
93 print STDERR
"Done.\n";