blib/script/sim2r.pl untested

filter: Statementstmt 0.0% 0 / 103 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 9 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 136 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 sim2r.pl - This program converts a series of umls-similarity output to
6 R format in order to run the SignificanceTesting.r program.
7  
8 =head1 SYNOPSIS
9  
10 This program converts output generated by umls-similarity.pl to
11 R format in order to run the SignificanceTesting.r program
12  
13 =head1 USAGE
14  
15 Usage: sim2r.pl GOLD_FILE [FILE1 FILE2 ...]
16  
17 =head1 INPUT
18  
19 =head2 Required:
20  
21 =head3 GOLD_FILE
22  
23 This is the gold standard. Usually this is the data that has
24 manually been score by human annotaters. This is what the
25 SignificanceTesting.r program is going to use to determine
26 the correlation against for the other files.
27  
28 The format of this file is the same as output format of the
29 umls-similarity.pl program.
30  
31 score<>cui1<>cui2
32 score<>term1<>term2
33 ...
34  
35  
36 =head3 FILE1 FILE2 ...
37  
38 These are the output files generated by the umls-similarity.pl
39 program. The header information in R will be the name of the
40 file.
41  
42 =head2 Options:
43  
44 =head3 --word
45  
46 The format of hte input files contains words rather than CUIs or is not
47 a umls-simmilarity.pl output file.
48  
49 =head3 --help
50  
51 Displays the quick summary of program options.
52  
53 =head3 --version
54  
55 Displays the version information.
56  
57 =head1 OUTPUT
58  
59 A cvs file that can be read by the SignificanceTesting.r program
60  
61  
62 =head1 SYSTEM REQUIREMENTS
63  
64 =over
65  
66 =item * Perl (version 5.8.5 or better) - http://www.perl.org
67  
68 =back
69  
70 =head1 CONTACT US
71
72 If you have any trouble installing and using UMLS-Similarity,
73 please contact us via the users mailing list :
74
75 umls-similarity@yahoogroups.com
76
77 You can join this group by going to:
78
79 http://tech.groups.yahoo.com/group/umls-similarity/
80
81 You may also contact us directly if you prefer :
82
83 Bridget T. McInnes: bthomson at cs.umn.edu
84  
85 Ted Pedersen : tpederse at d.umn.edu
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  
102 Siddharth Patwardhan, University of Utah, Salt Lake City
103 sidd@cs.utah.edu
104
105 Serguei Pakhomov, University of Minnesota Twin Cities
106 pakh0002@umn.edu
107  
108 This program is free software; you can redistribute it and/or modify it under
109 the terms of the GNU General Public License as published by the Free Software
110 Foundation; either version 2 of the License, or (at your option) any later
111 version.
112  
113 This program is distributed in the hope that it will be useful, but WITHOUT
114 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
115 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
116  
117 You should have received a copy of the GNU General Public License along with
118 this program; if not, write to:
119  
120 The Free Software Foundation, Inc.,
121 59 Temple Place - Suite 330,
122 Boston, MA 02111-1307, USA.
123  
124 =cut
125  
126 ###############################################################################
127  
128 # THE CODE STARTS HERE
129 ###############################################################################
130  
131 # ================================
132 # COMMAND LINE OPTIONS AND USAGE
133 # ================================
134  
135 use UMLS::Interface;
136 use Getopt::Long;
137  
138 eval(GetOptions( "version", "help", "word")) or die ("Please check the above mentioned option(s).\n");
139  
140 # if help is defined, print out help
141 if( defined $opt_help ) {
142 $opt_help = 1;
143 &showHelp();
144 exit;
145 }
146  
147 # if version is requested, show version
148 if( defined $opt_version ) {
149 $opt_version = 1;
150 &showVersion();
151 exit;
152 }
153  
154 # At least 2 terms should be given on the command line.
155 if( !(defined $opt_infile) and (scalar(@ARGV) < 2) ) {
156 print STDERR "At least 2 terms or CUIs should be given on the \n";
157 print STDERR "command line or use the --infile option\n";
158 &minimalUsageNotes();
159 exit;
160 }
161  
162  
163 my $goldfile = shift;
164 open(GOLD, $goldfile) || die "Could not open file: $goldfile\n";
165  
166 my %gold = (); my $gcounter = 0;
167 while(<GOLD>) {
168 chomp;
169 my ($score, $t1, $t2) = split/<>/;
170  
171 my $cui1 = ""; my $cui2 = "";
172  
173 if(defined $opt_word) {
174 $cui1 = $t1;
175 $cui2 = $t2;
176 }
177 else {
178 $t1=~/(C[0-9][0-9][0-9][0-9][0-9][0-9][0-9])/;
179 $cui1 = $1;
180  
181 $t2=~/(C[0-9][0-9][0-9][0-9][0-9][0-9][0-9])/;
182 $cui2 = $1;
183 }
184
185 $gold{"$cui1 $cui2"} = $score;
186 $gcounter++;
187 }
188  
189 print STDERR "TOTAL PAIRS IN GOLD STANDARD: $gcounter\n";
190  
191 my %remove = ();
192 my %hash = ();
193 my @headers = ();
194 my %terms = ();
195  
196 foreach my $file (@ARGV) {
197 open(FILE, $file) || die "Could not open file: $file\n";
198
199 $file=~/\/?(.*?)$/;
200 my $header = $1;
201  
202 push @headers, $header;
203 my $counter = 0;
204 while(<FILE>) {
205 chomp;
206 my ($score, $t1, $t2) = split/<>/;
207  
208 my $cui1 = ""; my $cui2 = "";
209
210 if(defined $opt_word) {
211 $cui1 = $t1;
212 $cui2 = $t2;
213 }
214 else {
215 $t1=~/(C[0-9][0-9][0-9][0-9][0-9][0-9][0-9])/;
216 $cui1 = $1;
217
218 $t2=~/(C[0-9][0-9][0-9][0-9][0-9][0-9][0-9])/;
219 $cui2 = $1;
220 }
221  
222 $hash{$header}{"$cui1 $cui2"} = $score;
223 $counter++;
224  
225 if($score < 0) { $remove{"$cui1 $cui2"}++; }
226
227 $t1=~s/\,//g; $t2=~s/\,//g;
228 $t1=~s/\'//g; $t2=~s/\'//g;
229 $terms{"$cui1 $cui2"} = "$t1 $t2";
230 }
231 print STDERR "TOTAL PAIRS IN $header: $counter\n";
232 }
233  
234 my $str_headers = join ",", @headers;
235 print "pair,gold,$str_headers\n";
236  
237 my $counter = 0; my $discard = 0;
238 foreach my $pair (sort keys %gold) {
239  
240 if(exists $remove{$pair}) {
241 $discard++;
242 next;
243 }
244  
245 my $output = "$terms{$pair},$gold{$pair},";
246 foreach my $header (@headers) {
247 $output.= "$hash{$header}{$pair},";
248 } chop $output;
249
250 print "$output\n";
251 $counter++;
252  
253 }
254  
255 print STDERR "TOTAL PAIRS BEING PROCESSED: $counter\n";
256  
257 print STDERR "TOTAL PAIRS IGNORED: $discard\n";
258  
259 ##############################################################################
260 # function to output minimal usage notes
261 ##############################################################################
262 sub minimalUsageNotes {
263
264 print "Usage: sim2r.pl [OPTIONS] GOLD_FILE [FILE1 FILE2 ...]\n";
265 &askHelp();
266 exit;
267 }
268  
269 ##############################################################################
270 # function to output help messages for this program
271 ##############################################################################
272 sub showHelp() {
273
274 print "This is a utility converts output generated by \n";
275 print "umls-similarity.pl to R format in order to run the \n";
276 print "SignificanceTesting.r program\n\n";
277
278 print "Usage: sim2r.pl [OPTIONS] GOLD_FILE [FILE1 FILE2...]\n\n";
279  
280 print "Options:\n\n";
281  
282 print "--word The format of the input files contains words\n";
283 print " rathar than CUIs or is not a umls-similarity.pl\n";
284 print " output file.\n\n";
285  
286 print "--version Prints the version number\n\n";
287
288 print "--help Prints this help message.\n\n";
289
290 }
291  
292 ##############################################################################
293 # function to output the version number
294 ##############################################################################
295 sub showVersion {
296 print '$Id: sim2r.pl,v 1.7 2011/08/29 22:56:31 btmcinnes Exp $';
297 print "\nCopyright (c) 2007-2011, Ted Pedersen & Bridget McInnes\n";
298 }
299  
300 ##############################################################################
301 # function to output "ask for help" message when user's goofed
302 ##############################################################################
303 sub askHelp {
304 print STDERR "Type sim2r.pl --help for help.\n";
305 }
306
307