| 1 | #!/usr/local/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 | use UMLS::Interface; | ||
| 152 | use Getopt::Long; | ||
| 153 | |||
| 154 | 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"); | ||
| 155 | |||
| 156 | |||
| 157 | # if help is defined, print out help | ||
| 158 | if( defined $opt_help ) { | ||
| 159 | $opt_help = 1; | ||
| 160 | &showHelp(); | ||
| 161 | exit; | ||
| 162 | } | ||
| 163 | |||
| 164 | # if version is requested, show version | ||
| 165 | if( defined $opt_version ) { | ||
| 166 | $opt_version = 1; | ||
| 167 | &showVersion(); | ||
| 168 | exit; | ||
| 169 | } | ||
| 170 | |||
| 171 | # At least 1 term should be given on the command line. | ||
| 172 | if(scalar(@ARGV) <= 1) { | ||
| 173 | print STDERR "A term and relation must be specified\n"; | ||
| 174 | &minimalUsageNotes(); | ||
| 175 | exit; | ||
| 176 | } | ||
| 177 | |||
| 178 | my $umls = ""; | ||
| 179 | my %option_hash = (); | ||
| 180 | |||
| 181 | if(defined $opt_config) { | ||
| 182 | $option_hash{"config"} = $opt_config; | ||
| 183 | } | ||
| 184 | if(defined $opt_verbose) { | ||
| 185 | $option_hash{"verbose"} = $opt_verbose; | ||
| 186 | } | ||
| 187 | if(defined $opt_debug) { | ||
| 188 | $option_hash{"debug"} = $opt_debug; | ||
| 189 | } | ||
| 190 | if(defined $opt_username) { | ||
| 191 | $option_hash{"username"} = $opt_username; | ||
| 192 | } | ||
| 193 | if(defined $opt_driver) { | ||
| 194 | $option_hash{"driver"} = $opt_driver; | ||
| 195 | } | ||
| 196 | if(defined $opt_database) { | ||
| 197 | $option_hash{"database"} = $opt_database; | ||
| 198 | } | ||
| 199 | if(defined $opt_password) { | ||
| 200 | $option_hash{"password"} = $opt_password; | ||
| 201 | } | ||
| 202 | if(defined $opt_hostname) { | ||
| 203 | $option_hash{"hostname"} = $opt_hostname; | ||
| 204 | } | ||
| 205 | if(defined $opt_socket) { | ||
| 206 | $option_hash{"socket"} = $opt_socket; | ||
| 207 | } | ||
| 208 | |||
| 209 | $umls = UMLS::Interface->new(\%option_hash); | ||
| 210 | die "Unable to create UMLS::Interface object.\n" if(!$umls); | ||
| 211 | |||
| 212 | my $input = shift; | ||
| 213 | my $rel = shift; | ||
| 214 | my $term = $input; | ||
| 215 | |||
| 216 | my $c = undef; | ||
| 217 | |||
| 218 | if($input=~/C[0-9]+/) { | ||
| 219 | push @{$c}, $input; | ||
| 220 | my $terms = $umls->getTermList($input); | ||
| 221 | $term = shift @{$terms}; | ||
| 222 | } | ||
| 223 | else { | ||
| 224 | $c = $umls->getConceptList($input); | ||
| 225 | } | ||
| 226 | |||
| 227 | my $printFlag = 0; | ||
| 228 | |||
| 229 | foreach my $cui (@{$c}) { | ||
| 230 | |||
| 231 | # make certain cui exists in this view | ||
| 232 | if($umls->exists($cui) == 0) { next; } | ||
| 233 | |||
| 234 | my $related = $umls->getRelated($cui, $rel); | ||
| 235 | |||
| 236 | if($#{$related} < 0) { | ||
| 237 | print "No CUIs are associated with $term ($cui) given the relation ($rel).\n"; | ||
| 238 | } | ||
| 239 | else { | ||
| 240 | print "The related ($rel) CUIs to $term ($cui):\n"; | ||
| 241 | foreach my $related_cui (@{$related}) { | ||
| 242 | my $ts = $umls->getTermList($related_cui); | ||
| 243 | my $t = shift @{$ts}; | ||
| 244 | print " $t ($related_cui)\n"; | ||
| 245 | } | ||
| 246 | } | ||
| 247 | $printFlag = 1; | ||
| 248 | } | ||
| 249 | |||
| 250 | if(! ($printFlag) ) { | ||
| 251 | 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 | print "Usage: getRelated.pl [OPTIONS] [CUI|TERM] REL\n"; | ||
| 262 | &askHelp(); | ||
| 263 | exit; | ||
| 264 | } | ||
| 265 | |||
| 266 | ############################################################################## | ||
| 267 | # function to output help messages for this program | ||
| 268 | ############################################################################## | ||
| 269 | sub showHelp() { | ||
| 270 | |||
| 271 | |||
| 272 | print "This is a utility that takes as input a CUI (or a \n"; | ||
| 273 | print "term) and a relation and returns all the related CUIs \n"; | ||
| 274 | print "a specified set of sources\n\n"; | ||
| 275 | |||
| 276 | print "Usage: getRelated.pl [OPTIONS] [CUI|TERM] REL\n\n"; | ||
| 277 | |||
| 278 | print "Options:\n\n"; | ||
| 279 | |||
| 280 | print "--debug Sets the debug flag for testing\n\n"; | ||
| 281 | |||
| 282 | print "--username STRING Username required to access mysql\n\n"; | ||
| 283 | |||
| 284 | print "--password STRING Password required to access mysql\n\n"; | ||
| 285 | |||
| 286 | print "--hostname STRING Hostname for mysql (DEFAULT: localhost)\n\n"; | ||
| 287 | |||
| 288 | print "--database STRING Database contain UMLS (DEFAULT: umls)\n\n"; | ||
| 289 | |||
| 290 | print "--socket STRING Socket used by mysql (DEFAULT: /tmp.mysql.sock)\n\n"; | ||
| 291 | |||
| 292 | print "--config FILE Configuration file\n\n"; | ||
| 293 | |||
| 294 | print "--version Prints the version number\n\n"; | ||
| 295 | |||
| 296 | print "--help Prints this help message.\n\n"; | ||
| 297 | } | ||
| 298 | |||
| 299 | ############################################################################## | ||
| 300 | # function to output the version number | ||
| 301 | ############################################################################## | ||
| 302 | sub showVersion { | ||
| 303 | print '$Id: getRelated.pl,v 1.13 2011/08/29 16:37:03 btmcinnes Exp $'; | ||
| 304 | 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 | print STDERR "Type getRelated.pl --help for help.\n"; | ||
| 312 | } | ||
| 313 |