2 # See the NOTICE file distributed with this work for additional information
3 # regarding copyright ownership.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
26 my ( $host, $port, $user, $pass, $dbpattern );
37 intron_supporting_evidence
53 $0 --dbhost=ens-staging1 [--dbport=3306] \\
54 \t--dbuser=ensadmin --dbpass=XXX \\
59 --dbpattern Specifies a regular expression
for (possibly) matching
62 --nobackup Do not backup the meta_coord table in a file.
64 --help Displays
this help text.
66 This script will dump the current meta_coord table to a backup file in
67 the current directory. Then it will update the meta_coord table
for the
68 data in the following tables:
72 print(
"\t", join(
"\n\t", @table_names ),
"\n" );
76 if ( scalar(@ARGV) == 0 ) {
83 # get the basic options for connecting to a database server
85 push(@$optsd,
'backup!');
86 # process the command line with the supplied options plus a help subroutine
87 my $opts = $cli_helper->process_args( $optsd, \&
usage );
89 # use the command line options to get an array of database details
90 # only process each database name once (to avoid duplication for multispecies dbs)
91 for my $db_args ( @{ $cli_helper->get_dba_args_for_opts( $opts, 0 ) } ) {
95 if (!exists $opts->{backup} or (exists $opts->{backup} and $opts->{backup})) {
97 $dba->dbc()->dbname() .
"_" . $dba->species_id() .
".meta_coord.backup";
98 my $sys_call = sprintf(
"mysql "
104 .
"--skip-column-names "
105 .
" --execute='SELECT * FROM meta_coord'"
107 $dba->dbc->host(), $dba->dbc->port(),
108 $dba->dbc->username(), $dba->dbc->password(),
109 $dba->dbc->dbname() );
110 unless ( system($sys_call) == 0 ) {
111 warn
"Can't dump the original meta_coord for back up "
112 .
"(skipping this species)\n";
115 print
"Original meta_coord table backed up in $file\n";
119 foreach my $table_name (@table_names) {
120 print(
"Updating $table_name table entries... ");
122 $dba->dbc()->sql_helper()->execute_update(
124 "DELETE mc.* FROM meta_coord mc, coord_system cs WHERE cs.coord_system_id=mc.coord_system_id AND table_name = ? AND cs.species_id=?",
125 -PARAMS => [ $table_name, $dba->species_id() ] );
127 my $sql =
"INSERT INTO meta_coord "
128 .
"SELECT '$table_name', s.coord_system_id, "
129 .
"MAX( t.seq_region_end - t.seq_region_start + 1 ) "
130 .
"FROM $table_name t, seq_region s, coord_system c "
131 .
"WHERE t.seq_region_id = s.seq_region_id AND c.coord_system_id=s.coord_system_id AND c.species_id=?"
132 .
"GROUP BY s.coord_system_id";
134 $dba->dbc()->sql_helper()->execute_update(
136 -PARAMS => [ $dba->species_id() ] );
142 print(
"==> Done with "
143 . $dba->dbc->dbname() .
"/"
146 } ## end
for my $db_args ( @{ $cli_helper...})
148 print(
"==> All done.\n");