diff --git a/src/pairToBed/pairToBed.cpp b/src/pairToBed/pairToBed.cpp index 5bfbe87e98b4f0976bcb6e5c9246d230345be2a1..5640791d0f78bfd613f400e348a12ed1c2be0e24 100644 --- a/src/pairToBed/pairToBed.cpp +++ b/src/pairToBed/pairToBed.cpp @@ -33,13 +33,14 @@ bool IsCorrectMappingForBEDPE (const BamAlignment &bam) { */ BedIntersectPE::BedIntersectPE(string bedAFilePE, string bedBFile, float overlapFraction, - string searchType, bool forceStrand, bool bamInput, + string searchType, bool sameStrand, bool diffStrand, bool bamInput, bool bamOutput, bool uncompressedBam, bool useEditDistance) { _bedAFilePE = bedAFilePE; _bedBFile = bedBFile; _overlapFraction = overlapFraction; - _forceStrand = forceStrand; + _sameStrand = sameStrand; + _diffStrand = diffStrand; _useEditDistance = useEditDistance; _searchType = searchType; _bamInput = bamInput; @@ -80,7 +81,7 @@ void BedIntersectPE::FindOverlaps(const BEDPE &a, vector<BED> &hits1, vector<BED // make sure we have a valid chromosome before we search if (a.chrom1 != ".") { // Find the quality hits between ***end1*** of the BEDPE and the B BED file - _bedB->FindOverlapsPerBin(a.chrom1, a.start1, a.end1, a.strand1, hits1, _forceStrand); + _bedB->FindOverlapsPerBin(a.chrom1, a.start1, a.end1, a.strand1, hits1, _sameStrand, _diffStrand); vector<BED>::const_iterator h = hits1.begin(); vector<BED>::const_iterator hitsEnd = hits1.end(); @@ -110,7 +111,7 @@ void BedIntersectPE::FindOverlaps(const BEDPE &a, vector<BED> &hits1, vector<BED // make sure we have a valid chromosome before we search if (a.chrom2 != ".") { // Now find the quality hits between ***end2*** of the BEDPE and the B BED file - _bedB->FindOverlapsPerBin(a.chrom2, a.start2, a.end2, a.strand2, hits2, _forceStrand); + _bedB->FindOverlapsPerBin(a.chrom2, a.start2, a.end2, a.strand2, hits2, _sameStrand, _diffStrand); vector<BED>::const_iterator h = hits2.begin(); vector<BED>::const_iterator hitsEnd = hits2.end(); @@ -198,7 +199,7 @@ bool BedIntersectPE::FindOneOrMoreOverlaps(const BEDPE &a, const string &type) { // Look for overlaps in end 1 assuming we have an aligned chromosome. if (a.chrom1 != ".") { end1Found = _bedB->FindOneOrMoreOverlapsPerBin(a.chrom1, a.start1, a.end1, a.strand1, - _forceStrand, _overlapFraction); + _sameStrand, _diffStrand, _overlapFraction); // can we bail out without checking end2? if ((type == "either") && (end1Found == true)) return true; @@ -210,7 +211,7 @@ bool BedIntersectPE::FindOneOrMoreOverlaps(const BEDPE &a, const string &type) { // Now look for overlaps in end 2 assuming we have an aligned chromosome. if (a.chrom2 != ".") { end2Found = _bedB->FindOneOrMoreOverlapsPerBin(a.chrom2, a.start2, a.end2, a.strand2, - _forceStrand, _overlapFraction); + _sameStrand, _diffStrand, _overlapFraction); if ((type == "either") && (end2Found == true)) return true; else if ((type == "neither") && (end2Found == true)) return false; @@ -271,7 +272,7 @@ void BedIntersectPE::FindSpanningOverlaps(const BEDPE &a, vector<BED> &hits, con spanLength = spanEnd - spanStart; // get the hits for the span - _bedB->FindOverlapsPerBin(a.chrom1, spanStart, spanEnd, a.strand1, hits, _forceStrand); + _bedB->FindOverlapsPerBin(a.chrom1, spanStart, spanEnd, a.strand1, hits, _sameStrand, _diffStrand); vector<BED>::const_iterator h = hits.begin(); vector<BED>::const_iterator hitsEnd = hits.end(); @@ -324,7 +325,7 @@ bool BedIntersectPE::FindOneOrMoreSpanningOverlaps(const BEDPE &a, const string spanLength = spanEnd - spanStart; overlapFound = _bedB->FindOneOrMoreOverlapsPerBin(a.chrom1, spanStart, spanEnd, a.strand1, - _forceStrand, _overlapFraction); + _sameStrand, _diffStrand, _overlapFraction); return overlapFound; } diff --git a/src/pairToBed/pairToBed.h b/src/pairToBed/pairToBed.h index b85497ca77989903b83605449fc50570d84f6bf8..d881c565fb945f89fd8c51a99978c8cac611fe51 100644 --- a/src/pairToBed/pairToBed.h +++ b/src/pairToBed/pairToBed.h @@ -43,7 +43,7 @@ public: // constructor BedIntersectPE(string bedAFilePE, string bedBFile, float overlapFraction, - string searchType, bool forceStrand, bool bamInput, bool bamOutput, bool uncompressedBam, bool useEditDistance); + string searchType, bool sameStrand, bool diffStrand, bool bamInput, bool bamOutput, bool uncompressedBam, bool useEditDistance); // destructor ~BedIntersectPE(void); @@ -66,7 +66,8 @@ private: string _bedBFile; float _overlapFraction; string _searchType; - bool _forceStrand; + bool _sameStrand; + bool _diffStrand; bool _useEditDistance; bool _bamInput; bool _bamOutput; diff --git a/src/pairToBed/pairToBedMain.cpp b/src/pairToBed/pairToBedMain.cpp index 068e6e3db1755a811f303edd844e2755693ec5c0..f29cf978d1fd0bbc08c628f68db0c672f3f42f52 100644 --- a/src/pairToBed/pairToBedMain.cpp +++ b/src/pairToBed/pairToBedMain.cpp @@ -41,7 +41,8 @@ int main(int argc, char* argv[]) { bool haveBedB = false; bool haveSearchType = false; bool haveFraction = false; - bool forceStrand = false; + bool sameStrand = false; + bool diffStrand = false; bool useEditDistance = false; bool inputIsBam = false; bool outputIsBam = true; @@ -110,7 +111,10 @@ int main(int argc, char* argv[]) { } } else if (PARAMETER_CHECK("-s", 2, parameterLength)) { - forceStrand = true; + sameStrand = true; + } + else if (PARAMETER_CHECK("-S", 2, parameterLength)) { + diffStrand = true; } else if(PARAMETER_CHECK("-ubam", 5, parameterLength)) { uncompressedBam = true; @@ -136,7 +140,7 @@ int main(int argc, char* argv[]) { } if ( ((searchType == "ispan") || (searchType == "ospan") || (searchType == "notispan") || (searchType == "notospan")) - && forceStrand ) { + && (sameStrand || diffStrand) ) { cerr << endl << "*****" << endl << "*****ERROR: Cannot enforce strandedness with selected searchtype" << endl << "*****" << endl; showHelp = true; } @@ -145,11 +149,16 @@ int main(int argc, char* argv[]) { cerr << endl << "*****" << endl << "*****ERROR: -ed must be used with -bedpe and -abam." << endl << "*****" << endl; showHelp = true; } + + if (sameStrand && diffStrand) { + cerr << endl << "*****" << endl << "*****ERROR: Request either -s OR -S, not both." << endl << "*****" << endl; + showHelp = true; + } if (!showHelp) { BedIntersectPE *bi = new BedIntersectPE(bedAFile, bedBFile, overlapFraction, - searchType, forceStrand, inputIsBam, + searchType, sameStrand, diffStrand, inputIsBam, outputIsBam, uncompressedBam, useEditDistance); delete bi; return 0; @@ -190,7 +199,11 @@ void ShowHelp(void) { cerr << "\t-f\t" << "Minimum overlap required as fraction of A (e.g. 0.05)." << endl; cerr << "\t\tDefault is 1E-9 (effectively 1bp)." << endl << endl; - cerr << "\t-s\t" << "Enforce strandedness when finding overlaps." << endl; + cerr << "\t-s\t" << "Require same strandedness when finding overlaps." << endl; + cerr << "\t\tDefault is to ignore stand." << endl; + cerr << "\t\tNot applicable with -type inspan or -type outspan." << endl << endl; + + cerr << "\t-S\t" << "Require different strandedness when finding overlaps." << endl; cerr << "\t\tDefault is to ignore stand." << endl; cerr << "\t\tNot applicable with -type inspan or -type outspan." << endl << endl;