blib/script/getCompounds.pl untested

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