4 delete_trials.pl - script to delete trials
8 perl delete_trials.pl -i trial_id -H host -D dbname
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_i, $opt_n, $opt_t);
34 my $trial_ids = $opt_i;
35 my $trial_names = $opt_t;
36 my $non_interactive = $opt_n;
38 my $dbh = CXGN
::DB
::InsertDBH
->new( { dbhost
=>$dbhost,
40 dbargs
=> {AutoCommit
=> 0,
45 print STDERR
"Connecting to database...\n";
46 my $schema= Bio
::Chado
::Schema
->connect( sub { $dbh->get_actual_dbh() } );
47 my $metadata_schema = CXGN
::Metadata
::Schema
->connect( sub { $dbh->get_actual_dbh() });
48 my $phenome_schema = CXGN
::Phenome
::Schema
->connect( sub { $dbh->get_actual_dbh() });
50 my @trial_ids = split ",", $trial_ids;
51 my @trial_names = split ",", $trial_names;
53 foreach my $name (@trial_names) {
54 my $trial = $schema->resultset("Project::Project")->find( { name
=> $name });
55 if (!$trial) { print STDERR
"Trial $name not found. Skipping...\n"; next; }
56 push @trial_ids, $trial->project_id();
59 foreach my $trial_id (@trial_ids) {
60 print STDERR
"Retrieving trial information for trial $trial_id...\n";
62 my $t = CXGN
::Trial
->new( { bcs_schema
=> $schema , trial_id
=> $trial_id } );
65 if (!$non_interactive) {
66 print $t->get_name().", ".$t->get_description().". Delete? ";
69 if ($non_interactive || $answer =~ m/^y/i) {
71 delete_trial
($metadata_schema, $phenome_schema, $t);
74 print STDERR
"An error occurred trying to delete trial ".$t->get_name()." ($@)\n";
79 print STDERR
"Trial ".$t->get_name()." successfully deleted\n";
87 print STDERR
"Done with everything.\n";
90 my $metadata_schema = shift;
91 my $phenome_schema = shift;
94 print STDERR
"Deleting trial ".$t->get_name()."\n";
95 print STDERR
"Delete metadata...\n";
96 $t->delete_metadata($metadata_schema, $phenome_schema);
97 print STDERR
"Deleting phenotypes...\n";
98 $t->delete_phenotype_data();
99 print STDERR
"Deleting layout...\n";
100 $t->delete_field_layout();
101 print STDERR
"Delete project entry...\n";
102 $t->delete_project_entry();