utils/findLeastCommonSubsumer.pl

filter: Statementstmt 11.5% 18 / 156 Branchbran 7.3% 5 / 68 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 66.6% 4 / 6 Podpod n/a totaltotal 11.4% 27 / 235 SCAR 5.5
CC
1
Cov
10%
showHelp
2.0
showVersion
2.0
BEGIN
1.0
CRAP 1.7
« blib/script/removeConfigData.pl ↑ Summary utils/getCuiList.pl »
1 #!/usr/bin/perl
2  
3 =head1 NAME
4  
5 findLeastCommonSubsumer.pl - This program finds the least common subsumer
6 between two concepts.
7  
8 =head1 SYNOPSIS
9  
10 This program takes two terms or CUIs and returns the least common
11 subsumer between them.
12  
13 =head1 USAGE
14  
15 Usage: findLeastCommonSubsumer.pl [OPTIONS] [CUI1|TERM1] [CUI2|TERM2]
16  
17 =head1 INPUT
18  
19 =head2 Required Arguments:
20  
21 =head3 [CUI1|TERM1] [CUI2|TERM2]
22  
23 A TERM or CUI (or some combination) from the Unified
24 Medical Language System
25  
26 =head2 Optional Arguments:
27  
28 =head3 --config FILE
29  
30 This is the configuration file. The format of the configuration
31 file is as follows:
32  
33 SAB :: <include|exclude> <source1, source2, ... sourceN>
34  
35 REL :: <include|exclude> <relation1, relation2, ... relationN>
36  
37 RELA :: <include|exclude> <rela1, rela2, ... relaN> (optional)
38  
39 For example, if we wanted to use the MSH vocabulary with only
40 the RB/RN relations, the configuration file would be:
41  
42 SAB :: include MSH
43 REL :: include RB, RN
44 RELA :: include inverse_isa, isa
45  
46 or
47  
48 SAB :: include MSH
49 REL :: exclude PAR, CHD
50  
51 If you go to the configuration file directory, there will
52 be example configuration files for the different runs that
53 you have performed.
54  
55 =head3 --depth
56  
57 The minimum and maximum depth of the least common subsummer
58  
59 =head3 --propagation
60  
61 The Information Content of the least common subsumer
62  
63 =head3 --infile
64  
65 A file containing pairs of concepts or terms in the following format:
66  
67 term1<>term2
68
69 or
70  
71 cui1<>cui2
72
73 or
74
75 cui1<>term2
76  
77 or
78  
79 term1<>cui2
80  
81 =head3 --debug
82  
83 Sets the debug flag for testing
84  
85 =head3 --username STRING
86  
87 Username is required to access the umls database on MySql
88 unless it was specified in the my.cnf file at installation
89  
90 =head3 --password STRING
91  
92 Password is required to access the umls database on MySql
93 unless it was specified in the my.cnf file at installation
94  
95 =head3 --hostname STRING
96  
97 Hostname where mysql is located. DEFAULT: localhost
98  
99 =head3 --socket STRING
100  
101 The socket your mysql is using. DEFAULT: /tmp/mysql.sock
102  
103 =head3 --database STRING
104  
105 Database contain UMLS DEFAULT: umls
106  
107 =head3 --realtime
108  
109 This option will not create a database of the path information
110 for all of concepts in the specified set of sources and relations
111 in the config file but obtain the information for just the
112 input concept
113  
114 =head3 --forcerun
115  
116 This option will bypass any command prompts such as asking
117 if you would like to continue with the index creation.
118  
119 =head3 --debugpath FILE
120  
121 This option prints out the path information for debugging
122 purposes. This option is only really available with the
123 --reatime option because otherwise the path information is
124 stored in the database. You can get this information in a
125 file if you use the --verbose option while creating the index.
126  
127 =head3 --verbose
128  
129 This option will print out the table information to the
130 config file that you specified.
131  
132 =head3 --cuilist FILE
133  
134 This option takes in a file containing a list of CUIs (one CUI
135 per line) and stores only the path information for those CUIs
136 rather than for all of the CUIs given the specified set of
137 sources and relations
138  
139 =head3 --help
140  
141 Displays the quick summary of program options.
142  
143 =head3 --version
144  
145 Displays the version information.
146  
147 =head1 OUTPUT
148  
149 List of CUIs that are associated with the input term
150  
151 =head1 SYSTEM REQUIREMENTS
152  
153 =over
154  
155 =item * Perl (version 5.8.5 or better) - http://www.perl.org
156  
157 =back
158  
159 =head1 AUTHOR
160  
161 Bridget T. McInnes, University of Minnesota
162  
163 =head1 COPYRIGHT
164  
165 Copyright (c) 2007-2009,
166  
167 Bridget T. McInnes, University of Minnesota
168 bthomson at cs.umn.edu
169
170 Ted Pedersen, University of Minnesota Duluth
171 tpederse at d.umn.edu
172  
173 Siddharth Patwardhan, University of Utah, Salt Lake City
174 sidd@cs.utah.edu
175
176 Serguei Pakhomov, University of Minnesota Twin Cities
177 pakh0002@umn.edu
178  
179 This program is free software; you can redistribute it and/or modify it under
180 the terms of the GNU General Public License as published by the Free Software
181 Foundation; either version 2 of the License, or (at your option) any later
182 version.
183  
184 This program is distributed in the hope that it will be useful, but WITHOUT
185 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
186 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
187  
188 You should have received a copy of the GNU General Public License along with
189 this program; if not, write to:
190  
191 The Free Software Foundation, Inc.,
192 59 Temple Place - Suite 330,
193 Boston, MA 02111-1307, USA.
194  
195 =cut
196  
197 ###############################################################################
198  
199 # THE CODE STARTS HERE
200 ###############################################################################
201  
202 # ================================
203 # COMMAND LINE OPTIONS AND USAGE
204 # ================================
205  
206  
207 2 ▶use UMLS::Interface;
Subroutine BEGIN: called CC=1 SCAR=0.0
208 2 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
209  
210 2 ▶eval(GetOptions( "version", "help", "debug", "username=s", "password=s", "hostname=s", "database=s", "socket=s", "config=s", "forcerun", "verbose", "debugpath=s", "cuilist=s", "realtime", "infile=s", "depth", "propagation=s")) or die ("Please check the above mentioned option(s).\n");
Branch: 1 branch
BranchTrueFalseTotal
eval &GetOptions("version", "help", "debug", "username=s", "password=s", "hostname=s", "database=s", "socket=s", "config=s", "forcerun", "verbose", "debugpath=s", "cuilist=s", "realtime", "infile=s", "depth", "propagation=s") or die "Please check the above mentioned option(s).\n" 0 2 2
211  
212  
213 # if help is defined, print out help
214 2 ▶if( defined $opt_help ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_help) 0 2 2
215 0 $opt_help = 1;
216 0 &showHelp();
217 0 exit;
218 }
219  
220 # if version is requested, show version
221 2 ▶if( defined $opt_version ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_version) 0 2 2
222 0 $opt_version = 1;
223 0 &showVersion();
224 0 exit;
225 }
226  
227 2 my @fileArray = ();
228 2 ▶if(defined $opt_infile) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_infile) { } 0 2 2
229 0 ▶ open(FILE, $opt_infile) || die "Could not open infile: $opt_infile\n";
Branch: 1 branch
BranchTrueFalseTotal
open FILE, $opt_infile or die "Could not open infile: $opt_infile\n" 0 0 0
230 0 ▶ while(<FILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline FILE)) 0 0 0
231 0 chomp;
232 0 ▶ if($_=~/^\s*$/) { next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^\s*$/) 0 0 0
233 0 push @fileArray, $_;
234 }
235 0 close FILE;
236 }
237 else {
238 # At least 2 terms and/or cuis should be given on the command line.
239 2 ▶ if( scalar(@ARGV) < 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @ARGV < 2) 2 0 2
240 2 print STDERR "Two terms and/or CUIs are required\n";
241 2 &minimalUsageNotes();
242 0 exit;
243 }
244
245 0 my $i1 = shift;
246 0 my $i2 = shift;
247
248 0 my $string = "$i1<>$i2";
249 0 push @fileArray, $string;
250 }
251  
252 0 my $umls = "";
253  
254 0 my $precision = 4;
255 0 my $floatformat = join '', '%', '.', $precision, 'f';
256  
257 0 my %option_hash = ();
258  
259 #$option_hash{"debug"} = 1;
260  
261 0 ▶if(defined $opt_propagation) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_propagation) 0 0 0
262 0 $option_hash{"propagation"} = $opt_propagation;
263 }
264 0 ▶if(defined $opt_debug) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_debug) 0 0 0
265 0 $option_hash{"debug"} = $opt_debug;
266 }
267 0 ▶if(defined $opt_realtime) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_realtime) 0 0 0
268 0 $option_hash{"realtime"} = $opt_realtime;
269 }
270 0 ▶if(defined $opt_config) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_config) 0 0 0
271 0 $option_hash{"config"} = $opt_config;
272 }
273 0 ▶if(defined $opt_forcerun) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_forcerun) 0 0 0
274 0 $option_hash{"forcerun"} = $opt_forcerun;
275 }
276 0 ▶if(defined $opt_verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_verbose) 0 0 0
277 0 $option_hash{"verbose"} = $opt_verbose;
278 }
279 0 ▶if(defined $opt_debugpath) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_debugpath) 0 0 0
280 0 $option_hash{"debugpath"} = $opt_debugpath;
281 }
282 0 ▶if(defined $opt_cuilist) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_cuilist) 0 0 0
283 0 $option_hash{"cuilist"} = $opt_cuilist;
284 }
285 0 ▶if(defined $opt_username) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_username) 0 0 0
286 0 $option_hash{"username"} = $opt_username;
287 }
288 0 ▶if(defined $opt_driver) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_driver) 0 0 0
289 0 $option_hash{"driver"} = $opt_driver;
290 }
291 0 ▶if(defined $opt_database) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_database) 0 0 0
292 0 $option_hash{"database"} = $opt_database;
293 }
294 0 ▶if(defined $opt_password) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_password) 0 0 0
295 0 $option_hash{"password"} = $opt_password;
296 }
297 0 ▶if(defined $opt_hostname) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_hostname) 0 0 0
298 0 $option_hash{"hostname"} = $opt_hostname;
299 }
300 0 ▶if(defined $opt_socket) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_socket) 0 0 0
301 0 $option_hash{"socket"} = $opt_socket;
302 }
303  
304  
305 0 $umls = UMLS::Interface->new(\%option_hash);
306 0 ▶die "Unable to create UMLS::Interface object.\n" if(!$umls);
Branch: 1 branch
BranchTrueFalseTotal
unless $umls 0 0 0
307  
308 0 foreach my $element (@fileArray) {
309
310 0 my ($input1, $input2) = split/<>/, $element;
311
312 0 my $c1; my $c2;
313  
314 # check if the input are CUIs or terms
315 0 ▶ if( ($input1=~/C[0-9]+/)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input1 =~ /C[0-9]+/) { } 0 0 0
316 0 push @{$c1}, $input1;
317 }
318 else {
319 0 $c1 = $umls->getConceptList($input1);
320 }
321 0 ▶ if( ($input2=~/C[0-9]+/)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input2 =~ /C[0-9]+/) { } 0 0 0
322 0 push @{$c2}, $input2;
323 }
324 else {
325 0 $c2 = $umls->getConceptList($input2);
326 }
327
328 0 my $printFlag = 0;
329
330 0 foreach $cui1 (@{$c1}) {
331 0 foreach $cui2 (@{$c2}) {
332  
333 0 my $t1 = $input1;
334 0 my $t2 = $input2;
335
336 0 ▶ if($t1=~/C[0-9]+/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t1 =~ /C[0-9]+/) 0 0 0
337 0 ($t1) = $umls->getAllPreferredTerm($cui1);
338 }
339
340 0 ▶ if($t2=~/C[0-9]+/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t2 =~ /C[0-9]+/) 0 0 0
341 0 ($t2) = $umls->getAllPreferredTerm($cui2);
342 }
343  
344 0 ▶ if(($umls->exists($cui1) == 0) or
Branch: 1 branch
BranchTrueFalseTotal
if ($umls->exists($cui1) == 0 or $umls->exists($cui2) == 0) 0 0 0
Condition0%0/3
$umls->exists($cui1) == 0 or $umls->exists($cui2) == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$umls->exists($cui1) == 0 or $umls->exists($cui2) == 0
$umls->exists($cui1) == 0 $umls->exists($cui2) == 0
Truth table0%0/3
A or B
A= $umls->exists($cui1) == 0B= $umls->exists($cui2) == 0
ABresult
1X1
011
000
345 0 ($umls->exists($cui2) == 0) ) { next; }
346
347 0 ▶ if($cui1 eq $cui2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cui1 eq $cui2) 0 0 0
348 0 print "\nThe least common subsumer between $t1 ($cui1) and $t2 ($cui2) is $t1 ($cui1) ";
349 0 ▶ if(defined $opt_depth) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_depth) 0 0 0
350 0 my $min = $umls->findMinimumDepth($cui1);
351 0 my $max = $umls->findMaximumDepth($cui1);
352 0 print "with a min and max depth of $min and $max ";
353 }
354 0 ▶ if(defined $opt_propagation) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_propagation) 0 0 0
355 0 my $ic = sprintf $floatformat, $umls->getIC($cui1);
356 0 print "with an IC of $ic ";
357 }
358 0 print "\n";
359
360 0 $printFlag = 1;
361 0 next;
362 }
363
364
365 0 my $lcses = $umls->findLeastCommonSubsumer($cui1, $cui2);
366
367 0 foreach my $lcs (@{$lcses}) {
368
369 0 my ($t) = $umls->getAllPreferredTerm($lcs);
370
371 0 print "\nThe least common subsumer between $t1 ($cui1) and $t2 ($cui2) is $t ($lcs) ";
372 0 ▶ if(defined $opt_depth) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_depth) 0 0 0
373 0 my $min = $umls->findMinimumDepth($lcs);
374 0 my $max = $umls->findMaximumDepth($lcs);
375 0 print "with a min and max depth of $min and $max ";
376 }
377 0 ▶ if(defined $opt_propagation) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_propagation) 0 0 0
378 0 my $ic = sprintf $floatformat, $umls->getIC($lcs);
379 0 print "with an IC of $ic ";
380 }
381 0 print "\n";
382
383 0 $printFlag = 1;
384 }
385 }
386 }
387 0 ▶ if( !($printFlag) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($printFlag) 0 0 0
388 0 print "\n";
389 0 print "There is not a least common subsumer between $input1 and $input2 given the current view of the UMLS.\n\n";
390 }
391 }
392  
393 ##############################################################################
394 # function to output minimal usage notes
395 ##############################################################################
396 sub minimalUsageNotes {
397
398 2 ▶ print "Usage: findLeastCommonSubsumer.pl [OPTIONS] [CUI1|TERM1] [CUI2|TERM2]\n";
Subroutine minimalUsageNotes: called CC=1 SCAR=0.0
399 2 &askHelp();
400 2 exit;
401 }
402  
403 ##############################################################################
404 # function to output help messages for this program
405 ##############################################################################
406 sub showHelp() {
407  
408
409 0 ▶ print "This is a utility that takes as input two Terms or CUIs\n";
Subroutine showHelp: not called CC=1 SCAR=6.9
410 0 print "and returns the Least Common Subsumer between the two.\n\n";
411
412 0 print "Usage: findLeastCommonSubsumer.pl [OPTIONS] [CUI1|TERM1] [CUI2|TERM2]\n\n";
413  
414 0 print "Options:\n\n";
415  
416 0 print "--infile FILE File containing TERM or CUI pairs\n\n";
417  
418 0 print "--depth Outputs the depth of the lcs\n\n";
419  
420 0 print "--propagation FILE Outputs the IC of the lcs\n\n";
421  
422 0 print "--debug Sets the debug flag for testing.\n\n";
423  
424 0 print "--username STRING Username required to access mysql\n\n";
425  
426 0 print "--password STRING Password required to access mysql\n\n";
427  
428 0 print "--hostname STRING Hostname for mysql (DEFAULT: localhost)\n\n";
429  
430 0 print "--database STRING Database contain UMLS (DEFAULT: umls)\n\n";
431
432 0 print "--socket STRING Socket used by mysql (DEFAULT: /tmp.mysql.sock)\n\n";
433  
434 0 print "--config FILE Configuration file\n\n";
435  
436  
437 0 print "--realtime This option will not create a database of the\n";
438 0 print " path information for all of concepts but just\n";
439 0 print " obtain the information for the input concept\n\n";
440  
441  
442 0 print "--forcerun This option will bypass any command \n";
443 0 print " prompts such as asking if you would \n";
444 0 print " like to continue with the index \n";
445 0 print " creation. \n\n";
446  
447 0 print "--debugpath FILE This option prints out the path\n";
448 0 print " information for debugging purposes\n\n";
449  
450 0 print "--verbose This option prints out table information\n";
451 0 print " to a directory in your config directory.\n\n";
452 0 print "--cuilist FILE This option takes in a file containing a \n";
453 0 print " list of CUIs (one CUI per line) and stores\n";
454 0 print " only the path information for those CUIs\n";
455 0 print " rather than for all of the CUIs\n\n";
456  
457 0 print "--version Prints the version number\n\n";
458
459 0 print "--help Prints this help message.\n\n";
460 }
461  
462 ##############################################################################
463 # function to output the version number
464 ##############################################################################
465 sub showVersion {
466 0 ▶ print '$Id: findLeastCommonSubsumer.pl,v 1.21 2011/08/29 16:37:03 btmcinnes Exp $';
Subroutine showVersion: not called CC=1 SCAR=6.9
467 0 print "\nCopyright (c) 2008, Ted Pedersen & Bridget McInnes\n";
468 }
469  
470 ##############################################################################
471 # function to output "ask for help" message when user's goofed
472 ##############################################################################
473 sub askHelp {
474 2 ▶ print STDERR "Type findLeastCommonSubsumer.pl --help for help.\n";
Subroutine askHelp: called CC=1 SCAR=0.0
475 }
476
« blib/script/removeConfigData.pl ↑ Summary utils/getCuiList.pl »