ensembl-hive  2.7.0
CompileCountsHoH.pm
Go to the documentation of this file.
1 =pod
2 
3 =head1 NAME
4 
6 
7 =head1 SYNOPSIS
8 
9  Please refer to Bio::EnsEMBL::Hive::Examples::Kmer::PipeConfig::KmerPipelineHoH_conf pipeline configuration file
10  to understand how this particular example pipeline is configured and run.
11 
12 =head1 DESCRIPTION
13 
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.
17 
18 =head1 LICENSE
19 
20  See the NOTICE file distributed with this work for additional information
21  regarding copyright ownership.
22 
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
25 
26  http://www.apache.org/licenses/LICENSE-2.0
27 
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.
31 
32 =head1 CONTACT
33 
34  Please subscribe to the Hive mailing list: http://listserver.ebi.ac.uk/mailman/listinfo/ehive-users to discuss Hive-related questions or to be notified of our updates
35 
36 =cut
37 
38 
39 package Bio::EnsEMBL::Hive::Examples::Kmer::RunnableDB::CompileCountsHoH;
40 
41 use strict;
42 use warnings;
43 
44 use base ('Bio::EnsEMBL::Hive::Process');
45 
46 
47 =head2 param_defaults
48 
49  Description : Implements param_defaults() interface method of Bio::EnsEMBL::Hive::Process that defines module defaults for parameters.
50 
51 =cut
52 
53 sub param_defaults {
54 }
55 
56 
57 =head2 fetch_input
58 
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.
63 
64 =cut
65 
66 sub fetch_input {
67 
68 }
69 
70 =head2 run
71 
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).
73 
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.
77 
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.
85 
86 =cut
87 
88 sub run {
89  my $self = shift @_;
90 
91  # Create a hash where we can add up counts for each kmer from each previous CountKmers job to determine overall total counts.
92  my %sum_of_counts;
93 
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');
97 
98  # Loop through all the results from each individual CountKmers job.
99  foreach my $count_kmers_result (values %{$all_counts}) {
100 
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};
104  }
105  }
106 
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);
109 }
110 
111 =head2 write_output
112 
113  Description : Implements write_output() interface method of Bio::EnsEMBL::Hive::Process that is used to deal with job's output after the execution.
114 
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
119 
120 =cut
121 
122 sub write_output {
123  my $self = shift(@_);
124 
125  my $sum_of_counts = $self->param('sum_of_counts');
126 
127  foreach my $kmer (keys(%{$sum_of_counts})) {
128  $self->dataflow_output_id({
129  'filename' => $self->param('inputfile'),
130  'kmer' => $kmer,
131  'count' => $sum_of_counts->{$kmer}
132  }, 4);
133  }
134 }
135 
136 1;
EnsEMBL
Definition: Filter.pm:1
Bio::EnsEMBL::Hive::Examples::Kmer::RunnableDB::CountKmers
Definition: CountKmers.pm:30
Bio::EnsEMBL::Hive::Version
Definition: Version.pm:19
Bio::EnsEMBL::Hive::Examples::Kmer::RunnableDB::CompileCountsHoH
Definition: CompileCountsHoH.pm:21
Bio::EnsEMBL::Hive::Process
Definition: Process.pm:77
main
public main()
Bio::EnsEMBL::Hive::Accumulator
Definition: Accumulator.pm:11
run
public run()
Bio::EnsEMBL::Hive::Examples::Kmer::PipeConfig::KmerPipelineHoH_conf
Definition: KmerPipelineHoH_conf.pm:66
Bio::EnsEMBL::Hive
Definition: Hive.pm:38
Bio
Definition: AltAlleleGroup.pm:4