blib/script/getIntrinsicIC.pl untested

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