blib/script/getSemanticRelation.pl untested

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