3 # See the NOTICE file distributed with this work for additional information
4 # regarding copyright ownership.
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
19 # Populate meta table with (e.g.) genebuild.level = toplevel if all genes are
20 # top level. Using v41 API code this can speed fetching & dumping greatly.
36 qw[gene
transcript exon repeat_feature dna_align_feature protein_align_feature simple_feature prediction_transcript prediction_exon];
38 # get the basic options for connecting to a database server
40 # add the print option
41 push(@{$optsd},
"print");
42 # process the command line with the supplied options plus a help subroutine
43 my $opts = $cli_helper->process_args($optsd,\&
usage);
45 # use the command line options to get an array of database details
46 for my $db_args (@{$cli_helper->get_dba_args_for_opts($opts)}) {
47 # use the args to create a DBA
56 my ($dba,$print) = @_;
57 my $ma = $dba->get_MetaContainer();
62 foreach my $type (@feature_types) {
69 push @inserted, $type;
73 push @not_inserted, $type;
79 print $dba->dbc()->dbname()
82 .
") inserted keys for "
83 . join(
", ", @inserted ) .
".\n"
85 print
"Did not insert keys for " . join(
", ", @not_inserted ) .
".\n"
89 #------------------------------------------------------------------------------
93 my ( $ma, $type ) = @_;
95 $ma->delete_key( $type .
"build.level" );
99 #------------------------------------------------------------------------------
103 my ( $dba, $type ) = @_;
105 # compare total count of typewith number of toplevel type, if they're the same,
106 # then we can use the key
108 my $sth = $dba->dbc()->prepare(
"SELECT COUNT(*) FROM $type");
110 my $total = ( $sth->fetchrow_array() )[0];
114 ->prepare(
"SELECT COUNT(*) "
115 .
"FROM $type t, seq_region_attrib sra, attrib_type at "
116 .
"WHERE t.seq_region_id=sra.seq_region_id "
117 .
"AND sra.attrib_type_id=at.attrib_type_id "
118 .
"AND at.code='toplevel'" );
120 my $toplevel = ( $sth->fetchrow_array() )[0];
122 if ( $toplevel > 0 ) {
123 return $total == $toplevel;
127 #------------------------------------------------------------------------------
130 my ( $ma, $type ) = @_;
131 $ma->store_key_value( $type .
"build.level",
"toplevel" );
134 #------------------------------------------------------------------------------
137 print <<EOF; exit(0);
139 Populate meta table with (e.g.) genebuild.level = toplevel if all genes
140 are top level. Using v41 API code this can speed fetching and dumping
143 Usage: perl $0 <options>
145 --host|dbhost Database host to connect to.
147 --port|dbport Database port to connect to (default is 3306).
149 --dbpattern Database name regexp
151 --user|dbuser Database username.
153 --pass|dbpass Password for user.
155 --print Just print, don't insert or delete keys.
159 --verbose Prints out the name of the database
160 which is going to be patched.
164 If you like to patch just a single database you can also use this
167 perl meta_levels.pl --host ... --user ... --pass ... --port ... --dbname ...