modified: pixi.toml
[GalaxyCodeBases.git] / BioInfo / BS-Seq / bwa-meth / example / test.sh
blob7b3dd43ece8da799d9af6862998d80ecb2489f3a
1 # from http://tldp.org/LDP/abs/html/debugging.html#ASSERT
2 set -e -o nounset
3 assert () # If condition false,
4 { #+ exit from script
5 #+ with appropriate error message.
6 E_PARAM_ERR=98
7 E_ASSERT_FAILED=99
10 if [ -z "$2" ] # Not enough parameters passed
11 then #+ to assert() function.
12 return $E_PARAM_ERR # No damage done.
15 lineno=$2
17 if [ ! $1 ]
18 then
19 echo "Assertion failed: \"$1\""
20 echo "File \"$0\", line $lineno" # Give name of file and line number.
21 exit $E_ASSERT_FAILED
22 # else
23 # return
24 # and continue executing the script.
25 fi
26 echo "
27 [TEST]: '$1' PASSED at line:$lineno
32 rm -f ref.bwameth* bwa-meth.bam
34 python ../bwameth.py index ref.fa
36 ##########################
37 # test read-group
38 ##########################
39 rm -f bwa-meth.bam*
40 python ../bwameth.py --read-group $'@RG\tID:asdf\tSM:asdf' --reference ref.fa t_R1.fastq.gz t_R2.fastq.gz | samtools view -b - > bwa-meth.bam
42 n=`samtools view -H bwa-meth.bam | grep "@RG" | grep -cw "ID:asdf"`
43 assert "$n -eq 1" $LINENO
44 a=`samtools view bwa-meth.bam | grep -c RG:Z:asdf`
45 b=`samtools view bwa-meth.bam | wc -l`
46 assert "$a -eq $b" $LINENO
50 ##########################
51 # test normal alignment
52 ##########################
53 python ../bwameth.py --reference ref.fa t_R1.fastq.gz t_R2.fastq.gz \
54 | samtools view -b - > bwa-meth.bam
55 assert " -e bwa-meth.bam " $LINENO
57 ##########################
58 # test multiple fastq sets
59 ##########################
60 # NOTE: here we repeat the same fastq, but you'd want diff ones from same sample
61 rm -f bwa-meth.bam*
62 python ../bwameth.py --reference ref.fa t_R1.fastq.gz,t_R1.fastq.gz t_R2.fastq.gz,t_R2.fastq.gz \
63 | samtools view -b - > bwa-meth.bam
64 assert " -e bwa-meth.bam " $LINENO
66 ##########################
67 # test single end
68 ##########################
69 rm -f bwa-meth.bam*
70 python ../bwameth.py --reference ref.fa t_R1.fastq.gz \
71 | samtools view -b - > bwa-meth.bam
73 assert " -e bwa-meth.bam " $LINENO
74 count=`samtools view -cf2 bwa-meth.bam`
75 assert "$count -eq 0" $LINENO
76 count=`samtools view -cF4 bwa-meth.bam`
77 assert "$count -gt 1000" $LINENO
80 ##############################
81 # test single end, many fastqs
82 ##############################
83 rm -f bwa-meth.bam*
84 python ../bwameth.py --reference ref.fa t_R1.fastq.gz,t_R1.fastq.gz \
85 | samtools view -b - > bwa-meth.bam
86 assert " -e bwa-meth.bam " $LINENO
87 count2=`samtools view -cf2 bwa-meth.bam`
88 assert "$count2 -eq 0" $LINENO
89 count2=`samtools view -cF4 bwa-meth.bam`
90 assert "$count2 -gt $count" $LINENO
93 echo "Success: ALL Tests PASS"