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