| 1 | #!/usr/bin/perl | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | getRelated.pl - This programs returns all CUIs of a given relation. | ||||||||||
| 6 | |||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||
| 8 | |||||||||||
| 9 | This program takes in a CUI or a term and returns all of its relation | ||||||||||
| 10 | given a specified set of sources. | ||||||||||
| 11 | |||||||||||
| 12 | =head1 USAGE | ||||||||||
| 13 | |||||||||||
| 14 | Usage: getRelated.pl [OPTIONS] [CUI|TERM] REL | ||||||||||
| 15 | |||||||||||
| 16 | =head1 INPUT | ||||||||||
| 17 | |||||||||||
| 18 | =head2 Required Arguments: | ||||||||||
| 19 | |||||||||||
| 20 | =head3 [CUI|TERM] | ||||||||||
| 21 | |||||||||||
| 22 | A concept or a term from the Unified Medical Language System | ||||||||||
| 23 | |||||||||||
| 24 | =head3 REL | ||||||||||
| 25 | |||||||||||
| 26 | The relation of the given CUI or term. | ||||||||||
| 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 --debug | ||||||||||
| 58 | |||||||||||
| 59 | Sets the debug flag for testing | ||||||||||
| 60 | |||||||||||
| 61 | =head3 --username STRING | ||||||||||
| 62 | |||||||||||
| 63 | Username is required to access the umls database on MySql | ||||||||||
| 64 | unless it was specified in the my.cnf file at installation | ||||||||||
| 65 | |||||||||||
| 66 | =head3 --password STRING | ||||||||||
| 67 | |||||||||||
| 68 | Password is required to access the umls database on MySql | ||||||||||
| 69 | unless it was specified in the my.cnf file at installation | ||||||||||
| 70 | |||||||||||
| 71 | =head3 --hostname STRING | ||||||||||
| 72 | |||||||||||
| 73 | Hostname where mysql is located. DEFAULT: localhost | ||||||||||
| 74 | |||||||||||
| 75 | =head3 --socket STRING | ||||||||||
| 76 | |||||||||||
| 77 | The socket your mysql is using. DEFAULT: /tmp/mysql.sock | ||||||||||
| 78 | |||||||||||
| 79 | =head3 --database STRING | ||||||||||
| 80 | |||||||||||
| 81 | Database contain UMLS DEFAULT: umls | ||||||||||
| 82 | |||||||||||
| 83 | =head4 --help | ||||||||||
| 84 | |||||||||||
| 85 | Displays the quick summary of program options. | ||||||||||
| 86 | |||||||||||
| 87 | =head4 --version | ||||||||||
| 88 | |||||||||||
| 89 | Displays the version information. | ||||||||||
| 90 | |||||||||||
| 91 | =head1 OUTPUT | ||||||||||
| 92 | |||||||||||
| 93 | List of related CUIs | ||||||||||
| 94 | |||||||||||
| 95 | =head1 SYSTEM REQUIREMENTS | ||||||||||
| 96 | |||||||||||
| 97 | =over | ||||||||||
| 98 | |||||||||||
| 99 | =item * Perl (version 5.8.5 or better) - http://www.perl.org | ||||||||||
| 100 | |||||||||||
| 101 | =back | ||||||||||
| 102 | |||||||||||
| 103 | =head1 AUTHOR | ||||||||||
| 104 | |||||||||||
| 105 | Bridget T. McInnes, University of Minnesota | ||||||||||
| 106 | |||||||||||
| 107 | =head1 COPYRIGHT | ||||||||||
| 108 | |||||||||||
| 109 | Copyright (c) 2007-2009, | ||||||||||
| 110 | |||||||||||
| 111 | Bridget T. McInnes, University of Minnesota | ||||||||||
| 112 | bthomson at cs.umn.edu | ||||||||||
| 113 | |||||||||||
| 114 | Ted Pedersen, University of Minnesota Duluth | ||||||||||
| 115 | tpederse at d.umn.edu | ||||||||||
| 116 | |||||||||||
| 117 | Siddharth Patwardhan, University of Utah, Salt Lake City | ||||||||||
| 118 | sidd@cs.utah.edu | ||||||||||
| 119 | |||||||||||
| 120 | Serguei Pakhomov, University of Minnesota Twin Cities | ||||||||||
| 121 | pakh0002@umn.edu | ||||||||||
| 122 | |||||||||||
| 123 | This program is free software; you can redistribute it and/or modify it under | ||||||||||
| 124 | the terms of the GNU General Public License as published by the Free Software | ||||||||||
| 125 | Foundation; either version 2 of the License, or (at your option) any later | ||||||||||
| 126 | version. | ||||||||||
| 127 | |||||||||||
| 128 | This program is distributed in the hope that it will be useful, but WITHOUT | ||||||||||
| 129 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||||||||||
| 130 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||||||||||
| 131 | |||||||||||
| 132 | You should have received a copy of the GNU General Public License along with | ||||||||||
| 133 | this program; if not, write to: | ||||||||||
| 134 | |||||||||||
| 135 | The Free Software Foundation, Inc., | ||||||||||
| 136 | 59 Temple Place - Suite 330, | ||||||||||
| 137 | Boston, MA 02111-1307, USA. | ||||||||||
| 138 | |||||||||||
| 139 | =cut | ||||||||||
| 140 | |||||||||||
| 141 | ############################################################################### | ||||||||||
| 142 | |||||||||||
| 143 | # THE CODE STARTS HERE | ||||||||||
| 144 | ############################################################################### | ||||||||||
| 145 | |||||||||||
| 146 | # ================================ | ||||||||||
| 147 | # COMMAND LINE OPTIONS AND USAGE | ||||||||||
| 148 | # ================================ | ||||||||||
| 149 | |||||||||||
| 150 | |||||||||||
| 151 | 3 | ▶ | use UMLS::Interface; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 152 | 3 | ▶ | use Getopt::Long; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 153 | |||||||||||
| 154 | 3 | ▶ | 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"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 155 | |||||||||||
| 156 | |||||||||||
| 157 | # if help is defined, print out help | ||||||||||
| 158 | 3 | ▶ | if( defined $opt_help ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 159 | 0 | $opt_help = 1; | |||||||||
| 160 | 0 | &showHelp(); | |||||||||
| 161 | 0 | exit; | |||||||||
| 162 | } | ||||||||||
| 163 | |||||||||||
| 164 | # if version is requested, show version | ||||||||||
| 165 | 3 | ▶ | if( defined $opt_version ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 166 | 0 | $opt_version = 1; | |||||||||
| 167 | 0 | &showVersion(); | |||||||||
| 168 | 0 | exit; | |||||||||
| 169 | } | ||||||||||
| 170 | |||||||||||
| 171 | # At least 1 term should be given on the command line. | ||||||||||
| 172 | 3 | ▶ | if(scalar(@ARGV) <= 1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 173 | 2 | print STDERR "A term and relation must be specified\n"; | |||||||||
| 174 | 2 | &minimalUsageNotes(); | |||||||||
| 175 | 0 | exit; | |||||||||
| 176 | } | ||||||||||
| 177 | |||||||||||
| 178 | 1 | my $umls = ""; | |||||||||
| 179 | 1 | my %option_hash = (); | |||||||||
| 180 | |||||||||||
| 181 | 1 | ▶ | if(defined $opt_config) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 182 | 0 | $option_hash{"config"} = $opt_config; | |||||||||
| 183 | } | ||||||||||
| 184 | 1 | ▶ | if(defined $opt_verbose) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 185 | 0 | $option_hash{"verbose"} = $opt_verbose; | |||||||||
| 186 | } | ||||||||||
| 187 | 1 | ▶ | if(defined $opt_debug) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 188 | 0 | $option_hash{"debug"} = $opt_debug; | |||||||||
| 189 | } | ||||||||||
| 190 | 1 | ▶ | if(defined $opt_username) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 191 | 0 | $option_hash{"username"} = $opt_username; | |||||||||
| 192 | } | ||||||||||
| 193 | 1 | ▶ | if(defined $opt_driver) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 194 | 0 | $option_hash{"driver"} = $opt_driver; | |||||||||
| 195 | } | ||||||||||
| 196 | 1 | ▶ | if(defined $opt_database) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 197 | 0 | $option_hash{"database"} = $opt_database; | |||||||||
| 198 | } | ||||||||||
| 199 | 1 | ▶ | if(defined $opt_password) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 200 | 0 | $option_hash{"password"} = $opt_password; | |||||||||
| 201 | } | ||||||||||
| 202 | 1 | ▶ | if(defined $opt_hostname) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 203 | 0 | $option_hash{"hostname"} = $opt_hostname; | |||||||||
| 204 | } | ||||||||||
| 205 | 1 | ▶ | if(defined $opt_socket) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 206 | 0 | $option_hash{"socket"} = $opt_socket; | |||||||||
| 207 | } | ||||||||||
| 208 | |||||||||||
| 209 | 1 | $umls = UMLS::Interface->new(\%option_hash); | |||||||||
| 210 | 0 | ▶ | die "Unable to create UMLS::Interface object.\n" if(!$umls); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 211 | |||||||||||
| 212 | 0 | my $input = shift; | |||||||||
| 213 | 0 | my $rel = shift; | |||||||||
| 214 | 0 | my $term = $input; | |||||||||
| 215 | |||||||||||
| 216 | 0 | my $c = undef; | |||||||||
| 217 | |||||||||||
| 218 | 0 | ▶ | if($input=~/C[0-9]+/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 219 | 0 | push @{$c}, $input; | |||||||||
| 220 | 0 | my $terms = $umls->getTermList($input); | |||||||||
| 221 | 0 | $term = shift @{$terms}; | |||||||||
| 222 | } | ||||||||||
| 223 | else { | ||||||||||
| 224 | 0 | $c = $umls->getConceptList($input); | |||||||||
| 225 | } | ||||||||||
| 226 | |||||||||||
| 227 | 0 | my $printFlag = 0; | |||||||||
| 228 | |||||||||||
| 229 | 0 | foreach my $cui (@{$c}) { | |||||||||
| 230 | |||||||||||
| 231 | # make certain cui exists in this view | ||||||||||
| 232 | 0 | ▶ | if($umls->exists($cui) == 0) { next; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 233 | |||||||||||
| 234 | 0 | my $related = $umls->getRelated($cui, $rel); | |||||||||
| 235 | |||||||||||
| 236 | 0 | ▶ | if($#{$related} < 0) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 237 | 0 | print "No CUIs are associated with $term ($cui) given the relation ($rel).\n"; | |||||||||
| 238 | } | ||||||||||
| 239 | else { | ||||||||||
| 240 | 0 | print "The related ($rel) CUIs to $term ($cui):\n"; | |||||||||
| 241 | 0 | foreach my $related_cui (@{$related}) { | |||||||||
| 242 | 0 | my $ts = $umls->getTermList($related_cui); | |||||||||
| 243 | 0 | my $t = shift @{$ts}; | |||||||||
| 244 | 0 | print " $t ($related_cui)\n"; | |||||||||
| 245 | } | ||||||||||
| 246 | } | ||||||||||
| 247 | 0 | $printFlag = 1; | |||||||||
| 248 | } | ||||||||||
| 249 | |||||||||||
| 250 | 0 | ▶ | if(! ($printFlag) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 251 | 0 | print "No CUIs are associated with $input given the relation ($rel).\n"; | |||||||||
| 252 | } | ||||||||||
| 253 | |||||||||||
| 254 | |||||||||||
| 255 | |||||||||||
| 256 | ############################################################################## | ||||||||||
| 257 | # function to output minimal usage notes | ||||||||||
| 258 | ############################################################################## | ||||||||||
| 259 | sub minimalUsageNotes { | ||||||||||
| 260 | |||||||||||
| 261 | 2 | ▶ | print "Usage: getRelated.pl [OPTIONS] [CUI|TERM] REL\n"; | ||||||||
|
Subroutine
minimalUsageNotes: called CC=1 SCAR=0.0
| |||||||||||
| 262 | 2 | &askHelp(); | |||||||||
| 263 | 2 | exit; | |||||||||
| 264 | } | ||||||||||
| 265 | |||||||||||
| 266 | ############################################################################## | ||||||||||
| 267 | # function to output help messages for this program | ||||||||||
| 268 | ############################################################################## | ||||||||||
| 269 | sub showHelp() { | ||||||||||
| 270 | |||||||||||
| 271 | |||||||||||
| 272 | 0 | ▶ | print "This is a utility that takes as input a CUI (or a \n"; | ||||||||
|
Subroutine
showHelp: not called CC=1 SCAR=6.9
| |||||||||||
| 273 | 0 | print "term) and a relation and returns all the related CUIs \n"; | |||||||||
| 274 | 0 | print "a specified set of sources\n\n"; | |||||||||
| 275 | |||||||||||
| 276 | 0 | print "Usage: getRelated.pl [OPTIONS] [CUI|TERM] REL\n\n"; | |||||||||
| 277 | |||||||||||
| 278 | 0 | print "Options:\n\n"; | |||||||||
| 279 | |||||||||||
| 280 | 0 | print "--debug Sets the debug flag for testing\n\n"; | |||||||||
| 281 | |||||||||||
| 282 | 0 | print "--username STRING Username required to access mysql\n\n"; | |||||||||
| 283 | |||||||||||
| 284 | 0 | print "--password STRING Password required to access mysql\n\n"; | |||||||||
| 285 | |||||||||||
| 286 | 0 | print "--hostname STRING Hostname for mysql (DEFAULT: localhost)\n\n"; | |||||||||
| 287 | |||||||||||
| 288 | 0 | print "--database STRING Database contain UMLS (DEFAULT: umls)\n\n"; | |||||||||
| 289 | |||||||||||
| 290 | 0 | print "--socket STRING Socket used by mysql (DEFAULT: /tmp.mysql.sock)\n\n"; | |||||||||
| 291 | |||||||||||
| 292 | 0 | print "--config FILE Configuration file\n\n"; | |||||||||
| 293 | |||||||||||
| 294 | 0 | print "--version Prints the version number\n\n"; | |||||||||
| 295 | |||||||||||
| 296 | 0 | print "--help Prints this help message.\n\n"; | |||||||||
| 297 | } | ||||||||||
| 298 | |||||||||||
| 299 | ############################################################################## | ||||||||||
| 300 | # function to output the version number | ||||||||||
| 301 | ############################################################################## | ||||||||||
| 302 | sub showVersion { | ||||||||||
| 303 | 0 | ▶ | print '$Id: getRelated.pl,v 1.13 2011/08/29 16:37:03 btmcinnes Exp $'; | ||||||||
|
Subroutine
showVersion: not called CC=1 SCAR=6.9
| |||||||||||
| 304 | 0 | print "\nCopyright (c) 2008, Ted Pedersen & Bridget McInnes\n"; | |||||||||
| 305 | } | ||||||||||
| 306 | |||||||||||
| 307 | ############################################################################## | ||||||||||
| 308 | # function to output "ask for help" message when user's goofed | ||||||||||
| 309 | ############################################################################## | ||||||||||
| 310 | sub askHelp { | ||||||||||
| 311 | 2 | ▶ | print STDERR "Type getRelated.pl --help for help.\n"; | ||||||||
|
Subroutine
askHelp: called CC=1 SCAR=0.0
| |||||||||||
| 312 | } | ||||||||||
| 313 | |||||||||||