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