blib/script/getSemanticGroup.pl untested

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