lib/MS/CV.pm

filter: Statementstmt 100% 90 / 90 Branchbran 78.5% 22 / 28 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 16 / 16 Podpod 100% 5 / 5 totaltotal 95.7% 136 / 142 CC 20 SCAR 14.8
CC
20
Cov
95%
BEGIN
7.0
print_tree
7.0
is_a
6.0
CRAP 4.4
« lib/MS/Reader/MGF.pm ↑ Summary lib/MS/Reader/MSn/Spectrum.pm »
1 package MS::CV;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Exporter qw/import/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use File::ShareDir qw/dist_file/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 my $terms;
12 my %exports;
13 4 my %roots;
14 4 our %EXPORT_TAGS;
15 4 our @EXPORT_OK;
16  
17 4 ▶BEGIN {
Subroutine BEGIN: called CC=7 SCAR=19.5
18  
19 # read in ontology file
20 4 my $fn_obo = dist_file('MS' => 'cv.stor');
21 4 $terms = retrieve $fn_obo;
22  
23 # necessary for symbol table manipulation
24 4 ▶ no strict 'refs'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
25
26 # generate constants and track root terms
27 4 for my $id (keys %{$terms} ) {
28  
29 42036 my $ref = $terms->{$id};
30 42036 my $const_name = $ref->{constant} ;
31 42036 ▶ next if (! defined $const_name);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $const_name 0 42036 42036
32 42036 my $cv = $ref->{cv};
33 42036 ▶ die "name undefined for $id" if (! defined $const_name);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $const_name 0 42036 42036
34  
35 # define constant
36 42036 ▶ *$const_name = sub () {$id};
Subroutine __ANON__: called CC=1 SCAR=0.0
37  
38 42036 push @{ $exports{$cv} }, $const_name;
39 42036 push @MS::CV::EXPORT_OK, $const_name;
40 42036 ▶ push @{$roots{$cv} }, $id if (! exists $ref->{is_a});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ref->{"is_a"} 2872 39164 42036
41  
42 42036 ▶ if (defined $ref->{alt_constants}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref->{"alt_constants"}) 448 41588 42036
43 448 for my $const_name (@{ $ref->{alt_constants} }) {
44 # define constant
45 448 ▶ *$const_name = sub () {$id};
Subroutine __ANON__: called CC=1 SCAR=0.0
46 448 push @{ $exports{$cv} }, $const_name;
47 448 push @MS::CV::EXPORT_OK, $const_name;
48 }
49 }
50  
51 }
52  
53 4 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 # update exportable constants and functions
56 4 %MS::CV::EXPORT_TAGS = map {$_ => \@{ $exports{$_} }} keys %exports;
57 4 push @MS::CV::EXPORT_OK, qw/is_a print_tree units_for regex_for cv_name/;
58  
59 } # end BEGIN
60  
61 1 ▶sub cv_name {
Subroutine cv_name: called CC=1 SCAR=0.0
Pod documented
62  
63 1 return $terms->{$_[0]}->{name};
64  
65 }
66  
67  
68 24 ▶sub is_a {
Subroutine is_a: called CC=6 SCAR=17.9
Pod documented
69
70 24 my ($child, $parent) = @_;
71  
72 24 ▶ return if (! defined $terms->{$child});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $terms->{$child} 0 24 24
73 24 ▶ return 0 if (! defined $terms->{$child}->{is_a});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $terms->{$child}{"is_a"} 2 22 24
74  
75 22 my @parents = @{ $terms->{$child}->{is_a} };
76 22 my $retval = 0;
77 22 for (@parents) {
78 24 ▶ return 1 if ($_ eq $parent);
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $parent 2 22 24
79 22 $retval += is_a( $_ => $parent );
80 }
81 20 ▶ return $retval ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$retval ? : 9 11 20
82  
83 }
84  
85 1 ▶sub units_for {
Subroutine units_for: called CC=2 SCAR=7.0
Pod documented
86  
87 1 my ($id) = @_;
88  
89 1 ▶ return if (! defined $terms->{$id}->{has_units});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $terms->{$id}{"has_units"} 0 1 1
90 1 return [ @{ $terms->{$id}->{has_units} } ];
91  
92 }
93  
94 3 ▶sub regex_for {
Subroutine regex_for: called CC=2 SCAR=7.1
Pod documented
95  
96 3 my ($id) = @_;
97  
98 3 ▶ return if (! defined $terms->{$id}->{regexp});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $terms->{$id}{"regexp"} 0 3 3
99 3 return qr/$terms->{$id}->{regexp}/;
100  
101 }
102  
103 641 ▶sub print_tree {
Subroutine print_tree: called CC=7 SCAR=19.5
Pod documented
104  
105 641 my ($cv, $level, @parents) = @_;
106  
107 641 ▶ croak "CV $cv not valid" if (! defined $roots{$cv});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $roots{$cv} 0 641 641
108  
109 641 ▶ $level = $level // 0;
Condition100%2/2
$level // 0
l!l
6401
MC/DC100%1/1
$level // 0
$level
Truth table100%2/2
A
A= $level
Aresult
11
00
110 641 ▶ if (! @parents) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@parents) 1 640 641
111 1 @parents = @{ $roots{$cv} };
112 }
113  
114 641 for my $parent (@parents) {
115 9074 ▶ next if (! defined $terms->{$parent}->{constant});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $terms->{$parent}{"constant"} 23 9051 9074
116 print "---" x $level . $parent,
117 "\t" . $terms->{$parent}->{name},
118 9051 "\t" . $terms->{$parent}->{constant}, "\n";
119 9051 ++$level;
120 9051 ▶ if (defined $terms->{$parent}->{children}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $terms->{$parent}{"children"}) 640 8411 9051
121 640 print_tree ($cv, $level, keys %{ $terms->{$parent}->{children}});
122 }
123 9051 --$level;
124 }
125 641 return;
126  
127 }
128  
129 4 1;
130  
131  
132 __END__
« lib/MS/Reader/MGF.pm ↑ Summary lib/MS/Reader/MSn/Spectrum.pm »