Seeder/Index.pm

filter: Statementstmt 100% 54 / 54 Branchbran 50.0% 3 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 95.8% 69 / 72 CC 7 SCAR 7.6
CC
7
Cov
95%
new
3.1
_output_index
3.0
_generate_index
3.0
CRAP 2.1
« Seeder.pm ↑ Summary ._Seeder.pm »
1 package Seeder::Index;
2  
3 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Seeder qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 our @EXPORT;
11 2 our %EXPORT_TAGS = (
12 'all' => [
13 qw(
14 new
15 get_index
16 )
17 ]
18 );
19 2 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
20  
21 =head1 NAME
22  
23 Seeder::Index - Index object
24  
25 =head1 VERSION
26  
27 Version 0.01
28  
29 =cut
30  
31 2 our $VERSION = '0.01';
32  
33 =head1 DESCRIPTION
34  
35 This module provides the get_index method.
36  
37 =head1 SYNOPSIS
38  
39 use Seeder::Index;
40 my $index = Seeder::Index->new(
41 seed_width => "6",
42 out_file => "6.index",
43 );
44 $index -> get_index;
45  
46 =head1 EXPORT
47  
48 None by default
49  
50 =head1 FUNCTIONS
51  
52 =head2 new
53  
54 Title : new
55 Usage : my $index = Seeder::Index->new(%args);
56 Function: constructor for the Seeder::Index object
57 Returns : new Seeder::Index object
58 Args :
59 seed_width # Seed width
60 out_file # Output file
61  
62 =cut
63  
64 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.2
Pod documented
65 1 my ( $class, %args ) = @_;
66 1 my $self;
67 $self->{seed_width} =
68 defined $args{seed_width}
69 ? $args{seed_width}
70 1 ▶ : croak "Please define a seed width!";
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'seed_width'} ? : 1 0 1
71 $self->{out_file} =
72 defined $args{out_file}
73 ? $args{out_file}
74 1 ▶ : croak "Please define an output file!";
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'out_file'} ? : 1 0 1
75 1 bless( $self, $class );
76 1 return $self;
77 }
78  
79 =head2 get_index
80  
81 Title : get_background
82 Usage : $background -> get_background;
83 Function: coordination of the collection of index values
84 Args : none
85  
86 =cut
87  
88 1 ▶sub get_index {
Subroutine get_index: called CC=1 SCAR=0.0
Pod documented
89 1 my $self = shift;
90 1 $self->generate_oligo;
91 1 $self->lookup_coord;
92 1 $self->_generate_index;
93 1 $self->_output_index;
94 }
95  
96 =head2 _generate_index
97  
98 Title : _generate_index
99 Usage : $self->_generate_index;
100 Function: generate an index of neighbors for Hamming distances in the range
101 from 0 to 3
102 Returns : reference to a 2D array of indices
103 Args : none
104  
105 =cut
106  
107 1 ▶sub _generate_index {
Subroutine _generate_index: called CC=3 SCAR=11.0
108 1 my $self = shift;
109 1 my @index;
110 1 for my $oligo_indice ( 0 .. $#{ $self->{oligo_ref} } ) {
111 4096 my @indices;
112 my $generated = $self->generate_hd_index(
113 4096 \@{ $self->{oligo_ref}->[$oligo_indice] } );
114 4096 for my $depth ( 0 .. 3 ) {
115 push @indices,
116 (
117 10808960 sort { $a <=> $b } @$generated[
118 $self->{from_ref}->[ $self->{seed_width} - 1 ][$depth]
119 16384 .. $self->{to_ref}->[ $self->{seed_width} - 1 ][$depth]
120 ]
121 );
122 }
123 4096 push @index, [@indices];
124 }
125 1 $self->{index_ref} = \@index;
126 1 return \@index;
127 }
128  
129 =head2 _output_index
130  
131 Title : _output_index
132 Usage : $self->_output_index;
133 Function: writes index to output file
134 Args : none
135  
136 =cut
137  
138 1 ▶sub _output_index {
Subroutine _output_index: called CC=3 SCAR=11.0
139 1 my $self = shift;
140 1 ▶ open( OUT, ">>$self->{out_file}" )
Branch: 1 branch
BranchTrueFalseTotal
open OUT, qq[>>$self->{"out_file"}] or croak(qq[Cannot open $self->{"out_file"}\n]) 1 0 1
141 or croak "Cannot open $self->{out_file}\n";
142 1 for my $oligo_indice ( 0 .. $#{ $self->{index_ref} } ) {
143 4096 print( OUT "@{$self->{index_ref}->[$oligo_indice]}\n" );
144 }
145 1 close OUT;
146 }
147  
148 =head1 AUTHOR
149  
150 François Fauteux, C<< <ffauteux at cpan.org> >>
151  
152 =head1 BUGS
153  
154 Please report any bugs or feature requests to C<bug-motif at rt.cpan.org>, or
155 at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Seeder>. I will be
156 notified, and then you'll automatically be notified of progress on your bug as
157 I make changes.
158  
159 =head1 SUPPORT
160  
161 You can find documentation for this module with the perldoc command.
162  
163 perldoc Seeder
164  
165 You can also look for information at:
166  
167 =over 4
168  
169 =item * RT: CPAN's request tracker
170  
171 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Seeder>
172  
173 =item * AnnoCPAN: Annotated CPAN documentation
174  
175 L<http://annocpan.org/dist/Seeder>
176  
177 =item * CPAN Ratings
178  
179 L<http://cpanratings.perl.org/d/Seeder>
180  
181 =item * Search CPAN
182  
183 L<http://search.cpan.org/dist/Seeder>
184  
185 =back
186  
187 =head1 ACKNOWLEDGEMENTS
188  
189 This algorithm was developed by François Fauteux, Mathieu Blanchette and
190 Martina Strömvik. We thank the Perl Monks <http://www.perlmonks.org/> for
191 their support.
192  
193 =head1 COPYRIGHT & LICENSE
194  
195 Copyright 2008 François Fauteux, all rights reserved.
196  
197 This program is free software; you can redistribute it and/or modify it
198 under the same terms as Perl itself.
199  
200 =cut
201  
202 2 1; # End of Seeder::Index
« Seeder.pm ↑ Summary ._Seeder.pm »