From b3ba4b983e8a63229218786aebd3697eb434d41c Mon Sep 17 00:00:00 2001 From: Aaron <aaronquinlan@gmail.com> Date: Thu, 8 Dec 2011 12:31:12 -0500 Subject: [PATCH] bamToBed -bedpe now handles singletons. --- src/bamToBed/bamToBed.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/bamToBed/bamToBed.cpp b/src/bamToBed/bamToBed.cpp index b825c524..4a4c56c6 100644 --- a/src/bamToBed/bamToBed.cpp +++ b/src/bamToBed/bamToBed.cpp @@ -267,20 +267,18 @@ void ConvertBamToBedpe(const string &bamFile, const bool &useEditDistance) { // rip through the BAM file and convert each mapped entry to BEDPE BamAlignment bam1, bam2; while (reader.GetNextAlignment(bam1)) { - // the alignment must be paired - if (bam1.IsPaired() == true) { - // grab the second alignment for the pair. - reader.GetNextAlignment(bam2); - - // require that the alignments are from the same query - if (bam1.Name == bam2.Name) { - PrintBedPE(bam1, bam2, refs, useEditDistance); - } - else { - cerr << "*****ERROR: -bedpe requires BAM to be sorted/grouped by query name. " << endl; - exit(1); + + reader.GetNextAlignment(bam2); + if (bam1.Name != bam2.Name) { + while (bam1.Name != bam2.Name) + { + bam1 = bam2; + reader.GetNextAlignment(bam2); } } + else if (bam1.IsPaired() == true) { + PrintBedPE(bam1, bam2, refs, useEditDistance); + } } reader.Close(); } -- GitLab