ensembl-hive  2.7.0
dump_by_seq_region.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 # Don't change the above line.
18 # Change the PATH in the myRun.ksh script if you want to use another perl.
19 
20 =head1 NAME
21 
22 
23 =head1 SYNOPSIS
24 
25 .pl [arguments]
26 
27 Required arguments:
28 
29  --dbname, db_name=NAME database name NAME
30  --host, --dbhost, --db_host=HOST database host HOST
31  --port, --dbport, --db_port=PORT database port PORT
32  --user, --dbuser, --db_user=USER database username USER
33  --pass, --dbpass, --db_pass=PASS database passwort PASS
34 
35 Optional arguments:
36 
37  --conffile, --conf=FILE read parameters from FILE
38  (default: conf/Conversion.ini)
39 
40  --logfile, --log=FILE log to FILE (default: *STDOUT)
41  --logpath=PATH write logfile to PATH (default: .)
42  --logappend, --log_append append to logfile (default: truncate)
43  --loglevel=LEVEL define log level (default: INFO)
44 
45  -i, --interactive=0|1 run script interactively (default: true)
46  -n, --dry_run, --dry=0|1 don't write results to database
47  -h, --help, -? print help (this message)
48 
49 =head1 DESCRIPTION
50 
51 
52 
53 =head1 AUTHOR
54 
55 Patrick Meidl <meidl@ebi.ac.uk>, Ensembl core API team
56 
57 =head1 CONTACT
58 
59 Please post comments/questions to the Ensembl development list
60 <http://lists.ensembl.org/mailman/listinfo/dev>
61 
62 =cut
63 
64 use strict;
65 use warnings;
66 no warnings 'uninitialized';
67 
68 use FindBin qw($Bin);
69 use Bio::EnsEMBL::Utils::ConfParser;
70 use Bio::EnsEMBL::Utils::Logger;
71 use Bio::EnsEMBL::Utils::ScriptUtils qw(inject path_append);
72 use Bio::EnsEMBL::Utils::Exception qw(throw warning);
73 
74 # parse configuration and commandline arguments
75 my $conf = new Bio::EnsEMBL::Utils::ConfParser(
76  -SERVERROOT => "$Bin/../../..",
77  -DEFAULT_CONF => "$Bin/default.conf"
78 );
79 
80 $conf->parse_options(
81  'sourcehost|source_host=s' => 1,
82  'sourceport|source_port=n' => 1,
83  'sourceuser|source_user=s' => 1,
84  'sourcepass|source_pass=s' => 0,
85  'sourcedbname|source_dbname=s' => 1,
86  'targethost|target_host=s' => 1,
87  'targetport|target_port=n' => 1,
88  'targetuser|target_user=s' => 1,
89  'targetpass|target_pass=s' => 0,
90  'targetdbname|target_dbname=s' => 1,
91  'basedir|basedir=s' => 1,
92  'biotypes=s@' => 0,
93  'biotypes_include=s@' => 0,
94  'biotypes_exclude=s@' => 0,
95  'dbtype=s' => 1,
96  'cache_impl=s' => 1,
97  'index|i=n' => 1,
98 );
99 
100 # set default logpath
101 unless ($conf->param('logpath')) {
102  $conf->param('logpath', path_append($conf->param('basedir'), 'log'));
103 }
104 # log to a subdirectory to prevent clutter
105 $conf->param('logpath', path_append($conf->param('logpath'),
106  'dump_by_seq_region'));
107 
108 # append job index to logfile name
109 my $dbtype = $conf->param('dbtype');
110 my $index = $conf->param('index');
111 my $logautobase = ($conf->param('logautobase') || 'dump_by_seq_region').
112  ".$dbtype";
113 
114 # get log filehandle and print heading and parameters to logfile
115 my $logger = new Bio::EnsEMBL::Utils::Logger(
116  -LOGFILE => $conf->param('logfile'),
117  -LOGAUTO => $conf->param('logauto'),
118  -LOGAUTOBASE => $logautobase,
119  -LOGAUTOID => $conf->param('logautoid'),
120  -LOGPATH => $conf->param('logpath'),
121  -LOGAPPEND => 1,
122  -LOGLEVEL => $conf->param('loglevel'),
123  -IS_COMPONENT => 1,
124 );
125 
126 # build cache
127 my $cache_impl = $conf->param('cache_impl');
128 inject($cache_impl);
129 
130 my $cache = $cache_impl->new(
131  -LOGGER => $logger,
132  -CONF => $conf,
133 );
134 
135 # determine which slice to process. to do so, read the file containing the
136 # slices to be processed, and take the one at position $index
137 my $logpath = $conf->param('logpath');
138 my $filename = "$dbtype.dump_cache.slices.txt";
139 open(my $fh, '<', "$logpath/$filename") or
140  throw("Unable to open $logpath/$filename for reading: $!");
141 my @slice_names = <$fh>;
142 my $slice_name = $slice_names[$index-1];
143 chomp($slice_name);
144 close($fh);
145 
146 # no build the cache for this slice
147 $cache->build_cache_by_slice($dbtype, $slice_name);
148 
149 # set flag to indicate everything went fine
150 my $success_file = $conf->param('logpath')."/$logautobase.$index.success";
151 open(TMPFILE, '>', $success_file) and close TMPFILE
152  or throw "Can't open $success_file for writing: $!";
153 
run
public run()