2557 |
05 Aug 14 |
nicklas |
#!/bin/sh |
2557 |
05 Aug 14 |
nicklas |
2 |
|
2557 |
05 Aug 14 |
nicklas |
# $Id$ |
2557 |
05 Aug 14 |
nicklas |
4 |
|
2557 |
05 Aug 14 |
nicklas |
# Nicklas Nordborg |
2557 |
05 Aug 14 |
nicklas |
6 |
|
2557 |
05 Aug 14 |
nicklas |
# run ./alignment_statistics.sh path-to-folder |
2557 |
05 Aug 14 |
nicklas |
# Path whould be given to a folder containing |
2557 |
05 Aug 14 |
nicklas |
# accepted_hits.bam and unmapped.bam |
2557 |
05 Aug 14 |
nicklas |
10 |
|
2786 |
13 Oct 14 |
nicklas |
11 |
if [ -z "$SAMTOOLS" ]; then |
2786 |
13 Oct 14 |
nicklas |
12 |
SAMTOOLS=samtools |
2786 |
13 Oct 14 |
nicklas |
13 |
fi |
2557 |
05 Aug 14 |
nicklas |
14 |
|
2557 |
05 Aug 14 |
nicklas |
15 |
DIR=$1 |
2557 |
05 Aug 14 |
nicklas |
16 |
|
4589 |
25 Sep 17 |
nicklas |
# Look for 'accepted_hits.bam' or 'alignment.bam' |
2557 |
05 Aug 14 |
nicklas |
18 |
ACCEPTED_HITS=${DIR}/accepted_hits.bam |
4589 |
25 Sep 17 |
nicklas |
19 |
if [ ! -f "${ACCEPTED_HITS}" ]; then |
4589 |
25 Sep 17 |
nicklas |
20 |
ACCEPTED_HITS=${DIR}/alignment.bam |
4589 |
25 Sep 17 |
nicklas |
21 |
fi |
4589 |
25 Sep 17 |
nicklas |
22 |
|
2557 |
05 Aug 14 |
nicklas |
23 |
UNMAPPED=${DIR}/unmapped.bam |
2557 |
05 Aug 14 |
nicklas |
24 |
|
2557 |
05 Aug 14 |
nicklas |
# Flag Chr Description |
2557 |
05 Aug 14 |
nicklas |
# 0x0001 p the read is paired in sequencing |
2557 |
05 Aug 14 |
nicklas |
# 0x0002 P the read is mapped in a proper pair |
2557 |
05 Aug 14 |
nicklas |
# 0x0004 u the query sequence itself is unmapped |
2557 |
05 Aug 14 |
nicklas |
# 0x0008 U the mate is unmapped |
2557 |
05 Aug 14 |
nicklas |
# 0x0010 r strand of the query (1 for reverse) |
2557 |
05 Aug 14 |
nicklas |
# 0x0020 R strand of the mate |
2557 |
05 Aug 14 |
nicklas |
# 0x0040 1 the read is the first read in a pair |
2557 |
05 Aug 14 |
nicklas |
# 0x0080 2 the read is the second read in a pair |
2557 |
05 Aug 14 |
nicklas |
# 0x0100 s the alignment is not primary |
2557 |
05 Aug 14 |
nicklas |
# 0x0200 f the read fails platform/vendor quality checks |
2557 |
05 Aug 14 |
nicklas |
# 0x0400 d the read is either a PCR or an optical duplicate |
2557 |
05 Aug 14 |
nicklas |
37 |
|
2557 |
05 Aug 14 |
nicklas |
38 |
SamtoolsVersion=`${SAMTOOLS} |& grep Version` |
2557 |
05 Aug 14 |
nicklas |
39 |
echo "${SAMTOOLS} ${SamtoolsVersion}" |
2557 |
05 Aug 14 |
nicklas |
40 |
echo "---------------------" |
4589 |
25 Sep 17 |
nicklas |
41 |
|
4589 |
25 Sep 17 |
nicklas |
42 |
if [ -f "${ACCEPTED_HITS}" ]; then |
2557 |
05 Aug 14 |
nicklas |
43 |
cmd="${SAMTOOLS} view -c" |
2557 |
05 Aug 14 |
nicklas |
# skip not primary alignments |
2557 |
05 Aug 14 |
nicklas |
45 |
cmd=${cmd}" -F 0x0100" |
2557 |
05 Aug 14 |
nicklas |
# keep first reads and mapped proper pair |
2557 |
05 Aug 14 |
nicklas |
47 |
cmd=${cmd}" -f 0x0042" |
2557 |
05 Aug 14 |
nicklas |
48 |
cmd=${cmd}" ${ACCEPTED_HITS}" |
2557 |
05 Aug 14 |
nicklas |
49 |
echo ${cmd} |
2557 |
05 Aug 14 |
nicklas |
50 |
${cmd} |
2557 |
05 Aug 14 |
nicklas |
51 |
|
2557 |
05 Aug 14 |
nicklas |
52 |
echo "---------------------" |
2557 |
05 Aug 14 |
nicklas |
53 |
|
2557 |
05 Aug 14 |
nicklas |
54 |
cmd="${SAMTOOLS} flagstat" |
2557 |
05 Aug 14 |
nicklas |
55 |
cmd=${cmd}" ${ACCEPTED_HITS}" |
2557 |
05 Aug 14 |
nicklas |
56 |
echo ${cmd} |
2557 |
05 Aug 14 |
nicklas |
57 |
${cmd} |
2557 |
05 Aug 14 |
nicklas |
58 |
|
2557 |
05 Aug 14 |
nicklas |
59 |
echo "---------------------" |
4589 |
25 Sep 17 |
nicklas |
60 |
fi |
2557 |
05 Aug 14 |
nicklas |
61 |
|
4589 |
25 Sep 17 |
nicklas |
62 |
if [ -f "${UNMAPPED}" ]; then |
2557 |
05 Aug 14 |
nicklas |
63 |
cmd="${SAMTOOLS} flagstat" |
2557 |
05 Aug 14 |
nicklas |
64 |
cmd=${cmd}" ${UNMAPPED}" |
2557 |
05 Aug 14 |
nicklas |
65 |
echo ${cmd} |
4589 |
25 Sep 17 |
nicklas |
66 |
${cmd} |
4589 |
25 Sep 17 |
nicklas |
67 |
fi |