5 replace_string_stock_name.pl
9 replace_string_stock_name.pl -H [dbhost] -D [dbname] -f "Ug" -r "UG"
11 =head1 COMMAND-LINE OPTIONS
16 -r replace string with this
23 Jeremy D. Edwards (jde22@cornell.edu)
29 Add support for other spreadsheet formats
38 use Bio
::Chado
::Schema
;
39 use CXGN
::DB
::InsertDBH
;
40 use CXGN
::DB
::Connection
;
44 our ($opt_H, $opt_D, $opt_f, $opt_r);
49 print STDERR
"A script to find and replace strings in stock names\nUsage: replace_string_stock_name.pl -D [database name] -H [database host, e.g., localhost] -f [find string] -r [replace string with this]\n";
53 if (!$opt_D || !$opt_H || !$opt_f ) {
55 die("Exiting: options missing\n");
58 my $dbh = CXGN
::DB
::InsertDBH
62 dbargs
=> {AutoCommit
=> 1,
66 my $chado_schema = Bio
::Chado
::Schema
->connect( sub { $dbh->get_actual_dbh() } );
68 my $rs = $chado_schema->resultset('Stock::Stock')->search({'uniquename' => {ilike
=> $opt_f.'%'}});
71 foreach my $stock ($rs->all()) {
72 print STDERR
"Original name: ".$stock->uniquename()."\n";
75 print STDERR
"\nFound $count accessions\n";
78 foreach my $stock ($rs->all()) {
79 my $stockid = $stock->stock_id();
80 my $uniquename = $stock->uniquename();
81 my $newname = $uniquename;
82 $newname =~ s/^$opt_f/$opt_r/i;
83 print STDERR
"new name: $newname\n";
84 if ($newname ne $uniquename) {
85 print STDERR
"$stockid changing name $uniquename to $newname\n";
86 $stock->uniquename($newname);