lib/Pheno/Ranker/Options.pm

filter: Statementstmt 100% 43 / 43 Branchbran 62.5% 5 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 2 totaltotal 92.0% 58 / 63 CC 8 SCAR 7.9
CC
8
Cov
94%
_validate_path_options
3.1
_validate_array_options
3.0
_apply_defaults
3.0
CRAP 2.2
« lib/Pheno/Ranker/Compare/Prepare.pm ↑ Summary lib/Pheno/Ranker/Compare/Ontology.pm »
1 package Pheno::Ranker::Options;
2  
3 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 9 ▶use File::Spec::Functions qw(catdir catfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 9 has config => (
10 is => 'ro',
11 required => 1,
12 );
13  
14 9 has share_dir => (
15 is => 'ro',
16 required => 1,
17 );
18  
19 53 ▶sub defined_constructor_args {
Subroutine defined_constructor_args: called CC=1 SCAR=0.0
Pod undocumented
20 53 my ( $class, $args ) = @_;
21 53 return { map { $_ => $args->{$_} } grep { defined $args->{$_} } keys %$args };
22 }
23  
24 37 ▶sub apply_to {
Subroutine apply_to: called CC=1 SCAR=0.0
Pod undocumented
25 37 my ( $self, $ranker ) = @_;
26  
27 37 $self->_apply_defaults($ranker);
28 37 $self->_validate_array_options($ranker);
29 37 $self->_validate_path_options($ranker);
30 37 $self->_validate_terms($ranker);
31  
32 37 return 1;
33 }
34  
35 37 ▶sub _apply_defaults {
Subroutine _apply_defaults: called CC=3 SCAR=11.0
36 37 my ( $self, $ranker ) = @_;
37  
38 37 my %defaults = (
39 append_prefixes => [],
40 cli => 0,
41 exclude_terms => [],
42 hpo_file => catfile( $self->share_dir, 'db', 'hp.json' ),
43 include_terms => [],
44 max_matrix_records_in_ram => $self->config->max_matrix_records_in_ram,
45 max_number_vars => $self->config->max_number_vars,
46 max_out => $self->config->max_out,
47 matrix_format => $self->config->matrix_format,
48 patients_of_interest => [],
49 poi_out_dir => catdir('./'),
50 reference_files => [],
51 similarity_metric_cohort => $self->config->similarity_metric_cohort,
52 sort_by => $self->config->sort_by,
53 );
54  
55 37 for my $attribute ( keys %defaults ) {
56 $ranker->{$attribute} = $defaults{$attribute}
57 518 ▶ unless exists $ranker->{$attribute};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ranker->{$attribute} 297 221 518
58 }
59  
60 37 return 1;
61 }
62  
63 37 ▶sub _validate_array_options {
Subroutine _validate_array_options: called CC=3 SCAR=11.1
64 37 my ( $self, $ranker ) = @_;
65  
66 37 for my $attribute (
67 qw(append_prefixes exclude_terms include_terms patients_of_interest reference_files)
68 )
69 {
70 die "<$attribute> must be an array ref\n"
71 185 ▶ unless ref $ranker->{$attribute} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ranker->{$attribute} eq "ARRAY" 0 185 185
72 }
73  
74 37 return 1;
75 }
76  
77 37 ▶sub _validate_path_options {
Subroutine _validate_path_options: called CC=3 SCAR=11.4
78 37 my ( $self, $ranker ) = @_;
79  
80 die "Error <$ranker->{hpo_file}> is not a valid file"
81 37 ▶ unless -e $ranker->{hpo_file};
Branch: 1 branch
BranchTrueFalseTotal
unless -e $ranker->{"hpo_file"} 0 37 37
82 die "<$ranker->{poi_out_dir}> dir does not exist"
83 37 ▶ unless -d $ranker->{poi_out_dir};
Branch: 1 branch
BranchTrueFalseTotal
unless -d $ranker->{"poi_out_dir"} 0 37 37
84  
85 37 return 1;
86 }
87  
88 37 ▶sub _validate_terms {
Subroutine _validate_terms: called CC=2 SCAR=6.9
89 37 my ( $self, $ranker ) = @_;
90  
91 37 for my $attribute (qw(include_terms exclude_terms)) {
92 74 $self->config->validate_terms( @{ $ranker->{$attribute} } );
93 }
94  
95 37 return 1;
96 }
97  
98 9 1;
« lib/Pheno/Ranker/Compare/Prepare.pm ↑ Summary lib/Pheno/Ranker/Compare/Ontology.pm »