Skip to content
Snippets Groups Projects
Commit 51e3f849 authored by Graham McVicker's avatar Graham McVicker
Browse files

script for propogating external_db changes to all core databases

parent 60c66623
No related branches found
No related tags found
No related merge requests found
100 AFFY_HG_U133 1 XREF
110 AFFY_HG_U95 1 XREF
120 AFFY_MG_U74 1 XREF
130 AFFY_MG_U74v2 1 XREF
140 AFFY_Mu11Ksub 1 XREF
150 AFFY_RG_U34 1 XREF
160 AFFY_RN_U34 1 XREF
170 AFFY_RT_U34 1 XREF
200 Anopheles_paper 1 KNOWNXREF
210 Anopheles_symbol 1 KNOWN
300 BRIGGSAE_HYBRID 1 KNOWNXREF
400 Celera_Gene 1 PRED
410 Celera_Pep 1 PRED
420 Celera_Trans 1 PRED
500 drosophila_gene_id 1 KNOWNXREF
600 DROS_ORTH 1 ORTH
700 EMBL 1 KNOWNXREF
800 flybase_gene 1 KNOWNXREF
810 flybase_symbol 1 KNOWNXREF
820 flybase_transcript 1 KNOWNXREF
900 GKB 1 XREF
1000 GO 1 KNOWNXREF
1100 HUGO 1 KNOWNXREF
1200 Interpro 1 XREF
1300 LocusLink 1 KNOWNXREF
1400 MarkerSymbol 1 KNOWNXREF
1500 MIM 1 KNOWNXREF
1600 PDB 1 KNOWNXREF
1700 protein_id 1 KNOWNXREF
1800 RefSeq 1 KNOWN
1900 Sanger_Hver1_2_1 1 XREF
1910 Sanger_Mver1_1_1 1 XREF
2000 SPTREMBL 1 KNOWN
2100 Superfamily 1 KNOWNXREF
2200 SWISSPROT 1 KNOWN
2300 Vega_gene 1 XREF
2310 Vega_transcript 1 XREF
2320 Vega_translation 1 XREF
2400 wormbase_gene 1 KNOWN
2410 wormbase_transcript 1 KNOWN
2420 wormpep_id 1 KNOWN
2500 ZFIN 1 KNOWNXREF
#
# updates the external db tables on all of the core databases on a given host
#
use strict;
use Getopt::Long;
use DBI;
use IO::File;
my ( $host, $user, $pass, $port,@dbnames, $file, $release_num);
GetOptions( "host=s", \$host,
"user=s", \$user,
"pass=s", \$pass,
"port=i", \$port,
"file=s", \$file,
"dbnames=s@", \@dbnames,
"release_num=i", \$release_num
);
#both host and file are required
usage() if(!$host || !$file);
#release num XOR dbname are required
usage() if(($release_num && @dbnames) || (!$release_num && !@dbnames));
$port ||= 3306;
my $dsn = "DBI:mysql:host=$host;port=$port";
my $db = DBI->connect( $dsn, $user, $pass, {RaiseError => 1} );
if($release_num) {
@dbnames = map {$_->[0] } @{ $db->selectall_arrayref( "show databases" ) };
#
# filter out all non-core databases
#
@dbnames = grep {/^[a-zA-Z]+\_[a-zA-Z]+\_(core|est|estgene)\_${release_num}\_\d+$/} @dbnames;
}
#
# make sure the user wishes to continue
#
print STDERR "The following databases will be external_db updated:\n ";
print join("\n ", @dbnames);
print "\ncontinue with update (yes/no)> ";
my $input = lc(<STDIN>);
chomp($input);
if($input ne 'yes') {
print "external_db conversion aborted\n";
exit();
}
#
# read all of the new external_db entries from the file
#
my $fh = IO::File->new();
$fh->open($file) or die("could not open input file $file");
my @rows;
while(<$fh>) {
my @a = split(/\t/);
push @rows, {'external_db_id' => $a[0],
'db_name' => $a[1],
'release' => $a[2],
'status' => $a[3]};
}
$fh->close();
foreach my $dbname (@dbnames) {
print STDERR "updating $dbname\n";
$db->do("use $dbname");
my $sth = $db->prepare('DELETE FROM external_db');
$sth->execute();
$sth->finish();
$sth = $db->prepare('INSERT INTO external_db (external_db_id, db_name,
release, status)
VALUES (?,?,?,?)');
foreach my $row (@rows) {
$sth->execute($row->{'external_db_id'},
$row->{'db_name'},
$row->{'release'},
$row->{'status'});
}
$sth->finish();
}
print STDERR "updates complete\n";
sub usage {
print STDERR <<EOF
Usage: update_external_db options
Where options are: -host hostname
-user username
-pass password
-port port_of_server optional
-release the release of the database to update used to
match database names. e.g. 13
-file the path of the file containing the insert statements
of the entries of the external_db table
-dbnames db1
the names of the database to update. if not provided
all of the core databases matching the release arg
will be updated. Either -dbnames or -release must
be specified, but not both. Multiple dbnames can
be provided.
E.g.:
#update 2 databases
perl update_external_dbs.pl -host ecs1c -file external_dbs.txt -user ensadmin -pass secret -dbnames homo_sapiens_core_14_33 -dbnames mus_musculus_core_14_30
#update all core databases for release 14
perl update_external_dbs.pl -host ecs2d -file external_dbs.txt -user ensadmin -pass secret -release 14
EOF
;
exit;
}
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