Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eliminate spurious errors after merge_stocks.pl script run #4846

Merged
merged 5 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions bin/merge_stocks.pl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ =head1 DESCRIPTION
-H the database host
-D the database name
-x flag; if present, delete the empty remaining accession
-P password
mergefile.txt: A tab-separated file with two columns. Include the following header as the first line: bad name good name
Expand All @@ -32,13 +33,16 @@ =head1 AUTHOR
use CXGN::Stock;


our($opt_H, $opt_D, $opt_x);
getopts('H:D:x');
our($opt_H, $opt_D, $opt_x, $opt_P);
getopts('H:D:xP:');

my $pw = $opt_P;

print "Password for $opt_H / $opt_D: \n";
my $pw = (<STDIN>);
chomp($pw);
if (! $pw) {
print "Password for $opt_H / $opt_D: \n";
$pw = (<STDIN>);
chomp($pw);
}

my $delete_merged_stock = $opt_x;

Expand Down
1 change: 1 addition & 0 deletions lib/CXGN/Stock.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2092,6 +2092,7 @@ sub merge {
Other stock deleted: $other_stock_deleted.
COUNTS

return undef;
}

=head2 delete
Expand Down
3 changes: 3 additions & 0 deletions t/data/scripts/merge_stocks_test_file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bad name good name
merge_candidate test_accession4

55 changes: 55 additions & 0 deletions t/unit_fixture/scripts/merge_stocks.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

use strict;

use Data::Dumper;
use Test::More;
use lib 't/lib';
use SGN::Test::Fixture;
use File::Temp qw | tempfile |;

my $f = SGN::Test::Fixture->new();

my $file = "t/data/scripts/merge_stocks_test_file.txt";

print STDERR "adding merge candidate accession to db...\n";

my $q = "INSERT INTO stock (organism_id, name, uniquename, type_id) values ((SELECT organism_id FROM organism where species ilike 'Solanum lycopersicum'), 'merge_candidate', 'merge_candidate', (SELECT cvterm_id FROM cvterm where name ='accession'))";

my $h = $f->dbh()->prepare($q);

$h->execute();

print STDERR "Running merge script...\n";

my ($fh, $temp_file) = tempfile( "merge_test_stderr_XXXXX", DIR => "/tmp" );
my $dbhost = $f->config->{dbhost};
my $dbname = $f->config->{dbname};
my $dbpass = $f->config->{dbpass};

my $cmd_line = "perl bin/merge_stocks.pl -H $dbhost -D $dbname -x -P $dbpass $file 2> $temp_file";

print STDERR "$cmd_line\n";

my @out = `$cmd_line\n`;

open(my $F, "<", $temp_file) || die "Can't open file $temp_file\n";
my @lines = <$F>;
close($F);

ok( grep( /Relationships moved:/, @lines ), "relationships moved presence test");
ok( grep( /Stock props: 0/, @lines), "stock props 0 test");
ok( grep( /Added old name as synonym: 1/, @lines), "added old name as synonym");

my $q2 = "SELECT * FROM stock where uniquename = 'merge_candidate'";
my $h2 = $f->dbh()->prepare($q2);
$h2->execute();
my $results = $h2->fetchall_arrayref();

print STDERR "RESULTS: ".Dumper($results);
ok(! scalar(@$results), "check that merge_candidate disappeared by merge");

$f->clean_up_db();

done_testing();

print STDERR "Done.\n";
Loading