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.
17 # this script will repopulate the meta coord table
18 # it makes an attempt to pick up all the right tables
19 # (all those which have seq_region_id, seq_region_start and seq_region_end)
21 # normally the API will populate the table ...
30 my ($host, $user, $pass, $port, $dbname); #ensembl core db
31 GetOptions(
'host=s' => \$host,
35 'dbname=s' => \$dbname,
39 my $dsn =
"DBI:mysql:host=$host;dbname=$dbname";
41 $dsn .=
";port=$port";
44 my $db = DBI->connect( $dsn, $user, $pass );
46 $db->do(
"delete from meta_coord" );
48 my $res = $db->selectall_arrayref(
"show tables" );
50 my @tables =
map { $_->[0] } @$res;
52 my %need_cols = (
"seq_region_id" => 1,
53 "seq_region_start" => 1,
54 "seq_region_end" => 1 );
56 for my $tablename ( @tables ) {
58 $res = $db->selectall_arrayref(
"select count(*) from $tablename" );
59 next
if( $res->[0]->[0] == 0 );
61 $res = $db->selectall_arrayref(
"desc $tablename" );
62 my @columns =
map { $_->[0] } @$res;
63 if( 3 == scalar( grep { exists $need_cols{$_}} @columns )) {
73 my $tablename = shift;
76 INSERT INTO meta_coord
77 SELECT
'$tablename', sr.coord_system_id,
78 MAX( f.seq_region_end - f.seq_region_start + 1)
79 FROM $tablename f, seq_region sr
80 WHERE sr.seq_region_id = f.seq_region_id
81 GROUP BY sr.coord_system_id