blib/script/findAncestors.pl untested

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