ensembl-hive  2.8.1
SchemaConversion.pm
Go to the documentation of this file.
1 =head1 LICENSE
2 
3 See the NOTICE file distributed with this work for additional information
4 regarding copyright ownership.
5 
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
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
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.
17 
18 =cut
19 
20 
21 =head1 CONTACT
22 
23  Please email comments or questions to the public Ensembl
24  developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
25 
26  Questions may also be sent to the Ensembl help desk at
27  <http://www.ensembl.org/Help/Contact>.
28 
29 =cut
30 
31 =head1 NAME
32 
33 Bio::EnsEMBL::Utils::SchemaConversion - Utility module for Vega schema conversion script
34 
35 =head1 SYNOPSIS
36 
37  my $serverroot = '/path/to/ensembl';
38  my $conversion =
40 
41  # parse common options
42  $conversion->conv_usage->parse_common_options;
43 
44  # convert from schema 19 to 20+
45  $conversion->do_conversion()
46 
47 =head1 DESCRIPTION
48 
49 This module is a helper module for database conversion, for
50 both vega-vega and ensembl-vega schemas. It provides a wrapper
51 around SeqStoreConverter::BasicConverter and the species specific
52 methods therein. Also provides access to helper functions in
54 
55 =head1 METHODS
56 
57 =cut
58 
59 package Bio::EnsEMBL::Utils::SchemaConversion;
60 
61 use strict;
62 use warnings;
63 
65 use Data::Dumper;
66 
67 =head2 new
68 
69  Example : $conversion->Bio::EnsEMBL::Utils::SchemaConversion->new($serverroot);
70  Description : Constructor, including an instance of a Bio::EnsEMBL::Utils::ConversionSupport
71  object. Parses input file and checks input with user
72  Return type : Bio::EnsEMBL::Utils::SchemaConversion object
73  Exceptions : thrown if $Siteroot not passed over
74  Caller : $Siteroot/utils/vega_schema_conversion
75 
76 =cut
77 
78 sub new {
79  my $class = shift;
80  my $support = shift;
81  my $self = {};
82  bless ($self,$class);
83  $self->{config} = Bio::EnsEMBL::Utils::ConversionSupport->new($support);
84  $self->conv_support->parse_common_options;
85  $self->conv_support->parse_extra_options('do_vega_sc=s',
86  'do_ens_sc=s',
87  'source_db=s',
88  'core_sql=s',
89  'vega_sql=s',
90  'patch_sql=s',
91  'force=s',
92  'do_features=s');
93 
94  #check input and show help
95  $self->conv_usage() if ($self->conv_support->param("help"));
96  $self->conv_usage("configuration file needed") unless ($self->conv_support->param("conffile"));
97  $self->conv_usage("password for database access needed") unless ($self->conv_support->param("pass"));
98  $self->conv_usage("can only do conversion to ensembl OR Vega, not both") if ($self->conv_support->param('do_vega_sc') && $self->conv_support->param('do_ens_sc'));
99  $self->conv_usage("You need to do vega->veg or ensembl->vega conversion") unless ($self->conv_support->param('do_vega_sc') || $self->conv_support->param('do_ens_sc'));
100 
101  # ask user to confirm parameters to proceed
102  $self->conv_support->allowed_params('conffile',
103  'do_vega_sc',
104  'do_ens_sc',
105  'host',
106  'port',
107  'user',
108  'pass',
109  'source_db',
110  'dbname',
111  'force',
112  'do_features',
113  'verbose',
114  'logpath',
115  'logfile',
116  'core_sql',
117  'vega_sql',
118  'patch_sql');
119  $self->conv_support->confirm_params;
120 
121  return $self;
122 }
123 
124 =head2 conv_support
125 
126  Example : $conversion->conv_support;
127  Description : Provides access to Bio::EnsEMBL::Utils::ConversionSupport methods
128  Return type : Bio::EnsEMBL::Utils::ConversionSuppor object
129  Exceptions : none
130  Caller : general
131 
132 =cut
133 
134 sub conv_support {
135  my $self = shift;
136  return $self->{config};
137 }
138 
139 =head2 conv_obj
140 
141  Example : $conversion->conv_obj;
142  Description : Provides access to SeqStoreConverter::BasicConverter methods
143  Return type : SeqStoreConverter::BasicConverter object
144  Exceptions : none
145  Caller : general
146 
147 =cut
148 
149 sub conv_obj {
150  my $self = shift;
151  return $self->{'converter_object'};
152 }
153 
154 
155 =head2 species_alias
156 
157  Example : $self->species_alias
158  Description : examines name of source database to determine which conversion module to use
159  Return type : string
160  Exceptions : die if wrong species name used
161  Caller : $self
162 
163 =cut
164 
165 sub species_alias {
166  my $self=shift;
167  my $name = shift;
168  return 'CanisFamiliaris' if $name =~ /canis/;
169  return 'HomoSapiens' if $name =~ /homo/;
170  return 'MusMusculus' if $name =~ /mus/;
171  return 'DanioRerio' if $name =~ /danio/;
172  ##hack - should use own modules
173  return 'HomoSapiens' if $name =~ /sus/;
174  die "invalid name of source database, please check configuration file";
175 }
176 
177 =head2 choose_conversion_type
178 
179  Example : $conversion->choose_conversion_type
180  Description : compares conversion type (ensembl or vega) and species type with
181  available modules and chooses that to use for the conversion. Stores
182  a converter object within the caller
183  Return type : none
184  Exceptions : none
185  Caller : $Siteroot/utils/vega_schema_conversion
186 
187 =cut
188 
189 sub choose_conversion_type {
190  my $self = shift;
191  my $converter;
192  my $species;
193 
194  $species = $self->species_alias($self->conv_support->param('source_db'));
195  if ($self->conv_support->param('do_vega_sc')) {
196  $species = "vega::".$species;
197  eval "require SeqStoreConverter::$species"; ## no critic
198  if($@) {
199  warn("Could not require conversion module SeqStoreConverter::$species\ for vega conversion\n" .
200  "Using SeqStoreConverter::BasicConverter instead:\n$@");
202  $species = "BasicConverter";
203  }
204  else {
205  warn "Using conversion module SeqStoreConverter::$species for vega conversion\n";
206  }
207  }
208  else {
209  eval "require SeqStoreConverter::$species"; ## no critic
210  if($@) {
211  warn("Could not require conversion module SeqStoreConverter::$species for Ensembl conversion\n" .
212  "Using SeqStoreConverter::BasicConverter instead:\n$@");
214  $species = "BasicConverter";
215  }
216  else {
217  warn "Using conversion module SeqStoreConverter::$species for Ensembl conversion\n";
218  }
219  $self->conv_support->param('vega_sql',0);
220  }
221  $converter = "SeqStoreConverter::$species"->new
222  ( $self->conv_support->param('user'),
223  $self->conv_support->param('pass'),
224  $self->conv_support->param('host').':'.$self->conv_support->param('port'),
225  $self->conv_support->param('source_db'),
226  $self->conv_support->param('dbname'),
227  $self->conv_support->param('core_sql'),
228  $self->conv_support->param('vega_sql'),
229  $self->conv_support->param('force'),
230  $self->conv_support->param('verbose'),
231  '',
232  );
233 
234  $self->{'converter_object'} = $converter;
235 }
236 
237 =head2 do_conversion
238 
239  Example : $conversion->do_conversion
240  Description : does the database conversion
241  Return type : none
242  Exceptions : none
243  Caller : $Siteroot/utils/vega_schema_conversion
244 
245 =cut
246 
247 
248 sub do_conversion {
249  my $self= shift;
250  $self->conv_obj->debug( "\n\n*** converting " . $self->conv_obj->source . " to " .
251  $self->conv_obj->target() . " ***");
252  $self->conv_obj->transfer_meta();
253  $self->conv_obj->create_coord_systems();
254  $self->conv_obj->create_seq_regions();
255  $self->conv_obj->create_assembly();
256  $self->conv_obj->create_attribs();
257  $self->conv_obj->set_top_level();
258  $self->conv_obj->transfer_dna();
259  $self->conv_obj->back_patch_schema();
260  $self->conv_obj->transfer_genes();
261  $self->conv_obj->transfer_prediction_transcripts();
262 
263  if ($self->conv_support->param('do_features')) {
264  $self->conv_obj->transfer_features();
265  }
266 #use this for both ensembl and vega for now,
267 #but might need changing when vega gets eg transcript modified dates
268  $self->conv_obj->transfer_vega_stable_ids();
269  $self->conv_obj->copy_other_tables();
270  $self->conv_obj->copy_repeat_consensus();
271  $self->conv_obj->create_meta_coord();
272  if ($self->conv_support->param('do_vega_sc')) {
273  $self->conv_obj->copy_other_vega_tables();
274  $self->conv_obj->update_clone_info();
275  $self->conv_obj->remove_supercontigs();
276  $self->conv_obj->copy_internal_clone_names();
277  $self->conv_obj->copy_assembly_exception;
278  }
279 }
280 
281 =head2 make_schema_up_to_date
282 
283  Example : $conversion->make_schema_up_to_date
284  Description : patches schema to latest version
285  Return type : none
286  Exceptions : none
287  Caller : $conversion
288 
289 =cut
290 
291 sub make_schema_up_to_date {
292  my $self = shift;
293  $self->conv_obj->debug ("\nPatching schema to latest version\n");
294  my $user = $self->conv_obj->user;
295  my $pass = $self->conv_obj->password;
296  my $port = $self->conv_obj->port;
297  my $host = $self->conv_obj->host;
298  my $target = $self->conv_obj->target;
299  my $patch_schema = $self->conv_support->param('patch_sql');
300  my $cmd = "/usr/local/mysql/bin/mysql -u $user -p$pass -P $port -h $host $target < $patch_schema";
301  system ($cmd);
302 }
303 
304 
305 
306 =head2 conv_usage
307 
308  Example : $conversion->conv_usage("message")
309  Description : prints usage information and exits
310  Return type : none
311  Exceptions : none
312  Caller : $Siteroot/utils/vega_schema_conversion
313 
314 =cut
315 
316 sub conv_usage {
317  my $self = shift;
318  my $msg = shift;
319 
320  print STDERR "\nMSG: $msg\n" if($msg);
321 
322  print STDERR <<EOF;
323 
324 ** Source and target databases must be on the same mysql instance
325 
326 usage: ./conversion_densities.pl <options>
327 
328 options: --conf <conf_file> configuration file (uses conf/Conversion.ini by default):
329 
330  fields:
331  do_vega_sc (do vega conversion: 0 or 1)
332  do_ens_sc (do ensembl conversion: 0 or 1)
333  user (a mysql db user with read/write priveleges)
334  host (eg ecs3f)
335  port (eg 3310)
336  source_db (schema 19 source database)
337  dbname (schema 20+ target database)
338  force (overwrite existing target database: 0 or 1)
339  verbose (print out debug statements: 0 or 1)
340  logpath (location of log file)
341  do_features (transfer dna- and protein-align features, for debugging: 0 or 1)
342  core_sql (location of ensembl schema creation script: ensembl/sql/table.sql)
343  vega_sql (location of creation script for additional vega tables: ensembl/sql/vega_specific_tables.sql)
344  patch_sql (location of schema patching script: ensembl/sql/vega_latest_schema.sql)
345 
346  --log name of log_file
347  --help display this message
348 
349 EOF
350  exit;
351 
352 }
353 
354 1;
355 
356 
357 
usage
public usage()
Bio::EnsEMBL::Utils::ConversionSupport
Definition: ConversionSupport.pm:39
Bio::EnsEMBL::Utils::SchemaConversion
Definition: SchemaConversion.pm:29
Bio::EnsEMBL::Utils::ConversionSupport::parse_common_options
public Boolean parse_common_options()
debug
public debug()
SeqStoreConverter::BasicConverter::new
public new()
Bio::EnsEMBL::Utils::ConversionSupport::new
public Bio::EnsEMBL::Utils::ConversionSupport new()
SeqStoreConverter::BasicConverter
Definition: BasicConverter.pm:3