ensembl-hive  2.7.0
generate_graph.pl
Go to the documentation of this file.
1 #!/usr/bin/env perl
2 
3 use strict;
4 use warnings;
5 
6  # Finding out own path in order to reference own components (including own modules):
7 use Cwd ();
8 use File::Basename ();
9 BEGIN {
10  $ENV{'EHIVE_ROOT_DIR'} ||= File::Basename::dirname( File::Basename::dirname( Cwd::realpath($0) ) );
11  unshift @INC, $ENV{'EHIVE_ROOT_DIR'}.'/modules';
12 }
13 
14 use Getopt::Long qw(:config pass_through no_auto_abbrev);
15 use Pod::Usage;
16 
18 use Bio::EnsEMBL::Hive::Utils ('load_file_or_module');
21 
23 
24 main();
25 
26 
27 sub main {
28 
29  my $self = {};
30 
31  GetOptions(
32  # connection parameters
33  'url=s' => \$self->{'url'},
34  'reg_conf|reg_file=s' => \$self->{'reg_conf'},
35  'reg_type=s' => \$self->{'reg_type'},
36  'reg_alias|reg_name=s' => \$self->{'reg_alias'},
37  'nosqlvc' => \$self->{'nosqlvc'}, # using "nosqlvc" instead of "sqlvc!" for consistency with scripts where it is a propagated option
38 
39  # json config files
40  'config_file=s@' => \$self->{'config_files'},
41 
42  'pipeconfig|pc=s@' => \$self->{'pipeconfigs'}, # now an array
43 
44  'f|format=s' => \$self->{'format'},
45  'o|out|output=s' => \$self->{'output'},
46 
47  'h|help' => \$self->{'help'},
48  );
49 
50  if($self->{'help'}) {
51  pod2usage({-exitvalue => 0, -verbose => 2});
52  }
53 
54  if($self->{'url'} or $self->{'reg_alias'}) {
55  $self->{'pipeline'} = Bio::EnsEMBL::Hive::HivePipeline->new(
56  -url => $self->{'url'},
57  -reg_conf => $self->{'reg_conf'},
58  -reg_type => $self->{'reg_type'},
59  -reg_alias => $self->{'reg_alias'},
60  -no_sql_schema_version_check => $self->{'nosqlvc'},
61  );
62 
63  } else {
64  $self->{'pipeline'} = Bio::EnsEMBL::Hive::HivePipeline->new();
65  die "A pipeline has to be given, either via -url/-reg* or via -pipeconfig" unless $self->{'pipeconfigs'};
66  }
67 
68  foreach my $pipeconfig (@{ $self->{'pipeconfigs'} || [] }) {
69  my $pipeconfig_package_name = load_file_or_module( $pipeconfig );
70 
71  my $pipeconfig_object = $pipeconfig_package_name->new();
72  $pipeconfig_object->process_options( 0 );
73 
74  $pipeconfig_object->add_objects_from_config( $self->{'pipeline'} );
75  }
76 
77  if($self->{'output'} or $self->{'format'}) {
78 
79  if(!$self->{'format'}) {
80  if($self->{'output'}=~/\.(\w+)$/) {
81  $self->{'format'} = $1;
82  } else {
83  die "Format was not set and could not guess from ".$self->{'output'}.". Please use either way to select it.\n";
84  }
85  }
86 
87  if($self->{'format'} eq 'txt') {
88  local *STDOUT;
89 
90  open (STDOUT, '>', $self->{'output'}); # redirect STDOUT to $self->{'output'}
91 
92  $self->{'pipeline'}->print_diagram; # and capture the Unicode diagram in a text file
93 
94  } else {
96  $self->{'pipeline'},
97  $self->{'config_files'} ? @{ $self->{'config_files'} } : ()
98  );
99  my $graphviz = $graph->build();
100 
101  if( $self->{'format'} eq 'dot' ) { # If you need to take a look at the intermediate dot file
102  $graphviz->dot_input_filename( $self->{'output'} || \*STDOUT);
103  $graphviz->as_canon( '/dev/null' );
104 
105  } else {
106  my $call = 'as_'.$self->{'format'};
107  $graphviz->$call($self->{'output'} || \*STDOUT);
108  }
109  }
110 
111  } else {
112  $self->{'pipeline'}->print_diagram;
113 
114  print "\n";
115  print "----------------------------------------------------------\n";
116  print " Did you forget to specify the -output flowchart.png ? \n";
117  print "----------------------------------------------------------\n";
118  }
119 }
120 
121 
122 __DATA__
123 
124 =pod
125 
126 =head1 NAME
127 
128 generate_graph.pl
129 
130 =head1 SYNOPSIS
131 
132  generate_graph.pl -help
133 
134  generate_graph.pl [ -url mysql://user:pass@server:port/dbname | -reg_conf <reg_conf_file> -reg_alias <reg_alias> ] [-pipeconfig TopUp_conf.pm]* -output OUTPUT_LOC
135 
136 =head1 DESCRIPTION
137 
138 This program will generate a graphical representation of your eHive pipeline.
139 This includes visualising the flow of data from the different analyses, blocking
140 rules and table writers. The graph is also coloured to indicate the stage
141 an Analysis is at. The colours and fonts used can be configured via
142 hive_config.json configuration file.
143 
144 =head1 OPTIONS
145 
146 =over
147 
148 =item --url <url>
149 
150 URL defining where eHive database is located
151 
152 =item --reg_conf <path>
153 
154 path to a Registry configuration file
155 
156 =item --reg_alias <str>
157 
158 species/alias name for the eHive DBAdaptor
159 
160 =item --nosqlvc
161 
162 "No SQL Version Check" - set if you want to force working with a database created by a potentially schema-incompatible API
163 
164 =item --config_file <path>
165 
166 Path to JSON eHive config file
167 
168 =item --pipeconfig <path|module_name>
169 
170 A pipeline configuration file that can function both as the initial source of pipeline structure or as a top-up config.
171 This option can now be used multiple times for multiple top-ups.
172 
173 =item --format <str>
174 
175 (Optional) specify the output format, or override the output format specified by the output file's extension
176 (e.g. png, jpeg, dot, gif, ps)
177 
178 =item --output <path>
179 
180 Location of the file to write to.
181 The file extension (.png , .jpeg , .dot , .gif , .ps) will define the output format.
182 
183 =item --help
184 
185 Print this help message
186 
187 =back
188 
189 =head1 EXTERNAL DEPENDENCIES
190 
191 =over
192 
193 =item GraphViz
194 
195 =back
196 
197 =head1 LICENSE
198 
199  See the NOTICE file distributed with this work for additional information
200  regarding copyright ownership.
201 
202  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
203  You may obtain a copy of the License at
204 
205  http://www.apache.org/licenses/LICENSE-2.0
206 
207  Unless required by applicable law or agreed to in writing, software distributed under the License
208  is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
209  See the License for the specific language governing permissions and limitations under the License.
210 
211 =head1 CONTACT
212 
213 Please subscribe to the eHive mailing list: http://listserver.ebi.ac.uk/mailman/listinfo/ehive-users to discuss eHive-related questions or to be notified of our updates
214 
215 =cut
216 
Bio::EnsEMBL::Hive::Utils
Definition: Collection.pm:4
Bio::EnsEMBL::Hive::Utils::URL::hide_url_password
public Void hide_url_password()
Bio::EnsEMBL::Hive::Utils::URL
Definition: URL.pm:11
Bio::EnsEMBL::Hive::HivePipeline::new
public new()
Bio::EnsEMBL::Hive::Utils::Graph::new
public Graph new()
Bio::EnsEMBL::Hive::Utils::Graph
Definition: Graph.pm:26
Bio::EnsEMBL::Hive::HivePipeline
Definition: HivePipeline.pm:13
BEGIN
public BEGIN()
main
public main()
Bio::EnsEMBL::Hive::Utils::Graph::build
public The build()