From adf85fd4335a5265f1882eb7afbf3151c3c11d67 Mon Sep 17 00:00:00 2001 From: Aaron <aaronquinlan@gmail.com> Date: Wed, 31 Aug 2011 12:10:56 -0400 Subject: [PATCH] Added -Sm to windowBed --- src/windowBed/windowBed.cpp | 9 +++++---- src/windowBed/windowBed.h | 5 +++-- src/windowBed/windowMain.cpp | 20 ++++++++++++++++---- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/windowBed/windowBed.cpp b/src/windowBed/windowBed.cpp index 95a78134..513d91fe 100644 --- a/src/windowBed/windowBed.cpp +++ b/src/windowBed/windowBed.cpp @@ -18,7 +18,7 @@ */ BedWindow::BedWindow(string bedAFile, string bedBFile, int leftSlop, int rightSlop, bool anyHit, bool noHit, bool writeCount, bool strandWindows, - bool matchOnStrand, bool bamInput, bool bamOutput, bool isUncompressedBam) { + bool matchOnSameStrand, bool matchOnDiffStrand, bool bamInput, bool bamOutput, bool isUncompressedBam) { _bedAFile = bedAFile; _bedBFile = bedBFile; @@ -30,7 +30,8 @@ BedWindow::BedWindow(string bedAFile, string bedBFile, int leftSlop, int rightSl _noHit = noHit; _writeCount = writeCount; _strandWindows = strandWindows; - _matchOnStrand = matchOnStrand; + _matchOnSameStrand = matchOnSameStrand; + _matchOnDiffStrand = matchOnDiffStrand; _bamInput = bamInput; _bamOutput = bamOutput; _isUncompressedBam = isUncompressedBam; @@ -70,7 +71,7 @@ void BedWindow::FindWindowOverlaps(const BED &a, vector<BED> &hits) { Now report the hits (if any) based on the window around a. */ // get the hits in B for the A feature - _bedB->FindOverlapsPerBin(a.chrom, aFudgeStart, aFudgeEnd, a.strand, hits, _matchOnStrand); + _bedB->FindOverlapsPerBin(a.chrom, aFudgeStart, aFudgeEnd, a.strand, hits, _matchOnSameStrand, _matchOnDiffStrand); int numOverlaps = 0; @@ -114,7 +115,7 @@ bool BedWindow::FindOneOrMoreWindowOverlaps(const BED &a) { CHRPOS aFudgeEnd; AddWindow(a, aFudgeStart, aFudgeEnd); - bool overlapsFound = _bedB->FindOneOrMoreOverlapsPerBin(a.chrom, a.start, a.end, a.strand, _matchOnStrand); + bool overlapsFound = _bedB->FindOneOrMoreOverlapsPerBin(a.chrom, a.start, a.end, a.strand, _matchOnSameStrand, _matchOnDiffStrand); return overlapsFound; } diff --git a/src/windowBed/windowBed.h b/src/windowBed/windowBed.h index 2256468e..84f1b1b1 100644 --- a/src/windowBed/windowBed.h +++ b/src/windowBed/windowBed.h @@ -34,7 +34,7 @@ public: // constructor BedWindow(string bedAFile, string bedBFile, int leftSlop, int rightSlop, bool anyHit, bool noHit, bool writeCount, bool strandWindows, - bool matchOnStrand, bool bamInput, bool bamOutput, bool isUncompressedBam); + bool matchOnSameStrand, bool matchOnDiffStrand, bool bamInput, bool bamOutput, bool isUncompressedBam); // destructor ~BedWindow(void); @@ -49,7 +49,8 @@ private: int _rightSlop; bool _noHit; bool _strandWindows; - bool _matchOnStrand; + bool _matchOnSameStrand; + bool _matchOnDiffStrand; bool _bamInput; bool _bamOutput; bool _isUncompressedBam; diff --git a/src/windowBed/windowMain.cpp b/src/windowBed/windowMain.cpp index b15854f2..982109e4 100644 --- a/src/windowBed/windowMain.cpp +++ b/src/windowBed/windowMain.cpp @@ -46,7 +46,8 @@ int main(int argc, char* argv[]) { bool haveLeft = false; bool haveRight = false; bool strandWindows = false; - bool matchOnStrand = false; + bool matchOnSameStrand = false; + bool matchOnDiffStrand = false; bool inputIsBam = false; bool outputIsBam = true; bool uncompressedBam = false; @@ -108,7 +109,10 @@ int main(int argc, char* argv[]) { strandWindows = true; } else if (PARAMETER_CHECK("-sm", 3, parameterLength)) { - matchOnStrand = true; + matchOnSameStrand = true; + } + else if (PARAMETER_CHECK("-sm", 3, parameterLength)) { + matchOnDiffStrand = true; } else if (PARAMETER_CHECK("-w", 2, parameterLength)) { if ((i+1) < argc) { @@ -177,9 +181,14 @@ int main(int argc, char* argv[]) { showHelp = true; } + if (matchOnSameStrand && matchOnDiffStrand) { + cerr << endl << "*****" << endl << "*****ERROR: Use either -sm or -Sm, not both." << endl << "*****" << endl; + showHelp = true; + } + if (!showHelp) { BedWindow *bi = new BedWindow(bedAFile, bedBFile, leftSlop, rightSlop, anyHit, - noHit, writeCount, strandWindows, matchOnStrand, + noHit, writeCount, strandWindows, matchOnSameStrand, matchOnDiffStrand, inputIsBam, outputIsBam, uncompressedBam); delete bi; return 0; @@ -233,7 +242,10 @@ void ShowHelp(void) { cerr << "\t\tfor a negative-stranded feature will add 500 bp downstream." << endl; cerr << "\t\t- Default = disabled." << endl << endl; - cerr << "\t-sm\t" << "Only report hits in B that overlap A on the same strand." << endl; + cerr << "\t-sm\t" << "Only report hits in B that overlap A on the _same_ strand." << endl; + cerr << "\t\t- By default, overlaps are reported without respect to strand." << endl << endl; + + cerr << "\t-Sm\t" << "Only report hits in B that overlap A on the _opposite_ strand." << endl; cerr << "\t\t- By default, overlaps are reported without respect to strand." << endl << endl; cerr << "\t-u\t" << "Write the original A entry _once_ if _any_ overlaps found in B." << endl; -- GitLab