| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | getCuiList.pl - This program returns a list of CUIs based on the configuration | ||
| 6 | file. | ||
| 7 | |||
| 8 | =head1 SYNOPSIS | ||
| 9 | |||
| 10 | This program returns a list of CUIs based on the sources and relations | ||
| 11 | specified in the configuration file. | ||
| 12 | |||
| 13 | =head1 USAGE | ||
| 14 | |||
| 15 | Usage: getCuiList.pl [OPTIONS] CONFIGFILE | ||
| 16 | |||
| 17 | =head1 INPUT | ||
| 18 | |||
| 19 | =head2 CONFIGFILE | ||
| 20 | |||
| 21 | This is the configuration file. The format of the configuration | ||
| 22 | file is as follows: | ||
| 23 | |||
| 24 | SAB :: <include|exclude> <source1, source2, ... sourceN> | ||
| 25 | REL :: <include|exclude> <relation1, relation2, ... relationN> | ||
| 26 | RELA :: <include|exclude> <rela1, rela2, .... relaN> (optional) | ||
| 27 | |||
| 28 | For example, if we wanted to use the MSH vocabulary with only | ||
| 29 | the RB/RN relations, the configuration file would be: | ||
| 30 | |||
| 31 | SAB :: include MSH | ||
| 32 | REL :: include RB, RN | ||
| 33 | RELA :: include inverse_isa, isa | ||
| 34 | |||
| 35 | or | ||
| 36 | |||
| 37 | SAB :: include MSH | ||
| 38 | REL :: exclude PAR, CHD | ||
| 39 | |||
| 40 | If you go to the configuration file directory, there will | ||
| 41 | be example configuration files for the different runs that | ||
| 42 | you have performed. | ||
| 43 | |||
| 44 | =head1 OUTPUT | ||
| 45 | |||
| 46 | List of CUIs that are associated with the input term | ||
| 47 | |||
| 48 | =head1 OPTIONAL ARGUMENTS: | ||
| 49 | |||
| 50 | =head2 --children | ||
| 51 | |||
| 52 | Returns the number of children of a given CUI. The format for just using | ||
| 53 | --children is: | ||
| 54 | |||
| 55 | CUI children | ||
| 56 | |||
| 57 | =head2 --parents | ||
| 58 | |||
| 59 | Returns the number of children of a given CUI. The format for just using | ||
| 60 | --parents is: | ||
| 61 | |||
| 62 | CUI parents | ||
| 63 | |||
| 64 | The format for using both --parents and --children is: | ||
| 65 | |||
| 66 | CUI children|parents | ||
| 67 | |||
| 68 | =head2 --relations REL | ||
| 69 | |||
| 70 | Returns the number of relations of a given CUI. The REL input can be | ||
| 71 | a list of comma seperated relations. For example: | ||
| 72 | |||
| 73 | --relation "SIB,RO" | ||
| 74 | |||
| 75 | This would return the number of SIB and RO relations for a given concept | ||
| 76 | in the format : CUI sib|ro | ||
| 77 | |||
| 78 | This option current can not be used with the --children and --parent | ||
| 79 | option because if you want them just add them to the list. For example: | ||
| 80 | --relation "SIB,PAR,CHD" | ||
| 81 | |||
| 82 | =head2 --term | ||
| 83 | |||
| 84 | Returns the terms associated with the CUI in the following format: | ||
| 85 | |||
| 86 | CUI term1|term2|term3|... | ||
| 87 | |||
| 88 | If used with the --parents and/or --children options or the --relation | ||
| 89 | options, the following format is returned: | ||
| 90 | |||
| 91 | CUI children|parents|term1|term2|... | ||
| 92 | |||
| 93 | Remember children and parents is a number! | ||
| 94 | |||
| 95 | =head2 --st <semantic type abbreviation> | ||
| 96 | |||
| 97 | Returns only those CUIs with the specified semantic type | ||
| 98 | |||
| 99 | =head2 --sg <semantic group name> | ||
| 100 | |||
| 101 | Returns only those CUIs with the specified semantic group | ||
| 102 | |||
| 103 | =head2 --debug | ||
| 104 | |||
| 105 | Sets the debug flag for testing | ||
| 106 | |||
| 107 | =head2 --username STRING | ||
| 108 | |||
| 109 | Username is required to access the umls database on MySql | ||
| 110 | unless it was specified in the my.cnf file at installation | ||
| 111 | |||
| 112 | =head2 --password STRING | ||
| 113 | |||
| 114 | Password is required to access the umls database on MySql | ||
| 115 | unless it was specified in the my.cnf file at installation | ||
| 116 | |||
| 117 | =head2 --hostname STRING | ||
| 118 | |||
| 119 | Hostname where mysql is located. DEFAULT: localhost | ||
| 120 | |||
| 121 | =head2 --socket STRING | ||
| 122 | |||
| 123 | The socket your mysql is using. DEFAULT: /tmp/mysql.sock | ||
| 124 | |||
| 125 | =head2 --database STRING | ||
| 126 | |||
| 127 | Database contain UMLS DEFAULT: umls | ||
| 128 | |||
| 129 | =head2 --help | ||
| 130 | |||
| 131 | Displays the quick summary of program options. | ||
| 132 | |||
| 133 | =head2 --version | ||
| 134 | |||
| 135 | Displays the version information. | ||
| 136 | |||
| 137 | =head1 SYSTEM REQUIREMENTS | ||
| 138 | |||
| 139 | =over | ||
| 140 | |||
| 141 | =item * Perl (version 5.8.5 or better) - http://www.perl.org | ||
| 142 | |||
| 143 | =back | ||
| 144 | |||
| 145 | =head1 AUTHOR | ||
| 146 | |||
| 147 | Bridget T. McInnes, University of Minnesota | ||
| 148 | |||
| 149 | =head1 COPYRIGHT | ||
| 150 | |||
| 151 | Copyright (c) 2007-2011, | ||
| 152 | |||
| 153 | Bridget T. McInnes, University of Minnesota | ||
| 154 | bthomson at cs.umn.edu | ||
| 155 | |||
| 156 | Ted Pedersen, University of Minnesota Duluth | ||
| 157 | tpederse at d.umn.edu | ||
| 158 | |||
| 159 | Serguei Pakhomov, University of Minnesota Twin Cities | ||
| 160 | pakh0002@umn.edu | ||
| 161 | |||
| 162 | This program is free software; you can redistribute it and/or modify it under | ||
| 163 | the terms of the GNU General Public License as published by the Free Software | ||
| 164 | Foundation; either version 2 of the License, or (at your option) any later | ||
| 165 | version. | ||
| 166 | |||
| 167 | This program is distributed in the hope that it will be useful, but WITHOUT | ||
| 168 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 169 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
| 170 | |||
| 171 | You should have received a copy of the GNU General Public License along with | ||
| 172 | this program; if not, write to: | ||
| 173 | |||
| 174 | The Free Software Foundation, Inc., | ||
| 175 | 59 Temple Place - Suite 330, | ||
| 176 | Boston, MA 02111-1307, USA. | ||
| 177 | |||
| 178 | =cut | ||
| 179 | |||
| 180 | ############################################################################### | ||
| 181 | |||
| 182 | # THE CODE STARTS HERE | ||
| 183 | ############################################################################### | ||
| 184 | |||
| 185 | # ================================ | ||
| 186 | # COMMAND LINE OPTIONS AND USAGE | ||
| 187 | # ================================ | ||
| 188 | |||
| 189 | |||
| 190 | use UMLS::Interface; | ||
| 191 | use Getopt::Long; | ||
| 192 | |||
| 193 | eval(GetOptions( "version", "help", "debug", "username=s", "password=s", "hostname=s", "database=s", "socket=s", "term", "st=s", "sg=s", "relations=s", "children", "parents")) or die ("Please check the above mentioned option(s).\n"); | ||
| 194 | |||
| 195 | |||
| 196 | # if help is defined, print out help | ||
| 197 | if( defined $opt_help ) { | ||
| 198 | $opt_help = 1; | ||
| 199 | &showHelp(); | ||
| 200 | exit; | ||
| 201 | } | ||
| 202 | |||
| 203 | # if version is requested, show version | ||
| 204 | if( defined $opt_version ) { | ||
| 205 | $opt_version = 1; | ||
| 206 | &showVersion(); | ||
| 207 | exit; | ||
| 208 | } | ||
| 209 | |||
| 210 | # At least 1 CUI should be given on the command line. | ||
| 211 | if(scalar(@ARGV) < 1) { | ||
| 212 | print STDERR "Configuration file was not specified on the command line\n"; | ||
| 213 | &minimalUsageNotes(); | ||
| 214 | exit; | ||
| 215 | } | ||
| 216 | |||
| 217 | if(defined $opt_relations && $opt_children) { | ||
| 218 | print STDERR "The --relation and --children option can not be used\n"; | ||
| 219 | print STDERR "together. Just add CHD to your relations. For example:\n"; | ||
| 220 | print STDERR " --relations \"SIB,PAR,CHD\"\n"; | ||
| 221 | &minimalUsageNotes(); | ||
| 222 | exit; | ||
| 223 | } | ||
| 224 | |||
| 225 | if(defined $opt_relations && $opt_parents) { | ||
| 226 | print STDERR "The --relation and --parents option can not be used\n"; | ||
| 227 | print STDERR "together. Just add CHD to your relations. For example:\n"; | ||
| 228 | print STDERR " --relations \"SIB,PAR,CHD\"\n"; | ||
| 229 | &minimalUsageNotes(); | ||
| 230 | exit; | ||
| 231 | } | ||
| 232 | |||
| 233 | |||
| 234 | my $config = shift; | ||
| 235 | |||
| 236 | my %option_hash = (); | ||
| 237 | |||
| 238 | $option_hash{"config"} = $config; | ||
| 239 | |||
| 240 | if(defined $opt_debug) { | ||
| 241 | $option_hash{"debug"} = $opt_debug; | ||
| 242 | } | ||
| 243 | if(defined $opt_username) { | ||
| 244 | $option_hash{"username"} = $opt_username; | ||
| 245 | } | ||
| 246 | if(defined $opt_driver) { | ||
| 247 | $option_hash{"driver"} = $opt_driver; | ||
| 248 | } | ||
| 249 | if(defined $opt_database) { | ||
| 250 | $option_hash{"database"} = $opt_database; | ||
| 251 | } | ||
| 252 | if(defined $opt_password) { | ||
| 253 | $option_hash{"password"} = $opt_password; | ||
| 254 | } | ||
| 255 | if(defined $opt_hostname) { | ||
| 256 | $option_hash{"hostname"} = $opt_hostname; | ||
| 257 | } | ||
| 258 | if(defined $opt_socket) { | ||
| 259 | $option_hash{"socket"} = $opt_socket; | ||
| 260 | } | ||
| 261 | |||
| 262 | $umls = UMLS::Interface->new(\%option_hash); | ||
| 263 | die "Unable to create UMLS::Interface object.\n" if(!$umls); | ||
| 264 | |||
| 265 | my $hashref = $umls->getCuiList(); | ||
| 266 | |||
| 267 | foreach my $cui (sort keys %{$hashref}) { | ||
| 268 | # flag to determine whether the cui is to be printed | ||
| 269 | my $flag = 1; | ||
| 270 | |||
| 271 | # if --st, check to make certain the cui is of the | ||
| 272 | # appropriate semantic type | ||
| 273 | if(defined $opt_st) { | ||
| 274 | $flag = 0; | ||
| 275 | my $sts = $umls->getSt($cui); | ||
| 276 | foreach my $st (@{$sts}) { | ||
| 277 | my $abbrev = $umls->getStAbr($st); | ||
| 278 | if($abbrev eq $opt_st) { | ||
| 279 | $flag = 1; | ||
| 280 | } | ||
| 281 | } | ||
| 282 | } | ||
| 283 | |||
| 284 | # if --sg, check to make certain the cui is of the | ||
| 285 | # appropriate semantic group | ||
| 286 | if(defined $opt_sg) { | ||
| 287 | $flag = 0; | ||
| 288 | my $sgs = $umls->getSemanticGroup($cui); | ||
| 289 | foreach my $sg (@{$sgs}) { | ||
| 290 | if($sg eq $opt_sg) { | ||
| 291 | $flag = 1; | ||
| 292 | } | ||
| 293 | } | ||
| 294 | } | ||
| 295 | |||
| 296 | if($flag == 0) { next; } | ||
| 297 | |||
| 298 | my @output = (); | ||
| 299 | |||
| 300 | if(defined $opt_term) { | ||
| 301 | $terms = $umls->getTermList($cui); | ||
| 302 | @output = @{$terms}; | ||
| 303 | } | ||
| 304 | |||
| 305 | if(defined $opt_parents) { | ||
| 306 | my $array = $umls->getParents($cui); | ||
| 307 | my $parents = $#{$array} + 1; | ||
| 308 | unshift @output, $parents; | ||
| 309 | } | ||
| 310 | |||
| 311 | if(defined $opt_children) { | ||
| 312 | my $array = $umls->getChildren($cui); | ||
| 313 | my $children = $#{$array} + 1; | ||
| 314 | unshift @output, $children; | ||
| 315 | } | ||
| 316 | |||
| 317 | if(defined $opt_relations) { | ||
| 318 | my @relations = split/\,/, $opt_relations; | ||
| 319 | foreach my $relation (reverse @relations) { | ||
| 320 | my $array = $umls->getRelated($cui, $relation); | ||
| 321 | my $rel = $#{$array}+1; | ||
| 322 | unshift @output, $rel; | ||
| 323 | } | ||
| 324 | } | ||
| 325 | |||
| 326 | if($#output >= 0) { | ||
| 327 | my $outputstring = join "|", @output; | ||
| 328 | print "$cui $outputstring\n"; | ||
| 329 | } | ||
| 330 | else { | ||
| 331 | print "$cui\n"; | ||
| 332 | } | ||
| 333 | |||
| 334 | } | ||
| 335 | |||
| 336 | ############################################################################## | ||
| 337 | # function to output minimal usage notes | ||
| 338 | ############################################################################## | ||
| 339 | sub minimalUsageNotes { | ||
| 340 | |||
| 341 | print "Usage: getCuiList.pl [OPTIONS] CONFIGFILE\n"; | ||
| 342 | &askHelp(); | ||
| 343 | exit; | ||
| 344 | } | ||
| 345 | |||
| 346 | ############################################################################## | ||
| 347 | # function to output help messages for this program | ||
| 348 | ############################################################################## | ||
| 349 | sub showHelp() { | ||
| 350 | |||
| 351 | |||
| 352 | print "This is a utility returns all the CUIs associated with a\n"; | ||
| 353 | print "configuration file.\n\n"; | ||
| 354 | |||
| 355 | print "Usage: getCuiList.pl [OPTIONS] CONFIGFILE\n\n"; | ||
| 356 | |||
| 357 | print "Options:\n\n"; | ||
| 358 | |||
| 359 | print "--term Returns CUIs associated terms\n\n"; | ||
| 360 | |||
| 361 | print "--parents Returns number of CUIs parents\n\n"; | ||
| 362 | |||
| 363 | print "--children Returns number of CUIs children\n\n"; | ||
| 364 | |||
| 365 | print "--relations RELs Returns the number of CUIs relations\n\n"; | ||
| 366 | |||
| 367 | print "--st <semantic type> Returns CUIs with specified semantic\n"; | ||
| 368 | print " type\n\n"; | ||
| 369 | |||
| 370 | print "--sg <semantic group> Returns CUIs with specified semantic\n"; | ||
| 371 | print " group\n\n"; | ||
| 372 | |||
| 373 | print "--debug Sets the debug flag for testing\n\n"; | ||
| 374 | |||
| 375 | print "--username STRING Username required to access mysql\n\n"; | ||
| 376 | |||
| 377 | print "--password STRING Password required to access mysql\n\n"; | ||
| 378 | |||
| 379 | print "--hostname STRING Hostname for mysql (DEFAULT: localhost)\n\n"; | ||
| 380 | |||
| 381 | print "--database STRING Database contain UMLS (DEFAULT: umls)\n\n"; | ||
| 382 | |||
| 383 | print "--socket STRING Socket used by mysql (DEFAULT: /tmp.mysql.sock)\n\n"; | ||
| 384 | |||
| 385 | print "--version Prints the version number\n\n"; | ||
| 386 | |||
| 387 | print "--help Prints this help message.\n\n"; | ||
| 388 | } | ||
| 389 | |||
| 390 | ############################################################################## | ||
| 391 | # function to output the version number | ||
| 392 | ############################################################################## | ||
| 393 | sub showVersion { | ||
| 394 | print '$Id: getCuiList.pl,v 1.10 2011/11/02 13:52:58 btmcinnes Exp $'; | ||
| 395 | print "\nCopyright (c) 2008, Ted Pedersen & Bridget McInnes\n"; | ||
| 396 | } | ||
| 397 | |||
| 398 | ############################################################################## | ||
| 399 | # function to output "ask for help" message when user's goofed | ||
| 400 | ############################################################################## | ||
| 401 | sub askHelp { | ||
| 402 | print STDERR "Type getCuiList.pl --help for help.\n"; | ||
| 403 | } | ||
| 404 |