Chobo/OntologyConf.pm

filter: Statementstmt 83.9% 89 / 106 Branchbran 59.5% 25 / 42 Conditioncond 75.0% 6 / 8 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 92.8% 13 / 14 Podpod n/a totaltotal 77.7% 136 / 175 CC 25 SCAR 14.7
CC
25
Cov
77%
__ANON__
7.1
__ANON__
6.0
__ANON__
5.2
CRAP 4.4
« Chobo/OntologyTerm.pm ↑ Summary Chobo/Role/ChadoStore.pm »
1 package PomBase::Chobo::OntologyConf;
2  
3 =head1 NAME
4  
5 PomBase::Chobo::OntologyConf - Configuration for ontology data
6  
7 =head1 AUTHOR
8  
9 Kim Rutherford C<< <kmr44@cam.ac.uk> >>
10  
11 =head1 BUGS
12  
13 Please report any bugs or feature requests to C<kmr44@cam.ac.uk>.
14  
15 =head1 SUPPORT
16  
17 You can find documentation for this module with the perldoc command.
18  
19 perldoc PomBase::Chobo::OntologyConf
20  
21 =over 4
22  
23 =back
24  
25 =head1 COPYRIGHT & LICENSE
26  
27 Copyright 2012 Kim Rutherford, all rights reserved.
28  
29 This program is free software; you can redistribute it and/or modify it
30 under the same terms as Perl itself.
31  
32 =head1 FUNCTIONS
33  
34 =cut
35  
36 6 our $VERSION = '0.041'; # VERSION
37  
38 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 our %field_conf = (
42 id => {
43 type => 'SINGLE',
44 },
45 name => {
46 type => 'SINGLE',
47 81 ▶ process => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
48 81 my $val = shift;
49 81 $val =~ s/\\"/"/g;
50 81 $val;
51 }
52 },
53 def => {
54 type => 'SINGLE_HASH',
55 57 ▶ process => sub {
Subroutine __ANON__: called CC=4 SCAR=14.4
56 57 my $val = shift;
57 57 ▶ if ($val =~ /"(.*)"(?:\s+\[(.*)\])?/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /"(.*)"(?:\s+\[(.*)\])?/) { } 57 0 57
58 57 my $definition = $1;
59 57 ▶ my $dbxrefs = $2 // '';
Condition100%2/2
$2 // ""
l!l
534
MC/DC100%1/1
$2 // ""
$2
Truth table100%2/2
A
A= $2
Aresult
11
00
60  
61 my @dbxrefs =
62 map {
63 # remove quoting
64 64 s|\\(.)|$1|g;
65 64 $_;
66 }
67 grep {
68 57 ▶ !m|^(?:url:)?https?\\?:| && /^\S+:\S+$/;
Condition33%1/3
!/^(?:url:)?https?\\?:/ && /^\S+:\S+$/
!ll&&!rl&&r
0064
MC/DC0%0/2
!/^(?:url:)?https?\\?:/ && /^\S+:\S+$/
!/^(?:url:)?https?\\?:/ /^\S+:\S+$/
Truth table33%1/3
not(A) && B
A= !/^(?:url:)?https?\\?:/B= /^\S+:\S+$/
ABresult
0X0
100
111
69 } split /\s*,\s/, $dbxrefs;
70  
71 return {
72 57 definition => $definition,
73 dbxrefs => \@dbxrefs,
74 }
75 } else {
76 0 croak qq(failed to parse "def:" line: $val);
77 }
78 },
79 2 ▶ merge => sub {
Subroutine __ANON__: called CC=4 SCAR=16.1
80 2 my $self = shift;
81 2 my $other = shift;
82  
83 2 ▶ if (!defined $other->def()) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $other->def) { } 1 1 2
84 1 return $self->def();
85 } else {
86 1 ▶ if (!defined $self->def()) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->def) { } 1 0 1
87 1 return $other->def();
88 } else {
89 0 ▶ if ($self->def()->{definition} ne $other->def()->{definition}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->def->{"definition"} ne $other->def->{"definition"}) 0 0 0
90 warn qq("def:" line differ\n ) . $self->def()->{definition} . "\nversus:\n " .
91 0 $other->def()->{definition};
92 }
93 0 return $self->def();
94 }
95 }
96 },
97 2 ▶ to_string => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
98 2 my $val = shift;
99 2 my $ret_string = $val->{definition};
100 2 $ret_string .= ' [' . (join ", ", @{$val->{dbxrefs}}) . ']';
101 }
102 },
103 comment => {
104 type => 'SINGLE',
105 },
106 replaced_by => {
107 type => 'SINGLE',
108 },
109 consider => {
110 type => 'SINGLE',
111 },
112 is_obsolete => {
113 type => 'SINGLE',
114 6 ▶ process => sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
115 6 my $val = shift;
116 6 ▶ if ($val eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($val eq 'true') { } 6 0 6
117 6 return 1;
118 } else {
119 0 return 0;
120 }
121 },
122 },
123 namespace => {
124 type => 'SINGLE',
125 7 ▶ merge => sub {
Subroutine __ANON__: called CC=5 SCAR=16.6
126 7 my $self = shift;
127 7 my $other = shift;
128  
129 7 my $self_namespace = $self->{namespace};
130 7 my $other_namespace = $other->{namespace};
131 7 ▶ if (defined $self_namespace &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self_namespace and defined $other_namespace) 3 4 7
Condition100%3/3
defined $self_namespace and defined $other_namespace
!ll&&!rl&&r
223
MC/DC100%2/2
defined $self_namespace and defined $other_namespace
defined $self_namespace defined $other_namespace
Truth table100%3/3
A and B
A= defined $self_namespaceB= defined $other_namespace
ABresult
0X0
100
111
132 defined $other_namespace) {
133 # if the namespace is the same as the db_name, remove it and use the
134 # namespace from the other term to avoid a namespace clash
135 3 ▶ if ($self_namespace eq $self->{db_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self_namespace eq $self->{'db_name'}) { } 0 3 3
136 0 $self->{namespace} = undef;
137 } else {
138 3 ▶ if ($other_namespace eq $other->{db_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($other_namespace eq $other->{"db_name"}) 0 3 3
139 0 $other->{namespace} = undef;
140 }
141 }
142 }
143 # do default merging
144 7 return undef;
145 },
146 },
147 alt_id => {
148 type => 'ARRAY',
149 },
150 is_a => {
151 type => 'ARRAY',
152 },
153 part_of => {
154 type => 'ARRAY',
155 },
156 subset => {
157 type => 'ARRAY',
158 },
159 xref => {
160 type => 'ARRAY',
161 15 ▶ process => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
162 15 my $val = shift;
163  
164 15 ▶ if ($val =~ /^([^\s:]+:[^\s]+)(?:$|\s)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /^([^\s:]+:[^\s]+)(?:$|\s)/) { } 14 1 15
165 14 return $1;
166 } else {
167 1 return undef;
168 }
169 },
170 },
171 relationship => {
172 type => 'ARRAY',
173 10 ▶ process => sub {
Subroutine __ANON__: called CC=3 SCAR=13.1
174 10 my $val = shift;
175  
176 10 ▶ if ($val =~ /^\s*(\S+)\s+(\S+)\s*(?:\{(.*)\})?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /^\s*(\S+)\s+(\S+)\s*(?:\{(.*)\})?$/) { } 10 0 10
177 10 my $relationship_name = $1;
178 10 my $other_term = $2;
179  
180 10 ▶ if ($relationship_name =~ /^:|:$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($relationship_name =~ /^:|:$/) 0 10 10
181 0 warn "illegal relationship name: $relationship_name\n";
182 0 return undef;
183 }
184  
185 return {
186 10 relationship_name => $relationship_name,
187 other_term => $other_term,
188 };
189 } else {
190 0 warn "can't parse relationship: $val\n";
191 0 return undef;
192 }
193 },
194 0 ▶ to_string => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
195 0 my $val = shift;
196  
197 0 ▶ if (ref $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val) { } 0 0 0
198 0 return $val->{relationship_name} . ' ' . $val->{other_term};
199 } else {
200 0 croak "can't output relationship '$val' - expected a reference";
201 }
202 },
203 },
204 synonym => {
205 type => 'ARRAY',
206 66 ▶ process => sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
207 66 my $val = shift;
208 66 ▶ if ($val =~ /^"(.*?[^\\])"\s*(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /^"(.*?[^\\])"\s*(.*)/) { } 66 0 66
209 66 my $synonym = $1;
210 66 my @dbxrefs = ();
211 66 my $rest = $2;
212  
213 66 $synonym =~ s/\\(.)/$1/g;
214  
215 66 my %ret = (
216 synonym => $synonym,
217 );
218  
219 66 my $scope_and_type;
220  
221 66 ▶ if ($rest =~ /^(?:\s*(\S.*)\s+)?\[([^\]]*)\]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /^(?:\s*(\S.*)\s+)?\[([^\]]*)\]/) { } 64 2 66
222 64 ▶ if (defined $1) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $1) { } 62 2 64
223 62 $scope_and_type = $1;
224 } else {
225 2 $scope_and_type = 'RELATED';
226 }
227  
228 64 my $dbxrefs_match = $2;
229  
230 64 ▶ if (defined $dbxrefs_match) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dbxrefs_match) 64 0 64
231 64 @dbxrefs = split /\s*,\s*/, $dbxrefs_match;
232 }
233 } else {
234 2 $scope_and_type = $rest;
235 }
236  
237 66 ▶ if (defined $scope_and_type) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $scope_and_type) 66 0 66
238 66 ▶ if ($scope_and_type =~ /(\S+)\s+(\S+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($scope_and_type =~ /(\S+)\s+(\S+)/) { } 4 62 66
239 4 my ($scope, $type) = ($1, $2, $3);
240  
241 4 $ret{scope} = $scope;
242 4 $ret{type} = $type;
243 } else {
244 62 $ret{scope} = $scope_and_type;
245 }
246 }
247  
248 66 $ret{dbxrefs} = \@dbxrefs;
249  
250 66 return \%ret;
251 } else {
252 0 die "unknown synonym format: $val\n";
253 }
254 },
255 17 ▶ to_string => sub {
Subroutine __ANON__: called CC=4 SCAR=14.5
256 17 my $val = shift;
257 17 my $ret_string = $val->{synonym};
258 17 ▶ if (defined $val->{scope}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val->{"scope"}) 17 0 17
259 17 $ret_string .= ' ' . $val->{scope};
260 }
261 17 ▶ if (defined $val->{type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val->{"type"}) 0 17 17
262 0 $ret_string .= ' ' . $val->{type};
263 }
264 17 ▶ if (defined $val->{dbxrefs}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val->{"dbxrefs"}) 17 0 17
265 17 $ret_string .= ' [' . (join ", ", @{$val->{dbxrefs}}) . ']';
266 }
267  
268 17 return $ret_string;
269 },
270 },
271 property_value => {
272 type => 'ARRAY',
273 5 ▶ process => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
274 5 my $raw_value = shift;
275  
276 5 $raw_value =~ s/\s+xsd:\w+\s*$//;
277  
278 5 my ($name, $value) = split(/\s+/, $raw_value, 2);
279  
280 return [
281 5 $name, $value
282 ]
283 },
284 },
285 6 );
286  
287 6 1;
« Chobo/OntologyTerm.pm ↑ Summary Chobo/Role/ChadoStore.pm »