blib/lib/Bio/Gonzales/Util/Text.pm

filter: Statementstmt 97.0% 33 / 34 Branchbran 60.0% 6 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 50.0% 1 / 2 totaltotal 88.6% 47 / 53 CC 7 SCAR 15.4
CC
7
Cov
89%
__ANON__
7.8
ccount_iter
1.0
BEGIN
1.0
CRAP 4.6
« blib/lib/Bio/Gonzales/Feat/IO.pm ↑ Summary blib/lib/Bio/Gonzales/Seq/IO/fastq.pm »
1 #Copyright (c) 2010 Joachim Bargsten <code at bargsten dot org>. All rights reserved.
2  
3 package Bio::Gonzales::Util::Text;
4  
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 our ( @EXPORT, @EXPORT_OK, %EXPORT_TAGS );
11 1 our $VERSION = '0.058'; # VERSION
12  
13 1 @EXPORT = qw();
14 1 %EXPORT_TAGS = ();
15 1 @EXPORT_OK = qw(ccount ccount_iter);
16  
17 sub ccount_iter {
18 1 ▶ my ($args) = @_;
Subroutine ccount_iter: called CC=1 SCAR=0.1
Pod undocumented
19  
20 1 my %counts;
21  
22 return sub {
23 1 ▶ my ($string) = @_;
Subroutine __ANON__: called CC=7 SCAR=20.5
24  
25 1 ▶ return \%counts unless($string);
Branch: 1 branch
BranchTrueFalseTotal
unless $string 0 1 1
26  
27 1 my @counts;
28  
29 1 ▶ for ( my $i = length($string) - 1; $i >= 0; $i-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 4 1 5
30 4 $counts[ ord( substr( $string, $i, 1 ) ) ]++;
31 }
32  
33 1 for my $idx ( 0 .. $#counts ) {
34 85 ▶ if ( $args->{ignore_case} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'ignore_case'}) { } 0 85 85
35 0 ▶ $counts{ lc( chr($idx) ) } += $counts[$idx] if exists $counts[$idx];
Branch: 1 branch
BranchTrueFalseTotal
if exists $counts[$idx] 0 0 0
36 } else {
37 85 ▶ $counts{ chr($idx) } += $counts[$idx] if exists $counts[$idx];
Branch: 1 branch
BranchTrueFalseTotal
if exists $counts[$idx] 3 82 85
38  
39 }
40 }
41  
42 1 return \%counts;
43 1 };
44 }
45  
46 sub ccount {
47 1 ▶ my ( $string, $args ) = @_;
Subroutine ccount: called CC=1 SCAR=0.0
Pod documented
48 1 my $counter = ccount_iter($args);
49  
50 1 return $counter->($string);
51 }
52  
53 1 1;
54  
55 __END__
56  
57 =head1 NAME
58  
59 Bio::Gonzales::Util::Text - text and string functions
60  
61 =head1 SYNOPSIS
62  
63 use Bio::Gonzales::Util::Text qw(ccount);
64  
65 =head1 DESCRIPTION
66  
67 Text and string functions that can be useful in a bioinformaticians daily life.
68  
69 =head1 SUBROUTINES
70  
71 =over 4
72  
73 =item B<< $counts = ccount($string) >>
74  
75 counts the character occurrences in C<$string> and returns a hash with
76 characters as keys and their corresponding counts as values.
77  
78 $counts = {
79 'A' => 34,
80 'G' => 234234,
81 'a' => 12,
82 'C' => 234234,
83 'T' => 46
84 };
85  
86 =back
87  
88 =head1 SEE ALSO
89  
90 =head1 AUTHOR
91  
92 jw bargsten, C<< <joachim.bargsten at wur.nl> >>
93  
94 =cut
« blib/lib/Bio/Gonzales/Feat/IO.pm ↑ Summary blib/lib/Bio/Gonzales/Seq/IO/fastq.pm »