CountATGC.pm 4.06 KB
Newer Older
1 2 3 4
=pod 

=head1 NAME

5
    Bio::EnsEMBL::Hive::Examples::GC::RunnableDB::CountATGC
6 7 8 9

=head1 SYNOPSIS

    Please refer to Bio::EnsEMBL::Hive::PipeConfig::GCPct_conf pipeline configuration file
10
    to see how this runnable fits into the %GC example pipeline.
11 12 13

=head1 DESCRIPTION

Brandon Walts's avatar
Brandon Walts committed
14 15 16
    'Bio::EnsEMBL::Hive::Examples::GC::RunnableDB::CountATGC' counts the occurrences of A/T and G/C bases in
    the sequences in a .fasta file. It takes a .fasta file with DNA sequences as input. It flows out two parameters:
    at_count and gc_count.
17 18 19

=head1 LICENSE

20
    Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
nwillhoft's avatar
nwillhoft committed
21
    Copyright [2016-2021] EMBL-European Bioinformatics Institute
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

    Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software distributed under the License
    is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and limitations under the License.

=head1 CONTACT

    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

=cut


39
package Bio::EnsEMBL::Hive::Examples::GC::RunnableDB::CountATGC;
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

use strict;
use warnings;

use Bio::SeqIO;

use base ('Bio::EnsEMBL::Hive::Process');


=head2 param_defaults

    Description : Implements param_defaults() interface method of Bio::EnsEMBL::Hive::Process that defines module defaults for parameters.

=cut

sub param_defaults {

    return {
        'take_time' => 0,   # how much time run() method will spend in sleeping state
    };
}


=head2 fetch_input

    Description : Implements fetch_input() interface method of Bio::EnsEMBL::Hive::Process that is used to read in parameters and load data.
Brandon Walts's avatar
Brandon Walts committed
66
                  There are no hard and fast rules on whether to fetch parameters in fetch_input(), or to wait until run() to fetch them.
Brandon Walts's avatar
Brandon Walts committed
67
                  In general, fetch_input() is a place to validate parameter existence and values for errors before the worker get set into RUN state 
Brandon Walts's avatar
Brandon Walts committed
68 69 70 71
                  from the FETCH_INPUT state.

                  In this case, we decide to try and open our input file in fetch_input(), so that it will fail early if there is a problem with the
                  file open operation.
72 73 74 75 76 77 78

=cut

sub fetch_input {
  my $self = shift @_;

    my $chunkfile = $self->param_required('chunk_name');
79 80
    my $chunk_in = Bio::SeqIO->new(-file => "$chunkfile");
    $self->param('chunk_in', $chunk_in);
81 82 83 84 85

}

=head2 run

Brandon Walts's avatar
Brandon Walts committed
86
    Description : Implements run() interface method of Bio::EnsEMBL::Hive::Process that is used to perform the main bulk of the job.
87
                  Here, we use the file opened in fetch_input, read in the sequences from the file, and tally up the number of 
Brandon Walts's avatar
Brandon Walts committed
88
                  AT and GC bases seen. We then store these in parameters named at_count and gc_count.
89 90 91

=cut

Brandon Walts's avatar
Brandon Walts committed
92
sub run { 
93 94 95 96
    my $self = shift @_;

    my $at_count = 0;
    my $gc_count = 0;
97
    foreach my $chunkseq ($self->param('chunk_in')->next_seq()) {
98 99 100 101 102 103 104 105 106 107 108 109 110
      my $seqstring = $chunkseq->seq();
      $at_count += @{[$seqstring =~ /([AaTt])/g]};
      $gc_count += @{[$seqstring =~ /([GgCc])/g]};
    }

    $self->param('at_count', $at_count);
    $self->param('gc_count', $gc_count);

    sleep( $self->param('take_time') );
}

=head2 write_output

111 112 113
    Description : Implements write_output() interface method of Bio::EnsEMBL::Hive::Process that is used to deal with  the 
                  job's output after the execution.
                  The AT and GC counts dataflow down branch 1 in two parameters: 'at_count' and 'gc_count'.
114 115 116 117 118 119 120

=cut

sub write_output {  # but this time we have something to store
    my $self = shift @_;

    $self->dataflow_output_id( {
Brandon Walts's avatar
Brandon Walts committed
121
				'at_count' => $self->param('at_count'),
122 123 124 125 126 127
				'gc_count' => $self->param('gc_count'),
    }, 1);
}

1;