blib/script/findNumberOfCloserConcepts.pl untested

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