File: scram.test

package info (click to toggle)
staden-io-lib 1.14.11-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 14,116 kB
  • sloc: ansic: 50,895; makefile: 341; sh: 219; perl: 198
file content (113 lines) | stat: -rwxr-xr-x 4,353 bytes parent folder | download
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
#!/bin/sh

$srcdir/generate_data.pl || exit 1

scramble="${VALGRIND} $top_builddir/progs/scramble ${SCRAMBLE_ARGS}"
cram_index="${VALGRIND} $top_builddir/progs/cram_index"
compare_sam=$srcdir/compare_sam.pl

#valgrind="valgrind --leak-check=full"
#scramble="$valgrind $scramble"

case $# in
    0) files=`/bin/ls $srcdir/data/*#*.sam $srcdir/data/*#*.bam | egrep -v '[._](full|\.sub|java)\.'`
       ;;
    *) files=${@+"$@"}
       ;;
esac

for i in $files
do
    ref=`echo $i | sed 's/#.*/.fa/'`
    root=`echo $i | sed 's/\.[sb]am$//;s:.*/::'`
    echo "=== testing $i ==="


    # Create BAM from SAM or SAM from BAM
    if [ `echo $i | sed 's/\.bam//'` = $i ]
    then
	echo "$scramble $i $outdir/$root.bam"
	$scramble $i $outdir/$root.bam || exit 1
	cmp_sam=$srcdir/data/$root.sam
	in_bam=$outdir/$root.bam
    else
	echo "$scramble $i $outdir/$root.sam"
	$scramble $i $outdir/$root.sam || exit 1
	cmp_sam=$outdir/$root.sam
	in_bam=$i
    fi

    # Create CRAM
    echo "$scramble -r $ref $in_bam $outdir/$root.full.cram"
    $scramble -r $ref $in_bam $outdir/$root.full.cram || exit 1

    # Test conversion back to SAM 
    echo "$scramble $in_bam > $outdir/tmp.sam"
    $scramble $in_bam > $outdir/tmp.sam || exit 1
    $compare_sam $cmp_sam $outdir/tmp.sam || exit 1

    echo "$scramble $outdir/$root.full.cram > $outdir/$root.full.sam"
    $scramble $outdir/$root.full.cram > $outdir/$root.full.sam || exit 1
    $compare_sam --nomd --unknownrg $cmp_sam $outdir/$root.full.sam || exit 1

    echo "$scramble -O bam $outdir/$root.full.cram > $outdir/$root.full.bam"
    $scramble -O bam $outdir/$root.full.cram > $outdir/$root.full.bam || exit 1
    echo "$scramble $outdir/$root.full.bam $outdir/tmp.sam"
    $scramble $outdir/$root.full.bam $outdir/tmp.sam || exit 1
    sed '/^@PG.*scramble\.3.*/d;s/^\(@PG.*scramble.*\) -O bam/\1/' $outdir/tmp.sam > $outdir/$root.full.bam.sam
    rm $outdir/tmp.sam
    echo "$compare_sam --nopg $outdir/$root.full.sam $outdir/$root.full.bam.sam"
    $compare_sam --nopg $outdir/$root.full.sam $outdir/$root.full.bam.sam || exit 1


    # Try again with embedded ref; skip for unsorted sams
    case "$root" in
    *"unsorted") #skip
        ;;
    *) 
        echo "$scramble -e -r $ref $in_bam $outdir/$root.full.cram"
        $scramble -e -r $ref $in_bam $outdir/$root.full.cram || exit 1
        
        echo "$scramble $outdir/$root.full.cram > $outdir/$root.full.sam"
        $scramble $outdir/$root.full.cram > $outdir/tmp.sam || exit 1
	sed '/^@PG.*scramble\.3.*/d;s/^\(@PG.*scramble.*\) -e /\1 /' $outdir/tmp.sam > $outdir/$root.full.bam.sam
        $compare_sam --nomd --unknownrg $cmp_sam $outdir/$root.full.sam || exit 1
        echo "$compare_sam --nopg $outdir/$root.full.sam $outdir/$root.full.bam.sam"
        $compare_sam --nopg $outdir/$root.full.sam $outdir/$root.full.bam.sam || exit 1
	;;
    esac


    # And again with no ref.
    echo "$scramble -x -r $ref $in_bam $outdir/$root.full.cram"
    $scramble -x -r $ref $in_bam $outdir/$root.full.cram || exit 1

    echo "$scramble $outdir/$root.full.cram > $outdir/$root.full.sam"
    $scramble $outdir/$root.full.cram > $outdir/tmp.sam || exit 1
    sed '/^@PG.*scramble\.3.*/d;s/^\(@PG.*scramble.*\) -x /\1 /' $outdir/tmp.sam > $outdir/$root.full.bam.sam
    $compare_sam --nomd --unknownrg $cmp_sam $outdir/$root.full.sam || exit 1
    # need compare against original here as ce#5b.sam as "*" in seq.
    echo "$compare_sam --unknownrg $cmp_sam $outdir/$root.full.bam.sam"
    $compare_sam --noqual --unknownrg $cmp_sam $outdir/$root.full.bam.sam || exit 1

    echo ""
done

# Range queries, CRAM only
$cram_index $outdir/ce#sorted.full.cram
echo $scramble -H -r $srcdir/data/ce.fa $outdir/ce#sorted.full.cram
nr=`$scramble -H -r $srcdir/data/ce.fa $outdir/ce#sorted.full.cram | wc -l`
echo "No region:               $nr"
[ $nr -eq 521616 ] || exit 1

nr=`$scramble -H -R "*" -r $srcdir/data/ce.fa $outdir/ce#sorted.full.cram | wc -l`
echo "* region:                $nr"
[ $nr -eq 2452 ] || exit 1

nr=`$scramble -H -R "CHROMOSOME_I" -r $srcdir/data/ce.fa $outdir/ce#sorted.full.cram | wc -l`
echo "CHROMOSOME_I:            $nr"
[ $nr -eq 504705 ] || exit 1

nr=`$scramble -H -R "CHROMOSOME_I:35000-45000" -r $srcdir/data/ce.fa $outdir/ce#sorted.full.cram | wc -l`
echo "CHROMOSOME_I:35000-45000 $nr"
[ $nr -eq 5066 ] || exit 1