6640 |
11 Mar 22 |
nicklas |
#!/bin/bash |
6640 |
11 Mar 22 |
nicklas |
2 |
|
6640 |
11 Mar 22 |
nicklas |
# $Id $ |
6640 |
11 Mar 22 |
nicklas |
4 |
|
6640 |
11 Mar 22 |
nicklas |
# Nicklas Nordborg |
6640 |
11 Mar 22 |
nicklas |
6 |
|
6640 |
11 Mar 22 |
nicklas |
# run ./alignment_statistics.sh path-to-aligned-bam <path-to-unmapped-bam> |
6640 |
11 Mar 22 |
nicklas |
8 |
|
6640 |
11 Mar 22 |
nicklas |
9 |
ALIGNMENT_BAM=$1 |
6640 |
11 Mar 22 |
nicklas |
10 |
UNMAPPED_BAM=$2 |
6640 |
11 Mar 22 |
nicklas |
11 |
|
6640 |
11 Mar 22 |
nicklas |
# Flag Chr Description |
6640 |
11 Mar 22 |
nicklas |
# 0x0001 p the read is paired in sequencing |
6640 |
11 Mar 22 |
nicklas |
# 0x0002 P the read is mapped in a proper pair |
6640 |
11 Mar 22 |
nicklas |
# 0x0004 u the query sequence itself is unmapped |
6640 |
11 Mar 22 |
nicklas |
# 0x0008 U the mate is unmapped |
6640 |
11 Mar 22 |
nicklas |
# 0x0010 r strand of the query (1 for reverse) |
6640 |
11 Mar 22 |
nicklas |
# 0x0020 R strand of the mate |
6640 |
11 Mar 22 |
nicklas |
# 0x0040 1 the read is the first read in a pair |
6640 |
11 Mar 22 |
nicklas |
# 0x0080 2 the read is the second read in a pair |
6640 |
11 Mar 22 |
nicklas |
# 0x0100 s the alignment is not primary |
6640 |
11 Mar 22 |
nicklas |
# 0x0200 f the read fails platform/vendor quality checks |
6640 |
11 Mar 22 |
nicklas |
# 0x0400 d the read is either a PCR or an optical duplicate |
6640 |
11 Mar 22 |
nicklas |
24 |
|
6640 |
11 Mar 22 |
nicklas |
25 |
SamtoolsVersion=`${SAMTOOLS} |& grep Version` |
6640 |
11 Mar 22 |
nicklas |
26 |
echo "${SAMTOOLS} ${SamtoolsVersion}" |
6640 |
11 Mar 22 |
nicklas |
27 |
echo "---------------------" |
6640 |
11 Mar 22 |
nicklas |
28 |
|
6640 |
11 Mar 22 |
nicklas |
29 |
if [ -f "${ALIGNMENT_BAM}" ]; then |
6640 |
11 Mar 22 |
nicklas |
30 |
cmd="${SAMTOOLS} view -c" |
6640 |
11 Mar 22 |
nicklas |
# skip not primary alignments |
6640 |
11 Mar 22 |
nicklas |
32 |
cmd=${cmd}" -F 0x0100" |
6640 |
11 Mar 22 |
nicklas |
# keep first reads and mapped proper pair |
6640 |
11 Mar 22 |
nicklas |
34 |
cmd=${cmd}" -f 0x0042" |
6640 |
11 Mar 22 |
nicklas |
35 |
cmd=${cmd}" ${ALIGNMENT_BAM}" |
6640 |
11 Mar 22 |
nicklas |
36 |
echo ${cmd} |
6640 |
11 Mar 22 |
nicklas |
37 |
${cmd} |
6640 |
11 Mar 22 |
nicklas |
38 |
|
6640 |
11 Mar 22 |
nicklas |
39 |
echo "---------------------" |
6640 |
11 Mar 22 |
nicklas |
40 |
|
6640 |
11 Mar 22 |
nicklas |
41 |
cmd="${SAMTOOLS} flagstat" |
6640 |
11 Mar 22 |
nicklas |
42 |
cmd=${cmd}" ${ALIGNMENT_BAM}" |
6640 |
11 Mar 22 |
nicklas |
43 |
echo ${cmd} |
6640 |
11 Mar 22 |
nicklas |
44 |
${cmd} |
6640 |
11 Mar 22 |
nicklas |
45 |
|
6640 |
11 Mar 22 |
nicklas |
46 |
echo "---------------------" |
6640 |
11 Mar 22 |
nicklas |
47 |
fi |
6640 |
11 Mar 22 |
nicklas |
48 |
|
6640 |
11 Mar 22 |
nicklas |
49 |
if [ -f "${UNMAPPED_BAM}" ]; then |
6640 |
11 Mar 22 |
nicklas |
50 |
cmd="${SAMTOOLS} flagstat" |
6640 |
11 Mar 22 |
nicklas |
51 |
cmd=${cmd}" ${UNMAPPED_BAM}" |
6640 |
11 Mar 22 |
nicklas |
52 |
echo ${cmd} |
6640 |
11 Mar 22 |
nicklas |
53 |
${cmd} |
6640 |
11 Mar 22 |
nicklas |
54 |
fi |