blib/script/getParents.pl untested

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