4 delete_trials.pl - script to delete trials
8 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 ]
24 comma separated list of trial ids
28 comma separated list of trial names
32 basebath is the install path of the software, most commonly /home/production/cxgn/sgn which is the default.
36 Specifies the temp file used to track nd_experiment_ids to delete. Defaults to /tmp/temp_nd_experiment_id_[date_and_time].
40 a file with trial names, one per line
44 file with trial ids, one per line
48 non-interactive mode. Will not prompt for confirmation of each trial to delete
52 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!
56 Lukas Mueller <lam87@cornell.edu>
64 use Bio
::Chado
::Schema
;
65 use CXGN
::Metadata
::Schema
;
66 use CXGN
::Phenome
::Schema
;
67 use CXGN
::DB
::InsertDBH
;
70 our ($opt_H, $opt_D, $opt_U, $opt_P, $opt_b, $opt_i, $opt_t, $opt_n, $opt_r, $opt_F, $opt_f);
72 getopts
('H:D:U:P:b:i:t:r:nf:F:');
74 my $dt = DateTime
->now();
75 my $date_string = $dt->ymd()."T".$dt->hms();
80 my $trial_ids = $opt_i;
81 my $trial_names = $opt_t;
82 my $trial_names_file = $opt_F;
83 my $trial_ids_file = $opt_f;
84 my $non_interactive = $opt_n;
85 my $basepath = $opt_b || '/home/production/cxgn/sgn';
86 my $tempfile = $opt_r || "/tmp/temp_nd_experiment_id_$date_string";
88 my $dbh = CXGN
::DB
::InsertDBH
->new( { dbhost
=>$dbhost,
90 dbargs
=> {AutoCommit
=> 0,
95 print STDERR
"Connecting to database...\n";
96 my $schema= Bio
::Chado
::Schema
->connect( sub { $dbh->get_actual_dbh() } );
97 my $metadata_schema = CXGN
::Metadata
::Schema
->connect( sub { $dbh->get_actual_dbh() });
98 my $phenome_schema = CXGN
::Phenome
::Schema
->connect( sub { $dbh->get_actual_dbh() });
100 my @trial_ids = split ",", $trial_ids;
101 my @trial_names = split ",", $trial_names;
103 if ($trial_names_file) {
104 open(my $F, "<", $trial_names_file) || die "Can't open the file $trial_names_file";
107 push @trial_names, $_;
112 if ($trial_ids_file) {
113 open(my $F, "<", $trial_ids_file) || die "Can't open the file $trial_ids_file";
121 foreach my $name (@trial_names) {
122 my $trial = $schema->resultset("Project::Project")->find( { name
=> $name });
123 if (!$trial) { print STDERR
"Trial $name not found. Skipping...\n"; next; }
124 push @trial_ids, $trial->project_id();
127 foreach my $trial_id (@trial_ids) {
128 print STDERR
"Retrieving trial information for trial $trial_id...\n";
130 my $t = CXGN
::Trial
->new({
131 bcs_schema
=> $schema,
132 metadata_schema
=> $metadata_schema,
133 phenome_schema
=> $phenome_schema,
134 trial_id
=> $trial_id
138 if (!$non_interactive) {
139 print $t->get_name().", ".$t->get_description().". Delete? ";
142 if ($non_interactive || $answer =~ m/^y/i) {
144 delete_trial
($metadata_schema, $phenome_schema, $t);
147 print STDERR
"An error occurred trying to delete trial ".$t->get_name()." ($@)\n";
152 print STDERR
"Trial ".$t->get_name()." successfully deleted\n";
160 print STDERR
"Done with everything (though nd_experiment entry deletion may still be occuring asynchronously).\n";
163 my $metadata_schema = shift;
164 my $phenome_schema = shift;
167 print STDERR
"Deleting trial ".$t->get_name()."\n";
168 print STDERR
"Delete metadata...\n";
169 $t->delete_metadata();
170 print STDERR
"Deleting phenotypes...\n";
171 $t->delete_phenotype_data($opt_b, $dbhost, $dbname, $dbuser, $dbpass, $opt_r);
172 print STDERR
"Deleting layout...\n";
173 $t->delete_field_layout();
174 print STDERR
"Delete project entry...\n";
175 $t->delete_project_entry();