blib/lib/Bio/Gonzales/Project.pm

filter: Statementstmt 36.8% 53 / 144 Branchbran 0.0% 0 / 48 Conditioncond 0.0% 0 / 19 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 38.8% 14 / 36 Podpod 14.2% 1 / 7 totaltotal 25.6% 68 / 265 CC 33 SCAR 37.4
CC
33
Cov
25%
conf
156.0
_build_config
72.0
__ANON__
30.0
CRAP 42.2
« blib/lib/Bio/Gonzales/Feat/IO/SWISS.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.062'; # VERSION
27  
28 0 ▶has '_config_key_cache' => ( is => 'rw', default => sub { {} } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
29 0 ▶has '_nfi_cache' => ( is => 'rw', default => sub { {} } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
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 12 has 'analysis_name' => (is => 'rw', lazy_build => 1);
37  
38 sub _build_analysis_name {
39 0 ▶ my ($self) = @_;
Subroutine _build_analysis_name: not called CC=1 SCAR=6.9
40  
41 0 return (File::Spec->splitdir(File::Spec->rel2abs('.')))[-1]
42 }
43  
44 sub _build_analysis_version {
45 0 ▶ my ($self) = @_;
Subroutine _build_analysis_version: not called CC=3 SCAR=24.8
46  
47 0 my $av;
48 0 ▶ if ( $ENV{ANALYSIS_VERSION} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ENV{'ANALYSIS_VERSION'}) { } 0 0 0
elsif (-f 'av') { } 0 0 0
49 0 $av = $ENV{ANALYSIS_VERSION};
50 } elsif ( -f 'av' ) {
51 0 $av = ( slurpc('av') )[0];
52 } else {
53 0 carp "using current dir as output dir";
54 0 $av = '.';
55 }
56 0 return _prepare_av($av);
57 }
58  
59 sub _build__substitute_conf {
60 0 ▶ my ($self) = @_;
Subroutine _build__substitute_conf: not called CC=1 SCAR=6.9
61  
62 my %subs = (
63 0 ▶ an => sub { return $self->analysis_name },
Subroutine __ANON__: not called CC=1 SCAR=6.9
64 0 ▶ av => sub { return $self->analysis_version },
Subroutine __ANON__: not called CC=1 SCAR=6.9
65 0 ▶ path_to => sub { return $self->path_to(@_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
66 0 ▶ data => sub { return $self->path_to('data') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
67 0 );
68  
69 return Data::Visitor::Callback->new(
70 plain_value => sub {
71 0 ▶ return unless defined $_;
Subroutine __ANON__: not called CC=5 SCAR=34.0
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 0 0
72 0 $_ =~ s{ ^ ~ ( [^/]* ) }
73 { $1
74 ? (getpwnam($1))[7]
75 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
76 }ex;
77  
78 0 my $subsre = join "|", keys %subs;
79 0 ▶ s{__($subsre)(?:\((.+?)\))?__}{ $subs{ $1 }->( $2 ? split( /,/, $2 ) : () ) }eg;
Branch: 1 branch
BranchTrueFalseTotal
$2 ? : 0 0 0
80 }
81 0 );
82 }
83  
84 sub _build_log {
85 0 ▶ my ($self) = @_;
Subroutine _build_log: not called CC=1 SCAR=6.9
86  
87 0 return Bio::Gonzales::Util::Log->new(
88 path => $self->_nfi('gonz.log'),
89 level => 'info',
90 namespace => $FindBin::Script
91 );
92 }
93  
94 sub _build_config {
95 0 ▶ my ($self) = @_;
Subroutine _build_config: not called CC=8 SCAR=42.8
96  
97 0 my $conf;
98 0 my $conf_f = $self->config_file;
99 0 ▶ if ( -f $conf_f ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $conf_f) 0 0 0
100 0 $conf = yslurp($conf_f);
101 0 ▶ $conf //= {};
Condition0%0/2
$conf //= {}
l!l
00
MC/DC0%0/1
$conf //= {}
$conf
Truth table0%0/2
A
A= $conf
Aresult
11
00
102  
103 0 ▶ confess "configuration file >> $conf_f << is not a hash/dictionary structure"
Branch: 1 branch
BranchTrueFalseTotal
if ref $conf ne "HASH" 0 0 0
104 if ( ref $conf ne 'HASH' );
105 0 $self->log->info("reading >> $conf_f <<");
106 0 $self->_substitute_conf->visit($conf);
107 }
108  
109 0 my $av_conf_f = join( ".", $self->analysis_version, "conf", "yml" );
110 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
111  
112 0 my $av_conf = yslurp($av_conf_f);
113 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
114 if ( ref $av_conf ne 'HASH' );
115  
116 0 $self->log->info("reading >> $av_conf_f <<");
117 0 $self->_substitute_conf->visit($av_conf);
118  
119 0 $conf = { %$conf, %$av_conf };
120 }
121 0 return $conf;
122 }
123  
124 sub BUILD {
125 0 ▶ my ($self) = @_;
Subroutine BUILD: not called CC=2 SCAR=17.9
Pod documented
126  
127 0 my $av = $self->analysis_version;
128  
129 $self->log->info("invoked ($av)") # if a script is run, log it
130 0 ▶ if ( !$ENV{GONZLOG_SILENT} );
Branch: 1 branch
BranchTrueFalseTotal
if not $ENV{"GONZLOG_SILENT"} 0 0 0
131 }
132  
133 around 'analysis_version' => sub {
134 0 ▶ my $orig = shift;
Subroutine __ANON__: not called CC=2 SCAR=17.9
135 0 my $self = shift;
136  
137 0 ▶ return $self->$orig()
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
138 unless @_;
139  
140 0 return $self->$orig( _prepare_av(shift) );
141 12 };
142  
143 sub _prepare_av {
144 0 ▶ my $av = shift;
Subroutine _prepare_av: not called CC=5 SCAR=34.0
145 0 ▶ if ( !$av ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $av) { } 0 0 0
elsif ($av =~ /^[-A-Za-z_.0-9]+$/) { } 0 0 0
146 0 return '.';
147 } elsif ( $av =~ /^[-A-Za-z_.0-9]+$/ ) {
148 0 ▶ mkdir $av unless ( -d $av );
Branch: 1 branch
BranchTrueFalseTotal
unless -d $av 0 0 0
149 } else {
150 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
151 0 carp "using current dir as output dir";
152 0 return '.';
153 }
154 0 return $av;
155 }
156  
157 0 ▶sub av { shift->analysis_version(@_) }
Subroutine av: not called CC=1 SCAR=6.9
Pod undocumented
158  
159 0 ▶sub c { shift->conf(@_) }
Subroutine c: not called CC=1 SCAR=6.9
Pod undocumented
160  
161 sub nfi {
162 0 ▶ my $self = shift;
Subroutine nfi: not called CC=2 SCAR=17.9
Pod undocumented
163  
164 0 my $f = $self->_nfi(@_);
165  
166 # only log it once per filename
167 $self->log->info("(nfi) > $f <")
168 0 ▶ unless ( $self->_nfi_cache->{$f}++ );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_nfi_cache->{$f}++ 0 0 0
169  
170 0 return $f;
171 }
172  
173 sub _nfi {
174 0 ▶ my $self = shift;
Subroutine _nfi: not called CC=1 SCAR=6.9
175 0 return File::Spec->catfile( $self->analysis_version, @_ );
176 }
177  
178 sub conf {
179 0 ▶ my ( $self, @keys ) = @_;
Subroutine conf: not called CC=12 SCAR=50.5
Pod undocumented
180  
181 0 my $data = $self->config;
182  
183 0 for my $k (@keys) {
184 0 ▶ confess "empty key supplied" unless ($k);
Branch: 1 branch
BranchTrueFalseTotal
unless $k 0 0 0
185 0 my $r = ref $data;
186 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
187 0 ▶ if ( exists( $data->{$k} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data->{$k}) { } 0 0 0
188 0 $data = $data->{$k};
189 } else {
190 0 $self->log->fatal_confess("$k not found in gonzconf");
191 }
192 ▶ } 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
193 0 ▶ if ( exists( $data->[$k] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data->[$k]) { } 0 0 0
194 0 $data = $data->[$k];
195 } else {
196 0 $self->log->fatal_confess("$k not found in gonzconf");
197 }
198 } else {
199 0 $self->log->fatal_confess("$k not found in gonzconf");
200 }
201 }
202 0 ▶ if (@keys) {
Branch: 1 branch
BranchTrueFalseTotal
if (@keys) { } 0 0 0
203 0 my $k = join( " ", @keys );
204 $self->log->info( "(gonzconf) > " . $k . " <", p($data) )
205 0 ▶ unless ( $self->_config_key_cache->{ '_' . $k }++ );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_config_key_cache->{'_' . $k}++ 0 0 0
206  
207 } else {
208 $self->log->info( "(gonzconf) dump", p($data) )
209 0 ▶ unless ( $self->_config_key_cache->{'_'}++ );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_config_key_cache->{"_"}++ 0 0 0
210 }
211 0 return $data;
212 }
213  
214 sub path_to {
215 0 ▶ my $self = shift;
Subroutine path_to: not called CC=2 SCAR=17.9
Pod undocumented
216  
217 0 my $home = Bio::Gonzales::Util::Development::File::find_root(
218 {
219 location => '.',
220 dirs => [ '.git', 'analysis', ],
221 files => ['Makefile']
222 }
223 );
224  
225 0 ▶ confess "Could not find project home"
Branch: 1 branch
BranchTrueFalseTotal
unless $home 0 0 0
226 unless ($home);
227 0 return File::Spec->catfile( $home, @_ );
228 }
229  
230 sub analysis_path {
231 0 ▶ my $self = shift;
Subroutine analysis_path: not called CC=1 SCAR=6.9
Pod undocumented
232  
233 0 return $self->path_to( "analysis", @_ );
234 }
235  
236 12 __PACKAGE__->meta->make_immutable();
« blib/lib/Bio/Gonzales/Feat/IO/SWISS.pm ↑ Summary blib/lib/Bio/Gonzales/Feat/IO/GFF3.pm »