utils/getStDef.pl

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