blib/script/getRelations.pl untested

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