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