blib/script/getAssociatedCuis.pl untested

filter: Statementstmt 0.0% 0 / 85 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 7 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 134 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 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 use UMLS::Interface;
150 use Getopt::Long;
151  
152 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");
153  
154  
155 # if help is defined, print out help
156 if( defined $opt_help ) {
157 $opt_help = 1;
158 &showHelp();
159 exit;
160 }
161  
162 # if version is requested, show version
163 if( defined $opt_version ) {
164 $opt_version = 1;
165 &showVersion();
166 exit;
167 }
168  
169 # At least 1 term should be given on the command line.
170 if(!(defined $opt_infile) && (scalar(@ARGV) < 1) ) {
171 print STDERR "No term was specified on the command line\n";
172 &minimalUsageNotes();
173 exit;
174 }
175  
176  
177 my $umls = "";
178 my %option_hash = ();
179  
180 if(defined $opt_config) {
181 $option_hash{"config"} = $opt_config;
182 }
183 if(defined $opt_debug) {
184 $option_hash{"debug"} = $opt_debug;
185 }
186 if(defined $opt_verbose) {
187 $option_hash{"verbose"} = $opt_verbose;
188 }
189 if(defined $opt_username) {
190 $option_hash{"username"} = $opt_username;
191 }
192 if(defined $opt_driver) {
193 $option_hash{"driver"} = $opt_driver;
194 }
195 if(defined $opt_database) {
196 $option_hash{"database"} = $opt_database;
197 }
198 if(defined $opt_password) {
199 $option_hash{"password"} = $opt_password;
200 }
201 if(defined $opt_hostname) {
202 $option_hash{"hostname"} = $opt_hostname;
203 }
204 if(defined $opt_socket) {
205 $option_hash{"socket"} = $opt_socket;
206 }
207  
208 $umls = UMLS::Interface->new(\%option_hash);
209 die "Unable to create UMLS::Interface object.\n" if(!$umls);
210  
211 my @terms;
212 if(defined $opt_infile) {
213 open(FILE, $opt_infile) || die "Could not open infile ($opt_infile)\n";
214 while(<FILE>) { chomp; push @terms, $_; }
215 }
216 else {
217 my $t = shift;
218 push @terms, $t;
219 }
220  
221 foreach my $term (@terms) {
222  
223 $term=~s/\'/\\\'/g;
224
225 my $cuis = $umls->getConceptList($term);
226
227 if($#{$cuis} < 0) {
228 print "No CUIs are associated with $term.\n";
229 }
230 else {
231 print "The CUIs associated with $term are:\n";
232 my $i = 1;
233 foreach my $cui (@{$cuis}) {
234 if(defined $opt_sab) {
235 my $sabs = $umls->getSab($cui);
236 print "$i. $cui (@{$sabs})\n"; $i++;
237 }
238 else {
239 print "$i. $cui\n"; $i++;
240 }
241 }
242 }
243 }
244 ##############################################################################
245 # function to output minimal usage notes
246 ##############################################################################
247 sub minimalUsageNotes {
248
249 print "Usage: getAssociatedCuis.pl [OPTIONS] TERM \n";
250 &askHelp();
251 exit;
252 }
253  
254 ##############################################################################
255 # function to output help messages for this program
256 ##############################################################################
257 sub showHelp() {
258  
259
260 print "This is a utility that takes as input a term\n";
261 print "and returns all of its possible CUIs.\n\n";
262
263 print "Usage: getAssociatedCuis.pl [OPTIONS] TERM\n\n";
264  
265 print "Options:\n\n";
266
267 print "--sab Prints out the source of the CUI\n\n";
268  
269 print "--debug Sets the debug flag for testing\n\n";
270  
271 print "--username STRING Username required to access mysql\n\n";
272  
273 print "--password STRING Password required to access mysql\n\n";
274  
275 print "--hostname STRING Hostname for mysql (DEFAULT: localhost)\n\n";
276  
277 print "--database STRING Database contain UMLS (DEFAULT: umls)\n\n";
278
279 print "--socket STRING Socket used by mysql (DEFAULT: /tmp.mysql.sock)\n\n";
280  
281 print "--config FILE Configuration file\n\n";
282  
283 print "--version Prints the version number\n\n";
284
285 print "--help Prints this help message.\n\n";
286 }
287  
288 ##############################################################################
289 # function to output the version number
290 ##############################################################################
291 sub showVersion {
292 print '$Id: getAssociatedCuis.pl,v 1.11 2014/06/03 16:36:48 btmcinnes Exp $';
293 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 print STDERR "Type getAssociatedCuis.pl --help for help.\n";
301 }
302