blib/lib/Bio/Gonzales/Project.pm

filter: Statementstmt 53.2% 74 / 139 Branchbran 14.5% 7 / 48 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 64.7% 22 / 34 Podpod 14.2% 1 / 7 totaltotal 40.7% 104 / 255 CC 32 SCAR 36.6
CC
32
Cov
40%
conf
156.0
_build_config
56.0
__ANON__
30.0
CRAP 39.0
« blib/lib/Bio/Gonzales/Search/IO/BLAST.pm ↑ Summary blib/lib/Bio/Gonzales/Feat/IO/GFF3.pm »
1 package Bio::Gonzales::Project;
2  
3 12 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use FindBin;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 12 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 ▶use Bio::Gonzales::Util::File qw/slurpc/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 12 ▶use Bio::Gonzales::Util::Cerial;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 12 ▶use Bio::Gonzales::Util::Development::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 12 ▶use Data::Visitor::Callback;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 12 ▶use Bio::Gonzales::Util::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 use Data::Printer {
16 12 indent => 2,
17 colored => '0',
18 use_prototypes => 0,
19 rc_file => '',
20 12 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 12 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 12 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 12 our $VERSION = '0.058'; # VERSION
27  
28 12 ▶has '_config_key_cache' => ( is => 'rw', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
29 12 ▶has '_nfi_cache' => ( is => 'rw', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
30 12 has 'analysis_version' => ( is => 'rw', builder => '_build_analysis_version' );
31 12 has '_substitute_conf' => ( is => 'rw', lazy_build => 1 );
32 12 has 'config' => ( is => 'rw', lazy_build => 1 );
33 12 has 'merge_av_config' => ( is => 'rw', default => 1 );
34 12 has 'log' => ( is => 'rw', builder => '_build_log' );
35 12 has 'config_file' => ( is => 'rw', default => 'gonz.conf.yml' );
36  
37 sub _build_analysis_version {
38 12 ▶ my ($self) = @_;
Subroutine _build_analysis_version: called CC=3 SCAR=12.0
39  
40 12 my $av;
41 12 ▶ if ( $ENV{ANALYSIS_VERSION} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ENV{'ANALYSIS_VERSION'}) { } 0 12 12
elsif (-f 'av') { } 0 12 12
42 0 $av = $ENV{ANALYSIS_VERSION};
43 } elsif ( -f 'av' ) {
44 0 $av = ( slurpc('av') )[0];
45 } else {
46 12 carp "using current dir as output dir";
47 12 $av = '.';
48 }
49 12 return _prepare_av($av);
50 }
51  
52 sub _build__substitute_conf {
53 0 ▶ my ($self) = @_;
Subroutine _build__substitute_conf: not called CC=1 SCAR=6.9
54  
55 my %subs = (
56 0 ▶ av => sub { return $self->analysis_version },
Subroutine __ANON__: not called CC=1 SCAR=6.9
57 0 ▶ path_to => sub { return $self->path_to(@_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
58 0 ▶ data => sub { return $self->path_to('data') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
59 0 );
60  
61 return Data::Visitor::Callback->new(
62 plain_value => sub {
63 0 ▶ return unless defined $_;
Subroutine __ANON__: not called CC=5 SCAR=34.0
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 0 0
64 0 $_ =~ s{ ^ ~ ( [^/]* ) }
65 { $1
66 ? (getpwnam($1))[7]
67 0 ▶ : ( $ENV{HOME} || (getpwuid($>))[7] )
Branch: 1 branch
BranchTrueFalseTotal
$1 ? : 0 0 0
Condition0%0/3
$ENV{"HOME"} or (getpwuid $>)[7]
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{"HOME"} or (getpwuid $>)[7]
$ENV{"HOME"} (getpwuid $>)[7]
Truth table0%0/3
A or B
A= $ENV{"HOME"}B= (getpwuid $>)[7]
ABresult
1X1
011
000
68 }ex;
69  
70 0 my $subsre = join "|", keys %subs;
71 0 ▶ s{__($subsre)(?:\((.+?)\))?__}{ $subs{ $1 }->( $2 ? split( /,/, $2 ) : () ) }eg;
Branch: 1 branch
BranchTrueFalseTotal
$2 ? : 0 0 0
72 }
73 0 );
74 }
75  
76 sub _build_log {
77 12 ▶ my ($self) = @_;
Subroutine _build_log: called CC=1 SCAR=0.0
78  
79 12 return Bio::Gonzales::Util::Log->new(
80 path => $self->_nfi('gonz.log'),
81 level => 'info',
82 namespace => $FindBin::Script
83 );
84 }
85  
86 sub _build_config {
87 0 ▶ my ($self) = @_;
Subroutine _build_config: not called CC=7 SCAR=40.3
88  
89 0 my $conf;
90 0 my $conf_f = $self->config_file;
91 0 ▶ if ( -f $conf_f ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $conf_f) 0 0 0
92 0 $conf = yslurp($conf_f);
93  
94 0 ▶ confess "configuration file >> $conf_f << is not a hash/dictionary structure"
Branch: 1 branch
BranchTrueFalseTotal
if ref $conf ne "HASH" 0 0 0
95 if ( ref $conf ne 'HASH' );
96 0 $self->log->info("reading >> $conf_f <<");
97 0 $self->_substitute_conf->visit($conf);
98 }
99  
100 0 my $av_conf_f = join( ".", $self->analysis_version, "conf", "yml" );
101 0 ▶ if ( $self->merge_av_config && $av_conf_f !~ /^\./ && -f $av_conf_f ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->merge_av_config and not $av_conf_f =~ /^\./ and -f $av_conf_f) 0 0 0
Condition0%0/6
$self->merge_av_config and not $av_conf_f =~ /^\./ and -f $av_conf_f
!ll&&!rl&&r
000
$self->merge_av_config and not $av_conf_f =~ /^\./
!ll&&!rl&&r
000
MC/DC0%0/3
$self->merge_av_config and not $av_conf_f =~ /^\./ and -f $av_conf_f
$self->merge_av_config not $av_conf_f =~ /^\./ -f $av_conf_f
Truth table0%0/4
A and not(B) and C
A= $self->merge_av_configB= not $av_conf_f =~ /^\./C= -f $av_conf_f
ABCresult
0XX0
10X0
1100
1111
102  
103 0 my $av_conf = yslurp($av_conf_f);
104 0 ▶ confess "configuration file >> $av_conf_f << is not a hash/dictionary structure"
Branch: 1 branch
BranchTrueFalseTotal
if ref $av_conf ne "HASH" 0 0 0
105 if ( ref $av_conf ne 'HASH' );
106  
107 0 $self->log->info("reading >> $av_conf_f <<");
108 0 $self->_substitute_conf->visit($av_conf);
109  
110 0 $conf = { %$conf, %$av_conf };
111 }
112 0 return $conf;
113 }
114  
115 sub BUILD {
116 12 ▶ my ($self) = @_;
Subroutine BUILD: called CC=2 SCAR=7.1
Pod documented
117  
118 12 my $av = $self->analysis_version;
119  
120 $self->log->info("invoked ($av)") # if a script is run, log it
121 12 ▶ if ( !$ENV{GONZLOG_SILENT} );
Branch: 1 branch
BranchTrueFalseTotal
if not $ENV{"GONZLOG_SILENT"} 12 0 12
122 }
123  
124 around 'analysis_version' => sub {
125 24 ▶ my $orig = shift;
Subroutine __ANON__: called CC=2 SCAR=7.6
126 24 my $self = shift;
127  
128 24 ▶ return $self->$orig()
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 24 0 24
129 unless @_;
130  
131 0 return $self->$orig( _prepare_av(shift) );
132 12 };
133  
134 sub _prepare_av {
135 12 ▶ my $av = shift;
Subroutine _prepare_av: called CC=5 SCAR=22.5
136 12 ▶ if ( !$av ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $av) { } 0 12 12
elsif ($av =~ /^[-A-Za-z_.0-9]+$/) { } 12 0 12
137 0 return '.';
138 } elsif ( $av =~ /^[-A-Za-z_.0-9]+$/ ) {
139 12 ▶ mkdir $av unless ( -d $av );
Branch: 1 branch
BranchTrueFalseTotal
unless -d $av 0 12 12
140 } else {
141 0 ▶ carp "analysis version not or not correctly specified, variable contains: " . ( $av // 'nothing' );
Condition0%0/2
$av // "nothing"
l!l
00
MC/DC0%0/1
$av // "nothing"
$av
Truth table0%0/2
A
A= $av
Aresult
11
00
142 0 carp "using current dir as output dir";
143 0 return '.';
144 }
145 12 return $av;
146 }
147  
148 0 ▶sub av { shift->analysis_version(@_) }
Subroutine av: not called CC=1 SCAR=6.9
Pod undocumented
149  
150 0 ▶sub c { shift->conf(@_) }
Subroutine c: not called CC=1 SCAR=6.9
Pod undocumented
151  
152 sub nfi {
153 0 ▶ my $self = shift;
Subroutine nfi: not called CC=2 SCAR=17.9
Pod undocumented
154  
155 0 my $f = $self->_nfi(@_);
156  
157 # only log it once per filename
158 $self->log->info("(nfi) > $f <")
159 0 ▶ unless ( $self->_nfi_cache->{$f}++ );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_nfi_cache->{$f}++ 0 0 0
160  
161 0 return $f;
162 }
163  
164 sub _nfi {
165 12 ▶ my $self = shift;
Subroutine _nfi: called CC=1 SCAR=0.0
166 12 return File::Spec->catfile( $self->analysis_version, @_ );
167 }
168  
169 sub conf {
170 0 ▶ my ( $self, @keys ) = @_;
Subroutine conf: not called CC=12 SCAR=50.5
Pod undocumented
171  
172 0 my $data = $self->config;
173  
174 0 for my $k (@keys) {
175 0 ▶ confess "empty key supplied" unless ($k);
Branch: 1 branch
BranchTrueFalseTotal
unless $k 0 0 0
176 0 my $r = ref $data;
177 0 ▶ if ( $r && $r eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($r and $r eq 'HASH') { } 0 0 0
elsif ($r and $r eq 'ARRAY') { } 0 0 0
Condition0%0/3
$r and $r eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$r and $r eq "HASH"
$r $r eq "HASH"
Truth table0%0/3
A and B
A= $rB= $r eq "HASH"
ABresult
0X0
100
111
178 0 ▶ if ( exists( $data->{$k} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data->{$k}) { } 0 0 0
179 0 $data = $data->{$k};
180 } else {
181 0 confess "$k not found in gonzconf";
182 }
183 ▶ } elsif ( $r && $r eq 'ARRAY' ) {
Condition0%0/3
$r and $r eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
$r and $r eq "ARRAY"
$r $r eq "ARRAY"
Truth table0%0/3
A and B
A= $rB= $r eq "ARRAY"
ABresult
0X0
100
111
184 0 ▶ if ( exists( $data->[$k] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data->[$k]) { } 0 0 0
185 0 $data = $data->[$k];
186 } else {
187 0 confess "$k not found in gonzconf";
188 }
189 } else {
190 0 confess "$k not found in gonzconf";
191 }
192 }
193 0 ▶ if (@keys) {
Branch: 1 branch
BranchTrueFalseTotal
if (@keys) { } 0 0 0
194 0 my $k = join( " ", @keys );
195 $self->log->info( "(gonzconf) > " . $k . " <", p($data) )
196 0 ▶ unless ( $self->_config_key_cache->{ '_' . $k }++ );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_config_key_cache->{'_' . $k}++ 0 0 0
197  
198 } else {
199 $self->log->info( "(gonzconf) dump", p($data) )
200 0 ▶ unless ( $self->_config_key_cache->{'_'}++ );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_config_key_cache->{"_"}++ 0 0 0
201 }
202 0 return $data;
203 }
204  
205 sub path_to {
206 0 ▶ my $self = shift;
Subroutine path_to: not called CC=2 SCAR=17.9
Pod undocumented
207  
208 0 my $home = Bio::Gonzales::Util::Development::File::find_root(
209 {
210 location => '.',
211 dirs => [ '.git', 'analysis', ],
212 files => ['Makefile']
213 }
214 );
215  
216 0 ▶ confess "Could not find project home"
Branch: 1 branch
BranchTrueFalseTotal
unless $home 0 0 0
217 unless ($home);
218 0 return File::Spec->catfile( $home, @_ );
219 }
220  
221 sub analysis_path {
222 0 ▶ my $self = shift;
Subroutine analysis_path: not called CC=1 SCAR=6.9
Pod undocumented
223  
224 0 return $self->path_to( "analysis", @_ );
225 }
226  
227 12 __PACKAGE__->meta->make_immutable();
« blib/lib/Bio/Gonzales/Search/IO/BLAST.pm ↑ Summary blib/lib/Bio/Gonzales/Feat/IO/GFF3.pm »