From 7a2a176bd8b22d69b680c65d83c3c783c13c682e Mon Sep 17 00:00:00 2001 From: nkindlon <nek3d@virginia.edu> Date: Wed, 6 Nov 2013 16:09:29 -0500 Subject: [PATCH] Fixed a bug in BamRecord::printUnmapped, added a unit test with with data file for unmapped Bam reads. --- .../FileRecordTools/Records/BamRecord.cpp | 6 +- test/intersect/a_with_bothUnmapped.bam | Bin 0 -> 2911 bytes test/intersect/mapped_and_unmapped.sam | 4 - test/intersect/new_test-intersect.sh | 210 +++++++++++++++++- 4 files changed, 212 insertions(+), 8 deletions(-) create mode 100644 test/intersect/a_with_bothUnmapped.bam delete mode 100644 test/intersect/mapped_and_unmapped.sam diff --git a/src/utils/FileRecordTools/Records/BamRecord.cpp b/src/utils/FileRecordTools/Records/BamRecord.cpp index fda5a28b..cde07329 100644 --- a/src/utils/FileRecordTools/Records/BamRecord.cpp +++ b/src/utils/FileRecordTools/Records/BamRecord.cpp @@ -148,10 +148,10 @@ void BamRecord::printRemainingBamFields(QuickString &outBuf, RecordKeyList *keyL } void BamRecord::printUnmapped(QuickString &outBuf) const { - outBuf.append(_chrName); + outBuf.append(_chrName.empty() ? "." : _chrName); outBuf.append("\t-1\t-1\t"); - outBuf.append(_name); + outBuf.append(_name.empty() ? "." : _name); outBuf.append('\t'); - outBuf.append(_score); + outBuf.append(_score.empty() ? "." : _score); outBuf.append("\t.\t-1\t-1\t-1\t0,0,0\t0\t.\t."); // dot for strand, -1 for blockStarts and blockEnd } diff --git a/test/intersect/a_with_bothUnmapped.bam b/test/intersect/a_with_bothUnmapped.bam new file mode 100644 index 0000000000000000000000000000000000000000..c8959e5be8ce17babfed2100134abd8e575fbf1f GIT binary patch literal 2911 zcmV-l3!wBLiwFb&00000{{{d;LjnMZ2%TA7Y#dh=KDJ578Wf5Ih$4hm5icn6?%cnb zxuz@GwQJXE);8JHG$GM4-W{*k-kouF){avUQYBObq7*8XBBd(fr%ivJ5WJuQYTimk zdEf!@BY2CDs3P$KfeIDw%$++k&P)+^9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UpVy!b0dQKTbqhd_HS;u^rnwS=j-tSV;D@sB~nPD+<76jxHa3RI1 zl!ZdH(#l-ZLg~r~J=uAlO-?{tw3d{mNmAwj_y0!*9umOl2x$>juNYIrV;CvpAt4|p z`qn$DdW^vl#(di{<q*ziaz-RrC8tCf3#LY0J3f^b0Vb3A3?@Px3xU<?@d?Meq5yg> z%1=Syw+C+Fu^CuyF0a<>&GK@!N)hm`V^Q(eg@BIJA;sT!ZQlmpDi@q<$-Ua0cq&qq zrPk>`umEWbltQ89I0Y$D7Y1ZesImehV4<tY{OAdYIX*c*Iy*bd^QZDDEaayJ@Q4Wf z4FDxQVQL`b;BXjHpU!#ULAmH$7l=bXj&a0MrL|8xa)2DCQp+M06sgmTT7X$7TbrsV zWMOing)VDn%42?#<`XeI<opi+@CQq}f9qfd001A02m}BC000301^_}s0stET0{{R3 J00000006s2nvnni literal 0 HcmV?d00001 diff --git a/test/intersect/mapped_and_unmapped.sam b/test/intersect/mapped_and_unmapped.sam deleted file mode 100644 index 111b41d1..00000000 --- a/test/intersect/mapped_and_unmapped.sam +++ /dev/null @@ -1,4 +0,0 @@ -@HD VN:1.0 GO:none SO:coordinate -@SQ SN:chr1 LN:249250621 -mapped 16 chr1 1 40 30M * 0 0 GAAGGCCACCGCCGCGGTTATTTTCCTTCA CCCDDB?=FJIIJIGFJIJHIJJJJJJJJI MD:Z:50 -umapped 4 * 1 40 30M * 0 0 GAAGGCCACCGCCGCGGTTATTTTCCTTCA CCCDDB?=FJIIJIGFJIJHIJJJJJJJJI MD:Z:50 diff --git a/test/intersect/new_test-intersect.sh b/test/intersect/new_test-intersect.sh index 6f21ef16..e23ff4bf 100755 --- a/test/intersect/new_test-intersect.sh +++ b/test/intersect/new_test-intersect.sh @@ -12,10 +12,218 @@ check() ########################################################### # Test intersection of a as bed from file vs b as bed from file ############################################################ -echo " intersect.t01...\c" +echo " intersect.new.t01...\c" echo \ "chr1 100 101 a2 2 - chr1 100 110 a2 2 -" > exp $BT intersect -a a.bed -b b.bed > obs check obs exp rm obs exp + + +########################################################### +# Test intersection of a as bed from redirect vs b as bed from file +############################################################ +echo " intersect.new.t02...\c" +echo \ +"chr1 100 101 a2 2 - +chr1 100 110 a2 2 -" > exp +$BT intersect -a - -b b.bed < a.bed > obs +check obs exp +rm obs exp + + +########################################################### +# Test intersection of a as bed from pipe vs b as bed from file +############################################################ +echo " intersect.new.t03...\c" +echo \ +"chr1 100 101 a2 2 - +chr1 100 110 a2 2 -" > exp +cat a.bed | $BT intersect -a - -b b.bed > obs +check obs exp +rm obs exp + + +########################################################### +# Test intersection of a as bed from fifo vs b as bed from file +############################################################ +echo " intersect.new.t04...\c" +echo \ +"chr1 100 101 a2 2 - +chr1 100 110 a2 2 -" > exp +$BT intersect -a <(cat a.bed) -b b.bed > obs +check obs exp +rm obs exp + + +########################################################### +# Test intersection of a as gzipped from file vs b as bed from file +############################################################ +echo " intersect.new.t05...\c" +echo \ +"chr1 100 101 a2 2 - +chr1 100 110 a2 2 -" > exp +$BT intersect -a a_gzipped.bed.gz -b b.bed > obs +check obs exp +rm obs exp + + +########################################################### +# Test intersection of a as gzipped from redirect vs b as bed from file +############################################################ +echo " intersect.new.t06...\c" +echo \ +"chr1 100 101 a2 2 - +chr1 100 110 a2 2 -" > exp +$BT intersect -a - -b b.bed < a_gzipped.bed.gz > obs +check obs exp +rm obs exp + + +########################################################### +# Test intersection of a as gzipped from pipe vs b as bed from file +############################################################ +echo " intersect.new.t07...\c" +echo \ +"chr1 100 101 a2 2 - +chr1 100 110 a2 2 -" > exp +cat a_gzipped.bed.gz | $BT intersect -a - -b b.bed > obs +check obs exp +rm obs exp + + +########################################################### +# Test intersection of a as gzipped from fifo vs b as bed from file +############################################################ +echo " intersect.new.t08...\c" +echo \ +"chr1 100 101 a2 2 - +chr1 100 110 a2 2 -" > exp +$BT intersect -a <(cat a_gzipped.bed.gz) -b b.bed > obs +check obs exp +rm obs exp + + +########################################################### +# Test intersection of a as bgzipped from file vs b as bed from file +############################################################ +echo " intersect.new.t09...\c" +echo \ +"chr1 100 101 a2 2 - +chr1 100 110 a2 2 -" > exp +$BT intersect -a a_bgzipped.bed.gz -b b.bed > obs +check obs exp +rm obs exp + + +########################################################### +# Test intersection of a as bgzipped from redirect vs b as bed from file +############################################################ +echo " intersect.new.t10...\c" +echo \ +"chr1 100 101 a2 2 - +chr1 100 110 a2 2 -" > exp +$BT intersect -a - -b b.bed < a_bgzipped.bed.gz > obs +check obs exp +rm obs exp + + +########################################################### +# Test intersection of a as bgzipped from pipe vs b as bed from file +############################################################ +echo " intersect.new.t11...\c" +echo \ +"chr1 100 101 a2 2 - +chr1 100 110 a2 2 -" > exp +cat a_bgzipped.bed.gz | $BT intersect -a - -b b.bed > obs +check obs exp +rm obs exp + + +########################################################### +# Test intersection of a as bgzipped from fifo vs b as bed from file +############################################################ +echo " intersect.new.t12...\c" +echo \ +"chr1 100 101 a2 2 - +chr1 100 110 a2 2 -" > exp +$BT intersect -a <(cat a_bgzipped.bed.gz) -b b.bed > obs +check obs exp +rm obs exp + + +########################################################### +# Test intersection of a as bam from file vs b as bed from file +############################################################ +echo " intersect.new.t13...\c" +$BT intersect -a a.bam -b b.bed> obs +check obs aVSb.bam +rm obs + + +########################################################### +# Test intersection of a as bam from redirect vs b as bed from file +############################################################ +echo " intersect.new.t14...\c" +$BT intersect -a - -b b.bed < a.bam> obs +check obs aVSb.bam +rm obs + + +########################################################### +# Test intersection of a as bam from pipe vs b as bed from file +############################################################ +echo " intersect.new.t15...\c" +cat a.bam | $BT intersect -a - -b b.bed> obs +check obs aVSb.bam +rm obs + + +########################################################### +# Test intersection of a as bam from fifo vs b as bed from file +############################################################ +echo " intersect.new.t16...\c" +$BT intersect -a <(cat a.bam) -b b.bed > obs +check obs aVSb.bam +rm obs + + +########################################################### +# Test intersection of bam file containing both good reads +# and those where both read and mate are unmapped vs b file +# as bed. +############################################################ +echo " intersect.new.t17...\c" +echo \ +"chr1 100 101 a2 255 - 100 200 0,0,0 1 100, 0, +chr1 100 110 a2 255 - 100 200 0,0,0 1 100, 0," > exp +$BT intersect -a a_with_bothUnmapped.bam -b b.bed -bed > obs +check obs exp +rm obs exp + + +########################################################### +# Test intersection of bam file containing both good reads +# and those where both read and mate are unmapped vs b file +# as bed, with noHit (-v) option. +############################################################ +echo " intersect.new.t18...\c" +echo \ +"chr1 10 20 a1 255 + 10 20 0,0,0 1 10, 0, +. -1 -1 FCC1MK2ACXX:1:1101:5780:51632#/1 0 . -1 -1 -1 0,0,0 0 . . +. -1 -1 FCC1MK2ACXX:1:1101:5780:51632#/2 0 . -1 -1 -1 0,0,0 0 . . +. -1 -1 FCC1MK2ACXX:1:1101:8137:99409#/1 0 . -1 -1 -1 0,0,0 0 . . +. -1 -1 FCC1MK2ACXX:1:1101:8137:99409#/2 0 . -1 -1 -1 0,0,0 0 . . +. -1 -1 FCC1MK2ACXX:1:1102:6799:2633#/1 0 . -1 -1 -1 0,0,0 0 . . +. -1 -1 FCC1MK2ACXX:1:1102:6799:2633#/2 0 . -1 -1 -1 0,0,0 0 . ." > exp +$BT intersect -a a_with_bothUnmapped.bam -b b.bed -bed -v > obs +check obs exp +#rm obs exp + + + + + + + -- GitLab