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