| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | getChildren.pl - This program returns all of a concepts children. | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | This program takes in a cui and returns all of its children | ||
| 10 | given a specified set of sources. | ||
| 11 | |||
| 12 | =head1 USAGE | ||
| 13 | |||
| 14 | Usage: getChildren.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 children | ||
| 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 children 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 | use UMLS::Interface; | ||
| 153 | use Getopt::Long; | ||
| 154 | |||
| 155 | eval(GetOptions( "version", "help", "debug", "username=s", "password=s", "hostname=s", "database=s", "socket=s", "config=s", "file=s", "info")) or die ("Please check the above mentioned option(s).\n"); | ||
| 156 | |||
| 157 | |||
| 158 | # if help is defined, print out help | ||
| 159 | if( defined $opt_help ) { | ||
| 160 | $opt_help = 1; | ||
| 161 | &showHelp(); | ||
| 162 | exit; | ||
| 163 | } | ||
| 164 | |||
| 165 | # if version is requested, show version | ||
| 166 | if( defined $opt_version ) { | ||
| 167 | $opt_version = 1; | ||
| 168 | &showVersion(); | ||
| 169 | exit; | ||
| 170 | } | ||
| 171 | |||
| 172 | # At least 1 term should be given on the command line. | ||
| 173 | if(scalar(@ARGV) < 1) { | ||
| 174 | print STDERR "No term was specified on the command line\n"; | ||
| 175 | &minimalUsageNotes(); | ||
| 176 | exit; | ||
| 177 | } | ||
| 178 | |||
| 179 | my $umls = ""; | ||
| 180 | my %option_hash = (); | ||
| 181 | |||
| 182 | if(defined $opt_config) { | ||
| 183 | $option_hash{"config"} = $opt_config; | ||
| 184 | } | ||
| 185 | if(defined $opt_verbose) { | ||
| 186 | $option_hash{"verbose"} = $opt_verbose; | ||
| 187 | } | ||
| 188 | if(defined $opt_username) { | ||
| 189 | $option_hash{"username"} = $opt_username; | ||
| 190 | } | ||
| 191 | if(defined $opt_debug) { | ||
| 192 | $option_hash{"debug"} = $opt_debug; | ||
| 193 | } | ||
| 194 | if(defined $opt_database) { | ||
| 195 | $option_hash{"database"} = $opt_database; | ||
| 196 | } | ||
| 197 | if(defined $opt_password) { | ||
| 198 | $option_hash{"password"} = $opt_password; | ||
| 199 | } | ||
| 200 | if(defined $opt_hostname) { | ||
| 201 | $option_hash{"hostname"} = $opt_hostname; | ||
| 202 | } | ||
| 203 | if(defined $opt_socket) { | ||
| 204 | $option_hash{"socket"} = $opt_socket; | ||
| 205 | } | ||
| 206 | |||
| 207 | $umls = UMLS::Interface->new(\%option_hash); | ||
| 208 | if(!$umls) { | ||
| 209 | print STDERR "Unable to create UMLS::Interface object.\n"; | ||
| 210 | exit; | ||
| 211 | } | ||
| 212 | |||
| 213 | my @terms = (); | ||
| 214 | if(defined $opt_file) { | ||
| 215 | open(FILE, $opt_file) || die "Could not open file: $file\n"; | ||
| 216 | while(<FILE>) { | ||
| 217 | chomp; | ||
| 218 | push @terms, $_; | ||
| 219 | } | ||
| 220 | } | ||
| 221 | else { | ||
| 222 | |||
| 223 | my $input = shift; | ||
| 224 | push @terms, $input; | ||
| 225 | } | ||
| 226 | |||
| 227 | foreach my $input (@terms) { | ||
| 228 | |||
| 229 | my $term = $input; | ||
| 230 | |||
| 231 | my $c = undef; | ||
| 232 | if($input=~/C[0-9]+/) { | ||
| 233 | push @{$c}, $input; | ||
| 234 | $term = $umls->getAllPreferredTerm($input); | ||
| 235 | } | ||
| 236 | else { | ||
| 237 | $c = $umls->getConceptList($input); | ||
| 238 | } | ||
| 239 | |||
| 240 | my $printFlag = 0; | ||
| 241 | |||
| 242 | foreach my $cui (@{$c}) { | ||
| 243 | if($umls->exists($cui) == 0) { next; } | ||
| 244 | |||
| 245 | my $rchildren= $umls->getChildren($cui); | ||
| 246 | |||
| 247 | my @children = @{$rchildren}; | ||
| 248 | |||
| 249 | if($#children < 0) { | ||
| 250 | print "The term $term ($cui) does not have any children\n"; | ||
| 251 | } | ||
| 252 | else { | ||
| 253 | print "The children of $term ($cui) are: \n"; | ||
| 254 | foreach my $child (@children) { | ||
| 255 | my $list = $umls->getTermList($child); | ||
| 256 | my $t = shift @{$list}; | ||
| 257 | print " $t ($child) "; | ||
| 258 | if(defined $opt_info) { | ||
| 259 | my $relations = $umls->getRelationsBetweenCuis($cui, $child); | ||
| 260 | print " => @{$relations}"; | ||
| 261 | } | ||
| 262 | print "\n"; | ||
| 263 | } | ||
| 264 | } | ||
| 265 | $printFlag = 1; | ||
| 266 | } | ||
| 267 | |||
| 268 | if(! ($printFlag) ) { | ||
| 269 | print "Input $input does not exist in this view of the UMLS.\n"; | ||
| 270 | } | ||
| 271 | } | ||
| 272 | |||
| 273 | ############################################################################## | ||
| 274 | # function to output minimal usage notes | ||
| 275 | ############################################################################## | ||
| 276 | sub minimalUsageNotes { | ||
| 277 | |||
| 278 | print "Usage: getChildren.pl [OPTIONS] [CUI|TERM]\n"; | ||
| 279 | &askHelp(); | ||
| 280 | exit; | ||
| 281 | } | ||
| 282 | |||
| 283 | ############################################################################## | ||
| 284 | # function to output help messages for this program | ||
| 285 | ############################################################################## | ||
| 286 | sub showHelp() { | ||
| 287 | |||
| 288 | |||
| 289 | print "This is a utility that takes as input a CUI or a term\n"; | ||
| 290 | print "and returns all of its possible children given\n"; | ||
| 291 | print "a specified set of sources\n\n"; | ||
| 292 | |||
| 293 | print "Usage: getChildren.pl [OPTIONS] [CUI|TERM]\n\n"; | ||
| 294 | |||
| 295 | print "Options:\n\n"; | ||
| 296 | |||
| 297 | print "--debug Sets the debug flag for testing\n\n"; | ||
| 298 | |||
| 299 | print "--info This prints out the relation and source\n"; | ||
| 300 | print " of the children\n\n"; | ||
| 301 | |||
| 302 | print "--username STRING Username required to access mysql\n\n"; | ||
| 303 | |||
| 304 | print "--password STRING Password required to access mysql\n\n"; | ||
| 305 | |||
| 306 | print "--hostname STRING Hostname for mysql (DEFAULT: localhost)\n\n"; | ||
| 307 | |||
| 308 | print "--database STRING Database contain UMLS (DEFAULT: umls)\n\n"; | ||
| 309 | |||
| 310 | print "--socket STRING Socket used by mysql (DEFAULT: /tmp.mysql.sock)\n\n"; | ||
| 311 | |||
| 312 | print "--config FILE Configuration file\n\n"; | ||
| 313 | |||
| 314 | print "--version Prints the version number\n\n"; | ||
| 315 | |||
| 316 | print "--help Prints this help message.\n\n"; | ||
| 317 | } | ||
| 318 | |||
| 319 | ############################################################################## | ||
| 320 | # function to output the version number | ||
| 321 | ############################################################################## | ||
| 322 | sub showVersion { | ||
| 323 | print '$Id: getChildren.pl,v 1.18 2016/01/07 22:49:33 btmcinnes Exp $'; | ||
| 324 | print "\nCopyright (c) 2008, Ted Pedersen & Bridget McInnes\n"; | ||
| 325 | } | ||
| 326 | |||
| 327 | ############################################################################## | ||
| 328 | # function to output "ask for help" message when user's goofed | ||
| 329 | ############################################################################## | ||
| 330 | sub askHelp { | ||
| 331 | print STDERR "Type getChildren.pl --help for help.\n"; | ||
| 332 | } | ||
| 333 |