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

filter: Statementstmt 82.9% 34 / 41 Branchbran 50.0% 3 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 88.8% 8 / 9 Podpod 50.0% 1 / 2 totaltotal 75.4% 46 / 61 CC 5 SCAR 10.2
CC
5
Cov
76%
combine_alphabet
6.0
shuffle
4.3
BEGIN
1.0
CRAP 2.8
« blib/lib/Bio/Gonzales/Matrix/IO/csv.pm ↑ Summary blib/lib/Bio/Gonzales/Feat/IO/BED.pm »
1 package Bio::Gonzales::Util::Math;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Math::Combinatorics;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use List::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 our ( @EXPORT, @EXPORT_OK, %EXPORT_TAGS );
14 1 our $VERSION = '0.062'; # VERSION
15  
16 1 @EXPORT = qw();
17 1 %EXPORT_TAGS = ();
18 1 @EXPORT_OK = qw(combine_alphabet shuffle);
19  
20 sub combine_alphabet {
21 0 ▶ my ($len) = @_;
Subroutine combine_alphabet: not called CC=2 SCAR=17.9
Pod documented
22 0 ▶ $len //= 2;
Condition0%0/2
$len //= 2
l!l
00
MC/DC0%0/1
$len //= 2
$len
Truth table0%0/2
A
A= $len
Aresult
11
00
23 0 my @n = ( 'a' .. 'z' );
24 0 my @c = combine( $len, @n );
25 0 return map { join "", @$_ } @c;
26 }
27  
28 sub shuffle {
29 100000 ▶ my $d = shift;
Subroutine shuffle: called CC=4 SCAR=14.6
Pod undocumented
30 100000 ▶ if ( ref $d eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $d eq 'HASH') { } 100000 0 100000
elsif (ref $d eq 'ARRAY') { } 0 0 0
31  
32 100000 my %shuffled;
33  
34 100000 my @keys = keys %$d;
35  
36 100000 my @key_idcs = List::Util::shuffle( 0 .. $#keys );
37 100000 ▶ for ( my $i = 0; $i < @keys; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @keys) 1000000 100000 1100000
38  
39 1000000 $shuffled{ $keys[ $key_idcs[$i] ] } = $d->{ $keys[$i] };
40 }
41 100000 return \%shuffled;
42 } elsif ( ref $d eq 'ARRAY' ) {
43 0 return [ List::Util::shuffle @$d ];
44 }
45  
46 }
47  
48 1 1;
49  
50 __END__
51  
52 =head1 NAME
53  
54 Bio::Gonzales::Util::Math::Util
55  
56 =head1 SYNOPSIS
57  
58 use Bio::Gonzales::Util::Math::Util qw/combine_alphabet/;
59  
60 =head1 DESCRIPTION
61  
62 =head1 SUBROUTINES
63  
64 =over 4
65  
66 =item B<< @character_combinations = combine_alphabet($length) >>
67  
68 Combine alphabetic characters from a-z into a sequence of strings, e.g.
69  
70 @c = combine_alphabet(3);
71  
72 results in
73  
74 abc
75 aca
76 aac
77 ...
78 zzz
79  
80 =back
81  
82 =head1 SEE ALSO
83  
84 =head1 AUTHOR
85  
86 jw bargsten, C<< <joachim.bargsten at wur.nl> >>
87  
88 =cut
« blib/lib/Bio/Gonzales/Matrix/IO/csv.pm ↑ Summary blib/lib/Bio/Gonzales/Feat/IO/BED.pm »