| 1 | #!/usr/local/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 | use UMLS::Interface; | ||
| 156 | use Getopt::Long; | ||
| 157 | |||
| 158 | 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"); | ||
| 159 | |||
| 160 | |||
| 161 | # if help is defined, print out help | ||
| 162 | if( defined $opt_help ) { | ||
| 163 | $opt_help = 1; | ||
| 164 | &showHelp(); | ||
| 165 | exit; | ||
| 166 | } | ||
| 167 | |||
| 168 | # if version is requested, show version | ||
| 169 | if( defined $opt_version ) { | ||
| 170 | $opt_version = 1; | ||
| 171 | &showVersion(); | ||
| 172 | exit; | ||
| 173 | } | ||
| 174 | |||
| 175 | # check the config | ||
| 176 | if( defined $opt_config) { | ||
| 177 | checkConfigFile($opt_config); | ||
| 178 | } | ||
| 179 | |||
| 180 | # At least 1 CUI should be given on the command line. | ||
| 181 | if(scalar(@ARGV) < 1) { | ||
| 182 | print STDERR "No term was specified on the command line\n"; | ||
| 183 | &minimalUsageNotes(); | ||
| 184 | exit; | ||
| 185 | } | ||
| 186 | |||
| 187 | my $umls = ""; | ||
| 188 | my %option_hash = (); | ||
| 189 | |||
| 190 | if(defined $opt_config) { | ||
| 191 | $option_hash{"config"} = $opt_config; | ||
| 192 | } | ||
| 193 | if(defined $opt_verbose) { | ||
| 194 | $option_hash{"verbose"} = $opt_verbose; | ||
| 195 | } | ||
| 196 | if(defined $opt_debug) { | ||
| 197 | $option_hash{"debug"} = $opt_debug; | ||
| 198 | } | ||
| 199 | if(defined $opt_username) { | ||
| 200 | $option_hash{"username"} = $opt_username; | ||
| 201 | } | ||
| 202 | if(defined $opt_driver) { | ||
| 203 | $option_hash{"driver"} = $opt_driver; | ||
| 204 | } | ||
| 205 | if(defined $opt_database) { | ||
| 206 | $option_hash{"database"} = $opt_database; | ||
| 207 | } | ||
| 208 | if(defined $opt_password) { | ||
| 209 | $option_hash{"password"} = $opt_password; | ||
| 210 | } | ||
| 211 | if(defined $opt_hostname) { | ||
| 212 | $option_hash{"hostname"} = $opt_hostname; | ||
| 213 | } | ||
| 214 | if(defined $opt_socket) { | ||
| 215 | $option_hash{"socket"} = $opt_socket; | ||
| 216 | } | ||
| 217 | |||
| 218 | $umls = UMLS::Interface->new(\%option_hash); | ||
| 219 | die "Unable to create UMLS::Interface object.\n" if(!$umls); | ||
| 220 | |||
| 221 | my $input = shift; | ||
| 222 | my $term = $input; | ||
| 223 | |||
| 224 | my @c = (); | ||
| 225 | if($input=~/C[0-9]+/) { | ||
| 226 | push @{$c}, $input; | ||
| 227 | my $terms = $umls->getPreferredTerm($input); | ||
| 228 | $term = shift @{$terms}; | ||
| 229 | } | ||
| 230 | else { | ||
| 231 | $c = $umls->getConceptList($input); | ||
| 232 | } | ||
| 233 | |||
| 234 | my $printFlag = 0; | ||
| 235 | |||
| 236 | foreach my $cui (@{$c}) { | ||
| 237 | |||
| 238 | my $defs = undef; | ||
| 239 | |||
| 240 | if(defined $opt_sab) { | ||
| 241 | $defs = $umls->getCuiDef($cui, $opt_sab); | ||
| 242 | } | ||
| 243 | else { | ||
| 244 | $defs = $umls->getCuiDef($cui); | ||
| 245 | } | ||
| 246 | |||
| 247 | if($#{$defs} >= 0) { | ||
| 248 | print "The definition(s) of $term ($cui):\n"; | ||
| 249 | my $i = 1; | ||
| 250 | foreach $def (@{$defs}) { | ||
| 251 | print " $i. $def\n"; $i++; | ||
| 252 | } | ||
| 253 | } | ||
| 254 | else { | ||
| 255 | print "There are no definitions for $term ($cui)\n"; | ||
| 256 | } | ||
| 257 | |||
| 258 | $printFlag = 1; | ||
| 259 | |||
| 260 | } | ||
| 261 | |||
| 262 | if(! ($printFlag) ) { | ||
| 263 | 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 | my $configfile = shift; | ||
| 271 | open(CONFIG, $configfile) || die "Could not open config file ($config)\n"; | ||
| 272 | while(<CONFIG>) { | ||
| 273 | chomp; | ||
| 274 | if($_=~/SABDEF/) { | ||
| 275 | print STDERR "SABDEF not valid parameter for getCuiDef.pl\n"; | ||
| 276 | &minimalUsageNotes(); | ||
| 277 | exit; | ||
| 278 | } | ||
| 279 | if($_=~/RELDEF/) { | ||
| 280 | print STDERR "RELDEF not valid parameter for getCuiDef.pl\n"; | ||
| 281 | &minimalUsageNotes(); | ||
| 282 | exit; | ||
| 283 | } | ||
| 284 | } | ||
| 285 | } | ||
| 286 | |||
| 287 | |||
| 288 | ############################################################################## | ||
| 289 | # function to output minimal usage notes | ||
| 290 | ############################################################################## | ||
| 291 | sub minimalUsageNotes { | ||
| 292 | |||
| 293 | print "Usage: getCuiDef.pl [OPTIONS] [CUI|TERM] \n"; | ||
| 294 | &askHelp(); | ||
| 295 | exit; | ||
| 296 | } | ||
| 297 | |||
| 298 | ############################################################################## | ||
| 299 | # function to output help messages for this program | ||
| 300 | ############################################################################## | ||
| 301 | sub showHelp() { | ||
| 302 | |||
| 303 | |||
| 304 | print "This is a utility that takes as input a term \n"; | ||
| 305 | print "or a CUI and returns all of its definitions.\n\n"; | ||
| 306 | |||
| 307 | print "Usage: getCuiDef.pl [OPTIONS] [CUI|TERM]\n\n"; | ||
| 308 | |||
| 309 | print "Options:\n\n"; | ||
| 310 | |||
| 311 | print " --sab Prints the source in which the \n"; | ||
| 312 | print " definition originates\n\n"; | ||
| 313 | |||
| 314 | print "--debug Sets the debug flag for testing\n\n"; | ||
| 315 | |||
| 316 | print "--username STRING Username required to access mysql\n\n"; | ||
| 317 | |||
| 318 | print "--password STRING Password required to access mysql\n\n"; | ||
| 319 | |||
| 320 | print "--hostname STRING Hostname for mysql (DEFAULT: localhost)\n\n"; | ||
| 321 | |||
| 322 | print "--database STRING Database contain UMLS (DEFAULT: umls)\n\n"; | ||
| 323 | |||
| 324 | print "--socket STRING Socket used by mysql (DEFAULT: /tmp.mysql.sock)\n\n"; | ||
| 325 | |||
| 326 | print "--config FILE Configuration file\n\n"; | ||
| 327 | |||
| 328 | print "--version Prints the version number\n\n"; | ||
| 329 | |||
| 330 | print "--help Prints this help message.\n\n"; | ||
| 331 | } | ||
| 332 | |||
| 333 | ############################################################################## | ||
| 334 | # function to output the version number | ||
| 335 | ############################################################################## | ||
| 336 | sub showVersion { | ||
| 337 | print '$Id: getCuiDef.pl,v 1.17 2011/08/29 16:37:03 btmcinnes Exp $'; | ||
| 338 | 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 | print STDERR "Type getCuiDef.pl --help for help.\n"; | ||
| 346 | } | ||
| 347 |