| 1 | #!/usr/bin/perl | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | getCuiDef.pl - This program returns the definition of a concept | ||||||||||
| 6 | or a term. | ||||||||||
| 7 | |||||||||||
| 8 | =head1 SYNOPSIS | ||||||||||
| 9 | |||||||||||
| 10 | This program takes in a CUI or a term and returns its definitions. If a | ||||||||||
| 11 | term is specified, the associated CUI is obtained using the sources | ||||||||||
| 12 | specified in the configuration file. The definitions come from the entire | ||||||||||
| 13 | UMLS. | ||||||||||
| 14 | |||||||||||
| 15 | =head1 USAGE | ||||||||||
| 16 | |||||||||||
| 17 | Usage: getCuiDef.pl [OPTIONS] [CUI|TERM] | ||||||||||
| 18 | |||||||||||
| 19 | =head1 INPUT | ||||||||||
| 20 | |||||||||||
| 21 | =head2 Required Arguments: | ||||||||||
| 22 | |||||||||||
| 23 | =head3 [CUI|TERM} | ||||||||||
| 24 | |||||||||||
| 25 | Concept Unique Identifier (CUI) or a term from the Unified Medical | ||||||||||
| 26 | Language System (UMLS) | ||||||||||
| 27 | |||||||||||
| 28 | =head2 Optional Arguments: | ||||||||||
| 29 | |||||||||||
| 30 | =head3 --config FILE | ||||||||||
| 31 | |||||||||||
| 32 | This is the configuration file. The format of the configuration | ||||||||||
| 33 | file is as follows: | ||||||||||
| 34 | |||||||||||
| 35 | SAB :: <include|exclude> <source1, source2, ... sourceN> | ||||||||||
| 36 | |||||||||||
| 37 | REL :: <include|exclude> <relation1, relation2, ... relationN> | ||||||||||
| 38 | |||||||||||
| 39 | RELA :: <include|exclude> <rela1, rela2, ... relaN> (optional) | ||||||||||
| 40 | |||||||||||
| 41 | For example, if we wanted to use the MSH vocabulary with only | ||||||||||
| 42 | the RB/RN relations, the configuration file would be: | ||||||||||
| 43 | |||||||||||
| 44 | SAB :: include MSH | ||||||||||
| 45 | REL :: include RB, RN | ||||||||||
| 46 | RELA :: include inverse_isa, isa | ||||||||||
| 47 | |||||||||||
| 48 | or | ||||||||||
| 49 | |||||||||||
| 50 | SAB :: include MSH | ||||||||||
| 51 | REL :: exclude PAR, CHD | ||||||||||
| 52 | |||||||||||
| 53 | If you go to the configuration file directory, there will | ||||||||||
| 54 | be example configuration files for the different runs that | ||||||||||
| 55 | you have performed. | ||||||||||
| 56 | |||||||||||
| 57 | =head3 --sab | ||||||||||
| 58 | |||||||||||
| 59 | Prints the source in which the definition comes from | ||||||||||
| 60 | |||||||||||
| 61 | =head3 --debug | ||||||||||
| 62 | |||||||||||
| 63 | Sets the debug flag for testing | ||||||||||
| 64 | |||||||||||
| 65 | =head3 --username STRING | ||||||||||
| 66 | |||||||||||
| 67 | Username is required to access the umls database on MySql | ||||||||||
| 68 | unless it was specified in the my.cnf file at installation | ||||||||||
| 69 | |||||||||||
| 70 | =head3 --password STRING | ||||||||||
| 71 | |||||||||||
| 72 | Password is required to access the umls database on MySql | ||||||||||
| 73 | unless it was specified in the my.cnf file at installation | ||||||||||
| 74 | |||||||||||
| 75 | =head3 --hostname STRING | ||||||||||
| 76 | |||||||||||
| 77 | Hostname where mysql is located. DEFAULT: localhost | ||||||||||
| 78 | |||||||||||
| 79 | =head3 --socket STRING | ||||||||||
| 80 | |||||||||||
| 81 | The socket your mysql is using. DEFAULT: /tmp/mysql.sock | ||||||||||
| 82 | |||||||||||
| 83 | =head3 --database STRING | ||||||||||
| 84 | |||||||||||
| 85 | Database contain UMLS DEFAULT: umls | ||||||||||
| 86 | |||||||||||
| 87 | =head4 --help | ||||||||||
| 88 | |||||||||||
| 89 | Displays the quick summary of program options. | ||||||||||
| 90 | |||||||||||
| 91 | =head4 --version | ||||||||||
| 92 | |||||||||||
| 93 | Displays the version information. | ||||||||||
| 94 | |||||||||||
| 95 | =head1 OUTPUT | ||||||||||
| 96 | |||||||||||
| 97 | List of CUIs that are associated with the input term | ||||||||||
| 98 | |||||||||||
| 99 | =head1 SYSTEM REQUIREMENTS | ||||||||||
| 100 | |||||||||||
| 101 | =over | ||||||||||
| 102 | |||||||||||
| 103 | =item * Perl (version 5.8.5 or better) - http://www.perl.org | ||||||||||
| 104 | |||||||||||
| 105 | =back | ||||||||||
| 106 | |||||||||||
| 107 | =head1 AUTHOR | ||||||||||
| 108 | |||||||||||
| 109 | Bridget T. McInnes, University of Minnesota | ||||||||||
| 110 | |||||||||||
| 111 | =head1 COPYRIGHT | ||||||||||
| 112 | |||||||||||
| 113 | Copyright (c) 2007-2009, | ||||||||||
| 114 | |||||||||||
| 115 | Bridget T. McInnes, University of Minnesota | ||||||||||
| 116 | bthomson at cs.umn.edu | ||||||||||
| 117 | |||||||||||
| 118 | Ted Pedersen, University of Minnesota Duluth | ||||||||||
| 119 | tpederse at d.umn.edu | ||||||||||
| 120 | |||||||||||
| 121 | Siddharth Patwardhan, University of Utah, Salt Lake City | ||||||||||
| 122 | sidd@cs.utah.edu | ||||||||||
| 123 | |||||||||||
| 124 | Serguei Pakhomov, University of Minnesota Twin Cities | ||||||||||
| 125 | pakh0002@umn.edu | ||||||||||
| 126 | |||||||||||
| 127 | This program is free software; you can redistribute it and/or modify it under | ||||||||||
| 128 | the terms of the GNU General Public License as published by the Free Software | ||||||||||
| 129 | Foundation; either version 2 of the License, or (at your option) any later | ||||||||||
| 130 | version. | ||||||||||
| 131 | |||||||||||
| 132 | This program is distributed in the hope that it will be useful, but WITHOUT | ||||||||||
| 133 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||||||||||
| 134 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||||||||||
| 135 | |||||||||||
| 136 | You should have received a copy of the GNU General Public License along with | ||||||||||
| 137 | this program; if not, write to: | ||||||||||
| 138 | |||||||||||
| 139 | The Free Software Foundation, Inc., | ||||||||||
| 140 | 59 Temple Place - Suite 330, | ||||||||||
| 141 | Boston, MA 02111-1307, USA. | ||||||||||
| 142 | |||||||||||
| 143 | =cut | ||||||||||
| 144 | |||||||||||
| 145 | ############################################################################### | ||||||||||
| 146 | |||||||||||
| 147 | # THE CODE STARTS HERE | ||||||||||
| 148 | ############################################################################### | ||||||||||
| 149 | |||||||||||
| 150 | # ================================ | ||||||||||
| 151 | # COMMAND LINE OPTIONS AND USAGE | ||||||||||
| 152 | # ================================ | ||||||||||
| 153 | |||||||||||
| 154 | |||||||||||
| 155 | 2 | ▶ | use UMLS::Interface; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 156 | 2 | ▶ | use Getopt::Long; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 157 | |||||||||||
| 158 | 2 | ▶ | eval(GetOptions( "version", "help", "debug", "username=s", "password=s", "hostname=s", "database=s", "socket=s", "config=s", "sab")) or die ("Please check the above mentioned option(s).\n"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 159 | |||||||||||
| 160 | |||||||||||
| 161 | # if help is defined, print out help | ||||||||||
| 162 | 2 | ▶ | if( defined $opt_help ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 163 | 0 | $opt_help = 1; | |||||||||
| 164 | 0 | &showHelp(); | |||||||||
| 165 | 0 | exit; | |||||||||
| 166 | } | ||||||||||
| 167 | |||||||||||
| 168 | # if version is requested, show version | ||||||||||
| 169 | 2 | ▶ | if( defined $opt_version ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 170 | 0 | $opt_version = 1; | |||||||||
| 171 | 0 | &showVersion(); | |||||||||
| 172 | 0 | exit; | |||||||||
| 173 | } | ||||||||||
| 174 | |||||||||||
| 175 | # check the config | ||||||||||
| 176 | 2 | ▶ | if( defined $opt_config) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 177 | 0 | checkConfigFile($opt_config); | |||||||||
| 178 | } | ||||||||||
| 179 | |||||||||||
| 180 | # At least 1 CUI should be given on the command line. | ||||||||||
| 181 | 2 | ▶ | if(scalar(@ARGV) < 1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 182 | 1 | print STDERR "No term was specified on the command line\n"; | |||||||||
| 183 | 1 | &minimalUsageNotes(); | |||||||||
| 184 | 0 | exit; | |||||||||
| 185 | } | ||||||||||
| 186 | |||||||||||
| 187 | 1 | my $umls = ""; | |||||||||
| 188 | 1 | my %option_hash = (); | |||||||||
| 189 | |||||||||||
| 190 | 1 | ▶ | if(defined $opt_config) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 191 | 0 | $option_hash{"config"} = $opt_config; | |||||||||
| 192 | } | ||||||||||
| 193 | 1 | ▶ | if(defined $opt_verbose) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 194 | 0 | $option_hash{"verbose"} = $opt_verbose; | |||||||||
| 195 | } | ||||||||||
| 196 | 1 | ▶ | if(defined $opt_debug) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 197 | 0 | $option_hash{"debug"} = $opt_debug; | |||||||||
| 198 | } | ||||||||||
| 199 | 1 | ▶ | if(defined $opt_username) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 200 | 0 | $option_hash{"username"} = $opt_username; | |||||||||
| 201 | } | ||||||||||
| 202 | 1 | ▶ | if(defined $opt_driver) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 203 | 0 | $option_hash{"driver"} = $opt_driver; | |||||||||
| 204 | } | ||||||||||
| 205 | 1 | ▶ | if(defined $opt_database) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 206 | 0 | $option_hash{"database"} = $opt_database; | |||||||||
| 207 | } | ||||||||||
| 208 | 1 | ▶ | if(defined $opt_password) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 209 | 0 | $option_hash{"password"} = $opt_password; | |||||||||
| 210 | } | ||||||||||
| 211 | 1 | ▶ | if(defined $opt_hostname) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 212 | 0 | $option_hash{"hostname"} = $opt_hostname; | |||||||||
| 213 | } | ||||||||||
| 214 | 1 | ▶ | if(defined $opt_socket) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 215 | 0 | $option_hash{"socket"} = $opt_socket; | |||||||||
| 216 | } | ||||||||||
| 217 | |||||||||||
| 218 | 1 | $umls = UMLS::Interface->new(\%option_hash); | |||||||||
| 219 | 0 | ▶ | die "Unable to create UMLS::Interface object.\n" if(!$umls); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 220 | |||||||||||
| 221 | 0 | my $input = shift; | |||||||||
| 222 | 0 | my $term = $input; | |||||||||
| 223 | |||||||||||
| 224 | 0 | my @c = (); | |||||||||
| 225 | 0 | ▶ | if($input=~/C[0-9]+/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 226 | 0 | push @{$c}, $input; | |||||||||
| 227 | 0 | my $terms = $umls->getPreferredTerm($input); | |||||||||
| 228 | 0 | $term = shift @{$terms}; | |||||||||
| 229 | } | ||||||||||
| 230 | else { | ||||||||||
| 231 | 0 | $c = $umls->getConceptList($input); | |||||||||
| 232 | } | ||||||||||
| 233 | |||||||||||
| 234 | 0 | my $printFlag = 0; | |||||||||
| 235 | |||||||||||
| 236 | 0 | foreach my $cui (@{$c}) { | |||||||||
| 237 | |||||||||||
| 238 | 0 | my $defs = undef; | |||||||||
| 239 | |||||||||||
| 240 | 0 | ▶ | if(defined $opt_sab) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 241 | 0 | $defs = $umls->getCuiDef($cui, $opt_sab); | |||||||||
| 242 | } | ||||||||||
| 243 | else { | ||||||||||
| 244 | 0 | $defs = $umls->getCuiDef($cui); | |||||||||
| 245 | } | ||||||||||
| 246 | |||||||||||
| 247 | 0 | ▶ | if($#{$defs} >= 0) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 248 | 0 | print "The definition(s) of $term ($cui):\n"; | |||||||||
| 249 | 0 | my $i = 1; | |||||||||
| 250 | 0 | foreach $def (@{$defs}) { | |||||||||
| 251 | 0 | print " $i. $def\n"; $i++; | |||||||||
| 252 | } | ||||||||||
| 253 | } | ||||||||||
| 254 | else { | ||||||||||
| 255 | 0 | print "There are no definitions for $term ($cui)\n"; | |||||||||
| 256 | } | ||||||||||
| 257 | |||||||||||
| 258 | 0 | $printFlag = 1; | |||||||||
| 259 | |||||||||||
| 260 | } | ||||||||||
| 261 | |||||||||||
| 262 | 0 | ▶ | if(! ($printFlag) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 263 | 0 | print "There are no definitions for $input\n"; | |||||||||
| 264 | } | ||||||||||
| 265 | |||||||||||
| 266 | ############################################################################## | ||||||||||
| 267 | # check to make certain the config file contains the correct parameters | ||||||||||
| 268 | ############################################################################## | ||||||||||
| 269 | sub checkConfigFile { | ||||||||||
| 270 | 0 | ▶ | my $configfile = shift; | ||||||||
|
Subroutine
checkConfigFile: not called CC=5 SCAR=34.0
| |||||||||||
| 271 | 0 | ▶ | open(CONFIG, $configfile) || die "Could not open config file ($config)\n"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 272 | 0 | ▶ | while(<CONFIG>) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 273 | 0 | chomp; | |||||||||
| 274 | 0 | ▶ | if($_=~/SABDEF/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 275 | 0 | print STDERR "SABDEF not valid parameter for getCuiDef.pl\n"; | |||||||||
| 276 | 0 | &minimalUsageNotes(); | |||||||||
| 277 | 0 | exit; | |||||||||
| 278 | } | ||||||||||
| 279 | 0 | ▶ | if($_=~/RELDEF/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 280 | 0 | print STDERR "RELDEF not valid parameter for getCuiDef.pl\n"; | |||||||||
| 281 | 0 | &minimalUsageNotes(); | |||||||||
| 282 | 0 | exit; | |||||||||
| 283 | } | ||||||||||
| 284 | } | ||||||||||
| 285 | } | ||||||||||
| 286 | |||||||||||
| 287 | |||||||||||
| 288 | ############################################################################## | ||||||||||
| 289 | # function to output minimal usage notes | ||||||||||
| 290 | ############################################################################## | ||||||||||
| 291 | sub minimalUsageNotes { | ||||||||||
| 292 | |||||||||||
| 293 | 1 | ▶ | print "Usage: getCuiDef.pl [OPTIONS] [CUI|TERM] \n"; | ||||||||
|
Subroutine
minimalUsageNotes: called CC=1 SCAR=0.0
| |||||||||||
| 294 | 1 | &askHelp(); | |||||||||
| 295 | 1 | exit; | |||||||||
| 296 | } | ||||||||||
| 297 | |||||||||||
| 298 | ############################################################################## | ||||||||||
| 299 | # function to output help messages for this program | ||||||||||
| 300 | ############################################################################## | ||||||||||
| 301 | sub showHelp() { | ||||||||||
| 302 | |||||||||||
| 303 | |||||||||||
| 304 | 0 | ▶ | print "This is a utility that takes as input a term \n"; | ||||||||
|
Subroutine
showHelp: not called CC=1 SCAR=6.9
| |||||||||||
| 305 | 0 | print "or a CUI and returns all of its definitions.\n\n"; | |||||||||
| 306 | |||||||||||
| 307 | 0 | print "Usage: getCuiDef.pl [OPTIONS] [CUI|TERM]\n\n"; | |||||||||
| 308 | |||||||||||
| 309 | 0 | print "Options:\n\n"; | |||||||||
| 310 | |||||||||||
| 311 | 0 | print " --sab Prints the source in which the \n"; | |||||||||
| 312 | 0 | print " definition originates\n\n"; | |||||||||
| 313 | |||||||||||
| 314 | 0 | print "--debug Sets the debug flag for testing\n\n"; | |||||||||
| 315 | |||||||||||
| 316 | 0 | print "--username STRING Username required to access mysql\n\n"; | |||||||||
| 317 | |||||||||||
| 318 | 0 | print "--password STRING Password required to access mysql\n\n"; | |||||||||
| 319 | |||||||||||
| 320 | 0 | print "--hostname STRING Hostname for mysql (DEFAULT: localhost)\n\n"; | |||||||||
| 321 | |||||||||||
| 322 | 0 | print "--database STRING Database contain UMLS (DEFAULT: umls)\n\n"; | |||||||||
| 323 | |||||||||||
| 324 | 0 | print "--socket STRING Socket used by mysql (DEFAULT: /tmp.mysql.sock)\n\n"; | |||||||||
| 325 | |||||||||||
| 326 | 0 | print "--config FILE Configuration file\n\n"; | |||||||||
| 327 | |||||||||||
| 328 | 0 | print "--version Prints the version number\n\n"; | |||||||||
| 329 | |||||||||||
| 330 | 0 | print "--help Prints this help message.\n\n"; | |||||||||
| 331 | } | ||||||||||
| 332 | |||||||||||
| 333 | ############################################################################## | ||||||||||
| 334 | # function to output the version number | ||||||||||
| 335 | ############################################################################## | ||||||||||
| 336 | sub showVersion { | ||||||||||
| 337 | 0 | ▶ | print '$Id: getCuiDef.pl,v 1.17 2011/08/29 16:37:03 btmcinnes Exp $'; | ||||||||
|
Subroutine
showVersion: not called CC=1 SCAR=6.9
| |||||||||||
| 338 | 0 | print "\nCopyright (c) 2008, Ted Pedersen & Bridget McInnes\n"; | |||||||||
| 339 | } | ||||||||||
| 340 | |||||||||||
| 341 | ############################################################################## | ||||||||||
| 342 | # function to output "ask for help" message when user's goofed | ||||||||||
| 343 | ############################################################################## | ||||||||||
| 344 | sub askHelp { | ||||||||||
| 345 | 1 | ▶ | print STDERR "Type getCuiDef.pl --help for help.\n"; | ||||||||
|
Subroutine
askHelp: called CC=1 SCAR=0.0
| |||||||||||
| 346 | } | ||||||||||
| 347 | |||||||||||