Commit 8c626811 authored by Aaron's avatar Aaron
Browse files

handle unaligned BAMs with -v

parent acf2ec5e
......@@ -323,12 +323,12 @@ void BedIntersect::IntersectBam(string bamFile) {
// get each set of alignments for each pair.
while (reader.GetNextAlignment(bam)) {
// BAM IsMapped() is false
if ((!bam.IsMapped()) && (_noHit == true))
writer.SaveAlignment(bam);
else if (!bam.IsMapped())
// save an unaligned read if -v
if (!bam.IsMapped()) {
if (_noHit == true)
writer.SaveAlignment(bam);
continue;
}
// break alignment into discrete blocks,
bedVector bed_blocks;
string chrom = refs.at(bam.RefID).RefName;
......
@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
......@@ -254,4 +254,25 @@ check obs exp
rm obs exp
##################################################################
# Test that only the mapped read is is found as an intersection
##################################################################
echo " intersect.t23...\c"
echo \
"mapped 16 chr1 1 40 30M * 0 0 GAAGGCCACCGCCGCGGTTATTTTCCTTCA CCCDDB?=FJIIJIGFJIJHIJJJJJJJJI MD:Z:50" > exp
samtools view -Sb mapped_and_unmapped.sam 2>/dev/null | $BT intersect -abam - -b a.bed | samtools view - > obs
check obs exp
rm obs exp
##################################################################
# Test that an unmapped read is handled properly with -v
##################################################################
echo " intersect.t24...\c"
echo \
"umapped 4 * 1 40 30M * 0 0 GAAGGCCACCGCCGCGGTTATTTTCCTTCA CCCDDB?=FJIIJIGFJIJHIJJJJJJJJI MD:Z:50" > exp
samtools view -Sb mapped_and_unmapped.sam 2>/dev/null | $BT intersect -abam - -b a.bed -v | samtools view - > obs
check obs exp
rm obs exp
rm *.bam
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment