Seeder/Finder.pm

filter: Statementstmt 10.7% 56 / 519 Branchbran 8.1% 8 / 98 Conditioncond 16.6% 2 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 40.0% 14 / 35 Podpod 100% 2 / 2 totaltotal 12.1% 82 / 673 CC 112 SCAR 45.2
CC
112
Cov
10%
_extend_motif
342.0
_build_hd_matrix
132.0
_mtc
132.0
CRAP 91.8
↑ Summary Seeder/Background.pm »
1 package Seeder::Finder;
2  
3 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
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 2 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Bio::SeqIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Bio::LiveSeq::DNA;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Bio::LiveSeq::SeqI;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use List::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use List::MoreUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Math::Spline;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 our @EXPORT;
18 2 our %EXPORT_TAGS = (
19 'all' => [
20 qw(
21 new
22 find_motifs
23 )
24 ]
25 );
26 2 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
27  
28 =head1 NAME
29  
30 Seeder::Finder - Finder object
31  
32 =head1 VERSION
33  
34 Version 0.01
35  
36 =cut
37  
38 2 our $VERSION = '0.01';
39  
40 =head1 DESCRIPTION
41  
42 This module provides the find_motifs method.
43  
44 =head1 SYNOPSIS
45  
46 use Seeder::Finder;
47 my $finder = Seeder::Finder->new(
48 seed_width => "6",
49 n_motif => "10",
50 hd_index_file => "6.index",
51 seq_file => "seq.fasta",
52 bkgd_file => "seq.bkgd",
53 out_file => "motif.out",
54 strand => "forward",
55 );
56 $finder -> find_motifs;
57  
58 =head1 EXPORT
59  
60 None by default
61  
62 =head1 FUNCTIONS
63  
64 =head2 new
65  
66 Title : new
67 Usage : my $finder = Seeder::Finder->new(%args);
68 Function: constructor for the Seeder::Finder object
69 Returns : a new Seeder::Finder object
70 Args :
71 seed_width # Seed width
72 motif_width # Motif width
73 n_motif # Number of motifs
74 hd_index_file # Index file
75 seq_file # Sequence file
76 bkgd_file # Background file
77 out_file # Output file
78 strand # Strand (forward or revcom), if the "revcom" option is
79 selected, the forward strand and the reverse
80 complement are included in the analysis
81  
82  
83 =cut
84  
85 1 ▶sub new {
Subroutine new: called CC=11 SCAR=27.9
Pod documented
86 1 my ( $class, %args ) = @_;
87 1 my $self;
88 $self->{seed_width} =
89 ( ( defined $args{seed_width} )
90 && ( $args{seed_width} >= 6 )
91 && ( $args{seed_width} <= 8 ) )
92 ? $args{seed_width}
93 1 ▶ : croak "Please define a seed width between 6 and 8!";
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'seed_width'} && $args{'seed_width'} >= 6 && $args{'seed_width'} <= 8 ? : 1 0 1
Condition33%2/6
defined $args{"seed_width"} and $args{"seed_width"} >= 6 and $args{"seed_width"} <= 8
!ll&&!rl&&r
001
defined $args{"seed_width"} and $args{"seed_width"} >= 6
!ll&&!rl&&r
001
MC/DC0%0/3
defined $args{"seed_width"} and $args{"seed_width"} >= 6 and $args{"seed_width"} <= 8
defined $args{"seed_width"} $args{"seed_width"} >= 6 $args{"seed_width"} <= 8
Truth table25%1/4
A and B and C
A= defined $args{"seed_width"}B= $args{"seed_width"} >= 6C= $args{"seed_width"} <= 8
ABCresult
0XX0
10X0
1100
1111
94 $self->{motif_width} =
95 defined $args{motif_width}
96 ? $args{motif_width}
97 1 ▶ : croak "Please define a motif width!";
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'motif_width'} ? : 1 0 1
98 $self->{n_motif} =
99 defined $args{n_motif}
100 ? $args{n_motif}
101 1 ▶ : croak "Please define a number of motifs!";
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'n_motif'} ? : 1 0 1
102 $self->{seq_file} =
103 defined $args{seq_file}
104 ? $args{seq_file}
105 1 ▶ : croak "Please define a promoter seq file!";
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'seq_file'} ? : 1 0 1
106 $self->{bkgd_file} =
107 defined $args{bkgd_file}
108 ? $args{bkgd_file}
109 1 ▶ : croak "Please define a bkgd file!";
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'bkgd_file'} ? : 1 0 1
110 $self->{hd_index_file} =
111 defined $args{hd_index_file}
112 ? $args{hd_index_file}
113 1 ▶ : croak "Please define a hamming dist index file!";
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'hd_index_file'} ? : 1 0 1
114 $self->{out_file} =
115 defined $args{out_file}
116 ? $args{out_file}
117 1 ▶ : croak "Please define an output file!";
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'out_file'} ? : 1 0 1
118 $self->{strand} =
119 defined $args{strand}
120 ? $args{strand}
121 1 ▶ : croak "Please define strand(s)!";
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'strand'} ? : 1 0 1
122 1 bless( $self, $class );
123 1 return $self;
124 }
125  
126 =head2 find_motifs
127  
128 Title : find_motifs
129 Usage : $finder -> find_motifs;
130 Function: coordination of the motif finding process
131 Args : none
132  
133 =cut
134  
135 0 ▶sub find_motifs {
Subroutine find_motifs: not called CC=2 SCAR=17.9
Pod documented
136 0 my $self = shift;
137 0 $self->_extent;
138 0 $self->_read_seq;
139 0 $self->_read_bkgd;
140 0 $self->read_hd_index;
141 0 $self->_oligo_count;
142 0 $self->generate_oligo;
143 0 $self->lookup_coord;
144  
145 0 for my $motif_no ( 1 .. $self->{n_motif} ) {
146 0 $self->{launch_time} = time;
147 0 $self->{iter} = 0;
148 0 $self->{motif_no} = $motif_no;
149 0 $self->_iupac;
150 0 $self->_build_hd_matrix;
151 0 $self->_get_seed;
152 0 $self->_output_data;
153 }
154 }
155  
156 =head2 _read_seq
157  
158 Title : _read_seq
159 Usage : $self->_read_seq;
160 Function: read the sequence file, count number of sequences
161 Returns : reference to sequence tables
162 ( $self->{n_seq} )
163 Args : none
164  
165 =cut
166  
167 0 ▶sub _read_seq {
Subroutine _read_seq: not called CC=3 SCAR=24.8
168 0 my $self = shift;
169 my $seqIO =
170 0 Bio::SeqIO->new( '-format' => 'fasta', -file => $self->{seq_file} );
171 0 my ( @seq_tbl, @seq_mask, @revcom_tbl, @revcom_mask );
172 0 ▶ while ( my $seq_obj = $seqIO->next_seq() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $seq_obj = $seqIO->next_seq) 0 0 0
173 0 my $seq_id = $seq_obj->display_id;
174 0 my $seq = $seq_obj->seq;
175 0 $seq = uc $seq;
176 0 my @seq = ( $seq_id, $seq );
177 0 push @seq_tbl, [@seq];
178 0 push @seq_mask, [@seq];
179 0 ▶ if ( $self->{strand} eq "revcom" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'strand'} eq 'revcom') { } 0 0 0
180 0 my $revcom = reverse $seq;
181 0 $revcom =~ tr{ACGTUMRWSYKVHDBXN}{TGCAUKYWSRMBDHVXN};
182 0 my @revcom = ( $seq_id, $revcom );
183 0 push @revcom_tbl, [@revcom];
184 0 push @revcom_mask, [@revcom];
185 }
186 else {
187 0 ();
188 }
189 }
190 0 $self->{seq_tbl_ref} = \@seq_tbl;
191 0 $self->{seq_mask_ref} = \@seq_mask;
192 0 $self->{revcom_tbl_ref} = \@revcom_tbl;
193 0 $self->{revcom_mask_ref} = \@revcom_mask;
194 0 $self->{n_seq} = $#seq_tbl + 1;
195 0 return (\@seq_tbl, \@seq_mask, \@revcom_tbl, \@revcom_mask);
196 }
197  
198 =head2 _read_bkgd
199  
200 Title : _read_bkgd
201 Usage : $self->_read_bkgd;
202 Function: read the background Hamming distance file
203 Returns : reference to a 2D array of background Hamming distances and
204 reference to an array of nucleotide frequencies
205 Args : none
206  
207 =cut
208  
209 0 ▶sub _read_bkgd {
Subroutine _read_bkgd: not called CC=6 SCAR=37.4
210 0 my $self = shift;
211 0 my ( @bkgd, @nf );
212 0 ▶ open( IN, "$self->{bkgd_file}" )
Branch: 1 branch
BranchTrueFalseTotal
open IN, qq[$self->{"bkgd_file"}] or croak(qq[Cannot open $self->{"bkgd_file"}\n]) 0 0 0
213 or croak "Cannot open $self->{bkgd_file}\n";
214 0 ▶ while (<IN>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline IN)) 0 0 0
215 0 my @bkgd_line = split( m{\s}, $_ );
216 0 shift @bkgd_line;
217 0 push @bkgd, [@bkgd_line];
218 }
219 0 for my $nucleotide ( 0 .. 3 ) {
220 0 $nf[$nucleotide] = $bkgd[0][0];
221 0 shift @bkgd;
222 }
223 0 $self->{bkgd_ref} = \@bkgd;
224 0 my $nf_sum = List::Util::sum(@nf);
225 0 ▶ if ( $self->{strand} eq "revcom" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'strand'} eq 'revcom') { } 0 0 0
226 0 $nf[0] = ( $nf[0] + $nf[3] ) / 2;
227 0 $nf[3] = $nf[0];
228 0 $nf[1] = ( $nf[1] + $nf[2] ) / 2;
229 0 $nf[2] = $nf[1];
230 }
231 else {
232 0 ();
233 }
234 0 for my $nucleotide ( 0 .. 3 ) {
235 0 $nf[$nucleotide] /= $nf_sum;
236 }
237 0 $self->{nf_ref} = \@nf;
238 0 return (\@bkgd, \@nf);
239 }
240  
241 =head2 _oligo_count
242  
243 Title : _oligo_count
244 Usage : $self->_oligo_count;
245 Function: count oligos in sequences
246 Returns : reference to a 2D array of oligo counts
247 Args : none
248  
249 =cut
250  
251 0 ▶sub _oligo_count {
Subroutine _oligo_count: not called CC=7 SCAR=40.3
252 0 my $self = shift;
253 0 my @count_matrix;
254 0 for my $seq_indice ( 0 .. $#{ $self->{seq_tbl_ref} } ) {
255 0 my @seq_count = split( q{}, 0 x ( 4**$self->{seed_width} ) );
256 0 my $seq = $self->{seq_tbl_ref}->[$seq_indice][1];
257 0 for my $x (
258 $self->{extent} .. ( length($seq) - $self->{motif_width} ) )
259 {
260 0 my $subseq = substr( $seq, $x, $self->{seed_width} );
261 0 $subseq =~ tr{ACGT}{0123};
262 0 ▶ if ( $subseq !~ m{\D} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $subseq =~ /\D/) { } 0 0 0
263 0 my $oligo_indice = decode( $subseq, 4 );
264 0 $seq_count[$oligo_indice] += 1;
265 }
266 else {
267 0 ();
268 }
269 }
270 0 ▶ if ( $self->{strand} eq "revcom" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'strand'} eq 'revcom') { } 0 0 0
271 0 my $revcom = $self->{revcom_tbl_ref}->[$seq_indice][1];
272 0 for my $x ( 0 .. ( length($revcom) - $self->{seed_width} ) ) {
273 0 my $subseq = substr( $revcom, $x, $self->{seed_width} );
274 0 $subseq =~ tr{ACGT}{0123};
275 0 ▶ if ( $subseq !~ m{\D} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $subseq =~ /\D/) { } 0 0 0
276 0 my $oligo_indice = decode( $subseq, 4 );
277 0 $seq_count[$oligo_indice] += 1;
278 }
279 else {
280 0 ();
281 }
282 }
283 }
284 else {
285 0 ();
286 }
287 0 push @count_matrix, [@seq_count];
288 }
289 0 $self->{count_matrix_ref} = \@count_matrix;
290 0 return \@count_matrix;
291 }
292  
293 =head2 _extent
294  
295 Title : _extent
296 Usage : $self->_extent;
297 Function: verify that motif extension width is even
298 Returns : motif extension width
299 Args : none
300  
301 =cut
302  
303 0 ▶sub _extent {
Subroutine _extent: not called CC=2 SCAR=17.9
304 0 my $self = shift;
305 $self->{motif_width} =
306 ( ( $self->{motif_width} - $self->{seed_width} ) / 2 ) =~ m{\.}
307 ? $self->{motif_width} + 1
308 0 ▶ : $self->{motif_width};
Branch: 1 branch
BranchTrueFalseTotal
(($self->{'motif_width'} - $self->{'seed_width'}) / 2) =~ /\./ ? : 0 0 0
309 0 my $extent = $self->{motif_width} - $self->{seed_width};
310 0 $self->{extent} = $extent;
311 0 return $extent;
312 }
313  
314 =head2 _build_hd_matrix
315  
316 Title : _build_hd_matrix
317 Usage : $self->_build_hd_matrix;
318 Function: calculate Hamming distance between oligos and sequences
319 Returns : reference to a 2D array of Hamming distances
320 Args : none
321  
322 =cut
323  
324 0 ▶sub _build_hd_matrix {
Subroutine _build_hd_matrix: not called CC=11 SCAR=48.8
325 0 my $self = shift;
326 0 my @hd_matrix;
327 0 for my $count_indice ( 0 .. $#{ $self->{count_matrix_ref} } ) {
328 0 for my $oligo_indice ( 0 .. $#{ $self->{oligo_ref} } ) {
329 0 ▶ if ( $self->{count_matrix_ref}->[$count_indice][$oligo_indice]
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'count_matrix_ref'}[$count_indice][$oligo_indice] > 0) { } 0 0 0
330 > 0 )
331 {
332 0 $hd_matrix[$oligo_indice][$count_indice] = 0;
333 }
334 else {
335 0 my $status;
336 0 HD: for my $depth ( 1 .. 3 ) {
337 0 ▶ if (List::MoreUtils::any {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&List::MoreUtils::any(sub { $self->{'count_matrix_ref'}[$count_indice][$_] > 0; } , @{$$self{'hd_index_ref'}[$oligo_indice];}[$self->{'from_ref'}[$self->{'seed_width'} - 1][$depth] .. $self->{'to_ref'}[$self->{'seed_width'} - 1][$depth]])) { } 0 0 0
338 0 $self->{count_matrix_ref}->[$count_indice][$_]
339 > 0;
340 }
341 0 @{ $self->{hd_index_ref}->[$oligo_indice] }[
342 $self->{from_ref}->[ $self->{seed_width} - 1 ][$depth]
343 .. $self->{to_ref}
344 ->[ $self->{seed_width} - 1 ][$depth]
345 ]
346 )
347 {
348 0 $status = 1;
349 0 ▶ $hd_matrix[$oligo_indice][$count_indice] = $depth
Branch: 1 branch
BranchTrueFalseTotal
$hd_matrix[$oligo_indice][$count_indice] = $depth and last HD 0 0 0
350 and last HD;
351 }
352 else {
353 0 ();
354 }
355 }
356 0 ▶ if ( !defined $status ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $status) { } 0 0 0
357 my $live_hd_index = $self->generate_hd_index(
358 0 \@{ $self->{oligo_ref}->[$oligo_indice] } );
359 0 HD: for my $depth ( 4 .. $self->{seed_width} ) {
360 0 ▶ if (List::MoreUtils::any {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&List::MoreUtils::any(sub { $self->{'count_matrix_ref'}[$count_indice][$_] > 0; } , @$live_hd_index[$self->{'from_ref'}[$self->{'seed_width'} - 1][$depth] .. $self->{'to_ref'}[$self->{'seed_width'} - 1][$depth]])) { } 0 0 0
361 0 $self->{count_matrix_ref}->[$count_indice][$_]
362 > 0;
363 }
364 @$live_hd_index[
365 $self->{from_ref}
366 ->[ $self->{seed_width} - 1 ][$depth]
367 .. $self->{to_ref}
368 ->[ $self->{seed_width} - 1 ][$depth]
369 ]
370 )
371 {
372 0 ▶ $hd_matrix[$oligo_indice][$count_indice] = $depth
Branch: 1 branch
BranchTrueFalseTotal
$hd_matrix[$oligo_indice][$count_indice] = $depth and last HD 0 0 0
373 and last HD;
374 }
375 else {
376 0 ();
377 }
378 }
379 }
380 else {
381 0 ();
382 }
383 }
384 }
385 }
386 0 $self->{hd_matrix_ref} = \@hd_matrix;
387 0 return \@hd_matrix;
388 }
389  
390 =head2 _pr_sum
391  
392 Title : _pr_sum
393 Usage : my $distribution = _pr_sum( $n_seq, \@freq );
394 Function: generate the probability distribution of a sum of i.i.d. random
395 variables
396 Returns : reference to an array of real numbers in the range from 0 to 1
397 Args : reference to oligo probability distribution, number of sequences
398  
399 =cut
400  
401 0 ▶sub _pr_sum {
Subroutine _pr_sum: not called CC=3 SCAR=24.8
402 0 my ( $n, $f ) = @_;
403 0 my ( $p, $r ) = ( $f, [qw(1)] );
404 0 ▶ while ( $n > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n > 1) 0 0 0
405 0 ▶ ( $r, $n ) = $n & 1 ? ( _convolution( $r, $p ), $n - 1 ) : ( $r, $n );
Branch: 1 branch
BranchTrueFalseTotal
$n & 1 ? : 0 0 0
406 0 $n /= 2;
407 0 $p = _convolution( $p, $p );
408 }
409 0 $r = _convolution( $r, $p );
410 0 return $r;
411 }
412  
413 =head2 _convolution
414  
415 Title : _convolution
416 Usage : my $p = _convolution($p, $f, $m);
417 Function: convolution of two distributions
418 Returns : reference to an array of real numbers in the range from 0 to 1
419 Args : reference to the distributions to be convoluted
420  
421 =cut
422  
423 0 ▶sub _convolution {
Subroutine _convolution: not called CC=3 SCAR=24.8
424 0 my ( $p, $f ) = @_;
425 0 my $r;
426 0 for my $i ( 0 .. $#{$p} ) {
427 0 for my $j ( 0 .. $#{$f} ) {
428 0 $r->[ $i + $j ] += $p->[$i] * $f->[$j];
429 }
430 }
431 0 return $r;
432 }
433  
434 =head2 _iupac
435  
436 Title : _iupac
437 Usage : $self->_iupac;
438 Function: set IUPAC degenerate symbol correspondence
439 Returns : reference to a hash of IUPAC degenerate symbol
440 Args : none
441  
442 =cut
443  
444 0 ▶sub _iupac {
Subroutine _iupac: not called CC=1 SCAR=6.9
445 0 my $self = shift;
446 0 $self->{iupac}->{M} = [qw( 0 1 )];
447 0 $self->{iupac}->{R} = [qw( 0 2 )];
448 0 $self->{iupac}->{W} = [qw( 0 3 )];
449 0 $self->{iupac}->{S} = [qw( 1 2 )];
450 0 $self->{iupac}->{Y} = [qw( 1 3 )];
451 0 $self->{iupac}->{K} = [qw( 2 3 )];
452 0 $self->{iupac}->{V} = [qw( 0 1 2 )];
453 0 $self->{iupac}->{H} = [qw( 0 1 3 )];
454 0 $self->{iupac}->{D} = [qw( 0 2 3 )];
455 0 $self->{iupac}->{B} = [qw( 1 2 3 )];
456 0 $self->{iupac}->{X} = [qw( 0 1 2 3 )];
457 0 $self->{iupac}->{N} = [qw( 0 1 2 3 )];
458 0 return $self->{iupac};
459 }
460  
461 =head2 _get_seed
462  
463 Title : _get_seed
464 Usage : $self->_get_seed;
465 Function: coordinate seed site selection
466 Args : none
467  
468 =cut
469  
470 0 ▶sub _get_seed {
Subroutine _get_seed: not called CC=8 SCAR=42.8
471 0 my $self = shift;
472 0 my $n_bkgd_seq = List::Util::sum( @{ $self->{bkgd_ref}->[0] } );
473 0 my @hd_sum;
474 0 for my $oligo_indice ( 0 .. $#{ $self->{oligo_ref} } ) {
475 $hd_sum[$oligo_indice] =
476 0 List::Util::sum( @{ $self->{hd_matrix_ref}->[$oligo_indice] } );
477 }
478 0 my @p_value;
479 0 for my $hd_sum_indice ( 0 .. $#hd_sum ) {
480 0 my $p_value = 0;
481 0 my @freq = @{ $self->{bkgd_ref}->[$hd_sum_indice] };
482 0 for my $freq (@freq) {
483 0 $freq = $freq / $n_bkgd_seq;
484 }
485 0 my $distribution = _pr_sum( $self->{n_seq}, \@freq );
486 0 for my $live_hd_sum ( 0 .. $hd_sum[$hd_sum_indice] ) {
487 0 $p_value += $distribution->[$live_hd_sum];
488 }
489 0 push @p_value, $p_value;
490 }
491 0 my $min = List::Util::min @p_value;
492 0 my @sorted_indice = sort { $p_value[$a] <=> $p_value[$b] } 0 .. $#p_value;
493 0 my $min_indice = $sorted_indice[0];
494 0 my @q_value = _mtc(@p_value);
495 0 $self->{p_value} = $min;
496 0 $self->{q_value} = $q_value[$min_indice];
497 0 $self->{hd_sum} = $hd_sum[$min_indice];
498 0 my @seed_oligo = encode( $min_indice, 4, $self->{seed_width} );
499 0 $self->{seed_oligo_ref} = \@seed_oligo;
500 0 my @hd_to_seq = @{ $self->{hd_matrix_ref}->[$min_indice] };
501 0 my @seed_instance;
502 0 my $seed_hd_index = $self->generate_hd_index( \@seed_oligo );
503  
504 0 for my $hd_indice ( 0 .. $#hd_to_seq ) {
505 0 my @live_instance;
506 my @oligo_indice =
507 @$seed_hd_index[ $self->{from_ref}
508 ->[ $self->{seed_width} - 1 ][ $hd_to_seq[$hd_indice] ]
509 .. $self->{to_ref}
510 0 ->[ $self->{seed_width} - 1 ][ $hd_to_seq[$hd_indice] ] ];
511 0 for my $oligo_indice (@oligo_indice) {
512 0 ▶ if ( $self->{count_matrix_ref}->[$hd_indice][$oligo_indice] > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'count_matrix_ref'}[$hd_indice][$oligo_indice] > 0) { } 0 0 0
513 {
514 push @live_instance,
515 0 join( q{}, @{ $self->{oligo_ref}->[$oligo_indice] } );
516 }
517 else {
518 0 ();
519 }
520 }
521 0 push @seed_instance, [ sort (@live_instance) ];
522 }
523 0 $self->{site_ref} = \@seed_instance;
524 0 $self->_frequency_matrix;
525 0 $self->_probability_matrix;
526 0 $self->_weight_matrix;
527 0 $self->_select_site;
528 0 $self->_frequency_matrix;
529 0 $self->_probability_matrix;
530 0 $self->_weight_matrix;
531 0 $self->_extend_motif;
532 }
533  
534 =head2 _mtc
535  
536 Title : _mtc
537 Usage : @q_value = _mtc(@p_value);
538 Function: generate a list of q-values from a list of p-values
539 Returns : array of q-values
540 Args : array of p-values
541 Note : This is an adaptation of the algorithm described in Storey, J.D.
542 and Tibshirani, R. (2003) Statistical significance for genomewide
543 studies, Proc Natl Acad Sci U S A, 100, 9440-9445
544  
545 =cut
546  
547 0 ▶sub _mtc {
Subroutine _mtc: not called CC=11 SCAR=48.8
548 0 my @pvalue = @_;
549 0 my @lambda =
550 qw(0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.60
551 0.65 0.70 0.75 0.80 0.85 0.90 0.95);
552 0 my @pi0;
553 0 for my $i ( 0 .. $#lambda ) {
554 0 for my $j ( 0 .. $#pvalue ) {
555 0 ▶ if ( $pvalue[$j] >= $lambda[$i] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pvalue[$j] >= $lambda[$i]) { } 0 0 0
556 0 $pi0[$i]++;
557 }
558 else {
559 0 ();
560 }
561 }
562 0 $pi0[$i] /= ( ( $#pvalue + 1 ) * ( 1 - $lambda[$i] ) );
563 }
564 0 my @u = sort { $pvalue[$a] <=> $pvalue[$b] } 0 .. $#pvalue;
565 0 my @v;
566 0 for my $i ( 0 .. $#pvalue ) {
567 0 for my $y ( 0 .. $#pvalue ) {
568 0 ▶ if ( $pvalue[$y] <= $pvalue[$i] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pvalue[$y] <= $pvalue[$i]) { } 0 0 0
569 0 $v[$i]++;
570 }
571 else {
572 0 ();
573 }
574 }
575 }
576 0 my $spline = new Math::Spline( \@lambda, \@pi0 );
577 0 my $pi0 = $spline->evaluate( List::Util::max @lambda );
578 0 ▶ $pi0 = $pi0 > 1 ? 1 : $pi0;
Branch: 1 branch
BranchTrueFalseTotal
$pi0 > 1 ? : 0 0 0
579 0 my @qvalue;
580 0 for my $i ( 0 .. $#pvalue ) {
581 0 $qvalue[$i] = ( $pi0 * ( $#pvalue + 1 ) * $pvalue[$i] ) / $v[$i];
582 }
583 0 ▶ $qvalue[$#qvalue] = $qvalue[$#qvalue] > 1 ? 1 : $qvalue[$#qvalue];
Branch: 1 branch
BranchTrueFalseTotal
$qvalue[$#qvalue] > 1 ? : 0 0 0
584 0 ▶ for ( my $i = $#pvalue - 1; $i >= 0; $i-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 0 0 0
585 0 $qvalue[ $u[$i] ] =
586 List::Util::min( $qvalue[ $u[$i] ], $qvalue[ $u[ $i + 1 ] ], 1 );
587 }
588 0 return @qvalue;
589 }
590  
591 =head2 _frequency_matrix
592  
593 Title : _frequency_matrix
594 Usage : $self->_frequency_matrix;
595 Function: convert a set of instances into a frequency matrix, frequencies for
596 sequences holding multiple instances are weighted proportionally
597 Returns : reference to a 2D array of nucleotide frequencies
598 Args : none
599  
600 =cut
601  
602 0 ▶sub _frequency_matrix {
Subroutine _frequency_matrix: not called CC=8 SCAR=42.8
603 0 my $self = shift;
604 my $width =
605 0 ▶ $self->{iter} > 0 ? $self->{motif_width} : $self->{seed_width};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'iter'} > 0 ? : 0 0 0
606 0 my @f_matrix;
607 0 for my $row ( 0 .. 3 ) {
608 0 @{ $f_matrix[$row] } = split( q{}, 0 x $width );
609 }
610 0 for my $instance_indice ( 0 .. $#{ $self->{site_ref} } ) {
611 0 my $n_instance = scalar @{ $self->{site_ref}->[$instance_indice] };
612 0 for my $live_instance ( @{ $self->{site_ref}->[$instance_indice] } ) {
613 0 for my $depth ( 0 .. $width - 1 ) {
614 0 my $nucleotide = substr $live_instance, $depth, 1;
615 0 ▶ if ( $nucleotide =~ m{\d} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nucleotide =~ /\d/) { } 0 0 0
616 0 $f_matrix[$nucleotide][$depth] += 1 / $n_instance;
617 }
618 else {
619 0 for my $iupac ( @{ $self->{iupac}->{$nucleotide} } ) {
620 $f_matrix[$iupac][$depth]
621 += 1
622 / ( $n_instance
623 0 * ( $#{ $self->{iupac}->{$nucleotide} } + 1 )
624 );
625 }
626 }
627 }
628 }
629 }
630 0 $self->{f_matrix_ref} = \@f_matrix;
631 0 return \@f_matrix;
632 }
633  
634 =head2 _probability_matrix
635  
636 Title : _probability_matrix
637 Usage : $self->_probability_matrix;
638 Function: convert a frequency matrix into a probability matrix
639 Returns : reference to a 2D array of probabilities
640 Args : none
641  
642 =cut
643  
644 0 ▶sub _probability_matrix {
Subroutine _probability_matrix: not called CC=5 SCAR=34.0
645 0 my $self = shift;
646 my $width =
647 0 ▶ $self->{iter} > 0 ? $self->{motif_width} : $self->{seed_width};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'iter'} > 0 ? : 0 0 0
648 0 my @p_matrix;
649 0 for my $row ( 0 .. 3 ) {
650 0 @{ $p_matrix[$row] } = split( q{}, 0 x $width );
651 }
652 0 for my $nucleotide ( 0 .. 3 ) {
653 0 for my $depth ( 0 .. $width - 1 ) {
654 $p_matrix[$nucleotide][$depth] = (
655 ( $self->{f_matrix_ref}->[$nucleotide][$depth]
656 + $self->{nf_ref}->[$nucleotide] *
657 sqrt( $self->{n_seq} )
658 0 ) / ( $self->{n_seq} + sqrt( $self->{n_seq} ) )
659 );
660 }
661 }
662 0 $self->{p_matrix_ref} = \@p_matrix;
663 0 return \@p_matrix;
664 }
665  
666 =head2 _weight_matrix
667  
668 Title : _weight_matrix
669 Usage : $self->_weight_matrix;
670 Function: convert a probability matrix into a weight matrix
671 Returns : reference to a 2D array of position weights
672 Args : none
673  
674 =cut
675  
676 0 ▶sub _weight_matrix {
Subroutine _weight_matrix: not called CC=5 SCAR=34.0
677 0 my $self = shift;
678 my $width =
679 0 ▶ $self->{iter} > 0 ? $self->{motif_width} : $self->{seed_width};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'iter'} > 0 ? : 0 0 0
680 0 my @w_matrix;
681 0 for my $row ( 0 .. 3 ) {
682 0 @{ $w_matrix[$row] } = split( q{}, 0 x $width );
683 }
684 0 for my $nucleotide ( 0 .. 3 ) {
685 0 for my $depth ( 0 .. $width - 1 ) {
686 $w_matrix[$nucleotide][$depth] =
687 log( $self->{p_matrix_ref}->[$nucleotide][$depth]
688 0 / $self->{nf_ref}->[$nucleotide] )
689 / log(2);
690 }
691 }
692 0 $self->{w_matrix_ref} = \@w_matrix;
693 0 return \@w_matrix;
694 }
695  
696 =head2 _select_site
697  
698 Title : _select_site
699 Usage : $self->_select_site;
700 Function: select the best site among instances for each sequence given
701 position weight matrix
702 Returns : reference to a 2D array of sites
703 Args : none
704  
705 =cut
706  
707 0 ▶sub _select_site {
Subroutine _select_site: not called CC=7 SCAR=40.3
708 0 my $self = shift;
709 0 my @site;
710 0 for my $instance_indice ( 0 .. $#{ $self->{site_ref} } ) {
711 0 my @score;
712 0 for my $live_instance ( @{ $self->{site_ref}->[$instance_indice] } ) {
713 0 my $live_score = 0;
714 0 for my $depth ( 0 .. $self->{seed_width} - 1 ) {
715 0 my $nucleotide = substr $live_instance, $depth, 1;
716 0 $live_score += $self->{w_matrix_ref}->[$nucleotide][$depth];
717 }
718 0 push @score, $live_score;
719 }
720 SCORE:
721 0 for my $score_indice ( 0 .. $#score ) {
722 0 ▶ if ( $score[$score_indice] == List::Util::max @score ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($score[$score_indice] == &List::Util::max(@score)) 0 0 0
723 0 push @{ $site[$instance_indice] },
724 0 ▶ $self->{site_ref}->[$instance_indice][$score_indice]
Branch: 1 branch
BranchTrueFalseTotal
push @{$site[$instance_indice];}, $self->{"site_ref"}[$instance_indice][$score_indice] and last SCORE 0 0 0
725 and last SCORE;
726 }
727 }
728 }
729 0 $self->{site_ref} = \@site;
730 0 return \@site;
731 }
732  
733 =head2 _extend_motif
734  
735 Title : _extend_motif
736 Usage : $self->_extend_motif;
737 Function: extend seeds to motif width
738 Returns : reference to a 2D array of sites
739 Args : none
740  
741 =cut
742  
743 0 ▶sub _extend_motif {
Subroutine _extend_motif: not called CC=18 SCAR=58.3
744 0 my $self = shift;
745 0 my $fm_extension = $self->{n_seq} / 4;
746 0 $fm_extension .= ";";
747 0 my $extent = $self->{extent} / 2;
748 0 ▶ while ( $self->{iter} == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"iter"} == 0) 0 0 0
749 0 for my $row ( 0 .. 3 ) {
750 0 push @{ $self->{f_matrix_ref}->[$row] },
751 split( q{;}, ($fm_extension) x ($extent) );
752 0 unshift @{ $self->{f_matrix_ref}->[$row] },
753 split( q{;}, ($fm_extension) x ($extent) );
754 }
755 0 $self->{iter}++;
756 }
757 0 $self->_probability_matrix;
758 0 $self->_weight_matrix;
759 0 my ( @site, @site_strand );
760 0 ▶ while ( $self->{iter} < 10 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"iter"} < 10) 0 0 0
761 0 for my $seq_indice ( 0 .. $#{ $self->{seq_mask_ref} } ) {
762 0 my ( @score, @rev_score );
763 0 my $m_seq = $self->{seq_mask_ref}->[$seq_indice][1];
764 0 for my $x ( 0 .. ( length($m_seq) - $self->{motif_width} ) ) {
765 0 my $live_score = 0;
766 0 my $m_subseq = substr( $m_seq, $x, $self->{motif_width} );
767 0 $m_subseq =~ tr{ACGT}{0123};
768 0 for my $depth ( 0 .. $self->{motif_width} - 1 ) {
769 0 my $nucleotide = substr $m_subseq, $depth, 1;
770 0 ▶ if ( $nucleotide =~ m{\d} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nucleotide =~ /\d/) { } 0 0 0
771 $live_score
772 0 += $self->{w_matrix_ref}->[$nucleotide][$depth];
773 }
774 else {
775 0 for my $iupac ( @{ $self->{iupac}->{$nucleotide} } ) {
776 $live_score += (
777 $self->{w_matrix_ref}->[$iupac][$depth] / (
778 0 $#{ $self->{iupac}->{$nucleotide} } + 1
779 )
780 );
781 }
782 }
783 }
784 0 push @score, $live_score;
785 }
786 0 ▶ if ( $self->{strand} eq "revcom" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'strand'} eq 'revcom') { } 0 0 0
787 0 my $m_seq = $self->{revcom_mask_ref}->[$seq_indice][1];
788 0 for my $x ( 0 .. ( length($m_seq) - $self->{motif_width} ) ) {
789 0 my $live_score = 0;
790 0 my $m_subseq = substr( $m_seq, $x, $self->{motif_width} );
791 0 $m_subseq =~ tr{ACGT}{0123};
792 0 for my $depth ( 0 .. $self->{motif_width} - 1 ) {
793 0 my $nucleotide = substr $m_subseq, $depth, 1;
794 0 ▶ if ( $nucleotide =~ m{\d} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nucleotide =~ /\d/) { } 0 0 0
795 $live_score += $self->{w_matrix_ref}
796 0 ->[$nucleotide][$depth];
797 }
798 else {
799 0 for my $iupac (
800 0 @{ $self->{iupac}->{$nucleotide} } )
801 {
802 $live_score += (
803 $self->{w_matrix_ref}->[$iupac][$depth]
804 / (
805 0 $#{ $self->{iupac}->{$nucleotide} }
806 + 1
807 )
808 );
809 }
810 }
811 }
812 0 push @rev_score, $live_score;
813 }
814 }
815 else {
816 0 ();
817 }
818 0 push @score, @rev_score;
819 SCORE:
820 0 for my $score_indice ( 0 .. $#score ) {
821 0 ▶ if ( $score[$score_indice] == List::Util::max @score ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($score[$score_indice] == &List::Util::max(@score)) { } 0 0 0
822 0 ▶ if ( ( $self->{strand} eq "revcom" )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'strand'} eq 'revcom' and $score_indice >= scalar @score / 2) { } 0 0 0
Condition0%0/3
$self->{"strand"} eq "revcom" and $score_indice >= scalar @score / 2
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"strand"} eq "revcom" and $score_indice >= scalar @score / 2
$self->{"strand"} eq "revcom" $score_indice >= scalar @score / 2
Truth table0%0/3
A and B
A= $self->{"strand"} eq "revcom"B= $score_indice >= scalar @score / 2
ABresult
0X0
100
111
823 && ( ($score_indice) >= ( scalar @score / 2 ) ) )
824 {
825 0 my $revcom_indice =
826 ( $score_indice - scalar @score / 2 );
827 my $live_site =
828 substr( $self->{revcom_tbl_ref}->[$seq_indice][1],
829 0 $revcom_indice, $self->{motif_width} );
830 0 $live_site =~ tr{ACGT}{0123};
831 0 $site[$seq_indice][0] = $live_site;
832 $self->{site_position_ref}->[$seq_indice][1] = (
833 ( length $self->{revcom_tbl_ref}
834 0 ->[$seq_indice][1]
835 ) - $revcom_indice
836 );
837 $self->{site_position_ref}->[$seq_indice][0] =
838 ( $self->{site_position_ref}->[$seq_indice][1]
839 - $self->{motif_width}
840 0 + 1 );
841 0 $site_strand[$seq_indice] = "minus";
842 }
843 else {
844 my $live_site =
845 substr( $self->{seq_tbl_ref}->[$seq_indice][1],
846 0 $score_indice, $self->{motif_width} );
847 0 $live_site =~ tr{ACGT}{0123};
848 0 $site[$seq_indice][0] = $live_site;
849 0 $self->{site_position_ref}->[$seq_indice][0] =
850 ( $score_indice + 1 );
851 $self->{site_position_ref}->[$seq_indice][1] =
852 0 ( $score_indice + $self->{motif_width} );
853 0 $site_strand[$seq_indice] = "plus";
854 }
855 0 last SCORE;
856 }
857 else {
858 0 ();
859 }
860 }
861 }
862 0 $self->{site_ref} = \@site;
863 0 $self->{site_strand} = \@site_strand;
864 0 $self->_frequency_matrix;
865 0 $self->_probability_matrix;
866 0 $self->_weight_matrix;
867 0 $self->{iter}++;
868 }
869 0 $self->{site_ref} = \@site;
870 0 $self->{site_strand} = \@site_strand;
871 0 $self->_information_content;
872 0 $self->_mask_site;
873 0 return \@site;
874 }
875  
876 =head2 _information_content
877  
878 Title : _information_content
879 Usage : $self->_information_content;
880 Function: calculate total information content
881 Returns : total information content
882 Args : none
883  
884 =cut
885  
886 0 ▶sub _information_content {
Subroutine _information_content: not called CC=3 SCAR=24.8
887 0 my $self = shift;
888 0 my $ic = 2 * $self->{motif_width};
889 0 for my $nucleotide ( 0 .. 3 ) {
890 0 for my $depth ( 0 .. $self->{motif_width} - 1 ) {
891 $ic += (
892 $self->{p_matrix_ref}->[$nucleotide][$depth] * (
893 0 log( $self->{p_matrix_ref}->[$nucleotide][$depth] ) /
894 log(2)
895 )
896 );
897 }
898 }
899 0 $self->{information_content} = $ic;
900 0 return $ic;
901 }
902  
903 =head2 _mask_site
904  
905 Title : _mask_site
906 Usage : $self->_mask_site;
907 Function: mask the occurence in the sequence and in the count matrix
908 Args : none
909  
910 =cut
911  
912 0 ▶sub _mask_site {
Subroutine _mask_site: not called CC=7 SCAR=40.3
913 0 my $self = shift;
914 0 my $mask = "X" x $self->{motif_width};
915 0 for my $seq_indice ( 0 .. $#{ $self->{seq_mask_ref} } ) {
916 my $live_seq = Bio::LiveSeq::DNA->new(
917 0 -seq => $self->{seq_mask_ref}->[$seq_indice][1] );
918 0 my $m_seq = $live_seq->seq;
919 0 for my $p (
920 ( $self->{site_position_ref}->[$seq_indice][0]
921 - $self->{seed_width}
922 ) .. ( $self->{site_position_ref}->[$seq_indice][1] - 1 )
923 )
924 {
925 0 eval {
926 0 my $overlap = substr( $m_seq, $p, $self->{seed_width} );
927 0 ▶ if ( ( $overlap !~ m{[^ACGT]} )
Branch: 1 branch
BranchTrueFalseTotal
if (not $overlap =~ /[^ACGT]/ and length $overlap == $self->{'seed_width'}) { } 0 0 0
Condition0%0/3
not $overlap =~ /[^ACGT]/ and length $overlap == $self->{"seed_width"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $overlap =~ /[^ACGT]/ and length $overlap == $self->{"seed_width"}
not $overlap =~ /[^ACGT]/ length $overlap == $self->{"seed_width"}
Truth table0%0/3
not(A) and B
A= not $overlap =~ /[^ACGT]/B= length $overlap == $self->{"seed_width"}
ABresult
0X0
100
111
928 && ( length($overlap) == $self->{seed_width} ) )
929 {
930 0 $overlap =~ tr{ACGT}{0123};
931 0 my $overlap_ind = decode( $overlap, 4 );
932 0 $self->{count_matrix_ref}->[$seq_indice][$overlap_ind]
933 -= 1;
934 0 ▶ if ( $self->{strand} eq "revcom" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'strand'} eq 'revcom') { } 0 0 0
935 0 my $rev_overlap = reverse $overlap;
936 0 $rev_overlap =~ tr{0123}{3210};
937 0 my $rev_overlap_ind = decode( $rev_overlap, 4 );
938 $self->{count_matrix_ref}
939 0 ->[$seq_indice][$rev_overlap_ind] -= 1;
940 }
941 else {
942 0 ();
943 }
944 }
945 else {
946 0 ();
947 }
948 };
949 }
950 $live_seq->change( $mask,
951 ( $self->{site_position_ref}->[$seq_indice][0] ),
952 0 $self->{motif_width} );
953 0 $self->{seq_mask_ref}->[$seq_indice][1] = $live_seq->seq;
954 0 ▶ if ( $self->{strand} eq "revcom" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'strand'} eq 'revcom') { } 0 0 0
955 my $reverse = Bio::LiveSeq::DNA->new(
956 0 -seq => $self->{revcom_mask_ref}->[$seq_indice][1] );
957 $reverse->change(
958 $mask,
959 ( ( length $m_seq )
960 - $self->{site_position_ref}->[$seq_indice][1] + 1
961 ),
962 $self->{motif_width}
963 0 );
964 0 $self->{revcom_mask_ref}->[$seq_indice][1] = $reverse->seq;
965 }
966 else {
967 0 ();
968 }
969 }
970 }
971  
972 =head2 _output_data
973  
974 Title : _output_data
975 Usage : $self->_output_data;
976 Function: writes predicted motif to the output file
977 Args : none
978  
979 =cut
980  
981 0 ▶sub _output_data {
Subroutine _output_data: not called CC=10 SCAR=47.0
982 0 my $self = shift;
983 0 $self->{land_time} = time;
984 0 my $seed = join( q{}, @{ $self->{seed_oligo_ref} } );
985 0 $seed =~ tr{0123}{ACGT};
986  
987 0 ▶ open( OUT, ">>$self->{out_file}" )
Branch: 1 branch
BranchTrueFalseTotal
open OUT, qq[>>$self->{"out_file"}] or croak(qq[Cannot open $self->{"out_file"}\n]) 0 0 0
988 or croak "Cannot open $self->{out_file}\n";
989 0 print( OUT "*" x 78, "\n" );
990 0 print( OUT "Motif $self->{motif_no}, width = $self->{motif_width},",
991 " seed width = $self->{seed_width},",
992 " sites = $self->{n_seq}\n"
993 );
994 0 print( OUT "Sum of HD to $seed in $self->{n_seq} seqs: $self->{hd_sum}\n");
995 0 print (OUT "P-value($seed) = ", sprintf "%.5e\n", $self->{p_value}, "\n");
996 0 print (OUT "Q-value($seed) = ", sprintf "%.5e\n", $self->{q_value}, "\n");
997 0 print( OUT "Information Content = ", sprintf "%.15g\n", $self->{information_content} );
998 0 print( OUT "*" x 78, "\n\n" );
999  
1000 0 print( OUT ">NFM $self->{motif_no}\n\n" );
1001 0 my @dna = qw(A C G T);
1002 0 print( OUT q{ } x 6 );
1003 0 for my $dna (@dna) {
1004 0 print( OUT sprintf "%-16s ", $dna );
1005 }
1006 0 print( OUT "\n" );
1007 0 my @depth = ( 0 .. $self->{motif_width} - 1 );
1008 0 for my $depth (@depth) {
1009 0 print( OUT "P" );
1010 0 print( OUT sprintf "%-3d ", $depth );
1011 0 for my $nuc ( 0 .. 3 ) {
1012 print( OUT sprintf "%-16d ",
1013 0 $self->{f_matrix_ref}->[$nuc][$depth] );
1014 }
1015 0 print( OUT "\n" );
1016 }
1017 0 print( OUT "\n" );
1018  
1019 0 print( OUT ">PWM $self->{motif_no}\n\n" );
1020 0 print( OUT q{ } x 6 );
1021 0 for my $dna (@dna) {
1022 0 print( OUT sprintf "%-16s ", $dna );
1023 }
1024 0 print( OUT "\n" );
1025 0 for my $depth (@depth) {
1026 0 print( OUT "P" );
1027 0 print( OUT sprintf "%-3d ", $depth );
1028 0 for my $nuc ( 0 .. 3 ) {
1029 0 ▶ if ( $self->{w_matrix_ref}->[$nuc][$depth] > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'w_matrix_ref'}[$nuc][$depth] > 0) { } 0 0 0
1030 print( OUT sprintf sprintf "%.14f ",
1031 0 $self->{w_matrix_ref}->[$nuc][$depth]
1032 );
1033 }
1034 else {
1035 print( OUT sprintf sprintf "%.13f ",
1036 0 $self->{w_matrix_ref}->[$nuc][$depth]
1037 );
1038 }
1039 }
1040 0 print( OUT "\n" );
1041 }
1042 0 print( OUT "\n" );
1043  
1044 0 print( OUT sprintf "%-" . $self->{motif_width} . "s ", "Site" );
1045 0 print( OUT "Position " );
1046 0 print( OUT "Strand " );
1047 0 print( OUT "Sequence\n" );
1048 0 print( OUT "-" x $self->{motif_width} );
1049 0 print( OUT ' ', "-" x 11 );
1050 0 print( OUT ' ', "-" x 6 );
1051 0 print( OUT ' ', "-" x ( 49 - $self->{motif_width} ), "\n" );
1052  
1053 0 for my $seq_indice ( 0 .. $#{ $self->{seq_tbl_ref} } ) {
1054 0 my $subseq = $self->{site_ref}->[$seq_indice][0];
1055 0 $subseq =~ tr{0123}{ACGT};
1056 0 print( OUT $subseq, ' ' );
1057 print( OUT sprintf "%-4d",
1058 0 $self->{site_position_ref}->[$seq_indice][0] );
1059 0 print( OUT " - " );
1060 print( OUT sprintf "%4d",
1061 0 $self->{site_position_ref}->[$seq_indice][1] );
1062 0 print( OUT sprintf " %-6s", $self->{site_strand}->[$seq_indice] );
1063 print( OUT ' ',
1064 sprintf "%." . ( 49 - $self->{motif_width} ) . "s",
1065 0 $self->{seq_tbl_ref}->[$seq_indice][0]
1066 );
1067 0 print( OUT "\n" );
1068 }
1069  
1070 0 print( OUT "\n", $self->execution_time, "\n\n\n" );
1071 0 close(OUT);
1072 }
1073  
1074 =head1 AUTHOR
1075  
1076 François Fauteux, C<< <ffauteux at cpan.org> >>
1077  
1078 =head1 BUGS
1079  
1080 Please report any bugs or feature requests to C<bug-motif at rt.cpan.org>, or
1081 at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Seeder>. I will be
1082 notified, and then you'll automatically be notified of progress on your bug as
1083 I make changes.
1084  
1085 =head1 SUPPORT
1086  
1087 You can find documentation for this module with the perldoc command.
1088  
1089 perldoc Seeder
1090  
1091 You can also look for information at:
1092  
1093 =over 4
1094  
1095 =item * RT: CPAN's request tracker
1096  
1097 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Seeder>
1098  
1099 =item * AnnoCPAN: Annotated CPAN documentation
1100  
1101 L<http://annocpan.org/dist/Seeder>
1102  
1103 =item * CPAN Ratings
1104  
1105 L<http://cpanratings.perl.org/d/Seeder>
1106  
1107 =item * Search CPAN
1108  
1109 L<http://search.cpan.org/dist/Seeder>
1110  
1111 =back
1112  
1113 =head1 ACKNOWLEDGEMENTS
1114  
1115 This algorithm was developed by François Fauteux, Mathieu Blanchette and
1116 Martina Strömvik. We thank the Perl Monks <http://www.perlmonks.org/> for
1117 their support.
1118  
1119 =head1 COPYRIGHT & LICENSE
1120  
1121 Copyright 2008 François Fauteux, all rights reserved.
1122  
1123 This program is free software; you can redistribute it and/or modify it
1124 under the same terms as Perl itself.
1125  
1126 =cut
1127  
1128 2 1; # End of Seeder::Finder
↑ Summary Seeder/Background.pm »