File: a3_diff_decipher.pl

package info (click to toggle)
primer3 2.6.1-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 142,204 kB
  • sloc: ansic: 11,150; cpp: 8,231; perl: 2,296; makefile: 318; sh: 53
file content (306 lines) | stat: -rwxr-xr-x 9,300 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/perl

# Regression test driver for the amplicon3_core executable.
#
# For usage, see the usage statement in the code, below.
#
# ======================================================================
# (c) Copyright 2021
# Whitehead Institute for Biomedical Research, Steve Rozen, 
# Andreas Untergasser and Helen Skaletsky
# All rights reserved.
# 
#   This file is part of the primer3 suite.
#
#   The primer3 suite is free software; you can redistribute it and/or
#   modify it under the terms of the GNU General Public License as
#   published by the Free Software Foundation; either version 2 of the
#   License, or (at your option) any later version.
#
#   This software is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this file (file gpl-2.0.txt in the source distribution); if
#   not, write to the Free Software Foundation, Inc., 51 Franklin St,
#   Fifth Floor, Boston, MA 02110-1301 USA
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# ======================================================================

use warnings 'all';
use strict;
use Cwd;
use Getopt::Long;
use POSIX; # For testing wait / system return value, e.g. WIFSIGNALED, WTERMSIG.....
use Config; # To get the number for SIGINT

sub perldiff($$);
sub perldifffloat($$);
sub main();

# Call system() with warnings turned off; needed for ActiveState / MS Windows.
sub _nowarn_system($); 

our $set_files = 'amplicon3/';

our %signo;


# Global variable for Errors
my $all_ok;

main();

sub main() {
    my %args;

    # select STDERR;
    $| = 1;
    my $exit_stat = 0;

    print "$0 compare with DECIPHER output\n";
    
    $all_ok = 1;
    my $overall_start_time = time();

    if (defined $Config{sig_name}) {
          my $i = 0;
          for my $name (split(' ', $Config{sig_name})) {
            $signo{$name} = $i;
            $i++;
          }
    }

    my $amplicons = $set_files . 'amplicons.csv';

    open(AMPLISEQ, '<', $amplicons) or die "Cannot read $amplicons";
    while(<AMPLISEQ>) {
        my @cur_amplicon = split(";", $_);
        my $r;  # Return value for tests

        my $amplicon3_output = $set_files . 'heli_ts_' . $cur_amplicon[0] . '_output';
        my $decipher_output = $set_files . 'decipher_' . $cur_amplicon[0] . '_heli.csv';

        $r = perldifffloat($amplicon3_output, $decipher_output);

        print ($cur_amplicon[0] . ": Helix values ");
        if ($r == 0) {
            print "[OK]\n";
        } else {
            $all_ok = 0;
            print "[FAILED]\n";
            $exit_stat = -1;
        }
        $r = 0;

        $amplicon3_output = $set_files . 'only_mv_ts_' . $cur_amplicon[0] . '_output';
        open(AMPOUT, '<', $amplicon3_output) or die "open $amplicon3_output: $!";
        my @out_arr = <AMPOUT>;
        my @temps;
        my @melt;
        my @deriv;
        for my $i (0 .. $#out_arr) {
            my @line = split("=", $out_arr[$i]);
            $line[1] =~ s/\n//g;
            if ($line[0] eq "AMPLICON_TEMPERATURES") {
                @temps = split(",", $line[1]);
            }
            if ($line[0] eq "AMPLICON_MELT_CURVE") {
                @melt = split(",", $line[1]);
            }
            if ($line[0] eq "AMPLICON_DERIVATIVE_CURVE") {
                @deriv = split(",", $line[1]);
            }
        }
        my $sum_melt = "";
        my $sum_deriv = "";
        for my $k (0 .. $#temps) {
            $sum_melt .= $temps[$k];
            $sum_deriv .= $temps[$k];
            $sum_melt .= "\t";
            $sum_deriv .= "\t";
            $sum_melt .= $melt[$k];
            $sum_deriv .= $deriv[$k];
            $sum_melt .= "\n";
            $sum_deriv .= "\n";
        }
        close(AMPOUT);

        $decipher_output = $set_files . 'decipher_' . $cur_amplicon[0] . '_melt.csv';
        $r = perldiff $sum_melt, $decipher_output;
        print ($cur_amplicon[0] . ": Melting values ");
        if ($r == 0) {
            print "[OK]\n";
        } else {
            $all_ok = 0;
            print "[FAILED]\n";
            $exit_stat = -1;
        }
        $r = 0;
        $decipher_output = $set_files . 'decipher_' . $cur_amplicon[0] . '_deriv.csv';
        $r = perldiff $sum_deriv, $decipher_output;
        print ($cur_amplicon[0] . ": Derivate values ");
        if ($r == 0) {
            print "[OK]\n";
        } else {
            $all_ok = 0;
            print "[FAILED]\n";
            $exit_stat = -1;
        }
    }
    close(AMPLISEQ);

    print "\nDONE ";

    print $all_ok ? "Passed all tests - [OK]\n\n\n" : "At least one test failed - [FAILED]\n\n\n";

    if ($all_ok != 1 ) {
        $exit_stat = -1;
    }

    exit 0;  #  Generally we want the testing to continue.
}

