| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | findShortestPath.pl - This program finds the shoretest path between two | ||||||||||||||||||||||||||||
| 6 | concepts. | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | This program takes two terms or CUIs and returns the shortest | ||||||||||||||||||||||||||||
| 11 | path between them. | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 USAGE | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | Usage: findShortestPath.pl [OPTIONS] [CUI1|TERM1] [CUI2|TERM2] | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =head1 INPUT | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =head2 Required Arguments: | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =head3 [CUI1|TERM1|ST1] [CUI2|TERM2|ST2] | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | A TERM or CUI (or some combination), or two semantic types (with the --st option) | ||||||||||||||||||||||||||||
| 24 | from the Unified Medical Language System | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =head2 Optional Arguments: | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =head3 --st | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | The input is two seamntic types and the shortest path between them comes | ||||||||||||||||||||||||||||
| 31 | from the semantic network. This can either be a TUI or the Abbreviation | ||||||||||||||||||||||||||||
| 32 | of the semantic type. | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =head3 --config FILE | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | This is the configuration file. The format of the configuration | ||||||||||||||||||||||||||||
| 37 | file is as follows: | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | SAB :: <include|exclude> <source1, source2, ... sourceN> | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | REL :: <include|exclude> <relation1, relation2, ... relationN> | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | RELA :: <include|exclude> <rela1, rela2, ... relaN> (optional) | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | For example, if we wanted to use the MSH vocabulary with only | ||||||||||||||||||||||||||||
| 46 | the RB/RN relations, the configuration file would be: | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | SAB :: include MSH | ||||||||||||||||||||||||||||
| 49 | REL :: include RB, RN | ||||||||||||||||||||||||||||
| 50 | RELA :: include inverse_isa, isa | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | or | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | SAB :: include MSH | ||||||||||||||||||||||||||||
| 55 | REL :: exclude PAR, CHD | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | If you go to the configuration file directory, there will | ||||||||||||||||||||||||||||
| 58 | be example configuration files for the different runs that | ||||||||||||||||||||||||||||
| 59 | you have performed. | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =head3 --undirected | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | The path between the concepts is not required to be directed such | ||||||||||||||||||||||||||||
| 64 | that an LCS can be obtained. This means that we can obtain a path | ||||||||||||||||||||||||||||
| 65 | from CUI1 to CUI2 by meandering through the graph rather than | ||||||||||||||||||||||||||||
| 66 | finding the CUI that subsumes both of them and then finding the | ||||||||||||||||||||||||||||
| 67 | shortest path between those points. | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =head3 --info | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | This prints out the relation and source information between the | ||||||||||||||||||||||||||||
| 72 | CUIs in the path | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =head3 --icpropagation FILE | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | Takes in a propagation file and then outputs the information | ||||||||||||||||||||||||||||
| 77 | content of the CUIs in the shortest path | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =head3 --length | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | Prints out the length of the shortest path for ease of counting | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =head3 --infile FILE | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | A file containing pairs of concepts or terms in the following format: | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | term1<>term2 | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | or | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | cui1<>cui2 | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | or | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | cui1<>term2 | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | or | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | term1<>cui2 | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =head3 --debug | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | Sets the debug flag for testing | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =head3 --username STRING | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | Username is required to access the umls database on MySql | ||||||||||||||||||||||||||||
| 108 | unless it was specified in the my.cnf file at installation | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =head3 --password STRING | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | Password is required to access the umls database on MySql | ||||||||||||||||||||||||||||
| 113 | unless it was specified in the my.cnf file at installation | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | =head3 --hostname STRING | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | Hostname where mysql is located. DEFAULT: localhost | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | =head3 --socket STRING | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | The socket your mysql is using. DEFAULT: /tmp/mysql.sock | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =head3 --database STRING | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | Database contain UMLS DEFAULT: umls | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | =head3 --realtime | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | This option will not create a database of the path information | ||||||||||||||||||||||||||||
| 130 | for all of concepts in the specified set of sources and relations | ||||||||||||||||||||||||||||
| 131 | in the config file but obtain the information for just the | ||||||||||||||||||||||||||||
| 132 | input concept | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | =head3 --forcerun | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | This option will bypass any command prompts such as asking | ||||||||||||||||||||||||||||
| 137 | if you would like to continue with the index creation. | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | =head3 --debugpath FILE | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | This option prints out the path information for debugging | ||||||||||||||||||||||||||||
| 142 | purposes. This option is only really available with the | ||||||||||||||||||||||||||||
| 143 | --reatime option because otherwise the path information is | ||||||||||||||||||||||||||||
| 144 | stored in the database. You can get this information in a | ||||||||||||||||||||||||||||
| 145 | file if you use the --verbose option while creating the index. | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | =head3 --verbose | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | This option will print out the table information to the | ||||||||||||||||||||||||||||
| 151 | config directory that you specified. | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =head3 --cuilist FILE | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | This option takes in a file containing a list of CUIs (one CUI | ||||||||||||||||||||||||||||
| 156 | per line) and stores only the path information for those CUIs | ||||||||||||||||||||||||||||
| 157 | rather than for all of the CUIs given the specified set of | ||||||||||||||||||||||||||||
| 158 | sources and relations | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | =head3 --help | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | Displays the quick summary of program options. | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | =head3 --version | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | Displays the version information. | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | =head1 OUTPUT | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | The path(s) between the two given CUIs or terms | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | =head1 SYSTEM REQUIREMENTS | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | =over | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | =item * Perl (version 5.8.5 or better) - http://www.perl.org | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | =back | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | Bridget T. McInnes, University of Minnesota | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | Copyright (c) 2007-2009, | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | Bridget T. McInnes, University of Minnesota | ||||||||||||||||||||||||||||
| 189 | bthomson at cs.umn.edu | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | Ted Pedersen, University of Minnesota Duluth | ||||||||||||||||||||||||||||
| 192 | tpederse at d.umn.edu | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | Siddharth Patwardhan, University of Utah, Salt Lake City | ||||||||||||||||||||||||||||
| 195 | sidd@cs.utah.edu | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | Serguei Pakhomov, University of Minnesota Twin Cities | ||||||||||||||||||||||||||||
| 198 | pakh0002@umn.edu | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | This program is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 201 | the terms of the GNU General Public License as published by the Free Software | ||||||||||||||||||||||||||||
| 202 | Foundation; either version 2 of the License, or (at your option) any later | ||||||||||||||||||||||||||||
| 203 | version. | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | This program is distributed in the hope that it will be useful, but WITHOUT | ||||||||||||||||||||||||||||
| 206 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||||||||||||||||||||||||||||
| 207 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | You should have received a copy of the GNU General Public License along with | ||||||||||||||||||||||||||||
| 210 | this program; if not, write to: | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | The Free Software Foundation, Inc., | ||||||||||||||||||||||||||||
| 213 | 59 Temple Place - Suite 330, | ||||||||||||||||||||||||||||
| 214 | Boston, MA 02111-1307, USA. | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | =cut | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | ############################################################################### | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | # THE CODE STARTS HERE | ||||||||||||||||||||||||||||
| 221 | ############################################################################### | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | # ================================ | ||||||||||||||||||||||||||||
| 224 | # COMMAND LINE OPTIONS AND USAGE | ||||||||||||||||||||||||||||
| 225 | # ================================ | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 3 | ▶ | use UMLS::Interface; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 228 | 3 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 3 | ▶ | eval(GetOptions( "version", "help", "username=s", "password=s", "hostname=s", "database=s", "socket=s", "config=s", "cui", "infile=s", "forcerun", "verbose", "debugpath=s", "cuilist=s", "realtime", "debug", "icpropagation=s", "length", "info", "undirected", "st")) or die ("Please check the above mentioned option(s).\n"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | # if help is defined, print out help | ||||||||||||||||||||||||||||
| 234 | 3 | ▶ | if( defined $opt_help ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 235 | 0 | $opt_help = 1; | |||||||||||||||||||||||||||
| 236 | 0 | &showHelp(); | |||||||||||||||||||||||||||
| 237 | 0 | exit; | |||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | # if version is requested, show version | ||||||||||||||||||||||||||||
| 241 | 3 | ▶ | if( defined $opt_version ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 242 | 0 | $opt_version = 1; | |||||||||||||||||||||||||||
| 243 | 0 | &showVersion(); | |||||||||||||||||||||||||||
| 244 | 0 | exit; | |||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | # the --info option is only available for the CUI heirarchy | ||||||||||||||||||||||||||||
| 248 | 3 | ▶ | if( (defined $opt_st) && (defined $opt_info) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $opt_st and defined $opt_info
MC/DC0%0/2
defined $opt_st and defined $opt_info
defined $opt_st
defined $opt_info
Truth table33%1/3
A and B
A= defined $opt_stB= defined $opt_info
| |||||||||||||||||||||||||||||
| 249 | 0 | print STDERR "The --info option is not available for the semantic network.\n"; | |||||||||||||||||||||||||||
| 250 | 0 | &minimalUsageNotes(); | |||||||||||||||||||||||||||
| 251 | 0 | exit; | |||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | 3 | my @fileArray = (); | |||||||||||||||||||||||||||
| 255 | 3 | ▶ | if(defined $opt_infile) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 256 | 0 | ▶ | open(FILE, $opt_infile) || die "Could not open infile: $opt_infile\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 257 | 0 | ▶ | while(<FILE>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 258 | 0 | chomp; | |||||||||||||||||||||||||||
| 259 | 0 | ▶ | if($_=~/^\s*$/) { next; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 260 | 0 | push @fileArray, $_; | |||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||
| 262 | 0 | close FILE; | |||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||
| 264 | else { | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | # At least 2 terms and/or cuis should be given on the command line. | ||||||||||||||||||||||||||||
| 267 | 3 | ▶ | if(scalar(@ARGV) < 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 268 | 2 | print STDERR "Two terms and/or CUIs are required\n"; | |||||||||||||||||||||||||||
| 269 | 2 | &minimalUsageNotes(); | |||||||||||||||||||||||||||
| 270 | 0 | exit; | |||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 1 | my $i1 = shift; | |||||||||||||||||||||||||||
| 275 | 1 | my $i2 = shift; | |||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | 1 | my $string = "$i1<>$i2"; | |||||||||||||||||||||||||||
| 278 | 1 | push @fileArray, $string; | |||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | 1 | my $umls = ""; | |||||||||||||||||||||||||||
| 282 | 1 | my %option_hash = (); | |||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | 1 | ▶ | if(defined $opt_icpropagation) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 285 | 0 | $option_hash{"icpropagation"} = $opt_icpropagation; | |||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||
| 287 | 1 | ▶ | if(defined $opt_debug) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 288 | 0 | $option_hash{"debug"} = $opt_debug; | |||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||
| 290 | 1 | ▶ | if(defined $opt_realtime) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 291 | 0 | $option_hash{"realtime"} = $opt_realtime; | |||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||
| 293 | 1 | ▶ | if(defined $opt_undirected) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 294 | 0 | $option_hash{"undirected"} = $opt_undirected; | |||||||||||||||||||||||||||
| 295 | 0 | $option_hash{"realtime"} = 1; | |||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||
| 297 | 1 | ▶ | if(defined $opt_config) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 298 | 0 | $option_hash{"config"} = $opt_config; | |||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||
| 300 | 1 | ▶ | if(defined $opt_forcerun) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 301 | 0 | $option_hash{"forcerun"} = $opt_forcerun; | |||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||
| 303 | 1 | ▶ | if(defined $opt_debugpath) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 304 | 0 | $option_hash{"debugpath"} = $opt_debugpath; | |||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||
| 306 | 1 | ▶ | if(defined $opt_verbose) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 307 | 0 | $option_hash{"verbose"} = $opt_verbose; | |||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||
| 309 | 1 | ▶ | if(defined $opt_cuilist) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 310 | 0 | $option_hash{"cuilist"} = $opt_cuilist; | |||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||
| 312 | 1 | ▶ | if(defined $opt_username) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 313 | 0 | $option_hash{"username"} = $opt_username; | |||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||
| 315 | 1 | ▶ | if(defined $opt_driver) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 316 | 0 | $option_hash{"driver"} = $opt_driver; | |||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | 1 | ▶ | if(defined $opt_database) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 319 | 0 | $option_hash{"database"} = $opt_database; | |||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||
| 321 | 1 | ▶ | if(defined $opt_password) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 322 | 0 | $option_hash{"password"} = $opt_password; | |||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||
| 324 | 1 | ▶ | if(defined $opt_hostname) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 325 | 0 | $option_hash{"hostname"} = $opt_hostname; | |||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||
| 327 | 1 | ▶ | if(defined $opt_socket) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 328 | 0 | $option_hash{"socket"} = $opt_socket; | |||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | 1 | $umls = UMLS::Interface->new(\%option_hash); | |||||||||||||||||||||||||||
| 332 | 0 | ▶ | die "Unable to create UMLS::Interface object.\n" if(!$umls); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | 0 | foreach my $element (@fileArray) { | |||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | 0 | my ($input1, $input2) = split/<>/, $element; | |||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | 0 | my $flag1 = "cui"; | |||||||||||||||||||||||||||
| 339 | 0 | my $flag2 = "cui"; | |||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | 0 | my $c1 = undef; my $c2 = undef; | |||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | 0 | ▶ | if(defined $opt_st) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 344 | 0 | ▶ | if($input1=~/T[0-9]+/) { push @{$c1}, $input1; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 345 | 0 | else { push @{$c1}, $umls->getStTui($input1); $flag1 = "term"; } | |||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | 0 | ▶ | if($input2=~/T[0-9]+/) { push @{$c2}, $input2; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 348 | 0 | else { push @{$c2}, $umls->getStTui($input2); $flag2 = "term"; } | |||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||
| 350 | else { | ||||||||||||||||||||||||||||
| 351 | 0 | ▶ | if( ($input1=~/C[0-9]+/)) { push @{$c1}, $input1; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 352 | 0 | else { $c1 = $umls->getConceptList($input1); $flag1 = "term"; } | |||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | 0 | ▶ | if( ($input2=~/C[0-9]+/)) { push @{$c2}, $input2; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 355 | 0 | else { $c2 = $umls->getConceptList($input2); $flag2 = "term"; } | |||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | 0 | my $printFlag = 0; | |||||||||||||||||||||||||||
| 360 | 0 | my $precision = 4; | |||||||||||||||||||||||||||
| 361 | 0 | my $floatformat = join '', '%', '.', $precision, 'f'; | |||||||||||||||||||||||||||
| 362 | 0 | foreach $cui1 (@{$c1}) { | |||||||||||||||||||||||||||
| 363 | 0 | foreach $cui2 (@{$c2}) { | |||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | 0 | my $t1 = $input1; | |||||||||||||||||||||||||||
| 366 | 0 | my $t2 = $input2; | |||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | 0 | ▶ | if($flag1 eq "cui") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 369 | 0 | ▶ | if($opt_st) { $t1 = $umls->getStAbr($cui1); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 370 | 0 | else { my $ts1 = $umls->getTermList($cui1); $t1 = shift @{$ts1}; } | |||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||
| 372 | 0 | ▶ | if($flag2 eq "cui") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 373 | 0 | ▶ | if($opt_st) { $t2 = $umls->getStAbr($cui2); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 374 | 0 | else { my $ts2 = $umls->getTermList($cui2); $t2 = shift @{$ts2}; } | |||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | 0 | my @shortestpaths = (); | |||||||||||||||||||||||||||
| 378 | 0 | ▶ | if($cui1 eq $cui2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 379 | 0 | my $path = "$cui1 $cui2"; | |||||||||||||||||||||||||||
| 380 | 0 | push @shortestpaths, $path; | |||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||
| 382 | else { | ||||||||||||||||||||||||||||
| 383 | 0 | ▶ | if(defined $opt_st) { $shortestpaths = $umls->stFindShortestPath($cui1, $cui2); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 384 | 0 | else { $shortestpaths = $umls->findShortestPath($cui1, $cui2); } | |||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | 0 | foreach my $path (@{$shortestpaths}) { | |||||||||||||||||||||||||||
| 388 | 0 | my @shortestpath = split/\s+/, $path; | |||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | 0 | my $length = $#shortestpath + 1; | |||||||||||||||||||||||||||
| 392 | 0 | print "\nThe shortest path "; | |||||||||||||||||||||||||||
| 393 | 0 | ▶ | if(defined $opt_length) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 394 | 0 | print "(length: $length) "; | |||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||
| 396 | 0 | print "between $t1 ($cui1) and $t2 ($cui2):\n"; | |||||||||||||||||||||||||||
| 397 | 0 | print " => "; | |||||||||||||||||||||||||||
| 398 | 0 | foreach my $i (0..$#shortestpath) { | |||||||||||||||||||||||||||
| 399 | # get the concept | ||||||||||||||||||||||||||||
| 400 | 0 | my $concept = $shortestpath[$i]; | |||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | # get one of the terms associated with the concept/st | ||||||||||||||||||||||||||||
| 403 | 0 | my $t = ""; | |||||||||||||||||||||||||||
| 404 | 0 | ▶ | if(defined $opt_st) { $t = $umls->getStAbr($concept); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 405 | 0 | else { $t = $umls->getAllPreferredTerm($concept); } | |||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | # print out the concept | ||||||||||||||||||||||||||||
| 408 | 0 | print "$concept ($t) "; | |||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | # if the propagation option was defined print out | ||||||||||||||||||||||||||||
| 411 | # the propagation count and IC count | ||||||||||||||||||||||||||||
| 412 | 0 | ▶ | if(defined $opt_icpropagation) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 413 | 0 | my $value = ""; | |||||||||||||||||||||||||||
| 414 | 0 | ▶ | if(defined $opt_st) { $value = $umls->getStIC($concept); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 415 | 0 | else { $value = $umls->getIC($concept); } | |||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||
| 417 | 0 | my $ic = sprintf $floatformat, $value; | |||||||||||||||||||||||||||
| 418 | 0 | print "($ic) "; | |||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | # if the info option was defined print out | ||||||||||||||||||||||||||||
| 422 | # the relation and source information | ||||||||||||||||||||||||||||
| 423 | 0 | ▶ | if(!defined $opt_st) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 424 | 0 | ▶ | if( (defined $opt_info) and ($i < $#shortestpath) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $opt_info and $i < $#shortestpath
MC/DC0%0/2
defined $opt_info and $i < $#shortestpath
defined $opt_info
$i < $#shortestpath
Truth table0%0/3
A and B
A= defined $opt_infoB= $i < $#shortestpath
| |||||||||||||||||||||||||||||
| 425 | 0 | my $second = $shortestpath[$i+1]; | |||||||||||||||||||||||||||
| 426 | 0 | my $relations = $umls->getRelationsBetweenCuis($concept, $second); | |||||||||||||||||||||||||||
| 427 | 0 | print " => @{$relations} => "; | |||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||
| 431 | 0 | print "\n"; | |||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | 0 | $printFlag = 1; | |||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | 0 | ▶ | if( !($printFlag) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 439 | 0 | print "\n"; | |||||||||||||||||||||||||||
| 440 | 0 | print "There is not a path between $input1 and $input2\n"; | |||||||||||||||||||||||||||
| 441 | 0 | print "given the current view of the UMLS.\n\n"; | |||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | ############################################################################## | ||||||||||||||||||||||||||||
| 446 | # function to output minimal usage notes | ||||||||||||||||||||||||||||
| 447 | ############################################################################## | ||||||||||||||||||||||||||||
| 448 | sub minimalUsageNotes { | ||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | 2 | ▶ | print "Usage: findShortestPath.pl [OPTIONS] [CUI1|TERM1] [CUI2|TERM2]\n"; | ||||||||||||||||||||||||||
|
Subroutine
minimalUsageNotes: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 451 | 2 | &askHelp(); | |||||||||||||||||||||||||||
| 452 | 2 | exit; | |||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | ############################################################################## | ||||||||||||||||||||||||||||
| 456 | # function to output help messages for this program | ||||||||||||||||||||||||||||
| 457 | ############################################################################## | ||||||||||||||||||||||||||||
| 458 | sub showHelp() { | ||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | 0 | ▶ | print "This is a utility that takes as input two Terms or\n"; | ||||||||||||||||||||||||||
|
Subroutine
showHelp: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 462 | 0 | print "CUIs and returns the shortest path between them.\n\n"; | |||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | 0 | print "Usage: findShortestPath.pl [OPTIONS] [CUI1|TERM1] [CUI2|TERM2]\n\n"; | |||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | 0 | print "Options:\n\n"; | |||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||
| 468 | 0 | print "--undirected The path between the concepts is not \n"; | |||||||||||||||||||||||||||
| 469 | 0 | print " required to be directed.\n\n"; | |||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||
| 471 | 0 | print "--info Outputs the source and relation information\n"; | |||||||||||||||||||||||||||
| 472 | 0 | print " between the concepts in the path\n\n"; | |||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||
| 474 | 0 | print "--icpropagation FILE Outputs the information content (IC) of\n"; | |||||||||||||||||||||||||||
| 475 | 0 | print " the CUIs in the path\n\n"; | |||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||
| 477 | 0 | print "--infile FILE File containing TERM or CUI pairs\n\n"; | |||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||
| 479 | 0 | print "--debug Sets the debug flag for testing\n\n"; | |||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||
| 481 | 0 | print "--username STRING Username required to access mysql\n\n"; | |||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | 0 | print "--password STRING Password required to access mysql\n\n"; | |||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | 0 | print "--hostname STRING Hostname for mysql (DEFAULT: localhost)\n\n"; | |||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||
| 487 | 0 | print "--database STRING Database contain UMLS (DEFAULT: umls)\n\n"; | |||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||
| 489 | 0 | print "--socket STRING Socket used by mysql (DEFAULT: /tmp.mysql.sock)\n\n"; | |||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | 0 | print "--config FILE Configuration file\n\n"; | |||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||
| 493 | 0 | print "--realtime | |||||||||||||||||||||||||||
| 494 | This option will not create a database of the\n"; | ||||||||||||||||||||||||||||
| 495 | 0 | print " path information for all of concepts but just\n"; | |||||||||||||||||||||||||||
| 496 | 0 | print " obtain the information for the input concept\n\n"; | |||||||||||||||||||||||||||
| 497 | 0 | print "--forcerun This option will bypass any command \n"; | |||||||||||||||||||||||||||
| 498 | 0 | print " prompts such as asking if you would \n"; | |||||||||||||||||||||||||||
| 499 | 0 | print " like to continue with the index \n"; | |||||||||||||||||||||||||||
| 500 | 0 | print " creation. \n\n"; | |||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||
| 502 | 0 | print "--debugpath FILE This option prints out the path\n"; | |||||||||||||||||||||||||||
| 503 | 0 | print " information for debugging purposes\n\n"; | |||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||
| 505 | 0 | print "--verbose This option prints out the path information\n"; | |||||||||||||||||||||||||||
| 506 | 0 | print " to a file in your config directory.\n\n"; | |||||||||||||||||||||||||||
| 507 | 0 | print "--cuilist FILE This option takes in a file containing a \n"; | |||||||||||||||||||||||||||
| 508 | 0 | print " list of CUIs (one CUI per line) and stores\n"; | |||||||||||||||||||||||||||
| 509 | 0 | print " only the path information for those CUIs\n"; | |||||||||||||||||||||||||||
| 510 | 0 | print " rather than for all of the CUIs\n\n"; | |||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||
| 512 | 0 | print "--version Prints the version number\n\n"; | |||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||
| 514 | 0 | print "--help Prints this help message.\n\n"; | |||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||
| 517 | ############################################################################## | ||||||||||||||||||||||||||||
| 518 | # function to output the version number | ||||||||||||||||||||||||||||
| 519 | ############################################################################## | ||||||||||||||||||||||||||||
| 520 | sub showVersion { | ||||||||||||||||||||||||||||
| 521 | 0 | ▶ | print '$Id: findShortestPath.pl,v 1.26 2014/06/27 00:18:32 btmcinnes Exp $'; | ||||||||||||||||||||||||||
|
Subroutine
showVersion: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 522 | 0 | print "\nCopyright (c) 2008, Ted Pedersen & Bridget McInnes\n"; | |||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||
| 525 | ############################################################################## | ||||||||||||||||||||||||||||
| 526 | # function to output "ask for help" message when user's goofed | ||||||||||||||||||||||||||||
| 527 | ############################################################################## | ||||||||||||||||||||||||||||
| 528 | sub askHelp { | ||||||||||||||||||||||||||||
| 529 | 2 | ▶ | print STDERR "Type findShortestPath.pl --help for help.\n"; | ||||||||||||||||||||||||||
|
Subroutine
askHelp: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||