blib/script/getSts.pl untested

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