utils/getSts.pl

filter: Statementstmt 30.5% 29 / 95 Branchbran 34.2% 13 / 38 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 66.6% 4 / 6 Podpod n/a totaltotal 34.0% 49 / 144 SCAR 2.7
CC
1
Cov
32%
showHelp
2.0
showVersion
2.0
BEGIN
1.0
CRAP 1.3
« utils/getAssociatedTerms.pl ↑ Summary utils/getRelated.pl »
1 #!/usr/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 2 ▶use UMLS::Interface;
Subroutine BEGIN: called CC=1 SCAR=0.0
132 2 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
133  
134 2 ▶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");
Branch: 1 branch
BranchTrueFalseTotal
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" 0 2 2
135  
136  
137 # if help is defined, print out help
138 2 ▶if( defined $opt_help ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_help) 0 2 2
139 0 $opt_help = 1;
140 0 &showHelp();
141 0 exit;
142 }
143  
144 # if version is requested, show version
145 2 ▶if( defined $opt_version ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_version) 0 2 2
146 0 $opt_version = 1;
147 0 &showVersion();
148 0 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 2 ▶if( !(defined $opt_infile) and (scalar(@ARGV) < 1) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $opt_infile and scalar @ARGV < 1) 1 1 2
Condition66%2/3
not defined $opt_infile and scalar @ARGV < 1
!ll&&!rl&&r
011
MC/DC50%1/2
not defined $opt_infile and scalar @ARGV < 1
not defined $opt_infile scalar @ARGV < 1
Truth table66%2/3
not(A) and B
A= not defined $opt_infileB= scalar @ARGV < 1
ABresult
0X0
100
111
154 1 print STDERR "At least 1 term or CUI should be given on the \n";
155 1 print STDERR "command line or use the --infile option\n";
156 1 &minimalUsageNotes();
157 0 exit;
158 }
159  
160 1 my $umls = "";
161 1 my %option_hash = ();
162  
163 1 ▶if(defined $opt_verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_verbose) 0 1 1
164 0 $option_hash{"verbose"} = $opt_verbose;
165 }
166 1 ▶if(defined $opt_debug) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_debug) 0 1 1
167 0 $option_hash{"debug"} = $opt_debug
168 }
169 1 ▶if(defined $opt_username) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_username) 0 1 1
170 0 $option_hash{"username"} = $opt_username;
171 }
172 1 ▶if(defined $opt_driver) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_driver) 0 1 1
173 0 $option_hash{"driver"} = $opt_driver; #mysql
174 }
175 1 ▶if(defined $opt_database) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_database) 0 1 1
176 0 $option_hash{"database"} = $opt_database;
177 }
178 1 ▶if(defined $opt_password) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_password) 0 1 1
179 0 $option_hash{"password"} = $opt_password;
180 }
181 1 ▶if(defined $opt_hostname) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_hostname) 0 1 1
182 0 $option_hash{"hostname"} = $opt_hostname;
183 }
184 1 ▶if(defined $opt_socket) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_socket) 0 1 1
185 0 $option_hash{"socket"} = $opt_socket;
186 }
187  
188 1 $option_hash{"t"} = 1;
189 1 $umls = UMLS::Interface->new(\%option_hash);
190 0 ▶die "Unable to create UMLS::Interface object.\n" if(!$umls);
Branch: 1 branch
BranchTrueFalseTotal
unless $umls 0 0 0
191  
192  
193  
194 0 my @terms = ();
195 0 ▶if(defined $opt_infile) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_infile) { } 0 0 0
196 0 ▶ open(INFILE, $opt_infile) || die "Could not open infile ($opt_infile)\n";
Branch: 1 branch
BranchTrueFalseTotal
open INFILE, $opt_infile or die "Could not open infile ($opt_infile)\n" 0 0 0
197 0 ▶ while(<INFILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline INFILE)) 0 0 0
198 0 chomp;
199 0 push @terms, $_;
200 0 } close INFILE;
201 }
202 else {
203 0 my $term = shift;
204 0 push @terms, $term;
205 }
206  
207 0 foreach my $input (@terms) {
208  
209 0 my $c = undef;
210 0 ▶ if($input=~/C[0-9]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input =~ /C[0-9]/) { } 0 0 0
211 0 push @{$c}, $input;
212 0 my $ts = $umls->getTermList($input);
213 0 $term = shift @{$ts};
214 }
215 else {
216 0 $c = $umls->getConceptList($input);
217 }
218
219 0 my $printFlag = 0;
220
221 0 foreach my $cui (@{$c}) {
222
223 0 my $sts = $umls->getSt($cui);
224
225 0 ▶ if($#{$sts} < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#{$sts;} < 0) { } 0 0 0
226 0 print "There are no semantic types associated with $term ($cui)\n";
227 }
228 else {
229 0 print "The semantic types associated with $term ($cui):\n";
230 0 foreach my $st (@{$sts}) {
231 0 my $abr = $umls->getStAbr($st);
232 0 my $string = $umls->getStString($abr);
233 0 print " $string ($abr)\n";
234 }
235 }
236 0 $printFlag = 1;
237 }
238  
239 0 ▶ if(! ($printFlag) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($printFlag) 0 0 0
240 0 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 1 ▶ print "Usage: getSts.pl [OPTIONS] [TERM|CUI] \n";
Subroutine minimalUsageNotes: called CC=1 SCAR=0.0
250 1 &askHelp();
251 1 exit;
252 }
253  
254 ##############################################################################
255 # function to output help messages for this program
256 ##############################################################################
257 sub showHelp() {
258  
259
260 0 ▶ print "This is a utility that takes as input a TERM or\n";
Subroutine showHelp: not called CC=1 SCAR=6.9
261 0 print "a CUI and returns all of its semantic types.\n\n";
262
263 0 print "Usage: getSts.pl [OPTIONS] [TERM|CUI]\n\n";
264  
265 0 print "Options:\n\n";
266
267 0 print "--infile FILE A file containing a list of concepts \n";
268 0 print " or terms.\n\n";
269  
270 0 print "--debug Sets the debug flag for testing\n\n";
271  
272 0 print "--username STRING Username required to access mysql\n\n";
273  
274 0 print "--password STRING Password required to access mysql\n\n";
275  
276 0 print "--hostname STRING Hostname for mysql (DEFAULT: localhost)\n\n";
277  
278 0 print "--database STRING Database contain UMLS (DEFAULT: umls)\n\n";
279
280 0 print "--socket STRING Socket used by mysql (DEFAULT: /tmp.mysql.sock)\n\n";
281  
282 0 print "--version Prints the version number\n\n";
283
284 0 print "--help Prints this help message.\n\n";
285 }
286  
287 ##############################################################################
288 # function to output the version number
289 ##############################################################################
290 sub showVersion {
291 0 ▶ print '$Id: getSts.pl,v 1.15 2011/08/29 16:37:03 btmcinnes Exp $';
Subroutine showVersion: not called CC=1 SCAR=6.9
292 0 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 1 ▶ print STDERR "Type getSts.pl --help for help.\n";
Subroutine askHelp: called CC=1 SCAR=0.0
300 }
301
« utils/getAssociatedTerms.pl ↑ Summary utils/getRelated.pl »