4 delete_genotypes.pl - delete genotypes from a breedbase database
8 perl delete_genotypes.pl -H [host] -D [dbname] -t (for testing) file
12 If the -t flag is provided, the changes will be rolled back in the database.
16 Lukas Mueller <lam87@cornell.edu>
23 use Bio
::Chado
::Schema
;
24 use CXGN
::Phenome
::Schema
;
27 our ($opt_H, $opt_D, $opt_t, $opt_p);
32 print "Password for $opt_H / $opt_D: \n";
36 print STDERR
"Connecting to database...\n";
37 my $dsn = 'dbi:Pg:database='.$opt_D.";host=".$opt_H.";port=5432";
39 my $dbh = DBI
->connect($dsn, "postgres", $pw);
41 print STDERR
"Connecting to DBI schema...\n";
42 my $bcs_schema = Bio
::Chado
::Schema
->connect($dsn, "postgres", $pw);
43 my $phenome_schema = CXGN
::Phenome
::Schema
->connect($dsn, "postgres", $pw, { on_connect_do
=> ['set search_path to public,phenome;'] });
45 $dbh->{RaiseError
} = 1;
48 my $q0 = "SELECT count(*) FROM genotypeprop WHERE genotypeprop_id in (SELECT genotypeprop_id FROM nd_experiment_protocol join nd_experiment_genotype using(nd_experiment_id) JOIN genotypeprop USING(genotype_id) WHERE nd_protocol_id=?)";
50 my $h0 = $dbh->prepare($q0);
53 my ($count) = $h0->fetchrow_array();
54 print "You are about to delete $count genotyping entries. Proceed? Y/n :";
57 if ($answer !~ m/y|Y/) {
58 die "Aborted due to user request.";
62 CXGN
::Genotype
->delete_genotypes_with_protocol_id($bcs_schema, $opt_p);
66 print STDERR
"An error occurred $@... Not deleting.\n";
70 print STDERR
"Deletion successful. Commit? Y/N : ";
72 if ($answer =~ m/Y|y/) {
73 print STDERR
"Deleting... ";
75 print STDERR
"Done.\n";