PerlStone2015/fasta.pm

filter: Statementstmt 37.6% 29 / 77 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 46.6% 7 / 15 Podpod 0.0% 0 / 7 totaltotal 28.3% 36 / 127 CC 19 SCAR 30.9
CC
19
Cov
28%
makeRandomFasta
42.0
makeRepeatFasta
42.0
selectRandom
30.0
CRAP 22.0
« PerlStone2015/regexdna.pm ↑ Summary PerlStone2015/01overview.pm »
1 package Benchmark::Perl::Formance::Plugin::PerlStone2015::fasta;
2 1 our $AUTHORITY = 'cpan:SCHWIGON';
3 # ABSTRACT: benchmark - Generate and write random DNA sequences
4 1 $Benchmark::Perl::Formance::Plugin::PerlStone2015::fasta::VERSION = '0.002';
5 # COMMAND LINE:
6 # /usr/bin/perl fasta.perl-4.perl 25000000
7  
8 # The Computer Language Benchmarks game
9 # http://shootout.alioth.debian.org/
10 #
11 # contributed by David Pyke
12 # tweaked by Danny Sauer
13 # optimized by Steffen Mueller
14 # tweaked by Kuang-che Wu
15 # Benchmark::Perl::Formance plugin by Steffen Schwigon
16  
17 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 #############################################################
21 # #
22 # Benchmark Code ahead - Don't touch without strong reason! #
23 # #
24 #############################################################
25  
26 1 ▶use Benchmark ':hireswallclock';
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 1 our $PRINT = 0;
29  
30 1 ▶use constant IM => 139968;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 ▶use constant IA => 3877;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 1 ▶use constant IC => 29573;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 1 ▶use constant LINELENGTH => 60;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 1 my $LAST = 42;
37 0 ▶sub gen_random {
Subroutine gen_random: not called CC=2 SCAR=17.9
Pod undocumented
38 0 ▶ return map {( ($_[0] * ($LAST = ($LAST * IA + IC) % IM)) / IM )} 1..($_[1]||1);
Condition0%0/2
$_[1] || 1
l!l
00
MC/DC0%0/1
$_[1] || 1
$_[1]
Truth table0%0/2
A
A= $_[1]
Aresult
11
00
39 }
40  
41 0 ▶sub makeCumulative {
Subroutine makeCumulative: not called CC=2 SCAR=17.9
Pod undocumented
42 0 my $genelist = shift;
43 0 my $cp = 0.0;
44  
45 0 $_->[1] = $cp += $_->[1] foreach @$genelist;
46 }
47  
48 0 ▶sub selectRandom {
Subroutine selectRandom: not called CC=5 SCAR=34.0
Pod undocumented
49 0 my $genelist = shift;
50 0 ▶ my $number = shift || 1;
Condition0%0/2
shift() || 1
l!l
00
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
51 0 my @r = gen_random(1, $number);
52  
53 0 my $s;
54 0 foreach my $r (@r) {
55 0 foreach (@$genelist){
56 0 ▶ if ($r < $_->[1]) { $s .= $_->[0]; last; }
Branch: 1 branch
BranchTrueFalseTotal
if ($r < $_->[1]) 0 0 0
57 }
58 }
59  
60 0 return $s;
61 }
62  
63  
64 0 ▶sub makeRandomFasta {
Subroutine makeRandomFasta: not called CC=6 SCAR=37.4
Pod undocumented
65 0 my ($id, $desc, $n, $genelist) = @_;
66  
67 0 ▶ print ">", $id, " ", $desc, "\n" if $PRINT;
Branch: 1 branch
BranchTrueFalseTotal
if $Benchmark::Perl::Formance::Plugin::PerlStone2015::fasta::PRINT 0 0 0
68  
69 # print whole lines
70 0 foreach (1 .. int($n / LINELENGTH) ){
71 0 my $dummy = selectRandom($genelist, LINELENGTH)."\n";
72 0 ▶ print $dummy if $PRINT;
Branch: 1 branch
BranchTrueFalseTotal
if $Benchmark::Perl::Formance::Plugin::PerlStone2015::fasta::PRINT 0 0 0
73 }
74 # print remaining line (if required)
75 0 ▶ if ($n % LINELENGTH){
Branch: 1 branch
BranchTrueFalseTotal
if ($n % 60) 0 0 0
76 0 my $dummy = selectRandom($genelist, $n % LINELENGTH)."\n";
77 0 ▶ print $dummy if $PRINT;
Branch: 1 branch
BranchTrueFalseTotal
if $Benchmark::Perl::Formance::Plugin::PerlStone2015::fasta::PRINT 0 0 0
78 }
79 }
80  
81 0 ▶sub makeRepeatFasta {
Subroutine makeRepeatFasta: not called CC=6 SCAR=37.4
Pod undocumented
82 0 my ($id, $desc, $s, $n) = @_;
83  
84 0 ▶ print ">", $id, " ", $desc, "\n" if $PRINT;
Branch: 1 branch
BranchTrueFalseTotal
if $Benchmark::Perl::Formance::Plugin::PerlStone2015::fasta::PRINT 0 0 0
85  
86 0 my $r = length $s;
87 0 my $ss = $s . $s . substr($s, 0, $n % $r);
88 0 for my $j(0..int($n / LINELENGTH)-1) {
89 0 my $i = $j*LINELENGTH % $r;
90 0 my $dummy = substr($ss, $i, LINELENGTH)."\n";
91 0 ▶ print $dummy if $PRINT;
Branch: 1 branch
BranchTrueFalseTotal
if $Benchmark::Perl::Formance::Plugin::PerlStone2015::fasta::PRINT 0 0 0
92 }
93 0 ▶ if ($n % LINELENGTH) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n % 60) 0 0 0
94 0 my $dummy = substr($ss, -($n % LINELENGTH)). "\n";
95 0 ▶ print $dummy if $PRINT;
Branch: 1 branch
BranchTrueFalseTotal
if $Benchmark::Perl::Formance::Plugin::PerlStone2015::fasta::PRINT 0 0 0
96 }
97 }
98  
99  
100 1 my $iub = [
101 [ 'a', 0.27 ],
102 [ 'c', 0.12 ],
103 [ 'g', 0.12 ],
104 [ 't', 0.27 ],
105 [ 'B', 0.02 ],
106 [ 'D', 0.02 ],
107 [ 'H', 0.02 ],
108 [ 'K', 0.02 ],
109 [ 'M', 0.02 ],
110 [ 'N', 0.02 ],
111 [ 'R', 0.02 ],
112 [ 'S', 0.02 ],
113 [ 'V', 0.02 ],
114 [ 'W', 0.02 ],
115 [ 'Y', 0.02 ]
116 ];
117  
118 1 my $homosapiens = [
119 [ 'a', 0.3029549426680 ],
120 [ 'c', 0.1979883004921 ],
121 [ 'g', 0.1975473066391 ],
122 [ 't', 0.3015094502008 ]
123 ];
124  
125 1 my $alu =
126 'GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG' .
127 'GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA' .
128 'CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT' .
129 'ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA' .
130 'GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG' .
131 'AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC' .
132 'AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA';
133  
134 ######################################################################
135 #main
136  
137 sub run
138 0 ▶{
Subroutine run: not called CC=1 SCAR=6.9
Pod undocumented
139 0 my ($n) = @_;
140  
141 0 makeCumulative($iub);
142 0 makeCumulative($homosapiens);
143  
144 0 makeRepeatFasta ('ONE', 'Homo sapiens alu', $alu, $n*2);
145 0 makeRandomFasta ('TWO', 'IUB ambiguity codes', $n*3, $iub);
146 0 makeRandomFasta ('THREE', 'Homo sapiens frequency', $n*5, $homosapiens);
147 }
148  
149 sub main
150 0 ▶{
Subroutine main: not called CC=3 SCAR=24.8
Pod undocumented
151 0 my ($options) = @_;
152  
153 0 $PRINT = $options->{print};
154 0 ▶ my $goal = ($options->{fastmode} ? 200_000 : 1_000_000);
Branch: 1 branch
BranchTrueFalseTotal
$options->{'fastmode'} ? : 0 0 0
155 0 ▶ my $count = ($options->{fastmode} ? 1 : 5);
Branch: 1 branch
BranchTrueFalseTotal
$options->{'fastmode'} ? : 0 0 0
156  
157 0 my $result;
158 0 ▶ my $t = timeit $count, sub { $result = run($goal) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
159 return {
160 0 Benchmark => $t,
161 goal => $goal,
162 count => $count,
163 result => $result,
164 };
165 }
166  
167 1 1;
168  
169 __END__
« PerlStone2015/regexdna.pm ↑ Summary PerlStone2015/01overview.pm »