blib/script/getSemanticGroup.pl untested

filter: Statementstmt 0.0% 0 / 104 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 7 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 155 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")) 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 (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 my @terms = ();
197 if(defined $opt_infile) {
198 open(INFILE, $opt_infile) || die "Could not open infile ($opt_infile)\n";
199 while(<INFILE>) {
200 chomp;
201 push @terms, $_;
202 } close INFILE;
203 }
204 else {
205 my $term = shift;
206 push @terms, $term;
207 }
208  
209 if(defined $opt_st) {
210
211 foreach my $st (@terms) {
212
213 my $groups = $umls->stGetSemanticGroup($st);
214
215 if($#{$groups} < 0) {
216 print "There are no semantic groups associated with the semantic type $st\n";
217 }
218 else {
219 print "The semantic groups associated with $st are: \n";
220 foreach my $group (@{$groups}) {
221 print " $group\n";
222 $printFlag = 1;
223 }
224 }
225 }
226 }
227 else {
228
229 foreach my $input (@terms) {
230
231 my $c = undef;
232 my $term = $input;
233
234 if($input=~/C[0-9]/) {
235 push @{$c}, $input;
236 my $terms = $umls->getTermList($input);
237 $term = shift @{$terms};
238 }
239 else {
240 $c = $umls->getConceptList($input);
241 }
242
243 my $printFlag = 0;
244
245 foreach my $cui (@{$c}) {
246
247 my $groups = $umls->getSemanticGroup($cui);
248
249 if($#{$groups} < 0) {
250 print "There are no semantic groups associated with the term $term ($cui)\n";
251 }
252 else {
253 print "The semantic groups associated with $term ($cui):\n";
254 foreach my $group (@{$groups}) {
255 print " $group\n";
256 $printFlag = 1;
257 }
258 }
259
260 }
261 }
262 }
263  
264 ##############################################################################
265 # function to output minimal usage notes
266 ##############################################################################
267 sub minimalUsageNotes {
268
269 print "Usage: getSemanticGroup.pl [OPTIONS] [TERM|CUI] \n";
270 &askHelp();
271 exit;
272 }
273  
274 ##############################################################################
275 # function to output help messages for this program
276 ##############################################################################
277 sub showHelp() {
278  
279
280 print "This is a utility that takes as input a TERM or\n";
281 print "a CUI and returns all of its semantic groupss.\n\n";
282
283 print "Usage: getSemanticGroup.pl [OPTIONS] [TERM|CUI]\n\n";
284  
285 print "Options:\n\n";
286
287 print "--st Input is a semantic type (ST)\n\n";
288  
289 print "--infile FILE A file containing a list of concepts \n";
290 print " or terms.\n\n";
291  
292 print "--debug Sets the debug flag for testing\n\n";
293  
294 print "--username STRING Username required to access mysql\n\n";
295  
296 print "--password STRING Password required to access mysql\n\n";
297  
298 print "--hostname STRING Hostname for mysql (DEFAULT: localhost)\n\n";
299  
300 print "--database STRING Database contain UMLS (DEFAULT: umls)\n\n";
301
302 print "--socket STRING Socket used by mysql (DEFAULT: /tmp.mysql.sock)\n\n";
303  
304 print "--version Prints the version number\n\n";
305
306 print "--help Prints this help message.\n\n";
307 }
308  
309 ##############################################################################
310 # function to output the version number
311 ##############################################################################
312 sub showVersion {
313 print '$Id: getSemanticGroup.pl,v 1.6 2011/08/29 16:37:03 btmcinnes Exp $';
314 print "\nCopyright (c) 2008-2011, Ted Pedersen & Bridget McInnes\n";
315 }
316  
317 ##############################################################################
318 # function to output "ask for help" message when user's goofed
319 ##############################################################################
320 sub askHelp {
321 print STDERR "Type getSemanticGroup.pl --help for help.\n";
322 }
323