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