Skip to content
Snippets Groups Projects
Commit 793ec9f3 authored by Aaron's avatar Aaron
Browse files

Added -S to pairToBed

parent f12f568c
No related branches found
No related tags found
No related merge requests found
...@@ -33,13 +33,14 @@ bool IsCorrectMappingForBEDPE (const BamAlignment &bam) { ...@@ -33,13 +33,14 @@ bool IsCorrectMappingForBEDPE (const BamAlignment &bam) {
*/ */
BedIntersectPE::BedIntersectPE(string bedAFilePE, string bedBFile, float overlapFraction, 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) { bool bamOutput, bool uncompressedBam, bool useEditDistance) {
_bedAFilePE = bedAFilePE; _bedAFilePE = bedAFilePE;
_bedBFile = bedBFile; _bedBFile = bedBFile;
_overlapFraction = overlapFraction; _overlapFraction = overlapFraction;
_forceStrand = forceStrand; _sameStrand = sameStrand;
_diffStrand = diffStrand;
_useEditDistance = useEditDistance; _useEditDistance = useEditDistance;
_searchType = searchType; _searchType = searchType;
_bamInput = bamInput; _bamInput = bamInput;
...@@ -80,7 +81,7 @@ void BedIntersectPE::FindOverlaps(const BEDPE &a, vector<BED> &hits1, vector<BED ...@@ -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 // make sure we have a valid chromosome before we search
if (a.chrom1 != ".") { if (a.chrom1 != ".") {
// Find the quality hits between ***end1*** of the BEDPE and the B BED file // 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 h = hits1.begin();
vector<BED>::const_iterator hitsEnd = hits1.end(); vector<BED>::const_iterator hitsEnd = hits1.end();
...@@ -110,7 +111,7 @@ void BedIntersectPE::FindOverlaps(const BEDPE &a, vector<BED> &hits1, vector<BED ...@@ -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 // make sure we have a valid chromosome before we search
if (a.chrom2 != ".") { if (a.chrom2 != ".") {
// Now find the quality hits between ***end2*** of the BEDPE and the B BED file // 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 h = hits2.begin();
vector<BED>::const_iterator hitsEnd = hits2.end(); vector<BED>::const_iterator hitsEnd = hits2.end();
...@@ -198,7 +199,7 @@ bool BedIntersectPE::FindOneOrMoreOverlaps(const BEDPE &a, const string &type) { ...@@ -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. // Look for overlaps in end 1 assuming we have an aligned chromosome.
if (a.chrom1 != ".") { if (a.chrom1 != ".") {
end1Found = _bedB->FindOneOrMoreOverlapsPerBin(a.chrom1, a.start1, a.end1, a.strand1, end1Found = _bedB->FindOneOrMoreOverlapsPerBin(a.chrom1, a.start1, a.end1, a.strand1,
_forceStrand, _overlapFraction); _sameStrand, _diffStrand, _overlapFraction);
// can we bail out without checking end2? // can we bail out without checking end2?
if ((type == "either") && (end1Found == true)) return true; if ((type == "either") && (end1Found == true)) return true;
...@@ -210,7 +211,7 @@ bool BedIntersectPE::FindOneOrMoreOverlaps(const BEDPE &a, const string &type) { ...@@ -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. // Now look for overlaps in end 2 assuming we have an aligned chromosome.
if (a.chrom2 != ".") { if (a.chrom2 != ".") {
end2Found = _bedB->FindOneOrMoreOverlapsPerBin(a.chrom2, a.start2, a.end2, a.strand2, end2Found = _bedB->FindOneOrMoreOverlapsPerBin(a.chrom2, a.start2, a.end2, a.strand2,
_forceStrand, _overlapFraction); _sameStrand, _diffStrand, _overlapFraction);
if ((type == "either") && (end2Found == true)) return true; if ((type == "either") && (end2Found == true)) return true;
else if ((type == "neither") && (end2Found == true)) return false; else if ((type == "neither") && (end2Found == true)) return false;
...@@ -271,7 +272,7 @@ void BedIntersectPE::FindSpanningOverlaps(const BEDPE &a, vector<BED> &hits, con ...@@ -271,7 +272,7 @@ void BedIntersectPE::FindSpanningOverlaps(const BEDPE &a, vector<BED> &hits, con
spanLength = spanEnd - spanStart; spanLength = spanEnd - spanStart;
// get the hits for the span // 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 h = hits.begin();
vector<BED>::const_iterator hitsEnd = hits.end(); vector<BED>::const_iterator hitsEnd = hits.end();
...@@ -324,7 +325,7 @@ bool BedIntersectPE::FindOneOrMoreSpanningOverlaps(const BEDPE &a, const string ...@@ -324,7 +325,7 @@ bool BedIntersectPE::FindOneOrMoreSpanningOverlaps(const BEDPE &a, const string
spanLength = spanEnd - spanStart; spanLength = spanEnd - spanStart;
overlapFound = _bedB->FindOneOrMoreOverlapsPerBin(a.chrom1, spanStart, spanEnd, a.strand1, overlapFound = _bedB->FindOneOrMoreOverlapsPerBin(a.chrom1, spanStart, spanEnd, a.strand1,
_forceStrand, _overlapFraction); _sameStrand, _diffStrand, _overlapFraction);
return overlapFound; return overlapFound;
} }
......
...@@ -43,7 +43,7 @@ public: ...@@ -43,7 +43,7 @@ public:
// constructor // constructor
BedIntersectPE(string bedAFilePE, string bedBFile, float overlapFraction, 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 // destructor
~BedIntersectPE(void); ~BedIntersectPE(void);
...@@ -66,7 +66,8 @@ private: ...@@ -66,7 +66,8 @@ private:
string _bedBFile; string _bedBFile;
float _overlapFraction; float _overlapFraction;
string _searchType; string _searchType;
bool _forceStrand; bool _sameStrand;
bool _diffStrand;
bool _useEditDistance; bool _useEditDistance;
bool _bamInput; bool _bamInput;
bool _bamOutput; bool _bamOutput;
......
...@@ -41,7 +41,8 @@ int main(int argc, char* argv[]) { ...@@ -41,7 +41,8 @@ int main(int argc, char* argv[]) {
bool haveBedB = false; bool haveBedB = false;
bool haveSearchType = false; bool haveSearchType = false;
bool haveFraction = false; bool haveFraction = false;
bool forceStrand = false; bool sameStrand = false;
bool diffStrand = false;
bool useEditDistance = false; bool useEditDistance = false;
bool inputIsBam = false; bool inputIsBam = false;
bool outputIsBam = true; bool outputIsBam = true;
...@@ -110,7 +111,10 @@ int main(int argc, char* argv[]) { ...@@ -110,7 +111,10 @@ int main(int argc, char* argv[]) {
} }
} }
else if (PARAMETER_CHECK("-s", 2, parameterLength)) { 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)) { else if(PARAMETER_CHECK("-ubam", 5, parameterLength)) {
uncompressedBam = true; uncompressedBam = true;
...@@ -136,7 +140,7 @@ int main(int argc, char* argv[]) { ...@@ -136,7 +140,7 @@ int main(int argc, char* argv[]) {
} }
if ( ((searchType == "ispan") || (searchType == "ospan") || (searchType == "notispan") || (searchType == "notospan")) if ( ((searchType == "ispan") || (searchType == "ospan") || (searchType == "notispan") || (searchType == "notospan"))
&& forceStrand ) { && (sameStrand || diffStrand) ) {
cerr << endl << "*****" << endl << "*****ERROR: Cannot enforce strandedness with selected searchtype" << endl << "*****" << endl; cerr << endl << "*****" << endl << "*****ERROR: Cannot enforce strandedness with selected searchtype" << endl << "*****" << endl;
showHelp = true; showHelp = true;
} }
...@@ -145,11 +149,16 @@ int main(int argc, char* argv[]) { ...@@ -145,11 +149,16 @@ int main(int argc, char* argv[]) {
cerr << endl << "*****" << endl << "*****ERROR: -ed must be used with -bedpe and -abam." << endl << "*****" << endl; cerr << endl << "*****" << endl << "*****ERROR: -ed must be used with -bedpe and -abam." << endl << "*****" << endl;
showHelp = true; showHelp = true;
} }
if (sameStrand && diffStrand) {
cerr << endl << "*****" << endl << "*****ERROR: Request either -s OR -S, not both." << endl << "*****" << endl;
showHelp = true;
}
if (!showHelp) { if (!showHelp) {
BedIntersectPE *bi = new BedIntersectPE(bedAFile, bedBFile, overlapFraction, BedIntersectPE *bi = new BedIntersectPE(bedAFile, bedBFile, overlapFraction,
searchType, forceStrand, inputIsBam, searchType, sameStrand, diffStrand, inputIsBam,
outputIsBam, uncompressedBam, useEditDistance); outputIsBam, uncompressedBam, useEditDistance);
delete bi; delete bi;
return 0; return 0;
...@@ -190,7 +199,11 @@ void ShowHelp(void) { ...@@ -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-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\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\tDefault is to ignore stand." << endl;
cerr << "\t\tNot applicable with -type inspan or -type outspan." << endl << endl; cerr << "\t\tNot applicable with -type inspan or -type outspan." << endl << endl;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment