-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modified a trial script to add more trials in bulk
- Loading branch information
Showing
1 changed file
with
14 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,11 @@ | |
|
||
=head1 NAME | ||
rename_stocks.pl - a script for renaming stocks | ||
rename_trials.pl - a script for renaming trials | ||
=head1 SYNOPSIS | ||
rename_stocks.pl -H [dbhost] -D [dbname] -i [infile] | ||
rename_trials.pl -H [dbhost] -D [dbname] -i [infile] | ||
=head2 Command-line options | ||
|
@@ -40,9 +40,9 @@ =head2 Command-line options | |
=head1 DESCRIPTION | ||
This script renames stocks in bulk using an xls and xlsx files as input with two columns: the first column is the stock uniquename as it is in the database, and in the second column is the new stock uniquename. There is no header line. Both stock.name and stock.uniquename fields will be changed to the new name. | ||
This script renames trials in bulk using an xls and xlsx files as input with two columns: the first column is the old projectname as it is in the database, and in the second column is the new projectname. There is no header line. Both stock.name and stock.projectname fields will be changed to the new name. | ||
The oldname will be stored as a synonym unless option -n is given. | ||
#The oldname will be stored as a synonym unless option -n is given. | ||
=head1 AUTHORS | ||
|
@@ -54,6 +54,8 @@ =head1 AUTHORS | |
Nicolas Morales ([email protected]) | ||
Srikanth Kumar K ([email protected]) | ||
=cut | ||
|
||
use strict; | ||
|
@@ -110,39 +112,22 @@ =head1 AUTHORS | |
my ( $row_min, $row_max ) = $worksheet->row_range(); | ||
my ( $col_min, $col_max ) = $worksheet->col_range(); | ||
|
||
my $stock_type_row = $schema->resultset("Cv::Cvterm")->find( { name => $stock_type }); | ||
|
||
if (! $stock_type_row) { die "The stock type $stock_type is not in the database."; } | ||
|
||
my $stock_type_id = $stock_type_row->cvterm_id(); | ||
|
||
my $coderef = sub { | ||
for my $row ( 0 .. $row_max ) { | ||
|
||
my $db_uniquename = $worksheet->get_cell($row,0)->value(); | ||
my $new_uniquename = $worksheet->get_cell($row,1)->value(); | ||
my $db_projectname = $worksheet->get_cell($row,0)->value(); | ||
my $new_projectname = $worksheet->get_cell($row,1)->value(); | ||
|
||
print STDERR "processing row $row: $db_uniquename -> $new_uniquename\n"; | ||
print STDERR "processing row $row: $db_projectname -> $new_projectname\n"; | ||
|
||
my $old_stock = $schema->resultset('Stock::Stock')->find({ name => $db_uniquename, uniquename => $db_uniquename, type_id => $stock_type_id }); | ||
my $old_project = $schema->resultset('Project::Project')->find({ name => $db_projectname, projectname => $db_projectname }); | ||
|
||
if (!$old_stock) { | ||
print STDERR "Warning! Stock with uniquename $db_uniquename was not found in the database.\n"; | ||
if (!$old_project) { | ||
print STDERR "Warning! Stock with projectname $db_projectname was not found in the database.\n"; | ||
next(); | ||
} | ||
|
||
my $new_stock = $old_stock->update({ name => $new_uniquename, uniquename => $new_uniquename}); | ||
if (! $opt_n) { | ||
print STDERR "Storing old name ($db_uniquename) as synonym or stock with id ".$new_stock->stock_id()." and type_id $synonym_id...\n"; | ||
my $synonym = { value => $db_uniquename, | ||
type_id => $synonym_id, | ||
stock_id => $new_stock->stock_id(), | ||
}; | ||
|
||
print STDERR "find_or_create...\n"; | ||
$schema->resultset('Stock::Stockprop')->find_or_create($synonym); | ||
print STDERR "Done.\n"; | ||
} | ||
my $new_project = $old_project->update({ name => $new_projectname }); | ||
} | ||
}; | ||
|
||
|
@@ -164,4 +149,4 @@ =head1 AUTHORS | |
print STDERR "Everything looks good. Committing.\n"; | ||
$schema->txn_commit(); | ||
print STDERR "Script Complete.\n"; | ||
} | ||
} |