utils/getAssociatedTerms.pl

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