| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | findCuiDepth.pl - This program returns the minimum and maximum depth | ||
| 6 | of a given CUI or term. | ||
| 7 | |||
| 8 | =head1 SYNOPSIS | ||
| 9 | |||
| 10 | This program takes in a CUI or a term and returns its minimum and | ||
| 11 | maximum depth. | ||
| 12 | |||
| 13 | =head1 USAGE | ||
| 14 | |||
| 15 | Usage: findCuiDepth.pl [OPTIONS] [TERM|CUI] | ||
| 16 | |||
| 17 | =head1 INPUT | ||
| 18 | |||
| 19 | =head2 Required Arguments: | ||
| 20 | |||
| 21 | =head3 [TERM|CUI] | ||
| 22 | |||
| 23 | Concept Unique Identifier (CUI) or a term from the Unified | ||
| 24 | Medical Language System (UMLS) | ||
| 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 isa, inverse_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 --debug | ||
| 56 | |||
| 57 | This sets the debug flag for testing | ||
| 58 | |||
| 59 | =head3 --infile FILE | ||
| 60 | |||
| 61 | This option takes a list of CUIs or TERMs and returns their | ||
| 62 | depth. Note one CUI or TERM per line is the expected format. | ||
| 63 | |||
| 64 | =head3 --minimum | ||
| 65 | |||
| 66 | Finds just the minimum CUI depth | ||
| 67 | |||
| 68 | =head3 --maximum | ||
| 69 | |||
| 70 | Finds just the maximum CUI depth | ||
| 71 | |||
| 72 | =head3 --username STRING | ||
| 73 | |||
| 74 | Username is required to access the umls database on MySql | ||
| 75 | unless it was specified in the my.cnf file at installation | ||
| 76 | |||
| 77 | =head3 --password STRING | ||
| 78 | |||
| 79 | Password is required to access the umls database on MySql | ||
| 80 | unless it was specified in the my.cnf file at installation | ||
| 81 | |||
| 82 | =head3 --hostname STRING | ||
| 83 | |||
| 84 | Hostname where mysql is located. DEFAULT: localhost | ||
| 85 | |||
| 86 | =head3 --socket STRING | ||
| 87 | |||
| 88 | The socket your mysql is using. DEFAULT: /tmp/mysql.sock | ||
| 89 | |||
| 90 | =head3 --database STRING | ||
| 91 | |||
| 92 | Database contain UMLS DEFAULT: umls | ||
| 93 | |||
| 94 | =head3 --realtime | ||
| 95 | |||
| 96 | This option will not create a database of the path information | ||
| 97 | for all of concepts in the specified set of sources and relations | ||
| 98 | in the config file but obtain the information for just the | ||
| 99 | input concept | ||
| 100 | |||
| 101 | =head3 --forcerun | ||
| 102 | |||
| 103 | This option will bypass any command prompts such as asking | ||
| 104 | if you would like to continue with the index creation. | ||
| 105 | |||
| 106 | =head3 --verbose | ||
| 107 | |||
| 108 | This option will print out the table information to the | ||
| 109 | config file that you specified. | ||
| 110 | |||
| 111 | =head3 --debugpath FILE | ||
| 112 | |||
| 113 | This option prints out the path information for debugging | ||
| 114 | purposes. This option is only really available with the | ||
| 115 | --reatime option because otherwise the path information is | ||
| 116 | stored in the database. You can get this information in a | ||
| 117 | file if you use the --verbose option while creating the index. | ||
| 118 | |||
| 119 | =head3 --cuilist FILE | ||
| 120 | |||
| 121 | This option takes in a file containing a list of CUIs (one CUI | ||
| 122 | per line) and stores only the path information for those CUIs | ||
| 123 | rather than for all of the CUIs given the specified set of | ||
| 124 | sources and relations | ||
| 125 | |||
| 126 | =head3 --help | ||
| 127 | |||
| 128 | Displays the quick summary of program options. | ||
| 129 | |||
| 130 | =head3 --version | ||
| 131 | |||
| 132 | Displays the version information. | ||
| 133 | |||
| 134 | =head1 OUTPUT | ||
| 135 | |||
| 136 | The minimum depth of a given CUI or term | ||
| 137 | |||
| 138 | =head1 CONFIGURATION FILE | ||
| 139 | |||
| 140 | There exist a configuration files to specify which source and what | ||
| 141 | relations are to be used. The default source is the Medical Subject | ||
| 142 | Heading (MSH) vocabulary and the default relations are the PAR/CHD | ||
| 143 | relation. | ||
| 144 | |||
| 145 | The format of the configuration file is as follows: | ||
| 146 | |||
| 147 | SAB :: <include|exclude> <source1, source2, ... sourceN> | ||
| 148 | |||
| 149 | REL :: <include|exclude> <relation1, relation2, ... relationN> | ||
| 150 | |||
| 151 | The SAB and REL are for specifing what sources and relations | ||
| 152 | should be used when traversing the UMLS. For example, if we | ||
| 153 | wanted to use the MSH vocabulary with only the RB/RN relations, | ||
| 154 | the configuration file would be: | ||
| 155 | |||
| 156 | SAB :: include MSH | ||
| 157 | REL :: include RB, RN | ||
| 158 | |||
| 159 | or if we wanted to use MSH and use any relation except for PAR/CHD, | ||
| 160 | the configuration would be: | ||
| 161 | |||
| 162 | SAB :: include MSH | ||
| 163 | REL :: exclude PAR, CHD | ||
| 164 | |||
| 165 | An example of the configuration file can be seen in the samples/ directory. | ||
| 166 | |||
| 167 | =head1 SYSTEM REQUIREMENTS | ||
| 168 | |||
| 169 | =over | ||
| 170 | |||
| 171 | =item * Perl (version 5.8.5 or better) - http://www.perl.org | ||
| 172 | |||
| 173 | =back | ||
| 174 | |||
| 175 | =head1 AUTHOR | ||
| 176 | |||
| 177 | Bridget T. McInnes, University of Minnesota | ||
| 178 | |||
| 179 | =head1 COPYRIGHT | ||
| 180 | |||
| 181 | Copyright (c) 2007-2009, | ||
| 182 | |||
| 183 | Bridget T. McInnes, University of Minnesota | ||
| 184 | bthomson at cs.umn.edu | ||
| 185 | |||
| 186 | Ted Pedersen, University of Minnesota Duluth | ||
| 187 | tpederse at d.umn.edu | ||
| 188 | |||
| 189 | Siddharth Patwardhan, University of Utah, Salt Lake City | ||
| 190 | sidd@cs.utah.edu | ||
| 191 | |||
| 192 | Serguei Pakhomov, University of Minnesota Twin Cities | ||
| 193 | pakh0002@umn.edu | ||
| 194 | |||
| 195 | This program is free software; you can redistribute it and/or modify it under | ||
| 196 | the terms of the GNU General Public License as published by the Free Software | ||
| 197 | Foundation; either version 2 of the License, or (at your option) any later | ||
| 198 | version. | ||
| 199 | |||
| 200 | This program is distributed in the hope that it will be useful, but WITHOUT | ||
| 201 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 202 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
| 203 | |||
| 204 | You should have received a copy of the GNU General Public License along with | ||
| 205 | this program; if not, write to: | ||
| 206 | |||
| 207 | The Free Software Foundation, Inc., | ||
| 208 | 59 Temple Place - Suite 330, | ||
| 209 | Boston, MA 02111-1307, USA. | ||
| 210 | |||
| 211 | =cut | ||
| 212 | |||
| 213 | ############################################################################### | ||
| 214 | |||
| 215 | # THE CODE STARTS HERE | ||
| 216 | ############################################################################### | ||
| 217 | |||
| 218 | # ================================ | ||
| 219 | # COMMAND LINE OPTIONS AND USAGE | ||
| 220 | # ================================ | ||
| 221 | |||
| 222 | |||
| 223 | use UMLS::Interface; | ||
| 224 | use Getopt::Long; | ||
| 225 | # catch, abort and print the message for unknown options specified | ||
| 226 | eval(GetOptions( "version", "help", "username=s", "password=s", "hostname=s", "database=s", "socket=s", "config=s", "forcerun", "debug", "verbose", "debugpath=s", "cuilist=s", "realtime", "minimum", "maximum", "infile=s")) or die ("Please check the above mentioned option(s).\n"); | ||
| 227 | |||
| 228 | |||
| 229 | # if help is defined, print out help | ||
| 230 | if( defined $opt_help ) { | ||
| 231 | $opt_help = 1; | ||
| 232 | &showHelp(); | ||
| 233 | exit; | ||
| 234 | } | ||
| 235 | |||
| 236 | # if version is requested, show version | ||
| 237 | if( defined $opt_version ) { | ||
| 238 | $opt_version = 1; | ||
| 239 | &showVersion(); | ||
| 240 | exit; | ||
| 241 | } | ||
| 242 | |||
| 243 | # At least 1 CUI should be given on the command line. | ||
| 244 | if( (!defined $opt_infile) and (scalar(@ARGV) < 1) ) { | ||
| 245 | print STDERR "No term was specified on the command line\n"; | ||
| 246 | &minimalUsageNotes(); | ||
| 247 | exit; | ||
| 248 | } | ||
| 249 | |||
| 250 | my $umls = ""; | ||
| 251 | |||
| 252 | my %option_hash = (); | ||
| 253 | |||
| 254 | if(defined $opt_realtime) { | ||
| 255 | $option_hash{"realtime"} = $opt_realtime; | ||
| 256 | } | ||
| 257 | if(defined $opt_config) { | ||
| 258 | $option_hash{"config"} = $opt_config; | ||
| 259 | } | ||
| 260 | if(defined $opt_forcerun) { | ||
| 261 | $option_hash{"forcerun"} = $opt_forcerun; | ||
| 262 | } | ||
| 263 | if(defined $opt_debug) { | ||
| 264 | $option_hash{"debug"} = $opt_debug; | ||
| 265 | } | ||
| 266 | if(defined $opt_verbose) { | ||
| 267 | $option_hash{"verbose"} = $opt_verbose; | ||
| 268 | } | ||
| 269 | if(defined $opt_debugpath) { | ||
| 270 | $option_hash{"debugpath"} = $opt_debugpath; | ||
| 271 | } | ||
| 272 | if(defined $opt_cuilist) { | ||
| 273 | $option_hash{"cuilist"} = $opt_cuilist; | ||
| 274 | } | ||
| 275 | if(defined $opt_username) { | ||
| 276 | $option_hash{"username"} = $opt_username; | ||
| 277 | } | ||
| 278 | if(defined $opt_driver) { | ||
| 279 | $option_hash{"driver"} = $opt_driver; #"mysql"; | ||
| 280 | } | ||
| 281 | if(defined $opt_database) { | ||
| 282 | $option_hash{"database"} = $opt_database; | ||
| 283 | } | ||
| 284 | if(defined $opt_password) { | ||
| 285 | $option_hash{"password"} = $opt_password; | ||
| 286 | } | ||
| 287 | if(defined $opt_hostname) { | ||
| 288 | $option_hash{"hostname"} = $opt_hostname; | ||
| 289 | } | ||
| 290 | if(defined $opt_socket) { | ||
| 291 | $option_hash{"socket"} = $opt_socket; | ||
| 292 | } | ||
| 293 | |||
| 294 | $umls = UMLS::Interface->new(\%option_hash); | ||
| 295 | die "Unable to create UMLS::Interface object.\n" if(!$umls); | ||
| 296 | |||
| 297 | # get the relations from the configuration file | ||
| 298 | my $configrel = $umls->getRelString(); | ||
| 299 | $configrel=~/(REL) (\:\:) (include|exclude) (.*?)$/; | ||
| 300 | my $relationstring = $4; | ||
| 301 | |||
| 302 | # check to make certain the configuration file only contains | ||
| 303 | # heirarchical relations (PAR/CHD or RB/RN). | ||
| 304 | my @relations = split/\s*\,\s*/, $relationstring; | ||
| 305 | foreach my $rel (@relations) { | ||
| 306 | if(! ($rel=~/(PAR|CHD|RB|RN)/) ) { | ||
| 307 | print STDERR "The findCuiDepth.pl program only supports heirarchical relations (PAR/CHD or RB/RN).\n"; | ||
| 308 | &minimalUsageNotes(); | ||
| 309 | exit; | ||
| 310 | } | ||
| 311 | } | ||
| 312 | |||
| 313 | my @inputarray = (); | ||
| 314 | |||
| 315 | if(defined $opt_infile) { | ||
| 316 | open(FILE, $opt_infile) || die "Could not open infile : $opt_infile\n"; | ||
| 317 | while(<FILE>) { | ||
| 318 | chomp; | ||
| 319 | $_=~s/^\s+//g; | ||
| 320 | $_=~s/\s+$//g; | ||
| 321 | push @inputarray, $_; | ||
| 322 | } | ||
| 323 | } | ||
| 324 | else { | ||
| 325 | my $input = shift; | ||
| 326 | push @inputarray, $input; | ||
| 327 | } | ||
| 328 | |||
| 329 | foreach my $input (@inputarray) { | ||
| 330 | |||
| 331 | if($input=~/^\s*$/) { next; } | ||
| 332 | |||
| 333 | my $term = $input; | ||
| 334 | |||
| 335 | my @c = (); | ||
| 336 | if($input=~/C[0-9]+/) { | ||
| 337 | push @{$c}, $input; | ||
| 338 | my $termlist = $umls->getTermList($input); | ||
| 339 | $term = shift @{$termlist}; | ||
| 340 | } | ||
| 341 | else { | ||
| 342 | $c = $umls->getConceptList($input); | ||
| 343 | } | ||
| 344 | |||
| 345 | my $printFlag = 0; | ||
| 346 | |||
| 347 | foreach my $cui (@{$c}) { | ||
| 348 | |||
| 349 | # make certain cui exists in this view | ||
| 350 | if(! ($umls->exists($cui)) ) { | ||
| 351 | next; | ||
| 352 | } | ||
| 353 | |||
| 354 | # get the minimum depth | ||
| 355 | if(defined $opt_minimum) { | ||
| 356 | my $min = $umls->findMinimumDepth($cui); | ||
| 357 | print "The minimum depth of $term ($cui) is $min\n"; | ||
| 358 | } | ||
| 359 | # get the maximum depth | ||
| 360 | elsif(defined $opt_maximum) { | ||
| 361 | my $max = $umls->findMaximumDepth($cui); | ||
| 362 | print "The maximum depth of $term ($cui) is $max\n"; | ||
| 363 | } | ||
| 364 | else { | ||
| 365 | my $min = $umls->findMinimumDepth($cui); | ||
| 366 | print "The minimum depth of $term ($cui) is $min\n"; | ||
| 367 | |||
| 368 | my $max = $umls->findMaximumDepth($cui); | ||
| 369 | print "The maximum depth of $term ($cui) is $max\n"; | ||
| 370 | } | ||
| 371 | |||
| 372 | $printFlag = 1; | ||
| 373 | } | ||
| 374 | |||
| 375 | if(! ($printFlag) ) { | ||
| 376 | print "$input does not exist in this view of the UMLS.\n"; | ||
| 377 | } | ||
| 378 | } | ||
| 379 | |||
| 380 | ############################################################################## | ||
| 381 | # function to output minimal usage notes | ||
| 382 | ############################################################################## | ||
| 383 | sub minimalUsageNotes { | ||
| 384 | |||
| 385 | print "Usage: findCuiDepth.pl [OPTIONS] [TERM|CUI] \n"; | ||
| 386 | &askHelp(); | ||
| 387 | exit; | ||
| 388 | } | ||
| 389 | |||
| 390 | ############################################################################## | ||
| 391 | # function to output help messages for this program | ||
| 392 | ############################################################################## | ||
| 393 | sub showHelp() { | ||
| 394 | |||
| 395 | |||
| 396 | print "This is a utility that takes as input a CUI or a TERM\n"; | ||
| 397 | print "and returns its minimum depth.\n\n"; | ||
| 398 | |||
| 399 | print "Usage: findCuiDepth.pl [OPTIONS] [TERM|CUI]\n\n"; | ||
| 400 | |||
| 401 | print "Options:\n\n"; | ||
| 402 | |||
| 403 | print "--debug This option prints out the debug\n"; | ||
| 404 | print " information.\n\n"; | ||
| 405 | |||
| 406 | print "--infile This option takes a list of CUIs or\n"; | ||
| 407 | print " TERMS and returns their depth. \n\n"; | ||
| 408 | |||
| 409 | print "--minimum Returns the minimum depth (DEFAULT)\n\n"; | ||
| 410 | |||
| 411 | print "--maximum Returns the maximum depth\n\n"; | ||
| 412 | |||
| 413 | print "--username STRING Username required to access mysql\n\n"; | ||
| 414 | |||
| 415 | print "--password STRING Password required to access mysql\n\n"; | ||
| 416 | |||
| 417 | print "--hostname STRING Hostname for mysql (DEFAULT: localhost)\n\n"; | ||
| 418 | |||
| 419 | print "--database STRING Database contain UMLS (DEFAULT: umls)\n\n"; | ||
| 420 | |||
| 421 | print "--socket STRING Socket used by mysql (DEFAULT: /tmp.mysql.sock)\n\n"; | ||
| 422 | |||
| 423 | print "--config FILE Configuration file\n\n"; | ||
| 424 | |||
| 425 | print "--realtime This option will not create a database of the\n"; | ||
| 426 | print " path information for all of concepts but just\n"; | ||
| 427 | print " obtain the information for the input concept\n\n"; | ||
| 428 | |||
| 429 | print "--debug Sets the debug flag for testing.\n\n"; | ||
| 430 | |||
| 431 | print "--forcerun This option will bypass any command \n"; | ||
| 432 | print " prompts such as asking if you would \n"; | ||
| 433 | print " like to continue with the index \n"; | ||
| 434 | print " creation. \n\n"; | ||
| 435 | |||
| 436 | print "--debugpath FILE This option prints out the path\n"; | ||
| 437 | print " information for debugging purposes\n\n"; | ||
| 438 | |||
| 439 | print "--verbose This option prints out the table \n"; | ||
| 440 | print " information to a file in your\n"; | ||
| 441 | print " specified config directory\n\n"; | ||
| 442 | |||
| 443 | print "--cuilist FILE This option takes in a file containing a \n"; | ||
| 444 | print " list of CUIs (one CUI per line) and stores\n"; | ||
| 445 | print " only the path information for those CUIs\n"; | ||
| 446 | print " rather than for all of the CUIs\n\n"; | ||
| 447 | |||
| 448 | print "--version Prints the version number\n\n"; | ||
| 449 | |||
| 450 | print "--help Prints this help message.\n\n"; | ||
| 451 | } | ||
| 452 | |||
| 453 | ############################################################################## | ||
| 454 | # function to output the version number | ||
| 455 | ############################################################################## | ||
| 456 | sub showVersion { | ||
| 457 | print '$Id: findCuiDepth.pl,v 1.16 2011/08/29 16:37:03 btmcinnes Exp $'; | ||
| 458 | print "\nCopyright (c) 2008, Ted Pedersen & Bridget McInnes\n"; | ||
| 459 | } | ||
| 460 | |||
| 461 | ############################################################################## | ||
| 462 | # function to output "ask for help" message when user's goofed | ||
| 463 | ############################################################################## | ||
| 464 | sub askHelp { | ||
| 465 | print STDERR "Type findCuiDepth.pl --help for help.\n"; | ||
| 466 | } | ||
| 467 |