# Usage: perldiff("string", "filename2")
# Return 0 if no differences are found,
# othewise return 1;
sub perldiff($$) {
    my ($f1, $f2) = @_;

    open(F2, '<', $f2) or die "open $f2: $!";

    my @f1 = split("\n", $f1);
    my @f2 = <F2>;

    my $test_count = 0;
    my $all_count = 0;

    # If different number of lines, return FAIL.
    if (@f1 != @f2) {
        print "\n   Different number of lines;\n";
        print "   Check file $f2\n\n";
        return 1;
    }
    # check for differences on the lines, themselves
    my $linenumber = 0;
    my $line_end_diff = 0;
    my $linErr = 0;
    # iterate using lines in file1
    while (@f1) {
        $linenumber++;

        # get the lines from each respective file
        my $l1 = shift @f1;
        my $l2 = shift @f2;
        my @arr1 = split("\t", $l1);
        my @arr2 = split("\t", $l2);
        if ($#arr1 != $#arr2) {
            $linErr = 1;
        }
        for my $i (0 .. $#arr1) {
            if ($arr1[$i] - $arr2[$i] > 0.000003) {
                $linErr = 1;
            }
            if (($arr1[$i] < 0.000003) || ($arr2[$i] < 0.000003)) {
               $test_count++;
            }
            $all_count++;
        }

        $linenumber++;
        # Check for difference between two edited lines (line by line)
        if ($linErr != 0) {
            print "\n   Difference found at line $linenumber!\n";
            print "   There may be additional differences.\n";
            print "   Check file $f2\n\n";
            return 1;
        }
    }
    close(F1);
    close(F2);
    my $percent = ($test_count / $all_count) * 100;
    print "\n   $test_count of $all_count (" . sprintf("%.1f", $percent) . "%) below test limit of 0.000003.\n";

    return 0;
}


sub perldifffloat($$) {
    my ($f1, $f2) = @_;

    open(F1, '<', $f1) or die "open $f1: $!";
    open(F2, '<', $f2) or die "open $f2: $!";

    my @f1 = <F1>;
    my @f2 = <F2>;

    shift @f1;
    shift @f1;
    shift @f2;

    my $test_count = 0;
    my $all_count = 0;

    # If different number of lines, return FAIL.
    if (@f1 != @f2) {
        print "\n   Different number of lines;\n";
        print "   on command line in test directory run:\n";
        print "   diff $f1 $f2\n\n";
        return 1;
    }
    # check for differences on the lines, themselves
    my $linenumber = 0;
    my $line_end_diff = 0;
    my $linErr = 0;
    # iterate using lines in file1
    while (@f1) {
        $linenumber++;

        # get the lines from each respective file
        my $l1 = shift @f1;
        my $l2 = shift @f2;
        my @arr1 = split("\t", $l1);
        my @arr2 = split("\t", $l2);
        if ($#arr1 != $#arr2) {
            $linErr = 1;
        }
        for my $i (0 .. $#arr1) {
            if ($arr1[$i] - $arr2[$i] > 0.000003) {
                $linErr = 1;
            }
            if (($arr1[$i] < 0.000003) || ($arr2[$i] < 0.000003)) {
               $test_count++;
            }
            $all_count++;
        }

        $linenumber++;
        # Check for difference between two edited lines (line by line)
        if ($linErr != 0) {
            print "\n   Difference found at line $linenumber!\n";
            print "   There may be additional differences.\n";
            print "   On command line in test directory run\n\n";
            print "   diff $f1 $f2\n\n";
            return 1;
        }
    }
    close(F1);
    close(F2);
    my $percent = ($test_count / $all_count) * 100;
    print "\n   $test_count of $all_count (" . sprintf("%.1f", $percent) . "%) below test limit of 0.000003.\n";

    return 0;
}