From 80f29d23dff7c91573e923d2f19b7c55902ebdf1 Mon Sep 17 00:00:00 2001
From: Aaron Quinlan <aaronquinlan@gmail.com>
Date: Tue, 21 Apr 2009 10:07:41 -0400
Subject: [PATCH] Updated mergeBed reporting logic

	1.  Changed the cout statements for the last entries for a chromosome.
	2.  I had forgotten to report the number of merged entries when -n is requested.
	3.  I also fixed a bug that occassionally caused the last entry for a chromosome
	    to report the chrom twice in the output.
---
 src/intersectBed/intersectBed.cpp | 44 ++++++++++++++++++++++++++++---
 src/mergeBed/mergeBed.cpp         | 15 ++++++++---
 2 files changed, 52 insertions(+), 7 deletions(-)

diff --git a/src/intersectBed/intersectBed.cpp b/src/intersectBed/intersectBed.cpp
index cdce4da2..c6b7dafe 100755
--- a/src/intersectBed/intersectBed.cpp
+++ b/src/intersectBed/intersectBed.cpp
@@ -1,6 +1,22 @@
+// 
+//  intersectBed.cpp
+//  BEDTools
+//  
+//  Created by Aaron Quinlan Spring 2009.
+//  Copyright 2009 Aaron Quinlan. All rights reserved.
+//
+//  Summary:  Looks for overlaps between features in two BED files.
+//
+
+/*
+	Includes
+*/
 #include "intersectBed.h"
 
 
+/*
+	Constructor
+*/
 BedIntersect::BedIntersect(string &bedAFile, string &bedBFile, bool &anyHit, 
 bool &writeB, float &overlapFraction, bool &noHit, bool &writeCount) {
 
@@ -16,12 +32,20 @@ bool &writeB, float &overlapFraction, bool &noHit, bool &writeCount) {
 	this->bedB = new BedFile(bedBFile);
 }
 
-
-
+/*
+	Destructor
+*/
 BedIntersect::~BedIntersect(void) {
 }
 
 
+
+/*
+	reportA
+	
+	Writes the _original_ BED entry for A.
+	Works for BED3 - BED6.
+*/
 void BedIntersect::reportA(const BED &a) {
 	
 	if (bedA->bedType == 3) {
@@ -39,11 +63,15 @@ void BedIntersect::reportA(const BED &a) {
 		cout << a.chrom << "\t" << a.start << "\t" << a.end << "\t" 
 		<< a.name << "\t" << a.score << "\t" << a.strand;
 	}
-	
 }
 
 
-
+/*
+	reportAIntersect
+	
+	Writes the base-pair _overlap_ for a BED entry in A.
+	Works for BED3 - BED6.
+*/
 void BedIntersect::reportAIntersect(const BED &a, int &start, int &end) {
 
 	if (bedA->bedType == 3) {
@@ -64,6 +92,14 @@ void BedIntersect::reportAIntersect(const BED &a, int &start, int &end) {
 	
 }
 
+
+
+/*
+	reportB
+	
+	Writes the _original_ BED entry for B.
+	Works for BED3 - BED6.
+*/
 void BedIntersect::reportB(const BED &b) {
 	if (bedB->bedType == 3) {
 		cout << b.chrom << "\t" << b.start << "\t" << b.end;
diff --git a/src/mergeBed/mergeBed.cpp b/src/mergeBed/mergeBed.cpp
index 499db702..76906f48 100755
--- a/src/mergeBed/mergeBed.cpp
+++ b/src/mergeBed/mergeBed.cpp
@@ -98,12 +98,21 @@ void BedMerge::MergeBed() {
 
 		// clean up based on the last entry for the current chromosome
 		if (OIP) {
-			cout << bedList[i-1].chrom << "\t" << minStart << "\t" << maxEnd << endl;
+			if (this->numEntries) {
+				cout << bedList[i-1].chrom << "\t" << minStart << "\t" << maxEnd << "\t" << mergeCount << endl;
+			}
+			else {
+				cout << bedList[i-1].chrom << "\t" << minStart << "\t" << maxEnd << endl;	
+			}
 		}
 		else {
-			cout << m->first << "\t" << bedList[i-1].chrom << "\t" << bedList[i-1].start << "\t" << bedList[i-1].end << endl;
+			if (this->numEntries) {
+				cout << bedList[i-1].chrom << "\t" << bedList[i-1].start << "\t" << bedList[i-1].end  << "\t" << mergeCount << endl;
+			}
+			else {
+				cout << bedList[i-1].chrom << "\t" << bedList[i-1].start << "\t" << bedList[i-1].end << endl;	
+			}
 		}
-
 	}
 }
 
-- 
GitLab