]> git.donarmstrong.com Git - biopieces.git/blobdiff - bp_bin/remove_mysql_tables
refactoring of assemble_pairs
[biopieces.git] / bp_bin / remove_mysql_tables
deleted file mode 120000 (symlink)
index 39a2428abb6f0ea325a73b69ff2084fe904fb137..0000000000000000000000000000000000000000
+++ /dev/null
@@ -1 +0,0 @@
-../code_perl/Maasha/bin/remove_mysql_tables
\ No newline at end of file
new file mode 100755 (executable)
index 0000000000000000000000000000000000000000..794ab0f9c36db3248f6da0414c68eefec04c2a41
--- /dev/null
@@ -0,0 +1,113 @@
+#!/usr/bin/env perl
+
+# Copyright (C) 2007-2009 Martin A. Hansen.
+
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+# http://www.gnu.org/copyleft/gpl.html
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+# Remove MySQL database tables.
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+use warnings;
+use strict;
+use Maasha::Biopieces;
+use Maasha::Common;
+use Maasha::SQL;
+use Maasha::UCSC;
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+my ( $options, $user, $password, $in, $out, $record, %table_hash, $dbh, $table );
+
+$user     = Maasha::Biopieces::biopiecesrc( "MYSQL_USER" );
+$password = Maasha::Biopieces::biopiecesrc( "MYSQL_PASSWORD" );
+
+$options = Maasha::Biopieces::parse_options(
+    [
+        { long => 'database', short => 'd', type => 'string', mandatory => 'yes', default => undef,     allowed => undef, disallowed => undef },
+        { long => 'tables',   short => 't', type => 'list',   mandatory => 'no',  default => undef,     allowed => undef, disallowed => undef },
+        { long => 'keys',     short => 'k', type => 'list',   mandatory => 'no',  default => undef,     allowed => undef, disallowed => undef },
+        { long => 'user',     short => 'u', type => 'string', mandatory => 'no',  default => $user,     allowed => undef, disallowed => undef },
+        { long => 'password', short => 'p', type => 'string', mandatory => 'no',  default => $password, allowed => undef, disallowed => undef },
+    ]   
+);
+
+$in  = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
+$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
+
+Maasha::Common::error( qq(both --tables and --keys specified) ) if     $options->{ "tables" } and     $options->{ "keys" };
+Maasha::Common::error( qq(no --tables or --keys specified) )    if not $options->{ "tables" } and not $options->{ "keys" };
+
+$options->{ "user" }     ||= Maasha::UCSC::ucsc_get_user();
+$options->{ "password" } ||= Maasha::UCSC::ucsc_get_password();
+
+map { $table_hash{ $_ } = 1 } @{ $options->{ 'tables' } };
+
+while ( $record = Maasha::Biopieces::get_record( $in ) )
+{
+    map { $table_hash{ $record->{ $_ } } = 1 } @{ $options->{ 'keys' } };
+
+    Maasha::Biopieces::put_record( $record, $out ) if not $options->{ 'no_stream' };
+}
+
+$dbh = Maasha::SQL::connect( $options->{ "database" }, $options->{ "user" }, $options->{ "password" } );
+
+foreach $table ( sort keys %table_hash )
+{
+    if ( Maasha::SQL::table_exists( $dbh, $table ) )
+    {
+        print STDERR qq(Removing table "$table" from database "$options->{ 'database' }" ... ) if $options->{ 'verbose' };
+        Maasha::SQL::delete_table( $dbh, $table );
+        print STDERR "done.\n" if $options->{ 'verbose' };
+    }
+    else
+    {
+        print STDERR qq(WARNING: table "$table" not found in database "$options->{ 'database' }\n");
+    }
+}
+
+Maasha::SQL::disconnect( $dbh );
+
+Maasha::Biopieces::close_stream( $in );
+Maasha::Biopieces::close_stream( $out );
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+BEGIN
+{
+    Maasha::Biopieces::status_set();
+}
+
+
+END
+{
+    Maasha::Biopieces::status_log();
+}
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+__END__