13 Runnable that takes a list of input_ids (
"input_id_list"), removes some elements from it that are dataflown to branch #2
14 whilst the remainder of the list is dataflown is dataflown to branch #1. Several things can be parametrized: the number
15 of elements taken from the list (on each end) and to which branch they are flown.
17 consume the list one element at a time and compute something along the way.
21 See the NOTICE file distributed with
this work
for additional information
22 regarding copyright ownership.
24 Licensed under the Apache License,
Version 2.0 (the
"License"); you may not use
this file except in compliance with the License.
25 You may obtain a copy of the License at
29 Unless required by applicable law or agreed to in writing, software distributed under the License
30 is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 See the License
for the specific language governing permissions and limitations under the License.
35 Please subscribe to the
Hive mailing list: http:
36 to discuss
Hive-related questions or to be notified of our updates
41 package Bio::EnsEMBL::Hive::Examples::Factories::RunnableDB::GrabN;
46 use base (
'Bio::EnsEMBL::Hive::Process');
51 'grab_n_left' => 1, # How many elements to take from the left-end of the list (
"shift")
52 'grab_n_right' => 0, # How many elements to take from the right-end of the list (
"pop")
53 'fan_branch_code' => 2, # On which branch flow the elements
59 Description : Implements fetch_input()
interface method of
Bio::EnsEMBL::Hive::Process that is used to read in parameters and load data.
60 This reads the list of hash "input_id_list" and extracts as many elements as requested (following the "grab_n_left" and
61 "grab_n_right" parameters) and push them to the "output_ids" array parameter. This represents the input_ids of the jobs
69 my $input_id_list = $self->param_required(
'input_id_list');
70 my $grab_n_left = $self->param_required(
'grab_n_left');
71 my $grab_n_right = $self->param_required(
'grab_n_right');
73 die
"Negative values are not allowed for 'grab_n_left'\n" if $grab_n_left < 0;
74 die
"Negative values are not allowed for 'grab_n_right'\n" if $grab_n_right < 0;
77 if ($grab_n_left+$grab_n_right <= scalar(@$input_id_list)) {
78 push @output_ids, splice(@$input_id_list, 0, $grab_n_left);
79 push @output_ids, splice(@$input_id_list, -$grab_n_right, $grab_n_right);
83 @output_ids = @$input_id_list;
87 $self->param(
'output_ids', \@output_ids);
93 Description : Implements write_output()
interface method of
Bio::EnsEMBL::Hive::Process that is used to deal with job's output after the execution.
94 This flows all the elements (hashes) of "output_ids" to the branch refered by "fan_branch_code" (default #2)
95 It then flows to branch #1 the remainder of the list, and a "_list_exhausted" flag that tells whether the list is now empty or not.
102 my $output_ids = $self->param_required(
'output_ids');
103 my $input_id_list = $self->param_required(
'input_id_list');
104 my $fan_branch_code = $self->param_required(
'fan_branch_code');
106 # Fan out the jobs (if any)
107 $self->dataflow_output_id($output_ids, $fan_branch_code)
if @$output_ids;
109 # Collector job. This dataflow replaces the autoflow
110 $self->dataflow_output_id({
'_list_exhausted' => !scalar(@$input_id_list),
'input_id_list' => $input_id_list}, 1);