| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | getStDef.pl - This program returns the definition of a semantic | ||
| 6 | type. | ||
| 7 | |||
| 8 | =head1 SYNOPSIS | ||
| 9 | |||
| 10 | This program takes in a semantic type (ST) and returns its definition. | ||
| 11 | |||
| 12 | =head1 USAGE | ||
| 13 | |||
| 14 | Usage: getStDef.pl [OPTIONS] <semantic type> | ||
| 15 | |||
| 16 | =head1 INPUT | ||
| 17 | |||
| 18 | =head2 Required Arguments: | ||
| 19 | |||
| 20 | =head3 <semantic type> | ||
| 21 | |||
| 22 | Semantic type (ST) from the Unified Medical Language System (UMLS) | ||
| 23 | |||
| 24 | =head2 Optional Arguments: | ||
| 25 | |||
| 26 | =head3 --debug | ||
| 27 | |||
| 28 | Sets the debug flag for testing | ||
| 29 | |||
| 30 | =head3 --username STRING | ||
| 31 | |||
| 32 | Username is required to access the umls database on MySql | ||
| 33 | unless it was specified in the my.cnf file at installation | ||
| 34 | |||
| 35 | =head3 --password STRING | ||
| 36 | |||
| 37 | Password is required to access the umls database on MySql | ||
| 38 | unless it was specified in the my.cnf file at installation | ||
| 39 | |||
| 40 | =head3 --hostname STRING | ||
| 41 | |||
| 42 | Hostname where mysql is located. DEFAULT: localhost | ||
| 43 | |||
| 44 | =head3 --socket STRING | ||
| 45 | |||
| 46 | The socket your mysql is using. DEFAULT: /tmp/mysql.sock | ||
| 47 | |||
| 48 | =head3 --database STRING | ||
| 49 | |||
| 50 | Database contain UMLS DEFAULT: umls | ||
| 51 | |||
| 52 | =head4 --help | ||
| 53 | |||
| 54 | Displays the quick summary of program options. | ||
| 55 | |||
| 56 | =head4 --version | ||
| 57 | |||
| 58 | Displays the version information. | ||
| 59 | |||
| 60 | =head1 OUTPUT | ||
| 61 | |||
| 62 | List of CUIs that are associated with the input term | ||
| 63 | |||
| 64 | =head1 SYSTEM REQUIREMENTS | ||
| 65 | |||
| 66 | =over | ||
| 67 | |||
| 68 | =item * Perl (version 5.8.5 or better) - http://www.perl.org | ||
| 69 | |||
| 70 | =back | ||
| 71 | |||
| 72 | =head1 AUTHOR | ||
| 73 | |||
| 74 | Bridget T. McInnes, University of Minnesota | ||
| 75 | |||
| 76 | =head1 COPYRIGHT | ||
| 77 | |||
| 78 | Copyright (c) 2007-2011, | ||
| 79 | |||
| 80 | Bridget T. McInnes, University of Minnesota | ||
| 81 | bthomson at cs.umn.edu | ||
| 82 | |||
| 83 | Ted Pedersen, University of Minnesota Duluth | ||
| 84 | tpederse at d.umn.edu | ||
| 85 | |||
| 86 | Siddharth Patwardhan, University of Utah, Salt Lake City | ||
| 87 | sidd@cs.utah.edu | ||
| 88 | |||
| 89 | Serguei Pakhomov, University of Minnesota Twin Cities | ||
| 90 | pakh0002@umn.edu | ||
| 91 | |||
| 92 | This program is free software; you can redistribute it and/or modify it under | ||
| 93 | the terms of the GNU General Public License as published by the Free Software | ||
| 94 | Foundation; either version 2 of the License, or (at your option) any later | ||
| 95 | version. | ||
| 96 | |||
| 97 | This program is distributed in the hope that it will be useful, but WITHOUT | ||
| 98 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 99 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
| 100 | |||
| 101 | You should have received a copy of the GNU General Public License along with | ||
| 102 | this program; if not, write to: | ||
| 103 | |||
| 104 | The Free Software Foundation, Inc., | ||
| 105 | 59 Temple Place - Suite 330, | ||
| 106 | Boston, MA 02111-1307, USA. | ||
| 107 | |||
| 108 | =cut | ||
| 109 | |||
| 110 | ############################################################################### | ||
| 111 | |||
| 112 | # THE CODE STARTS HERE | ||
| 113 | ############################################################################### | ||
| 114 | |||
| 115 | # ================================ | ||
| 116 | # COMMAND LINE OPTIONS AND USAGE | ||
| 117 | # ================================ | ||
| 118 | |||
| 119 | |||
| 120 | use UMLS::Interface; | ||
| 121 | use Getopt::Long; | ||
| 122 | |||
| 123 | eval(GetOptions( "version", "help", "debug", "username=s", "password=s", "hostname=s", "database=s", "socket=s")) or die ("Please check the above mentioned option(s).\n"); | ||
| 124 | |||
| 125 | |||
| 126 | # if help is defined, print out help | ||
| 127 | if( defined $opt_help ) { | ||
| 128 | $opt_help = 1; | ||
| 129 | &showHelp(); | ||
| 130 | exit; | ||
| 131 | } | ||
| 132 | |||
| 133 | # if version is requested, show version | ||
| 134 | if( defined $opt_version ) { | ||
| 135 | $opt_version = 1; | ||
| 136 | &showVersion(); | ||
| 137 | exit; | ||
| 138 | } | ||
| 139 | |||
| 140 | # At least 1 CUI should be given on the command line. | ||
| 141 | if(scalar(@ARGV) < 1) { | ||
| 142 | print STDERR "No semantic type was specified on the command line\n"; | ||
| 143 | &minimalUsageNotes(); | ||
| 144 | exit; | ||
| 145 | } | ||
| 146 | |||
| 147 | my $umls = ""; | ||
| 148 | my %option_hash = (); | ||
| 149 | |||
| 150 | if(defined $opt_verbose) { | ||
| 151 | $option_hash{"verbose"} = $opt_verbose; | ||
| 152 | } | ||
| 153 | if(defined $opt_debug) { | ||
| 154 | $option_hash{"debug"} = $opt_debug; | ||
| 155 | } | ||
| 156 | if(defined $opt_username) { | ||
| 157 | $option_hash{"username"} = $opt_username; | ||
| 158 | } | ||
| 159 | if(defined $opt_driver) { | ||
| 160 | $option_hash{"driver"} = $opt_driver; | ||
| 161 | } | ||
| 162 | if(defined $opt_database) { | ||
| 163 | $option_hash{"database"} = $opt_database; | ||
| 164 | } | ||
| 165 | if(defined $opt_password) { | ||
| 166 | $option_hash{"password"} = $opt_password; | ||
| 167 | } | ||
| 168 | if(defined $opt_hostname) { | ||
| 169 | $option_hash{"hostname"} = $opt_hostname; | ||
| 170 | } | ||
| 171 | if(defined $opt_socket) { | ||
| 172 | $option_hash{"socket"} = $opt_socket; | ||
| 173 | } | ||
| 174 | |||
| 175 | $option_hash{"t"} = 1; | ||
| 176 | $umls = UMLS::Interface->new(\%option_hash); | ||
| 177 | die "Unable to create UMLS::Interface object.\n" if(!$umls); | ||
| 178 | |||
| 179 | my $st = shift; | ||
| 180 | |||
| 181 | my $def = $umls->getStDef($st); | ||
| 182 | |||
| 183 | if($#{$def} < 0) { | ||
| 184 | print "There are no definitions for the semantic type ($st)\n"; | ||
| 185 | } | ||
| 186 | else { | ||
| 187 | print "The definition of the semantic type ($st):\n"; | ||
| 188 | print "@{$def}\n"; | ||
| 189 | } | ||
| 190 | |||
| 191 | ############################################################################## | ||
| 192 | # function to output minimal usage notes | ||
| 193 | ############################################################################## | ||
| 194 | sub minimalUsageNotes { | ||
| 195 | |||
| 196 | print "Usage: getStDef.pl [OPTIONS] <semantic type> \n"; | ||
| 197 | &askHelp(); | ||
| 198 | exit; | ||
| 199 | } | ||
| 200 | |||
| 201 | ############################################################################## | ||
| 202 | # function to output help messages for this program | ||
| 203 | ############################################################################## | ||
| 204 | sub showHelp() { | ||
| 205 | |||
| 206 | |||
| 207 | print "This is a utility that takes as input a semantic type\n"; | ||
| 208 | print "and returns its definition.\n\n"; | ||
| 209 | |||
| 210 | print "Usage: getStDef.pl [OPTIONS] <semantic type>\n\n"; | ||
| 211 | |||
| 212 | print "Options:\n\n"; | ||
| 213 | |||
| 214 | print "--debug Sets the debug flag for testing\n\n"; | ||
| 215 | |||
| 216 | print "--username STRING Username required to access mysql\n\n"; | ||
| 217 | |||
| 218 | print "--password STRING Password required to access mysql\n\n"; | ||
| 219 | |||
| 220 | print "--hostname STRING Hostname for mysql (DEFAULT: localhost)\n\n"; | ||
| 221 | |||
| 222 | print "--database STRING Database contain UMLS (DEFAULT: umls)\n\n"; | ||
| 223 | |||
| 224 | print "--socket STRING Socket used by mysql (DEFAULT: /tmp.mysql.sock)\n\n"; | ||
| 225 | |||
| 226 | print "--version Prints the version number\n\n"; | ||
| 227 | |||
| 228 | print "--help Prints this help message.\n\n"; | ||
| 229 | } | ||
| 230 | |||
| 231 | ############################################################################## | ||
| 232 | # function to output the version number | ||
| 233 | ############################################################################## | ||
| 234 | sub showVersion { | ||
| 235 | print '$Id: getStDef.pl,v 1.12 2011/08/29 16:37:03 btmcinnes Exp $'; | ||
| 236 | print "\nCopyright (c) 2011, Ted Pedersen & Bridget McInnes\n"; | ||
| 237 | } | ||
| 238 | |||
| 239 | ############################################################################## | ||
| 240 | # function to output "ask for help" message when user's goofed | ||
| 241 | ############################################################################## | ||
| 242 | sub askHelp { | ||
| 243 | print STDERR "Type getStDef.pl --help for help.\n"; | ||
| 244 | } | ||
| 245 |