annotate ezBAMQC/src/htslib/test/test_view.pl @ 0:dfa3745e5fd8

Uploaded
author youngkim
date Thu, 24 Mar 2016 17:12:52 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
1 #! /usr/bin/env perl
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
2 #
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
3 # Copyright (C) 2013 Genome Research Ltd.
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
4 #
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
5 # Author: James Bonfield <jkb@sanger.ac.uk>
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
6 #
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
7 # Permission is hereby granted, free of charge, to any person obtaining a copy
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
8 # of this software and associated documentation files (the "Software"), to deal
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
9 # in the Software without restriction, including without limitation the rights
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
10 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
11 # copies of the Software, and to permit persons to whom the Software is
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
12 # furnished to do so, subject to the following conditions:
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
13 #
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
14 # The above copyright notice and this permission notice shall be included in
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
15 # all copies or substantial portions of the Software.
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
16 #
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
20 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
22 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
23 # DEALINGS IN THE SOFTWARE.
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
24 use strict;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
25 use warnings;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
26
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
27 my $err_count = 0;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
28 my $suc_count = 0;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
29
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
30 sub test {
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
31 my ($cmd) = @_;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
32 print " $cmd\n";
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
33 if (system("$cmd || exit 1") != 0) {
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
34 print "FAIL $!\n";
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
35 $err_count++;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
36 } else {
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
37 $suc_count++;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
38 }
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
39 }
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
40
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
41 foreach my $sam (glob("*#*.sam")) {
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
42 my ($base, $ref) = ($sam =~ /((.*)#.*)\.sam/);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
43 $ref .= ".fa";
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
44
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
45 my $bam = "$base.tmp.bam";
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
46 my $cram = "$base.tmp.cram";
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
47
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
48 print "\n=== Testing $sam, ref $ref ===\n";
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
49
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
50 # SAM -> BAM -> SAM
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
51 test "./test_view -S -b $sam > $bam";
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
52 test "./test_view $bam > $bam.sam_";
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
53 test "./compare_sam.pl $sam $bam.sam_";
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
54
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
55 # SAM -> CRAM -> SAM
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
56 test "./test_view -t $ref -S -C $sam > $cram";
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
57 test "./test_view -D $cram > $cram.sam_";
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
58 test "./compare_sam.pl -nomd $sam $cram.sam_";
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
59
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
60 # BAM -> CRAM -> BAM -> SAM
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
61 $cram = "$bam.cram";
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
62 test "./test_view -t $ref -C $bam > $cram";
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
63 test "./test_view -b -D $cram > $cram.bam";
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
64 test "./test_view $cram.bam > $cram.bam.sam_";
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
65 test "./compare_sam.pl -nomd $sam $cram.bam.sam_";
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
66 }
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
67
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
68 print "\nSuccesses $suc_count\n";
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
69 print "\nFailures $err_count\n";
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
70
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
71 exit ($err_count > 0);