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