blib/lib/MS/CV.pm

filter: Statementstmt 100% 84 / 84 Branchbran 78.5% 22 / 28 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 15 / 15 Podpod 100% 5 / 5 totaltotal 95.5% 129 / 135 CC 19 SCAR 14.0
CC
19
Cov
95%
print_tree
7.0
is_a
6.0
BEGIN
5.0
CRAP 4.0
« Build ↑ Summary blib/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 BEGIN {
18  
19 # read in ontology file
20 4 ▶ my $fn_obo = dist_file('MS' => 'cv.stor');
Subroutine BEGIN: called CC=5 SCAR=16.1
21 4 $terms = retrieve $fn_obo;
22  
23 # necessary for symbol table manipulation
24 4 ▶ no strict 'refs';
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 29548 my $ref = $terms->{$id};
30 29548 my $const_name = $ref->{constant} ;
31 29548 ▶ next if (! defined $const_name);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $const_name 2440 27108 29548
32 27108 my $cv = $ref->{cv};
33 27108 ▶ die "name undefined for $id" if (! defined $const_name);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $const_name 0 27108 27108
34  
35 # define constant
36 27108 ▶ *$const_name = sub () {$id};
Subroutine __ANON__: called CC=1 SCAR=0.0
37  
38 27108 push @{ $exports{$cv} }, $const_name;
39 27108 push @MS::CV::EXPORT_OK, $const_name;
40 27108 ▶ push @{$roots{$cv} }, $id if (! exists $ref->{is_a});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ref->{"is_a"} 564 26544 27108
41  
42 }
43  
44 4 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 # update exportable constants and functions
47 4 %MS::CV::EXPORT_TAGS = map {$_ => \@{ $exports{$_} }} keys %exports;
48 4 push @MS::CV::EXPORT_OK, qw/is_a print_tree units_for regex_for cv_name/;
49  
50 } # end BEGIN
51  
52 sub cv_name {
53  
54 1 ▶ return $terms->{$_[0]}->{name};
Subroutine cv_name: called CC=1 SCAR=0.0
Pod documented
55  
56 }
57  
58  
59 sub is_a {
60
61 24 ▶ my ($child, $parent) = @_;
Subroutine is_a: called CC=6 SCAR=17.9
Pod documented
62  
63 24 ▶ return undef if (! defined $terms->{$child});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $terms->{$child} 0 24 24
64 24 ▶ return 0 if (! defined $terms->{$child}->{is_a});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $terms->{$child}{"is_a"} 2 22 24
65  
66 22 my @parents = @{ $terms->{$child}->{is_a} };
67 22 my $retval = 0;
68 22 for (@parents) {
69 24 ▶ return 1 if ($_ eq $parent);
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $parent 2 22 24
70 22 $retval += is_a( $_ => $parent );
71 }
72 20 ▶ return $retval ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$retval ? : 9 11 20
73  
74 }
75  
76 sub units_for {
77  
78 1 ▶ my ($id) = @_;
Subroutine units_for: called CC=2 SCAR=7.0
Pod documented
79  
80 1 ▶ return undef if (! defined $terms->{$id}->{has_units});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $terms->{$id}{"has_units"} 0 1 1
81 1 return [ @{ $terms->{$id}->{has_units} } ];
82  
83 }
84  
85 sub regex_for {
86  
87 3 ▶ my ($id) = @_;
Subroutine regex_for: called CC=3 SCAR=11.3
Pod documented
88  
89 3 ▶ return undef if (! defined $terms->{$id}->{has_regexp});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $terms->{$id}{"has_regexp"} 0 3 3
90 croak "Multiple regular expressions not supported for $id\n"
91 3 ▶ if (defined $terms->{$id}->{has_regexp}->[1]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $terms->{$id}{"has_regexp"}[1] 0 3 3
92 3 my $rid = $terms->{$id}->{has_regexp}->[0];
93 3 return qr/$terms->{$rid}->{name}/;
94  
95 }
96  
97 sub print_tree {
98  
99 448 ▶ my ($cv, $level, @parents) = @_;
Subroutine print_tree: called CC=7 SCAR=19.5
Pod documented
100  
101 448 ▶ croak "CV $cv not valid" if (! defined $roots{$cv});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $roots{$cv} 0 448 448
102  
103 448 ▶ $level = $level // 0;
Condition100%2/2
$level // 0
l!l
4471
MC/DC100%1/1
$level // 0
$level
Truth table100%2/2
A
A= $level
Aresult
11
00
104 448 ▶ if (! @parents) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@parents) 1 447 448
105 1 @parents = @{ $roots{$cv} };
106 }
107  
108 448 for my $parent (@parents) {
109 3420 ▶ next if (! defined $terms->{$parent}->{constant});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $terms->{$parent}{"constant"} 19 3401 3420
110 print "---" x $level . $parent,
111 "\t" . $terms->{$parent}->{name},
112 3401 "\t" . $terms->{$parent}->{constant}, "\n";
113 3401 ++$level;
114 3401 ▶ if (defined $terms->{$parent}->{children}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $terms->{$parent}{"children"}) 447 2954 3401
115 447 print_tree ($cv, $level, keys %{ $terms->{$parent}->{children}});
116 }
117 3401 --$level;
118 }
119 448 return;
120  
121 }
122  
123 4 1;
124  
125  
126 __END__
« Build ↑ Summary blib/lib/MS/Reader/MSn/Spectrum.pm »