X-Git-Url: https://git.donarmstrong.com/?p=rsem.git;a=blobdiff_plain;f=samValidator.cpp;h=5b02ba4c46f41f20884915d7f117c2a3213f49b0;hp=06e91d454707c0298b47212e8fc32210bf0b74e8;hb=683863b75f8d8bef2461039a6911b0e9619cc113;hpb=fb2aa1ca9d00710943155ef3abbbdd87df116e4a diff --git a/samValidator.cpp b/samValidator.cpp index 06e91d4..5b02ba4 100644 --- a/samValidator.cpp +++ b/samValidator.cpp @@ -9,6 +9,7 @@ #include "sam/bam.h" #include "sam/sam.h" +#include "utils.h" #include "my_assert.h" using namespace std; @@ -45,12 +46,12 @@ int main(int argc, char* argv[]) { isValid = true; - long cnt = 0; + HIT_INT_TYPE cnt = 0; string cqname(""), qname; uint64_t creadlen = 0, readlen; bool cispaired = false, ispaired; - printf("."); + printf("."); fflush(stdout); do { if (samread(in, b) < 0) break; assert(b->core.l_qseq > 0); @@ -60,11 +61,16 @@ int main(int argc, char* argv[]) { // if this is a paired-end read ispaired = b->core.flag & 0x0001; if (ispaired) { + isValid = (samread(in, b2) >= 0) && (qname == bam1_qname(b2)) && (b2->core.flag & 0x0001); if (!isValid) { printf("\nOnly find one mate for paired-end read %s!\n", qname.c_str()); continue; } assert(b2->core.l_qseq > 0); + isValid = !((b->core.flag & 0x0040) && (b->core.flag & 0x0080)) && !((b2->core.flag & 0x0040) & (b2->core.flag & 0x0080)); + if (!isValid) { printf("\nRead %s has more than 2 segments (e.g. tripled or more ended reads)!\n", qname.c_str()); continue; } isValid = !(((b->core.flag & 0x0040) && (b2->core.flag & 0x0040)) || ((b->core.flag & 0x0080) && (b2->core.flag & 0x0080))); if (!isValid) { printf("\nThe two mates of paired-end read %s are not adjacent!\n", qname.c_str()); continue; } + + // both mates are mapped if (!(b->core.flag & 0x0004) && !(b2->core.flag & 0x0004)) { isValid = (b->core.tid == b2->core.tid) && (b->core.pos == b2->core.mpos) && (b2->core.pos == b->core.mpos); @@ -92,7 +98,7 @@ int main(int argc, char* argv[]) { } ++cnt; - if (cnt % 1000000 == 0) printf("."); + if (cnt % 1000000 == 0) { printf("."); fflush(stdout); } } while(isValid);