Commit 31dd94b0 authored by Thomas Juettemann's avatar Thomas Juettemann
Browse files

1) Added option to include name of the target DB; 2) Update %global_tables for funcgen

parent b7f58904
#!/usr/bin/env perl #!/usr/bin/env perl
# Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute # Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
# Copyright [2016-2018] EMBL-European Bioinformatics Institute # Copyright [2016-2017] EMBL-European Bioinformatics Institute
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...@@ -34,7 +34,7 @@ use Scalar::Util qw/looks_like_number/; ...@@ -34,7 +34,7 @@ use Scalar::Util qw/looks_like_number/;
my %global_tables = ( my %global_tables = (
core => [qw/attrib_type meta coord_system external_db unmapped_reason/], core => [qw/attrib_type meta coord_system external_db unmapped_reason/],
funcgen => [qw/feature_set/], funcgen => [qw/ analysis analysis_description epigenome experiment experimental_group external_db feature_type meta meta_coord regulatory_build/],
); );
run(); run();
...@@ -55,7 +55,7 @@ sub parse_options { ...@@ -55,7 +55,7 @@ sub parse_options {
group => 'core', group => 'core',
dest_port => 3306 dest_port => 3306
}; };
GetOptions($opts, qw/ GetOptions($opts, qw/
host|hostname|h=s host|hostname|h=s
port|P=i port|P=i
...@@ -64,19 +64,20 @@ sub parse_options { ...@@ -64,19 +64,20 @@ sub parse_options {
dbname|database|db=s dbname|database|db=s
species=s species=s
group=s group=s
dest_host|dest_hostname|dh=s dest_host|dest_hostname|dh=s
dest_port|dP=i dest_port|dP=i
dest_user|dest_username|du=s dest_user|dest_username|du=s
dest_pass|dest_password|dp=s dest_pass|dest_password|dp=s
dest_dbname|dd=s
registry|reg_conf=s registry|reg_conf=s
json=s json=s
directory=s directory=s
drop_database drop_database
help help
man man
/) or pod2usage(-msg => 'Misconfigured options given', -verbose => 1, -exitval => 1); /) or pod2usage(-msg => 'Misconfigured options given', -verbose => 1, -exitval => 1);
...@@ -140,7 +141,7 @@ sub process { ...@@ -140,7 +141,7 @@ sub process {
my $dbc = $self->target_dbc(); my $dbc = $self->target_dbc();
my $config_hash = $self->{json}; my $config_hash = $self->{json};
my $is_dna = 1; my $is_dna = 1;
foreach my $species (keys %{$config_hash}) { foreach my $species (keys %{$config_hash}) {
foreach my $group (keys %{$config_hash->{$species}}) { foreach my $group (keys %{$config_hash->{$species}}) {
$is_dna = 0 if $group ne 'core'; $is_dna = 0 if $group ne 'core';
...@@ -174,7 +175,7 @@ sub process { ...@@ -174,7 +175,7 @@ sub process {
sub dump_database { sub dump_database {
my ($self, $dba) = @_; my ($self, $dba) = @_;
my $dir = $self->{opts}->{directory}; my $dir = $self->{opts}->{directory};
if($dir) { if($dir) {
print STDERR "Directory given; will dump database to this location\n"; print STDERR "Directory given; will dump database to this location\n";
my $dumper = Bio::EnsEMBL::Test::DumpDatabase->new($dba, $dir); my $dumper = Bio::EnsEMBL::Test::DumpDatabase->new($dba, $dir);
...@@ -216,7 +217,7 @@ sub copy_regions { ...@@ -216,7 +217,7 @@ sub copy_regions {
my $seq_region_names; my $seq_region_names;
# Grab all toplevel slices and record those IDs which need to be # Grab all toplevel slices and record those IDs which need to be
# transferred for the # transferred for the
my @toplevel_slices; my @toplevel_slices;
my %seq_region_id_list; my %seq_region_id_list;
foreach my $region (@{$regions}) { foreach my $region (@{$regions}) {
...@@ -248,18 +249,18 @@ sub copy_regions { ...@@ -248,18 +249,18 @@ sub copy_regions {
my $contig_slice = $contig->[2]; my $contig_slice = $contig->[2];
$seq_region_id_list{$contig_slice->get_seq_region_id} = 1; $seq_region_id_list{$contig_slice->get_seq_region_id} = 1;
} }
} }
#Copy the information about each contig/supercontig's assembly #Copy the information about each contig/supercontig's assembly
my $seq_region_ids = join(q{,}, keys %seq_region_id_list); my $seq_region_ids = join(q{,}, keys %seq_region_id_list);
if ($is_dna) { if ($is_dna) {
my $sr_query = "SELECT a.* FROM seq_region s JOIN assembly a ON (s.seq_region_id = a.cmp_seq_region_id) WHERE seq_region_id IN ($seq_region_ids)"; my $sr_query = "SELECT a.* FROM seq_region s JOIN assembly a ON (s.seq_region_id = a.cmp_seq_region_id) WHERE seq_region_id IN ($seq_region_ids)";
$self->copy_data($from, $to, "assembly", $sr_query); $self->copy_data($from, $to, "assembly", $sr_query);
} }
# Once we've got the original list of slices we have to know if one is an # Once we've got the original list of slices we have to know if one is an
# assembly what it maps to & bring that seq_region along (toplevel def). If # assembly what it maps to & bring that seq_region along (toplevel def). If
# seq is wanted then user has to specify that region # seq is wanted then user has to specify that region
my @seq_region_exception_ids; my @seq_region_exception_ids;
...@@ -271,20 +272,20 @@ sub copy_regions { ...@@ -271,20 +272,20 @@ sub copy_regions {
push(@seq_region_exception_ids, $slice_adaptor->get_seq_region_id($exception->alternate_slice())); push(@seq_region_exception_ids, $slice_adaptor->get_seq_region_id($exception->alternate_slice()));
} }
} }
#Grab the copied IDs from the target DB & use this to drive the copy of assembly exceptions #Grab the copied IDs from the target DB & use this to drive the copy of assembly exceptions
my $asm_cmp_ids = join(q{,}, @seq_region_exception_ids); my $asm_cmp_ids = join(q{,}, @seq_region_exception_ids);
if (scalar(@seq_region_exception_ids) > 0) { if (scalar(@seq_region_exception_ids) > 0) {
$self->copy_data($from, $to, 'assembly_exception', "SELECT * FROM assembly_exception WHERE seq_region_id in ($asm_cmp_ids)"); $self->copy_data($from, $to, 'assembly_exception', "SELECT * FROM assembly_exception WHERE seq_region_id in ($asm_cmp_ids)");
} }
#Now transfer all seq_regions from seq_region into the new DB #Now transfer all seq_regions from seq_region into the new DB
my @seq_regions_to_copy = (@seq_region_exception_ids, (map { $slice_adaptor->get_seq_region_id($_) } @toplevel_slices), keys %seq_region_id_list); my @seq_regions_to_copy = (@seq_region_exception_ids, (map { $slice_adaptor->get_seq_region_id($_) } @toplevel_slices), keys %seq_region_id_list);
my $seq_regions_to_copy_in = join(q{,}, @seq_regions_to_copy); my $seq_regions_to_copy_in = join(q{,}, @seq_regions_to_copy);
$self->copy_data($from, $to, 'seq_region', "SELECT * FROM seq_region WHERE seq_region_id in ($seq_regions_to_copy_in)"); $self->copy_data($from, $to, 'seq_region', "SELECT * FROM seq_region WHERE seq_region_id in ($seq_regions_to_copy_in)");
$self->copy_data($from, $to, 'seq_region_attrib', "SELECT * FROM seq_region_attrib WHERE seq_region_id in ($seq_regions_to_copy_in)") if $is_dna; $self->copy_data($from, $to, 'seq_region_attrib', "SELECT * FROM seq_region_attrib WHERE seq_region_id in ($seq_regions_to_copy_in)") if $is_dna;
$self->copy_data($from, $to, 'dna', "SELECT * FROM dna WHERE seq_region_id in ($seq_regions_to_copy_in)") if $is_dna; $self->copy_data($from, $to, 'dna', "SELECT * FROM dna WHERE seq_region_id in ($seq_regions_to_copy_in)") if $is_dna;
return \@toplevel_slices; return \@toplevel_slices;
} }
...@@ -298,7 +299,7 @@ sub copy_features { ...@@ -298,7 +299,7 @@ sub copy_features {
$sig_warn = $SIG{__WARN__}; $sig_warn = $SIG{__WARN__};
$sig_warn_guard = scope_guard(sub { $SIG{__WARN__} = $sig_warn }); $sig_warn_guard = scope_guard(sub { $SIG{__WARN__} = $sig_warn });
$SIG{__WARN__} = sub {}; #ignore everything $SIG{__WARN__} = sub {}; #ignore everything
} }
print STDERR "Copying $name features\n"; print STDERR "Copying $name features\n";
my $from_adaptor = $from->get_adaptor($name); my $from_adaptor = $from->get_adaptor($name);
my $to_adaptor = $to->get_adaptor($name); my $to_adaptor = $to->get_adaptor($name);
...@@ -317,7 +318,7 @@ sub copy_features { ...@@ -317,7 +318,7 @@ sub copy_features {
print STDERR sprintf('Processing %d out of %d'."\n", $count, $total_features); print STDERR sprintf('Processing %d out of %d'."\n", $count, $total_features);
} }
} }
$f = $self->post_process_feature($f, $slice); $f = $self->post_process_feature($f, $slice);
next unless $f; # means we decided not to store it next unless $f; # means we decided not to store it
$to_adaptor->store($f); $to_adaptor->store($f);
...@@ -338,7 +339,7 @@ sub copy_database_structure { ...@@ -338,7 +339,7 @@ sub copy_database_structure {
$target_dbc->do('create database '.$target_name); $target_dbc->do('create database '.$target_name);
my $cmd_tmpl = 'mysqldump --host=%s --port=%d --user=%s --no-data --skip-add-locks --skip-lock-tables %s | mysql --host=%s --port=%d --user=%s --password=%s %s'; my $cmd_tmpl = 'mysqldump --host=%s --port=%d --user=%s --no-data --skip-add-locks --skip-lock-tables %s | mysql --host=%s --port=%d --user=%s --password=%s %s';
my @src_args = map { $dbc->$_() } qw/host port username dbname/; my @src_args = map { $dbc->$_() } qw/host port username dbname/;
my @trg_args = ((map { $target_dbc->$_() } qw/host port username password/), $target_name); my @trg_args = ((map { $target_dbc->$_() } qw/host port username password/), $target_name);
my $cmd = sprintf($cmd_tmpl, @src_args, @trg_args); my $cmd = sprintf($cmd_tmpl, @src_args, @trg_args);
system($cmd); system($cmd);
my $rc = $? >> 8; my $rc = $? >> 8;
...@@ -394,7 +395,7 @@ sub copy_data { ...@@ -394,7 +395,7 @@ sub copy_data {
} }
elsif(!looks_like_number($e)) { elsif(!looks_like_number($e)) {
$e =~ s/\n/\\\n/g; $e =~ s/\n/\\\n/g;
$e =~ s/\t/\\\t/g; $e =~ s/\t/\\\t/g;
} }
push(@copy, $e); push(@copy, $e);
} }
...@@ -409,6 +410,9 @@ sub copy_data { ...@@ -409,6 +410,9 @@ sub copy_data {
sub new_dbname { sub new_dbname {
my ($self, $dbname) = @_; my ($self, $dbname) = @_;
if(defined $self->{opts}->{dest_dbname}){
return $self->{opts}->{dest_dbname};
}
my @localtime = localtime(); my @localtime = localtime();
my $date = strftime '%Y%m%d', @localtime; my $date = strftime '%Y%m%d', @localtime;
my $time = strftime '%H%M%S', @localtime; my $time = strftime '%H%M%S', @localtime;
...@@ -419,7 +423,7 @@ sub post_process_feature { ...@@ -419,7 +423,7 @@ sub post_process_feature {
my ($self, $f, $slice, $filter_exception) = @_; my ($self, $f, $slice, $filter_exception) = @_;
my $filter = $self->filter_on_exception($f, $slice, $filter_exception); my $filter = $self->filter_on_exception($f, $slice, $filter_exception);
return if $filter; return if $filter;
#Core objects #Core objects
if($f->can('load')) { if($f->can('load')) {
$f->load(); $f->load();
...@@ -427,8 +431,8 @@ sub post_process_feature { ...@@ -427,8 +431,8 @@ sub post_process_feature {
elsif($f->isa('Bio::EnsEMBL::RepeatFeature')) { elsif($f->isa('Bio::EnsEMBL::RepeatFeature')) {
$self->_load_repeat($f); $self->_load_repeat($f);
} }
return $f; return $f;
} }
......
Markdown is supported
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