-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathribotest
executable file
·488 lines (439 loc) · 22.4 KB
/
ribotest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Long;
use Time::HiRes qw(gettimeofday);
# ribotest :: test ribovore scripts [TEST SCRIPT]
# Usage: ribotest [-options] <input test file e.g. testfiles/testin.1> <output directory to create>
require "ribo.pm";
# make sure required environment variables are set
my $env_riboscripts_dir = utl_DirEnvVarValid("RIBOSCRIPTSDIR");
#my %execs_H = (); # hash with paths to all required executables
#$execs_H{"cmsearch"} = $env_riboinfernal_dir . "/cmsearch";
#$execs_H{"esl-seqstat"} = $env_riboeasel_dir . "/esl-seqstat";
#$execs_H{"esl-sfetch"} = $env_riboeasel_dir . "/esl-sfetch";
#ribo_ValidateExecutableHash(\%execs_H);
#########################################################
# Command line and option processing using sqp_opts.pm
#
# opt_HH: 2D hash:
# 1D key: option name (e.g. "-h")
# 2D key: string denoting type of information
# (one of "type", "default", "group", "requires", "incompatible", "preamble", "help")
# value: string explaining 2D key:
# "type": "boolean", "string", "integer" or "real"
# "default": default value for option
# "group": integer denoting group number this option belongs to
# "requires": string of 0 or more other options this option requires to work, each separated by a ','
# "incompatible": string of 0 or more other options this option is incompatible with, each separated by a ','
# "preamble": string describing option for preamble section (beginning of output from script)
# "help": string describing option for help section (printed if -h used)
# "setby": '1' if option set by user, else 'undef'
# "value": value for option, can be undef if default is undef
#
# opt_order_A: array of options in the order they should be processed
#
# opt_group_desc_H: key: group number (integer), value: description of group for help output
my %opt_HH = ();
my @opt_order_A = ();
my %opt_group_desc_H = ();
# Add all options to %opt_HH and @opt_order_A.
# This section needs to be kept in sync (manually) with the &GetOptions call below
$opt_group_desc_H{"1"} = "basic options";
# option type default group requires incompat preamble-output help-output
opt_Add("-h", "boolean", 0, 0, undef, undef, undef, "display this help", \%opt_HH, \@opt_order_A);
opt_Add("-f", "boolean", 0, 1, undef, undef, "forcing directory overwrite", "force; if dir <output directory> exists, overwrite it", \%opt_HH, \@opt_order_A);
opt_Add("-v", "boolean", 0, 1, undef, undef, "be verbose", "be verbose; output commands to stdout as they're run", \%opt_HH, \@opt_order_A);
opt_Add("-s", "boolean", 0, 1, undef, undef, "skip commands, they were already run, just compare files", "skip commands, they were already run, just compare files", \%opt_HH, \@opt_order_A);
$opt_group_desc_H{"2"} = "options for defining variables in testing files";
# option type default group requires incompat preamble-output help-output
#opt_Add("--dirbuild", "string", undef, 2, undef, undef, "build directory, replaces !dirbuild! in test file with <s>", "build directory, replaces !dirbuild! in test file with <s>", \%opt_HH, \@opt_order_A);
$opt_group_desc_H{"3"} = "other options";
opt_Add("--rmout", "boolean", 0, 2, undef, "-s", "if output files listed in testin file already exist, remove them", "if output files listed in testin file already exist, remove them", \%opt_HH, \@opt_order_A);
opt_Add("--keep", "boolean", 0, 2, undef, undef, "leaving intermediate files on disk", "do not remove intermediate files, keep them all on disk", \%opt_HH, \@opt_order_A);
# This section needs to be kept in sync (manually) with the opt_Add() section above
my %GetOptions_H = ();
my $usage = "Usage: ribotest [-options] <input test file e.g. testfiles/testin.1> <output directory to create>\n";
my $synopsis = "ribotest :: test ribovore scripts [TEST SCRIPT]";
my $options_okay =
&GetOptions('h' => \$GetOptions_H{"-h"},
'v' => \$GetOptions_H{"-v"},
'f' => \$GetOptions_H{"-f"},
's' => \$GetOptions_H{"-s"},
# 'dirbuild=s' => \$GetOptions_H{"--dirbuild"},
'rmout' => \$GetOptions_H{"--rmout"},
'keep' => \$GetOptions_H{"--keep"});
my $total_seconds = -1 * ofile_SecondsSinceEpoch(); # by multiplying by -1, we can just add another ofile_SecondsSinceEpoch call at end to get total time
my $executable = $0;
my $date = scalar localtime();
my $version = "1.0.5";
my $releasedate = "Sep 2023";
my $package_name = "ribovore";
# make *STDOUT file handle 'hot' so it automatically flushes whenever we print to it
select *STDOUT;
$| = 1;
# print help and exit if necessary
if((! $options_okay) || ($GetOptions_H{"-h"})) {
ofile_OutputBanner(*STDOUT, $package_name, $version, $releasedate, $synopsis, $date, undef);
opt_OutputHelp(*STDOUT, $usage, \%opt_HH, \@opt_order_A, \%opt_group_desc_H);
if(! $options_okay) { die "ERROR, unrecognized option;"; }
else { exit 0; } # -h, exit with 0 status
}
# check that number of command line args is correct
if(scalar(@ARGV) != 2) {
print "Incorrect number of command line arguments.\n";
print $usage;
print "\nTo see more help on available options, enter 'ribotest -h'\n\n";
exit(1);
}
my ($test_file, $dir_out) = (@ARGV);
# set options in opt_HH
opt_SetFromUserHash(\%GetOptions_H, \%opt_HH);
# validate options (check for conflicts)
opt_ValidateSet(\%opt_HH, \@opt_order_A);
#############################
# create the output directory
#############################
my $cmd; # a command to run with utl_RunCommand()
my @early_cmd_A = (); # array of commands we run before our log file is opened
if($dir_out !~ m/\/$/) { $dir_out =~ s/\/$//; } # remove final '/' if it exists
if(-d $dir_out) {
$cmd = "rm -rf $dir_out";
if(opt_Get("-f", \%opt_HH)) {
utl_RunCommand($cmd, opt_Get("-v", \%opt_HH), 0, undef); push(@early_cmd_A, $cmd);
}
else { # $dir_out directory exists but -f not used
die "ERROR directory named $dir_out already exists. Remove it, or use -f to overwrite it.";
}
}
elsif(-e $dir_out) {
$cmd = "rm $dir_out";
if(opt_Get("-f", \%opt_HH)) {
utl_RunCommand($cmd, opt_Get("-v", \%opt_HH), 0, undef); push(@early_cmd_A, $cmd);
}
else { # $dir_out file exists but -f not used
die "ERROR a file named $dir_out already exists. Remove it, or use -f to overwrite it.";
}
}
# create the dir
$cmd = "mkdir $dir_out";
utl_RunCommand($cmd, opt_Get("-v", \%opt_HH), 0, undef);
push(@early_cmd_A, $cmd);
my $dir_tail = $dir_out;
$dir_tail =~ s/^.+\///; # remove all but last dir
my $out_root = $dir_out . "/" . $dir_tail . ".ribotest";
#############################################
# output program banner and open output files
#############################################
# output preamble
my @arg_desc_A = ("test file", "output directory name");
my @arg_A = ($test_file, $dir_out);
my %extra_H = ();
$extra_H{"\$RIBOSCRIPTSDIR"} = $env_riboscripts_dir;
ofile_OutputBanner(*STDOUT, $package_name, $version, $releasedate, $synopsis, $date, \%extra_H);
opt_OutputPreamble(*STDOUT, \@arg_desc_A, \@arg_A, \%opt_HH, \@opt_order_A);
# open the log and command files:
# set output file names and file handles, and open those file handles
my %ofile_info_HH = (); # hash of information on output files we created,
# 1D keys:
# "fullpath": full path to the file
# "nodirpath": file name, full path minus all directories
# "desc": short description of the file
# "FH": file handle to output to for this file, maybe undef
# 2D keys:
# "log": log file of what's output to stdout
# "cmd": command file with list of all commands executed
# open the log and command files
ofile_OpenAndAddFileToOutputInfo(\%ofile_info_HH, "list", $out_root . ".list", 1, 1, "List and description of all output files");
ofile_OpenAndAddFileToOutputInfo(\%ofile_info_HH, "log", $out_root . ".log", 1, 1, "Output printed to screen");
ofile_OpenAndAddFileToOutputInfo(\%ofile_info_HH, "cmd", $out_root . ".cmd", 1, 1, "List of executed commands");
my $log_FH = $ofile_info_HH{"FH"}{"log"};
my $cmd_FH = $ofile_info_HH{"FH"}{"cmd"};
# output files are all open, if we exit after this point, we'll need
# to close these first.
# now we have the log file open, output the banner there too
ofile_OutputBanner($log_FH, $package_name, $version, $releasedate, $synopsis, $date, \%extra_H);
opt_OutputPreamble($log_FH, \@arg_desc_A, \@arg_A, \%opt_HH, \@opt_order_A);
# output any commands we already executed to $log_FH
foreach $cmd (@early_cmd_A) {
print $cmd_FH $cmd . "\n";
}
#######################
# Parse the test file
#######################
my @cmd_A = (); # array of the commands to run
my @desc_A = (); # array of the descriptions for the commands
my @outfile_AA = (); # array of arrays of output files to compare for each command
my @expfile_AA = (); # array of arrays of expected files to compare output to for each command
my @rmdir_AA = (); # array of directories to remove after each command is completed
my $ncmd = test_ParseTestFile($test_file, \@cmd_A, \@desc_A, \@outfile_AA, \@expfile_AA, \@rmdir_AA, \%opt_HH, $ofile_info_HH{"FH"});
my $npass = 0;
my $nfail = 0;
# TODO: I SHOULD PUT THIS INTO A FUNCTION IN sqp_opts.pm (e.g. test_RunTestFile) but currently it requires
# a utl_RunCommand() call in the rmdir section.
# I could get around this by adding ofile_RemoveDir() and ofile_RemoveFile() functions.
my $start_secs = undef;
for(my $i = 1; $i <= $ncmd; $i++) {
my $cmd = $cmd_A[($i-1)];
my $desc = $desc_A[($i-1)];
my $outfile_AR = \@{$outfile_AA[($i-1)]};
my $expfile_AR = \@{$expfile_AA[($i-1)]};
my $rmdir_AR = \@{$rmdir_AA[($i-1)]};
my $progress_w = 50; # the width of the left hand column in our progress output, hard-coded
if((opt_IsUsed("-s", \%opt_HH)) && (opt_Get("-s", \%opt_HH))) {
# -s used, we aren't running commands, just comparing files
$start_secs = ofile_OutputProgressPrior(sprintf("Skipping command %2d [%20s]", $i, $desc_A[($i-1)]), $progress_w, $log_FH, *STDOUT);
ofile_OutputProgressComplete($start_secs, undef, $log_FH, *STDOUT);
}
else {
# -s not used, run command
$start_secs = ofile_OutputProgressPrior(sprintf("Running command %2d [%20s]", $i, $desc_A[($i-1)]), $progress_w, $log_FH, *STDOUT);
utl_RunCommand($cmd, opt_Get("-v", \%opt_HH), 0, $ofile_info_HH{"FH"});
ofile_OutputProgressComplete($start_secs, undef, $log_FH, *STDOUT);
}
my $nout = scalar(@{$outfile_AR});
for(my $j = 0; $j < $nout; $j++) {
my $diff_file = $out_root . "." . $i . "." . ($j+1) . ".diff";
my $pass = test_DiffTwoFiles($outfile_AR->[$j], $expfile_AR->[$j], $diff_file, $ofile_info_HH{"FH"});
if($pass) { $npass++; }
else { $nfail++; }
}
if(($nfail == 0) && (! opt_Get("--keep", \%opt_HH))) { # only remove dir if no tests failed
my $nrmdir = (defined $rmdir_AR) ? scalar(@{$rmdir_AR}) : 0;
for(my $k = 0; $k < $nrmdir; $k++) {
ofile_OutputString($log_FH, 1, sprintf("#\t%-60s ... ", "removing directory $rmdir_AR->[$k]"));
utl_RunCommand("rm -rf $rmdir_AR->[$k]", opt_Get("-v", \%opt_HH), 0, $ofile_info_HH{"FH"});
ofile_OutputString($log_FH, 1, "done\n");
}
}
}
##########
# Conclude
##########
# summarize number of files checked and passed
my $overall_pass = ($nfail == 0) ? 1 : 0;
ofile_OutputString($log_FH, 1, "#\n#\n");
if($overall_pass) {
ofile_OutputString($log_FH, 1, "# PASS: all $npass files were created correctly.\n");
}
else {
ofile_OutputString($log_FH, 1, sprintf("# FAIL: %d of %d files were not created correctly.\n", $nfail, $npass+$nfail));
ofile_FAIL("ERROR, at least one test FAILed", 1, undef);
}
ofile_OutputString($log_FH, 1, sprintf("#\n"));
$total_seconds += ofile_SecondsSinceEpoch();
ofile_OutputConclusionAndCloseFilesOk($total_seconds, $dir_out, \%ofile_info_HH);
exit(0);
#####################################################################
# SUBROUTINES
#####################################################################
#################################################################
# Subroutine: test_ParseTestFile()
# Incept: EPN, Wed May 16 16:03:40 2018
#
# Purpose: Parse an input test file and store the relevant information
# in passed in array references.
#
# Arguments:
# $testfile: name of file to parse
# $cmd_AR: ref to array of commands to fill here
# $desc_AR: ref to array of descriptions to fill here
# $outfile_AAR: ref to 2D array of output files to fill here
# $expfile_AAR: ref to 2D array of expected files to fill here
# $rmdir_AAR: ref to 2D array of directories to remove after calling each command
# $opt_HHR: ref to 2D hash of option values, see top of epn-options.pm for description
# $FH_HR: ref to hash of file handles, including "log" and "cmd"
#
# Returns: number of commands read in $testfile
#
# Dies: - if any of the expected files do not exist
# - if number of expected files is not equal to number of output files
# for any command
# - if there are 0 output files for a given command
# - if output file already exists
#################################################################
sub test_ParseTestFile {
my $sub_name = "test_ParseTestFile";
my $nargs_expected = 8;
if(scalar(@_) != $nargs_expected) { printf STDERR ("ERROR, $sub_name entered with %d != %d input arguments.\n", scalar(@_), $nargs_expected); exit(1); }
my ($testfile, $cmd_AR, $desc_AR, $outfile_AAR, $expfile_AAR, $rmdir_AAR, $opt_HHR, $FH_HR) = @_;
open(IN, $testfile) || ofile_FileOpenFailure($testfile, $sub_name, $!, "reading", $FH_HR);
my $ncmd = 0;
my $ndesc = 0;
my $outfile;
my $expfile;
my $rmdir;
while(my $line = <IN>) {
if(($line !~ m/^\#/) && ($line =~ m/\w/)) {
# example input file:
# # comment line (ignored)
# command: perl $DNAORGDIR/dnaorg_scripts/dnaorg_classify.pl -f -A /panfs/pan1/dnaorg/virseqannot/dnaorg-build-directories/norovirus-builds --infasta testfiles/noro.9.fa --dirbuild /panfs/pan1/dnaorg/virseqannot/dnaorg-build-directories/norovirus-builds --dirout test-noro.9
# out: test-noro.9/test-noro.9-NC_001959.dnaorg_annotate.sqtable
# exp: testfiles/testout.1/test-noro.9/test-noro.9-NC_001959.dnaorg_annotate.sqtable
chomp $line;
if($line =~ m/\r$/) { chop $line; } # remove ^M if it exists
if($line =~ s/^command\:\s+//) {
my $cmd = $line;
if($ncmd > 0) {
# make sure we have read >= 1 outfiles and expfiles for previous command
if(! (@{$outfile_AAR->[($ncmd-1)]})) { ofile_FAIL("ERROR did not read any out: lines for command " . ($ncmd+1), 1, $FH_HR); }
if(! (@{$expfile_AAR->[($ncmd-1)]})) { ofile_FAIL("ERROR did not read any exp: lines for command " . ($ncmd+1), 1, $FH_HR); }
my $nout_prv = scalar(@{$outfile_AAR->[($ncmd-1)]});
my $nexp_prv = scalar(@{$expfile_AAR->[($ncmd-1)]});
if($nout_prv != $nexp_prv) {
ofile_FAIL("ERROR different number of output and expected lines for command " . ($ncmd+1), 1, $FH_HR);
}
}
# replace !<s>! with value of --<s> from options, die if it wasn't set or doesn't exist
while($cmd =~ /\!(\w+)\!/) {
my $var = $1;
my $varopt = "--" . $var;
if(! opt_Exists($varopt, $opt_HHR)) {
ofile_FAIL("ERROR trying to replace !$var! in test file but option --$var does not exist in command line options", 1, $FH_HR);
}
if(! opt_IsUsed($varopt, $opt_HHR)) {
ofile_FAIL("ERROR trying to replace !$var! in test file but option --$var was not specified on the command line, please rerun with --$var", 1, $FH_HR);
}
my $replacevalue = opt_Get($varopt, $opt_HHR);
$cmd =~ s/\!$var\!/$replacevalue/g;
}
push(@{$cmd_AR}, $cmd);
$ncmd++;
}
elsif($line =~ s/^desc\:\s+//) {
my $desc = $line;
push(@{$desc_AR}, $desc);
$ndesc++;
}
elsif($line =~ s/^out\:\s+//) {
$outfile = $line;
$outfile =~ s/^\s+//;
$outfile =~ s/\s+$//;
if($outfile =~ m/\s/) { ofile_FAIL("ERROR output file has spaces: $outfile", 1, $FH_HR); }
if(scalar(@{$outfile_AAR}) < $ncmd) {
@{$outfile_AAR->[($ncmd-1)]} = ();
}
push(@{$outfile_AAR->[($ncmd-1)]}, $outfile);
if((opt_IsUsed("-s", $opt_HHR)) && (opt_Get("-s", $opt_HHR))) {
# -s used, we aren't running commands, just comparing files, output files must already exist
if(! -e $outfile) { ofile_FAIL("ERROR, output file $outfile does not already exist (and -s used)", 1, $FH_HR); }
}
elsif((opt_IsUsed("--rmout", $opt_HHR)) && (opt_Get("--rmout", $opt_HHR))) {
# --rmout used, remove any file that already exists
if(-e $outfile) { utl_FileRemoveUsingSystemRm($outfile, "ribotest", $opt_HHR, $FH_HR); }
}
else {
# -s not used
if(-e $outfile) { ofile_FAIL("ERROR, output file $outfile already exists (and -s not used)", 1, $FH_HR); }
}
}
elsif($line =~ s/^exp\:\s+//) {
$expfile = $line;
$expfile =~ s/^\s+//;
$expfile =~ s/\s+$//;
# replace @<s>@ with value of $ENV{'<s>'}
while($expfile =~ /\@(\w+)\@/) {
my $envvar = $1;
my $replacevalue = $ENV{"$envvar"};
$expfile =~ s/\@$envvar\@/$replacevalue/g;
}
if($expfile =~ m/\s/) { ofile_FAIL("ERROR expected file has spaces: $expfile", 1, $FH_HR) }
if(scalar(@{$expfile_AAR}) < $ncmd) {
@{$expfile_AAR->[($ncmd-1)]} = ();
}
push(@{$expfile_AAR->[($ncmd-1)]}, $expfile);
if(! -e $expfile) { ofile_FAIL("ERROR, expected file $expfile does not exist", 1, $FH_HR); }
}
elsif($line =~ s/^rmdir\:\s+//) {
$rmdir = $line;
$rmdir =~ s/^\s+//;
$rmdir =~ s/\s+$//;
if(! defined $rmdir_AAR->[($ncmd-1)]) {
@{$rmdir_AAR->[($ncmd-1)]} = ();
}
push(@{$rmdir_AAR->[($ncmd-1)]}, "$rmdir");
}
else {
ofile_FAIL("ERROR unable to parse line $line in $testfile", 1, $FH_HR);
}
}
}
close(IN);
if($ndesc != $ncmd) { ofile_FAIL("ERROR did not read same number of descriptions and commands", 1, $FH_HR); }
# for final command, check that number of exp and out files is equal
if(! (@{$outfile_AAR->[($ncmd-1)]})) { ofile_FAIL("ERROR did not read any out: lines for command " . ($ncmd+1), 1, $FH_HR); }
if(! (@{$expfile_AAR->[($ncmd-1)]})) { ofile_FAIL("ERROR did not read any exp: lines for command " . ($ncmd+1), 1, $FH_HR); }
my $nout_prv = scalar(@{$outfile_AAR->[($ncmd-1)]});
my $nexp_prv = scalar(@{$expfile_AAR->[($ncmd-1)]});
if($nout_prv != $nexp_prv) {
ofile_FAIL("ERROR different number of output and expected lines for command " . ($ncmd+1), 1, $FH_HR);
}
return $ncmd;
}
#################################################################
# Subroutine: test_DiffTwoFiles()
# Incept: EPN, Thu May 17 14:24:06 2018
#
# Purpose: Diff two files, and output whether they are identical or not.
#
# Arguments:
# $out_file: name of output file
# $exp_file: name of expected file
# $diff_file: output file for diff command
# $FH_HR: REF to hash of file handles, including "log" and "cmd"
#
# Returns: '1' if $outfile is identical to $expfile as determined by diff
#
# Dies: If an expected file does not exist or is empty.
#
#################################################################
sub test_DiffTwoFiles {
my $sub_name = "test_DiffTwoFiles";
my $nargs_expected = 4;
if(scalar(@_) != $nargs_expected) { printf STDERR ("ERROR, $sub_name entered with %d != %d input arguments.\n", scalar(@_), $nargs_expected); exit(1); }
my ($out_file, $exp_file, $diff_file, $FH_HR) = @_;
my $out_file_exists = (-e $out_file) ? 1 : 0;
my $exp_file_exists = (-e $exp_file) ? 1 : 0;
my $out_file_nonempty = (-s $out_file) ? 1 : 0;
my $exp_file_nonempty = (-s $exp_file) ? 1 : 0;
my $conclusion = "";
my $pass = 0;
if(! $exp_file_exists) {
ofile_FAIL("ERROR in $sub_name, expected file $exp_file does not exist", 1, $FH_HR) ;
}
if(! $exp_file_nonempty) {
ofile_FAIL("ERROR in $sub_name, expected file $exp_file exists but is empty", 1, $FH_HR);
}
ofile_OutputString($FH_HR->{"log"}, 1, sprintf("#\t%-60s ... ", "checking $out_file"));
if($out_file_nonempty) {
my $cmd = "diff -U 0 $out_file $exp_file > $diff_file";
# don't use runCommand() because diff 'fails' if files are not identical
ofile_OutputString($FH_HR->{"cmd"}, 0, "$cmd\n");
system($cmd);
if(-s $diff_file) {
# copy the two files here:
my $copy_of_out_file = $diff_file . ".out";
my $copy_of_exp_file = $diff_file . ".exp";
utl_RunCommand("cp $out_file $copy_of_out_file", 0, 0, $FH_HR);
utl_RunCommand("cp $exp_file $copy_of_exp_file", 0, 0, $FH_HR);
# analyze the diff file and print out how many lines
if($out_file =~ m/\.sqtable/ && $exp_file =~ m/\.sqtable/) {
my $sqtable_diff_file = $diff_file . ".man";
test_DnaorgCompareTwoSqtableFiles($out_file, $exp_file, $sqtable_diff_file, $FH_HR);
$conclusion = "FAIL [files differ, see $sqtable_diff_file]";
}
else {
$conclusion = "FAIL [files differ, see $diff_file]";
}
}
else {
$conclusion = "pass";
$pass = 1;
}
}
else {
$conclusion = ($out_file_exists) ? "FAIL [output file exists but is empty]" : "FAIL [output file does not exist]";
}
ofile_OutputString($FH_HR->{"log"}, 1, "$conclusion\n");
return $pass;
}