10 to understand how
this particular example pipeline is configured and
run.
14 Kmer::RunnableDB::CompileCounts is the last runnable in the kmer counting pipeline (
using an array of hashes Accumulator).
15 This runnable fetches kmer counts that the previous jobs stored in the hash Accumulator, and combines them to determine
16 the overall kmer counts from the sequences in the original input file.
20 See the NOTICE file distributed with
this work
for additional information
21 regarding copyright ownership.
23 Licensed under the Apache License, Version 2.0 (the
"License"); you may not use
this file except in compliance with the License.
24 You may obtain a copy of the License at
28 Unless required by applicable law or agreed to in writing, software distributed under the License
29 is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30 See the License
for the specific language governing permissions and limitations under the License.
34 Please subscribe to the Hive mailing list: http:
39 package Bio::EnsEMBL::Hive::Examples::Kmer::RunnableDB::CompileCountsHoH;
44 use base (
'Bio::EnsEMBL::Hive::Process');
49 Description : Implements param_defaults()
interface method of
Bio::EnsEMBL::Hive::Process that defines module defaults for parameters.
59 Description : Implements fetch_input()
interface method of
Bio::EnsEMBL::Hive::Process that is used to read in parameters and load data.
60 In this runnable, fetch_input is left empty. It fetches data from a hive Accumulator, so there are no extra database
61 connections to open, nor files to check. It's more sensible to fetch data from the Accumulator in
run, where it's needed
62 rather than to fetch it here, then pass it along in another parameter.
72 Description : Implements
run()
interface method of
Bio::EnsEMBL::Hive::Process that is used to perform the
main bulk of the job (minus input and output).
74 In this method, we fetch kmer counts produced by previous jobs and stored in an Accumulator. We sum up the
75 number of times each kmer is found over all the chunks, and store the sums in a param. Storing the results
76 in a param makes them available to other methods in this runnable -- specifically write_output.
78 This method expects counts to be stored in the accumulator as an hash of hashes. The key in the top-level hash (in fact ignored in this
79 Runnable) is the name of the file in which kmers were counted. This is not necessarily the same file as the input file since the latter
80 is broken down in smaller pieces by chunk_sequence or split_sequence. The value in the top-level hash is itself a hash representing the
81 kmer counts in this chunk file; the key
82 being the kmer sequence, and the value being the count (e.g. {'ACGT' => 5, 'CCGG' => 3, ...}). This second-level hash can be either taken
83 as a whole from a
CountKmers job, or assembled from all the individual counts generated by a
CountKmers job. See KmerPipelineHoH_conf.pm
84 for more information regarding the configuration of the accumulator.
91 # Create a hash where we can add up counts for each kmer from each previous CountKmers job to determine overall total counts.
94 # Accessing the Accumulator by it's name ('all_counts'), as a param.
95 # We get an arrayref back.
96 my $all_counts = $self->param(
'all_counts');
98 # Loop through all the results from each individual CountKmers job.
99 foreach my $count_kmers_result (values %{$all_counts}) {
101 # for each CountKmers result, retrieve the count for each particular kmer, and add to our total.
102 foreach my $kmer (keys %{$count_kmers_result}) {
103 $sum_of_counts{$kmer} += $count_kmers_result->{$kmer};
107 # Finally, store our total counts for each kmer in a param called 'sum_of_counts', making them available to other methods
108 $self->param(
'sum_of_counts', \%sum_of_counts);
113 Description : Implements write_output() interface method of
Bio::
EnsEMBL::Hive::Process that is used to deal with job's output after the execution.
115 Here, we flow out three values:
116 * filename -- name of the sequence file given at the start of the pipeline
117 * kmer -- the kmer being counted
118 * count -- count of that kmer across the entire original input
123 my $self = shift(@_);
125 my $sum_of_counts = $self->param(
'sum_of_counts');
127 foreach my $kmer (keys(%{$sum_of_counts})) {
128 $self->dataflow_output_id({
129 'filename' => $self->param(
'inputfile'),
131 'count' => $sum_of_counts->{$kmer}