| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
if [ $# -ne 2 ]; then |
| 4 |
echo "Usage: $(basename $0) <abyss_map_sam_file> <dida_sam_file>" >&2 |
| 5 |
exit 1 |
| 6 |
fi |
| 7 |
|
| 8 |
remove_cosmetic_diffs() { |
| 9 |
# (1) take out @PG headers, they are expected to be different |
| 10 |
# (2) in case of unmapped reads |
| 11 |
# (i) DIDA sets RNEXT = "*" instead of "=" |
| 12 |
# (ii) DIDA sets SEQ and QUAL to "*" instead of actual SEQ/QUAL |
| 13 |
egrep -v '^@PG' "$@" | \ |
| 14 |
awk 'BEGIN { OFS="\t" } !/^@/ && $2 == 4 { $7=$10=$11="*" } { print }' |
| 15 |
} |
| 16 |
|
| 17 |
set -eu -o pipefail |
| 18 |
|
| 19 |
abyss_map_output="$1" |
| 20 |
dida_output="$2" |
| 21 |
|
| 22 |
# Known types of differences: |
| 23 |
# |
| 24 |
# (i) Multiple aligns, abyss-map sets MAPQ=0 but DIDA has MAPQ>0. |
| 25 |
# (ii) MAPQ values are equal and > 0, but different CIGAR strings |
| 26 |
# When different fragments of the same read have equal quality |
| 27 |
# alignments, abyss-map will choose arbitrarily. |
| 28 |
# (iii) Different choice between forward and reverse complement, |
| 29 |
# where both aligns have equal quality. |
| 30 |
# (iv) bloom filter miss |
| 31 |
# |
| 32 |
# I have not seen any other types of differences in my testing. |
| 33 |
# |
| 34 |
# - Ben V |
| 35 |
|
| 36 |
paste -d'\n' \ |
| 37 |
<(egrep -v '^@' $abyss_map_output | remove_cosmetic_diffs) \ |
| 38 |
<(egrep -v '^@' $dida_output | remove_cosmetic_diffs) \ |
| 39 |
| awk '\ |
| 40 |
BEGIN { |
| 41 |
mapq_not_zero=diff_read_frags=bloom_filter_misses=diff_dir=unclassified=0; |
| 42 |
aborted=0; |
| 43 |
UNMAPPED_FLAG=4; |
| 44 |
RC_FLAG=16; |
| 45 |
} |
| 46 |
{ |
| 47 |
line1=$0; qname1=$1; flags1=$2; mapq1=$5; cigar1=$6; |
| 48 |
getline; |
| 49 |
line2=$0; qname2=$1; flags2=$2; mapq2=$5; cigar2=$6; |
| 50 |
if (qname1 != qname2) { |
| 51 |
print "error: mismatch between read ids "qname1" and "qname2"!" > "/dev/stderr"; |
| 52 |
print "Ensure that read ids occur in the same order in both files." > "/dev/stderr"; |
| 53 |
aborted=1; |
| 54 |
exit 1; |
| 55 |
} |
| 56 |
if (line1 != line2) { |
| 57 |
if (mapq1 == 0 && mapq2 != 0) { |
| 58 |
mapq_not_zero++; |
| 59 |
print line1 > "mapq_not_zero.abyss-map.lines"; |
| 60 |
print line2 > "mapq_not_zero.dida.lines" |
| 61 |
} |
| 62 |
else if (mapq1 != 0 && mapq2 == 0) { |
| 63 |
mapq_zero++; |
| 64 |
print line1 > "mapq_zero.abyss-map.lines"; |
| 65 |
print line2 > "mapq_zero.dida.lines" |
| 66 |
} |
| 67 |
else if (mapq1 > 0 && mapq1 == mapq2) { |
| 68 |
if (cigar1 != cigar2) { |
| 69 |
diff_read_frags++; |
| 70 |
print line1 > "diff_read_frags.abyss-map.lines"; |
| 71 |
print line2 > "diff_read_frags.dida.lines"; |
| 72 |
} |
| 73 |
else if (and(flags1,RC_FLAG) != and(flags2,RC_FLAG)) { |
| 74 |
diff_dir++; |
| 75 |
print line1 > "diff_dir.abyss-map.lines"; |
| 76 |
print line2 > "diff_dir.dida.lines"; |
| 77 |
} |
| 78 |
else { |
| 79 |
unclassified++; |
| 80 |
print line1 > "unclassified.abyss-map.lines"; |
| 81 |
print line2 > "unclassified.dida.lines"; |
| 82 |
} |
| 83 |
} |
| 84 |
else if (!and(flags1,UNMAPPED_FLAG) && and(flags2,UNMAPPED_FLAG)) { |
| 85 |
bloom_filter_misses++; |
| 86 |
print line1 > "bloom_filter_miss.abyss-map.lines"; |
| 87 |
print line2 > "bloom_filter_miss.dida.lines"; |
| 88 |
} |
| 89 |
else if (mapq1 > 0 || mapq2 > 0) { |
| 90 |
unclassified++; |
| 91 |
print line1 > "unclassified.abyss-map.lines"; |
| 92 |
print line2 > "unclassified.dida.lines"; |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
END { |
| 97 |
if (aborted) |
| 98 |
exit 1; |
| 99 |
|
| 100 |
print "diff counts:"; |
| 101 |
print "\tdue to bloom filter misses: "bloom_filter_misses; |
| 102 |
print "\tabyss-map MAPQ == 0, DIDA MAPQ != 0: "mapq_not_zero; |
| 103 |
print "\tabyss-map MAPQ != 0, DIDA MAPQ == 0: "mapq_zero; |
| 104 |
print "\tequal len aligns for diff frags of same read: "diff_read_frags; |
| 105 |
print "\tequal len aligns for forward/reverse complement: "diff_dir; |
| 106 |
print "\tunclassified diff: "unclassified; |
| 107 |
|
| 108 |
if (bloom_filter_misses + mapq_not_zero + mapq_zero + diff_read_frags + diff_dir + unclassified > 0) |
| 109 |
exit 1; |
| 110 |
}' |