utils/getAssociatedCuis.pl

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