ensembl-hive  2.7.0
InitPipeline.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 package Bio::EnsEMBL::Hive::Scripts::InitPipeline;
22 
23 use strict;
24 use warnings;
25 
27 use Bio::EnsEMBL::Hive::Utils ('load_file_or_module');
28 
29 
30 sub init_pipeline {
31  my ($file_or_module, $tweaks) = @_;
32 
33  my $pipeconfig_package_name = load_file_or_module( $file_or_module );
34 
35  my $pipeconfig_object = $pipeconfig_package_name->new();
36  die "PipeConfig $pipeconfig_package_name not created\n" unless $pipeconfig_object;
37  die "PipeConfig $pipeconfig_package_name is not a Bio::EnsEMBL::Hive::PipeConfig::HiveGeneric_conf\n" unless $pipeconfig_object->isa('Bio::EnsEMBL::Hive::PipeConfig::HiveGeneric_conf');
38 
39  print "> Parsing the command-line options.\n\n";
40  $pipeconfig_object->process_options( 1 );
41 
42  # Restore the password in the URL so that pipelines that need
43  # pipeline_url() don't see _EHIVE_HIDDEN_PASS
44  if ($pipeconfig_object->pipeline_url =~ /\$\{_EHIVE_HIDDEN_PASS\}/) {
45  my $real_password = $ENV{_EHIVE_HIDDEN_PASS};
46  $pipeconfig_object->root()->{'pipeline_url'} =~ s/\$\{_EHIVE_HIDDEN_PASS\}/$real_password/;
47  $pipeconfig_object->root()->{'pipeline_url'} =~ s/'//g;
48  }
49 
50  print "> Running the creation commands.\n\n";
51  $pipeconfig_object->run_pipeline_create_commands();
52 
53  my $pipeline = Bio::EnsEMBL::Hive::HivePipeline->new(
54  -url => $pipeconfig_object->pipeline_url(),
55  -no_sql_schema_version_check => !$pipeconfig_object->is_analysis_topup );
56 
57  my $hive_dba = $pipeline->hive_dba()
58  or die "HivePipeline could not be created for ".$pipeconfig_object->pipeline_url();
59  $hive_dba->dbc->requires_write_access();
60 
61  print "> Parsing the PipeConfig file and adding objects (this may take a while).\n\n";
62  $pipeconfig_object->add_objects_from_config( $pipeline );
63 
64  if($tweaks and @$tweaks) {
65  print "> Applying tweaks.\n\n";
66  my ($need_write, $msg_list_ref, $json) = $pipeline->apply_tweaks( $tweaks );
67  $pipeconfig_object->print_debug(join("", @$msg_list_ref), "\n");
68  }
69 
70  $pipeline->test_connections();
71 
72  print "> Storing the pipeline in the database.\n\n";
73  $pipeline->save_collections();
74 
75  print "Pipeline successfully stored at ", $pipeconfig_object->pipeline_url, " !\n\n";
76 
77  print $pipeconfig_object->useful_commands_legend();
78 
79  $hive_dba->dbc->disconnect_if_idle; # This is necessary because the current lack of global DBC caching may leave this DBC connected and prevent deletion of the DB in pgsql mode
80 
81  return $hive_dba->dbc->url;
82 }
83 
84 
85 1;
Bio::EnsEMBL::Hive::Utils
Definition: Collection.pm:4
Bio::EnsEMBL::Hive::Version
Definition: Version.pm:19
Bio::EnsEMBL::Hive::HivePipeline
Definition: HivePipeline.pm:13