blib/script/getStString.pl untested

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