From 48be73b47c64dd585cf4e89bbce72e294972e997 Mon Sep 17 00:00:00 2001 From: Lukas Mueller Date: Sun, 25 Aug 2024 10:02:56 +0200 Subject: [PATCH] improve the trial script by adding options to read trial names (-F) and trial ids (-f) from a file; tweak POD. --- bin/delete_trials.pl | 74 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 4 deletions(-) diff --git a/bin/delete_trials.pl b/bin/delete_trials.pl index 0771a686c1..169b8b9055 100644 --- a/bin/delete_trials.pl +++ b/bin/delete_trials.pl @@ -5,9 +5,50 @@ delete_trials.pl - script to delete trials =head1 DESCRIPTION -perl delete_trials.pl -i trial_id -H host -D dbname -U dbuser -P dbpass -b basepath -r temp_file_nd_experiment_id +perl delete_trials.pl -i trial_ids [ -t trial_names ] [ -F file_with_trial_names ] [ -f file_with_trial_ids ] -H host -D dbname -U dbuser -P dbpass -b basepath -r temp_file_nd_experiment_id [ -n ] + +Options: + +=over 5 + +=item -H + +hostname for database + +=item -D + +database name + +=item -i + +comma separated list of trial ids + +=item -t + +comma separated list of trial names + +=item -b + +basebath is the install path of the software, most commonly /home/production/cxgn/sgn which is the default. + +=item -r + +Specifies the temp file used to track nd_experiment_ids to delete. Defaults to /tmp/temp_nd_experiment_id_[date_and_time]. + +=item -F + +a file with trial names, one per line + +=item -f + +file with trial ids, one per line + +=item -n + +non-interactive mode. Will not prompt for confirmation of each trial to delete + +=back -Deletes trials that whose ids are provided as a comma separated list for the -i parameter. First, it deletes metadata, then trial layouts, then phenotypes, and finally the trial entry in the project table. All deletes are hard deletes. There is no way of bringing the trial back, except from a backup. So be careful! =head1 AUTHOR @@ -19,23 +60,30 @@ Lukas Mueller use strict; use Getopt::Std; +use DateTime; use Bio::Chado::Schema; use CXGN::Metadata::Schema; use CXGN::Phenome::Schema; use CXGN::DB::InsertDBH; use CXGN::Trial; -our ($opt_H, $opt_D, $opt_U, $opt_P, $opt_b, $opt_i, $opt_n, $opt_t, $opt_r); +our ($opt_H, $opt_D, $opt_U, $opt_P, $opt_b, $opt_i, $opt_t, $opt_n, $opt_r, $opt_F, $opt_f); -getopts('H:D:U:P:b:i:t:r:n'); +getopts('H:D:U:P:b:i:t:r:nf:F:'); +my $dt = DateTime->now(); +my $date_string = $dt->ymd()."T".$dt->hms(); my $dbhost = $opt_H; my $dbname = $opt_D; my $dbuser = $opt_U; my $dbpass = $opt_P; my $trial_ids = $opt_i; my $trial_names = $opt_t; +my $trial_names_file = $opt_F; +my $trial_ids_file = $opt_f; my $non_interactive = $opt_n; +my $basepath = $opt_b || '/home/production/cxgn/sgn'; +my $tempfile = $opt_r || "/tmp/temp_nd_experiment_id_$date_string"; my $dbh = CXGN::DB::InsertDBH->new( { dbhost=>$dbhost, dbname=>$dbname, @@ -52,6 +100,24 @@ my $phenome_schema = CXGN::Phenome::Schema->connect( sub { $dbh->get_actual_dbh( my @trial_ids = split ",", $trial_ids; my @trial_names = split ",", $trial_names; +if ($trial_names_file) { + open(my $F, "<", $trial_names_file) || die "Can't open the file $trial_names_file"; + while (<$F>) { + chomp; + push @trial_names, $_; + } + close($F); +} + +if ($trial_ids_file) { + open(my $F, "<", $trial_ids_file) || die "Can't open the file $trial_ids_file"; + while(<$F>) { + chomp; + push @trial_ids, $_; + } + close($F); +} + foreach my $name (@trial_names) { my $trial = $schema->resultset("Project::Project")->find( { name => $name }); if (!$trial) { print STDERR "Trial $name not found. Skipping...\n"; next; } -- 2.11.4.GIT