blib/lib/UMLS/Interface/CuiFinder.pm

filter: Statementstmt 6.0% 163 / 2695 Branchbran 1.1% 11 / 948 Conditioncond 0.6% 3 / 486 MC/DCmcdc 0.0% 0 / 298 Subroutinesub 10.4% 11 / 105 Podpod 0.0% 0 / 1 totaltotal 4.1% 188 / 4533 CC 698 SCAR 67.0
CC
698
Cov
4%
_config
5402.0
_getExtendedDefinition
1892.0
_setRelas
1406.0
CRAP 814.3
« blib/lib/UMLS/Interface/PathFinder.pm ↑ Summary blib/lib/UMLS/Interface/STFinder.pm »
1 # UMLS::Interface::CuiFinder
2 # (Last Updated $Id: CuiFinder.pm,v 1.84 2016/09/13 17:15:51 btmcinnes Exp $)
3 #
4 # Perl module that provides a perl interface to the
5 # Unified Medical Language System (UMLS)
6 #
7 # Copyright (c) 2004-2011,
8 #
9 # Bridget T. McInnes, University of Minnesota, Twin Cities
10 # bthomson at cs.umn.edu
11 #
12 # Siddharth Patwardhan, University of Utah, Salt Lake City
13 # sidd at cs.utah.edu
14 #
15 # Serguei Pakhomov, University of Minnesota, Twin Cities
16 # pakh0002 at umn.edu
17 #
18 # Ted Pedersen, University of Minnesota, Duluth
19 # tpederse at d.umn.edu
20 #
21 # Ying Liu, University of Minnesota, Twin Cities
22 # liux0935 at umn.edu
23 #
24 # This program is free software; you can redistribute it and/or
25 # modify it under the terms of the GNU General Public License
26 # as published by the Free Software Foundation; either version 2
27 # of the License, or (at your option) any later version.
28 #
29 # This program is distributed in the hope that it will be useful,
30 # but WITHOUT ANY WARRANTY; without even the implied warranty of
31 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 # GNU General Public License for more details.
33 #
34 # You should have received a copy of the GNU General Public License
35 # along with this program; if not, write to
36 #
37 # The Free Software Foundation, Inc.,
38 # 59 Temple Place - Suite 330,
39 # Boston, MA 02111-1307, USA.
40  
41 package UMLS::Interface::CuiFinder;
42  
43 58 ▶use Fcntl;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 58 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 58 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 58 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 58 ▶use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
48  
49 58 ▶use Digest::SHA1 qw(sha1 sha1_hex sha1_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
50  
51 # error handling variables
52 58 my $errorhandler = "";
53 58 my $pkg = "UMLS::Interface::CuiFinder";
54  
55 # debug variables
56 58 local(*DEBUG_FILE);
57  
58 # global variables
59 58 my $debug = 0;
60 58 my $umlsRoot = "C0000000";
61 58 my $version = "";
62  
63 # list of allowable sources
64 58 my $sources = "";
65 58 my %sabHash = ();
66 58 my %sabnamesHash = ();
67 58 my $sabstring = "";
68  
69 # list of allowable relations
70 58 my $relations = "";
71 58 my $childRelations = "";
72 58 my $parentRelations = "";
73 58 my $relstring = "";
74 58 my $relastring = "";
75  
76 # upper level taxonomy
77 58 my %parentTaxonomyArray = ();
78 58 my %childTaxonomyArray = ();
79  
80 # list of interested cuis - default is
81 # all given the specified set of sources
82 # and relations.
83 58 my %cuiListHash = ();
84  
85 # initialize the semantic groups and relations hash
86 58 my %semanticGroups = ();
87 58 my %semanticRelations = ();
88 58 my %sgConversion = ();
89 58 my %sgConversion1 = ();
90  
91 # database
92 58 my $indexDB = "umlsinterfaceindex";
93 58 my $umlsinterface = $ENV{UMLSINTERFACE_CONFIGFILE_DIR};
94  
95 # table names
96 58 my $tableName = "";
97 58 my $intrinsicTable = "";
98 58 my $parentTable = "";
99 58 my $childTable = "";
100 58 my $tableFile = "";
101 58 my $intrinsicTableHuman= "";
102 58 my $parentTableHuman = "";
103 58 my $childTableHuman = "";
104 58 my $tableNameHuman = "";
105 58 my $configFile = "";
106 58 my $childFile = "";
107 58 my $parentFile = "";
108 58 my $infoTable = "";
109 58 my $infoTableHuman = "";
110 58 my $cacheTable = "";
111 58 my $cacheTableHuman = "";
112  
113 # flags and options
114 58 my $umlsall = 0;
115 58 my $sabdef_umlsall = 0;
116 58 my $option_verbose = 0;
117 58 my $option_cuilist = 0;
118 58 my $option_t = 0;
119 58 my $option_config = 0;
120 58 my $defflag = 0;
121  
122 # definition containers
123 58 my $sabdefsources = "";
124 58 my %relDefHash = ();
125 58 my %sabDefHash = ();
126 58 my $reldefstring = "";
127 58 my $sabdefstring = "";
128 58 my $reladefchildren = "";
129 58 my $reladefparents = "";
130  
131 58 my %parameters = ();
132  
133 ######################################################################
134 # functions to initialize the package
135 ######################################################################
136  
137 # method to create a new UMLS::Interface object
138 # input : $parameters <- reference to a hash
139 # output: $self
140 sub new {
141  
142 36 ▶ my $self = {};
Subroutine new: called CC=2 SCAR=7.8
Pod undocumented
143 36 my $className = shift;
144 36 my $params = shift;
145  
146 # bless the object.
147 36 bless($self, $className);
148  
149 36 $self->_initializeGlobalVariables();
150  
151 # initialize error handler
152 36 $errorhandler = UMLS::Interface::ErrorHandler->new();
153 36 ▶ if(! defined $errorhandler) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $errorhandler) 0 36 36
154 0 print STDERR "The error handler did not get passed properly.\n";
155 0 exit;
156 }
157  
158 # initialize the object.
159 36 $self->_initialize($params);
160  
161 # set the semantic groups
162 0 $self->_setSemanticGroups();
163  
164 0 return $self;
165 }
166  
167 # method to re-initialize the UMLS::Interface parameters
168 sub _reConfig {
169  
170 0 ▶ my $self = shift;
Subroutine _reConfig: not called CC=1 SCAR=6.9
171 0 my $params = shift;
172  
173 0 my $function = "_reConfig";
174 0 &_debug($function);
175  
176 # re initialize the global variables
177 0 $self->_initializeGlobalVariables();
178  
179 # initialize the object.
180 0 $self->_initialize($params);
181  
182 0 return $self;
183
184
185 }
186 # method to initialize the UMLS::Interface global variables
187 sub _initializeGlobalVariables {
188
189 36 ▶ my $self = shift;
Subroutine _initializeGlobalVariables: called CC=1 SCAR=0.0
190  
191 36 my $function = "_initializeGlobalVariables";
192 36 &_debug($function);
193
194 # global variables
195 36 $debug = 0;
196 36 $version = "";
197  
198 # list of allowable sources
199 36 $sources = "";
200 36 %sabHash = ();
201 36 %sabnamesHash = ();
202 36 $sabstring = "";
203  
204 # list of allowable relations
205 36 $relations = "";
206 36 $childRelations = "";
207 36 $parentRelations = "";
208 36 $relstring = "";
209 36 $relastring = "";
210  
211 # upper level taxonomy
212 36 %parentTaxonomyArray = ();
213 36 %childTaxonomyArray = ();
214  
215 # list of interested cuis - default is
216 # all given the specified set of sources
217 # and relations.
218 36 %cuiListHash = ();
219  
220  
221 # table names
222 36 $tableName = "";
223 36 $parentTable = "";
224 36 $intrinsicTable = "";
225 36 $childTable = "";
226 36 $tableFile = "";
227 36 $intrinsicTableHuman= "";
228 36 $parentTableHuman = "";
229 36 $childTableHuman = "";
230 36 $tableNameHuman = "";
231 36 $configFile = "";
232 36 $childFile = "";
233 36 $parentFile = "";
234 36 $infoTable = "";
235 36 $infoTableHuman = "";
236 36 $cacheTable = "";
237 36 $cacheTableHuman = "";
238  
239 # flags and options
240 36 $umlsall = 0;
241 36 $option_verbose = 0;
242 36 $option_cuilist = 0;
243 36 $option_t = 0;
244 36 $option_config = 0;
245  
246 # definition containers
247 36 $sabdefsources = "";
248 36 %relDefHash = ();
249 36 %sabDefHash = ();
250 36 $reldefstring = "";
251 36 $sabdefstring = "";
252 36 $reladefchildren = "";
253 36 $reladefparents = "";
254 36 %parameters = ();
255  
256 }
257  
258 # method to initialize the UMLS::Interface object.
259 # input : $parameters <- reference to a hash
260 # output:
261 sub _initialize {
262  
263 36 ▶ my $self = shift;
Subroutine _initialize: called CC=4 SCAR=19.3
264 36 my $params = shift;
265  
266 36 my $function = "_initialize";
267 36 &_debug($function);
268  
269 # check self
270 36 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 36 36
Condition33%1/3
defined $self and ref $self
!ll&&!rl&&r
0036
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table33%1/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
271 0 $errorhandler->_error($pkg, $function, "", 2);
272 }
273  
274  
275 36 ▶ $params = {} if(!defined $params);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params 0 36 36
276  
277 # get some of the parameters
278 36 my $config = $params->{'config'};
279 36 my $cuilist = $params->{'cuilist'};
280 36 my $database = $params->{'database'};
281  
282 # to store the database object
283 36 my $db = $self->_setDatabase($params);
284
285 # set up the options
286 0 $self->_setOptions($params);
287  
288 # check that all of the tables required exist in the db
289 0 $self->_checkTablesExist();
290  
291 # set the version information
292 0 $self->_setVersion();
293  
294 # set the configuration
295 0 $self->_config($config);
296
297 # set the umls interface configuration variable
298 0 $self->_setEnvironmentVariable();
299  
300 # set the table and file names for indexing
301 0 $self->_setConfigurationFile();
302  
303 # set the configfile
304 0 $self->_setConfigFile();
305  
306 # load the cuilist if it has been defined
307 0 $self->_loadCuiList($cuilist);
308  
309 # create the index database
310 0 $self->_createIndexDB();
311  
312 # connect to the index database
313 0 $self->_connectIndexDB();
314  
315 # set the upper level taxonomy
316 0 $self->_setUpperLevelTaxonomy();
317  
318 # set the cache tables
319 0 $self->_setCacheTable();
320 }
321  
322 # this function returns the umls root
323 # input :
324 # output: $string <- string containing the root
325 sub _root {
326  
327 0 ▶ return $umlsRoot;
Subroutine _root: not called CC=1 SCAR=6.9
328 }
329  
330 # this function sets the upper level taxonomy between
331 # the sources and the root UMLS node
332 # input :
333 # output:
334 sub _setCacheTable {
335  
336 0 ▶ my $self = shift;
Subroutine _setCacheTable: not called CC=5 SCAR=34.0
337  
338 0 my $function = "_setCacheTable";
339 0 &_debug($function);
340  
341 # check self
342 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
343 0 $errorhandler->_error($pkg, $function, "", 2);
344 }
345  
346 # set the sourceDB handler
347 0 my $sdb = $self->{'sdb'};
348 0 ▶ if(!$sdb) { $errorhandler->_error($pkg, $function, "Error with sdb.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($sdb) 0 0 0
349  
350 # check if the cache table exists
351 # if does just return otherwise create it
352 0 ▶ if($self->_checkTableExists($cacheTable)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_checkTableExists($cacheTable)) { } 0 0 0
353 0 return;
354 }
355 else {
356 # create cache table
357 0 $sdb->do("CREATE TABLE IF NOT EXISTS $cacheTable (CUI1 char(8), CUI2 char(8), LENGTH char(8))");
358 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
359 # store the name in the table index
360 0 $sdb->do("INSERT INTO tableindex (TABLENAME, HEX) VALUES ('$cacheTableHuman', '$cacheTable')");
361 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
362 }
363 }
364  
365 # this function sets the upper level taxonomy between
366 # the sources and the root UMLS node
367 # input :
368 # output:
369 sub _setUpperLevelTaxonomy {
370  
371 0 ▶ my $self = shift;
Subroutine _setUpperLevelTaxonomy: not called CC=9 SCAR=45.0
372  
373 0 my $function = "_setUpperLevelTaxonomy";
374 0 &_debug($function);
375  
376 # check self
377 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
378 0 $errorhandler->_error($pkg, $function, "", 2);
379 }
380  
381 # set the sourceDB handler
382 0 my $sdb = $self->{'sdb'};
383 0 ▶ if(!$sdb) { $errorhandler->_error($pkg, $function, "Error with sdb.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($sdb) 0 0 0
384  
385 # check if the taxonomy is already set
386 0 my $ckeys = keys %childTaxonomyArray;
387 0 my $pkeys = keys %parentTaxonomyArray;
388 0 ▶ if($pkeys > 0) { return; }
Branch: 1 branch
BranchTrueFalseTotal
if ($pkeys > 0) 0 0 0
389  
390 # check if the parent and child tables exist and
391 # if they do just return otherwise create them
392 0 ▶ if($self->_checkTableExists($childTable) and
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_checkTableExists($childTable) and $self->_checkTableExists($parentTable)) { } 0 0 0
Condition0%0/3
$self->_checkTableExists($childTable) and $self->_checkTableExists($parentTable)
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_checkTableExists($childTable) and $self->_checkTableExists($parentTable)
$self->_checkTableExists($childTable) $self->_checkTableExists($parentTable)
Truth table0%0/3
A and B
A= $self->_checkTableExists($childTable)B= $self->_checkTableExists($parentTable)
ABresult
0X0
100
111
393 $self->_checkTableExists($parentTable)) {
394 0 $self->_loadTaxonomyArrays();
395 0 return;
396 }
397 else {
398 0 $self->_createTaxonomyTables();
399 }
400  
401 # if the parent and child files exist just load them into the database
402 0 ▶ if( (-e $childFile) and (-e $parentFile) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $childFile and -e $parentFile) { } 0 0 0
Condition0%0/3
-e $childFile and -e $parentFile
!ll&&!rl&&r
000
MC/DC0%0/2
-e $childFile and -e $parentFile
-e $childFile -e $parentFile
Truth table0%0/3
A and B
A= -e $childFileB= -e $parentFile
ABresult
0X0
100
111
403 0 $self->_loadTaxonomyTables();
404 }
405 # otherwise we need to create them
406 else {
407 0 $self->_createUpperLevelTaxonomy();
408 }
409 }
410  
411 # this function creates the upper level taxonomy between the
412 # the sources and the root UMLS node
413 # this function creates the upper level taxonomy between the
414 # the sources and the root UMLS node
415 # input :
416 # output:
417 sub _createUpperLevelTaxonomy {
418  
419 0 ▶ my $self = shift;
Subroutine _createUpperLevelTaxonomy: not called CC=19 SCAR=59.4
420  
421 0 my $function = "_createUpperLevelTaxonomy";
422 0 &_debug($function);
423  
424 # check self
425 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
426 0 $errorhandler->_error($pkg, $function, "", 2);
427 }
428  
429 # set the index DB handler
430 0 my $sdb = $self->{'sdb'};
431 0 ▶ if(!$sdb) { $errorhandler->_error($pkg, $function, "Error with sdb.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($sdb) 0 0 0
432  
433 # set up the database
434 0 my $db = $self->{'db'};
435 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
436  
437 # open the parent and child files to store the upper level
438 # taxonomy information if the verbose option is defined
439 0 ▶ if($option_verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($option_verbose) 0 0 0
440 0 ▶ open(CHD, ">$childFile") || die "Could not open $childFile\n";
Branch: 1 branch
BranchTrueFalseTotal
open CHD, ">$childFile" or die "Could not open $childFile\n" 0 0 0
441 0 ▶ open(PAR, ">$parentFile") || die "Could not open $parentFile\n";
Branch: 1 branch
BranchTrueFalseTotal
open PAR, ">$parentFile" or die "Could not open $parentFile\n" 0 0 0
442 }
443  
444 0 foreach my $sab (sort keys %sabnamesHash) {
445  
446 # get the sab's cui
447 0 my $sab_cui = $self->_getSabCui($sab);
448
449 # select all the CUIs from MRREL
450 0 my $allCuis = $self->_getCuis($sab);
451  
452 # select all the CUI1s from MRREL that have a parent link
453 # if a parent relation exists
454 0 my $parCuis = "";
455 0 my %parCuisHash = ();
456 0 ▶ if( !($parentRelations=~/\(\)/) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($parentRelations =~ /\(\)/) 0 0 0
457 0 $parCuis = $db->selectcol_arrayref("select CUI1 from MRREL where ($parentRelations) and (SAB=\'$sab\') and SUPPRESS='N'");
458 0 $errorhandler->_checkDbError($pkg, $function, $db);
459  
460 # load the cuis that have a parent into a temporary hash
461 0 foreach my $cui (@{$parCuis}) { $parCuisHash{$cui}++; }
462 }
463  
464 # load the cuis that do not have a parent into the parent
465 # and chilren taxonomy for the upper level
466 0 foreach my $cui (@{$allCuis}) {
467  
468 # if the cui has a parent move on
469 0 ▶ if(exists $parCuisHash{$cui}) { next; }
Branch: 1 branch
BranchTrueFalseTotal
if (exists $parCuisHash{$cui}) 0 0 0
470  
471 # already seen this cui so move on
472 0 ▶ if(exists $parentTaxonomyArray{$cui}) { next; }
Branch: 1 branch
BranchTrueFalseTotal
if (exists $parentTaxonomyArray{$cui}) 0 0 0
473  
474  
475 0 ▶ if($sab_cui eq $cui) { next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($sab_cui eq $cui) 0 0 0
476  
477 0 push @{$parentTaxonomyArray{$cui}}, $sab_cui;
478 0 push @{$childTaxonomyArray{$sab_cui}}, $cui;
479  
480 0 $sdb->do("INSERT INTO $parentTable (CUI1, CUI2) VALUES ('$cui', '$sab_cui')");
481 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
482  
483 0 $sdb->do("INSERT INTO $childTable (CUI1, CUI2) VALUES ('$sab_cui', '$cui')");
484 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
485  
486 # print this information to the parent and child
487 # file is the verbose option has been set
488 0 ▶ if($option_verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($option_verbose) 0 0 0
489 0 print PAR "$cui $sab_cui\n";
490 0 print CHD "$sab_cui $cui\n";
491 }
492 }
493  
494 # add the sab cuis to the parent and children Taxonomy
495 0 push @{$parentTaxonomyArray{$sab_cui}}, $umlsRoot;
496 0 push @{$childTaxonomyArray{$umlsRoot}}, $sab_cui;
497  
498 # print it to the table if the verbose option is set
499 0 ▶ if($option_verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($option_verbose) 0 0 0
500 0 print PAR "$sab_cui $umlsRoot\n";
501 0 print CHD "$umlsRoot $sab_cui\n";
502 }
503  
504 # store this information in the database
505 0 $sdb->do("INSERT INTO $parentTable (CUI1, CUI2) VALUES ('$sab_cui', '$umlsRoot')");
506 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
507  
508 0 $sdb->do("INSERT INTO $childTable (CUI1, CUI2) VALUES ('$umlsRoot', '$sab_cui')");
509 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
510 }
511  
512 # close the parent and child tables if opened
513 0 ▶ if($option_verbose) { close PAR; close CHD; }
Branch: 1 branch
BranchTrueFalseTotal
if ($option_verbose) 0 0 0
514  
515 # print out some information
516 0 my $pkey = keys %parentTaxonomyArray;
517 0 my $ckey = keys %childTaxonomyArray;
518  
519 0 ▶ if($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 0 0
520 0 print STDERR "Taxonomy is set:\n";
521 0 print STDERR " parentTaxonomyArray: $pkey\n";
522 0 print STDERR " childTaxonomyArray: $ckey\n\n";
523 }
524 }
525  
526 # this function creates the taxonomy tables if they don't
527 # already exist in the umlsinterfaceindex database
528 # input :
529 # output:
530 sub _createTaxonomyTables {
531  
532 0 ▶ my $self = shift;
Subroutine _createTaxonomyTables: not called CC=4 SCAR=30.0
533  
534 0 my $function = "_createTaxonomyTables";
535 0 &_debug($function);
536  
537 # check self
538 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
539 0 $errorhandler->_error($pkg, $function, "", 2);
540 }
541  
542 # set the index DB handler
543 0 my $sdb = $self->{'sdb'};
544 0 ▶ if(!$sdb) { $errorhandler->_error($pkg, $function, "Error with sdb.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($sdb) 0 0 0
545  
546 # create intrinsic table
547 0 $sdb->do("CREATE TABLE IF NOT EXISTS $intrinsicTable (CUI char(8), LEAVES int, SUBSUMERS int, INDEX(CUI))");
548 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
549  
550 # create parent table
551 0 $sdb->do("CREATE TABLE IF NOT EXISTS $parentTable (CUI1 char(8), CUI2 char(8))");
552 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
553  
554 # create child table
555 0 $sdb->do("CREATE TABLE IF NOT EXISTS $childTable (CUI1 char(8), CUI2 char(8))");
556 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
557  
558 # create info table
559 0 $sdb->do("CREATE TABLE IF NOT EXISTS $infoTable (ITEM char(8), INFO char(8))");
560 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
561  
562 # create the index table if it doesn't already exist
563 0 $sdb->do("CREATE TABLE IF NOT EXISTS tableindex (TABLENAME blob(1000000), HEX char(41))");
564 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
565  
566 # add them to the index table
567 0 $sdb->do("INSERT INTO tableindex (TABLENAME, HEX) VALUES ('$intrinsicTableHuman', '$intrinsicTable')");
568 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
569 0 $sdb->do("INSERT INTO tableindex (TABLENAME, HEX) VALUES ('$parentTableHuman', '$parentTable')");
570 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
571 0 $sdb->do("INSERT INTO tableindex (TABLENAME, HEX) VALUES ('$childTableHuman', '$childTable')");
572 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
573 0 $sdb->do("INSERT INTO tableindex (TABLENAME, HEX) VALUES ('$infoTableHuman', '$infoTable')");
574 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
575 }
576  
577 # this function loads the taxonomy tables if the
578 # configuration files exist for them
579 # input :
580 # output:
581 sub _loadTaxonomyTables {
582  
583 0 ▶ my $self = shift;
Subroutine _loadTaxonomyTables: not called CC=10 SCAR=47.0
584  
585 0 my $function = "_loadTaxonomyTables";
586 0 &_debug($function);
587  
588 # check self
589 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
590 0 $errorhandler->_error($pkg, $function, "", 2);
591 }
592  
593 # set the index DB handler
594 0 my $sdb = $self->{'sdb'};
595 0 ▶ if(!$sdb) { $errorhandler->_error($pkg, $function, "Error with sdb.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($sdb) 0 0 0
596  
597 0 ▶ open(PAR, $parentFile) || die "Could not open $parentFile\n";
Branch: 1 branch
BranchTrueFalseTotal
open PAR, $parentFile or die "Could not open $parentFile\n" 0 0 0
598 0 ▶ open(CHD, $childFile) || die "Could not open $childFile\n";
Branch: 1 branch
BranchTrueFalseTotal
open CHD, $childFile or die "Could not open $childFile\n" 0 0 0
599  
600 # load parent table
601 0 ▶ while(<PAR>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline PAR)) 0 0 0
602 0 chomp;
603 0 ▶ if($_=~/^\s*$/) { next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^\s*$/) 0 0 0
604 0 my ($cui1, $cui2) = split/\s+/;
605  
606 0 my $arrRef = $sdb->do("INSERT INTO $parentTable (CUI1, CUI2) VALUES ('$cui1', '$cui2')");
607 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
608 }
609  
610 # load child table
611 0 ▶ while(<CHD>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline CHD)) 0 0 0
612 0 chomp;
613 0 ▶ if($_=~/^\s*$/) { next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^\s*$/) 0 0 0
614 0 my ($cui1, $cui2) = split/\s+/;
615 0 my $arrRef = $sdb->do("INSERT INTO $childTable (CUI1, CUI2) VALUES ('$cui1', '$cui2')");
616 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
617 }
618 0 close PAR; close CHD;
619 }
620  
621 # this function sets the taxonomy arrays
622 # input :
623 # output:
624 sub _loadTaxonomyArrays {
625  
626 0 ▶ my $self = shift;
Subroutine _loadTaxonomyArrays: not called CC=6 SCAR=37.4
627  
628 0 my $function = "_loadTaxonomyArrays";
629 0 &_debug($function);
630  
631 # check self
632 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
633 0 $errorhandler->_error($pkg, $function, "", 2);
634 }
635  
636 # set the index DB handler
637 0 my $sdb = $self->{'sdb'};
638 0 ▶ if(!$sdb) { $errorhandler->_error($pkg, $function, "Error with sdb.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($sdb) 0 0 0
639  
640 # set the parent taxonomy
641 0 my $sql = qq{ SELECT CUI1, CUI2 FROM $parentTable};
642 0 my $sth = $sdb->prepare( $sql );
643 0 $sth->execute();
644 0 my($cui1, $cui2);
645 0 $sth->bind_columns( undef, \$cui1, \$cui2 );
646 0 ▶ while( $sth->fetch() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sth->fetch) 0 0 0
647 0 push @{$parentTaxonomyArray{$cui1}}, $cui2;
648 }
649 0 $errorhandler->_checkDbError($pkg, $function, $sth);
650 0 $sth->finish();
651  
652 # set the child taxonomy
653 0 $sql = qq{ SELECT CUI1, CUI2 FROM $childTable};
654 0 $sth = $sdb->prepare( $sql );
655 0 $sth->execute();
656 0 $sth->bind_columns( undef, \$cui1, \$cui2 );
657 0 ▶ while( $sth->fetch() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sth->fetch) 0 0 0
658 0 push @{$childTaxonomyArray{$cui1}}, $cui2;
659 }
660 0 $errorhandler->_checkDbError($pkg, $function, $sth);
661 0 $sth->finish();
662 }
663  
664 # function checks to see if a given table exists
665 # input : $table <- string
666 # output: 0 | 1 <- integers
667 sub _checkTableExists {
668  
669 0 ▶ my $self = shift;
Subroutine _checkTableExists: not called CC=7 SCAR=40.3
670 0 my $table = shift;
671  
672 0 my $function = "_checkTableExists";
673 0 &_debug($function);
674  
675 # check self
676 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
677 0 $errorhandler->_error($pkg, $function, "", 2);
678 }
679  
680 0 ▶ if(!defined $table) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $table) 0 0 0
681 0 $errorhandler->_error($pkg, $function, "Error with input variable \$table.", 4);
682 }
683  
684 # check that the database exists
685 0 my $sdb = $self->{'sdb'};
686 0 ▶ if(!$sdb) { $errorhandler->_error($pkg, $function, "Error with sdb.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($sdb) 0 0 0
687  
688 # set an execute the query to show all of the tables
689 0 my $sth = $sdb->prepare("show tables");
690 0 $sth->execute();
691 0 $errorhandler->_checkDbError($pkg, $function, $sth);
692  
693 0 my $t = "";
694 0 my %tables = ();
695 0 ▶ while(($t) = $sth->fetchrow()) {
Branch: 1 branch
BranchTrueFalseTotal
if (($t) = $sth->fetchrow) 0 0 0
696 0 $tables{lc($t)} = 1;
697 }
698 0 $sth->finish();
699  
700 0 ▶ if(! (exists$tables{lc($table)})) { return 0; }
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $tables{lc $table}) { } 0 0 0
701 0 else { return 1; }
702  
703 }
704  
705 # connect the database to the source db that holds
706 # the path tables for user specified source(s) and
707 # relation(s)
708 # input :
709 # output: $sdb <- reference to the database
710 sub _connectIndexDB {
711  
712 0 ▶ my $self = shift;
Subroutine _connectIndexDB: not called CC=6 SCAR=37.4
713  
714 0 my $function = "_connectIndexDB";
715 0 &_debug($function);
716  
717 # check self
718 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
719 0 $errorhandler->_error($pkg, $function, "", 2);
720 }
721  
722 0 my $sdb = "";
723 0 ▶ if(defined $self->{'username'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'username'}) { } 0 0 0
724  
725 0 my $username = $self->{'username'};
726 0 my $password = $self->{'password'};
727 0 my $hostname = $self->{'hostname'};
728 0 my $socket = $self->{'socket'};
729  
730 0 eval{$sdb = DBI->connect("DBI:mysql:database=$indexDB;mysql_socket=$socket;host=$hostname",
731 $username, $password,
732 {RaiseError => 1, PrintError => 1, AutoCommit => 0 });};
733  
734 0 ▶ if($@) { $errorhandler->_error($pkg, $function, "No database to connect to", 1); }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
735 }
736 else {
737 0 my $dsn = "DBI:mysql:$indexDB;mysql_read_default_group=client;";
738 0 eval{$sdb = DBI->connect($dsn);};
739 0 ▶ if($@) { $errorhandler->_error($pkg, $function, "No database to connect to", 1); }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
740 }
741  
742 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
743  
744 # set database parameters
745 0 $sdb->{'mysql_enable_utf8'} = 1;
746 0 $sdb->do('SET NAMES utf8');
747 0 $sdb->{mysql_auto_reconnect} = 1;
748  
749 0 $self->{'sdb'} = $sdb;
750  
751 0 return $sdb;
752 }
753  
754 # return the database connection to the umlsinterfaceindex
755 # input :
756 # output: $sdb <- database handler
757 sub _getIndexDB {
758 0 ▶ my $self = shift;
Subroutine _getIndexDB: not called CC=4 SCAR=30.0
759  
760 0 my $function = "_getIndexDB";
761 0 &_debug($function);
762  
763 # check self
764 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
765 0 $errorhandler->_error($pkg, $function, "", 2);
766 }
767  
768 # get the databawse
769 0 my $sdb = $self->{'sdb'};
770 0 ▶ if(!$sdb) { $errorhandler->_error($pkg, $function, "Error with sdb.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($sdb) 0 0 0
771  
772 # return the database
773 0 return $sdb;
774 }
775  
776 # return the database connection to the umls database
777 # input :
778 # output: $db <- database handler
779 sub _getDB {
780 0 ▶ my $self = shift;
Subroutine _getDB: not called CC=4 SCAR=30.0
781  
782 0 my $function = "_getDB";
783 0 &_debug($function);
784  
785 # check self
786 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
787 0 $errorhandler->_error($pkg, $function, "", 2);
788 }
789  
790 # get the databawse
791 0 my $db = $self->{'db'};
792 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
793  
794 # return the database
795 0 return $db;
796 }
797  
798 # this function creates the umlsinterfaceindex database connection
799 # input :
800 # output:
801 sub _createIndexDB {
802  
803 0 ▶ my $self = shift;
Subroutine _createIndexDB: not called CC=6 SCAR=37.4
804  
805 0 my $function = "_createIndexDB";
806 0 &_debug($function);
807  
808 # check self
809 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
810 0 $errorhandler->_error($pkg, $function, "", 2);
811 }
812  
813 # check that the database exists
814 0 my $db = $self->{'db'};
815 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
816  
817 # show all of the databases
818 0 my $sth = $db->prepare("show databases");
819 0 $sth->execute();
820 0 $errorhandler->_checkDbError($pkg, $function, $sth);
821  
822 # get all the databases in mysql
823 0 my $database = "";
824 0 my %databases = ();
825 0 ▶ while(($database) = $sth->fetchrow()) {
Branch: 1 branch
BranchTrueFalseTotal
if (($database) = $sth->fetchrow) 0 0 0
826 0 $databases{$database}++;
827 }
828 0 $sth->finish();
829  
830 # removing any spaces that may have been
831 # introduced in while creating its name
832 0 $indexDB=~s/\s+//g;
833  
834 # if the database doesn't exist create it
835 0 ▶ if(! (exists $databases{$indexDB})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $databases{$indexDB}) 0 0 0
836 0 $db->do("create database $indexDB");
837 0 $errorhandler->_checkDbError($pkg, $function, $db);
838 }
839 }
840  
841 # gets the DUI of a given CUI
842 # input: $concept -> string containing the cui
843 # output: $dui -> string containing the dui
844 sub _getDUI {
845
846 0 ▶ my $self = shift;
Subroutine _getDUI: not called CC=5 SCAR=34.0
847 0 my $concept = shift;
848
849 0 my $function = "_getDUI";
850
851 # check input values
852 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
853 0 $errorhandler->_error($pkg, $function, "", 2);
854 }
855
856 # check parameters
857 0 ▶ if(!defined $concept) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $concept) 0 0 0
858 0 $errorhandler->_error($pkg, $function, "Error with input variable \$concept.", 4);
859 }
860
861 # set the database
862 0 my $db = $self->{'db'};
863 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
864  
865 0 my $duis = $db->selectcol_arrayref("select SDUI from MRCONSO where CUI=\'$concept\' and SAB=\'MSH\'");
866
867 0 my $dui = shift @{$duis};
868  
869 0 return $dui;
870 }
871  
872  
873 # checks to see if a concept is in the CuiList
874 # input : $concept -> string containing the cui
875 # output: 1|0 -> indicating if the cui is in the cuilist
876 sub _inCuiList {
877  
878 0 ▶ my $self = shift;
Subroutine _inCuiList: not called CC=5 SCAR=34.0
879 0 my $concept = shift;
880  
881 0 my $function = "_inCuiList";
882  
883 # check input vluaes
884 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
885 0 $errorhandler->_error($pkg, $function, "", 2);
886 }
887  
888 # check parameters
889 0 ▶ if(!defined $concept) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $concept) 0 0 0
890 0 $errorhandler->_error($pkg, $function, "Error with input variable \$concept.", 4);
891 }
892  
893 0 ▶ if(exists $cuiListHash{$concept}) { return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if (exists $cuiListHash{$concept}) { } 0 0 0
894 0 else { return 0; }
895 }
896  
897  
898 # if the cuilist option is specified load the information
899 # input : $cuilist <- file containing the list of cuis
900 # output:
901 sub _loadCuiList {
902  
903 0 ▶ my $self = shift;
Subroutine _loadCuiList: not called CC=7 SCAR=40.3
904 0 my $cuilist = shift;
905  
906 0 my $function = "_loadCuiList";
907  
908 # check the input values
909 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
910 0 $errorhandler->_error($pkg, $function, "", 2);
911 }
912  
913 0 ▶ if(defined $cuilist) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cuilist) 0 0 0
914 0 ▶ open(CUILIST, $cuilist) || die "Could not open the cuilist file: $cuilist\n";
Branch: 1 branch
BranchTrueFalseTotal
open CUILIST, $cuilist or die "Could not open the cuilist file: $cuilist\n" 0 0 0
915 0 ▶ while(<CUILIST>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline CUILIST)) 0 0 0
916 0 chomp;
917  
918 0 ▶ if(! ($errorhandler->_validCui($_)) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($errorhandler->_validCui($_)) 0 0 0
919 0 $errorhandler->_error($pkg, $function, "Incorrect input value ($_) in cuilist.", 6);
920 }
921  
922 0 $cuiListHash{$_}++;
923 }
924 }
925 }
926  
927 # create the configuration file
928 # input :
929 # output:
930 sub _setConfigFile {
931  
932 0 ▶ my $self = shift;
Subroutine _setConfigFile: not called CC=8 SCAR=42.8
933  
934 0 ▶ if($option_verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($option_verbose) 0 0 0
935  
936 0 my $function = "_setConfigFile";
937 0 &_debug($function);
938  
939 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
940 0 $errorhandler->_error($pkg, $function, "", 2);
941 }
942  
943 0 ▶ if(! (-e $configFile)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not -e $configFile) 0 0 0
944  
945 0 ▶ open(CONFIG, ">$configFile") ||
Branch: 1 branch
BranchTrueFalseTotal
open CONFIG, ">$configFile" or die "Could not open configuration file: $configFile\n" 0 0 0
946 die "Could not open configuration file: $configFile\n";
947  
948 0 my @sarray = ();
949 0 my @rarray = ();
950  
951 0 print CONFIG "SAB :: include ";
952 0 ▶ while($sources=~/=\'(.*?)\'/g) { push @sarray, $1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($sources =~ /=\'(.*?)\'/g) 0 0 0
953 0 my $slist = join ", ", @sarray;
954 0 print CONFIG "$slist\n";
955  
956 0 print CONFIG "REL :: include ";
957 0 ▶ while($relations=~/=\'(.*?)\'/g) { push @rarray, $1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($relations =~ /=\'(.*?)\'/g) 0 0 0
958 0 my $rlist = join ", ", @rarray;
959 0 print CONFIG "$rlist\n";
960  
961 0 close CONFIG;
962  
963 0 my $temp = chmod 0777, $configFile;
964 }
965 }
966 }
967  
968  
969 # set the table and file names that store the upper level taxonomy and path information
970 # input :
971 # output:
972 sub _setConfigurationFile {
973  
974 0 ▶ my $self = shift;
Subroutine _setConfigurationFile: not called CC=19 SCAR=59.4
975  
976 0 my $function = "_setConfigurationFile";
977 0 &_debug($function);
978  
979 # check self
980 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
981 0 $errorhandler->_error($pkg, $function, "", 2);
982 }
983  
984 # get the database name that we are using
985 0 my $database = $self->{'database'};
986  
987 # set appropriate version output
988 0 my $ver = $version;
989 0 $ver=~s/-/_/g;
990  
991 # set table and upper level relations files as well the
992 # output of the configuration information for the user
993 0 $childFile = "$umlsinterface/$ver";
994 0 $parentFile = "$umlsinterface/$ver";
995 0 $tableFile = "$umlsinterface/$ver";
996  
997 0 $configFile = "$umlsinterface/$ver";
998  
999 0 $tableName = "$ver";
1000 0 $intrinsicTable= "$ver";
1001 0 $parentTable = "$ver";
1002 0 $childTable = "$ver";
1003 0 $infoTable = "$ver";
1004 0 $cacheTable = "$ver";
1005  
1006 0 my $output = "";
1007 0 $output .= "UMLS-Interface Configuration Information\n";
1008  
1009 0 my $saboutput = "";
1010 0 my %sabs = ();
1011 0 ▶ if($defflag == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($defflag == 1) { } 0 0 0
1012 0 $output .= " Sources (SABDEF):\n";
1013 0 foreach my $sab (sort keys %sabDefHash) { $saboutput .= " $sab\n"; }
1014 }
1015 else {
1016 0 $output .= " Sources (SAB):\n";
1017 0 foreach my $sab (sort keys %sabnamesHash) { $saboutput .= " $sab\n"; }
1018 }
1019
1020  
1021 0 foreach my $sab (sort keys %sabnamesHash) {
1022 0 $tableFile .= "_$sab";
1023 0 $childFile .= "_$sab";
1024 0 $parentFile .= "_$sab";
1025 0 $configFile .= "_$sab";
1026 0 $tableName .= "_$sab";
1027 0 $intrinsicTable.= "_$sab";
1028 0 $parentTable .= "_$sab";
1029 0 $childTable .= "_$sab";
1030 0 $cacheTable .= "_$sab";
1031 0 $infoTable .= "_$sab";
1032 }
1033  
1034 0 ▶ if($umlsall) {
Branch: 1 branch
BranchTrueFalseTotal
if ($umlsall) { } 0 0 0
1035 0 $output .= " UMLS_ALL\n";
1036 }
1037 else {
1038 0 $output .= $saboutput;
1039 }
1040  
1041 # seperate the RELs and the RELAs from $relations
1042 0 my %rels = (); my %relas = ();
1043  
1044  
1045 0 ▶ if($defflag == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($defflag == 1) { } 0 0 0
1046 0 $output .= " Relations (RELDEF):\n";
1047 0 foreach my $rel (sort keys %relDefHash) { $rels{$rel}++; }
1048 }
1049 else {
1050 0 $output .= " Relations (REL):\n";
1051 0 ▶ while($relations=~/=\'(.*?)\'/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($relations =~ /=\'(.*?)\'/g) 0 0 0
1052 0 my $rel = $1;
1053 0 ▶ if($rel=~/[a-z\_]+/) { $relas{$rel}++; }
Branch: 1 branch
BranchTrueFalseTotal
if ($rel =~ /[a-z\_]+/) { } 0 0 0
1054 0 else { $rels{$rel}++; }
1055 }
1056 }
1057  
1058 0 foreach my $rel (sort keys %rels) {
1059 0 $tableFile .= "_$rel";
1060 0 $childFile .= "_$rel";
1061 0 $parentFile .= "_$rel";
1062 0 $configFile .= "_$rel";
1063 0 $tableName .= "_$rel";
1064 0 $intrinsicTable.= "_$rel";
1065 0 $parentTable .= "_$rel";
1066 0 $childTable .= "_$rel";
1067 0 $cacheTable .= "_$rel";
1068 0 $infoTable .= "_$rel";
1069  
1070 0 $output .= " $rel\n";
1071 }
1072  
1073 0 my $rak = keys %relas;
1074 0 ▶ if($rak > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rak > 0) 0 0 0
1075 0 ▶ if($defflag == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($defflag == 1) { } 0 0 0
1076 0 $output .= " Relations (RELADEF):\n";
1077 }
1078 else {
1079 0 $output .= " Relations (RELA):\n";
1080 }
1081 }
1082 0 foreach my $rel (sort keys %relas) {
1083 0 $tableFile .= "_$rel";
1084 0 $childFile .= "_$rel";
1085 0 $parentFile .= "_$rel";
1086 0 $configFile .= "_$rel";
1087 0 $tableName .= "_$rel";
1088 0 $intrinsicTable.= "_$rel";
1089 0 $parentTable .= "_$rel";
1090 0 $childTable .= "_$rel";
1091 0 $cacheTable .= "_$rel";
1092 0 $infoTable .= "_$rel";
1093  
1094 0 $output .= " $rel\n";
1095 }
1096  
1097 0 $tableFile .= "_table";
1098 0 $childFile .= "_child";
1099 0 $parentFile .= "_parent";
1100 0 $configFile .= "_config";
1101 0 $tableName .= "_table";
1102 0 $intrinsicTable.= "_intrinsic";
1103 0 $parentTable .= "_parent";
1104 0 $childTable .= "_child";
1105 0 $cacheTable .= "_cache";
1106 0 $infoTable .= "_info";
1107  
1108 # convert the databases to the hex name
1109 # and store the human readable form
1110 0 $tableNameHuman = $tableName;
1111 0 $intrinsicTableHuman = $intrinsicTable;
1112 0 $childTableHuman = $childTable;
1113 0 $cacheTableHuman = $cacheTable;
1114 0 $parentTableHuman = $parentTable;
1115 0 $infoTableHuman = $infoTable;
1116  
1117 0 $tableName = "a" . sha1_hex($tableNameHuman);
1118 0 $intrinsicTable = "a" . sha1_hex($intrinsicTableHuman);
1119 0 $childTable = "a" . sha1_hex($childTableHuman);
1120 0 $parentTable = "a" . sha1_hex($parentTableHuman);
1121 0 $infoTable = "a" . sha1_hex($infoTableHuman);
1122 0 $cacheTable = "a" . sha1_hex($cacheTableHuman);
1123  
1124 0 ▶ if($option_verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($option_verbose) 0 0 0
1125 0 $output .= " Configuration file:\n";
1126 0 $output .= " $configFile\n";
1127 }
1128  
1129 0 $output .= " Database: \n";
1130 0 $output .= " $database ($version)\n\n";
1131  
1132 0 ▶ if($option_t == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($option_t == 0) 0 0 0
1133 0 ▶ if($option_config) {
Branch: 1 branch
BranchTrueFalseTotal
if ($option_config) { } 0 0 0
1134 0 print STDERR "$output\n";
1135 }
1136 else {
1137 0 print STDERR "UMLS-Interface Configuration Information:\n";
1138 0 print STDERR "(Default Information - no config file)\n\n";
1139 0 print STDERR " Sources (SAB):\n";
1140 0 print STDERR " MSH\n";
1141 0 print STDERR " Relations (REL):\n";
1142 0 print STDERR " PAR\n";
1143 0 print STDERR " CHD\n\n";
1144 0 print STDERR " Sources (SABDEF):\n";
1145 0 print STDERR " UMLS_ALL\n";
1146 0 print STDERR " Relations (RELDEF):\n";
1147 0 print STDERR " UMLS_ALL\n";
1148 }
1149 }
1150 }
1151  
1152 # set the configuration environment variable
1153 # input :
1154 # output:
1155 sub _setEnvironmentVariable {
1156  
1157 0 ▶ my $self = shift;
Subroutine _setEnvironmentVariable: not called CC=9 SCAR=45.0
1158  
1159 0 my $function = "_setEnvironmentVariable";
1160 0 &_debug($function);
1161  
1162 # check self
1163 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
1164 0 $errorhandler->_error($pkg, $function, "", 2);
1165 }
1166  
1167 0 ▶ if($option_verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($option_verbose) { } 0 0 0
1168 0 ▶ if(! (defined $umlsinterface) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $umlsinterface) 0 0 0
1169 0 my $answerFlag = 0;
1170 0 my $interfaceFlag = 0;
1171  
1172 0 ▶ while(! ($interfaceFlag) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $interfaceFlag) 0 0 0
1173  
1174 0 print STDERR "The UMLSINTERFACE_CONFIGFILE_DIR environment\n";
1175 0 print STDERR "variable has not been defined yet. Please \n";
1176 0 print STDERR "enter a location that the UMLS-Interface can\n";
1177 0 print STDERR "use to store its configuration files:\n";
1178  
1179 0 $umlsinterface = <STDIN>; chomp $umlsinterface;
1180  
1181 0 ▶ while(! ($answerFlag)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($answerFlag) 0 0 0
1182 0 print STDERR " Is $umlsinterface the correct location? ";
1183 0 my $answer = <STDIN>; chomp $answer;
1184 0 ▶ if($answer=~/[Yy]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($answer =~ /[Yy]/) { } 0 0 0
1185 0 $answerFlag = 1;
1186 0 $interfaceFlag = 1;
1187 }
1188 else {
1189 0 print STDERR "Please entire in location:\n";
1190 0 $umlsinterface = <STDIN>; chomp $umlsinterface;
1191 }
1192 }
1193  
1194 0 ▶ if(! (-e $umlsinterface) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $umlsinterface) 0 0 0
1195 0 system "mkdir -m 777 $umlsinterface";
1196 }
1197  
1198 0 print STDERR "Please set the UMLSINTERFACE_CONFIGFILE_DIR variable:\n\n";
1199 0 print STDERR "It can be set in csh as follows:\n\n";
1200 0 print STDERR " setenv UMLSINTERFACE_CONFIGFILE_DIR $umlsinterface\n\n";
1201 0 print STDERR "And in bash shell:\n\n";
1202 0 print STDERR " export UMLSINTERFACE_CONFIGFILE_DIR=$umlsinterface\n\n";
1203 0 print STDERR "Thank you!\n\n";
1204 }
1205 }
1206 }
1207 else {
1208 0 $umlsinterface = "";
1209 }
1210 }
1211  
1212 # sets the relations, parentRelations and childRelations
1213 # variables from the information in the config file
1214 # input : $includerelkeys <- integer
1215 # : $excluderelkeys <- integer
1216 # : $includerel <- reference to hash
1217 # : $excluderel <- reference to hash
1218 # output:
1219 sub _setRelations {
1220  
1221 0 ▶ my $self = shift;
Subroutine _setRelations: not called CC=22 SCAR=62.3
1222 0 my $includerelkeys = shift;
1223 0 my $excluderelkeys = shift;
1224 0 my $includerel = shift;
1225 0 my $excluderel = shift;
1226  
1227 0 my $function = "_setRelations";
1228 0 &_debug($function);
1229  
1230 # check self
1231 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
1232 0 $errorhandler->_error($pkg, $function, "", 2);
1233 }
1234  
1235 # check the parameters
1236 0 ▶ if(!(defined $includerelkeys) || !(defined $excluderelkeys) ||
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $includerelkeys and defined $excluderelkeys and defined $includerel and defined $excluderel) 0 0 0
Condition0%0/9
defined $includerelkeys and defined $excluderelkeys and defined $includerel and defined $excluderel
!ll&&!rl&&r
000
defined $includerelkeys and defined $excluderelkeys and defined $includerel
!ll&&!rl&&r
000
defined $includerelkeys and defined $excluderelkeys
!ll&&!rl&&r
000
MC/DC0%0/4
defined $includerelkeys and defined $excluderelkeys and defined $includerel and defined $excluderel
defined $includerelkeys defined $excluderelkeys defined $includerel defined $excluderel
Truth table0%0/5
A and B and C and D
A= defined $includerelkeysB= defined $excluderelkeysC= defined $includerelD= defined $excluderel
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1237 !(defined $includerel) || !(defined $excluderel)) {
1238 0 $errorhandler->_error($pkg, $function, "REL variables not defined.", 4);
1239 }
1240  
1241 0 ▶ if($includerelkeys <= 0 && $excluderelkeys <=0) { return; }
Branch: 1 branch
BranchTrueFalseTotal
if ($includerelkeys <= 0 and $excluderelkeys <= 0) 0 0 0
Condition0%0/3
$includerelkeys <= 0 and $excluderelkeys <= 0
!ll&&!rl&&r
000
MC/DC0%0/2
$includerelkeys <= 0 and $excluderelkeys <= 0
$includerelkeys <= 0 $excluderelkeys <= 0
Truth table0%0/3
A and B
A= $includerelkeys <= 0B= $excluderelkeys <= 0
ABresult
0X0
100
111
1242  
1243 # if the umls all option is set clear out the the includerel hash and
1244 # add the umlsall to the exclude. This way all should be included since
1245 # there will never be a source called UMLS_ALL - this is a bit of a dirty
1246 # swap but I think it will simplify the code and work
1247 0 ▶ if(exists ${$includerel}{"UMLS_ALL"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists do { $includerel }->{"UMLS_ALL"}) 0 0 0
1248 0 $includerel = ""; $includerelkeys = 0;
1249 0 ${$excluderel}{"UMLS_ALL"} = 1; $excluderelkeys = 1;
1250  
1251 }
1252  
1253 # set the database
1254 0 my $db = $self->{'db'};
1255 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
1256  
1257 0 $parentRelations = "(";
1258 0 $childRelations = "(";
1259 0 $relations = "(";
1260  
1261 # get the relations
1262 0 my @array = ();
1263 0 ▶ if($includerelkeys > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($includerelkeys > 0) { } 0 0 0
1264 0 @array = keys %{$includerel};
1265 }
1266 else {
1267  
1268 0 my $arrRef = $db->selectcol_arrayref("select distinct REL from MRREL");
1269 0 $errorhandler->_checkDbError($pkg, $function, $db);
1270 0 @array = @{$arrRef};
1271 }
1272  
1273  
1274 0 my $relcount = 0;
1275 0 my @parents = ();
1276 0 my @children = ();
1277 0 foreach my $rel (@array) {
1278  
1279 0 $relcount++;
1280  
1281 # if we are excluding check to see if this one should be excluded
1282 0 ▶ if( ($excluderelkeys > 0) and (exists ${$excluderel}{$rel}) ) { next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($excluderelkeys > 0 and exists do { $excluderel }->{$rel}) 0 0 0
Condition0%0/3
$excluderelkeys > 0 and exists do { $excluderel }->{$rel}
!ll&&!rl&&r
000
MC/DC0%0/2
$excluderelkeys > 0 and exists do { $excluderel }->{$rel}
$excluderelkeys > 0 exists do { $excluderel }->{$rel}
Truth table0%0/3
A and B
A= $excluderelkeys > 0B= exists do { $excluderel }->{$rel}
ABresult
0X0
100
111
1283  
1284 # otherwise store the relation in the relations variable
1285 0 ▶ if($relcount == ($#array+1)) { $relations .= "REL=\'$rel\'"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($relcount == $#array + 1) { } 0 0 0
1286 0 else { $relations .= "REL=\'$rel\' or "; }
1287  
1288 # put it in its proper parent or child array
1289 0 ▶ if ($rel=~/(PAR|RB)/) { push @parents, $rel; }
Branch: 2 branches
BranchTrueFalseTotal
if ($rel =~ /(PAR|RB)/) { } 0 0 0
elsif ($rel =~ /(CHD|RN)/) { } 0 0 0
1290 0 elsif($rel=~/(CHD|RN)/) { push @children, $rel; }
1291 0 else { push @parents, $rel; push @children, $rel; }
1292  
1293 }
1294  
1295 # set the parentRelations and childRelations variables
1296 0 ▶ if($#parents >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#parents >= 0) 0 0 0
1297 0 for my $i (0..($#parents-1)) {
1298 0 $parentRelations .= "REL=\'$parents[$i]\' or ";
1299 0 } $parentRelations .= "REL=\'$parents[$#parents]\'";
1300 }
1301 0 ▶ if($#children >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#children >= 0) 0 0 0
1302 0 for my $i (0..($#children-1)) {
1303 0 $childRelations .= "REL=\'$children[$i]\' or ";
1304 0 } $childRelations .= "REL=\'$children[$#children]\'";
1305 }
1306  
1307 0 $parentRelations .= ") ";
1308 0 $childRelations .= ") ";
1309 0 $relations .= ") ";
1310  
1311 }
1312  
1313 # sets the source variables from the information in the config file
1314 # input : $includesabdefkeys <- integer
1315 # : $excludesabdefkeys <- integer
1316 # : $includedefsab <- reference to hash
1317 # : $excludedefsab <- reference to hash
1318 # output:
1319 sub _setSabDef {
1320  
1321 0 ▶ my $self = shift;
Subroutine _setSabDef: not called CC=16 SCAR=56.1
1322 0 my $includesabdefkeys = shift;
1323 0 my $excludesabdefkeys = shift;
1324 0 my $includesabdef = shift;
1325 0 my $excludesabdef = shift;
1326  
1327 0 my $function = "_setSabDef";
1328 0 &_debug($function);
1329  
1330 # check self
1331 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
1332 0 $errorhandler->_error($pkg, $function, "", 2);
1333 }
1334  
1335 # check the parameters are defined
1336 0 ▶ if(!(defined $includesabdefkeys) || !(defined $excludesabdefkeys) ||
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $includesabdefkeys and defined $excludesabdefkeys and defined $includesabdef and defined $excludesabdef) 0 0 0
Condition0%0/9
defined $includesabdefkeys and defined $excludesabdefkeys and defined $includesabdef and defined $excludesabdef
!ll&&!rl&&r
000
defined $includesabdefkeys and defined $excludesabdefkeys and defined $includesabdef
!ll&&!rl&&r
000
defined $includesabdefkeys and defined $excludesabdefkeys
!ll&&!rl&&r
000
MC/DC0%0/4
defined $includesabdefkeys and defined $excludesabdefkeys and defined $includesabdef and defined $excludesabdef
defined $includesabdefkeys defined $excludesabdefkeys defined $includesabdef defined $excludesabdef
Truth table0%0/5
A and B and C and D
A= defined $includesabdefkeysB= defined $excludesabdefkeysC= defined $includesabdefD= defined $excludesabdef
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1337 !(defined $includesabdef) || !(defined $excludesabdef)) {
1338 0 $errorhandler->_error($pkg, $function, "SAB variables not defined", 4);
1339 }
1340  
1341 0 ▶ if($includesabdefkeys <= 0 && $excludesabdefkeys <=0) { return; }
Branch: 1 branch
BranchTrueFalseTotal
if ($includesabdefkeys <= 0 and $excludesabdefkeys <= 0) 0 0 0
Condition0%0/3
$includesabdefkeys <= 0 and $excludesabdefkeys <= 0
!ll&&!rl&&r
000
MC/DC0%0/2
$includesabdefkeys <= 0 and $excludesabdefkeys <= 0
$includesabdefkeys <= 0 $excludesabdefkeys <= 0
Truth table0%0/3
A and B
A= $includesabdefkeys <= 0B= $excludesabdefkeys <= 0
ABresult
0X0
100
111
1342  
1343 0 $sabdef_umlsall = 0;
1344  
1345 # if the umls all option is set clear out the the includesabdef hash and
1346 # add the umlsall to the exclude. This way all should be included since
1347 # there will never be a source called UMLS_ALL - this is a bit of a dirty
1348 # swap but I think it will simplify the code and work
1349 0 ▶ if(exists ${$includesabdef}{"UMLS_ALL"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists do { $includesabdef }->{"UMLS_ALL"}) 0 0 0
1350 0 $includesabdef = ""; $includesabdefkeys = 0;
1351 0 ${$excludesabdef}{"UMLS_ALL"} = 1; $excludesabdefkeys = 1;
1352 0 $sabdef_umlsall = 1;
1353 }
1354  
1355 # check that the db is defined
1356 0 my $db = $self->{'db'};
1357 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
1358  
1359 # get the sabs
1360 0 my @array = ();
1361 0 ▶ if($includesabdefkeys > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($includesabdefkeys > 0) { } 0 0 0
1362 0 @array = keys %{$includesabdef};
1363 }
1364 else {
1365 0 my $arrRef = $db->selectcol_arrayref("select distinct SAB from MRREL");
1366 0 $errorhandler->_checkDbError($pkg, $function, $db);
1367 0 @array = @{$arrRef};
1368 }
1369  
1370 # get the sabs
1371 0 my $sabcount = 0; my @sabarray = ();
1372 0 foreach my $sab (@array) {
1373 0 $sabcount++;
1374  
1375 # if we are excluding check to see if this sab can be included
1376 0 ▶ if(($excludesabdefkeys > 0) and (exists ${$excludesabdef}{$sab})) { next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($excludesabdefkeys > 0 and exists do { $excludesabdef }->{$sab}) 0 0 0
Condition0%0/3
$excludesabdefkeys > 0 and exists do { $excludesabdef }->{$sab}
!ll&&!rl&&r
000
MC/DC0%0/2
$excludesabdefkeys > 0 and exists do { $excludesabdef }->{$sab}
$excludesabdefkeys > 0 exists do { $excludesabdef }->{$sab}
Truth table0%0/3
A and B
A= $excludesabdefkeys > 0B= exists do { $excludesabdef }->{$sab}
ABresult
0X0
100
111
1377  
1378 # otherwise store it in the sabdef hash and store it in the array
1379 0 push @sabarray, "SAB=\'$sab\'";
1380  
1381 0 $sabDefHash{$sab}++;
1382 }
1383  
1384 0 ▶ if(!$sabdef_umlsall) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $sabdef_umlsall) 0 0 0
1385 0 my $string = join " or ", @sabarray;
1386 0 $sabdefsources = "( $string )";
1387 }
1388 }
1389  
1390 # sets the relations, parentRelations and childRelations
1391 # variables from the information in the config file
1392 # input : $includereldefkeys <- integer
1393 # : $excludereldefkeys <- integer
1394 # : $includereldef <- reference to hash
1395 # : $excludereldef <- reference to hash
1396 # output:
1397 sub _setRelDef {
1398  
1399 0 ▶ my $self = shift;
Subroutine _setRelDef: not called CC=23 SCAR=63.1
1400 0 my $includereldefkeys = shift;
1401 0 my $excludereldefkeys = shift;
1402 0 my $includereldef = shift;
1403 0 my $excludereldef = shift;
1404  
1405 0 my $function = "_setRelDef";
1406 0 &_debug($function);
1407  
1408 # check self
1409 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
1410 0 $errorhandler->_error($pkg, $function, "", 2);
1411 }
1412  
1413 # check the parameters are defined
1414 0 ▶ if(!(defined $includereldefkeys) || !(defined $excludereldefkeys) ||
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $includereldefkeys and defined $excludereldefkeys and defined $includereldef and defined $excludereldef) 0 0 0
Condition0%0/9
defined $includereldefkeys and defined $excludereldefkeys and defined $includereldef and defined $excludereldef
!ll&&!rl&&r
000
defined $includereldefkeys and defined $excludereldefkeys and defined $includereldef
!ll&&!rl&&r
000
defined $includereldefkeys and defined $excludereldefkeys
!ll&&!rl&&r
000
MC/DC0%0/4
defined $includereldefkeys and defined $excludereldefkeys and defined $includereldef and defined $excludereldef
defined $includereldefkeys defined $excludereldefkeys defined $includereldef defined $excludereldef
Truth table0%0/5
A and B and C and D
A= defined $includereldefkeysB= defined $excludereldefkeysC= defined $includereldefD= defined $excludereldef
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1415 !(defined $includereldef) || !(defined $excludereldef)) {
1416 0 $errorhandler->_error($pkg, $function, "RELDEF variables not defined.", 4);
1417 }
1418  
1419 0 ▶ if($includereldefkeys <= 0 && $excludereldefkeys <=0) { return; }
Branch: 1 branch
BranchTrueFalseTotal
if ($includereldefkeys <= 0 and $excludereldefkeys <= 0) 0 0 0
Condition0%0/3
$includereldefkeys <= 0 and $excludereldefkeys <= 0
!ll&&!rl&&r
000
MC/DC0%0/2
$includereldefkeys <= 0 and $excludereldefkeys <= 0
$includereldefkeys <= 0 $excludereldefkeys <= 0
Truth table0%0/3
A and B
A= $includereldefkeys <= 0B= $excludereldefkeys <= 0
ABresult
0X0
100
111
1420  
1421 # if the umls all option is set clear out the the includereldef hash and
1422 # add the umlsall to the exclude. This way all should be included since
1423 # there will never be a source called UMLS_ALL - this is a bit of a dirty
1424 # swap but I think it will simplify the code and work
1425 0 ▶ if(exists ${$includereldef}{"UMLS_ALL"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists do { $includereldef }->{"UMLS_ALL"}) 0 0 0
1426 0 $includereldef = ""; $includereldefkeys = 0;
1427 0 ${$excludereldef}{"UMLS_ALL"} = 1; $excludereldefkeys = 1;
1428 }
1429  
1430 # set the database
1431 0 my $db = $self->{'db'};
1432 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
1433  
1434 # get the relations
1435 0 my @array = ();
1436 0 ▶ if($includereldefkeys > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($includereldefkeys > 0) { } 0 0 0
1437 0 @array = keys %{$includereldef};
1438 }
1439 else {
1440  
1441 0 my $arrRef = $db->selectcol_arrayref("select distinct REL from MRREL");
1442 0 $errorhandler->_checkDbError($pkg, $function, $db);
1443 0 @array = @{$arrRef};
1444 }
1445  
1446 0 my $relcount = 0;
1447  
1448 0 foreach my $rel (@array) {
1449  
1450 0 $relcount++;
1451  
1452 # if we are excluding check to see if this one should be excluded
1453 0 ▶ if( ($excludereldefkeys > 0) and (exists ${$excludereldef}{$rel}) ) { next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($excludereldefkeys > 0 and exists do { $excludereldef }->{$rel}) 0 0 0
Condition0%0/3
$excludereldefkeys > 0 and exists do { $excludereldef }->{$rel}
!ll&&!rl&&r
000
MC/DC0%0/2
$excludereldefkeys > 0 and exists do { $excludereldef }->{$rel}
$excludereldefkeys > 0 exists do { $excludereldef }->{$rel}
Truth table0%0/3
A and B
A= $excludereldefkeys > 0B= exists do { $excludereldef }->{$rel}
ABresult
0X0
100
111
1454  
1455 # otherwise store the relation in the reldef hash
1456 0 $relDefHash{$rel}++;
1457 }
1458  
1459  
1460 # now add the TERM and CUI which are not actual relations but should be in
1461 # the relDefHash if in the includereldef or not in the excludereldef or
1462 # nothing has been defined
1463 0 ▶ if($includereldefkeys > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($includereldefkeys > 0) { } 0 0 0
elsif ($excludereldefkeys > 0) { } 0 0 0
1464 0 ▶ if(exists ${$includereldef}{"TERM"}) { $relDefHash{"TERM"}++; }
Branch: 1 branch
BranchTrueFalseTotal
if (exists do { $includereldef }->{"TERM"}) 0 0 0
1465 0 ▶ if(exists ${$includereldef}{"CUI"}) { $relDefHash{"CUI"}++; }
Branch: 1 branch
BranchTrueFalseTotal
if (exists do { $includereldef }->{"CUI"}) 0 0 0
1466 0 ▶ if(exists ${$includereldef}{"ST"}) { $relDefHash{"ST"}++; }
Branch: 1 branch
BranchTrueFalseTotal
if (exists do { $includereldef }->{"ST"}) 0 0 0
1467 }
1468 elsif($excludereldefkeys > 0) {
1469 0 ▶ if(! exists ${$excludereldef}{"TERM"}) { $relDefHash{"TERM"}++; }
Branch: 1 branch
BranchTrueFalseTotal
unless (exists do { $excludereldef }->{"TERM"}) 0 0 0
1470 0 ▶ if(! exists ${$excludereldef}{"CUI"}) { $relDefHash{"CUI"}++; }
Branch: 1 branch
BranchTrueFalseTotal
unless (exists do { $excludereldef }->{"CUI"}) 0 0 0
1471 0 ▶ if(! exists ${$excludereldef}{"ST"}) { $relDefHash{"ST"}++; }
Branch: 1 branch
BranchTrueFalseTotal
if (not exists do { $excludereldef }->{"ST"}) 0 0 0
1472 }
1473 else {
1474 0 $relDefHash{"TERM"}++; $relDefHash{"CUI"}++; $relDefHash{"ST"}++;
1475 }
1476 }
1477  
1478 # sets the variables for using the entire umls rather than just a subset
1479 # input :
1480 # output:
1481 sub _setSabUmlsAll {
1482  
1483 0 ▶ my $self = shift;
Subroutine _setSabUmlsAll: not called CC=5 SCAR=34.0
1484  
1485 0 my $function = "_setSabUmlsAll";
1486 0 &_debug($function);
1487  
1488 # check input value
1489 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
1490 0 $errorhandler->_error($pkg, $function, "", 2);
1491 }
1492  
1493 # set the database
1494 0 my $db = $self->{'db'};
1495 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
1496  
1497 0 my $arrRef = $db->selectcol_arrayref("select distinct SAB from MRREL where $relations");
1498 0 $errorhandler->_checkDbError($pkg, $function, $db);
1499  
1500 0 foreach my $sab (@{$arrRef}) {
1501 0 my $cui = $self->_getSabCui($sab);
1502  
1503 0 $sabnamesHash{$sab}++;
1504 0 $sabHash{$cui}++;
1505 }
1506 }
1507  
1508 # sets the source variables from the information in the config file
1509 # input : $includesabkeys <- integer
1510 # : $excludesabkeys <- integer
1511 # : $includesab <- reference to hash
1512 # : $excludesab <- reference to hash
1513 # output:
1514 sub _setSabs {
1515  
1516 0 ▶ my $self = shift;
Subroutine _setSabs: not called CC=16 SCAR=56.1
1517 0 my $includesabkeys = shift;
1518 0 my $excludesabkeys = shift;
1519 0 my $includesab = shift;
1520 0 my $excludesab = shift;
1521  
1522 0 my $function = "_setSabs";
1523 0 &_debug($function);
1524  
1525 # check input value
1526 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
1527 0 $errorhandler->_error($pkg, $function, "", 2);
1528 }
1529  
1530 # check the parameters are defined
1531 0 ▶ if(!(defined $includesabkeys) || !(defined $excludesabkeys) ||
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $includesabkeys and defined $excludesabkeys and defined $includesab and defined $excludesab) 0 0 0
Condition0%0/9
defined $includesabkeys and defined $excludesabkeys and defined $includesab and defined $excludesab
!ll&&!rl&&r
000
defined $includesabkeys and defined $excludesabkeys and defined $includesab
!ll&&!rl&&r
000
defined $includesabkeys and defined $excludesabkeys
!ll&&!rl&&r
000
MC/DC0%0/4
defined $includesabkeys and defined $excludesabkeys and defined $includesab and defined $excludesab
defined $includesabkeys defined $excludesabkeys defined $includesab defined $excludesab
Truth table0%0/5
A and B and C and D
A= defined $includesabkeysB= defined $excludesabkeysC= defined $includesabD= defined $excludesab
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1532 !(defined $includesab) || !(defined $excludesab)) {
1533 0 $errorhandler->_error($pkg, $function, "SAB variables not defined.", 4);
1534 }
1535  
1536 # return if no sab or rel options were in the config file
1537 0 ▶ if($includesabkeys <= 0 && $excludesabkeys <=0) { return; }
Branch: 1 branch
BranchTrueFalseTotal
if ($includesabkeys <= 0 and $excludesabkeys <= 0) 0 0 0
Condition0%0/3
$includesabkeys <= 0 and $excludesabkeys <= 0
!ll&&!rl&&r
000
MC/DC0%0/2
$includesabkeys <= 0 and $excludesabkeys <= 0
$includesabkeys <= 0 $excludesabkeys <= 0
Truth table0%0/3
A and B
A= $includesabkeys <= 0B= $excludesabkeys <= 0
ABresult
0X0
100
111
1538  
1539 # initialize the sources
1540 0 $sources = "";
1541  
1542 # if the umls all option is set clear out the the includesab hash and
1543 # add the umlsall to the exclude. This way all should be included since
1544 # there will never be a source called UMLS_ALL - this is a bit of a dirty
1545 # swap but I think it will simplify the code and work
1546 0 ▶ if(exists ${$includesab}{"UMLS_ALL"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists do { $includesab }->{"UMLS_ALL"}) 0 0 0
1547 0 $includesab = ""; $includesabkeys = 0;
1548 0 ${$excludesab}{"UMLS_ALL"} = 1; $excludesabkeys = 1;
1549 0 $umlsall = 1;
1550 0 $sources = "UMLS_ALL";
1551 }
1552  
1553 # check that the db is defined
1554 # set the database
1555 0 my $db = $self->{'db'};
1556 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
1557  
1558 # get the sabs
1559 0 my @array = ();
1560 0 ▶ if($includesabkeys > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($includesabkeys > 0) { } 0 0 0
1561 0 @array = keys %{$includesab};
1562 }
1563 else {
1564 0 my $arrRef = $db->selectcol_arrayref("select distinct SAB from MRREL where $relations");
1565 0 $errorhandler->_checkDbError($pkg, $function, $db);
1566 0 @array = @{$arrRef};
1567 }
1568  
1569 0 my $sabcount = 0;
1570 0 foreach my $sab (@array) {
1571  
1572 0 $sabcount++;
1573  
1574 # if we are excluding check to see if this sab can be included
1575 0 ▶ if(($excludesabkeys > 0) and (exists ${$excludesab}{$sab})) { next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($excludesabkeys > 0 and exists do { $excludesab }->{$sab}) 0 0 0
Condition0%0/3
$excludesabkeys > 0 and exists do { $excludesab }->{$sab}
!ll&&!rl&&r
000
MC/DC0%0/2
$excludesabkeys > 0 and exists do { $excludesab }->{$sab}
$excludesabkeys > 0 exists do { $excludesab }->{$sab}
Truth table0%0/3
A and B
A= $excludesabkeys > 0B= exists do { $excludesab }->{$sab}
ABresult
0X0
100
111
1576  
1577 # include the sab in the sources variable
1578 0 ▶ if($sabcount == ($#array+1)) { $sources .="SAB=\'$sab\'"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($sabcount == $#array + 1) { } 0 0 0
1579 0 else { $sources .="SAB=\'$sab\' or "; }
1580  
1581 # get the sabs cui
1582 0 my $cui = $self->_getSabCui($sab);
1583  
1584 # store the sabs cui and name information
1585 0 $sabnamesHash{$sab}++;
1586 0 $sabHash{$cui}++;
1587 }
1588 }
1589  
1590 # sets the rela variables from the information in the config file
1591 # input : $includerelakeys <- integer
1592 # : $excluderelakeys <- integer
1593 # : $includerela <- reference to hash
1594 # : $excluderela <- reference to hash
1595 # output:
1596 sub _setRelas {
1597  
1598 0 ▶ my $self = shift;
Subroutine _setRelas: not called CC=37 SCAR=72.5
1599 0 my $includerelakeys = shift;
1600 0 my $excluderelakeys = shift;
1601 0 my $includerela = shift;
1602 0 my $excluderela = shift;
1603  
1604 0 my $function = "_setRelas";
1605 0 &_debug($function);
1606  
1607 # check the input values
1608 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
1609 0 $errorhandler->_error($pkg, $function, "", 2);
1610 }
1611  
1612 # check the parameters are defined
1613 0 ▶ if(!(defined $includerelakeys) || !(defined $excluderelakeys) ||
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $includerelakeys and defined $excluderelakeys and defined $includerela and defined $excluderela) 0 0 0
Condition0%0/9
defined $includerelakeys and defined $excluderelakeys and defined $includerela and defined $excluderela
!ll&&!rl&&r
000
defined $includerelakeys and defined $excluderelakeys and defined $includerela
!ll&&!rl&&r
000
defined $includerelakeys and defined $excluderelakeys
!ll&&!rl&&r
000
MC/DC0%0/4
defined $includerelakeys and defined $excluderelakeys and defined $includerela and defined $excluderela
defined $includerelakeys defined $excluderelakeys defined $includerela defined $excluderela
Truth table0%0/5
A and B and C and D
A= defined $includerelakeysB= defined $excluderelakeysC= defined $includerelaD= defined $excluderela
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1614 !(defined $includerela) || !(defined $excluderela)) {
1615 0 $errorhandler->_error($pkg, $function, "RELA variables not defined.", 4);
1616 }
1617  
1618 # if no relas were specified just return
1619 0 ▶ if($includerelakeys <= 0 && $excluderelakeys <=0) { return }
Branch: 1 branch
BranchTrueFalseTotal
if ($includerelakeys <= 0 and $excluderelakeys <= 0) 0 0 0
Condition0%0/3
$includerelakeys <= 0 and $excluderelakeys <= 0
!ll&&!rl&&r
000
MC/DC0%0/2
$includerelakeys <= 0 and $excluderelakeys <= 0
$includerelakeys <= 0 $excluderelakeys <= 0
Truth table0%0/3
A and B
A= $includerelakeys <= 0B= $excluderelakeys <= 0
ABresult
0X0
100
111
1620  
1621 # set the database
1622 0 my $db = $self->{'db'};
1623 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
1624  
1625 # initalize the hash tables that will hold children and parent relas
1626 0 my %childrelas = ();
1627 0 my %parentrelas = ();
1628  
1629 # set the parent relations
1630 0 my $prelations = "";
1631 0 ▶ if($relations=~/PAR/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($relations =~ /PAR/) { } 0 0 0
elsif ($relations =~ /RB/) { } 0 0 0
1632 0 ▶ if($relations=~/RB/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($relations =~ /RB/) { } 0 0 0
1633 0 $prelations = "(REL='PAR') or (REL='RB')";
1634 0 } else { $prelations = "(REL='PAR')"; }
1635 0 } elsif($relations=~/RB/) { $prelations = "(REL='RB')"; }
1636  
1637 # set the child relations
1638 0 my $crelations = "";
1639 0 ▶ if($relations=~/CHD/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($relations =~ /CHD/) { } 0 0 0
elsif ($relations =~ /RB/) { } 0 0 0
1640 0 ▶ if($relations=~/RN/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($relations =~ /RN/) { } 0 0 0
1641 0 $crelations = "(REL='CHD') or (REL='RN')";
1642 0 } else { $crelations = "(REL='CHD')"; }
1643 0 } elsif($relations=~/RB/) { $crelations = "(REL='RN')"; }
1644  
1645 # get the rela relations that exist for the given set of sources and
1646 # relations for the children relations that are specified in the config
1647 0 my $sth = "";
1648 0 ▶ if($umlsall) {
Branch: 1 branch
BranchTrueFalseTotal
if ($umlsall) { } 0 0 0
1649 0 $sth = $db->prepare("select distinct RELA from MRREL where $crelations");
1650 0 $errorhandler->_checkDbError($pkg, $function, $db);
1651 }
1652 else {
1653 0 $sth = $db->prepare("select distinct RELA from MRREL where $crelations and ($sources)");
1654 0 $errorhandler->_checkDbError($pkg, $function, $db);
1655 }
1656 0 $sth->execute();
1657 0 $errorhandler->_checkDbError($pkg, $function, $sth);
1658  
1659 # get all the relas for the children
1660 0 my $crela = "";
1661 0 ▶ while(($crela) = $sth->fetchrow()) {
Branch: 1 branch
BranchTrueFalseTotal
if (($crela) = $sth->fetchrow) 0 0 0
1662 0 ▶ if(defined $crela) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $crela) 0 0 0
1663 0 ▶ if($crela ne "NULL") {
Branch: 1 branch
BranchTrueFalseTotal
if ($crela ne "NULL") 0 0 0
1664 0 $childrelas{$crela}++;
1665 }
1666 }
1667 }
1668 0 $sth->finish();
1669  
1670 0 my $crelakeys = keys %childrelas;
1671 0 ▶ if($crelakeys <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($crelakeys <= 0) 0 0 0
1672 0 $errorhandler->_error($pkg,
1673 $function,
1674 "There are no RELA relations for the given sources/relations.",
1675 5);
1676 }
1677  
1678  
1679 # get the rela relations that exist for the given set of sources and
1680 # relations for the children relations that are specified in the config
1681 0 ▶ if($umlsall) {
Branch: 1 branch
BranchTrueFalseTotal
if ($umlsall) { } 0 0 0
1682 0 $sth = $db->prepare("select distinct RELA from MRREL where $prelations");
1683 0 $errorhandler->_checkDbError($pkg, $function, $db);
1684 }
1685 else {
1686 0 $sth = $db->prepare("select distinct RELA from MRREL where $prelations and ($sources)");
1687 0 $errorhandler->_checkDbError($pkg, $function, $db);
1688 }
1689 0 $sth->execute();
1690 0 $errorhandler->_checkDbError($pkg, $function, $sth);
1691  
1692 # get all the relas for the parents
1693 0 my $prela = "";
1694 0 ▶ while(($prela) = $sth->fetchrow()) {
Branch: 1 branch
BranchTrueFalseTotal
if (($prela) = $sth->fetchrow) 0 0 0
1695 0 ▶ if(defined $prela) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $prela) 0 0 0
1696 0 ▶ if($prela ne "NULL") {
Branch: 1 branch
BranchTrueFalseTotal
if ($prela ne "NULL") 0 0 0
1697 0 $parentrelas{$prela}++;
1698 }
1699 }
1700 }
1701 0 $sth->finish();
1702  
1703 0 my $prelakeys = keys %parentrelas;
1704 0 ▶ if($prelakeys <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prelakeys <= 0) 0 0 0
1705 0 $errorhandler->_error($pkg,
1706 $function,
1707 "There are no RELA relations for the given sources.",
1708 5);
1709 }
1710  
1711 # uses the relas that are set in the includrelakeys or excluderelakeys
1712 0 my @array = ();
1713 0 ▶ if($includerelakeys > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($includerelakeys > 0) { } 0 0 0
1714 0 @array = keys %{$includerela};
1715 }
1716 else {
1717  
1718 0 my $arrRef =
1719 $db->selectcol_arrayref("select distinct RELA from MRREL where ($sources) and $prelations and $crelations");
1720 0 $errorhandler->_checkDbError($pkg, $function, $db);
1721 0 @array = @{$arrRef};
1722 0 shift @array;
1723 }
1724  
1725 0 my @crelas = ();
1726 0 my @prelas = ();
1727 0 my $relacount = 0;
1728  
1729 0 my @newrelations = ();
1730  
1731 0 foreach my $r (@array) {
1732  
1733 0 $relacount++;
1734  
1735 0 ▶ if( ($excluderelakeys > 0) and (exists ${$excluderela}{$r}) ) { next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($excluderelakeys > 0 and exists do { $excluderela }->{$r}) 0 0 0
Condition0%0/3
$excluderelakeys > 0 and exists do { $excluderela }->{$r}
!ll&&!rl&&r
000
MC/DC0%0/2
$excluderelakeys > 0 and exists do { $excluderela }->{$r}
$excluderelakeys > 0 exists do { $excluderela }->{$r}
Truth table0%0/3
A and B
A= $excluderelakeys > 0B= exists do { $excluderela }->{$r}
ABresult
0X0
100
111
1736  
1737 0 push @newrelations, "RELA=\'$r\'";
1738  
1739 0 ▶ if(exists $childrelas{$r}) { push @crelas, "RELA=\'$r\'"; }
Branch: 2 branches
BranchTrueFalseTotal
if (exists $childrelas{$r}) { } 0 0 0
elsif (exists $parentrelas{$r}) { } 0 0 0
1740 0 elsif(exists $parentrelas{$r}) { push @prelas, "RELA=\'$r\'"; }
1741 else {
1742 0 my $errorstring = "RELA relation ($r) does not exist for the given sources/relations.";
1743 0 $errorhandler->_error($pkg, $function, $errorstring, 5);
1744 }
1745 }
1746  
1747 0 ▶ if($#newrelations >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#newrelations >= 0) 0 0 0
1748 0 my $string = join " or ", @newrelations;
1749  
1750 0 $relations .= "and ( $string )";
1751  
1752 0 my $crelasline = join " or ", @crelas;
1753 0 my $prelasline = join " or ", @prelas;
1754  
1755 # set the parent relations
1756 0 ▶ if($parentRelations=~/PAR/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parentRelations =~ /PAR/) 0 0 0
1757 0 $parentRelations=~s/REL='PAR'/\(REL='PAR' and \($prelasline\)\)/g;
1758 0 $relations=~s/REL='PAR'/\(REL='PAR' and \($prelasline\)\)/g;
1759 }
1760 0 ▶ if($parentRelations=~/RB/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parentRelations =~ /RB/) 0 0 0
1761 0 $parentRelations=~s/REL='RB'/\(REL='RB' and \($prelasline\)\)/g;
1762 0 $relations=~s/REL='RB'/\(REL='RB' and \($prelasline\)\)/g;
1763 }
1764 # set the child relations
1765 0 ▶ if($childRelations=~/CHD/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($childRelations =~ /CHD/) 0 0 0
1766 0 $childRelations=~s/REL='CHD'/\(REL='CHD' and \($crelasline\)\)/g;
1767 0 $relations=~s/REL='CHD'/\(REL='CHD' and \($crelasline\)\)/g;
1768 }
1769 0 ▶ if($childRelations=~/RN/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($childRelations =~ /RN/) 0 0 0
1770 0 $childRelations=~s/REL='RN'/\(REL='RN' and \($crelasline\)\)/g;
1771 0 $relations=~s/REL='RN'/\(REL='RN' and \($crelasline\)\)/g;
1772 }
1773 }
1774 }
1775  
1776 # sets the reladef variables from the information in the config file
1777 # input : $includereladefkeys <- integer
1778 # : $excludereladefkeys <- integer
1779 # : $includereladef <- reference to hash
1780 # : $excludereladef <- reference to hash
1781 # output:
1782 sub _setRelaDef {
1783  
1784 0 ▶ my $self = shift;
Subroutine _setRelaDef: not called CC=33 SCAR=70.2
1785 0 my $includereladefkeys = shift;
1786 0 my $excludereladefkeys = shift;
1787 0 my $includereladef = shift;
1788 0 my $excludereladef = shift;
1789  
1790 0 my $function = "_setRelaDef";
1791 0 &_debug($function);
1792  
1793 # check the input values
1794 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
1795 0 $errorhandler->_error($pkg, $function, "", 2);
1796 }
1797  
1798 # check the parameters are defined
1799 0 ▶ if(!(defined $includereladefkeys) || !(defined $excludereladefkeys) ||
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $includereladefkeys and defined $excludereladefkeys and defined $includereladef and defined $excludereladef) 0 0 0
Condition0%0/9
defined $includereladefkeys and defined $excludereladefkeys and defined $includereladef and defined $excludereladef
!ll&&!rl&&r
000
defined $includereladefkeys and defined $excludereladefkeys and defined $includereladef
!ll&&!rl&&r
000
defined $includereladefkeys and defined $excludereladefkeys
!ll&&!rl&&r
000
MC/DC0%0/4
defined $includereladefkeys and defined $excludereladefkeys and defined $includereladef and defined $excludereladef
defined $includereladefkeys defined $excludereladefkeys defined $includereladef defined $excludereladef
Truth table0%0/5
A and B and C and D
A= defined $includereladefkeysB= defined $excludereladefkeysC= defined $includereladefD= defined $excludereladef
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1800 !(defined $includereladef) || !(defined $excludereladef)) {
1801 0 $errorhandler->_error($pkg, $function, "RELADEF variables not defined.", 4);
1802 }
1803  
1804 # if no relas were specified just return
1805 0 ▶ if($includereladefkeys <= 0 && $excludereladefkeys <=0) { return; }
Branch: 1 branch
BranchTrueFalseTotal
if ($includereladefkeys <= 0 and $excludereladefkeys <= 0) 0 0 0
Condition0%0/3
$includereladefkeys <= 0 and $excludereladefkeys <= 0
!ll&&!rl&&r
000
MC/DC0%0/2
$includereladefkeys <= 0 and $excludereladefkeys <= 0
$includereladefkeys <= 0 $excludereladefkeys <= 0
Truth table0%0/3
A and B
A= $includereladefkeys <= 0B= $excludereladefkeys <= 0
ABresult
0X0
100
111
1806  
1807 # set the database
1808 0 my $db = $self->{'db'};
1809 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
1810  
1811 # initalize the hash tables that will hold children and parent relas
1812 0 my %childrelas = ();
1813 0 my %parentrelas = ();
1814  
1815 # set the parent relations
1816 0 my $prelations = "";
1817 0 ▶ if($reldefstring=~/PAR/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($reldefstring =~ /PAR/) { } 0 0 0
elsif ($reldefstring =~ /RB/) { } 0 0 0
1818 0 ▶ if($reldefstring=~/RB/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reldefstring =~ /RB/) { } 0 0 0
1819 0 $prelations = "(REL='PAR') or (REL='RB')";
1820 0 } else { $prelations = "(REL='PAR')"; }
1821 0 } elsif($reldefstring=~/RB/) { $prelations = "(REL='RB')"; }
1822  
1823 # set the child relations
1824 0 my $crelations = "";
1825 0 ▶ if($reldefstring=~/CHD/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($reldefstring =~ /CHD/) { } 0 0 0
elsif ($reldefstring =~ /RB/) { } 0 0 0
1826 0 ▶ if($reldefstring=~/RN/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reldefstring =~ /RN/) { } 0 0 0
1827 0 $crelations = "(REL='CHD') or (REL='RN')";
1828 0 } else { $crelations = "(REL='CHD')"; }
1829 0 } elsif($reldefstring=~/RB/) { $crelations = "(REL='RN')"; }
1830  
1831 # get the rela relations that exist for the given set of sources and
1832 # relations for the children relations that are specified in the config
1833 0 my $sth = "";
1834 0 ▶ if($umlsall) {
Branch: 1 branch
BranchTrueFalseTotal
if ($umlsall) { } 0 0 0
1835 0 $sth = $db->prepare("select distinct RELA from MRREL where $crelations");
1836 0 $errorhandler->_checkDbError($pkg, $function, $db);
1837 }
1838 else {
1839 0 $sth = $db->prepare("select distinct RELA from MRREL where $crelations and ($sabdefsources)");
1840 0 $errorhandler->_checkDbError($pkg, $function, $db);
1841 }
1842 0 $sth->execute();
1843 0 $errorhandler->_checkDbError($pkg, $function, $sth);
1844  
1845 # get all the relas for the children
1846 0 my $crela = "";
1847 0 ▶ while(($crela) = $sth->fetchrow()) {
Branch: 1 branch
BranchTrueFalseTotal
if (($crela) = $sth->fetchrow) 0 0 0
1848 0 ▶ if(defined $crela) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $crela) 0 0 0
1849 0 ▶ if($crela ne "NULL") {
Branch: 1 branch
BranchTrueFalseTotal
if ($crela ne "NULL") 0 0 0
1850 0 $childrelas{$crela}++;
1851 }
1852 }
1853 }
1854 0 $sth->finish();
1855  
1856 0 my $crelakeys = keys %childrelas;
1857 0 ▶ if($crelakeys <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($crelakeys <= 0) 0 0 0
1858 0 $errorhandler->_error($pkg,
1859 $function,
1860 "There are no RELA relations for the given sources/relations.",
1861 5);
1862 }
1863  
1864 # get the rela relations that exist for the given set of sources and
1865 # relations for the children relations that are specified in the config
1866 0 ▶ if($umlsall) {
Branch: 1 branch
BranchTrueFalseTotal
if ($umlsall) { } 0 0 0
1867 0 $sth = $db->prepare("select distinct RELA from MRREL where $prelations");
1868 0 $errorhandler->_checkDbError($pkg, $function, $db);
1869 }
1870 else {
1871 0 $sth = $db->prepare("select distinct RELA from MRREL where $prelations and ($sabdefsources)");
1872 0 $errorhandler->_checkDbError($pkg, $function, $db);
1873 }
1874 0 $sth->execute();
1875 0 $errorhandler->_checkDbError($pkg, $function, $sth);
1876  
1877 # get all the relas for the parents
1878 0 my $prela = "";
1879 0 ▶ while(($prela) = $sth->fetchrow()) {
Branch: 1 branch
BranchTrueFalseTotal
if (($prela) = $sth->fetchrow) 0 0 0
1880 0 ▶ if(defined $prela) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $prela) 0 0 0
1881 0 ▶ if($prela ne "NULL") {
Branch: 1 branch
BranchTrueFalseTotal
if ($prela ne "NULL") 0 0 0
1882 0 $parentrelas{$prela}++;
1883 }
1884 }
1885 }
1886 0 $sth->finish();
1887  
1888 0 my $prelakeys = keys %parentrelas;
1889 0 ▶ if($prelakeys <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prelakeys <= 0) 0 0 0
1890 0 $errorhandler->_error($pkg,
1891 $function,
1892 "There are no RELA relations for the given sources.",
1893 5);
1894 }
1895  
1896 # uses the relas that are set in the includrelakeys or excludereladefkeys
1897 0 my @array = ();
1898 0 ▶ if($includereladefkeys > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($includereladefkeys > 0) { } 0 0 0
1899 0 @array = keys %{$includereladef};
1900 }
1901 else {
1902  
1903 0 my $arrRef =
1904 $db->selectcol_arrayref("select distinct RELA from MRREL where ($sources) and $prelations and $crelations");
1905 0 $errorhandler->_checkDbError($pkg, $function, $db);
1906 0 @array = @{$arrRef};
1907 0 shift @array;
1908 }
1909  
1910 0 my @crelas = ();
1911 0 my @prelas = ();
1912 0 my $relacount = 0;
1913  
1914 0 my @newrelations = ();
1915  
1916 0 foreach my $r (@array) {
1917  
1918 0 $relacount++;
1919  
1920 0 ▶ if( ($excludereladefkeys > 0) and (exists ${$excludereladef}{$r}) ) { next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($excludereladefkeys > 0 and exists do { $excludereladef }->{$r}) 0 0 0
Condition0%0/3
$excludereladefkeys > 0 and exists do { $excludereladef }->{$r}
!ll&&!rl&&r
000
MC/DC0%0/2
$excludereladefkeys > 0 and exists do { $excludereladef }->{$r}
$excludereladefkeys > 0 exists do { $excludereladef }->{$r}
Truth table0%0/3
A and B
A= $excludereladefkeys > 0B= exists do { $excludereladef }->{$r}
ABresult
0X0
100
111
1921  
1922 0 push @newrelations, "RELA=\'$r\'";
1923  
1924 0 ▶ if(exists $childrelas{$r}) { push @crelas, "RELA=\'$r\'"; }
Branch: 2 branches
BranchTrueFalseTotal
if (exists $childrelas{$r}) { } 0 0 0
elsif (exists $parentrelas{$r}) { } 0 0 0
1925 0 elsif(exists $parentrelas{$r}) { push @prelas, "RELA=\'$r\'"; }
1926 else {
1927 0 my $errorstring = "RELA relation ($r) does not exist for the given sources/relations.";
1928 0 $errorhandler->_error($pkg, $function, $errorstring, 5);
1929 }
1930 }
1931  
1932 0 ▶ if($#newrelations >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#newrelations >= 0) 0 0 0
1933 0 my $string = join " or ", @newrelations;
1934  
1935 0 $relations .= "and ( $string )";
1936  
1937 0 $reladefchildren = join " or ", @crelas;
1938 0 $reladefparents = join " or ", @prelas;
1939 }
1940 }
1941  
1942 # This sets the sources that are to be used. These sources
1943 # are found in the config file. The defaults are:
1944 # input : $file <- string
1945 # output:
1946 sub _config {
1947  
1948 0 ▶ my $self = shift;
Subroutine _config: not called CC=73 SCAR=85.9
1949 0 my $file = shift;
1950  
1951 0 my $function = "_config";
1952 0 &_debug($function);
1953  
1954 # check self
1955 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
1956 0 $errorhandler->_error($pkg, $function, "", 2);
1957 }
1958  
1959 0 my %includesab = (); my %excludesab = ();
1960 0 my %includerel = (); my %excluderel = ();
1961 0 my %includerela = (); my %excluderela = ();
1962 0 my %includereldef = (); my %excludereldef = ();
1963 0 my %includesabdef = (); my %excludesabdef = ();
1964 0 my %includereladef = (); my %excludereladef = ();
1965  
1966 0 my %check = ();
1967  
1968 0 ▶ if(defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) 0 0 0
1969 0 ▶ open(FILE, $file) || die "Could not open configuration file: $file\n";
Branch: 1 branch
BranchTrueFalseTotal
open FILE, $file or die "Could not open configuration file: $file\n" 0 0 0
1970 0 ▶ while(<FILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline FILE)) 0 0 0
1971 0 chomp;
1972 # if blank line skip
1973 0 ▶ if($_=~/^\s*$/) { next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^\s*$/) 0 0 0
1974  
1975 0 ▶ if($_=~/([A-Z]+)\s*\:\:\s*(include|exclude)\s+(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /([A-Z]+)\s*\:\:\s*(include|exclude)\s+(.*)/) { } 0 0 0
1976  
1977 0 my $type = $1;
1978 0 my $det = $2;
1979 0 my $list = $3;
1980  
1981 # catch what types are in the config file for checking
1982 # right now the checking is pretty simple but I think
1983 # in the future as others get added it might be more
1984 # extensive
1985 0 $check{$type}++;
1986  
1987 0 my @array = split/\s*\,\s*/, $list;
1988 0 foreach my $element (@array) {
1989  
1990 0 $element=~s/^\s+//g; $element=~s/\s+$//g;
1991 0 ▶ if( $type eq "SAB" and $det eq "include") { $includesab{$element}++;
Branch: 12 branches
BranchTrueFalseTotal
if ($type eq 'SAB' and $det eq 'include') { } 0 0 0
elsif ($type eq 'SAB' and $det eq 'exclude') { } 0 0 0
elsif ($type eq 'REL' and $det eq 'include') { } 0 0 0
elsif ($type eq 'REL' and $det eq 'exclude') { } 0 0 0
elsif ($type eq 'RELA' and $det eq 'include') { } 0 0 0
elsif ($type eq 'RELA' and $det eq 'exclude') { } 0 0 0
elsif ($type eq 'RELDEF' and $det eq 'include') { } 0 0 0
elsif ($type eq 'RELDEF' and $det eq 'exclude') { } 0 0 0
elsif ($type eq 'SABDEF' and $det eq 'include') { } 0 0 0
elsif ($type eq 'SABDEF' and $det eq 'exclude') { } 0 0 0
elsif ($type eq 'RELADEF' and $det eq 'include') { } 0 0 0
elsif ($type eq 'RELADEF' and $det eq 'exclude') { } 0 0 0
Condition0%0/3
$type eq "SAB" and $det eq "include"
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "SAB" and $det eq "include"
$type eq "SAB" $det eq "include"
Truth table0%0/3
A and B
A= $type eq "SAB"B= $det eq "include"
ABresult
0X0
100
111
1992 0 $sabstring = $_;
1993 0 $parameters{"SAB"}++;
1994 }
1995 0 ▶ elsif($type eq "SAB" and $det eq "exclude") { $excludesab{$element}++;
Condition0%0/3
$type eq "SAB" and $det eq "exclude"
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "SAB" and $det eq "exclude"
$type eq "SAB" $det eq "exclude"
Truth table0%0/3
A and B
A= $type eq "SAB"B= $det eq "exclude"
ABresult
0X0
100
111
1996 0 $sabstring = $_;
1997 0 $parameters{"SAB"}++;
1998 }
1999 0 ▶ elsif($type eq "REL" and $det eq "include") { $includerel{$element}++;
Condition0%0/3
$type eq "REL" and $det eq "include"
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "REL" and $det eq "include"
$type eq "REL" $det eq "include"
Truth table0%0/3
A and B
A= $type eq "REL"B= $det eq "include"
ABresult
0X0
100
111
2000 0 $relstring = $_;
2001 0 $parameters{"REL"}++;
2002 }
2003 0 ▶ elsif($type eq "REL" and $det eq "exclude") { $excluderel{$element}++;
Condition0%0/3
$type eq "REL" and $det eq "exclude"
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "REL" and $det eq "exclude"
$type eq "REL" $det eq "exclude"
Truth table0%0/3
A and B
A= $type eq "REL"B= $det eq "exclude"
ABresult
0X0
100
111
2004 0 $relstring = $_;
2005 0 $parameters{"REL"}++;
2006 }
2007 0 ▶ elsif($type eq "RELA" and $det eq "include") { $includerela{$element}++;
Condition0%0/3
$type eq "RELA" and $det eq "include"
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "RELA" and $det eq "include"
$type eq "RELA" $det eq "include"
Truth table0%0/3
A and B
A= $type eq "RELA"B= $det eq "include"
ABresult
0X0
100
111
2008 0 $relastring = $_;
2009 0 $parameters{"RELA"}++;
2010 }
2011 0 ▶ elsif($type eq "RELA" and $det eq "exclude") { $excluderela{$element}++;
Condition0%0/3
$type eq "RELA" and $det eq "exclude"
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "RELA" and $det eq "exclude"
$type eq "RELA" $det eq "exclude"
Truth table0%0/3
A and B
A= $type eq "RELA"B= $det eq "exclude"
ABresult
0X0
100
111
2012 0 $relastring = $_;
2013 0 $parameters{"RELA"}++;
2014 }
2015 0 ▶ elsif($type eq "RELDEF" and $det eq "include") { $includereldef{$element}++;
Condition0%0/3
$type eq "RELDEF" and $det eq "include"
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "RELDEF" and $det eq "include"
$type eq "RELDEF" $det eq "include"
Truth table0%0/3
A and B
A= $type eq "RELDEF"B= $det eq "include"
ABresult
0X0
100
111
2016 0 $reldefstring = $_;
2017 0 $parameters{"RELDEF"}++;
2018 }
2019 0 ▶ elsif($type eq "RELDEF" and $det eq "exclude") { $excludereldef{$element}++;
Condition0%0/3
$type eq "RELDEF" and $det eq "exclude"
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "RELDEF" and $det eq "exclude"
$type eq "RELDEF" $det eq "exclude"
Truth table0%0/3
A and B
A= $type eq "RELDEF"B= $det eq "exclude"
ABresult
0X0
100
111
2020 0 $reldefstring = $_;
2021 0 $parameters{"RELDEF"}++;
2022 }
2023 0 ▶ elsif($type eq "SABDEF" and $det eq "include") { $includesabdef{$element}++;
Condition0%0/3
$type eq "SABDEF" and $det eq "include"
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "SABDEF" and $det eq "include"
$type eq "SABDEF" $det eq "include"
Truth table0%0/3
A and B
A= $type eq "SABDEF"B= $det eq "include"
ABresult
0X0
100
111
2024 0 $sabdefstring = $_;
2025 0 $parameters{"SABDEF"}++;
2026 }
2027 0 ▶ elsif($type eq "SABDEF" and $det eq "exclude") { $excludesabdef{$element}++;
Condition0%0/3
$type eq "SABDEF" and $det eq "exclude"
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "SABDEF" and $det eq "exclude"
$type eq "SABDEF" $det eq "exclude"
Truth table0%0/3
A and B
A= $type eq "SABDEF"B= $det eq "exclude"
ABresult
0X0
100
111
2028 0 $sabdefstring = $_;
2029 0 $parameters{"SABDEF"}++;
2030 }
2031 0 ▶ elsif($type eq "RELADEF" and $det eq "include"){ $includereladef{$element}++;
Condition0%0/3
$type eq "RELADEF" and $det eq "include"
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "RELADEF" and $det eq "include"
$type eq "RELADEF" $det eq "include"
Truth table0%0/3
A and B
A= $type eq "RELADEF"B= $det eq "include"
ABresult
0X0
100
111
2032 0 $parameters{"RELADEF"}++;
2033 }
2034 0 ▶ elsif($type eq "RELADEF" and $det eq "exclude"){ $excludereladef{$element}++;
Condition0%0/3
$type eq "RELADEF" and $det eq "exclude"
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "RELADEF" and $det eq "exclude"
$type eq "RELADEF" $det eq "exclude"
Truth table0%0/3
A and B
A= $type eq "RELADEF"B= $det eq "exclude"
ABresult
0X0
100
111
2035 0 $parameters{"RELADEF"}++;
2036 }
2037 }
2038 }
2039 else {
2040 0 $errorhandler->_error($pkg, $function, "Format not correct ($_)", 5);
2041 }
2042 }
2043 }
2044  
2045  
2046
2047 # check about the UMLS_ALL option in RELA and RELADEF
2048 # this is the default so just remove them - it is here
2049 # for the user not really for us
2050 0 ▶ if(exists $includerela{"UMLS_ALL"}) { %includerela = (); }
Branch: 1 branch
BranchTrueFalseTotal
if (exists $includerela{"UMLS_ALL"}) 0 0 0
2051 0 ▶ if(exists $includereladef{"UMLS_ALL"}) { %includereladef = (); }
Branch: 1 branch
BranchTrueFalseTotal
if (exists $includereladef{"UMLS_ALL"}) 0 0 0
2052  
2053 0 my $includesabkeys = keys %includesab;
2054 0 my $excludesabkeys = keys %excludesab;
2055 0 my $includerelkeys = keys %includerel;
2056 0 my $excluderelkeys = keys %excluderel;
2057 0 my $includerelakeys = keys %includerela;
2058 0 my $excluderelakeys = keys %excluderela;
2059 0 my $includereldefkeys = keys %includereldef;
2060 0 my $excludereldefkeys = keys %excludereldef;
2061 0 my $includesabdefkeys = keys %includesabdef;
2062 0 my $excludesabdefkeys = keys %excludesabdef;
2063 0 my $includereladefkeys = keys %includereladef;
2064 0 my $excludereladefkeys = keys %excludereladef;
2065  
2066 # check for errors
2067 0 ▶ if( (!exists $check{"SAB"} && exists $check{"REL"}) ||
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $check{"SAB"} and exists $check{"REL"} or not exists $check{"REL"} and exists $check{"SAB"}) 0 0 0
Condition0%0/9
not exists $check{"SAB"} and exists $check{"REL"} or not exists $check{"REL"} and exists $check{"SAB"}
l!l&&r!l&&!r
000
not exists $check{"SAB"} and exists $check{"REL"}
!ll&&!rl&&r
000
not exists $check{"REL"} and exists $check{"SAB"}
!ll&&!rl&&r
000
MC/DC0%0/4
not exists $check{"SAB"} and exists $check{"REL"} or not exists $check{"REL"} and exists $check{"SAB"}
not exists $check{"SAB"} exists $check{"REL"} not exists $check{"REL"} exists $check{"SAB"}
Truth table0%0/7
not(A) and B or not(C) and D
A= not exists $check{"SAB"}B= exists $check{"REL"}C= not exists $check{"REL"}D= exists $check{"SAB"}
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
2068 (!exists $check{"REL"} && exists $check{"SAB"}) ) {
2069 0 $errorhandler->_error($pkg,
2070 $function,
2071 "Configuration file must include both REL and SAB information.",
2072 5);
2073 }
2074 0 ▶ if( (!exists $check{"SABDEF"} && exists $check{"RELDEF"}) ||
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $check{"SABDEF"} and exists $check{"RELDEF"} or not exists $check{"RELDEF"} and exists $check{"SABDEF"}) 0 0 0
Condition0%0/9
not exists $check{"SABDEF"} and exists $check{"RELDEF"} or not exists $check{"RELDEF"} and exists $check{"SABDEF"}
l!l&&r!l&&!r
000
not exists $check{"SABDEF"} and exists $check{"RELDEF"}
!ll&&!rl&&r
000
not exists $check{"RELDEF"} and exists $check{"SABDEF"}
!ll&&!rl&&r
000
MC/DC0%0/4
not exists $check{"SABDEF"} and exists $check{"RELDEF"} or not exists $check{"RELDEF"} and exists $check{"SABDEF"}
not exists $check{"SABDEF"} exists $check{"RELDEF"} not exists $check{"RELDEF"} exists $check{"SABDEF"}
Truth table0%0/7
not(A) and B or not(C) and D
A= not exists $check{"SABDEF"}B= exists $check{"RELDEF"}C= not exists $check{"RELDEF"}D= exists $check{"SABDEF"}
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
2075 (!exists $check{"RELDEF"} && exists $check{"SABDEF"}) ) {
2076 0 $errorhandler->_error($pkg,
2077 $function,
2078 "Configuration file must include both RELDEF and SABDEF information.",
2079 5);
2080 }
2081 0 ▶ if($includesabkeys > 0 && $excludesabkeys > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($includesabkeys > 0 and $excludesabkeys > 0) 0 0 0
Condition0%0/3
$includesabkeys > 0 and $excludesabkeys > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$includesabkeys > 0 and $excludesabkeys > 0
$includesabkeys > 0 $excludesabkeys > 0
Truth table0%0/3
A and B
A= $includesabkeys > 0B= $excludesabkeys > 0
ABresult
0X0
100
111
2082 0 $errorhandler->_error($pkg,
2083 $function,
2084 "Configuration file can not have an include and exclude list of sources.",
2085 5);
2086 }
2087 0 ▶ if($includerelkeys > 0 && $excluderelkeys > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($includerelkeys > 0 and $excluderelkeys > 0) 0 0 0
Condition0%0/3
$includerelkeys > 0 and $excluderelkeys > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$includerelkeys > 0 and $excluderelkeys > 0
$includerelkeys > 0 $excluderelkeys > 0
Truth table0%0/3
A and B
A= $includerelkeys > 0B= $excluderelkeys > 0
ABresult
0X0
100
111
2088 0 $errorhandler->_error($pkg,
2089 $function,
2090 "Configuration file can not have an include and exclude list of relations.",
2091 5);
2092 }
2093 0 ▶ if( ($includerelkeys <= 0 && $excluderelkeys <= 0) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($includerelkeys <= 0 and $excluderelkeys <= 0 and $includerelakeys > 0 || $excluderelakeys > 0) 0 0 0
Condition0%0/9
$includerelkeys <= 0 and $excluderelkeys <= 0 and $includerelakeys > 0 || $excluderelakeys > 0
!ll&&!rl&&r
000
$includerelkeys <= 0 and $excluderelkeys <= 0
!ll&&!rl&&r
000
$includerelakeys > 0 or $excluderelakeys > 0
l!l&&r!l&&!r
000
MC/DC0%0/4
$includerelkeys <= 0 and $excluderelkeys <= 0 and $includerelakeys > 0 || $excluderelakeys > 0
$includerelkeys <= 0 $excluderelkeys <= 0 $includerelakeys > 0 $excluderelakeys > 0
Truth table0%0/5
A and B and C or D
A= $includerelkeys <= 0B= $excluderelkeys <= 0C= $includerelakeys > 0D= $excluderelakeys > 0
ABCDresult
0XXX0
10XX0
11000
111X1
11011
2094 ($includerelakeys > 0 || $excluderelakeys > 0) ) {
2095 0 $errorhandler->_error($pkg,
2096 $function,
2097 "The relations (REL) must be specified if using the rela relations (RELA).",
2098 5);
2099 }
2100 0 ▶ if( ($includereldefkeys <= 0 && $excludereldefkeys <= 0) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($includereldefkeys <= 0 and $excludereldefkeys <= 0 and $includereladefkeys > 0 || $excludereladefkeys > 0) 0 0 0
Condition0%0/9
$includereldefkeys <= 0 and $excludereldefkeys <= 0 and $includereladefkeys > 0 || $excludereladefkeys > 0
!ll&&!rl&&r
000
$includereldefkeys <= 0 and $excludereldefkeys <= 0
!ll&&!rl&&r
000
$includereladefkeys > 0 or $excludereladefkeys > 0
l!l&&r!l&&!r
000
MC/DC0%0/4
$includereldefkeys <= 0 and $excludereldefkeys <= 0 and $includereladefkeys > 0 || $excludereladefkeys > 0
$includereldefkeys <= 0 $excludereldefkeys <= 0 $includereladefkeys > 0 $excludereladefkeys > 0
Truth table0%0/5
A and B and C or D
A= $includereldefkeys <= 0B= $excludereldefkeys <= 0C= $includereladefkeys > 0D= $excludereladefkeys > 0
ABCDresult
0XXX0
10XX0
11000
111X1
11011
2101 ($includereladefkeys > 0 || $excludereladefkeys > 0) ) {
2102 0 $errorhandler->_error($pkg,
2103 $function,
2104 "The relations (RELDEF) must be specified if using the rela relations (RELADEF).",
2105 5);
2106 }
2107  
2108  
2109 # set the defaults
2110 0 ▶ if($includerelkeys <= 0 && $excluderelkeys <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($includerelkeys <= 0 and $excluderelkeys <= 0) 0 0 0
Condition0%0/3
$includerelkeys <= 0 and $excluderelkeys <= 0
!ll&&!rl&&r
000
MC/DC0%0/2
$includerelkeys <= 0 and $excluderelkeys <= 0
$includerelkeys <= 0 $excluderelkeys <= 0
Truth table0%0/3
A and B
A= $includerelkeys <= 0B= $excluderelkeys <= 0
ABresult
0X0
100
111
2111 0 $includesab{"MSH"}++;
2112 0 $includerel{"PAR"}++;
2113 0 $includerel{"CHD"}++;
2114  
2115 0 $sabstring = "SAB :: include MSH";
2116 0 $relstring = "REL :: include CHD, PAR";
2117  
2118 0 $includerelkeys = keys %includerel;
2119 0 $includesabkeys = keys %includesab;
2120 }
2121  
2122 # set the defaults
2123 0 ▶ if($includereldefkeys <= 0 && $excludereldefkeys <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($includereldefkeys <= 0 and $excludereldefkeys <= 0) { } 0 0 0
Condition0%0/3
$includereldefkeys <= 0 and $excludereldefkeys <= 0
!ll&&!rl&&r
000
MC/DC0%0/2
$includereldefkeys <= 0 and $excludereldefkeys <= 0
$includereldefkeys <= 0 $excludereldefkeys <= 0
Truth table0%0/3
A and B
A= $includereldefkeys <= 0B= $excludereldefkeys <= 0
ABresult
0X0
100
111
2124
2125 0 $includesabdef{"UMLS_ALL"}++;
2126 0 $includereldef{"UMLS_ALL"}++;
2127  
2128 0 $sabdefstring = "SAB :: include UMLS_ALL";
2129 0 $reldefstring = "REL :: include UMLS_ALL";
2130  
2131 0 $includereldefkeys = keys %includereldef;
2132 0 $includesabdefkeys = keys %includesabdef;
2133
2134 }
2135 else {
2136 0 $defflag = 1;
2137 }
2138  
2139 # The order matters here so don't mess with it! The relations have to be set
2140 # prior to the sabs and both need to be set prior to the relas.
2141  
2142 # set the relations
2143 0 $self->_setRelations($includerelkeys, $excluderelkeys, \%includerel, \%excluderel);
2144  
2145 # set the sabs
2146 0 $self->_setSabs($includesabkeys, $excludesabkeys, \%includesab, \%excludesab);
2147  
2148 # set the relas as long as there exists a PAR/CHD or RB/RN relation
2149 0 ▶ if($relations=~/(PAR|CHD|RB|RN)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($relations =~ /(PAR|CHD|RB|RN)/) { } 0 0 0
2150 0 $self->_setRelas($includerelakeys, $excluderelakeys, \%includerela, \%excluderela);
2151 }
2152 else {
2153 0 ▶ if(($includerelkeys > 0 || $excluderelkeys > 0) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($includerelkeys > 0 || $excluderelkeys > 0 and $includerelakeys > 0 || $excluderelakeys > 0) 0 0 0
Condition0%0/9
$includerelkeys > 0 || $excluderelkeys > 0 and $includerelakeys > 0 || $excluderelakeys > 0
!ll&&!rl&&r
000
$includerelkeys > 0 or $excluderelkeys > 0
l!l&&r!l&&!r
000
$includerelakeys > 0 or $excluderelakeys > 0
l!l&&r!l&&!r
000
MC/DC0%0/4
$includerelkeys > 0 || $excluderelkeys > 0 and $includerelakeys > 0 || $excluderelakeys > 0
$includerelkeys > 0 $excluderelkeys > 0 $includerelakeys > 0 $excluderelakeys > 0
Truth table0%0/7
A or B and C or D
A= $includerelkeys > 0B= $excluderelkeys > 0C= $includerelakeys > 0D= $excluderelakeys > 0
ABCDresult
00XX0
1X000
01000
1X1X1
1X011
011X1
01011
2154 ($includerelakeys > 0 || $excluderelakeys > 0) ) {
2155 0 $errorhandler->_error($pkg,
2156 $function,
2157 "The rela relations (RELA) can only be used with the PAR/CHD or RB/RN relations (REL).",
2158 5);
2159 }
2160 }
2161  
2162 # set the sabs for the CUI and extended definitions
2163 0 $self->_setSabDef($includesabdefkeys, $excludesabdefkeys, \%includesabdef, \%excludesabdef);
2164  
2165 # set the rels for the extended definition
2166 0 $self->_setRelDef($includereldefkeys, $excludereldefkeys, \%includereldef, \%excludereldef);
2167  
2168 # set the relas for the extended definition
2169 0 ▶ if($reldefstring=~/(PAR|CHD|RB|RN)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reldefstring =~ /(PAR|CHD|RB|RN)/) { } 0 0 0
2170 0 $self->_setRelaDef($includereladefkeys, $excludereladefkeys, \%includereladef, \%excludereladef);
2171 }
2172 else {
2173 0 ▶ if(($includereldefkeys > 0 || $excludereldefkeys > 0) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($includereldefkeys > 0 || $excludereldefkeys > 0 and $includereladefkeys > 0 || $excludereladefkeys > 0) 0 0 0
Condition0%0/9
$includereldefkeys > 0 || $excludereldefkeys > 0 and $includereladefkeys > 0 || $excludereladefkeys > 0
!ll&&!rl&&r
000
$includereldefkeys > 0 or $excludereldefkeys > 0
l!l&&r!l&&!r
000
$includereladefkeys > 0 or $excludereladefkeys > 0
l!l&&r!l&&!r
000
MC/DC0%0/4
$includereldefkeys > 0 || $excludereldefkeys > 0 and $includereladefkeys > 0 || $excludereladefkeys > 0
$includereldefkeys > 0 $excludereldefkeys > 0 $includereladefkeys > 0 $excludereladefkeys > 0
Truth table0%0/7
A or B and C or D
A= $includereldefkeys > 0B= $excludereldefkeys > 0C= $includereladefkeys > 0D= $excludereladefkeys > 0
ABCDresult
00XX0
1X000
01000
1X1X1
1X011
011X1
01011
2174 ($includereladefkeys > 0 || $excludereladefkeys > 0) ) {
2175 0 $errorhandler->_error($pkg,
2176 $function,
2177 "The rela relations (RELADEF) can only be used with the PAR/CHD or RB/RN relations (RELDEF).",
2178 5);
2179 }
2180 }
2181  
2182 # now at this point everything that is set with the names are set
2183 # if though SABDEF has been set without SAB then use SABDEF
2184 # similarity if SABREL has been set without REL then use SABREL
2185 # set the relations - this is done right now to extract terms and
2186 # and such from the umls - I don't really like how this is done but
2187 # it will be okay for right now. It would be nice to have them
2188 # completely seperate. Doing it this way though allows for the REL,
2189 # SAB, RELDEF and SABDEF to all be specified - again order matters here.
2190  
2191 #if($includerelkeys == 0 && $excluderelkeys == 0) {
2192 # $self->_setRelations($includereldefkeys, $excludereldefkeys, \%includereldef, \%excludereldef);
2193 #}
2194 #if($includesabkeys == 0 && $excludesabkeys == 0) {
2195 # $self->_setSabs($includesabdefkeys, $excludesabdefkeys, \%includesabdef, \%excludesabdef);
2196 #}
2197 #if($includerelkeys == 0 && $excluderelkeys == 0) {
2198 # if($relations=~/(PAR|CHD|RB|RN)/) {
2199 # $self->_setRelas($includereladefkeys, $excludereladefkeys, \%includereladef, \%excludereladef);
2200 # }
2201 #}
2202  
2203 0 ▶ if($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 0 0
2204 0 ▶ if($umlsall) { print STDERR "SOURCE : UMLS_ALL\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($umlsall) { } 0 0 0
2205 0 else { print STDERR "SOURCE : $sources\n"; }
2206 0 print STDERR "RELATIONS: $relations\n";
2207 0 print STDERR "PARENTS : $parentRelations\n";
2208 0 print STDERR "CHILDREN : $childRelations\n\n";
2209 0 ▶ if($sabdefsources eq "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($sabdefsources eq '') { } 0 0 0
2210 0 print STDERR "SABDEF : UMLS_ALL\n";
2211 }
2212 else {
2213 0 print STDERR "SABDEF : $sabdefsources\n";
2214 }
2215 0 my $reldefrelations = "UMLS_ALL";
2216 0 ▶ if($reldefstring ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($reldefstring ne "") 0 0 0
2217 0 $reldefstring=~/RELDEF :: include ([A-Z0-9\, ]+)/;
2218 0 $reldefrelations = $1;
2219 }
2220 0 print STDERR "RELDEF : $reldefrelations\n";
2221 0 print STDERR "SAB : $sources\n";
2222 0 print STDERR "REL : $relations\n";
2223 }
2224 }
2225  
2226 # returns the SAB from the configuratino file
2227 # input :
2228 # output: $string <- containing SAB line from config file
2229 sub _getSabString {
2230 0 ▶ my $self = shift;
Subroutine _getSabString: not called CC=1 SCAR=6.9
2231  
2232 0 return $sabstring;
2233 }
2234  
2235 # returns the REL from the configuratino file
2236 # input :
2237 # output: $string <- containing REL line from config file
2238 sub _getRelString {
2239 0 ▶ my $self = shift;
Subroutine _getRelString: not called CC=1 SCAR=6.9
2240  
2241 0 return $relstring;
2242 }
2243  
2244 # returns the RELA from the configuratino file
2245 # input :
2246 # output: $string <- containing RELA line from config file
2247 sub _getRelaString {
2248 0 ▶ my $self = shift;
Subroutine _getRelaString: not called CC=1 SCAR=6.9
2249  
2250 0 return $relastring;
2251 }
2252  
2253 # returns the SABDEF from the configuratino file
2254 # input :
2255 # output: $string <- containing SABDEF line from config file
2256 sub _getSabDefString {
2257 0 ▶ my $self = shift;
Subroutine _getSabDefString: not called CC=1 SCAR=6.9
2258  
2259 0 return $sabdefstring;
2260 }
2261  
2262 # returns the RELDEF from the configuratino file
2263 # input :
2264 # output: $string <- containing RELDEF line from config file
2265 sub _getRelDefString {
2266 0 ▶ my $self = shift;
Subroutine _getRelDefString: not called CC=1 SCAR=6.9
2267  
2268 0 return $reldefstring;
2269 }
2270  
2271  
2272  
2273 # set the version
2274 # input :
2275 # output:
2276 sub _setVersion {
2277  
2278 0 ▶ my $self = shift;
Subroutine _setVersion: not called CC=5 SCAR=34.0
2279  
2280 0 my $function = "_setVersion";
2281 0 &_debug($function);
2282  
2283 # check self
2284 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
2285 0 $errorhandler->_error($pkg, $function, "", 2);
2286 }
2287  
2288 # set the database
2289 0 my $db = $self->{'db'};
2290 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
2291  
2292 # get the verstion information
2293 0 my $arrRef = $db->selectcol_arrayref("select EXPL from MRDOC where VALUE = \'mmsys.version\'");
2294 0 $errorhandler->_checkDbError($pkg, $function, $db);
2295  
2296 # check that it was returned
2297 0 ▶ if(scalar(@{$arrRef}) < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$arrRef;} < 1) 0 0 0
2298 0 $errorhandler->_error($pkg, $function, "No version info in table MRDOC.", 7);
2299 }
2300  
2301 0 ($version) = @{$arrRef};
2302 }
2303  
2304  
2305 # check if the UMLS tables required all exist
2306 # input :
2307 # output:
2308 sub _checkTablesExist {
2309  
2310 0 ▶ my $self = shift;
Subroutine _checkTablesExist: not called CC=17 SCAR=57.2
2311  
2312 0 my $function = "_checkTablesExist";
2313 0 &_debug($function);
2314  
2315 # check self
2316 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
2317 0 $errorhandler->_error($pkg, $function, "", 2);
2318 }
2319  
2320 # set up the database
2321 0 my $db = $self->{'db'};
2322 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
2323  
2324 # check if the tables exist...
2325 0 my $sth = $db->prepare("show tables");
2326 0 $sth->execute();
2327 0 $errorhandler->_checkDbError($pkg, $function, $sth);
2328  
2329 0 my $table = "";
2330 0 my %tables = ();
2331 0 ▶ while(($table) = $sth->fetchrow()) {
Branch: 1 branch
BranchTrueFalseTotal
if (($table) = $sth->fetchrow) 0 0 0
2332 0 $tables{$table} = 1;
2333 }
2334 0 $sth->finish();
2335  
2336 0 ▶ if(!defined $tables{"MRCONSO"} and !defined $tables{"mrconso"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tables{"MRCONSO"} or defined $tables{"mrconso"}) 0 0 0
Condition0%0/3
defined $tables{"MRCONSO"} or defined $tables{"mrconso"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $tables{"MRCONSO"} or defined $tables{"mrconso"}
defined $tables{"MRCONSO"} defined $tables{"mrconso"}
Truth table0%0/3
A or B
A= defined $tables{"MRCONSO"}B= defined $tables{"mrconso"}
ABresult
1X1
011
000
2337 0 $errorhandler->_error($pkg, $function, "Table MRCONSO not found in database", 7);
2338 }
2339 0 ▶ if(!defined $tables{"MRDEF"} and !defined $tables{"mrdef"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tables{"MRDEF"} or defined $tables{"mrdef"}) 0 0 0
Condition0%0/3
defined $tables{"MRDEF"} or defined $tables{"mrdef"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $tables{"MRDEF"} or defined $tables{"mrdef"}
defined $tables{"MRDEF"} defined $tables{"mrdef"}
Truth table0%0/3
A or B
A= defined $tables{"MRDEF"}B= defined $tables{"mrdef"}
ABresult
1X1
011
000
2340 0 $errorhandler->_error($pkg, $function, "Table MRDEF not found in database", 7);
2341 }
2342 0 ▶ if(!defined $tables{"SRDEF"} and !defined $tables{"srdef"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tables{"SRDEF"} or defined $tables{"srdef"}) 0 0 0
Condition0%0/3
defined $tables{"SRDEF"} or defined $tables{"srdef"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $tables{"SRDEF"} or defined $tables{"srdef"}
defined $tables{"SRDEF"} defined $tables{"srdef"}
Truth table0%0/3
A or B
A= defined $tables{"SRDEF"}B= defined $tables{"srdef"}
ABresult
1X1
011
000
2343 0 $errorhandler->_error($pkg, $function, "Table SRDEF not found in database", 7);
2344 }
2345 0 ▶ if(!defined $tables{"MRREL"} and !defined $tables{"mrrel"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tables{"MRREL"} or defined $tables{"mrrel"}) 0 0 0
Condition0%0/3
defined $tables{"MRREL"} or defined $tables{"mrrel"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $tables{"MRREL"} or defined $tables{"mrrel"}
defined $tables{"MRREL"} defined $tables{"mrrel"}
Truth table0%0/3
A or B
A= defined $tables{"MRREL"}B= defined $tables{"mrrel"}
ABresult
1X1
011
000
2346 0 $errorhandler->_error($pkg, $function, "Table MRREL not found in database", 7);
2347 }
2348 0 ▶ if(!defined $tables{"MRDOC"} and !defined $tables{"mrdoc"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tables{"MRDOC"} or defined $tables{"mrdoc"}) 0 0 0
Condition0%0/3
defined $tables{"MRDOC"} or defined $tables{"mrdoc"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $tables{"MRDOC"} or defined $tables{"mrdoc"}
defined $tables{"MRDOC"} defined $tables{"mrdoc"}
Truth table0%0/3
A or B
A= defined $tables{"MRDOC"}B= defined $tables{"mrdoc"}
ABresult
1X1
011
000
2349 0 $errorhandler->_error($pkg, $function, "Table MRDEC not found in database", 7);
2350 }
2351 0 ▶ if(!defined $tables{"MRSAB"} and !defined $tables{"mrsab"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $tables{"MRSAB"} || defined $tables{"mrsab"}) 0 0 0
Condition0%0/3
defined $tables{'MRSAB'} || defined $tables{'mrsab'}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $tables{'MRSAB'} || defined $tables{'mrsab'}
defined $tables{'MRSAB'} defined $tables{'mrsab'}
Truth table0%0/3
A || B
A= defined $tables{'MRSAB'}B= defined $tables{'mrsab'}
ABresult
1X1
011
000
2352 0 $errorhandler->_error($pkg, $function, "Table MRSAB not found in database", 7);
2353 }
2354 }
2355  
2356 # method to set the global parameter options
2357 # input : $params <- reference to a hash
2358 # output:
2359 sub _setOptions {
2360 0 ▶ my $self = shift;
Subroutine _setOptions: not called CC=14 SCAR=53.5
2361 0 my $params = shift;
2362  
2363 0 my $function = "_setOptions";
2364 0 &_debug($function);
2365  
2366 # check self
2367 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
2368 0 $errorhandler->_error($pkg, $function, "", 2);
2369 }
2370  
2371 # check the params
2372 0 ▶ $params = {} if(!defined $params);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params 0 0 0
2373  
2374 # get all the parameters
2375 0 my $verbose = $params->{'verbose'};
2376 0 my $cuilist = $params->{'cuilist'};
2377 0 my $t = $params->{'t'};
2378 0 my $debugoption = $params->{'debug'};
2379 0 my $config = $params->{'config'};
2380  
2381 0 ▶ if(defined $t) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $t) 0 0 0
2382 0 $option_t = 1;
2383 }
2384  
2385 0 my $output = "";
2386  
2387 0 ▶ if(defined $verbose || defined $cuilist ||
Branch: 1 branch
BranchTrueFalseTotal
if (defined $verbose or defined $cuilist or defined $debugoption or defined $config) 0 0 0
Condition0%0/9
defined $verbose or defined $cuilist or defined $debugoption or defined $config
l!l&&r!l&&!r
000
defined $verbose or defined $cuilist or defined $debugoption
l!l&&r!l&&!r
000
defined $verbose or defined $cuilist
l!l&&r!l&&!r
000
MC/DC0%0/4
defined $verbose or defined $cuilist or defined $debugoption or defined $config
defined $verbose defined $cuilist defined $debugoption defined $config
Truth table0%0/5
A or B or C or D
A= defined $verboseB= defined $cuilistC= defined $debugoptionD= defined $config
ABCDresult
1XXX1
01XX1
001X1
00011
00000
2388 defined $debugoption || defined $config) {
2389 0 $output .= "\nCuiFinder User Options: \n";
2390 }
2391  
2392 # check the debug option
2393 0 ▶ if(defined $debugoption) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $debugoption) 0 0 0
2394 0 $debug = 1;
2395 0 $output .= " --debug";
2396 }
2397  
2398 # check if verbose run has been identified
2399 0 ▶ if(defined $verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $verbose) 0 0 0
2400 0 $option_verbose = 1;
2401 0 $output .= " --verbose option set\n";
2402 }
2403  
2404  
2405 # check if the cuilist option has been set
2406 0 ▶ if(defined $cuilist) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cuilist) 0 0 0
2407 0 $option_cuilist = 1;
2408 0 $output .= " --cuilist option set\n";
2409 }
2410  
2411 # check if the config file is set
2412 0 ▶ if(defined $config) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $config) 0 0 0
2413 0 $option_config = 1;
2414 0 $output .= " --config option set\n";
2415 }
2416  
2417 0 ▶ if($option_t == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($option_t == 0) 0 0 0
2418 0 print STDERR "$output\n\n";
2419 }
2420 }
2421  
2422 # method to set the umlsinterface index database
2423 # input : $params <- reference to a hash
2424 # output:
2425 sub _setDatabase {
2426  
2427 36 ▶ my $self = shift;
Subroutine _setDatabase: called CC=12 SCAR=34.3
2428 36 my $params = shift;
2429  
2430 36 my $function = "_setDatabase";
2431 36 &_debug($function);
2432  
2433 # check self
2434 36 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 36 36
Condition33%1/3
defined $self and ref $self
!ll&&!rl&&r
0036
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table33%1/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
2435 0 $errorhandler->_error($pkg, $function, "", 2);
2436 }
2437  
2438 # check the params
2439 36 ▶ $params = {} if(!defined $params);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params 0 36 36
2440  
2441 # get the database connection parameters
2442 36 my $database = $params->{'database'};
2443 36 my $hostname = $params->{'hostname'};
2444 36 my $socket = $params->{'socket'};
2445 36 my $port = $params->{'port'};
2446 36 my $username = $params->{'username'};
2447 36 my $password = $params->{'password'};
2448  
2449 # set up defaults if the options were not passed
2450 36 ▶ if(! defined $database) { $database = "umls"; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $database) 36 0 36
2451 36 ▶ if(! defined $socket) { $socket = "/var/run/mysqld/mysqld.sock"; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $socket) 36 0 36
2452 36 ▶ if(! defined $hostname) { $hostname = "localhost"; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $hostname) 36 0 36
2453  
2454 # initialize the database handler
2455 36 my $db = "";
2456  
2457 # create the database object...
2458 36 ▶ if(defined $username and defined $password) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $username and defined $password) { } 0 36 36
Condition33%1/3
defined $username and defined $password
!ll&&!rl&&r
3600
MC/DC0%0/2
defined $username and defined $password
defined $username defined $password
Truth table33%1/3
A and B
A= defined $usernameB= defined $password
ABresult
0X0
100
111
2459 0 ▶ if($debug) { print STDERR "Connecting with username and password\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 0 0
2460 0 $db = DBI->connect("DBI:mysql:database=$database;mysql_socket=$socket;host=$hostname",$username, $password, {RaiseError => 0});
2461 }
2462 else {
2463 36 ▶ if($debug) { print STDERR "Connecting using the my.cnf file\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 36 36
2464 36 my $dsn = "DBI:mysql:umls;mysql_read_default_group=client;";
2465 36 $db = DBI->connect($dsn);
2466 }
2467  
2468 # check if there is an error
2469 0 $errorhandler->_checkDbError($pkg, $function, $db);
2470  
2471 # check that the db exists
2472 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
2473  
2474 # set database parameters
2475 0 $db->{'mysql_enable_utf8'} = 1;
2476 0 $db->do('SET NAMES utf8');
2477 0 $db->{mysql_auto_reconnect} = 1;
2478  
2479 # set the self parameters
2480 0 $self->{'db'} = $db;
2481 0 $self->{'username'} = $username;
2482 0 $self->{'password'} = $password;
2483 0 $self->{'hostname'} = $hostname;
2484 0 $self->{'socket'} = $socket;
2485 0 $self->{'database'} = $database;
2486  
2487 # return the database handler
2488 0 return $db;
2489 }
2490  
2491 # returns the parameters set in the configuration file
2492 # input:
2493 # output : $hash <- reference to hash containing parameters in the
2494 # configuration file - if there was not config
2495 # file the hash is empty and defaults are being
2496 # use
2497 sub _getConfigParameters {
2498 0 ▶ my $self = shift;
Subroutine _getConfigParameters: not called CC=1 SCAR=6.9
2499  
2500 0 my $function = "_getConfigParameters";
2501  
2502 0 return \%parameters;
2503 }
2504  
2505 # returns all of the cuis given the specified set of sources
2506 # and relations defined in the configuration file
2507 # input : $sab <- string containing a source
2508 # output: $array <- reference to array of cuis
2509 sub _getCuis {
2510  
2511 0 ▶ my $self = shift;
Subroutine _getCuis: not called CC=5 SCAR=34.0
2512 0 my $sab = shift;
2513  
2514 0 my $function = "_getCuis";
2515 #&_debug($function);
2516  
2517 # check self
2518 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
2519 0 $errorhandler->_error($pkg, $function, "", 2);
2520 }
2521  
2522 # check input variables
2523 0 ▶ if(!$sab) { $errorhandler->_error($pkg, $function, "Error with input variable \$sab.", 4); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($sab) 0 0 0
2524  
2525 # set up the database
2526 0 my $db = $self->{'db'};
2527 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
2528  
2529 # NOTE: it is quicker to get all the CUI1s and then all of the CUI2 and then merge
2530 # rather than try to get them all together in a single query.
2531 # get all of the CUI1s
2532 0 my $allCui1 = $db->selectcol_arrayref("select CUI1 from MRREL where ($relations) and (SAB=\'$sab\') and SUPPRESS='N'\;");
2533 0 $errorhandler->_checkDbError($pkg, $function, $db);
2534  
2535 # get all of the CUI1s
2536 0 my $allCui2 = $db->selectcol_arrayref("select CUI2 from MRREL where ($relations) and (SAB=\'$sab\')and SUPPRESS='N'");
2537 0 $errorhandler->_checkDbError($pkg, $function, $db);
2538  
2539 # merge and return them
2540 0 my @allCuis = (@{$allCui1}, @{$allCui2});
2541  
2542 0 return \@allCuis;
2543 }
2544  
2545 # Takes as input a SAB and returns its corresponding
2546 # UMLS CUI. Keep in mind this is the root cui not
2547 # the version cui that is returned. The information
2548 # for this is obtained from the MRSAB table
2549 # input : $sab <- string containing source
2550 # output: $cui <- string containing cui
2551 sub _getSabCui {
2552 0 ▶ my $self = shift;
Subroutine _getSabCui: not called CC=8 SCAR=42.8
2553 0 my $sab = shift;
2554  
2555 0 my $function = "_getSabCui";
2556  
2557 # check self
2558 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
2559 0 $errorhandler->_error($pkg, $function, "", 2);
2560 }
2561  
2562 # check input variables
2563 0 ▶ if(!$sab) { $errorhandler->_error($pkg, $function, "Error with input variable \$sab.", 4); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($sab) 0 0 0
2564  
2565 # set up the database
2566 0 my $db = $self->{'db'};
2567 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
2568  
2569 # if the sab is umls all
2570 0 ▶ if($sab eq "UMLS_ALL") {
Branch: 1 branch
BranchTrueFalseTotal
if ($sab eq "UMLS_ALL") 0 0 0
2571 0 return $umlsRoot;
2572 }
2573  
2574 0 my $arrRef = $db->selectcol_arrayref("select distinct RCUI from MRSAB where RSAB='$sab' and SABIN='Y'");
2575 0 $errorhandler->_checkDbError($pkg, $function, $db);
2576  
2577 0 ▶ if(scalar(@{$arrRef}) < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$arrRef;} < 1) 0 0 0
2578 0 $errorhandler->_error($pkg, $function, "SAB ($sab) does not exist in your current UMLS view.", 7);
2579 }
2580  
2581 0 ▶ if(scalar(@{$arrRef}) > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$arrRef;} > 1) 0 0 0
2582 0 $errorhandler->_error($pkg, $function, "Internal error: Duplicate concept rows.", 7);
2583 }
2584  
2585 0 return (pop @{$arrRef});
2586 }
2587  
2588  
2589 # method to destroy the created object.
2590 # input :
2591 # output:
2592 sub _disconnect {
2593 0 ▶ my $self = shift;
Subroutine _disconnect: not called CC=5 SCAR=34.0
2594  
2595 0 my $function = "_disconnect";
2596  
2597 # check self
2598 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
2599 0 $errorhandler->_error($pkg, $function, "", 2);
2600 }
2601  
2602 0 ▶ if($self) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self) 0 0 0
2603 0 my $db = $self->{'db'};
2604 0 ▶ $db->disconnect() if($db);
Branch: 1 branch
BranchTrueFalseTotal
if $db 0 0 0
2605 }
2606 }
2607  
2608 # returns the version of the UMLS currently being used
2609 # input :
2610 # output: $version <- string containing version
2611 sub _version {
2612  
2613 0 ▶ return $version;
Subroutine _version: not called CC=1 SCAR=6.9
2614 }
2615  
2616 # print out the function name to standard error
2617 # input : $function <- string containing function name
2618 # output:
2619 sub _debug {
2620 108 ▶ my $function = shift;
Subroutine _debug: called CC=2 SCAR=8.1
2621 108 ▶ if($debug) { print STDERR "In UMLS::Interface::CuiFinder::$function\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 108 108
2622 }
2623  
2624 ######################################################################
2625 # functions to obtain information about the cuis
2626 ######################################################################
2627  
2628 # Method to check if a concept ID exists in the database.
2629 # input : $concept <- string containing a cui
2630 # output: $bool <- string indicating if the cui exists
2631 sub _exists {
2632  
2633 0 ▶ my $self = shift;
Subroutine _exists: not called CC=10 SCAR=47.0
2634 0 my $concept = shift;
2635  
2636 0 my $function = "_exists";
2637  
2638 # check self
2639 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
2640 0 $errorhandler->_error($pkg, $function, "", 2);
2641 }
2642  
2643 # check parameter exists
2644 0 ▶ if(!defined $concept) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $concept) 0 0 0
2645 0 $errorhandler->_error($pkg, $function, "Error with input variable \$concept.", 4);
2646 }
2647  
2648 # check if valid concept
2649 0 ▶ if(! ($errorhandler->_validCui($concept)) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($errorhandler->_validCui($concept)) 0 0 0
2650 0 $errorhandler->_error($pkg, $function, "Concept ($concept) is not valid.", 6);
2651 }
2652  
2653 # check if root
2654 0 ▶ if($concept eq $umlsRoot) { return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($concept eq $umlsRoot) 0 0 0
2655  
2656 # check if a sab
2657 0 ▶ if(exists $sabHash{$concept}) { return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if (exists $sabHash{$concept}) 0 0 0
2658  
2659 # set up database
2660 0 my $db = $self->{'db'};
2661 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
2662  
2663 # get the concept
2664 0 my $arrRef = "";
2665 0 ▶ if($umlsall) {
Branch: 1 branch
BranchTrueFalseTotal
if ($umlsall) { } 0 0 0
2666 0 $arrRef = $db->selectcol_arrayref("select distinct CUI from MRCONSO where CUI='$concept'");
2667 }
2668 else {
2669 0 $arrRef = $db->selectcol_arrayref("select distinct CUI from MRCONSO where CUI='$concept' and $sources");
2670 }
2671  
2672 # check the database for errors
2673 0 $errorhandler->_checkDbError($pkg, $function, $db);
2674  
2675 # get the count
2676 0 my $count = scalar(@{$arrRef});
2677  
2678 0 ▶ return 1 if($count); return 0;
Branch: 1 branch
BranchTrueFalseTotal
if $count 0 0 0
2679 }
2680  
2681 # method that returns a list of concepts (@concepts) related
2682 # to a concept $concept through a relation $rel
2683 # input : $concept <- string containing cui
2684 # $rel <- string containing a relation
2685 # output: $array <- reference to an array of cuis
2686 sub _getRelated {
2687  
2688 0 ▶ my $self = shift;
Subroutine _getRelated: not called CC=8 SCAR=42.8
2689 0 my $concept = shift;
2690 0 my $rel = shift;
2691  
2692 0 my $function = "_getRelated";
2693 0 &_debug($function);
2694  
2695 # check self
2696 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
2697 0 $errorhandler->_error($pkg, $function, "", 2);
2698 }
2699  
2700 # check parameter exists
2701 0 ▶ if(!defined $concept) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $concept) 0 0 0
2702 0 $errorhandler->_error($pkg, $function, "Error with input variable \$concept.", 4);
2703 }
2704  
2705 0 ▶ if(!defined $rel) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $rel) 0 0 0
2706 0 $errorhandler->_error($pkg, $function, "Error with input variable \$rel.", 4);
2707 }
2708  
2709 # check if valid concept
2710 0 ▶ if(! ($errorhandler->_validCui($concept)) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($errorhandler->_validCui($concept)) 0 0 0
2711 0 $errorhandler->_error($pkg, $function, "Concept ($concept) is not valid.", 6);
2712 }
2713  
2714 # set up database
2715 0 my $db = $self->{'db'};
2716 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
2717  
2718 # return all the relations 'rel' for cui 'concept'
2719 0 my $arrRef = "";
2720 0 ▶ if($umlsall) {
Branch: 1 branch
BranchTrueFalseTotal
if ($umlsall) { } 0 0 0
2721 0 $arrRef = $db->selectcol_arrayref("select distinct CUI2 from MRREL where CUI1='$concept' and REL='$rel' and CUI2!='$concept'");
2722 }
2723 else {
2724 0 $arrRef = $db->selectcol_arrayref("select distinct CUI2 from MRREL where CUI1='$concept' and REL='$rel' and ($sources) and CUI2!='$concept'");
2725 }
2726  
2727 # check for errors
2728 0 $errorhandler->_checkDbError($pkg, $function, $db);
2729  
2730 0 return $arrRef;
2731 }
2732  
2733 # method that returns the preferred term of a cui from the UMLS
2734 # input : $concept <- string containing cui
2735 # output: $string <- string containing the preferred term
2736 sub _getAllPreferredTerm {
2737 0 ▶ my $self = shift;
Subroutine _getAllPreferredTerm: not called CC=8 SCAR=42.8
2738 0 my $concept = shift;
2739  
2740 0 my $function = "_getAllPreferredTerm";
2741  
2742 # check self
2743 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
2744 0 $errorhandler->_error($pkg, $function, "", 2);
2745 }
2746  
2747 # check parameter exists
2748 0 ▶ if(!defined $concept) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $concept) 0 0 0
2749 0 $errorhandler->_error($pkg, $function, "Error with input variable \$concept.", 4);
2750 }
2751  
2752 # check if valid concept
2753 0 ▶ if(! ($errorhandler->_validCui($concept)) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($errorhandler->_validCui($concept)) 0 0 0
2754 0 $errorhandler->_error($pkg, $function, "Concept ($concept) is not valid.", 6);
2755 }
2756  
2757 # set the return hash
2758 0 my %retHash = ();
2759  
2760 # if the concept is the root return the root string
2761 0 ▶ if($concept eq $umlsRoot) {
Branch: 1 branch
BranchTrueFalseTotal
if ($concept eq $umlsRoot) 0 0 0
2762 0 $retHash{"**UMLS ROOT**"}++;
2763 0 my @array = keys(%retHash);
2764 0 return \@array;
2765 }
2766  
2767 # set the database
2768 0 my $db = $self->{'db'};
2769 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
2770  
2771 # get the strings associated to the CUI
2772 0 my $arrRef = $db->selectcol_arrayref("select distinct STR from MRCONSO where CUI='$concept' and TS='P' and LAT='ENG'");
2773  
2774 # check the database for errors
2775 0 $errorhandler->_checkDbError($pkg, $function, $db);
2776  
2777 # clean up the strings a bit and lower case them
2778 0 my $term = "";
2779 0 foreach my $tr (@{$arrRef}) {
2780 0 $tr =~ s/^\s+//;
2781 0 $tr =~ s/\s+$//;
2782 0 $tr =~ s/\s+/ /g;
2783 0 $term = $tr;
2784 }
2785  
2786 # return the strings
2787 0 return $term;
2788 }
2789  
2790 # method that returns the preferred term of a cui from
2791 # sources specified in the configuration file
2792 # input : $concept <- string containing cui
2793 # output: $string <- string containing the preferred term
2794 sub _getPreferredTerm {
2795 0 ▶ my $self = shift;
Subroutine _getPreferredTerm: not called CC=9 SCAR=45.0
2796 0 my $concept = shift;
2797  
2798 0 my $function = "_getPreferredTerm";
2799  
2800 # check self
2801 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
2802 0 $errorhandler->_error($pkg, $function, "", 2);
2803 }
2804  
2805 # check parameter exists
2806 0 ▶ if(!defined $concept) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $concept) 0 0 0
2807 0 $errorhandler->_error($pkg, $function, "Error with input variable \$concept.", 4);
2808 }
2809  
2810 # check if valid concept
2811 0 ▶ if(! ($errorhandler->_validCui($concept)) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($errorhandler->_validCui($concept)) 0 0 0
2812 0 $errorhandler->_error($pkg, $function, "Concept ($concept) is not valid.", 6);
2813 }
2814  
2815 # set the return hash
2816 0 my %retHash = ();
2817  
2818 # if the concept is the root return the root string
2819 0 ▶ if($concept eq $umlsRoot) {
Branch: 1 branch
BranchTrueFalseTotal
if ($concept eq $umlsRoot) 0 0 0
2820 0 $retHash{"**UMLS ROOT**"}++;
2821 0 my @array = keys(%retHash);
2822 0 return \@array;
2823 }
2824  
2825 # set the database
2826 0 my $db = $self->{'db'};
2827 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
2828  
2829 # get the strings associated to the CUI
2830 0 my $arrRef = "";
2831 0 ▶ if($umlsall) {
Branch: 1 branch
BranchTrueFalseTotal
if ($umlsall) { } 0 0 0
2832 0 $arrRef = $db->selectcol_arrayref("select distinct STR from MRCONSO where CUI='$concept' and TS='P' and LAT='ENG'");
2833 }
2834 else {
2835 0 $arrRef = $db->selectcol_arrayref("select distinct STR from MRCONSO where CUI='$concept' and TS='P' and ($sources or SAB='SRC') and LAT='ENG'");
2836 }
2837  
2838 # check the database for errors
2839 0 $errorhandler->_checkDbError($pkg, $function, $db);
2840  
2841  
2842 # clean up the strings a bit and lower case them
2843 0 my $term = "";
2844 0 foreach my $tr (@{$arrRef}) {
2845 0 $tr =~ s/^\s+//;
2846 0 $tr =~ s/\s+$//;
2847 0 $tr =~ s/\s+/ /g;
2848 0 $term = $tr;
2849 }
2850
2851 # return the strings
2852 0 return $term;
2853 }
2854  
2855  
2856  
2857 # method that maps terms to cuis in the sources specified in
2858 # in the configuration file by the user using the SAB parameter
2859 # input : $concept <- string containing cui
2860 # output: $array <- reference to an array of terms (strings)
2861 sub _getTermList {
2862 0 ▶ my $self = shift;
Subroutine _getTermList: not called CC=9 SCAR=45.0
2863 0 my $concept = shift;
2864  
2865 0 my $function = "_getTermList";
2866  
2867 # check self
2868 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
2869 0 $errorhandler->_error($pkg, $function, "", 2);
2870 }
2871  
2872 # check parameter exists
2873 0 ▶ if(!defined $concept) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $concept) 0 0 0
2874 0 $errorhandler->_error($pkg, $function, "Error with input variable \$concept.", 4);
2875 }
2876  
2877 # check if valid concept
2878 0 ▶ if(! ($errorhandler->_validCui($concept)) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($errorhandler->_validCui($concept)) 0 0 0
2879 0 $errorhandler->_error($pkg, $function, "Concept ($concept) is not valid.", 6);
2880 }
2881  
2882 # set the return hash
2883 0 my %retHash = ();
2884  
2885 # if the concept is the root return the root string
2886 0 ▶ if($concept eq $umlsRoot) {
Branch: 1 branch
BranchTrueFalseTotal
if ($concept eq $umlsRoot) 0 0 0
2887 0 $retHash{"**UMLS ROOT**"}++;
2888 0 my @array = keys(%retHash);
2889 0 return \@array;
2890 }
2891  
2892 # set the database
2893 0 my $db = $self->{'db'};
2894 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
2895  
2896 # get the strings associated to the CUI
2897 0 my $arrRef = "";
2898 0 ▶ if($umlsall) {
Branch: 1 branch
BranchTrueFalseTotal
if ($umlsall) { } 0 0 0
2899 0 $arrRef = $db->selectcol_arrayref("select distinct STR from MRCONSO where CUI='$concept'");
2900 }
2901 else {
2902 0 $arrRef = $db->selectcol_arrayref("select distinct STR from MRCONSO where CUI='$concept' and ($sources or SAB='SRC')");
2903 }
2904  
2905 # check the database for errors
2906 0 $errorhandler->_checkDbError($pkg, $function, $db);
2907  
2908 # clean up the strings a bit and lower case them
2909 0 foreach my $tr (@{$arrRef}) {
2910 0 $tr =~ s/^\s+//;
2911 0 $tr =~ s/\s+$//;
2912 0 $tr =~ s/\s+/ /g;
2913 0 $retHash{lc($tr)} = 1;
2914 }
2915  
2916 0 my @array = keys(%retHash);
2917  
2918 # return the strings
2919 0 return \@array;
2920 }
2921  
2922 # method that maps terms to cuis in the sources specified in
2923 # in the configuration file by the user using the SABDEF parameter
2924 # input : $concept <- string containing cui
2925 # output: $array <- reference to an array of terms
2926 sub _getDefTermList {
2927 0 ▶ my $self = shift;
Subroutine _getDefTermList: not called CC=9 SCAR=45.0
2928 0 my $concept = shift;
2929  
2930 0 my $function = "_getTermList";
2931  
2932 # check self
2933 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
2934 0 $errorhandler->_error($pkg, $function, "", 2);
2935 }
2936  
2937 # check parameter exists
2938 0 ▶ if(!defined $concept) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $concept) 0 0 0
2939 0 $errorhandler->_error($pkg, $function, "Error with input variable \$concept.", 4);
2940 }
2941  
2942 # check if valid concept
2943 0 ▶ if(! ($errorhandler->_validCui($concept)) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($errorhandler->_validCui($concept)) 0 0 0
2944 0 $errorhandler->_error($pkg, $function, "Concept ($concept) is not valid.", 6);
2945 }
2946  
2947 # set the return hash
2948 0 my %retHash = ();
2949  
2950 # if the concept is the root return the root string
2951 0 ▶ if($concept eq $umlsRoot) {
Branch: 1 branch
BranchTrueFalseTotal
if ($concept eq $umlsRoot) 0 0 0
2952 0 $retHash{"**UMLS ROOT**"}++;
2953 0 my @array = keys(%retHash);
2954 0 return \@array;
2955 }
2956  
2957 # set the database
2958 0 my $db = $self->{'db'};
2959 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
2960  
2961 # get the strings associated to the CUI
2962 0 my $arrRef = "";
2963 0 ▶ if($sabdef_umlsall) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sabdef_umlsall) { } 0 0 0
2964 0 $arrRef = $db->selectcol_arrayref("select distinct STR from MRCONSO where CUI='$concept'");
2965 }
2966 else {
2967 0 $arrRef = $db->selectcol_arrayref("select distinct STR from MRCONSO where CUI='$concept' and ($sabdefsources or SAB='SRC')");
2968 }
2969  
2970 # check the database for errors
2971 0 $errorhandler->_checkDbError($pkg, $function, $db);
2972  
2973 # clean up the strings a bit and lower case them
2974 0 foreach my $tr (@{$arrRef}) {
2975 0 $tr =~ s/^\s+//;
2976 0 $tr =~ s/\s+$//;
2977 0 $tr =~ s/\s+/ /g;
2978 0 $retHash{lc($tr)} = 1;
2979 }
2980  
2981 # return the strings
2982 0 my @array = keys(%retHash);
2983 0 return \@array;
2984 }
2985  
2986 # method that maps terms to cuis in the sources specified in
2987 # in the configuration file by the user
2988 # input : $concept <- string containing cui
2989 # output: $array <- reference to an array of terms and their sources
2990 sub _getTermSabList {
2991 0 ▶ my $self = shift;
Subroutine _getTermSabList: not called CC=9 SCAR=45.0
2992 0 my $concept = shift;
2993  
2994 0 my $function = "_getTermSabList";
2995 0 &_debug($function);
2996  
2997 # check self
2998 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
2999 0 $errorhandler->_error($pkg, $function, "", 2);
3000 }
3001  
3002 # check parameter exists
3003 0 ▶ if(!defined $concept) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $concept) 0 0 0
3004 0 $errorhandler->_error($pkg, $function, "Error with input variable \$concept.", 4);
3005 }
3006  
3007 # check if valid concept
3008 0 ▶ if(! ($errorhandler->_validCui($concept)) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($errorhandler->_validCui($concept)) 0 0 0
3009 0 $errorhandler->_error($pkg, $function, "Concept ($concept) is not valid.", 6);
3010 }
3011  
3012 # initialize the return hash
3013 0 my %retHash = ();
3014  
3015 # if the concept is the root return the root string
3016 0 ▶ if($concept eq $umlsRoot) {
Branch: 1 branch
BranchTrueFalseTotal
if ($concept eq $umlsRoot) 0 0 0
3017 0 $retHash{"**UMLS ROOT**"}++;
3018 0 my @array = keys(%retHash);
3019 0 return \@array;
3020 }
3021  
3022 # otherwise, set up the db
3023 0 my $db = $self->{'db'};
3024 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
3025 # get all of the strings with their corresponding sab
3026 0 my %strhash = (); my $sql = "";
3027 0 ▶ if($sabdef_umlsall) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sabdef_umlsall) { } 0 0 0
3028 0 $sql = qq{ select STR, SAB from MRCONSO where CUI='$concept' };
3029 }
3030 else {
3031 0 $sql = qq{select STR, SAB from MRCONSO where CUI='$concept' and ($sabdefsources or SAB='SRC') };
3032 }
3033 0 my $sth = $db->prepare( $sql );
3034 0 $sth->execute();
3035 0 my($str, $sab);
3036 0 $sth->bind_columns( undef, \$str, \$sab );
3037 0 ▶ while( $sth->fetch() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sth->fetch) 0 0 0
3038 0 $str =~ s/^\s+//;
3039 0 $str =~ s/\s+$//;
3040 0 $str =~ s/\s+/ /g;
3041 0 $str = lc($str);
3042 0 my $item = "$sab : $str";
3043 0 $retHash{$item}++;
3044 }
3045  
3046 0 $errorhandler->_checkDbError($pkg, $function, $sth);
3047 0 $sth->finish();
3048  
3049 # return keys
3050 0 my @array = keys(%retHash);
3051 0 return \@array;
3052 }
3053  
3054  
3055 # method to map terms to any concept in the umls
3056 # input : $concept <- string containing cui
3057 # output: $array <- reference to an array containing terms (strings)
3058 sub _getAllTerms {
3059 0 ▶ my $self = shift;
Subroutine _getAllTerms: not called CC=9 SCAR=45.0
3060 0 my $concept = shift;
3061  
3062 0 my $function = "_getAllTerms";
3063 0 &_debug($function);
3064  
3065 # check self
3066 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
3067 0 $errorhandler->_error($pkg, $function, "", 2);
3068 }
3069  
3070 # check parameter exists
3071 0 ▶ if(!defined $concept) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $concept) 0 0 0
3072 0 $errorhandler->_error($pkg, $function, "Error with input variable \$concept.", 4);
3073 }
3074  
3075 # check if valid concept
3076 0 ▶ if(! ($errorhandler->_validCui($concept)) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($errorhandler->_validCui($concept)) 0 0 0
3077 0 $errorhandler->_error($pkg, $function, "Concept ($concept) is not valid.", 6);
3078 }
3079  
3080 # initialize the return hash
3081 0 my %retHash = ();
3082  
3083 # if the concept is the root return the root string
3084 0 ▶ if($concept eq $umlsRoot) {
Branch: 1 branch
BranchTrueFalseTotal
if ($concept eq $umlsRoot) 0 0 0
3085 0 $retHash{"**UMLS ROOT**"}++;
3086 0 my @array = keys(%retHash);
3087 0 return \@array;
3088 }
3089  
3090 # otherwise, set up the db
3091 0 my $db = $self->{'db'};
3092 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
3093  
3094 # get all of the strings with their corresponding sab
3095 0 my %strhash = ();
3096 0 my $sql = qq{ select STR, SAB from MRCONSO where CUI='$concept' };
3097 0 my $sth = $db->prepare( $sql );
3098 0 $sth->execute();
3099 0 my($str, $sab);
3100 0 $sth->bind_columns( undef, \$str, \$sab );
3101 0 ▶ while( $sth->fetch() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sth->fetch) 0 0 0
3102 0 $str =~ s/^\s+//;
3103 0 $str =~ s/\s+$//;
3104 0 $str =~ s/\s+/ /g;
3105 0 $str = lc($str);
3106 0 push @{$strhash{$str}}, $sab;
3107 }
3108 0 $errorhandler->_checkDbError($pkg, $function, $sth);
3109 0 $sth->finish();
3110  
3111 # set the output
3112 0 foreach my $str (sort keys %strhash) {
3113 0 my $sabs = join ", ", @{$strhash{$str}};
3114 0 my $index = "$str - $sabs";
3115 0 $retHash{$index}++;
3116 }
3117  
3118 0 my @array = keys(%retHash);
3119
3120 0 return \@array;
3121 }
3122  
3123 # method to map CUIs to a terms in the sources and the relations
3124 # specified in the configuration file by SAB and REL
3125 # input : $term <- string containing a term
3126 # output: $array <- reference to an array containing cuis
3127 sub _getConceptList {
3128  
3129 0 ▶ my $self = shift;
Subroutine _getConceptList: not called CC=7 SCAR=40.3
3130 0 my $term = shift;
3131  
3132 0 my $function = "_getConceptList";
3133 0 &_debug($function);
3134  
3135 # check self
3136 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
3137 0 $errorhandler->_error($pkg, $function, "", 2);
3138 }
3139  
3140 # check parameter exists
3141 0 ▶ if(!defined $term) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $term) 0 0 0
3142 0 $errorhandler->_error($pkg, $function, "Error with input variable \$term.", 4);
3143 }
3144  
3145 # check that the ' are escaped if exist
3146 0 $term=~s/\\?\'/\\\'/;
3147  
3148 # set up the database
3149 0 my $db = $self->{'db'};
3150 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
3151  
3152 # get the cuis
3153 0 my $arrRef = "";
3154  
3155 0 ▶ if($umlsall) {
Branch: 2 branches
BranchTrueFalseTotal
if ($umlsall) { } 0 0 0
elsif ($sources ne '') { } 0 0 0
3156 0 $arrRef = $db->selectcol_arrayref("select distinct CUI from MRCONSO where STR='$term'");
3157 }
3158 elsif($sources ne "") {
3159  
3160 0 $arrRef = $db->selectcol_arrayref("select distinct CUI from MRCONSO where STR='$term' and ($sources)");
3161 }
3162 else {
3163 0 $errorhandler->_error($pkg, $function, "Error with sources from configuration file.", 5);
3164 }
3165 # check for database errors
3166 0 $errorhandler->_checkDbError($pkg, $function, $db);
3167  
3168 0 return $arrRef;
3169 }
3170  
3171 # method to map CUIs to a terms in the sources and the relations
3172 # specified in the configuration file by SABDEF and RELDEF
3173 # input : $term <- string containing a term
3174 # output: $array <- reference to an array containing cuis
3175 sub _getDefConceptList {
3176  
3177 0 ▶ my $self = shift;
Subroutine _getDefConceptList: not called CC=7 SCAR=40.3
3178 0 my $term = shift;
3179  
3180 0 my $function = "_getDefConceptList";
3181  
3182 # check self
3183 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
3184 0 $errorhandler->_error($pkg, $function, "", 2);
3185 }
3186  
3187 # check parameter exists
3188 0 ▶ if(!defined $term) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $term) 0 0 0
3189 0 $errorhandler->_error($pkg, $function, "Error with input variable \$term.", 4);
3190 }
3191  
3192 # check that the ' are escaped if exist
3193 0 $term=~s/\\?\'/\\\'/;
3194  
3195 # set up the database
3196 0 my $db = $self->{'db'};
3197 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
3198  
3199 # get the cuis
3200 0 my $arrRef = "";
3201
3202 0 ▶ if($sabdef_umlsall) {
Branch: 2 branches
BranchTrueFalseTotal
if ($sabdef_umlsall) { } 0 0 0
elsif ($sabdefsources ne '') { } 0 0 0
3203 0 $arrRef = $db->selectcol_arrayref("select distinct CUI from MRCONSO where STR='$term'");
3204 }
3205 elsif($sabdefsources ne "") {
3206 0 $arrRef = $db->selectcol_arrayref("select distinct CUI from MRCONSO where STR='$term' and ($sabdefsources)");
3207 }
3208 else {
3209 0 $errorhandler->_error($pkg, $function, "Error with sources from configuration file.", 5);
3210 }
3211 # check for database errors
3212 0 $errorhandler->_checkDbError($pkg, $function, $db);
3213  
3214 0 return $arrRef;
3215 }
3216  
3217 # method to map CUIs to a terms using the CUIs in the
3218 # entire UMLS not just the sources in the config file
3219 # input : $term <- string containing a term
3220 # output: $array <- reference to an array containing cuis
3221 sub _getAllConcepts {
3222  
3223 0 ▶ my $self = shift;
Subroutine _getAllConcepts: not called CC=5 SCAR=34.0
3224 0 my $term = shift;
3225  
3226 0 my $function = "_getAllConcepts";
3227  
3228 # check self
3229 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
3230 0 $errorhandler->_error($pkg, $function, "", 2);
3231 }
3232  
3233 # check parameter exists
3234 0 ▶ if(!defined $term) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $term) 0 0 0
3235 0 $errorhandler->_error($pkg, $function, "Error with input variable \$term.", 4);
3236 }
3237  
3238 # check that the ' are escaped if exist
3239 0 $term=~s/\\?\'/\\\'/;
3240  
3241 # set up the database
3242 0 my $db = $self->{'db'};
3243 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
3244  
3245 # get the cuis
3246 0 my $arrRef = $db->selectcol_arrayref("select distinct CUI from MRCONSO where STR='$term'");
3247  
3248 # check for database errors
3249 0 $errorhandler->_checkDbError($pkg, $function, $db);
3250  
3251 0 return $arrRef;
3252 }
3253  
3254 # method returns all the compounds in the sources
3255 # specified in the configuration file
3256 # input:
3257 # output: $hash <- reference to a hash containing cuis
3258 sub _getCompounds {
3259  
3260 0 ▶ my $self = shift;
Subroutine _getCompounds: not called CC=10 SCAR=47.0
3261  
3262 0 my $function = "_getCompounds";
3263 0 &_debug($function);
3264  
3265 # check self
3266 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
3267 0 $errorhandler->_error($pkg, $function, "", 2);
3268 }
3269  
3270 # set up the database
3271 0 my $db = $self->{'db'};
3272 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
3273  
3274 # initialize return hash
3275 0 my %compounds = ();
3276  
3277 # get strings in the MRCONSO table
3278 0 ▶ if($umlsall) {
Branch: 1 branch
BranchTrueFalseTotal
if ($umlsall) { } 0 0 0
3279 # get all the terms from the MRCONSO table
3280 0 my $strs = $db->selectcol_arrayref("select distinct STR from MRCONSO");
3281 0 $errorhandler->_checkDbError($pkg, $function, $db);
3282  
3283 # loop through the terms and add the ones that have more than one word to the hash
3284 0 foreach my $str (@{$strs}) {
3285 0 my @array = split/\s+/, $str;
3286 0 ▶ if($#array > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#array > 0) 0 0 0
3287 0 $compounds{$str} = 0;
3288 }
3289 }
3290 }
3291 else {
3292  
3293 # for each of the sabs in the configuratinon file get strings
3294 0 foreach my $sab (sort keys %sabnamesHash) {
3295
3296 # get the cuis for that sab
3297 0 my $strs = $db->selectcol_arrayref("select distinct STR from MRCONSO where SAB=\'$sab\'");
3298 0 $errorhandler->_checkDbError($pkg, $function, $db);
3299
3300 # loop through the terms and add the ones that have more than one word to the hash
3301 0 foreach my $str (@{$strs}) {
3302 0 my @array = split/\s+/, $str;
3303 0 ▶ if($#array > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#array > 0) 0 0 0
3304 0 $compounds{$str} = 0;
3305 }
3306 }
3307 }
3308 }
3309
3310 0 return \%compounds;
3311 }
3312  
3313  
3314 # method returns all of the cuis in the sources
3315 # specified in the configuration file
3316 # input :
3317 # output: $hash <- reference to a hash containing cuis
3318 sub _getCuiList {
3319  
3320 0 ▶ my $self = shift;
Subroutine _getCuiList: not called CC=11 SCAR=48.8
3321  
3322 0 my $function = "_getCuiList";
3323 0 &_debug($function);
3324  
3325 # check self
3326 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
3327 0 $errorhandler->_error($pkg, $function, "", 2);
3328 }
3329  
3330 # if this has already been done just return the stored cuiListHash
3331 0 my $elements = keys %cuiListHash;
3332 0 ▶ if($elements > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elements > 0) 0 0 0
3333 0 return \%cuiListHash;
3334 }
3335  
3336 # otherwise, set up the database
3337 0 my $db = $self->{'db'};
3338 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
3339  
3340 # get the sabs in the config file
3341 0 my @sabs = ();
3342 0 ▶ if($umlsall) {
Branch: 1 branch
BranchTrueFalseTotal
if ($umlsall) { } 0 0 0
3343 0 my $s = $db->selectcol_arrayref("select distinct SAB from MRREL");
3344 0 $errorhandler->_checkDbError($pkg, $function, $db);
3345 0 @sabs = @{$s};
3346 }
3347 else {
3348 0 foreach my $sab (sort keys %sabnamesHash) { push @sabs, $sab; }
3349 }
3350  
3351 # initialize the cui list hash
3352 0 %cuiListHash = ();
3353  
3354 # for each of the sabs in the configuratino file
3355 0 foreach my $sab (@sabs) {
3356  
3357 # get the cuis for that sab
3358 0 my $cuis = $self->_getCuis($sab);
3359  
3360 # add the cuis to the hash
3361 0 foreach my $cui (@{$cuis}) { $cuiListHash{$cui} = 0 };
3362 }
3363  
3364 # add upper level taxonomy
3365 0 foreach my $cui (sort keys %parentTaxonomyArray) { $cuiListHash{$cui} = 0; }
3366 0 foreach my $cui (sort keys %childTaxonomyArray) { $cuiListHash{$cui} = 0; }
3367  
3368 0 return \%cuiListHash;
3369 }
3370  
3371 # returns the cuis from a specified source
3372 # input : $sab <- string contain the sources abbreviation
3373 # output: $array <- reference to an array containing cuis
3374 sub _getCuisFromSource {
3375  
3376 0 ▶ my $self = shift;
Subroutine _getCuisFromSource: not called CC=3 SCAR=24.8
3377 0 my $sab = shift;
3378  
3379 0 my $function = "_getCuisFromSource";
3380 0 &_debug($function);
3381  
3382 # check self
3383 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
3384 0 $errorhandler->_error($pkg, $function, "", 2);
3385 }
3386  
3387 # get the cuis from the specified source
3388 0 my $arrRef = $self->_getCuis($sab);
3389  
3390 0 return ($arrRef);
3391 }
3392  
3393 # returns all of the sources specified that contain the given cui
3394 # input : $concept <- string containing the cui
3395 # output: $array <- reference to an array contain the sources (abbreviations)
3396 sub _getSab {
3397  
3398 0 ▶ my $self = shift;
Subroutine _getSab: not called CC=6 SCAR=37.4
3399 0 my $concept = shift;
3400  
3401 0 my $function = "_getSab";
3402  
3403 # check self
3404 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
3405 0 $errorhandler->_error($pkg, $function, "", 2);
3406 }
3407  
3408 # check parameter exists
3409 0 ▶ if(!defined $concept) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $concept) 0 0 0
3410 0 $errorhandler->_error($pkg, $function, "Error with input variable \$concept.", 4);
3411 }
3412  
3413 # check if valid concept
3414 0 ▶ if(! ($errorhandler->_validCui($concept)) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($errorhandler->_validCui($concept)) 0 0 0
3415 0 $errorhandler->_error($pkg, $function, "Concept ($concept) is not valid.", 6);
3416 }
3417  
3418 # connect to the database
3419 0 my $db = $self->{'db'};
3420 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
3421  
3422 # select all the sources from the mrconso table
3423 0 my $arrRef = $db->selectcol_arrayref("select distinct SAB from MRCONSO where CUI='$concept'");
3424  
3425 # check the database for errors
3426 0 $errorhandler->_checkDbError($pkg, $function, $db);
3427  
3428 0 return $arrRef;
3429 }
3430  
3431 # returns the child relations
3432 # input :
3433 # output: $string <- containing the child relations
3434 sub _getChildRelations {
3435 0 ▶ my $self = shift;
Subroutine _getChildRelations: not called CC=1 SCAR=6.9
3436  
3437 0 return $childRelations;
3438 }
3439 # returns the parent relations
3440 # input :
3441 # output: $string <- containing the parent relations
3442 sub _getParentRelations {
3443 0 ▶ my $self = shift;
Subroutine _getParentRelations: not called CC=1 SCAR=6.9
3444  
3445 0 return $parentRelations;
3446 }
3447  
3448  
3449 # returns the children of a concept - the relations that
3450 # are considered children are predefined by the user.
3451 # the default are the RN and CHD relations
3452 # input : $concept <- string containing a cui
3453 # output: $array <- reference to an array containing a list of cuis
3454 sub _getChildren {
3455  
3456 0 ▶ my $self = shift;
Subroutine _getChildren: not called CC=9 SCAR=45.0
3457 0 my $concept = shift;
3458  
3459 0 my $function = "_getChildren";
3460 #&_debug($function);
3461  
3462 # check self
3463 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
3464 0 $errorhandler->_error($pkg, $function, "", 2);
3465 }
3466  
3467 # check parameter exists
3468 0 ▶ if(!defined $concept) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $concept) 0 0 0
3469 0 $errorhandler->_error($pkg, $function, "Error with input variable \$concept.", 4);
3470 }
3471  
3472 # check if valid concept
3473 0 ▶ if(! ($errorhandler->_validCui($concept)) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($errorhandler->_validCui($concept)) 0 0 0
3474 0 $errorhandler->_error($pkg, $function, "Concept ($concept) is not valid.", 6);
3475 }
3476  
3477 # connect to the database
3478 0 my $db = $self->{'db'};
3479 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
3480  
3481 # if the concept is the umls root node cui return
3482 # the source's cuis
3483 0 ▶ if($concept eq $umlsRoot) {
Branch: 1 branch
BranchTrueFalseTotal
if ($concept eq $umlsRoot) { } 0 0 0
3484 0 my @array = (keys %sabHash);
3485 0 return \@array;
3486 }
3487  
3488 # otherwise everything is normal so return its children
3489 else {
3490 0 my $arrRef = "";
3491 0 ▶ if($umlsall) {
Branch: 1 branch
BranchTrueFalseTotal
if ($umlsall) { } 0 0 0
3492 0 $arrRef = $db->selectcol_arrayref("select distinct CUI2 from MRREL where CUI1='$concept' and ($childRelations) and CUI2!='$concept' and SUPPRESS='N'");
3493 }
3494 else {
3495 0 $arrRef = $db->selectcol_arrayref("select distinct CUI2 from MRREL where CUI1='$concept' and ($childRelations) and ($sources) and CUI2!='$concept' and SUPPRESS='N'");
3496 }
3497  
3498 # check the database for errors
3499 0 $errorhandler->_checkDbError($pkg, $function, $db);
3500  
3501 # add the children in the upper taxonomy
3502 0 my @array = ();
3503 0 ▶ if(exists $childTaxonomyArray{$concept}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $childTaxonomyArray{$concept}) { } 0 0 0
3504 0 @array = (@{$childTaxonomyArray{$concept}}, @{$arrRef});
3505 }
3506 else {
3507 0 @array = @{$arrRef};
3508 }
3509 0 return \@array;
3510 }
3511 }
3512  
3513  
3514 # returns the parents of a concept - the relations that
3515 # are considered parents are predefined by the user.
3516 # the default are the PAR and RB relations.
3517 # input : $concept <- string containing cui
3518 # outupt: $array <- reference to an array containing a list of cuis
3519 sub _getParents {
3520  
3521 0 ▶ my $self = shift;
Subroutine _getParents: not called CC=11 SCAR=48.8
3522 0 my $concept = shift;
3523  
3524 0 my $function = "_getParents";
3525  
3526 # check self
3527 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
3528 0 $errorhandler->_error($pkg, $function, "", 2);
3529 }
3530  
3531 # check parameter exists
3532 0 ▶ if(!defined $concept) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $concept) 0 0 0
3533 0 $errorhandler->_error($pkg, $function, "Error with input variable \$concept.", 4);
3534 }
3535  
3536 # check if valid concept
3537 0 ▶ if(! ($errorhandler->_validCui($concept)) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($errorhandler->_validCui($concept)) 0 0 0
3538 0 $errorhandler->_error($pkg, $function, "Concept ($concept) is not valid.", 6);
3539 }
3540  
3541 # connect to the database
3542 0 my $db = $self->{'db'};
3543 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
3544  
3545 # if the cui is a root return an empty array
3546 0 ▶ if($concept eq $umlsRoot) {
Branch: 2 branches
BranchTrueFalseTotal
if ($concept eq $umlsRoot) { } 0 0 0
elsif (exists $sabHash{$concept} and $concept ne $umlsRoot) { } 0 0 0
3547 0 my @returnarray = ();
3548 0 return \@returnarray; # empty array
3549 }
3550 # if the cui is a source cui but not a root return the umls root
3551 ▶ elsif( (exists $sabHash{$concept}) and ($concept ne $umlsRoot)) {
Condition0%0/3
exists $sabHash{$concept} and $concept ne $umlsRoot
!ll&&!rl&&r
000
MC/DC0%0/2
exists $sabHash{$concept} and $concept ne $umlsRoot
exists $sabHash{$concept} $concept ne $umlsRoot
Truth table0%0/3
A and B
A= exists $sabHash{$concept}B= $concept ne $umlsRoot
ABresult
0X0
100
111
3552 0 my @returnarray = ();
3553 0 push @returnarray, $umlsRoot;
3554 0 return \@returnarray;
3555 }
3556 # otherwise everything is normal so return its parents
3557 else {
3558 0 my $arrRef = "";
3559 0 ▶ if($umlsall) {
Branch: 1 branch
BranchTrueFalseTotal
if ($umlsall) { } 0 0 0
3560 0 $arrRef = $db->selectcol_arrayref("select distinct CUI2 from MRREL where CUI1='$concept' and ($parentRelations) and CUI2!='$concept' and SUPPRESS='N'");
3561 }
3562 else {
3563 0 $arrRef = $db->selectcol_arrayref("select distinct CUI2 from MRREL where CUI1='$concept' and ($parentRelations) and ($sources) and CUI2!='$concept' and SUPPRESS='N'");
3564 }
3565  
3566 # check the database for errors
3567 0 $errorhandler->_checkDbError($pkg, $function, $db);
3568  
3569 # add the parents in the upper taxonomy
3570 0 my @array = ();
3571 0 ▶ if(exists $parentTaxonomyArray{$concept}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $parentTaxonomyArray{$concept}) { } 0 0 0
3572 0 @array = (@{$parentTaxonomyArray{$concept}}, @{$arrRef});
3573 }
3574 else {
3575 0 @array = @{$arrRef};
3576 }
3577 0 return \@array;
3578 }
3579 }
3580  
3581 # returns the relations of a concept given a specified source
3582 # input : $concept <- string containing a cui
3583 # output: $array <- reference to an array containing strings of relations
3584 sub _getRelations {
3585  
3586 0 ▶ my $self = shift;
Subroutine _getRelations: not called CC=7 SCAR=40.3
3587 0 my $concept = shift;
3588  
3589 0 my $function = "_getRelations";
3590 0 &_debug($function);
3591  
3592 # check self
3593 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
3594 0 $errorhandler->_error($pkg, $function, "", 2);
3595 }
3596  
3597 # check parameter exists
3598 0 ▶ if(!defined $concept) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $concept) 0 0 0
3599 0 $errorhandler->_error($pkg, $function, "Error with input variable \$concept.", 4);
3600 }
3601  
3602 # check if valid concept
3603 0 ▶ if(! ($errorhandler->_validCui($concept)) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($errorhandler->_validCui($concept)) 0 0 0
3604 0 $errorhandler->_error($pkg, $function, "Concept ($concept) is not valid.", 6);
3605 }
3606  
3607 # connect to the database
3608 0 my $db = $self->{'db'};
3609 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
3610  
3611 # get the relations
3612 0 my $arrRef = "";
3613 0 ▶ if($umlsall) {
Branch: 1 branch
BranchTrueFalseTotal
if ($umlsall) { } 0 0 0
3614 0 $arrRef = $db->selectcol_arrayref("select distinct REL from MRREL where (CUI1='$concept' or CUI2='$concept') and CUI1!=CUI2");
3615 }
3616 else {
3617 0 $arrRef = $db->selectcol_arrayref("select distinct REL from MRREL where (CUI1='$concept' or CUI2='$concept') and ($sources) and CUI1!=CUI2");
3618 }
3619  
3620 # check the database for errors
3621 0 $errorhandler->_checkDbError($pkg, $function, $db);
3622  
3623 0 return $arrRef;
3624 }
3625  
3626 # returns the relations and its source between two concepts
3627 # input : $concept1 <- string containing a cui
3628 # : $concept2 <- string containing a cui
3629 # output: $array <- reference to an array containing the relations
3630 sub _getRelationsBetweenCuis {
3631  
3632 0 ▶ my $self = shift;
Subroutine _getRelationsBetweenCuis: not called CC=11 SCAR=48.8
3633 0 my $concept1 = shift;
3634 0 my $concept2 = shift;
3635  
3636 0 my $function = "_getRelationBetweenCuis";
3637 0 &_debug($function);
3638  
3639 # check self
3640 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
3641 0 $errorhandler->_error($pkg, $function, "", 2);
3642 }
3643  
3644 # check parameter exists
3645 0 ▶ if(!defined $concept1) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $concept1) 0 0 0
3646 0 $errorhandler->_error($pkg, $function, "Error with input variable \$concept1.", 4);
3647 }
3648 0 ▶ if(!defined $concept2) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $concept2) 0 0 0
3649 0 $errorhandler->_error($pkg, $function, "Error with input variable \$concept2.", 4);
3650 }
3651  
3652 # check if valid concept
3653 0 ▶ if(! ($errorhandler->_validCui($concept1)) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($errorhandler->_validCui($concept1)) 0 0 0
3654 0 $errorhandler->_error($pkg, $function, "Concept ($concept1) is not valid.", 6);
3655 }
3656 0 ▶ if(! ($errorhandler->_validCui($concept2)) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($errorhandler->_validCui($concept2)) 0 0 0
3657 0 $errorhandler->_error($pkg, $function, "Concept ($concept2) is not valid.", 6);
3658 }
3659 # connect to the database
3660 0 my $db = $self->{'db'};
3661 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
3662  
3663 0 my @array = ();
3664  
3665 0 ▶ if($concept1 eq $umlsRoot) {
Branch: 1 branch
BranchTrueFalseTotal
if ($concept1 eq $umlsRoot) 0 0 0
3666 0 push @array, "CHD (source)";
3667 0 return \@array;
3668 }
3669  
3670 # get the relations
3671 0 my $sql = "";
3672 0 ▶ if($umlsall) {
Branch: 1 branch
BranchTrueFalseTotal
if ($umlsall) { } 0 0 0
3673 0 $sql = qq{ select distinct REL, SAB from MRREL where (CUI1='$concept1' and CUI2='$concept2') and ($relations)};
3674 }
3675 else {
3676 0 $sql = qq{ select distinct REL, SAB from MRREL where (CUI1='$concept1' and CUI2='$concept2') and ($sources) and ($relations)};
3677 }
3678  
3679 0 my $sth = $db->prepare( $sql );
3680 0 $sth->execute();
3681 0 $errorhandler->_checkDbError($pkg, $function, $sth);
3682  
3683 0 my($rel, $sab);
3684 0 $sth->bind_columns( undef, \$rel, \$sab );
3685 0 ▶ while( $sth->fetch() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sth->fetch) 0 0 0
3686 0 my $str = "$rel ($sab)";
3687 0 push @array, $str;
3688 0 } $sth->finish();
3689  
3690 0 return \@array;
3691 }
3692  
3693 # checks to see a concept is forbidden
3694 # input : $concept <- string containing a cui
3695 # output: $string <- integer indicating true or false
3696 sub _forbiddenConcept {
3697  
3698 0 ▶ my $self = shift;
Subroutine _forbiddenConcept: not called CC=14 SCAR=53.5
3699 0 my $concept = shift;
3700  
3701 0 my $function = "_forbiddenConcept";
3702  
3703 # check self
3704 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
3705 0 $errorhandler->_error($pkg, $function, "", 2);
3706 }
3707  
3708 # check parameter exists
3709 0 ▶ if(!defined $concept) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $concept) 0 0 0
3710 0 $errorhandler->_error($pkg, $function, "Error with input variable \$concept.", 4);
3711 }
3712  
3713 # check if valid concept
3714 0 ▶ if(! ($errorhandler->_validCui($concept)) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($errorhandler->_validCui($concept)) 0 0 0
3715 0 $errorhandler->_error($pkg, $function, "Concept ($concept) is not valid.", 6);
3716 }
3717  
3718 # if concept is one of the following just return
3719 #C1274012|Ambiguous concept (inactive concept)
3720 0 ▶ if($concept=~/C1274012/) { return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($concept =~ /C1274012/) 0 0 0
3721 #C1274013|Duplicate concept (inactive concept)
3722 0 ▶ if($concept=~/C1274013/) { return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($concept =~ /C1274013/) 0 0 0
3723 #C1276325|Reason not stated concept (inactive concept)
3724 0 ▶ if($concept=~/C1276325/) { return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($concept =~ /C1276325/) 0 0 0
3725 #C1274014|Outdated concept (inactive concept)
3726 0 ▶ if($concept=~/C1274014/) { return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($concept =~ /C1274014/) 0 0 0
3727 #C1274015|Erroneous concept (inactive concept)
3728 0 ▶ if($concept=~/C1274015/) { return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($concept =~ /C1274015/) 0 0 0
3729 #C1274021|Moved elsewhere (inactive concept)
3730 0 ▶ if($concept=~/C1274021/) { return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($concept =~ /C1274021/) 0 0 0
3731 #C1443286|unapproved attribute
3732 0 ▶ if($concept=~/C1443286/) { return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($concept =~ /C1443286/) 0 0 0
3733 #C1274012|non-current concept - ambiguous
3734 0 ▶ if($concept=~/C1274012/) { return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($concept =~ /C1274012/) 0 0 0
3735 #C2733115|limited status concept
3736 0 ▶ if($concept=~/C2733115/) { return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($concept =~ /C2733115/) 0 0 0
3737  
3738 0 return 0;
3739 }
3740  
3741 # Subroutine to get the semantic type's tui of a concept
3742 # input : $cui <- string containing a concept
3743 # output: $array <- reference to an array containing the semantic
3744 # type's TUIs associated with the concept
3745 sub _getSt {
3746  
3747 0 ▶ my $self = shift;
Subroutine _getSt: not called CC=6 SCAR=37.4
3748 0 my $concept = shift;
3749  
3750 0 my $function = "_getSt";
3751 0 &_debug($function);
3752  
3753 # check self
3754 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
3755 0 $errorhandler->_error($pkg, $function, "", 2);
3756 }
3757  
3758 # check parameter exists
3759 0 ▶ if(!defined $concept) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $concept) 0 0 0
3760 0 $errorhandler->_error($pkg, $function, "Error with input variable \$concept.", 4);
3761 }
3762  
3763 # check if valid concept
3764 0 ▶ if(! ($errorhandler->_validCui($concept)) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($errorhandler->_validCui($concept)) 0 0 0
3765 0 $errorhandler->_error($pkg, $function, "Concept ($concept) is not valid.", 6);
3766 }
3767  
3768 # set the database
3769 0 my $db = $self->{'db'};
3770 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
3771  
3772 # get the TUI
3773 0 my $arrRef = $db->selectcol_arrayref("select TUI from MRSTY where CUI=\'$concept\'");
3774  
3775 # check for database errors
3776 0 $errorhandler->_checkDbError($pkg, $function, $db);
3777  
3778 0 return $arrRef;
3779 }
3780  
3781 # Subroutine to get the semantic type's tui of a semantic group
3782 # input : $sg <- string containing a semantic group
3783 # output: $array <- reference to an array containing the semantic
3784 # type's TUIs associated with the concept
3785 sub _getStsFromSg {
3786  
3787 0 ▶ my $self = shift;
Subroutine _getStsFromSg: not called CC=8 SCAR=42.8
3788 0 my $sg = shift;
3789  
3790 0 my $function = "_getSt";
3791 0 &_debug($function);
3792  
3793 # check self
3794 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
3795 0 $errorhandler->_error($pkg, $function, "", 2);
3796 }
3797  
3798 # set the database
3799 0 my $db = $self->{'db'};
3800 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
3801  
3802  
3803 0 my $string = "";
3804 0 ▶ if(exists $sgConversion{$sg}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $sgConversion{$sg}) { } 0 0 0
3805 0 $string = $sgConversion{$sg};
3806 }
3807 else {
3808 0 $errorhandler->_error($pkg, $function, "Semantic Group ($sg) is not valid.", 6);
3809 }
3810
3811 0 my @sts = ();
3812 0 foreach my $st (sort keys %semanticGroups) {
3813 0 foreach my $group (@{$semanticGroups{$st}}) {
3814 0 ▶ if($string eq $group) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string eq $group) 0 0 0
3815 0 my $arrRef = $db->selectcol_arrayref("select ABR from SRDEF where STY_RL=\'$st\'");
3816 0 my $el = shift @{$arrRef};
3817 0 push @sts, $el;
3818 }
3819 }
3820 }
3821  
3822 0 return \@sts;
3823 }
3824  
3825  
3826 # Subroutine to get the semantic type's tui of a concept
3827 # input :
3828 # output: $array <- reference to an array containing all the semantic
3829 # type's TUIs
3830 sub _getAllSts {
3831  
3832 0 ▶ my $self = shift;
Subroutine _getAllSts: not called CC=4 SCAR=30.0
3833  
3834 0 my $function = "_getAllSt";
3835 0 &_debug($function);
3836  
3837 # check self
3838 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
3839 0 $errorhandler->_error($pkg, $function, "", 2);
3840 }
3841  
3842 # set the database
3843 0 my $db = $self->{'db'};
3844 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
3845  
3846 # get the TUI
3847 0 my $arrRef = $db->selectcol_arrayref("select distinct(TUI) from MRSTY");
3848
3849 # check for database errors
3850 0 $errorhandler->_checkDbError($pkg, $function, $db);
3851
3852 0 return $arrRef;
3853 }
3854  
3855 # subroutine to get the relation(s) between two semantic types
3856 # input : $st1 <- semantic type abbreviation
3857 # $st2 <- semantic type abbreviation
3858 # output: $array <- reference to an array of semantic relation(s)
3859 sub _getSemanticRelation {
3860  
3861 0 ▶ my $self = shift;
Subroutine _getSemanticRelation: not called CC=6 SCAR=37.4
3862 0 my $st1 = shift;
3863 0 my $st2 = shift;
3864  
3865 0 my $function = "_getSemanticRelation";
3866 0 &_debug($function);
3867  
3868 # check self
3869 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
3870 0 $errorhandler->_error($pkg, $function, "", 2);
3871 }
3872
3873 # check input
3874 0 ▶ if(!defined $st1) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $st1) 0 0 0
3875 0 $errorhandler->_error($pkg, $function, "Error with input variable \$st1.", 4);
3876 }
3877 0 ▶ if(!defined $st2) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $st2) 0 0 0
3878 0 $errorhandler->_error($pkg, $function, "Error with input variable \$st2.", 4);
3879 }
3880  
3881 # set the database
3882 0 my $db = $self->{'db'};
3883 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
3884  
3885 0 my $string1 = $self->_getStString($st1);
3886 0 my $string2 = $self->_getStString($st2);
3887  
3888 # get the string associated with the semantic type
3889 0 my $arrRef = $db->selectcol_arrayref("select distinct RL from SRSTR where STY_RL1=\'$string1\' and STY_RL2=\'$string2\'");
3890  
3891 # check database errors
3892 0 $errorhandler->_checkDbError($pkg, $function, $db);
3893  
3894 0 my @rarray = shift @{$arrRef};
3895 0 return \@rarray;;
3896 }
3897  
3898 # subroutine to get the name of a semantic type given its abbreviation
3899 # input : $st <- string containing the abbreviation of the semantic type
3900 # output: $string <- string containing the full name of the semantic type
3901 sub _getStString {
3902  
3903 0 ▶ my $self = shift;
Subroutine _getStString: not called CC=5 SCAR=34.0
3904 0 my $st = shift;
3905  
3906 0 my $function = "_getStString";
3907 0 &_debug($function);
3908  
3909 # check self
3910 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
3911 0 $errorhandler->_error($pkg, $function, "", 2);
3912 }
3913  
3914 # check parameter exists
3915 0 ▶ if(!defined $st) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $st) 0 0 0
3916 0 $errorhandler->_error($pkg, $function, "Error with input variable \$st.", 4);
3917 }
3918  
3919 # set the database
3920 0 my $db = $self->{'db'};
3921 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
3922  
3923 # get the string associated with the semantic type
3924 0 my $arrRef = $db->selectcol_arrayref("select STY_RL from SRDEF where ABR=\'$st\'");
3925  
3926 # check database errors
3927 0 $errorhandler->_checkDbError($pkg, $function, $db);
3928  
3929 0 return (shift @{$arrRef});
3930 }
3931  
3932  
3933 # subroutine to get the name of a semantic type given its TUI (UI)
3934 # input : $tui <- string containing the semantic type's TUI
3935 # output: $string <- string containing the semantic type's abbreviation
3936 sub _getStAbr {
3937  
3938 0 ▶ my $self = shift;
Subroutine _getStAbr: not called CC=6 SCAR=37.4
3939 0 my $tui = shift;
3940  
3941 0 my $function = "_getStAbr";
3942 0 &_debug($function);
3943  
3944 # check self
3945 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
3946 0 $errorhandler->_error($pkg, $function, "", 2);
3947 }
3948  
3949 # check parameter exists
3950 0 ▶ if(!defined $tui) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tui) 0 0 0
3951 0 $errorhandler->_error($pkg, $function, "Error with input variable \$tui.", 4);
3952 }
3953  
3954 # if tui is the root return ROOT
3955 0 ▶ if($tui eq "T000") {
Branch: 1 branch
BranchTrueFalseTotal
if ($tui eq "T000") 0 0 0
3956 0 return "ST ROOT";
3957 }
3958  
3959 # set the database
3960 0 my $db = $self->{'db'};
3961 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
3962  
3963 # obtain the abbreviation
3964 0 my $arrRef = $db->selectcol_arrayref("select ABR from SRDEF where UI=\'$tui\'");
3965  
3966 # check database errors
3967 0 $errorhandler->_checkDbError($pkg, $function, $db);
3968  
3969 0 return (shift @{$arrRef});
3970 }
3971  
3972  
3973 # subroutine to get the name of a semantic type's TUI given its abbrevation
3974 # input : $string <- string containing the semantic type's abbreviation
3975 # output: $tui <- string containing the semantic type's TUI
3976 sub _getStTui {
3977  
3978 0 ▶ my $self = shift;
Subroutine _getStTui: not called CC=5 SCAR=34.0
3979 0 my $abbrev = shift;
3980  
3981 0 my $function = "_getStTui";
3982 0 &_debug($function);
3983  
3984 # check self
3985 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
3986 0 $errorhandler->_error($pkg, $function, "", 2);
3987 }
3988  
3989 # check parameter exists
3990 0 ▶ if(!defined $abbrev) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $abbrev) 0 0 0
3991 0 $errorhandler->_error($pkg, $function, "Error with input variable \$abbrev.", 4);
3992 }
3993  
3994 # set the database
3995 0 my $db = $self->{'db'};
3996 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
3997  
3998 # obtain the abbreviation
3999 0 my $arrRef = $db->selectcol_arrayref("select UI from SRDEF where ABR=\'$abbrev\'");
4000  
4001 # check database errors
4002 0 $errorhandler->_checkDbError($pkg, $function, $db);
4003  
4004 0 return (shift @{$arrRef});
4005 }
4006  
4007  
4008 # subroutine to get the definition of a given TUI
4009 # input : $st <- string containing the semantic type's abbreviation
4010 # output: $string <- string containing the semantic type's definition
4011 sub _getStDef {
4012  
4013 0 ▶ my $self = shift;
Subroutine _getStDef: not called CC=5 SCAR=34.0
4014 0 my $st = shift;
4015  
4016 0 my $function = "_getStDef";
4017 0 &_debug($function);
4018  
4019 # check self
4020 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
4021 0 $errorhandler->_error($pkg, $function, "", 2);
4022 }
4023  
4024 # check parameter exists
4025 0 ▶ if(!defined $st) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $st) 0 0 0
4026 0 $errorhandler->_error($pkg, $function, "Error with input variable \$st.", 4);
4027 }
4028  
4029 # set the database
4030 0 my $db = $self->{'db'};
4031 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
4032  
4033 # get the definition
4034 0 my $arrRef = $db->selectcol_arrayref("select DEF from SRDEF where ABR=\'$st\'");
4035  
4036 # check database errors
4037 0 $errorhandler->_checkDbError($pkg, $function, $db);
4038  
4039 0 return $arrRef;
4040 }
4041  
4042 # method returns the semantic group(s) associated with the concept
4043 # input : $concept <- string containing a cui
4044 # output: $array <- reference to an array containing semantic groups
4045 sub _getSemanticGroup {
4046 0 ▶ my $self = shift;
Subroutine _getSemanticGroup: not called CC=7 SCAR=40.3
4047 0 my $concept = shift;
4048  
4049 0 my $function = "_getSemanticGroup";
4050 0 &_debug($function);
4051  
4052 # check self
4053 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
4054 0 $errorhandler->_error($pkg, $function, "", 2);
4055 }
4056  
4057 # check parameter exists
4058 0 ▶ if(!defined $concept) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $concept) 0 0 0
4059 0 $errorhandler->_error($pkg, $function, "Error with input variable \$concept.", 4);
4060 }
4061  
4062 0 my $sts = $self->_getSt($concept);
4063
4064 0 my %groups = ();
4065 0 foreach my $st (@{$sts}) {
4066 0 my $abr = $self->_getStAbr($st);
4067 0 my $string = $self->_getStString($abr);
4068 0 foreach my $group (@{$semanticGroups{$string}}) {
4069 0 $groups{$group}++;
4070 }
4071 }
4072
4073 0 my @array = ();
4074 0 foreach my $group (sort keys %groups) {
4075 0 push @array, $group;
4076 }
4077
4078 0 return \@array;
4079 }
4080  
4081 # method returns the semantic groups
4082 # input :
4083 # output: $array <- reference to an array containing semantic groups
4084 sub _getAllSemanticGroups {
4085 0 ▶ my $self = shift;
Subroutine _getAllSemanticGroups: not called CC=6 SCAR=37.4
4086  
4087 0 my $function = "_getSemanticGroup";
4088 0 &_debug($function);
4089  
4090 # check self
4091 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
4092 0 $errorhandler->_error($pkg, $function, "", 2);
4093 }
4094  
4095 0 my %groups = ();
4096 0 foreach my $st (sort keys %semanticGroups) {
4097 0 foreach my $group (@{$semanticGroups{$st}}) {
4098 0 $groups{$group}++;
4099 }
4100 }
4101  
4102 0 my @array = ();
4103 0 foreach my $group (sort keys %groups) {
4104 0 my $code = $sgConversion1{$group};
4105 0 push @array, $code;
4106 }
4107
4108 0 return \@array;
4109 }
4110  
4111 # method returns the semantic group(s) associated with a semantic type
4112 # input : $st <- string containing a st
4113 # output: $array <- reference to an array containing semantic groups
4114 sub _stGetSemanticGroup {
4115 0 ▶ my $self = shift;
Subroutine _stGetSemanticGroup: not called CC=5 SCAR=34.0
4116 0 my $st = shift;
4117  
4118 0 my $function = "_stGetSemanticGroup";
4119 0 &_debug($function);
4120  
4121 # check self
4122 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
4123 0 $errorhandler->_error($pkg, $function, "", 2);
4124 }
4125 0 my %groups = ();
4126  
4127 0 my $string = $self->_getStString($st);
4128  
4129 0 foreach my $group (@{$semanticGroups{$string}}) {
4130 0 $groups{$group}++;
4131 }
4132
4133 0 my @array = ();
4134 0 foreach my $group (sort keys %groups) { push @array, $group; }
4135
4136 0 return \@array;
4137 }
4138  
4139  
4140 # method returns the semantic group(s) associated with the concept
4141 # input : $st <- string containing a semantic type abbreviation
4142 # output: $array <- reference to an array containing semantic groups
4143 sub _getSemanticGroupOfSt {
4144 0 ▶ my $self = shift;
Subroutine _getSemanticGroupOfSt: not called CC=6 SCAR=37.4
4145 0 my $st = shift;
4146  
4147 0 my $function = "_getSemanticGroupOfSt";
4148 0 &_debug($function);
4149  
4150 # check self
4151 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
4152 0 $errorhandler->_error($pkg, $function, "", 2);
4153 }
4154  
4155 # check parameter exists
4156 0 ▶ if(!defined $st) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $st) 0 0 0
4157 0 $errorhandler->_error($pkg, $function, "Error with input variable \$st.", 4);
4158 }
4159
4160 0 my $string = $self->_getStString($st);
4161  
4162 0 my %groups = ();
4163 0 foreach my $group (@{$semanticGroups{$string}}) {
4164 0 $groups{$group}++;
4165 }
4166
4167 0 my @array = ();
4168 0 foreach my $group (sort keys %groups) { push @array, $group; }
4169
4170 0 return \@array;
4171 }
4172  
4173
4174 # method that returns a list of concepts (@concepts) related
4175 # to a concept $concept through a relation $rel
4176 # input : $concept <- string containing cui
4177 # $rel <- string containing a relation
4178 # output: $array <- reference to an array of cuis
4179 sub _getExtendedRelated {
4180  
4181 0 ▶ my $self = shift;
Subroutine _getExtendedRelated: not called CC=13 SCAR=52.0
4182 0 my $concept = shift;
4183 0 my $rel = shift;
4184  
4185 0 my $function = "_getExtendedRelated";
4186 0 &_debug($function);
4187  
4188 # check self
4189 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
4190 0 $errorhandler->_error($pkg, $function, "", 2);
4191 }
4192  
4193 # check parameter exists
4194 0 ▶ if(!defined $concept) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $concept) 0 0 0
4195 0 $errorhandler->_error($pkg, $function, "Error with input variable \$concept.", 4);
4196 }
4197  
4198 0 ▶ if(!defined $rel) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $rel) 0 0 0
4199 0 $errorhandler->_error($pkg, $function, "Error with input variable \$rel.", 4);
4200 }
4201  
4202 # check if valid concept
4203 0 ▶ if(! ($errorhandler->_validCui($concept)) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($errorhandler->_validCui($concept)) 0 0 0
4204 0 $errorhandler->_error($pkg, $function, "Concept ($concept) is not valid.", 6);
4205 }
4206  
4207 # set up database
4208 0 my $db = $self->{'db'};
4209 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
4210  
4211 # check if sources are specified and it is not umlsall
4212 0 my $optional = "";
4213 0 ▶ if(!$umlsall) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($umlsall) 0 0 0
4214 0 ▶ if($sabdefsources ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($sabdefsources ne "") 0 0 0
4215 0 $optional = " and ($sabdefsources)";
4216 }
4217 }
4218 # if the relations is either a parent or a child add the reladefparents if specified
4219 0 ▶ if( ($rel=~/PAR|RB/) && ($reladefparents ne "") ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rel =~ /PAR|RB/ and $reladefparents ne "") 0 0 0
Condition0%0/3
$rel =~ /PAR|RB/ and $reladefparents ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
$rel =~ /PAR|RB/ and $reladefparents ne ""
$rel =~ /PAR|RB/ $reladefparents ne ""
Truth table0%0/3
A and B
A= $rel =~ /PAR|RB/B= $reladefparents ne ""
ABresult
0X0
100
111
4220 0 $optional .= " and ($reladefparents)";
4221 }
4222 0 ▶ if( ($rel=~/CHD|RN/) && ($reladefchildren ne "") ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rel =~ /CHD|RN/ and $reladefchildren ne "") 0 0 0
Condition0%0/3
$rel =~ /CHD|RN/ and $reladefchildren ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
$rel =~ /CHD|RN/ and $reladefchildren ne ""
$rel =~ /CHD|RN/ $reladefchildren ne ""
Truth table0%0/3
A and B
A= $rel =~ /CHD|RN/B= $reladefchildren ne ""
ABresult
0X0
100
111
4223 0 $optional .= " and ($reladefchildren)";
4224 }
4225 # return all the relations 'rel' for cui 'concept'
4226 0 my $arrRef = $db->selectcol_arrayref("select distinct CUI2 from MRREL where CUI1='$concept' and REL='$rel' and CUI2!='$concept' $optional");
4227  
4228 # check for errors
4229 0 $errorhandler->_checkDbError($pkg, $function, $db);
4230  
4231 0 return $arrRef;
4232 }
4233  
4234 # subroutine to get the extended definition of a concept from
4235 # the concept and its surrounding relations as specified in the
4236 # the configuration file.
4237 # input : $concept <- string containing a cui
4238 # output: $array <- reference to an array containing the definitions
4239 sub _getExtendedDefinition {
4240  
4241 0 ▶ my $self = shift;
Subroutine _getExtendedDefinition: not called CC=43 SCAR=75.5
4242 0 my $concept = shift;
4243  
4244 0 my $function = "_getExtendedDefinition";
4245  
4246 # check self
4247 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
4248 0 $errorhandler->_error($pkg, $function, "", 2);
4249 }
4250  
4251 # check parameter exists
4252 0 ▶ if(!defined $concept) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $concept) 0 0 0
4253 0 $errorhandler->_error($pkg, $function, "Error with input variable \$concept.", 4);
4254 }
4255  
4256 # check if valid concept
4257 0 ▶ if(! ($errorhandler->_validCui($concept)) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($errorhandler->_validCui($concept)) 0 0 0
4258 0 $errorhandler->_error($pkg, $function, "Concept ($concept) is not valid.", 6);
4259 }
4260  
4261 # get database
4262 0 my $db = $self->{'db'};
4263 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
4264  
4265 0 my $sabflag = 1;
4266  
4267 0 my @defs = ();
4268  
4269 0 my $dkeys = keys %relDefHash;
4270  
4271 0 ▶ if( ($dkeys <= 0) or (exists $relDefHash{"ST"}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dkeys <= 0 or exists $relDefHash{"ST"}) 0 0 0
Condition0%0/3
$dkeys <= 0 or exists $relDefHash{"ST"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$dkeys <= 0 or exists $relDefHash{"ST"}
$dkeys <= 0 exists $relDefHash{"ST"}
Truth table0%0/3
A or B
A= $dkeys <= 0B= exists $relDefHash{"ST"}
ABresult
1X1
011
000
4272 0 my $sts = $self->_getSt($concept);
4273 0 foreach my $st (@{$sts}) {
4274 0 my $abr = $self->_getStAbr($st);
4275 0 my $def = $self->_getStDef($abr);
4276 0 my $str = "$concept ST $abr STDEF : @{$def}";
4277 0 push @defs, $str;
4278 }
4279 }
4280 0 ▶ if( ($dkeys <= 0) or (exists $relDefHash{"PAR"}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dkeys <= 0 or exists $relDefHash{"PAR"}) 0 0 0
Condition0%0/3
$dkeys <= 0 or exists $relDefHash{"PAR"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$dkeys <= 0 or exists $relDefHash{"PAR"}
$dkeys <= 0 exists $relDefHash{"PAR"}
Truth table0%0/3
A or B
A= $dkeys <= 0B= exists $relDefHash{"PAR"}
ABresult
1X1
011
000
4281 0 my $parents = $self->_getExtendedRelated($concept, "PAR");
4282 0 foreach my $parent (@{$parents}) {
4283 0 my $odefs = $self->_getCuiDef($parent, $sabflag);
4284 0 foreach my $d (@{$odefs}) {
4285 0 my @darray = split/\s+/, $d;
4286 0 my $sab = shift @darray;
4287 0 my $def = "$concept PAR $parent $sab : " . (join " ", @darray);
4288 0 push @defs, $def;
4289 }
4290 }
4291 }
4292 0 ▶ if( ($dkeys <= 0) or (exists $relDefHash{"CHD"}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dkeys <= 0 or exists $relDefHash{"CHD"}) 0 0 0
Condition0%0/3
$dkeys <= 0 or exists $relDefHash{"CHD"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$dkeys <= 0 or exists $relDefHash{"CHD"}
$dkeys <= 0 exists $relDefHash{"CHD"}
Truth table0%0/3
A or B
A= $dkeys <= 0B= exists $relDefHash{"CHD"}
ABresult
1X1
011
000
4293 0 my $children = $self->_getExtendedRelated($concept, "CHD");
4294 0 foreach my $child (@{$children}) {
4295 0 my $odefs = $self->_getCuiDef($child, $sabflag);
4296 0 foreach my $d (@{$odefs}) {
4297 0 my @darray = split/\s+/, $d;
4298 0 my $sab = shift @darray;
4299 0 my $def = "$concept CHD $child $sab : " . (join " ", @darray);
4300 0 push @defs, $def;
4301 }
4302 }
4303 }
4304 0 ▶ if( ($dkeys <= 0) or (exists $relDefHash{"SIB"}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dkeys <= 0 or exists $relDefHash{"SIB"}) 0 0 0
Condition0%0/3
$dkeys <= 0 or exists $relDefHash{"SIB"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$dkeys <= 0 or exists $relDefHash{"SIB"}
$dkeys <= 0 exists $relDefHash{"SIB"}
Truth table0%0/3
A or B
A= $dkeys <= 0B= exists $relDefHash{"SIB"}
ABresult
1X1
011
000
4305 0 my $siblings = $self->_getExtendedRelated($concept, "SIB");
4306 0 foreach my $sib (@{$siblings}) {
4307 0 my $odefs = $self->_getCuiDef($sib, $sabflag);
4308 0 foreach my $d (@{$odefs}) {
4309 0 my @darray = split/\s+/, $d;
4310 0 my $sab = shift @darray;
4311 0 my $def = "$concept SIB $sib $sab : " . (join " ", @darray);
4312 0 push @defs, $def;
4313 }
4314 }
4315 }
4316 0 ▶ if( ($dkeys <= 0) or (exists $relDefHash{"SYN"}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dkeys <= 0 or exists $relDefHash{"SYN"}) 0 0 0
Condition0%0/3
$dkeys <= 0 or exists $relDefHash{"SYN"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$dkeys <= 0 or exists $relDefHash{"SYN"}
$dkeys <= 0 exists $relDefHash{"SYN"}
Truth table0%0/3
A or B
A= $dkeys <= 0B= exists $relDefHash{"SYN"}
ABresult
1X1
011
000
4317 0 my $syns = $self->_getExtendedRelated($concept, "SYN");
4318 0 foreach my $syn (@{$syns}) {
4319 0 my $odefs = $self->_getCuiDef($syn, $sabflag);
4320 0 foreach my $d (@{$odefs}) {
4321 0 my @darray = split/\s+/, $d;
4322 0 my $sab = shift @darray;
4323 0 my $def = "$concept SYN $syn $sab : " . (join " ", @darray);
4324 0 push @defs, $def;
4325 }
4326 }
4327 }
4328 0 ▶ if( ($dkeys <= 0) or (exists $relDefHash{"RB"}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dkeys <= 0 or exists $relDefHash{"RB"}) 0 0 0
Condition0%0/3
$dkeys <= 0 or exists $relDefHash{"RB"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$dkeys <= 0 or exists $relDefHash{"RB"}
$dkeys <= 0 exists $relDefHash{"RB"}
Truth table0%0/3
A or B
A= $dkeys <= 0B= exists $relDefHash{"RB"}
ABresult
1X1
011
000
4329 0 my $rbs = $self->_getExtendedRelated($concept, "RB");
4330 0 foreach my $rb (@{$rbs}) {
4331 0 my $odefs = $self->_getCuiDef($rb, $sabflag);
4332 0 foreach my $d (@{$odefs}) {
4333 0 my @darray = split/\s+/, $d;
4334 0 my $sab = shift @darray;
4335 0 my $def = "$concept RB $rb $sab : " . (join " ", @darray);
4336 0 push @defs, $def;
4337 }
4338 }
4339 }
4340 0 ▶ if( ($dkeys <= 0) or (exists $relDefHash{"RN"}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dkeys <= 0 or exists $relDefHash{"RN"}) 0 0 0
Condition0%0/3
$dkeys <= 0 or exists $relDefHash{"RN"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$dkeys <= 0 or exists $relDefHash{"RN"}
$dkeys <= 0 exists $relDefHash{"RN"}
Truth table0%0/3
A or B
A= $dkeys <= 0B= exists $relDefHash{"RN"}
ABresult
1X1
011
000
4341 0 my $rns = $self->_getExtendedRelated($concept, "RN");
4342 0 foreach my $rn (@{$rns}) {
4343 0 my $odefs = $self->_getCuiDef($rn, $sabflag);
4344 0 foreach my $d (@{$odefs}) {
4345 0 my @darray = split/\s+/, $d;
4346 0 my $sab = shift @darray;
4347 0 my $def = "$concept RN $rn $sab : " . (join " ", @darray);
4348 0 push @defs, $def;
4349 }
4350 }
4351 }
4352 0 ▶ if( ($dkeys <= 0) or (exists $relDefHash{"RO"}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dkeys <= 0 or exists $relDefHash{"RO"}) 0 0 0
Condition0%0/3
$dkeys <= 0 or exists $relDefHash{"RO"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$dkeys <= 0 or exists $relDefHash{"RO"}
$dkeys <= 0 exists $relDefHash{"RO"}
Truth table0%0/3
A or B
A= $dkeys <= 0B= exists $relDefHash{"RO"}
ABresult
1X1
011
000
4353 0 my $ros = $self->_getExtendedRelated($concept, "RO");
4354 0 foreach my $ro (@{$ros}) {
4355 0 my $odefs = $self->_getCuiDef($ro, $sabflag);
4356 0 foreach my $d (@{$odefs}) {
4357 0 my @darray = split/\s+/, $d;
4358 0 my $sab = shift @darray;
4359 0 my $def = "$concept RO $ro $sab : " . (join " ", @darray);
4360 0 push @defs, $def;
4361 }
4362 }
4363 }
4364 0 ▶ if( ($dkeys <= 0) or (exists $relDefHash{"CUI"}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dkeys <= 0 or exists $relDefHash{"CUI"}) 0 0 0
Condition0%0/3
$dkeys <= 0 or exists $relDefHash{"CUI"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$dkeys <= 0 or exists $relDefHash{"CUI"}
$dkeys <= 0 exists $relDefHash{"CUI"}
Truth table0%0/3
A or B
A= $dkeys <= 0B= exists $relDefHash{"CUI"}
ABresult
1X1
011
000
4365 0 my $odefs = $self->_getCuiDef($concept, $sabflag);
4366 0 foreach my $d (@{$odefs}) {
4367 0 my @darray = split/\s+/, $d;
4368 0 my $sab = shift @darray;
4369 0 my $def = "$concept CUI $concept $sab : " . (join " ", @darray);
4370 0 push @defs, $def;
4371 }
4372 }
4373 0 ▶ if( ($dkeys <= 0) or (exists $relDefHash{"TERM"}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dkeys <= 0 or exists $relDefHash{"TERM"}) 0 0 0
Condition0%0/3
$dkeys <= 0 or exists $relDefHash{"TERM"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$dkeys <= 0 or exists $relDefHash{"TERM"}
$dkeys <= 0 exists $relDefHash{"TERM"}
Truth table0%0/3
A or B
A= $dkeys <= 0B= exists $relDefHash{"TERM"}
ABresult
1X1
011
000
4374 0 my $odefs = $self->_getTermSabList($concept);
4375 0 foreach my $item (@{$odefs}) {
4376 0 my ($sab, $term) = split/\s*\:\s*/, $item;
4377 0 my $def = "$concept TERM $concept $sab : $term";
4378 0 push @defs, $def;
4379 }
4380 }
4381 0 return \@defs;
4382 }
4383  
4384 # subroutine to get a CUIs definition
4385 # input : $concept <- string containing a cui
4386 # output: $array <- reference to an array of definitions (strings)
4387 sub _getCuiDef {
4388  
4389 0 ▶ my $self = shift;
Subroutine _getCuiDef: not called CC=9 SCAR=45.0
4390 0 my $concept = shift;
4391 0 my $sabflag = shift;
4392  
4393 0 my $function = "_getCuiDef";
4394  
4395 # check self
4396 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
4397 0 $errorhandler->_error($pkg, $function, "", 2);
4398 }
4399  
4400 # check parameter exists
4401 0 ▶ if(!defined $concept) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $concept) 0 0 0
4402 0 $errorhandler->_error($pkg, $function, "Error with input variable \$concept.", 4);
4403 }
4404  
4405 # check if valid concept
4406 0 ▶ if(! ($errorhandler->_validCui($concept)) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($errorhandler->_validCui($concept)) 0 0 0
4407 0 $errorhandler->_error($pkg, $function, "Concept ($concept) is not valid.", 6);
4408 }
4409  
4410 # get database
4411 0 my $db = $self->{'db'};
4412 0 ▶ if(!$db) { $errorhandler->_error($pkg, $function, "Error with db.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
4413  
4414 # set the query
4415 0 my $sql = "";
4416  
4417 0 ▶ if($sabdefsources ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($sabdefsources ne '') { } 0 0 0
4418 0 $sql = qq{ SELECT DEF, SAB FROM MRDEF WHERE CUI=\'$concept\' and ($sabdefsources) };
4419 }
4420 else {
4421 0 $sql = qq{ SELECT DEF, SAB FROM MRDEF WHERE CUI=\'$concept\' };
4422 }
4423  
4424 # get the information from the database
4425 0 my $sth = $db->prepare( $sql );
4426 0 $sth->execute();
4427 0 $errorhandler->_checkDbError($pkg, $function, $sth);
4428  
4429 # set the output variable
4430 0 my($def, $sab);
4431 0 my @defs = ();
4432 0 $sth->bind_columns( undef, \$def, \$sab );
4433 0 ▶ while( $sth->fetch() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sth->fetch) 0 0 0
4434 0 ▶ if(defined $sabflag) { push @defs, "$sab $def"; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sabflag) { } 0 0 0
4435 0 else { push @defs, $def; }
4436 0 } $sth->finish();
4437  
4438 0 return \@defs;
4439 }
4440  
4441  
4442 # returns the table names in both human readable and hex form
4443 # input :
4444 # output: $hash <- reference to a hash containin the table
4445 # names in human readable and hex form
4446 sub _returnTableNames {
4447 0 ▶ my $self = shift;
Subroutine _returnTableNames: not called CC=3 SCAR=24.8
4448  
4449 0 my $function = "_returnTableNames";
4450  
4451 # check self
4452 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
4453 0 $errorhandler->_error($pkg, $function, "", 2);
4454 }
4455  
4456 # set the output variable
4457 0 my %hash = ();
4458 0 $hash{$parentTableHuman} = $parentTable;
4459 0 $hash{$childTableHuman} = $childTable;
4460 0 $hash{$intrinsicTableHuman} = $intrinsicTable;
4461 0 $hash{$tableNameHuman} = $tableName;
4462 0 $hash{$cacheTableHuman} = $cacheTable;
4463  
4464 0 return \%hash;
4465 }
4466  
4467 # sets the semantic groups
4468 # input:
4469 # output:
4470 sub _setSemanticGroups {
4471  
4472 0 ▶ %semanticGroups = ();
Subroutine _setSemanticGroups: not called CC=1 SCAR=6.9
4473  
4474 0 push @{$semanticGroups{"Activity"}}, "Activities & Behaviors";
4475 0 push @{$semanticGroups{"Behavior"}}, "Activities & Behaviors";
4476 0 push @{$semanticGroups{"Daily or Recreational Activity"}}, "Activities & Behaviors";
4477 0 push @{$semanticGroups{"Event"}}, "Activities & Behaviors";
4478 0 push @{$semanticGroups{"Governmental or Regulatory Activity"}}, "Activities & Behaviors";
4479 0 push @{$semanticGroups{"Individual Behavior"}}, "Activities & Behaviors";
4480 0 push @{$semanticGroups{"Machine Activity"}}, "Activities & Behaviors";
4481 0 push @{$semanticGroups{"Occupational Activity"}}, "Activities & Behaviors";
4482 0 push @{$semanticGroups{"Social Behavior"}}, "Activities & Behaviors";
4483 0 push @{$semanticGroups{"Anatomical Structure"}}, "Anatomy";
4484 0 push @{$semanticGroups{"Body Location or Region"}}, "Anatomy";
4485 0 push @{$semanticGroups{"Body Part, Organ, or Organ Component"}}, "Anatomy";
4486 0 push @{$semanticGroups{"Body Space or Junction"}}, "Anatomy";
4487 0 push @{$semanticGroups{"Body Substance"}}, "Anatomy";
4488 0 push @{$semanticGroups{"Body System"}}, "Anatomy";
4489 0 push @{$semanticGroups{"Cell"}}, "Anatomy";
4490 0 push @{$semanticGroups{"Cell Component"}}, "Anatomy";
4491 0 push @{$semanticGroups{"Embryonic Structure"}}, "Anatomy";
4492 0 push @{$semanticGroups{"Fully Formed Anatomical Structure"}}, "Anatomy";
4493 0 push @{$semanticGroups{"Tissue"}}, "Anatomy";
4494 0 push @{$semanticGroups{"Amino Acid, Peptide, or Protein"}}, "Chemicals & Drugs";
4495 0 push @{$semanticGroups{"Antibiotic"}}, "Chemicals & Drugs";
4496 0 push @{$semanticGroups{"Biologically Active Substance"}}, "Chemicals & Drugs";
4497 0 push @{$semanticGroups{"Biomedical or Dental Material"}}, "Chemicals & Drugs";
4498 0 push @{$semanticGroups{"Carbohydrate"}}, "Chemicals & Drugs";
4499 0 push @{$semanticGroups{"Chemical"}}, "Chemicals & Drugs";
4500 0 push @{$semanticGroups{"Chemical Viewed Functionally"}}, "Chemicals & Drugs";
4501 0 push @{$semanticGroups{"Chemical Viewed Structurally"}}, "Chemicals & Drugs";
4502 0 push @{$semanticGroups{"Clinical Drug"}}, "Chemicals & Drugs";
4503 0 push @{$semanticGroups{"Eicosanoid"}}, "Chemicals & Drugs";
4504 0 push @{$semanticGroups{"Element, Ion, or Isotope"}}, "Chemicals & Drugs";
4505 0 push @{$semanticGroups{"Enzyme"}}, "Chemicals & Drugs";
4506 0 push @{$semanticGroups{"Hazardous or Poisonous Substance"}}, "Chemicals & Drugs";
4507 0 push @{$semanticGroups{"Hormone"}}, "Chemicals & Drugs";
4508 0 push @{$semanticGroups{"Immunologic Factor"}}, "Chemicals & Drugs";
4509 0 push @{$semanticGroups{"Indicator, Reagent, or Diagnostic Aid"}}, "Chemicals & Drugs";
4510 0 push @{$semanticGroups{"Inorganic Chemical"}}, "Chemicals & Drugs";
4511 0 push @{$semanticGroups{"Lipid"}}, "Chemicals & Drugs";
4512 0 push @{$semanticGroups{"Neuroreactive Substance or Biogenic Amine"}}, "Chemicals & Drugs";
4513 0 push @{$semanticGroups{"Nucleic Acid, Nucleoside, or Nucleotide"}}, "Chemicals & Drugs";
4514 0 push @{$semanticGroups{"Organic Chemical"}}, "Chemicals & Drugs";
4515 0 push @{$semanticGroups{"Organophosphorus Compound"}}, "Chemicals & Drugs";
4516 0 push @{$semanticGroups{"Pharmacologic Substance"}}, "Chemicals & Drugs";
4517 0 push @{$semanticGroups{"Receptor"}}, "Chemicals & Drugs";
4518 0 push @{$semanticGroups{"Steroid"}}, "Chemicals & Drugs";
4519 0 push @{$semanticGroups{"Vitamin"}}, "Chemicals & Drugs";
4520 0 push @{$semanticGroups{"Classification"}}, "Concepts & Ideas";
4521 0 push @{$semanticGroups{"Conceptual Entity"}}, "Concepts & Ideas";
4522 0 push @{$semanticGroups{"Functional Concept"}}, "Concepts & Ideas";
4523 0 push @{$semanticGroups{"Group Attribute"}}, "Concepts & Ideas";
4524 0 push @{$semanticGroups{"Idea or Concept"}}, "Concepts & Ideas";
4525 0 push @{$semanticGroups{"Intellectual Product"}}, "Concepts & Ideas";
4526 0 push @{$semanticGroups{"Language"}}, "Concepts & Ideas";
4527 0 push @{$semanticGroups{"Qualitative Concept"}}, "Concepts & Ideas";
4528 0 push @{$semanticGroups{"Quantitative Concept"}}, "Concepts & Ideas";
4529 0 push @{$semanticGroups{"Regulation or Law"}}, "Concepts & Ideas";
4530 0 push @{$semanticGroups{"Spatial Concept"}}, "Concepts & Ideas";
4531 0 push @{$semanticGroups{"Temporal Concept"}}, "Concepts & Ideas";
4532 0 push @{$semanticGroups{"Drug Delivery Device"}}, "Devices";
4533 0 push @{$semanticGroups{"Medical Device"}}, "Devices";
4534 0 push @{$semanticGroups{"Research Device"}}, "Devices";
4535 0 push @{$semanticGroups{"Acquired Abnormality"}}, "Disorders";
4536 0 push @{$semanticGroups{"Anatomical Abnormality"}}, "Disorders";
4537 0 push @{$semanticGroups{"Cell or Molecular Dysfunction"}}, "Disorders";
4538 0 push @{$semanticGroups{"Congenital Abnormality"}}, "Disorders";
4539 0 push @{$semanticGroups{"Disease or Syndrome"}}, "Disorders";
4540 0 push @{$semanticGroups{"Experimental Model of Disease"}}, "Disorders";
4541 0 push @{$semanticGroups{"Finding"}}, "Disorders";
4542 0 push @{$semanticGroups{"Injury or Poisoning"}}, "Disorders";
4543 0 push @{$semanticGroups{"Mental or Behavioral Dysfunction"}}, "Disorders";
4544 0 push @{$semanticGroups{"Neoplastic Process"}}, "Disorders";
4545 0 push @{$semanticGroups{"Pathologic Function"}}, "Disorders";
4546 0 push @{$semanticGroups{"Sign or Symptom"}}, "Disorders";
4547 0 push @{$semanticGroups{"Amino Acid Sequence"}}, "Genes & Molecular Sequences";
4548 0 push @{$semanticGroups{"Carbohydrate Sequence"}}, "Genes & Molecular Sequences";
4549 0 push @{$semanticGroups{"Gene or Genome"}}, "Genes & Molecular Sequences";
4550 0 push @{$semanticGroups{"Molecular Sequence"}}, "Genes & Molecular Sequences";
4551 0 push @{$semanticGroups{"Nucleotide Sequence"}}, "Genes & Molecular Sequences";
4552 0 push @{$semanticGroups{"Geographic Area"}}, "Geographic Areas";
4553 0 push @{$semanticGroups{"Age Group"}}, "Living Beings";
4554 0 push @{$semanticGroups{"Amphibian"}}, "Living Beings";
4555 0 push @{$semanticGroups{"Animal"}}, "Living Beings";
4556 0 push @{$semanticGroups{"Archaeon"}}, "Living Beings";
4557 0 push @{$semanticGroups{"Bacterium"}}, "Living Beings";
4558 0 push @{$semanticGroups{"Bird"}}, "Living Beings";
4559 0 push @{$semanticGroups{"Eukaryote"}}, "Living Beings";
4560 0 push @{$semanticGroups{"Family Group"}}, "Living Beings";
4561 0 push @{$semanticGroups{"Fish"}}, "Living Beings";
4562 0 push @{$semanticGroups{"Fungus"}}, "Living Beings";
4563 0 push @{$semanticGroups{"Group"}}, "Living Beings";
4564 0 push @{$semanticGroups{"Human"}}, "Living Beings";
4565 0 push @{$semanticGroups{"Mammal"}}, "Living Beings";
4566 0 push @{$semanticGroups{"Organism"}}, "Living Beings";
4567 0 push @{$semanticGroups{"Patient or Disabled Group"}}, "Living Beings";
4568 0 push @{$semanticGroups{"Plant"}}, "Living Beings";
4569 0 push @{$semanticGroups{"Population Group"}}, "Living Beings";
4570 0 push @{$semanticGroups{"Professional or Occupational Group"}}, "Living Beings";
4571 0 push @{$semanticGroups{"Reptile"}}, "Living Beings";
4572 0 push @{$semanticGroups{"Vertebrate"}}, "Living Beings";
4573 0 push @{$semanticGroups{"Virus"}}, "Living Beings";
4574 0 push @{$semanticGroups{"Entity"}}, "Objects";
4575 0 push @{$semanticGroups{"Food"}}, "Objects";
4576 0 push @{$semanticGroups{"Manufactured Object"}}, "Objects";
4577 0 push @{$semanticGroups{"Physical Object"}}, "Objects";
4578 0 push @{$semanticGroups{"Substance"}}, "Objects";
4579 0 push @{$semanticGroups{"Biomedical Occupation or Discipline"}}, "Occupations";
4580 0 push @{$semanticGroups{"Occupation or Discipline"}}, "Occupations";
4581 0 push @{$semanticGroups{"Health Care Related Organization"}}, "Organizations";
4582 0 push @{$semanticGroups{"Organization"}}, "Organizations";
4583 0 push @{$semanticGroups{"Professional Society"}}, "Organizations";
4584 0 push @{$semanticGroups{"Self-help or Relief Organization"}}, "Organizations";
4585 0 push @{$semanticGroups{"Biologic Function"}}, "Phenomena";
4586 0 push @{$semanticGroups{"Environmental Effect of Humans"}}, "Phenomena";
4587 0 push @{$semanticGroups{"Human-caused Phenomenon or Process"}}, "Phenomena";
4588 0 push @{$semanticGroups{"Laboratory or Test Result"}}, "Phenomena";
4589 0 push @{$semanticGroups{"Natural Phenomenon or Process"}}, "Phenomena";
4590 0 push @{$semanticGroups{"Phenomenon or Process"}}, "Phenomena";
4591 0 push @{$semanticGroups{"Cell Function"}}, "Physiology";
4592 0 push @{$semanticGroups{"Clinical Attribute"}}, "Physiology";
4593 0 push @{$semanticGroups{"Genetic Function"}}, "Physiology";
4594 0 push @{$semanticGroups{"Mental Process"}}, "Physiology";
4595 0 push @{$semanticGroups{"Molecular Function"}}, "Physiology";
4596 0 push @{$semanticGroups{"Organism Attribute"}}, "Physiology";
4597 0 push @{$semanticGroups{"Organism Function"}}, "Physiology";
4598 0 push @{$semanticGroups{"Organ or Tissue Function"}}, "Physiology";
4599 0 push @{$semanticGroups{"Physiologic Function"}}, "Physiology";
4600 0 push @{$semanticGroups{"Diagnostic Procedure"}}, "Procedures";
4601 0 push @{$semanticGroups{"Educational Activity"}}, "Procedures";
4602 0 push @{$semanticGroups{"Health Care Activity"}}, "Procedures";
4603 0 push @{$semanticGroups{"Laboratory Procedure"}}, "Procedures";
4604 0 push @{$semanticGroups{"Molecular Biology Research Technique"}}, "Procedures";
4605 0 push @{$semanticGroups{"Research Activity"}}, "Procedures";
4606 0 push @{$semanticGroups{"Therapeutic or Preventive Procedure"}}, "Procedures";
4607  
4608 0 $sgConversion{"ACTI"} = "Activities & Behaviors";
4609 0 $sgConversion{"ANAT"} = "Anatomy";
4610 0 $sgConversion{"CHEM"} = "Chemicals & Drugs";
4611 0 $sgConversion{"CONC"} = "Concepts & Ideas";
4612 0 $sgConversion{"DEVI"} = "Devices";
4613 0 $sgConversion{"DISO"} = "Disorders";
4614 0 $sgConversion{"GENE"} = "Genes & Molecular Sequences";
4615 0 $sgConversion{"GEOG"} = "Geographic Areas";
4616 0 $sgConversion{"LIVB"} = "Living Beings";
4617 0 $sgConversion{"OBJC"} = "Objects";
4618 0 $sgConversion{"OCCU"} = "Occupations";
4619 0 $sgConversion{"ORGA"} = "Organizations";
4620 0 $sgConversion{"PHEN"} = "Phenomena";
4621 0 $sgConversion{"PHYS"} = "Physiology";
4622 0 $sgConversion{"PROC"} = "Procedures";
4623  
4624 0 $sgConversion1{"Activities & Behaviors"} = "ACTI";
4625 0 $sgConversion1{"Anatomy"} = "ANAT";
4626 0 $sgConversion1{"Chemicals & Drugs"} = "CHEM";
4627 0 $sgConversion1{"Concepts & Ideas"} = "CONC";
4628 0 $sgConversion1{"Devices"} = "DEVI";
4629 0 $sgConversion1{"Disorders"} = "DISO";
4630 0 $sgConversion1{"Genes & Molecular Sequences"} = "GENE";
4631 0 $sgConversion1{"Geographic Areas"} = "GEOG";
4632 0 $sgConversion1{"Living Beings"} = "LIVB";
4633 0 $sgConversion1{"Objects"} = "OBJ";
4634 0 $sgConversion1{"Occupations"} = "OCCU";
4635 0 $sgConversion1{"Organizations"} = "ORGA";
4636 0 $sgConversion1{"Phenomena"} = "PHEN";
4637 0 $sgConversion1{"Physiology"} = "PHYS";
4638 0 $sgConversion1{"Procedures"} = "PROC";
4639 }
4640  
4641 # removes the configuration tables
4642 # input :
4643 # output:
4644 sub _dropConfigTable {
4645  
4646 0 ▶ my $self = shift;
Subroutine _dropConfigTable: not called CC=12 SCAR=50.5
4647  
4648 0 my $function = "_dropConfigTable";
4649 0 &_debug($function);
4650  
4651 # check self
4652 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
4653 0 $errorhandler->_error($pkg, $function, "", 2);
4654 }
4655  
4656 # connect to the database
4657 0 my $sdb = $self->_connectIndexDB();
4658 0 ▶ if(!$sdb) { $errorhandler->_error($pkg, $function, "Error with sdb.", 3); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($sdb) 0 0 0
4659  
4660 # show all of the tables
4661 0 my $sth = $sdb->prepare("show tables");
4662 0 $sth->execute();
4663 0 $errorhandler->_checkDbError($pkg, $function, $sth);
4664  
4665 # get all the tables in mysql
4666 0 my $table = "";
4667 0 my %tables = ();
4668 0 ▶ while(($table) = $sth->fetchrow()) {
Branch: 1 branch
BranchTrueFalseTotal
if (($table) = $sth->fetchrow) 0 0 0
4669 0 $tables{$table}++;
4670 }
4671 0 $sth->finish();
4672  
4673 0 ▶ if(exists $tables{$intrinsicTable}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $tables{$intrinsicTable}) 0 0 0
4674 0 $sdb->do("drop table $intrinsicTable");
4675 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
4676 }
4677 0 ▶ if(exists $tables{$parentTable}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $tables{$parentTable}) 0 0 0
4678 0 $sdb->do("drop table $parentTable");
4679 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
4680 }
4681 0 ▶ if(exists $tables{$childTable}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $tables{$childTable}) 0 0 0
4682 0 $sdb->do("drop table $childTable");
4683 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
4684 }
4685 0 ▶ if(exists $tables{$cacheTable}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $tables{$cacheTable}) 0 0 0
4686 0 $sdb->do("drop table $cacheTable");
4687 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
4688 }
4689 0 ▶ if(exists $tables{$tableName}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $tables{$tableName}) 0 0 0
4690 0 $sdb->do("drop table $tableName");
4691 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
4692 }
4693 0 ▶ if(exists $tables{$infoTable}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $tables{$infoTable}) 0 0 0
4694 0 $sdb->do("drop table $infoTable");
4695 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
4696 }
4697 0 ▶ if(exists $tables{"tableindex"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $tables{"tableindex"}) 0 0 0
4698  
4699 0 $sdb->do("delete from tableindex where HEX='$intrinsicTable'");
4700 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
4701  
4702 0 $sdb->do("delete from tableindex where HEX='$parentTable'");
4703 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
4704  
4705 0 $sdb->do("delete from tableindex where HEX='$childTable'");
4706 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
4707  
4708 0 $sdb->do("delete from tableindex where HEX='$cacheTable'");
4709 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
4710  
4711 0 $sdb->do("delete from tableindex where HEX='$tableName'");
4712 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
4713  
4714 0 $sdb->do("delete from tableindex where HEX='$infoTable'");
4715 0 $errorhandler->_checkDbError($pkg, $function, $sdb);
4716 }
4717 }
4718  
4719 # removes the configuration files
4720 # input :
4721 # output:
4722 sub _removeConfigFiles {
4723  
4724 0 ▶ my $self = shift;
Subroutine _removeConfigFiles: not called CC=7 SCAR=40.3
4725  
4726 0 my $function = "_removeConfigFiles";
4727 0 &_debug($function);
4728  
4729 # check self
4730 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
4731 0 $errorhandler->_error($pkg, $function, "", 2);
4732 }
4733  
4734 # remove the files
4735 0 ▶ if(-e $tableFile) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $tableFile) 0 0 0
4736 0 system "rm $tableFile";
4737 }
4738 0 ▶ if(-e $childFile) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $childFile) 0 0 0
4739 0 system "rm $childFile";
4740 }
4741 0 ▶ if(-e $parentFile) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $parentFile) 0 0 0
4742 0 system "rm $parentFile";
4743 }
4744 0 ▶ if(-e $configFile) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $configFile) 0 0 0
4745 0 system "rm $configFile";
4746 }
4747  
4748 }
4749  
4750 # checks to see if the cui is in the parent taxonomy
4751 # input : $concept <- string containing a cui
4752 # output: $bool <- indicating if the cui exists in
4753 # the upper level taxonamy
4754 sub _inParentTaxonomy {
4755  
4756 0 ▶ my $self = shift;
Subroutine _inParentTaxonomy: not called CC=6 SCAR=37.4
4757 0 my $concept = shift;
4758  
4759 0 my $function = "_inParentTaxonomy";
4760 0 &_debug($function);
4761  
4762 # check self
4763 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
4764 0 $errorhandler->_error($pkg, $function, "", 2);
4765 }
4766  
4767 # check parameter exists
4768 0 ▶ if(!defined $concept) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $concept) 0 0 0
4769 0 $errorhandler->_error($pkg, $function, "Error with input variable \$concept.", 4);
4770 }
4771  
4772 # check if valid concept
4773 0 ▶ if(! ($errorhandler->_validCui($concept)) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($errorhandler->_validCui($concept)) 0 0 0
4774 0 $errorhandler->_error($pkg, $function, "Concept ($concept) is not valid.", 6);
4775 }
4776  
4777 0 ▶ if(exists $parentTaxonomyArray{$concept}) { return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if (exists $parentTaxonomyArray{$concept}) { } 0 0 0
4778 0 else { return 0; }
4779 }
4780  
4781 # checks to see if the cui is in the child taxonomy
4782 # input : $concept <- string containing a cui
4783 # output: $bool <- indicating if the cui exists in
4784 # the upper level taxonamy
4785 sub _inChildTaxonomy {
4786  
4787 0 ▶ my $self = shift;
Subroutine _inChildTaxonomy: not called CC=6 SCAR=37.4
4788 0 my $concept = shift;
4789  
4790 0 my $function = "_inChildTaxonomy";
4791 0 &_debug($function);
4792  
4793 # check self
4794 0 ▶ if(!defined $self || !ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
4795 0 $errorhandler->_error($pkg, $function, "", 2);
4796 }
4797  
4798 # check parameter exists
4799 0 ▶ if(!defined $concept) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $concept) 0 0 0
4800 0 $errorhandler->_error($pkg, $function, "Error with input variable \$concept.", 4);
4801 }
4802  
4803 # check if valid concept
4804 0 ▶ if(! ($errorhandler->_validCui($concept)) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($errorhandler->_validCui($concept)) 0 0 0
4805 0 $errorhandler->_error($pkg, $function, "Concept ($concept) is not valid.", 6);
4806 }
4807  
4808 0 ▶ if(exists $childTaxonomyArray{$concept}) { return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if (exists $childTaxonomyArray{$concept}) { } 0 0 0
4809 0 else { return 0; }
4810 }
4811  
4812  
4813 # function to create a timestamp
4814 # input :
4815 # output: $string <- containing the time stamp
4816 sub _timeStamp {
4817  
4818 0 ▶ my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
Subroutine _timeStamp: not called CC=1 SCAR=6.9
4819  
4820 0 $year += 1900;
4821 0 $mon++;
4822 0 my $d = sprintf("%4d%2.2d%2.2d",$year,$mon,$mday);
4823 0 my $t = sprintf("%2.2d%2.2d%2.2d",$hour,$min,$sec);
4824  
4825 0 my $stamp = $d . $t;
4826  
4827 0 return $stamp;
4828 }
4829  
4830 # function to get the time
4831 # input :
4832 # output: $string <- containing the time
4833 sub _printTime {
4834 0 ▶ my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
Subroutine _printTime: not called CC=1 SCAR=6.9
4835  
4836 0 $year += 1900;
4837 0 $mon++;
4838  
4839 0 my $d = sprintf("%4d%2.2d%2.2d",$year,$mon,$mday);
4840 0 my $t = sprintf("%2.2d%2.2d%2.2d",$hour,$min,$sec);
4841  
4842 0 print STDERR "$t\n";
4843  
4844 }
4845  
4846 # return the file name containing the index table
4847 sub _getTableFile {
4848  
4849 0 ▶ return $tableFile;
Subroutine _getTableFile: not called CC=1 SCAR=6.9
4850 }
4851  
4852  
4853 # return the table name in the index - this is the hex
4854 sub _getTableName {
4855  
4856 0 ▶ return $tableName;
Subroutine _getTableName: not called CC=1 SCAR=6.9
4857 }
4858  
4859 # return the table name in the index in human form
4860 sub _getTableNameHuman {
4861  
4862 0 ▶ return $tableNameHuman;
Subroutine _getTableNameHuman: not called CC=1 SCAR=6.9
4863 }
4864  
4865 sub _getCacheTableName {
4866 0 ▶ return $cacheTable;
Subroutine _getCacheTableName: not called CC=1 SCAR=6.9
4867 }
4868  
4869 sub _getCacheTableNameHuman{
4870 0 ▶ return $cacheTableHuman;
Subroutine _getCacheTableNameHuman: not called CC=1 SCAR=6.9
4871 }
4872  
4873 sub _getInfoTableName {
4874 0 ▶ return $infoTable;
Subroutine _getInfoTableName: not called CC=1 SCAR=6.9
4875 }
4876  
4877 sub _getInfoTableNameHuman {
4878 0 ▶ return $infoTableHuman;
Subroutine _getInfoTableNameHuman: not called CC=1 SCAR=6.9
4879 }
4880  
4881 sub _getIntrinsicTableName {
4882 0 ▶ return $intrinsicTable;
Subroutine _getIntrinsicTableName: not called CC=1 SCAR=6.9
4883 }
4884  
4885 sub _getIntrinsicTableNameHuman {
4886 0 ▶ return $intrinsicTableHuman;
Subroutine _getIntrinsicTableNameHuman: not called CC=1 SCAR=6.9
4887 }
4888  
4889 58 1;
4890  
4891  
4892  
4893  
4894 __END__
« blib/lib/UMLS/Interface/PathFinder.pm ↑ Summary blib/lib/UMLS/Interface/STFinder.pm »