Egaz/Common.pm

filter: Statementstmt 60.1% 89 / 148 Branchbran 40.0% 8 / 20 Conditioncond 10.0% 1 / 10 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 86.2% 25 / 29 Podpod 0.0% 0 / 7 totaltotal 56.1% 123 / 219 CC 20 SCAR 19.9
CC
20
Cov
55%
get_size
20.0
ladder
20.0
exec_cmd
20.0
CRAP 7.3
« Egaz/Command/normalize.pm ↑ Summary Egaz/Command/maskfasta.pm »
1 package App::Egaz::Common;
2 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 19 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 19 ▶use 5.018001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 19 ▶use Bio::Phylo qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 19 ▶use Bio::Phylo::IO qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 19 ▶use Carp qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 19 ▶use File::Find::Rule;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 19 ▶use File::ShareDir qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 19 ▶use IO::Zlib;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 19 ▶use IPC::Cmd qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 19 ▶use JSON qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 19 ▶use List::Util qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 19 ▶use List::MoreUtils qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 19 ▶use MCE;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 19 ▶use Number::Format qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
20 19 ▶use Path::Tiny qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
21 19 ▶use Set::Scalar;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 19 ▶use String::Similarity;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 19 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 19 ▶use YAML::Syck qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 19 ▶use App::Fasops::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 8 ▶sub resolve_file {
Subroutine resolve_file: called CC=6 SCAR=18.8
Pod undocumented
29 8 my $original = shift;
30 8 my @paths = @_;
31  
32 8 my $file = $original;
33 8 ▶ if ( !-e $file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $file) 8 0 8
34 8 $file = Path::Tiny::path($file)->basename();
35  
36 8 ▶ if ( !-e $file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $file) 8 0 8
37 8 for my $p (@paths) {
38 8 $file = Path::Tiny::path($p)->child($file);
39 8 ▶ last if -e $file;
Branch: 1 branch
BranchTrueFalseTotal
if -e $file 8 0 8
40 }
41 }
42 }
43  
44 8 ▶ if ( -e $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $file) { } 8 0 8
45 8 return $file->stringify;
46 }
47 else {
48 0 Carp::confess "Can't resole file for [$original]\n";
49 }
50 }
51  
52 254 ▶sub round {
Subroutine round: called CC=2 SCAR=7.2
Pod undocumented
53 254 my $float = shift;
54  
55 254 ▶ return int( $float + $float / abs( $float * 2 || 1 ) );
Condition50%1/2
$float * 2 || 1
l!l
2540
MC/DC0%0/1
$float * 2 || 1
$float * 2
Truth table50%1/2
A
A= $float * 2
Aresult
11
00
56 }
57  
58 # Return a list of 1-based overlapping ranges
59 1 ▶sub overlap_ranges {
Subroutine overlap_ranges: called CC=3 SCAR=11.0
Pod undocumented
60 1 my $start = shift;
61 1 my $end = shift;
62 1 my $chunk = shift;
63 1 my $overlap = shift;
64  
65 1 my @ranges;
66 1 ▶ for ( my $i = $start - 1; $i < $end; $i += $chunk ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $end) 4 1 5
67 4 my $j = $i + $chunk + $overlap;
68 4 ▶ $j = $end if ( $j > $end );
Branch: 1 branch
BranchTrueFalseTotal
if $j > $end 1 3 4
69 4 push @ranges, [ ( $i + 1 ), $j ];
70 }
71 1 return \@ranges;
72 }
73  
74 0 ▶sub run_sparsemem {
Subroutine run_sparsemem: not called CC=3 SCAR=24.8
Pod undocumented
75 0 my Path::Tiny $result = shift;
76 0 my $query = shift;
77 0 my $genome = shift;
78 0 ▶ my $length = shift || 20;
Condition0%0/2
shift() || 20
l!l
00
MC/DC0%0/1
shift() || 20
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
79  
80 # mummer
81 # -b compute forward and reverse complement matches
82 # -F force 4 column output format regardless of the number of reference sequence inputs
83 # -n match only the characters a, c, g, or t
84 #
85 # sparsemem only
86 # -k sampled suffix positions (one by default)
87 0 my $template;
88 my $exe;
89 0 ▶ if ( IPC::Cmd::can_run('sparsemem') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (IPC::Cmd::can_run('sparsemem')) { } 0 0 0
90 0 $exe = 'sparsemem';
91 0 $template = "%s -maxmatch -F -l %d -b -n -k 4 -threads 4 %s %s > %s";
92 }
93 else {
94 0 $exe = 'mummer';
95 0 $template = "%s -maxmatch -F -l %d -b -n %s %s > %s";
96 }
97  
98 0 my $cmd = sprintf $template, $exe, $length, $genome, $query, $result->stringify;
99 0 system $cmd;
100 }
101  
102 0 ▶sub get_size {
Subroutine get_size: not called CC=4 SCAR=30.0
Pod undocumented
103 0 my $file = shift;
104  
105 0 tie my %length_of, "Tie::IxHash";
106  
107 0 ▶ if ( IPC::Cmd::can_run('faops') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (IPC::Cmd::can_run('faops')) { } 0 0 0
108 0 my $cmd = sprintf "faops size %s", $file;
109 0 my @lines = grep {defined} split /\n/, `$cmd`;
110  
111 0 for (@lines) {
112 0 my ( $key, $value ) = split /\t/;
113 0 $length_of{$key} = $value;
114 }
115 }
116 else {
117 0 my $seq_of = App::Fasops::Common::read_fasta($file);
118 0 my @seq_names = keys %{$seq_of};
119  
120 0 for my $name (@seq_names) {
121 0 $length_of{$name} = length $seq_of->{$name};
122 }
123 }
124  
125 0 return \%length_of;
126 }
127  
128 #----------------------------#
129 # parsing tree
130 #----------------------------#
131 0 ▶sub ladder {
Subroutine ladder: not called CC=4 SCAR=30.0
Pod undocumented
132 0 my $file = shift;
133 0 my $target_name = shift;
134  
135 0 my $tree = Bio::Phylo::IO::parse( -format => 'newick', -file => $file )->first;
136  
137 0 my $target = $tree->get_by_name($target_name);
138  
139 0 my @ladder = ( [$target_name], );
140 0 my $set = Set::Scalar->new;
141 0 $set->insert($target_name);
142  
143 0 my $start = $target;
144 0 while (1) {
145 0 my $parent = $start->get_parent;
146 0 ▶ last unless $parent;
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 0 0
147 my @nodes
148 0 = grep { !$set->has( $_->get_name ) } @{ $parent->get_terminals };
149 0 $set->insert( $_->get_name ) for @nodes;
150 0 my $distance_of = {};
151 0 for my $node (@nodes) {
152 0 $distance_of->{ $node->get_name } = $node->calc_patristic_distance($target);
153 }
154 0 my @sorted = map { $_->[0] }
155 0 sort { $a->[1] <=> $b->[1] }
156 0 map { [ $_, $distance_of->{$_} ] }
157 0 keys %{$distance_of};
158 0 push @ladder, [@sorted];
159  
160 0 $start = $parent;
161 }
162  
163 0 return \@ladder;
164 }
165  
166 0 ▶sub exec_cmd {
Subroutine exec_cmd: not called CC=4 SCAR=30.0
Pod undocumented
167 0 my $cmd = shift;
168 0 my $opt = shift;
169  
170 0 ▶ if ( defined $opt and ref $opt eq "HASH" and $opt->{verbose} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt and ref $opt eq "HASH" and $opt->{"verbose"}) 0 0 0
Condition0%0/6
defined $opt and ref $opt eq "HASH" and $opt->{"verbose"}
!ll&&!rl&&r
000
defined $opt and ref $opt eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/3
defined $opt and ref $opt eq "HASH" and $opt->{"verbose"}
defined $opt ref $opt eq "HASH" $opt->{"verbose"}
Truth table0%0/4
A and B and C
A= defined $optB= ref $opt eq "HASH"C= $opt->{"verbose"}
ABCresult
0XX0
10X0
1100
1111
171 0 print STDERR "CMD: ", $cmd, "\n";
172 }
173  
174 0 system $cmd;
175 }
176  
177 19 1;
178  
« Egaz/Command/normalize.pm ↑ Summary Egaz/Command/maskfasta.pm »