| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | umls-association.pl This program calculates the assocation between | ||
| 6 | two concepts (or terms) | ||
| 7 | |||
| 8 | =head1 SYNOPSIS | ||
| 9 | |||
| 10 | This utility takes two concepts (or terms) and returns their assocation | ||
| 11 | score | ||
| 12 | |||
| 13 | =head1 USAGE | ||
| 14 | |||
| 15 | Usage: umls-assocation.pl [OPTIONS] CUI1|TERM CUI2|TERM | ||
| 16 | |||
| 17 | =head1 INPUT | ||
| 18 | |||
| 19 | =head2 [CUI1|TERM1] [CUI2|TERM2] | ||
| 20 | |||
| 21 | The input are two terms or two CUIs associated to concepts in the UMLS. | ||
| 22 | |||
| 23 | =head1 OPTIONS | ||
| 24 | |||
| 25 | Optional command line arguements | ||
| 26 | |||
| 27 | =head2 General Options: | ||
| 28 | |||
| 29 | Displays the quick summary of program options. | ||
| 30 | |||
| 31 | =head3 --conceptexpansion | ||
| 32 | |||
| 33 | Calculates the association score taking into account the occurrences of | ||
| 34 | descendants of the specified CUIs. | ||
| 35 | |||
| 36 | =head3 --noorder | ||
| 37 | |||
| 38 | If selected, the order in which CUIs appear will be disregarded when | ||
| 39 | the association score is calculated. | ||
| 40 | |||
| 41 | =head3 --lta | ||
| 42 | |||
| 43 | Linking Term Association - Calculates the association scores using | ||
| 44 | implicit or intermediate relationships between the specified CUIs, | ||
| 45 | and the count of unique shared co-occurrences. | ||
| 46 | |||
| 47 | =head3 --mwa | ||
| 48 | |||
| 49 | Minimum Weight Association - Calculates the association scores using | ||
| 50 | implicit or intermediate relationships between the specified CUIs, | ||
| 51 | and the minimum co-occurrence count between shared co-occurrences. | ||
| 52 | |||
| 53 | =head3 --vsa | ||
| 54 | |||
| 55 | Vector Set Association - Calculates the association scores using the | ||
| 56 | association between the sets of co-occurring terms of the original terms | ||
| 57 | |||
| 58 | =head3 --precision N | ||
| 59 | |||
| 60 | Displays values up to N places of decimal. (DEFAULT: 4) | ||
| 61 | |||
| 62 | =head3 --measure STRING | ||
| 63 | |||
| 64 | The measure used to calculate the assocation. Default = tscore. | ||
| 65 | |||
| 66 | The package uses the Text::NSP package to do the calculation. | ||
| 67 | The measure included within this package are: | ||
| 68 | |||
| 69 | 1. Dice Coefficient | ||
| 70 | 2. Fishers exact test - left sided | ||
| 71 | 3. Fishers exact test - right sided | ||
| 72 | 4. Fishers twotailed test - right sided | ||
| 73 | 5. Jaccard Coefficient | ||
| 74 | 6. Log-likelihood ratio | ||
| 75 | 7. Mutual Information | ||
| 76 | 8. Odds Ratio | ||
| 77 | 9. Pointwise Mutual Information | ||
| 78 | 10. Phi Coefficient | ||
| 79 | 11. Pearson's Chi Squared Test | ||
| 80 | 12. Poisson Stirling Measure | ||
| 81 | 13. T-score (DEFAULT) | ||
| 82 | |||
| 83 | =head3 --help | ||
| 84 | |||
| 85 | Displays the quick summary of program options. | ||
| 86 | |||
| 87 | =head3 --version | ||
| 88 | |||
| 89 | Displays the version information. | ||
| 90 | |||
| 91 | =head2 Input Options: | ||
| 92 | |||
| 93 | =head2 General Database Options: | ||
| 94 | |||
| 95 | =head3 --username STRING | ||
| 96 | |||
| 97 | Username is required to access the umls database on mysql | ||
| 98 | |||
| 99 | =head3 --password STRING | ||
| 100 | |||
| 101 | Password is required to access the umls database on mysql | ||
| 102 | |||
| 103 | =head3 --hostname STRING | ||
| 104 | |||
| 105 | Hostname where mysql is located. DEFAULT: localhost | ||
| 106 | |||
| 107 | =head3 --socket STRING | ||
| 108 | |||
| 109 | Socket where the mysql.sock or mysqld.sock is located. | ||
| 110 | DEFAULT: mysql.sock | ||
| 111 | |||
| 112 | =head2 UMLS::Interface Database Options: | ||
| 113 | |||
| 114 | =head3 --umlsdatabase STRING | ||
| 115 | |||
| 116 | Database contain UMLS DEFAULT: umls | ||
| 117 | |||
| 118 | =head3 --matrix FILE | ||
| 119 | |||
| 120 | File name containing co-occurrence data in sparse matrix format | ||
| 121 | This is an alternative to storing in a database, but will be | ||
| 122 | slower for single queries, but much faster for multiple queries | ||
| 123 | File should should be sparse format of the form CUI1\tCUI2\tvalue\\n \n\n"; | ||
| 124 | |||
| 125 | =head2 UMLS::Association Database Options: | ||
| 126 | |||
| 127 | =head3 --assocdatabase STRING | ||
| 128 | |||
| 129 | The UMLS-Association database containing the CUI bigrams and their | ||
| 130 | associated frequency information. DEFAULT: CUI_BIGRAMS | ||
| 131 | |||
| 132 | =head1 OUTPUT | ||
| 133 | |||
| 134 | The association between the two concepts (or terms) | ||
| 135 | |||
| 136 | =head1 SYSTEM REQUIREMENTS | ||
| 137 | |||
| 138 | =over | ||
| 139 | |||
| 140 | =item * Perl (version 5.8.5 or better) - http://www.perl.org | ||
| 141 | |||
| 142 | =item * UMLS::Interface - http://search.cpan.org/dist/UMLS-Interface | ||
| 143 | |||
| 144 | =item * Text::NSP - http://search.cpan.org/dist/Text-NSP | ||
| 145 | |||
| 146 | =back | ||
| 147 | |||
| 148 | =head1 CONTACT US | ||
| 149 | |||
| 150 | If you have any trouble installing and using UMLS-Assocation, | ||
| 151 | please contact us via the users mailing list : | ||
| 152 | |||
| 153 | umls-association@yahoogroups.com | ||
| 154 | |||
| 155 | You can join this group by going to: | ||
| 156 | |||
| 157 | http://tech.groups.yahoo.com/group/umls-assocation/ | ||
| 158 | |||
| 159 | You may also contact us directly if you prefer : | ||
| 160 | |||
| 161 | Bridget T. McInnes: btmcinnes at vcu.edu | ||
| 162 | |||
| 163 | =head1 AUTHOR | ||
| 164 | |||
| 165 | Bridget T. McInnes, Virginia Commonwealth University | ||
| 166 | Alexander D. McQuilkin, Virginia Commonwealth University | ||
| 167 | Sam Henry, Virginia Commonwealth University | ||
| 168 | |||
| 169 | =head1 COPYRIGHT | ||
| 170 | |||
| 171 | Copyright (c) 2015 | ||
| 172 | |||
| 173 | Bridget T. McInnes, Virginia Commonwealth University | ||
| 174 | btmcinnes at vcu.edu | ||
| 175 | |||
| 176 | This program is free software; you can redistribute it and/or modify it under | ||
| 177 | the terms of the GNU General Public License as published by the Free Software | ||
| 178 | Foundation; either version 2 of the License, or (at your option) any later | ||
| 179 | version. | ||
| 180 | |||
| 181 | This program is distributed in the hope that it will be useful, but WITHOUT | ||
| 182 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 183 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
| 184 | |||
| 185 | You should have received a copy of the GNU General Public License along with | ||
| 186 | this program; if not, write to: | ||
| 187 | |||
| 188 | The Free Software Foundation, Inc., | ||
| 189 | 59 Temple Place - Suite 330, | ||
| 190 | Boston, MA 02111-1307, USA. | ||
| 191 | |||
| 192 | =cut | ||
| 193 | |||
| 194 | use UMLS::Interface; | ||
| 195 | use UMLS::Association; | ||
| 196 | use Getopt::Long; | ||
| 197 | |||
| 198 | my $DEFAULT_MEASURE = "tscore"; | ||
| 199 | |||
| 200 | ############################################# | ||
| 201 | # Get Options and params | ||
| 202 | ############################################# | ||
| 203 | eval(GetOptions( "version", "help", "debug", "username=s", "password=s", "hostname=s", "umlsdatabase=s", "assocdatabase=s", "socket=s", "measure=s", "conceptexpansion", "noorder", "lta", "mwa", "vsa", "matrix=s", "config=s","precision=s")) or die ("Please check the above mentioned option(s).\n"); | ||
| 204 | |||
| 205 | |||
| 206 | ############################################# | ||
| 207 | # Check help, version, minimal usage notes | ||
| 208 | ############################################# | ||
| 209 | # if help is defined, print out help | ||
| 210 | if( defined $opt_help ) { | ||
| 211 | $opt_help = 1; | ||
| 212 | &showHelp(); | ||
| 213 | exit; | ||
| 214 | } | ||
| 215 | |||
| 216 | # if version is requested, show version | ||
| 217 | if( defined $opt_version ) { | ||
| 218 | $opt_version = 1; | ||
| 219 | &showVersion(); | ||
| 220 | exit; | ||
| 221 | } | ||
| 222 | |||
| 223 | # At least 1 term should be given on the command line. | ||
| 224 | if(!(defined $opt_infile) && (scalar(@ARGV) < 1) ) { | ||
| 225 | print STDERR "No term was specified on the command line\n"; | ||
| 226 | &minimalUsageNotes(); | ||
| 227 | exit; | ||
| 228 | } | ||
| 229 | |||
| 230 | #get required input | ||
| 231 | my $cui1 = shift; | ||
| 232 | my $cui2 = shift; | ||
| 233 | |||
| 234 | |||
| 235 | ############################################# | ||
| 236 | # Set Up UMLS::Interface | ||
| 237 | ############################################# | ||
| 238 | # set UMLS-Interface options | ||
| 239 | my %umls_option_hash = (); | ||
| 240 | |||
| 241 | $umls_option_hash{"t"} = 1; | ||
| 242 | |||
| 243 | if(defined $opt_debug) { | ||
| 244 | $umls_option_hash{"debug"} = $opt_debug; | ||
| 245 | } | ||
| 246 | if(defined $opt_verbose) { | ||
| 247 | $umls_option_hash{"verbose"} = $opt_verbose; | ||
| 248 | } | ||
| 249 | if(defined $opt_username) { | ||
| 250 | $umls_option_hash{"username"} = $opt_username; | ||
| 251 | } | ||
| 252 | if(defined $opt_driver) { | ||
| 253 | $umls_option_hash{"driver"} = $opt_driver; | ||
| 254 | } | ||
| 255 | if(defined $opt_umlsdatabase) { | ||
| 256 | $umls_option_hash{"database"} = $opt_umlsdatabase; | ||
| 257 | } | ||
| 258 | if(defined $opt_password) { | ||
| 259 | $umls_option_hash{"password"} = $opt_password; | ||
| 260 | } | ||
| 261 | if(defined $opt_hostname) { | ||
| 262 | $umls_option_hash{"hostname"} = $opt_hostname; | ||
| 263 | } | ||
| 264 | if(defined $opt_socket) { | ||
| 265 | $umls_option_hash{"socket"} = $opt_socket; | ||
| 266 | } | ||
| 267 | if(defined $opt_config){ | ||
| 268 | $umls_option_hash{"config"} = $opt_config; | ||
| 269 | } | ||
| 270 | |||
| 271 | # instantiate instance of UMLS-Interface | ||
| 272 | my $umls = UMLS::Interface->new(\%umls_option_hash); | ||
| 273 | die "Unable to create UMLS::Interface object.\n" if(!$umls); | ||
| 274 | |||
| 275 | ############################################# | ||
| 276 | # Set Up UMLS::Association | ||
| 277 | ############################################# | ||
| 278 | # set UMLS-Association option hash | ||
| 279 | my %assoc_option_hash = (); | ||
| 280 | $assoc_option_hash{'umls'} = $umls; | ||
| 281 | |||
| 282 | if(defined $opt_measure) { | ||
| 283 | $assoc_option_hash{"measure"} = $opt_measure; | ||
| 284 | } | ||
| 285 | else { | ||
| 286 | $assoc_option_hash = $DEFAULT_MEASURE; | ||
| 287 | } | ||
| 288 | if(defined $opt_debug) { | ||
| 289 | $assoc_option_hash{"debug"} = $opt_debug; | ||
| 290 | } | ||
| 291 | if(defined $opt_verbose) { | ||
| 292 | $assoc_option_hash{"verbose"} = $opt_verbose; | ||
| 293 | } | ||
| 294 | if(defined $opt_username) { | ||
| 295 | $assoc_option_hash{"username"} = $opt_username; | ||
| 296 | } | ||
| 297 | if(defined $opt_driver) { | ||
| 298 | $assoc_option_hash{"driver"} = $opt_driver; | ||
| 299 | } | ||
| 300 | if(defined $opt_assocdatabase) { | ||
| 301 | $assoc_option_hash{"database"} = $opt_assocdatabase; | ||
| 302 | } | ||
| 303 | if(defined $opt_password) { | ||
| 304 | $assoc_option_hash{"password"} = $opt_password; | ||
| 305 | } | ||
| 306 | if(defined $opt_hostname) { | ||
| 307 | $assoc_option_hash{"hostname"} = $opt_hostname; | ||
| 308 | } | ||
| 309 | if(defined $opt_socket) { | ||
| 310 | $assoc_option_hash{"socket"} = $opt_socket; | ||
| 311 | } | ||
| 312 | if(defined $opt_conceptexpansion) { | ||
| 313 | $assoc_option_hash{"conceptexpansion"} = $opt_conceptexpansion; | ||
| 314 | } | ||
| 315 | if(defined $opt_precision){ | ||
| 316 | $assoc_option_hash{"precision"} = $opt_precision; | ||
| 317 | } | ||
| 318 | if(defined $opt_lta){ | ||
| 319 | $assoc_option_hash{"lta"} = $opt_lta; | ||
| 320 | } | ||
| 321 | if(defined $opt_mwa){ | ||
| 322 | $assoc_option_hash{"mwa"} = $opt_mwa; | ||
| 323 | } | ||
| 324 | if(defined $opt_vsa) { | ||
| 325 | $assoc_option_hash{"vsa"} = $opt_vsa; | ||
| 326 | } | ||
| 327 | if(defined $opt_noorder){ | ||
| 328 | $assoc_option_hash{"noorder"} = $opt_noorder; | ||
| 329 | } | ||
| 330 | if(defined $opt_matrix){ | ||
| 331 | $assoc_option_hash{"matrix"} = $opt_matrix; | ||
| 332 | } | ||
| 333 | |||
| 334 | # instantiate instance of UMLS-Assocation | ||
| 335 | my $association = UMLS::Association->new(\%assoc_option_hash); | ||
| 336 | die "Unable to create UMLS::Association object.\n" if(!$association); | ||
| 337 | |||
| 338 | |||
| 339 | ############################################# | ||
| 340 | # Calculate Association | ||
| 341 | ############################################# | ||
| 342 | |||
| 343 | my $score = $association->calculateAssociation_termPair($cui1, $cui2, $assoc_option_hash{"measure"}); | ||
| 344 | print "$score<>$cui1<>$cui2\n"; | ||
| 345 | |||
| 346 | ############################################################################## | ||
| 347 | # function to output minimal usage notes | ||
| 348 | ############################################################################## | ||
| 349 | sub minimalUsageNotes { | ||
| 350 | print "Usage: umls-association.pl [OPTIONS] [TERM1 TERM2] [CUI1 CUI2]\n"; | ||
| 351 | &askHelp(); | ||
| 352 | exit; | ||
| 353 | } | ||
| 354 | |||
| 355 | ############################################################################## | ||
| 356 | # function to output help messages for this program | ||
| 357 | ############################################################################## | ||
| 358 | sub showHelp() { | ||
| 359 | |||
| 360 | print "This is a utility that takes as input either two terms \n"; | ||
| 361 | print "or two CUIs from the command line or a file and returns \n"; | ||
| 362 | print "their association using one of the following measures: \n"; | ||
| 363 | |||
| 364 | print "1. Dice Coefficient (dice) \n"; | ||
| 365 | print "2. Fishers exact test - left sided (left)\n"; | ||
| 366 | print "3. Fishers exact test - right sided (right)\n"; | ||
| 367 | print "4. Fishers twotailed test - right sided (twotailed)\n"; | ||
| 368 | print "5. Jaccard Coefficient (jaccard)\n"; | ||
| 369 | print "6. Log-likelihood ratio (ll)\n"; | ||
| 370 | print "7. Mutual Information (tmi)\n"; | ||
| 371 | print "8. Odds Ratio (oods)\n"; | ||
| 372 | print "9. Pointwise Mutual Information (pmi)\n"; | ||
| 373 | print "10. Phi Coefficient (phi)\n"; | ||
| 374 | print "11. Pearson's Chi Squared Test (chi)\n"; | ||
| 375 | print "12. Poisson Stirling Measure (ps)\n"; | ||
| 376 | print "13. T-score (tscore) DEFAULT\n\n"; | ||
| 377 | |||
| 378 | print "Usage: umls-assocation.pl [OPTIONS] TERM1 TERM2\n\n"; | ||
| 379 | |||
| 380 | print "General Options:\n\n"; | ||
| 381 | |||
| 382 | print "--measure MEASURE The measure to use to calculate the\n"; | ||
| 383 | print " assocation. (DEFAULT: tscore)\n\n"; | ||
| 384 | |||
| 385 | print "--precision N Displays values up to N places of decimal. (DEFAULT: 4)\n\n"; | ||
| 386 | |||
| 387 | print "--version Prints the version number\n\n"; | ||
| 388 | |||
| 389 | print "--help Prints this help message.\n\n"; | ||
| 390 | |||
| 391 | print "--conceptexpansion Calculates the association score taking into account | ||
| 392 | the occurrences of descendants of the specified CUIs.\n\n"; | ||
| 393 | |||
| 394 | print "--lta Linking Term Association - Calculates the association scores using implicit | ||
| 395 | or intermediate relationships between the specified CUIs, and the count | ||
| 396 | of unique shared co-occurrences. \n\n"; | ||
| 397 | |||
| 398 | print "--mwa Minimum Weight Association - Calculates the association scores using implicit | ||
| 399 | or intermediate relationships between the specified CUIs, and the minimum | ||
| 400 | of co-occurrence count between shared co-occurrences. \n\n"; | ||
| 401 | |||
| 402 | print "--vsa Vector Set Association - Calculates the association scores using the | ||
| 403 | association between the sets of co-occurring terms of the original terms\n\n"; | ||
| 404 | |||
| 405 | print "--noorder If selected, the order in which CUIs appear will be disregarded when the association | ||
| 406 | score is calculated.\n\n"; | ||
| 407 | |||
| 408 | print "--config FILE Configuration file\n\n"; | ||
| 409 | |||
| 410 | print "\n\nInput Options: \n\n"; | ||
| 411 | |||
| 412 | print "\n\nGeneral Database Options:\n\n"; | ||
| 413 | |||
| 414 | print "--username STRING Username required to access mysql\n\n"; | ||
| 415 | |||
| 416 | print "--password STRING Password required to access mysql\n\n"; | ||
| 417 | |||
| 418 | print "--hostname STRING Hostname for mysql (DEFAULT: localhost)\n\n"; | ||
| 419 | print "--socket STRING Socket for mysql (DEFAULT: /tmp/mysql.sock\n\n"; | ||
| 420 | |||
| 421 | print "\n\nUMLS-Interface Database Options: \n\n"; | ||
| 422 | |||
| 423 | print "--matrix FILE File name containing co-occurrence data in sparse matrix format | ||
| 424 | This is an alternative to storing in a database, but will be | ||
| 425 | slower for single queries, but much faster for multiple queries. | ||
| 426 | File should should be sparse format of the form CUI1\tCUI2\tvalue\\n \n\n"; | ||
| 427 | |||
| 428 | print "--umlsdatabase STRING Database contain UMLS (DEFAULT: umls)\n\n"; | ||
| 429 | |||
| 430 | print "\n\nUMLS-Association Database Options: \n\n"; | ||
| 431 | |||
| 432 | print "--assocdatabase STRING Database containing CUI bigrams | ||
| 433 | (DEFAULT: CUI_BIGRAMS)\n\n"; | ||
| 434 | } | ||
| 435 | ############################################################################## | ||
| 436 | # function to output the version number | ||
| 437 | ############################################################################## | ||
| 438 | sub showVersion { | ||
| 439 | print "current version is ".(Association->version())."\n"; | ||
| 440 | exit; | ||
| 441 | } | ||
| 442 | |||
| 443 | ############################################################################## | ||
| 444 | # function to output "ask for help" message when user's goofed | ||
| 445 | ############################################################################## | ||
| 446 | sub askHelp { | ||
| 447 | print STDERR "Type umls-association.pl --help for help.\n"; | ||
| 448 | } | ||
| 449 |