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