ensembl-hive  2.7.0
convert_seqstore.pl
Go to the documentation of this file.
1 #!/usr/bin/env perl
2 # See the NOTICE file distributed with this work for additional information
3 # regarding copyright ownership.
4 #
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
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
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.
16 
17 use strict;
18 use warnings;
19 
20 use Getopt::Long;
21 use Cwd;
22 
23 use vars qw(@INC);
24 
25 #effectively add this directory to the PERL5LIB automatically
26 my $dir = cwd() . '/' . __FILE__;
27 my @d = split(/\//, $dir);
28 pop(@d);
29 $dir = join('/', @d);
30 unshift @INC, $dir;
31 
32 
33 my ($file, $user, $password, $verbose, $force, $help, $schema, $vega_schema, $limit);
34 
35 GetOptions ('file=s' => \$file,
36  'schema=s' => \$schema,
37  'vega_schema=s' => \$vega_schema,
38  'user=s' => \$user,
39  'password=s' => \$password,
40  'verbose' => \$verbose,
41  'force' => \$force,
42  'limit=s' => \$limit,
43  'help' => sub { &show_help(); exit 1;} );
44 
45 usage("-file option is required") if(!$file);
46 usage("-schema option is required") if(!$schema);
47 usage() if($help);
48 
49 open(FILE, $file) or die("Could not open input file '$file'");
50 
51 my @all_species_converters;
52 
53 while( my $line = <FILE> ) {
54  chomp($line);
55  next if $line =~ /^#/;
56  next if !$line;
57 
58  my ( $species, $host, $source_db_name, $target_db_name ) =
59  split( "\t", $line );
60 
61  my $converter;
62  if ($vega_schema) {
63  $species = "vega::".$species;
64  eval "require SeqStoreConverter::$species";
65  if($@) {
66  warn("Could not require conversion module SeqStoreConverter::$species\n" .
67  "Using SeqStoreConverter::BasicConverter instead:\n$@");
69  $species = "BasicConverter";
70  }
71  else {
72  warn "Using conversion module SeqStoreConverter::$species\n";
73  }
74  }
75 
76  else {
77  eval "require SeqStoreConverter::$species";
78  if($@) {
79  warn("Could not require conversion module SeqStoreConverter::$species\n" .
80  "Using SeqStoreConverter::BasicConverter instead:\n$@");
82  $species = "BasicConverter";
83  }
84  }
85 
86  {
87  no strict 'refs';
88  $converter = "SeqStoreConverter::$species"->new
89  ( $user, $password, $host, $source_db_name, $target_db_name,
90  $schema, $vega_schema, $force, $verbose, $limit );
91  }
92 
93  push @all_species_converters, $converter;
94 
95 }
96 
97 for my $converter ( @all_species_converters ) {
98  $converter->debug( "\n\n*** converting " . $converter->source . " to " .
99  $converter->target() . " ***");
100  $converter->transfer_meta();
101  $converter->create_coord_systems();
102  $converter->create_seq_regions();
103  $converter->create_assembly();
104  $converter->create_attribs();
105  $converter->set_top_level();
106 
107  $converter->transfer_dna();
108  $converter->transfer_genes();
109  $converter->transfer_prediction_transcripts();
110  $converter->transfer_features();
111  if ($vega_schema) {
112  $converter->transfer_vega_stable_ids();
113  } else {
114  $converter->transfer_stable_ids();
115  }
116  $converter->copy_other_tables();
117  $converter->copy_repeat_consensus();
118  $converter->create_meta_coord();
119  if ($vega_schema) {
120  $converter->update_clone_info();
121  $converter->remove_supercontigs();
122  $converter->copy_internal_clone_names();
123  }
124 }
125 
126 
127 print STDERR "*** All finished ***\n";
128 
129 sub usage {
130  my $msg = shift;
131 
132  print STDERR "$msg\n\n" if($msg);
133 
134  print STDERR <<EOF;
135 usage: perl convert_seqstore <options>
136 
137 options: -file <input_file> input file with tab delimited 'species',
138  'host', 'source_db', 'target_db' values
139  on each line
140 
141  -schema <table_file> file containing SQL schema definition
142 
143  -vega_schema <table_file> file containing SQL for additional Vega tables
144 
145  -user <user> a mysql db user with read/write priveleges
146 
147  -password <password> the mysql user's password
148 
149  -verbose print out debug statements
150 
151  -force replace any target dbs that already exists
152 
153  -limit <num_rows> limit the number of features transfered to
154  speed up testing
155 
156  -help display this message
157 
158 example: perl convert_seqstore.pl -file converter.input \\
159  -schema ../../sql/table.sql -user ensadmin -password secret \\
160  -force -verbose
161 
162 EOF
163 #'
164 
165  exit;
166 }
SeqStoreConverter::BasicConverter::new
public new()
show_help
public show_help()
SeqStoreConverter::BasicConverter
Definition: BasicConverter.pm:3
usage
public usage()