utils/getChildren.pl

filter: Statementstmt 26.2% 27 / 103 Branchbran 30.9% 13 / 42 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 4 / 6 Podpod n/a totaltotal 29.1% 44 / 151 SCAR 3.2
CC
1
Cov
28%
showHelp
2.0
showVersion
2.0
BEGIN
1.0
CRAP 1.4
« utils/findCuiDepth.pl ↑ Summary utils/getParents.pl »
1 #!/usr/bin/perl
2  
3 =head1 NAME
4  
5 getChildren.pl - This program returns all of a concepts children.
6  
7 =head1 SYNOPSIS
8  
9 This program takes in a cui and returns all of its children
10 given a specified set of sources.
11  
12 =head1 USAGE
13  
14 Usage: getChildren.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 children
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 children 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 2 ▶use UMLS::Interface;
Subroutine BEGIN: called CC=1 SCAR=0.0
153 2 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
154  
155 2 ▶eval(GetOptions( "version", "help", "debug", "username=s", "password=s", "hostname=s", "database=s", "socket=s", "config=s", "file=s", "info")) or die ("Please check the above mentioned option(s).\n");
Branch: 1 branch
BranchTrueFalseTotal
eval &GetOptions("version", "help", "debug", "username=s", "password=s", "hostname=s", "database=s", "socket=s", "config=s", "file=s", "info") or die "Please check the above mentioned option(s).\n" 0 2 2
156  
157  
158 # if help is defined, print out help
159 2 ▶if( defined $opt_help ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_help) 0 2 2
160 0 $opt_help = 1;
161 0 &showHelp();
162 0 exit;
163 }
164  
165 # if version is requested, show version
166 2 ▶if( defined $opt_version ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_version) 0 2 2
167 0 $opt_version = 1;
168 0 &showVersion();
169 0 exit;
170 }
171  
172 # At least 1 term should be given on the command line.
173 2 ▶if(scalar(@ARGV) < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @ARGV < 1) 1 1 2
174 1 print STDERR "No term was specified on the command line\n";
175 1 &minimalUsageNotes();
176 0 exit;
177 }
178  
179 1 my $umls = "";
180 1 my %option_hash = ();
181  
182 1 ▶if(defined $opt_config) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_config) 0 1 1
183 0 $option_hash{"config"} = $opt_config;
184 }
185 1 ▶if(defined $opt_verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_verbose) 0 1 1
186 0 $option_hash{"verbose"} = $opt_verbose;
187 }
188 1 ▶if(defined $opt_username) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_username) 0 1 1
189 0 $option_hash{"username"} = $opt_username;
190 }
191 1 ▶if(defined $opt_debug) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_debug) 0 1 1
192 0 $option_hash{"debug"} = $opt_debug;
193 }
194 1 ▶if(defined $opt_database) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_database) 0 1 1
195 0 $option_hash{"database"} = $opt_database;
196 }
197 1 ▶if(defined $opt_password) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_password) 0 1 1
198 0 $option_hash{"password"} = $opt_password;
199 }
200 1 ▶if(defined $opt_hostname) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_hostname) 0 1 1
201 0 $option_hash{"hostname"} = $opt_hostname;
202 }
203 1 ▶if(defined $opt_socket) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_socket) 0 1 1
204 0 $option_hash{"socket"} = $opt_socket;
205 }
206  
207 1 $umls = UMLS::Interface->new(\%option_hash);
208 0 ▶if(!$umls) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($umls) 0 0 0
209 0 print STDERR "Unable to create UMLS::Interface object.\n";
210 0 exit;
211 }
212  
213 0 my @terms = ();
214 0 ▶if(defined $opt_file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_file) { } 0 0 0
215 0 ▶ open(FILE, $opt_file) || die "Could not open file: $file\n";
Branch: 1 branch
BranchTrueFalseTotal
open FILE, $opt_file or die "Could not open file: $file\n" 0 0 0
216 0 ▶ while(<FILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline FILE)) 0 0 0
217 0 chomp;
218 0 push @terms, $_;
219 }
220 }
221 else {
222
223 0 my $input = shift;
224 0 push @terms, $input;
225 }
226  
227 0 foreach my $input (@terms) {
228
229 0 my $term = $input;
230  
231 0 my $c = undef;
232 0 ▶ if($input=~/C[0-9]+/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input =~ /C[0-9]+/) { } 0 0 0
233 0 push @{$c}, $input;
234 0 $term = $umls->getAllPreferredTerm($input);
235 }
236 else {
237 0 $c = $umls->getConceptList($input);
238 }
239
240 0 my $printFlag = 0;
241
242 0 foreach my $cui (@{$c}) {
243 0 ▶ if($umls->exists($cui) == 0) { next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($umls->exists($cui) == 0) 0 0 0
244  
245 0 my $rchildren= $umls->getChildren($cui);
246
247 0 my @children = @{$rchildren};
248  
249 0 ▶ if($#children < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#children < 0) { } 0 0 0
250 0 print "The term $term ($cui) does not have any children\n";
251 }
252 else {
253 0 print "The children of $term ($cui) are: \n";
254 0 foreach my $child (@children) {
255 0 my $list = $umls->getTermList($child);
256 0 my $t = shift @{$list};
257 0 print " $t ($child) ";
258 0 ▶ if(defined $opt_info) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_info) 0 0 0
259 0 my $relations = $umls->getRelationsBetweenCuis($cui, $child);
260 0 print " => @{$relations}";
261 }
262 0 print "\n";
263 }
264 }
265 0 $printFlag = 1;
266 }
267
268 0 ▶ if(! ($printFlag) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($printFlag) 0 0 0
269 0 print "Input $input does not exist in this view of the UMLS.\n";
270 }
271 }
272  
273 ##############################################################################
274 # function to output minimal usage notes
275 ##############################################################################
276 sub minimalUsageNotes {
277
278 1 ▶ print "Usage: getChildren.pl [OPTIONS] [CUI|TERM]\n";
Subroutine minimalUsageNotes: called CC=1 SCAR=0.0
279 1 &askHelp();
280 1 exit;
281 }
282  
283 ##############################################################################
284 # function to output help messages for this program
285 ##############################################################################
286 sub showHelp() {
287  
288
289 0 ▶ print "This is a utility that takes as input a CUI or a term\n";
Subroutine showHelp: not called CC=1 SCAR=6.9
290 0 print "and returns all of its possible children given\n";
291 0 print "a specified set of sources\n\n";
292
293 0 print "Usage: getChildren.pl [OPTIONS] [CUI|TERM]\n\n";
294  
295 0 print "Options:\n\n";
296  
297 0 print "--debug Sets the debug flag for testing\n\n";
298  
299 0 print "--info This prints out the relation and source\n";
300 0 print " of the children\n\n";
301  
302 0 print "--username STRING Username required to access mysql\n\n";
303  
304 0 print "--password STRING Password required to access mysql\n\n";
305  
306 0 print "--hostname STRING Hostname for mysql (DEFAULT: localhost)\n\n";
307  
308 0 print "--database STRING Database contain UMLS (DEFAULT: umls)\n\n";
309
310 0 print "--socket STRING Socket used by mysql (DEFAULT: /tmp.mysql.sock)\n\n";
311  
312 0 print "--config FILE Configuration file\n\n";
313  
314 0 print "--version Prints the version number\n\n";
315
316 0 print "--help Prints this help message.\n\n";
317 }
318  
319 ##############################################################################
320 # function to output the version number
321 ##############################################################################
322 sub showVersion {
323 0 ▶ print '$Id: getChildren.pl,v 1.18 2016/01/07 22:49:33 btmcinnes Exp $';
Subroutine showVersion: not called CC=1 SCAR=6.9
324 0 print "\nCopyright (c) 2008, Ted Pedersen & Bridget McInnes\n";
325 }
326  
327 ##############################################################################
328 # function to output "ask for help" message when user's goofed
329 ##############################################################################
330 sub askHelp {
331 1 ▶ print STDERR "Type getChildren.pl --help for help.\n";
Subroutine askHelp: called CC=1 SCAR=0.0
332 }
333
« utils/findCuiDepth.pl ↑ Summary utils/getParents.pl »