13 This RunnableDB module acts as a wrapper around a database connection. It interfaces with the database the same way as you would
14 on the command line (i.e. with redirections and / or pipes to other commands) but with hive parameters instead.
15 The database connection is created from the
"data_dbc" parameter,
if provided, or the current hive database.
17 =head1 CONFIGURATION EXAMPLE
20 # The following examples show how to configure SystemCmd in a PipeConfig module.
23 # The most common use-case is to apply a SQL script onto the current database
25 { -logic_name =>
'write_member_counts',
26 -module =>
'Bio::EnsEMBL::Hive::RunnableDB::DbCmd',
28 'input_file' => $self->o(
'ensembl_cvs_root_dir').
'/ensembl-compara/scripts/production/populate_member_production_counts_table.sql',
30 -flow_into => [
'notify_pipeline_completed' ],
34 # You can also use the advanced parameters to run a query on the
35 # database with the db_cmd.pl and pipe its output onto another command
36 # e.g. mysql -h... -u... curr_db_name -N -q -e 'select * from mcl_sparse_matrix' | #mcl_bin_dir#/mcxload -abc ...
38 { -logic_name =>
'mcxload_matrix',
39 -module =>
'Bio::EnsEMBL::Hive::RunnableDB::DbCmd',
41 'append' => [qw(-N -q)],
42 'input_query' =>
'select * from mcl_sparse_matrix',
43 'command_out' => [qw(#mcl_bin_dir#/mcxload -abc - -ri max -o #work_dir#/#file_basename#.tcx -write-tab #work_dir#/#file_basename#.itab)],
45 -flow_into => [
'mcl' ],
49 # Finally, you can run another executable (like mysqlimport) with its
50 # own parameters onto another database (specified by 'db_conn')
52 { -logic_name =>
'populate_method_links_from_file',
53 -module =>
'Bio::EnsEMBL::Hive::RunnableDB::DbCmd',
55 'db_conn' =>
'#rel_db#',
56 'method_link_dump_file' => $self->o(
'method_link_dump_file'),
57 'executable' =>
'mysqlimport',
58 'append' => [
'#method_link_dump_file#' ],
60 -flow_into => [
'load_all_genomedbs' ],
65 Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
66 Copyright [2016-2024] EMBL-European Bioinformatics Institute
68 Licensed under the Apache License, Version 2.0 (the
"License"); you may not use
this file except in compliance with the License.
69 You may obtain a copy of the License at
73 Unless required by applicable law or agreed to in writing, software distributed under the License
74 is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
75 See the License
for the specific language governing permissions and limitations under the License.
79 Please subscribe to the Hive mailing list: http:
84 package Bio::EnsEMBL::Hive::RunnableDB::DbCmd;
91 # This runnable is simply a SystemCmd specialized for database commands
93 use base (
'Bio::EnsEMBL::Hive::RunnableDB::SystemCmd');
99 %{$self->SUPER::param_defaults(@_)},
100 'executable' => undef,
103 'input_file' => undef,
104 'input_query' => undef,
105 'output_file' => undef,
106 'command_in' => undef,
107 'command_out' => undef,
114 Description : Implements fetch_input() interface method of
Bio::
EnsEMBL::Hive::Process that is used to read in parameters and load data.
115 Here it deals with finding the command line, doing parameter substitution and storing the result in a predefined place.
117 param('cmd'): The recommended way of passing in the command line. It can be either a
string, or an array-ref of strings. The later is safer if some of the
118 arguments contain white-spaces.
120 param('*'): Any other parameters can be freely used for parameter substitution.
127 # Validate the arguments
128 # There can be only 1 input
129 if (not $self->param(
'executable') and not ($self->param(
'input_file') or $self->param(
'input_query') or $self->param(
'command_in'))) {
130 die
"No input defined (missing 'input_file', 'input_query' and 'command_in')\n";
131 } elsif (($self->param(
'input_file') and ($self->param(
'input_query') or $self->param(
'command_in'))) or ($self->param(
'input_query') and $self->param(
'command_in'))) {
132 die
"Only 1 input ('input_file', 'input_query' and 'command_in') can be defined\n";
135 if ($self->param(
'output_file') and $self->param(
'command_out')) {
136 die
"'output_file' and 'command_out' cannot be set together\n";
139 # If there is any of those, system() will need a shell to deal with
140 # the pipes / redirections, and we need to hide the passwords
141 my $need_a_shell = ($self->param(
'input_file') or $self->param(
'command_in') or $self->param(
'output_file') or $self->param(
'command_out')) ? 1 : 0;
143 my @cmd = @{ $self->data_dbc->to_cmd(
144 $self->param(
'executable'),
145 [grep {defined $_} @{$self->param(
'prepend')}],
146 [grep {defined $_} @{$self->param(
'append')}],
147 $self->param(
'input_query'),
153 if ($self->param(
'input_file')) {
154 push @cmd,
'<', $self->param(
'input_file');
155 } elsif ($self->param(
'input_query')) {
156 # the query as already been fed into @cmd by to_cmd()
157 } elsif ($self->param(
'command_in')) {
158 $prefix = (join_command_args($self->param(
'command_in')))[1] .
' | ';
161 # Add the output data
163 if ($self->param(
'output_file')) {
164 push @cmd,
'>', $self->param(
'output_file');
165 } elsif ($self->param(
'command_out')) {
166 $postfix =
' | ' . (join_command_args($self->param(
'command_out')))[1];
170 my ($join_needed, $flat_cmd) = join_command_args(\@cmd);
171 $flat_cmd =~ s/
'(\S*\$EHIVE_TMP_PASSWORD_\d+)' / $1 /g;
172 $self->param(
'cmd', $prefix.$flat_cmd.$postfix);
174 $self->param(
'cmd', \@cmd);