blib/script/getSts.pl untested

filter: Statementstmt 0.0% 0 / 111 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 10 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 167 CC 1 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", "all", "sg")) 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 !(defined $opt_all) 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 if(defined $opt_all) {
193
194 my $sts = $umls->getAllSts();
195
196 foreach my $st (@{$sts}) {
197 my $abr = $umls->getStAbr($st);
198 my $string = $umls->getStString($abr);
199 print " $string ($abr) ($st)\n";
200 }
201 exit;
202 }
203  
204 my @terms = ();
205 if(defined $opt_infile) {
206 open(INFILE, $opt_infile) || die "Could not open infile ($opt_infile)\n";
207 while(<INFILE>) {
208 chomp;
209 push @terms, $_;
210 } close INFILE;
211 }
212 else {
213 my $term = shift;
214 push @terms, $term;
215 }
216  
217 if(defined $opt_sg) {
218
219 foreach my $input (@terms) {
220
221 my $array = $umls->getStsFromSg($input);
222  
223 print "The semantic types associated with $input : \n";
224 foreach my $abr (@{$array}) {
225 my $string = $umls->getStString($abr);
226 print " $string ($abr)\n";
227 }
228
229 }
230
231 }
232 else {
233  
234 foreach my $input (@terms) {
235
236 my $c = undef;
237 if($input=~/C[0-9]/) {
238 push @{$c}, $input;
239 my $ts = $umls->getTermList($input);
240 $term = shift @{$ts};
241 }
242 else {
243 $c = $umls->getConceptList($input);
244 }
245
246 my $printFlag = 0;
247
248 foreach my $cui (@{$c}) {
249
250 my $sts = $umls->getSt($cui);
251
252 if($#{$sts} < 0) {
253 print "There are no semantic types associated with $term ($cui)\n";
254 }
255 else {
256 print "The semantic types associated with $term ($cui):\n";
257 foreach my $st (@{$sts}) {
258 my $abr = $umls->getStAbr($st);
259 my $string = $umls->getStString($abr);
260 print " $string ($abr)\n";
261 }
262 }
263 $printFlag = 1;
264 }
265
266 if(! ($printFlag) ) {
267 print "There are no semantic types associated with $input\n";
268 }
269 }
270 }
271 ##############################################################################
272 # function to output minimal usage notes
273 ##############################################################################
274 sub minimalUsageNotes {
275
276 print "Usage: getSts.pl [OPTIONS] [TERM|CUI] \n";
277 &askHelp();
278 exit;
279 }
280  
281 ##############################################################################
282 # function to output help messages for this program
283 ##############################################################################
284 sub showHelp() {
285  
286
287 print "This is a utility that takes as input a TERM or\n";
288 print "a CUI and returns all of its semantic types.\n\n";
289
290 print "Usage: getSts.pl [OPTIONS] [TERM|CUI]\n\n";
291  
292 print "Options:\n\n";
293
294 print "--infile FILE A file containing a list of concepts \n";
295 print " or terms.\n\n";
296  
297 print "--debug Sets the debug flag for testing\n\n";
298  
299 print "--username STRING Username required to access mysql\n\n";
300  
301 print "--password STRING Password required to access mysql\n\n";
302  
303 print "--hostname STRING Hostname for mysql (DEFAULT: localhost)\n\n";
304  
305 print "--database STRING Database contain UMLS (DEFAULT: umls)\n\n";
306
307 print "--socket STRING Socket used by mysql (DEFAULT: /tmp.mysql.sock)\n\n";
308  
309 print "--version Prints the version number\n\n";
310
311 print "--help Prints this help message.\n\n";
312 }
313  
314 ##############################################################################
315 # function to output the version number
316 ##############################################################################
317 sub showVersion {
318 print '$Id: getSts.pl,v 1.17 2016/07/11 16:36:48 btmcinnes Exp $';
319 print "\nCopyright (c) 2011, Ted Pedersen & Bridget McInnes\n";
320 }
321  
322 ##############################################################################
323 # function to output "ask for help" message when user's goofed
324 ##############################################################################
325 sub askHelp {
326 print STDERR "Type getSts.pl --help for help.\n";
327 }
328