EnsEMBL/Utils/SchemaConversion.pm untested

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