Skip to content
Snippets Groups Projects
Commit 39b703eb authored by Andreas Kusalananda Kähäri's avatar Andreas Kusalananda Kähäri
Browse files

Allow for using dbhost, dbport etc. as options, and set default value

for port to '3306'. Some formatting.
parent ac77391b
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,8 @@ use Getopt::Long;
my $help = 0;
my ( $host, $port, $user, $pass, $dbpattern );
$port = '3306';
my $usage = qq(
$0 --host ens-staging --port 3306 --user ensadmin \\
--pass XXX --dbpattern core
......@@ -37,34 +39,50 @@ table for all the following table names one by one
transcript
);
if (scalar @ARGV == 0 ) {
if ( scalar @ARGV == 0 ) {
print $usage, "\n";
exit 0;
}
GetOptions( 'help' => \$help,
'host=s' => \$host,
'port=i' => \$port,
'user=s' => \$user,
'pass=s' => \$pass,
'dbpattern=s' => \$dbpattern );
if ($help) {
if ( !GetOptions( 'help!' => \$help,
'dbhost|host=s' => \$host,
'dbport|port=i' => \$port,
'dbuser|user=s' => \$user,
'dbpass|password|pass=s' => \$pass,
'dbpattern=s' => \$dbpattern
) ||
$help )
{
print $usage, "\n";
exit 0;
exit;
}
#print "help: $help argv:"
#. scalar(@ARGV)
#. "$host $port $user $pass $dbname\n";
my $dsn = "DBI:mysql:host=$host";
$dsn .= ";port=$port" if ($port);
my $dsn = "DBI:mysql:host=$host;port=$port";
my $db = DBI->connect( $dsn, $user, $pass );
my @dbnames =
map { $_->[0] } @{ $db->selectall_arrayref("show databases") };
map { $_->[0] } @{ $db->selectall_arrayref("SHOW DATABASES") };
my @table_names = qw(
assembly_exception
gene
exon
density_feature
ditag_feature
dna_align_feature
karyotype
marker_feature
misc_feature
qtl_feature
prediction_exon
prediction_transcript
protein_align_feature
repeat_feature
simple_feature
splicing_event
transcript
);
for my $dbname (@dbnames) {
......@@ -77,37 +95,16 @@ for my $dbname (@dbnames) {
-pass => $pass,
-dbname => $dbname );
my @table_names = qw(
assembly_exception
gene
exon
density_feature
ditag_feature
dna_align_feature
karyotype
marker_feature
misc_feature
qtl_feature
prediction_exon
prediction_transcript
protein_align_feature
repeat_feature
simple_feature
splicing_event
transcript
);
unless (
system( "mysql -h$host -P$port -u$user -p'$pass' -N "
. "-e 'SELECT * FROM meta_coord' $dbname "
. "> $dbname.meta_coord.backup"
) == 0 )
if ( system( "mysql -h$host -P$port -u$user -p'$pass' -N " .
"-e 'SELECT * FROM meta_coord' $dbname " .
"> $dbname.meta_coord.backup" ) )
{
print STDERR "Can't dump the original meta_coord for back up\n";
exit 1;
} else {
print STDERR "Original meta_coord table backed up in "
. "$dbname.meta_coord.backup\n";
}
else {
print STDERR "Original meta_coord table backed up in " .
"$dbname.meta_coord.backup\n";
}
foreach my $table_name (@table_names) {
......@@ -118,12 +115,12 @@ for my $dbname (@dbnames) {
$sth->finish;
$sql =
"INSERT INTO meta_coord "
. "SELECT '$table_name', s.coord_system_id, "
. "MAX( t.seq_region_end - t.seq_region_start + 1 ) "
. "FROM $table_name t, seq_region s "
. "WHERE t.seq_region_id = s.seq_region_id "
. "GROUP BY s.coord_system_id";
"INSERT INTO meta_coord " .
"SELECT '$table_name', s.coord_system_id, " .
"MAX( t.seq_region_end - t.seq_region_start + 1 ) " .
"FROM $table_name t, seq_region s " .
"WHERE t.seq_region_id = s.seq_region_id " .
"GROUP BY s.coord_system_id";
$sth = $dbc->prepare($sql);
$sth->execute;
$sth->finish;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment