4 delete_trials.pl - script to delete trials
8 perl delete_trials.pl -i trial_id -H host -D dbname -U dbuser -P dbpass -b basepath -r temp_file_nd_experiment_id
10 Deletes trials that whose ids are provided as a comma separated list for the -i parameter.
11 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!
15 Lukas Mueller <lam87@cornell.edu>
22 use Bio
::Chado
::Schema
;
23 use CXGN
::Metadata
::Schema
;
24 use CXGN
::Phenome
::Schema
;
25 use CXGN
::DB
::InsertDBH
;
28 our ($opt_H, $opt_D, $opt_U, $opt_P, $opt_b, $opt_i, $opt_n, $opt_t, $opt_r);
30 getopts
('H:D:U:P:b:i:t:r:n');
36 my $trial_ids = $opt_i;
37 my $trial_names = $opt_t;
38 my $non_interactive = $opt_n;
40 my $dbh = CXGN
::DB
::InsertDBH
->new( { dbhost
=>$dbhost,
42 dbargs
=> {AutoCommit
=> 0,
47 print STDERR
"Connecting to database...\n";
48 my $schema= Bio
::Chado
::Schema
->connect( sub { $dbh->get_actual_dbh() } );
49 my $metadata_schema = CXGN
::Metadata
::Schema
->connect( sub { $dbh->get_actual_dbh() });
50 my $phenome_schema = CXGN
::Phenome
::Schema
->connect( sub { $dbh->get_actual_dbh() });
52 my @trial_ids = split ",", $trial_ids;
53 my @trial_names = split ",", $trial_names;
55 foreach my $name (@trial_names) {
56 my $trial = $schema->resultset("Project::Project")->find( { name
=> $name });
57 if (!$trial) { print STDERR
"Trial $name not found. Skipping...\n"; next; }
58 push @trial_ids, $trial->project_id();
61 foreach my $trial_id (@trial_ids) {
62 print STDERR
"Retrieving trial information for trial $trial_id...\n";
64 my $t = CXGN
::Trial
->new({
65 bcs_schema
=> $schema,
66 metadata_schema
=> $metadata_schema,
67 phenome_schema
=> $phenome_schema,
72 if (!$non_interactive) {
73 print $t->get_name().", ".$t->get_description().". Delete? ";
76 if ($non_interactive || $answer =~ m/^y/i) {
78 delete_trial
($metadata_schema, $phenome_schema, $t);
81 print STDERR
"An error occurred trying to delete trial ".$t->get_name()." ($@)\n";
86 print STDERR
"Trial ".$t->get_name()." successfully deleted\n";
94 print STDERR
"Done with everything (though nd_experiment entry deletion may still be occuring asynchronously).\n";
97 my $metadata_schema = shift;
98 my $phenome_schema = shift;
101 print STDERR
"Deleting trial ".$t->get_name()."\n";
102 print STDERR
"Delete metadata...\n";
103 $t->delete_metadata();
104 print STDERR
"Deleting phenotypes...\n";
105 $t->delete_phenotype_data($opt_b, $dbhost, $dbname, $dbuser, $dbpass, $opt_r);
106 print STDERR
"Deleting layout...\n";
107 $t->delete_field_layout();
108 print STDERR
"Delete project entry...\n";
109 $t->delete_project_entry();