From d245bbc9fda885d9dac1341b7c83b21c9399e893 Mon Sep 17 00:00:00 2001 From: Aaron <aaronquinlan@gmail.com> Date: Wed, 14 Apr 2010 23:04:35 -0400 Subject: [PATCH] Updated most of the code to use _ notation and the Open,GetNext,Close functionality. --- src/closestBed/closestBed.cpp | 97 +++----- src/closestBed/closestBed.h | 29 +-- src/closestBed/closestMain.cpp | 1 - src/complementBed/complementBed.cpp | 17 +- src/complementBed/complementBed.h | 12 +- src/coverageBed/coverageBed.cpp | 95 ++++---- src/coverageBed/coverageBed.h | 22 +- src/coverageBed/coverageMain.cpp | 3 +- src/fastaFromBed/fastaFromBed.cpp | 54 ++--- src/fastaFromBed/fastaFromBed.h | 14 +- src/fastaFromBed/fastaFromBedMain.cpp | 3 +- src/genomeCoverageBed/genomeCoverageBed.cpp | 174 +++++++------- src/genomeCoverageBed/genomeCoverageBed.h | 39 ++-- src/genomeCoverageBed/genomeCoverageMain.cpp | 3 +- src/intersectBed/intersectBed.cpp | 40 ++-- src/intersectBed/intersectBed.h | 1 - src/intersectBed/intersectMain.cpp | 2 +- src/linksBed/linksBed.cpp | 66 ++---- src/linksBed/linksBed.h | 18 +- src/linksBed/linksMain.cpp | 2 +- src/maskFastaFromBed/maskFastaFromBed.cpp | 33 +-- src/maskFastaFromBed/maskFastaFromBed.h | 19 +- src/maskFastaFromBed/maskFastaFromBedMain.cpp | 2 +- src/mergeBed/mergeBed.cpp | 65 +++--- src/mergeBed/mergeBed.h | 14 +- src/mergeBed/mergeMain.cpp | 8 +- src/pairToBed/pairToBed.cpp | 148 ++++++------ src/pairToBed/pairToBed.h | 21 +- src/shuffleBed/shuffleBed.cpp | 217 ++++++++---------- src/shuffleBed/shuffleBed.h | 37 ++- src/shuffleBed/shuffleBedMain.cpp | 4 +- src/slopBed/slopBed.cpp | 64 ++---- src/slopBed/slopBed.h | 30 +-- src/slopBed/slopBedMain.cpp | 2 +- src/sortBed/sortBed.cpp | 52 +++-- src/sortBed/sortBed.h | 9 +- 36 files changed, 636 insertions(+), 781 deletions(-) diff --git a/src/closestBed/closestBed.cpp b/src/closestBed/closestBed.cpp index 07aeaa87..f339eec5 100755 --- a/src/closestBed/closestBed.cpp +++ b/src/closestBed/closestBed.cpp @@ -23,14 +23,15 @@ const int SLOPGROWTH = 2048000; */ BedClosest::BedClosest(string &bedAFile, string &bedBFile, bool &forceStrand, string &tieMode) { - this->bedAFile = bedAFile; - this->bedBFile = bedBFile; - this->forceStrand = forceStrand; - this->tieMode = tieMode; + _bedAFile = bedAFile; + _bedBFile = bedBFile; + _forceStrand = forceStrand; + _tieMode = tieMode; - this->bedA = new BedFile(bedAFile); - this->bedB = new BedFile(bedBFile); + _bedA = new BedFile(bedAFile); + _bedB = new BedFile(bedBFile); + FindClosestBed(); } /* @@ -47,16 +48,16 @@ BedClosest::~BedClosest(void) { Works for BED3 - BED6. */ void BedClosest::reportNullB() { - if (bedB->bedType == 3) { + if (_bedB->bedType == 3) { printf("none\t-1\t-1\n"); } - else if (bedB->bedType == 4) { + else if (_bedB->bedType == 4) { printf("none\t-1\t-1\t-1\n"); } - else if (bedB->bedType == 5) { + else if (_bedB->bedType == 5) { printf("none\t-1\t-1\t-1\t-1\n"); } - else if (bedB->bedType == 6) { + else if (_bedB->bedType == 6) { printf("none\t-1\t-1\t-1\t-1\t-1\n"); } } @@ -79,7 +80,7 @@ void BedClosest::FindWindowOverlaps(BED &a, vector<BED> &hits) { int minDistance = 999999999; - if(bedB->bedMap.find(a.chrom) != bedB->bedMap.end()) { + if(_bedB->bedMap.find(a.chrom) != _bedB->bedMap.end()) { while ((numOverlaps == 0) && (slop <= MAXSLOP)) { @@ -91,7 +92,7 @@ void BedClosest::FindWindowOverlaps(BED &a, vector<BED> &hits) { if ((a.start + slop) < 2 * MAXSLOP) aFudgeEnd = a.end + slop; else aFudgeEnd = 2 * MAXSLOP; - bedB->FindOverlapsPerBin(a.chrom, aFudgeStart, aFudgeEnd, a.strand, hits, this->forceStrand); + _bedB->FindOverlapsPerBin(a.chrom, aFudgeStart, aFudgeEnd, a.strand, hits, _forceStrand); vector<BED>::const_iterator h = hits.begin(); vector<BED>::const_iterator hitsEnd = hits.end(); @@ -141,82 +142,54 @@ void BedClosest::FindWindowOverlaps(BED &a, vector<BED> &hits) { } } else { - bedA->reportBedTab(a); + _bedA->reportBedTab(a); reportNullB(); } if (numOverlaps > 0) { if (closestB.size() == 1) { - bedA->reportBedTab(a); - bedB->reportBedNewLine(closestB[0]); + _bedA->reportBedTab(a); + _bedB->reportBedNewLine(closestB[0]); } else { - if (this->tieMode == "all") { + if (_tieMode == "all") { for (vector<BED>::iterator b = closestB.begin(); b != closestB.end(); ++b) { - bedA->reportBedTab(a); - bedB->reportBedNewLine(*b); + _bedA->reportBedTab(a); + _bedB->reportBedNewLine(*b); } } - else if (this->tieMode == "first") { - bedA->reportBedTab(a); - bedB->reportBedNewLine(closestB[0]); + else if (_tieMode == "first") { + _bedA->reportBedTab(a); + _bedB->reportBedNewLine(closestB[0]); } - else if (this->tieMode == "last") { - bedA->reportBedTab(a); - bedB->reportBedNewLine(closestB[closestB.size()-1]); + else if (_tieMode == "last") { + _bedA->reportBedTab(a); + _bedB->reportBedNewLine(closestB[closestB.size()-1]); } } } } -void BedClosest::ClosestBed(istream &bedInput) { +void BedClosest::FindClosestBed() { // load the "B" bed file into a map so // that we can easily compare "A" to it for overlaps - bedB->loadBedFileIntoMap(); - - string bedLine; + _bedB->loadBedFileIntoMap(); + + BED a; int lineNum = 0; // current input line number vector<BED> hits; // vector of potential hits - vector<string> bedFields; // vector for a BED entry - - // reserve some space hits.reserve(100); - bedFields.reserve(12); - - // process each entry in A - while (getline(bedInput, bedLine)) { - lineNum++; - Tokenize(bedLine,bedFields); - BED a; - - // find the overlaps with B if it's a valid BED entry. - if (bedA->parseLine(a, bedFields, lineNum)) { - FindWindowOverlaps(a, hits); - hits.clear(); - } - // reset for the next input line - bedFields.clear(); + _bedA->Open(); + // process each entry in A in search of the closest feature in B + while (_bedA->GetNextBed(a, lineNum)) { + FindWindowOverlaps(a, hits); + hits.clear(); } + _bedA->Close(); } // END ClosestBed - - -void BedClosest::DetermineBedInput() { - if (bedA->bedFile != "stdin") { // process a file - ifstream beds(bedA->bedFile.c_str(), ios::in); - if ( !beds ) { - cerr << "Error: The requested bed file (" << bedA->bedFile << ") could not be opened. Exiting!" << endl; - exit (1); - } - ClosestBed(beds); - } - else { // process stdin - ClosestBed(cin); - } -} - diff --git a/src/closestBed/closestBed.h b/src/closestBed/closestBed.h index 0e3804bc..41c43cd6 100755 --- a/src/closestBed/closestBed.h +++ b/src/closestBed/closestBed.h @@ -27,28 +27,29 @@ class BedClosest { public: // constructor - BedClosest(string &, string &, bool &, string &); + BedClosest(string &bedAFile, string &bedAFile, bool &forceStrand, string &tieMode); // destructor ~BedClosest(void); + + // find the closest feature in B to A + void FindClosestBed(); +private: + + // data + string _bedAFile; + string _bedBFile; + string _tieMode; + bool _forceStrand; + + BedFile *_bedA, *_bedB; + + // methods void reportA(const BED &); void reportB(const BED &); void reportNullB(); - - void ClosestBed(istream &bedInput); void FindWindowOverlaps(BED &, vector<BED> &); - void DetermineBedInput(); - -private: - - string bedAFile; - string bedBFile; - string tieMode; - bool forceStrand; - - // instance of a bed file class. - BedFile *bedA, *bedB; }; #endif /* CLOSEST_H */ diff --git a/src/closestBed/closestMain.cpp b/src/closestBed/closestMain.cpp index d72fa759..6cafec77 100755 --- a/src/closestBed/closestMain.cpp +++ b/src/closestBed/closestMain.cpp @@ -98,7 +98,6 @@ int main(int argc, char* argv[]) { if (!showHelp) { BedClosest *bc = new BedClosest(bedAFile, bedBFile, forceStrand, tieMode); - bc->DetermineBedInput(); return 0; } else { diff --git a/src/complementBed/complementBed.cpp b/src/complementBed/complementBed.cpp index 0ef9ab99..275455b3 100755 --- a/src/complementBed/complementBed.cpp +++ b/src/complementBed/complementBed.cpp @@ -14,11 +14,12 @@ BedComplement::BedComplement(string &bedFile, string &genomeFile) { - this->bedFile = bedFile; - this->genomeFile = genomeFile; + _bedFile = bedFile; + _genomeFile = genomeFile; - this->bed = new BedFile(bedFile); - this->genome = new GenomeFile(genomeFile); + _bed = new BedFile(bedFile); + _genome = new GenomeFile(genomeFile); + } @@ -33,16 +34,16 @@ void BedComplement::ComplementBed() { // load the "B" bed file into a map so // that we can easily compare "A" to it for overlaps - bed->loadBedFileIntoMapNoBin(); + _bed->loadBedFileIntoMapNoBin(); vector<short> chromMasks; string currChrom; // loop through each chromosome and merge their BED entries - for (masterBedMapNoBin::iterator m = bed->bedMapNoBin.begin(); m != bed->bedMapNoBin.end(); ++m) { + for (masterBedMapNoBin::iterator m = _bed->bedMapNoBin.begin(); m != _bed->bedMapNoBin.end(); ++m) { currChrom = m->first; - int currChromSize = genome->getChromSize(currChrom); + int currChromSize = _genome->getChromSize(currChrom); // bedList is already sorted by start position. vector<BED> bedList = m->second; @@ -57,7 +58,7 @@ void BedComplement::ComplementBed() { // sanity check the end of the bed entry if (bIt->end > currChromSize) { cout << "End of BED entry exceeds chromosome length. Please correct." << endl; - bed->reportBedNewLine(*bIt); + _bed->reportBedNewLine(*bIt); exit(1); } diff --git a/src/complementBed/complementBed.h b/src/complementBed/complementBed.h index dcdec407..7d3a94ab 100755 --- a/src/complementBed/complementBed.h +++ b/src/complementBed/complementBed.h @@ -30,7 +30,7 @@ class BedComplement { public: // constructor - BedComplement(string &, string &); + BedComplement(string &bedFile, string &genomeFile); // destructor ~BedComplement(void); @@ -39,10 +39,8 @@ public: private: - string bedFile; - string genomeFile; - - // instance of a bed file class. - BedFile *bed; - GenomeFile *genome; + string _bedFile; + string _genomeFile; + BedFile *_bed; + GenomeFile *_genome; }; diff --git a/src/coverageBed/coverageBed.cpp b/src/coverageBed/coverageBed.cpp index d07e7261..13f61939 100755 --- a/src/coverageBed/coverageBed.cpp +++ b/src/coverageBed/coverageBed.cpp @@ -15,48 +15,52 @@ // build BedCoverage::BedCoverage(string &bedAFile, string &bedBFile, bool &forceStrand, bool &writeHistogram, bool &bamInput) { - this->bedAFile = bedAFile; - this->bedBFile = bedBFile; + _bedAFile = bedAFile; + _bedBFile = bedBFile; - this->bedA = new BedFile(bedAFile); - this->bedB = new BedFile(bedBFile); + _bedA = new BedFile(bedAFile); + _bedB = new BedFile(bedBFile); - this->forceStrand = forceStrand; - this->writeHistogram = writeHistogram; - this->bamInput = bamInput; + _forceStrand = forceStrand; + _writeHistogram = writeHistogram; + _bamInput = bamInput; + + if (_bedA->bedFile != "stdin") { // process a file + if (_bamInput == false) { //bed/gff + CollectCoverageBed(); + } + else { + CollectCoverageBam(_bedA->bedFile); + } + } + else { // process stdin + if (_bamInput == false) + CollectCoverageBed(); + else { + CollectCoverageBam("stdin"); + } + } } // destroy BedCoverage::~BedCoverage(void) { - delete this->bedA; - delete this->bedB; + delete _bedA; + delete _bedB; } -void BedCoverage::CollectCoverageBed(istream &bedInput) { +void BedCoverage::CollectCoverageBed() { // load the "B" bed file into a map so // that we can easily compare "A" to it for overlaps - bedB->loadBedFileIntoMap(); + _bedB->loadBedFileIntoMap(); - string bedLine; int lineNum = 0; // current input line number - vector<string> bedFields; // vector for a BED entry - bedFields.reserve(12); - + BED a; // process each entry in A - while (getline(bedInput, bedLine)) { - - lineNum++; - Tokenize(bedLine,bedFields); - BED a; - - if (bedA->parseLine(a, bedFields, lineNum)) { - // count a as a hit with all the relevant features in B - bedB->countHits(a, this->forceStrand); - } - // reset for the next input line - bedFields.clear(); + while (_bedA->GetNextBed(a, lineNum)) { + // count a as a hit with all the relevant features in B + _bedB->countHits(a, _forceStrand); } // report the coverage (summary or histogram) for BED B. @@ -68,7 +72,7 @@ void BedCoverage::CollectCoverageBam(string bamFile) { // load the "B" bed file into a map so // that we can easily compare "A" to it for overlaps - bedB->loadBedFileIntoMap(); + _bedB->loadBedFileIntoMap(); // open the BAM file BamReader reader; @@ -92,7 +96,7 @@ void BedCoverage::CollectCoverageBam(string bamFile) { a.end = bam.Position + bam.AlignedBases.size(); a.strand = "+"; if (bam.IsReverseStrand()) a.strand = "-"; - bedB->countHits(a, this->forceStrand); + _bedB->countHits(a, _forceStrand); } } // report the coverage (summary or histogram) for BED B. @@ -107,8 +111,8 @@ void BedCoverage::ReportCoverage() { map<unsigned int, unsigned int> allDepthHist; unsigned int totalLength = 0; - masterBedMap::const_iterator chromItr = bedB->bedMap.begin(); - masterBedMap::const_iterator chromEnd = bedB->bedMap.end(); + masterBedMap::const_iterator chromItr = _bedB->bedMap.begin(); + masterBedMap::const_iterator chromEnd = _bedB->bedMap.end(); for (; chromItr != chromEnd; ++chromItr) { binsToBeds::const_iterator binItr = chromItr->second.begin(); @@ -157,8 +161,8 @@ void BedCoverage::ReportCoverage() { int nonZeroBases = (length - zeroDepthCount); float fractCovered = (float) nonZeroBases / length; - if (this->writeHistogram == false) { - bedB->reportBedTab(*bedItr); + if (_writeHistogram == false) { + _bedB->reportBedTab(*bedItr); printf("%d\t%d\t%d\t%0.7f\n", bedItr->count, nonZeroBases, length, fractCovered); } else { @@ -166,14 +170,14 @@ void BedCoverage::ReportCoverage() { map<unsigned int, unsigned int>::const_iterator histEnd = depthHist.end(); for (; histItr != histEnd; ++histItr) { float fractAtThisDepth = (float) histItr->second / length; - bedB->reportBedTab(*bedItr); + _bedB->reportBedTab(*bedItr); printf("%d\t%d\t%d\t%0.7f\n", histItr->first, histItr->second, length, fractAtThisDepth); } } } } } - if (this->writeHistogram == true) { + if (_writeHistogram == true) { map<unsigned int, unsigned int>::const_iterator histItr = allDepthHist.begin(); map<unsigned int, unsigned int>::const_iterator histEnd = allDepthHist.end(); for (; histItr != histEnd; ++histItr) { @@ -184,24 +188,3 @@ void BedCoverage::ReportCoverage() { } -void BedCoverage::DetermineBedInput() { - if (bedA->bedFile != "stdin") { // process a file - if (this->bamInput == false) { //bed/gff - ifstream beds(bedA->bedFile.c_str(), ios::in); - if ( !beds ) { - cerr << "Error: The requested bed file (" << bedA->bedFile << ") could not be opened. Exiting!" << endl; - exit (1); - } - CollectCoverageBed(beds); - } - else - CollectCoverageBam(bedA->bedFile); - } - else { // process stdin - if (this->bamInput == false) - CollectCoverageBed(cin); - else - CollectCoverageBam("stdin"); - } -} - diff --git a/src/coverageBed/coverageBed.h b/src/coverageBed/coverageBed.h index a4aa2fc6..60ea56c2 100755 --- a/src/coverageBed/coverageBed.h +++ b/src/coverageBed/coverageBed.h @@ -40,31 +40,29 @@ public: // destructor ~BedCoverage(void); - void CollectCoverageBed(istream &bedInput); - - void CollectCoverageBam(string bamFile); - - void DetermineBedInput(); - private: // input files. - string bedAFile; - string bedBFile; + string _bedAFile; + string _bedBFile; // instance of a bed file class. - BedFile *bedA, *bedB; + BedFile *_bedA, *_bedB; // do we care about strandedness when counting coverage? - bool forceStrand; + bool _forceStrand; // should we write a histogram for each feature in B? - bool writeHistogram; + bool _writeHistogram; // are we dealing with BAM input for "A"? - bool bamInput; + bool _bamInput; // private function for reporting coverage information void ReportCoverage(); + + void CollectCoverageBed(); + + void CollectCoverageBam(string bamFile); }; #endif /* COVERAGEBED_H */ diff --git a/src/coverageBed/coverageMain.cpp b/src/coverageBed/coverageMain.cpp index 804a997f..df618ebb 100755 --- a/src/coverageBed/coverageMain.cpp +++ b/src/coverageBed/coverageMain.cpp @@ -99,9 +99,8 @@ int main(int argc, char* argv[]) { } if (!showHelp) { - BedCoverage *bg = new BedCoverage(bedAFile, bedBFile, forceStrand, writeHistogram, bamInput); - bg->DetermineBedInput(); + delete bg; return 0; } else { diff --git a/src/fastaFromBed/fastaFromBed.cpp b/src/fastaFromBed/fastaFromBed.cpp index 931ebb86..c69736bd 100755 --- a/src/fastaFromBed/fastaFromBed.cpp +++ b/src/fastaFromBed/fastaFromBed.cpp @@ -16,16 +16,18 @@ Bed2Fa::Bed2Fa(bool &useName, string &dbFile, string &bedFile, string &fastaOutF bool &useFasta, bool &useStrand) { if (useName) { - this->useName = true; + _useName = true; } - this->dbFile = dbFile; - this->bedFile = bedFile; - this->fastaOutFile = fastaOutFile; - this->useFasta = useFasta; - this->useStrand = useStrand; + _dbFile = dbFile; + _bedFile = bedFile; + _fastaOutFile = fastaOutFile; + _useFasta = useFasta; + _useStrand = useStrand; - this->bed = new BedFile(this->bedFile); + _bed = new BedFile(_bedFile); + + ExtractDNA(); } @@ -41,21 +43,21 @@ void Bed2Fa::ExtractDNA() { /* Make sure that we can oen all of the files successfully*/ // open the fasta database for reading - ifstream faDb(this->dbFile.c_str(), ios::in); + ifstream faDb(_dbFile.c_str(), ios::in); if ( !faDb ) { - cerr << "Error: The requested fasta database file (" << this->dbFile << ") could not be opened. Exiting!" << endl; + cerr << "Error: The requested fasta database file (" << _dbFile << ") could not be opened. Exiting!" << endl; exit (1); } // open the fasta database for reading - ofstream faOut(this->fastaOutFile.c_str(), ios::out); + ofstream faOut(_fastaOutFile.c_str(), ios::out); if ( !faOut ) { - cerr << "Error: The requested fasta output file (" << this->fastaOutFile << ") could not be opened. Exiting!" << endl; + cerr << "Error: The requested fasta output file (" << _fastaOutFile << ") could not be opened. Exiting!" << endl; exit (1); } // load the BED file into an unbinned map. - bed->loadBedFileIntoMapNoBin(); + _bed->loadBedFileIntoMapNoBin(); //Read the fastaDb chromosome by chromosome string fastaDbLine; @@ -71,7 +73,7 @@ void Bed2Fa::ExtractDNA() { else { if (currDNA.size() > 0) { - vector<BED> bedList = bed->bedMapNoBin[currChrom]; + vector<BED> bedList = _bed->bedMapNoBin[currChrom]; // loop through each BED entry for this chrom and // print the sequence @@ -84,13 +86,13 @@ void Bed2Fa::ExtractDNA() { string dna = currDNA.substr(bedList[i].start, ((bedList[i].end - bedList[i].start))); // revcomp if necessary. Thanks to Thomas Doktor. - if ((this->useStrand == true) && (bedList[i].strand == "-")) { + if ((_useStrand == true) && (bedList[i].strand == "-")) { reverseComplement(dna); } - if (!(this->useName)) { - if (this->useFasta == true) { - if (this->useStrand == true) { + if (!(_useName)) { + if (_useFasta == true) { + if (_useStrand == true) { faOut << ">" << currChrom << ":" << bedList[i].start << "-" << bedList[i].end << "(" << bedList[i].strand << ")" << endl << dna << endl; } @@ -100,7 +102,7 @@ void Bed2Fa::ExtractDNA() { } } else { - if (this->useStrand == true) { + if (_useStrand == true) { faOut << currChrom << ":" << bedList[i].start << "-" << bedList[i].end << "(" << bedList[i].strand << ")" << "\t" << dna << endl; @@ -112,7 +114,7 @@ void Bed2Fa::ExtractDNA() { } } else { - if (this->useFasta == true) { + if (_useFasta == true) { faOut << ">" << bedList[i].name << endl << dna << endl; } else { @@ -132,7 +134,7 @@ void Bed2Fa::ExtractDNA() { // process the last chromosome in the fasta file. if (currDNA.size() > 0) { - vector<BED> bedList = bed->bedMapNoBin[currChrom]; + vector<BED> bedList = _bed->bedMapNoBin[currChrom]; // loop through each BED entry for this chrom and // print the sequence. @@ -145,13 +147,13 @@ void Bed2Fa::ExtractDNA() { string dna = currDNA.substr(bedList[i].start, ((bedList[i].end - bedList[i].start))); // revcomp if necessary. Thanks to Thomas Doktor. - if ((this->useStrand == true) && (bedList[i].strand == "-")) { + if ((_useStrand == true) && (bedList[i].strand == "-")) { reverseComplement(dna); } - if (!(this->useName)) { - if (this->useFasta == true) { - if (this->useStrand == true) { + if (!(_useName)) { + if (_useFasta == true) { + if (_useStrand == true) { faOut << ">" << currChrom << ":" << bedList[i].start << "-" << bedList[i].end << "(" << bedList[i].strand << ")" << endl << dna << endl; } @@ -161,7 +163,7 @@ void Bed2Fa::ExtractDNA() { } } else { - if (this->useStrand == true) { + if (_useStrand == true) { faOut << currChrom << ":" << bedList[i].start << "-" << bedList[i].end << "(" << bedList[i].strand << ")" << "\t" << dna << endl; @@ -173,7 +175,7 @@ void Bed2Fa::ExtractDNA() { } } else { - if (this->useFasta == true) { + if (_useFasta == true) { faOut << ">" << bedList[i].name << endl << dna << endl; } else { diff --git a/src/fastaFromBed/fastaFromBed.h b/src/fastaFromBed/fastaFromBed.h index 1b62f367..17b12215 100755 --- a/src/fastaFromBed/fastaFromBed.h +++ b/src/fastaFromBed/fastaFromBed.h @@ -38,15 +38,15 @@ public: private: - bool useName; - string dbFile; - string bedFile; - string fastaOutFile; - bool useFasta; - bool useStrand; + bool _useName; + string _dbFile; + string _bedFile; + string _fastaOutFile; + bool _useFasta; + bool _useStrand; // instance of a bed file class. - BedFile *bed; + BedFile *_bed; }; diff --git a/src/fastaFromBed/fastaFromBedMain.cpp b/src/fastaFromBed/fastaFromBedMain.cpp index 1a3e0eb3..e2028815 100755 --- a/src/fastaFromBed/fastaFromBedMain.cpp +++ b/src/fastaFromBed/fastaFromBedMain.cpp @@ -106,7 +106,8 @@ int main(int argc, char* argv[]) { if (!showHelp) { Bed2Fa *b2f = new Bed2Fa(useNameOnly, fastaDbFile, bedFile, fastaOutFile, useFasta, useStrand); - b2f->ExtractDNA(); + delete b2f; + return 0; } else { diff --git a/src/genomeCoverageBed/genomeCoverageBed.cpp b/src/genomeCoverageBed/genomeCoverageBed.cpp index 0c25590a..1d845c80 100755 --- a/src/genomeCoverageBed/genomeCoverageBed.cpp +++ b/src/genomeCoverageBed/genomeCoverageBed.cpp @@ -16,25 +16,38 @@ BedGenomeCoverage::BedGenomeCoverage(string &bedFile, string &genomeFile, bool &eachBase, bool &startSites, bool &bedGraph, int &max, bool &bamInput) { - this->bedFile = bedFile; - this->genomeFile = genomeFile; - this->eachBase = eachBase; - this->startSites = startSites; - this->bedGraph = bedGraph; - this->max = max; - this->bamInput = bamInput; + _bedFile = bedFile; + _genomeFile = genomeFile; + _eachBase = eachBase; + _startSites = startSites; + _bedGraph = bedGraph; + _max = max; + _bamInput = bamInput; - this->bed = new BedFile(bedFile); - this->genome = new GenomeFile(genomeFile); + _bed = new BedFile(bedFile); + _genome = new GenomeFile(genomeFile); + + if (_bed->bedFile != "stdin") { // process a file + if (_bamInput == false) + CoverageBed(); + else + CoverageBam(_bed->bedFile); + } + else { // process stdin + if (_bamInput == false) + CoverageBed(); + else + CoverageBam("stdin"); + } } BedGenomeCoverage::~BedGenomeCoverage(void) { - delete this->bed; + delete _bed; } -void BedGenomeCoverage::CoverageBed(istream &bedInput) { +void BedGenomeCoverage::CoverageBed() { chromHistMap chromDepthHist; @@ -45,71 +58,64 @@ void BedGenomeCoverage::CoverageBed(istream &bedInput) { int currChromSize = 0; int start, end; - string bedLine; + BED a; int lineNum = 0; // current input line number - vector<string> bedFields; // vector for a BED entry - bedFields.reserve(12); - while (getline(bedInput, bedLine)) { - - Tokenize(bedLine,bedFields); - lineNum++; - BED bedEntry; // used to store the current BED line from the BED file. - - if (bed->parseLine(bedEntry, bedFields, lineNum)) { + _bed->Open(); + while (_bed->GetNextBed(a, lineNum)) { - currChrom = bedEntry.chrom; - start = bedEntry.start; - end = bedEntry.end - 1; - - if (currChrom != prevChrom) { - // If we've moved beyond the first encountered chromosomes, - // process the results of the previous chromosome. - if (prevChrom.length() > 0) { - ReportChromCoverage(chromCov, prevChromSize, prevChrom, chromDepthHist); - } + currChrom = a.chrom; + start = a.start; + end = a.end - 1; - // empty the previous chromosome and reserve new - std::vector<DEPTH>().swap(chromCov); - - // get the current chrom size and allocate space - currChromSize = genome->getChromSize(currChrom); - chromCov.resize(currChromSize); - - // process the first line for this chromosome. - // make sure the coordinates fit within the chrom - if (start < currChromSize) { - chromCov[start].starts++; - } - if (end < currChromSize) { - chromCov[end].ends++; - } - else { - chromCov[currChromSize-1].ends++; - } + if (currChrom != prevChrom) { + // If we've moved beyond the first encountered chromosomes, + // process the results of the previous chromosome. + if (prevChrom.length() > 0) { + ReportChromCoverage(chromCov, prevChromSize, prevChrom, chromDepthHist); + } + + // empty the previous chromosome and reserve new + std::vector<DEPTH>().swap(chromCov); + + // get the current chrom size and allocate space + currChromSize = _genome->getChromSize(currChrom); + chromCov.resize(currChromSize); + + // process the first line for this chromosome. + // make sure the coordinates fit within the chrom + if (start < currChromSize) { + chromCov[start].starts++; + } + if (end < currChromSize) { + chromCov[end].ends++; } else { - // process the other lines for this chromosome. - // make sure the coordinates fit within the chrom - if (start < currChromSize) { - chromCov[start].starts++; - } - if (end < currChromSize) { - chromCov[end].ends++; - } - else { - chromCov[currChromSize-1].ends++; - } + chromCov[currChromSize-1].ends++; } - prevChrom = currChrom; - prevChromSize = currChromSize; } - bedFields.clear(); + else { + // process the other lines for this chromosome. + // make sure the coordinates fit within the chrom + if (start < currChromSize) { + chromCov[start].starts++; + } + if (end < currChromSize) { + chromCov[end].ends++; + } + else { + chromCov[currChromSize-1].ends++; + } + } + prevChrom = currChrom; + prevChromSize = currChromSize; } + _bed->Close(); + // process the results of the last chromosome. ReportChromCoverage(chromCov, currChromSize, currChrom, chromDepthHist); - if (this->eachBase == false && this->bedGraph == false) { + if (_eachBase == false && _bedGraph == false) { ReportGenomeCoverage(chromDepthHist); } } @@ -156,7 +162,7 @@ void BedGenomeCoverage::CoverageBam(string bamFile) { std::vector<DEPTH>().swap(chromCov); // get the current chrom size and allocate space - currChromSize = genome->getChromSize(currChrom); + currChromSize = _genome->getChromSize(currChrom); chromCov.resize(currChromSize); // process the first line for this chromosome. @@ -191,7 +197,7 @@ void BedGenomeCoverage::CoverageBam(string bamFile) { // process the results of the last chromosome. ReportChromCoverage(chromCov, currChromSize, currChrom, chromDepthHist); - if (this->eachBase == false && this->bedGraph == false) { + if (_eachBase == false && _bedGraph == false) { ReportGenomeCoverage(chromDepthHist); } @@ -202,7 +208,7 @@ void BedGenomeCoverage::CoverageBam(string bamFile) { void BedGenomeCoverage::ReportChromCoverage(const vector<DEPTH> &chromCov, int &chromSize, string &chrom, chromHistMap &chromDepthHist) { - if (this->eachBase) { + if (_eachBase) { int depth = 0; // initialize the depth for (int pos = 0; pos < chromSize; pos++) { @@ -212,7 +218,7 @@ void BedGenomeCoverage::ReportChromCoverage(const vector<DEPTH> &chromCov, int & depth = depth - chromCov[pos].ends; } } - else if (this->bedGraph) { + else if (_bedGraph) { ReportChromCoverageBedGraph(chromCov, chromSize, chrom); } else { @@ -226,8 +232,8 @@ void BedGenomeCoverage::ReportChromCoverage(const vector<DEPTH> &chromCov, int & // add the depth at this position to the depth histogram // for this chromosome. if the depth is greater than the // maximum bin requested, then readjust the depth to be the max - if (depth >= this->max) { - chromDepthHist[chrom][this->max]++; + if (depth >= _max) { + chromDepthHist[chrom][_max]++; } else { chromDepthHist[chrom][depth]++; @@ -250,18 +256,18 @@ void BedGenomeCoverage::ReportChromCoverage(const vector<DEPTH> &chromCov, int & void BedGenomeCoverage::ReportGenomeCoverage(chromHistMap &chromDepthHist) { // get the list of chromosome names in the genome - vector<string> chromList = genome->getChromList(); + vector<string> chromList = _genome->getChromList(); unsigned int genomeSize = 0; vector<string>::const_iterator chromItr = chromList.begin(); vector<string>::const_iterator chromEnd = chromList.end(); for (; chromItr != chromEnd; ++chromItr) { string chrom = *chromItr; - genomeSize += genome->getChromSize(chrom); + genomeSize += _genome->getChromSize(chrom); // if there were no reads for a give chromosome, then // add the length of the chrom to the 0 bin. if ( chromDepthHist.find(chrom) == chromDepthHist.end() ) { - chromDepthHist[chrom][0] += genome->getChromSize(chrom); + chromDepthHist[chrom][0] += _genome->getChromSize(chrom); } } @@ -328,25 +334,3 @@ void BedGenomeCoverage::ReportChromCoverageBedGraph(const vector<DEPTH> &chromCo cout << chrom << "\t" << lastStart << "\t" << chromSize << "\t" << lastDepth << endl; } } - - -void BedGenomeCoverage::DetermineBedInput() { - if (bed->bedFile != "stdin") { // process a file - if (this->bamInput == false) { //bed/gff - ifstream beds(bed->bedFile.c_str(), ios::in); - if ( !beds ) { - cerr << "Error: The requested bed file (" << bed->bedFile << ") could not be opened. Exiting!" << endl; - exit (1); - } - CoverageBed(beds); - } - else - CoverageBam(bed->bedFile); - } - else { // process stdin - if (this->bamInput == false) - CoverageBed(cin); - else - CoverageBam("stdin"); - } -} diff --git a/src/genomeCoverageBed/genomeCoverageBed.h b/src/genomeCoverageBed/genomeCoverageBed.h index a08e03bc..e598181e 100755 --- a/src/genomeCoverageBed/genomeCoverageBed.h +++ b/src/genomeCoverageBed/genomeCoverageBed.h @@ -45,31 +45,28 @@ public: // destructor ~BedGenomeCoverage(void); - void CoverageBed(istream &bedInput); +private: - void CoverageBam(string bamFile); + // data + string _bedFile; + string _genomeFile; + bool _bamInput; + bool _eachBase; + bool _startSites; + bool _bedGraph; + int _max; + // The BED file from which to compute coverage. + BedFile *_bed; + GenomeFile *_genome; + + chromDepthMap _chromCov; + + // methods + void CoverageBed(); + void CoverageBam(string bamFile); void ReportChromCoverage(const vector<DEPTH> &, int &chromSize, string &chrom, chromHistMap&); - void ReportGenomeCoverage(chromHistMap &chromDepthHist); - void ReportChromCoverageBedGraph(const vector<DEPTH> &chromCov, int &chromSize, string &chrom); - - void DetermineBedInput(); - -private: - - string bedFile; - string genomeFile; - bool bamInput; - bool eachBase; - bool startSites; - bool bedGraph; - int max; - - // The BED file from which to compute coverage. - BedFile *bed; - GenomeFile *genome; - chromDepthMap chromCov; }; diff --git a/src/genomeCoverageBed/genomeCoverageMain.cpp b/src/genomeCoverageBed/genomeCoverageMain.cpp index 731f2b07..3dcf152b 100755 --- a/src/genomeCoverageBed/genomeCoverageMain.cpp +++ b/src/genomeCoverageBed/genomeCoverageMain.cpp @@ -114,8 +114,7 @@ int main(int argc, char* argv[]) { BedGenomeCoverage *bc = new BedGenomeCoverage(bedFile, genomeFile, eachBase, startSites, bedGraph, max, bamInput); - - bc->DetermineBedInput(); + delete bc; return 0; } diff --git a/src/intersectBed/intersectBed.cpp b/src/intersectBed/intersectBed.cpp index 1b8359bf..15491a6f 100755 --- a/src/intersectBed/intersectBed.cpp +++ b/src/intersectBed/intersectBed.cpp @@ -39,6 +39,21 @@ BedIntersect::BedIntersect(string bedAFile, string bedBFile, bool anyHit, // create new BED file objects for A and B _bedA = new BedFile(bedAFile); _bedB = new BedFile(bedBFile); + + // dealing with a proper file + if (_bedA->bedFile != "stdin") { + if (_bamInput == false) + IntersectBed(); + else + IntersectBam(_bedA->bedFile); + } + // reading from stdin + else { + if (_bamInput == false) + IntersectBed(); + else + IntersectBam("stdin"); + } } @@ -262,28 +277,3 @@ void BedIntersect::IntersectBam(string bamFile) { } } - -void BedIntersect::DetermineBedInput() { - - // dealing with a proper file - if (_bedA->bedFile != "stdin") { - // it's BED or GFF - if (_bamInput == false) { - IntersectBed(); - } - else { - IntersectBam(_bedA->bedFile); - } - } - // reading from stdin - else { - // it's BED or GFF - if (_bamInput == false) { - IntersectBed(); - } - // it's BAM - else { - IntersectBam("stdin"); - } - } -} diff --git a/src/intersectBed/intersectBed.h b/src/intersectBed/intersectBed.h index e49f9fa1..9b4a05e4 100755 --- a/src/intersectBed/intersectBed.h +++ b/src/intersectBed/intersectBed.h @@ -39,7 +39,6 @@ public: // destructor ~BedIntersect(void); - void DetermineBedInput(); private: diff --git a/src/intersectBed/intersectMain.cpp b/src/intersectBed/intersectMain.cpp index 086cf603..a57df8d4 100755 --- a/src/intersectBed/intersectMain.cpp +++ b/src/intersectBed/intersectMain.cpp @@ -194,7 +194,7 @@ int main(int argc, char* argv[]) { BedIntersect *bi = new BedIntersect(bedAFile, bedBFile, anyHit, writeA, writeB, writeOverlap, writeAllOverlap, overlapFraction, noHit, writeCount, forceStrand, reciprocalFraction, inputIsBam, outputIsBam); - bi->DetermineBedInput(); + delete bi; return 0; } else { diff --git a/src/linksBed/linksBed.cpp b/src/linksBed/linksBed.cpp index d0594992..25097157 100755 --- a/src/linksBed/linksBed.cpp +++ b/src/linksBed/linksBed.cpp @@ -16,12 +16,14 @@ // Constructor // BedLinks::BedLinks(string &bedFile, string &base, string &org, string &db) { - this->bedFile = bedFile; - this->bed = new BedFile(bedFile); + _bedFile = bedFile; + _bed = new BedFile(bedFile); - this->base = base; - this->org = org; - this->db = db; + _base = base; + _org = org; + _db = db; + + CreateLinks(); } // @@ -45,12 +47,12 @@ void BedLinks::WriteURL(BED &bed, string &base) { cout << "</a>" << endl; cout << "\t</td>" << endl; - if (this->bed->bedType == 4) { + if (_bed->bedType == 4) { cout << "\t<td>" << endl; cout << bed.name << endl; cout << "\t</td>" << endl; } - else if (this->bed->bedType == 5) { + else if (_bed->bedType == 5) { cout << "\t<td>" << endl; cout << bed.name << endl; cout << "\t</td>" << endl; @@ -59,7 +61,7 @@ void BedLinks::WriteURL(BED &bed, string &base) { cout << bed.score << endl; cout << "\t</td>" << endl; } - else if ((this->bed->bedType == 6) || (this->bed->bedType == 9) || (this->bed->bedType == 12)) { + else if ((_bed->bedType == 6) || (_bed->bedType == 9) || (_bed->bedType == 12)) { cout << "\t<td>" << endl; cout << bed.name << endl; cout << "\t</td>" << endl; @@ -76,13 +78,13 @@ void BedLinks::WriteURL(BED &bed, string &base) { } -void BedLinks::LinksBed(istream &bedInput) { +void BedLinks::CreateLinks() { // construct the html base. - string org = this->org; - string db = this->db; - string base = this->base; + string org = _org; + string db = _db; + string base = _base; base.append("/cgi-bin/hgTracks?org="); base.append(org); base.append("&db="); @@ -91,49 +93,27 @@ void BedLinks::LinksBed(istream &bedInput) { // create the HTML header cout << "<html>" << endl <<"\t<body>" << endl; - cout << "<title>" << this->bedFile << "</title>" << endl; + cout << "<title>" << _bedFile << "</title>" << endl; // start the table of entries cout << "<br>Firefox users: Press and hold the \"apple\" or \"alt\" key and click link to open in new tab." << endl; cout << "<p style=\"font-family:courier\">" << endl; cout << "<table border=\"0\" align=\"justify\"" << endl; + cout << "<h3>BED Entries from: stdin </h3>" << endl; - string bedLine; int lineNum = 0; - vector<string> bedFields; - bedFields.reserve(12); - - cout << "<h3>BED Entries from: stdin </h3>" << endl; - - while (getline(bedInput, bedLine)) { + BED bedEntry; - Tokenize(bedLine,bedFields); - lineNum++; - BED bedEntry; - - if (this->bed->parseLine(bedEntry, bedFields, lineNum)) { - bedEntry.count = 0; - WriteURL(bedEntry, base); - } - bedFields.clear(); + _bed->Open(); + while (_bed->GetNextBed(bedEntry, lineNum)) { + bedEntry.count = 0; + WriteURL(bedEntry, base); } + _bed->Close(); + cout << "</table>" << endl; cout << "</p>" << endl; cout << "\t</body>" << endl <<"</html>" << endl; } -void BedLinks::DetermineBedInput() { - - if (this->bedFile != "stdin") { // process a file - ifstream beds(this->bedFile.c_str(), ios::in); - if ( !beds ) { - cerr << "Error: The requested bed file (" << this->bedFile << ") could not be opened. Exiting!" << endl; - exit (1); - } - LinksBed(beds); - } - else { // process stdin - LinksBed(cin); - } -} diff --git a/src/linksBed/linksBed.h b/src/linksBed/linksBed.h index 06e8b851..01b768ac 100755 --- a/src/linksBed/linksBed.h +++ b/src/linksBed/linksBed.h @@ -25,22 +25,20 @@ class BedLinks { public: // constructor - BedLinks(string &, string &, string &, string &); + BedLinks(string &bedFile, string &base, string &org, string &db); // destructor ~BedLinks(void); - - void WriteURL(BED &, string &); - void LinksBed(istream &bedInput); // the default. sorts by chrom (asc.) then by start (asc.) - void DetermineBedInput(); private: - string bedFile; - string base; - string org; - string db; + string _bedFile; + string _base; + string _org; + string _db; // instance of a bed file class. - BedFile *bed; + BedFile *_bed; + void WriteURL(BED &bed, string &base); + void CreateLinks(); // the default. sorts by chrom (asc.) then by start (asc.) }; diff --git a/src/linksBed/linksMain.cpp b/src/linksBed/linksMain.cpp index f5b8ea2a..a03e300e 100755 --- a/src/linksBed/linksMain.cpp +++ b/src/linksBed/linksMain.cpp @@ -95,7 +95,7 @@ int main(int argc, char* argv[]) { if (!showHelp) { BedLinks *bl = new BedLinks(bedFile, base, org, db); - bl->DetermineBedInput(); + delete bl; return 0; } else { diff --git a/src/maskFastaFromBed/maskFastaFromBed.cpp b/src/maskFastaFromBed/maskFastaFromBed.cpp index ab283ce7..f2629f83 100755 --- a/src/maskFastaFromBed/maskFastaFromBed.cpp +++ b/src/maskFastaFromBed/maskFastaFromBed.cpp @@ -15,19 +15,20 @@ MaskFastaFromBed::MaskFastaFromBed(string &fastaInFile, string &bedFile, string &fastaOutFile, bool &softMask) { - this->softMask = false; + _softMask = false; if (softMask) { - this->softMask = true; + _softMask = true; } - this->fastaInFile = fastaInFile; - this->bedFile = bedFile; - this->fastaOutFile = fastaOutFile; + _fastaInFile = fastaInFile; + _bedFile = bedFile; + _fastaOutFile = fastaOutFile; - this->bed = new BedFile(this->bedFile); + _bed = new BedFile(_bedFile); + + _bed->loadBedFileIntoMapNoBin(); - // - bed->loadBedFileIntoMapNoBin(); + MaskFasta(); } @@ -43,16 +44,16 @@ void MaskFastaFromBed::MaskFasta() { /* Make sure that we can open all of the files successfully*/ // open the fasta database for reading - ifstream fa(this->fastaInFile.c_str(), ios::in); + ifstream fa(_fastaInFile.c_str(), ios::in); if ( !fa ) { - cerr << "Error: The requested fasta file (" << this->fastaInFile << ") could not be opened. Exiting!" << endl; + cerr << "Error: The requested fasta file (" << _fastaInFile << ") could not be opened. Exiting!" << endl; exit (1); } // open the fasta database for reading - ofstream faOut(this->fastaOutFile.c_str(), ios::out); + ofstream faOut(_fastaOutFile.c_str(), ios::out); if ( !faOut ) { - cerr << "Error: The requested fasta output file (" << this->fastaOutFile << ") could not be opened. Exiting!" << endl; + cerr << "Error: The requested fasta output file (" << _fastaOutFile << ") could not be opened. Exiting!" << endl; exit (1); } @@ -79,7 +80,7 @@ void MaskFastaFromBed::MaskFasta() { else { if (currDNA.size() > 0) { - vector<BED> bedList = bed->bedMapNoBin[currChrom]; + vector<BED> bedList = _bed->bedMapNoBin[currChrom]; /* loop through each BED entry for this chrom and @@ -95,7 +96,7 @@ void MaskFastaFromBed::MaskFasta() { then put it back (2) otherwise replace with Ns */ - if (this->softMask) { + if (_softMask) { replacement = currDNA.substr(start, length); toLowerCase(replacement); currDNA.replace(start, length, replacement); @@ -119,14 +120,14 @@ void MaskFastaFromBed::MaskFasta() { // exact same logic as in the main loop. if (currDNA.size() > 0) { - vector<BED> bedList = bed->bedMapNoBin[currChrom]; + vector<BED> bedList = _bed->bedMapNoBin[currChrom]; for (unsigned int i = 0; i < bedList.size(); i++) { start = bedList[i].start; end = bedList[i].end; length = end - start; - if (this->softMask) { + if (_softMask) { replacement = currDNA.substr(start, length); toLowerCase(replacement); currDNA.replace(start, length, replacement); diff --git a/src/maskFastaFromBed/maskFastaFromBed.h b/src/maskFastaFromBed/maskFastaFromBed.h index 6550a7bf..e9fec55a 100755 --- a/src/maskFastaFromBed/maskFastaFromBed.h +++ b/src/maskFastaFromBed/maskFastaFromBed.h @@ -28,25 +28,26 @@ class MaskFastaFromBed { public: // constructor - MaskFastaFromBed(string &, string &, string &, bool &); + MaskFastaFromBed(string &fastaInFile, string &bedFile, string &fastaOutFile, bool &softMask); // destructor ~MaskFastaFromBed(void); - void MaskFasta(); - - void PrettyPrintChrom(ofstream &, string , const string &, int); private: - bool softMask; + bool _softMask; - string fastaInFile; - string bedFile; - string fastaOutFile; + string _fastaInFile; + string _bedFile; + string _fastaOutFile; // instance of a bed file class. - BedFile *bed; + BedFile *_bed; + + void MaskFasta(); + + void PrettyPrintChrom(ofstream &out, string chrom, const string &sequence, int width); }; diff --git a/src/maskFastaFromBed/maskFastaFromBedMain.cpp b/src/maskFastaFromBed/maskFastaFromBedMain.cpp index 00add002..720070f5 100755 --- a/src/maskFastaFromBed/maskFastaFromBedMain.cpp +++ b/src/maskFastaFromBed/maskFastaFromBedMain.cpp @@ -98,7 +98,7 @@ int main(int argc, char* argv[]) { if (!showHelp) { MaskFastaFromBed *maskFasta = new MaskFastaFromBed(fastaInFile, bedFile, fastaOutFile, softMask); - maskFasta->MaskFasta(); + delete maskFasta; return 0; } else { diff --git a/src/mergeBed/mergeBed.cpp b/src/mergeBed/mergeBed.cpp index b577e466..6720bf14 100755 --- a/src/mergeBed/mergeBed.cpp +++ b/src/mergeBed/mergeBed.cpp @@ -29,13 +29,18 @@ void ReportMergedNames(const map<string, bool> &names) { // =============== BedMerge::BedMerge(string &bedFile, bool &numEntries, int &maxDistance, bool &forceStrand, bool &reportNames) { - this->bedFile = bedFile; - this->numEntries = numEntries; - this->maxDistance = -1 * maxDistance; - this->forceStrand = forceStrand; - this->reportNames = reportNames; + _bedFile = bedFile; + _numEntries = numEntries; + _maxDistance = -1 * maxDistance; + _forceStrand = forceStrand; + _reportNames = reportNames; - this->bed = new BedFile(bedFile); + _bed = new BedFile(bedFile); + + if (_forceStrand == false) + MergeBed(); + else + MergeBedStranded(); } @@ -53,10 +58,10 @@ void BedMerge::MergeBed() { // load the "B" bed file into a map so // that we can easily compare "A" to it for overlaps - bed->loadBedFileIntoMapNoBin(); + _bed->loadBedFileIntoMapNoBin(); // loop through each chromosome and merge their BED entries - for (masterBedMapNoBin::iterator m = bed->bedMapNoBin.begin(); m != bed->bedMapNoBin.end(); ++m) { + for (masterBedMapNoBin::iterator m = _bed->bedMapNoBin.begin(); m != _bed->bedMapNoBin.end(); ++m) { // bedList is already sorted by start position. vector<BED> bedList = m->second; @@ -81,7 +86,7 @@ void BedMerge::MergeBed() { // Is there an overlap between the current and previous entries? if ( overlaps(bedList[prev].start, bedList[prev].end, - bedList[curr].start, bedList[curr].end) >= this->maxDistance) { + bedList[curr].start, bedList[curr].end) >= _maxDistance) { OIP = true; mergeCount++; minStart = min(bedList[prev].start, min(minStart, bedList[curr].start)); @@ -91,7 +96,7 @@ void BedMerge::MergeBed() { names[bedList[curr].name] = true; } else if ( overlaps(minStart, maxEnd, - bedList[curr].start, bedList[curr].end) >= this->maxDistance) { + bedList[curr].start, bedList[curr].end) >= _maxDistance) { mergeCount++; minStart = min(minStart, bedList[curr].start); maxEnd = max(maxEnd, bedList[curr].end); @@ -100,10 +105,10 @@ void BedMerge::MergeBed() { else { // was there an overlap befor the current entry broke it? if (OIP) { - if (this->numEntries) { + if (_numEntries) { cout << bedList[prev].chrom << "\t" << minStart << "\t" << maxEnd << "\t" << mergeCount << endl; } - else if (this->reportNames) { + else if (_reportNames) { cout << bedList[prev].chrom << "\t" << minStart << "\t" << maxEnd << "\t"; ReportMergedNames(names); cout << endl; @@ -113,10 +118,10 @@ void BedMerge::MergeBed() { } } else { - if (this->numEntries) { + if (_numEntries) { cout << bedList[prev].chrom << "\t" << bedList[prev].start << "\t" << bedList[prev].end << "\t" << mergeCount << endl; } - else if (this->reportNames) { + else if (_reportNames) { cout << bedList[prev].chrom << "\t" << bedList[prev].start << "\t" << bedList[prev].end << "\t" << bedList[prev].name << endl; } else { @@ -138,10 +143,10 @@ void BedMerge::MergeBed() { // clean up based on the last entry for the current chromosome if (OIP) { - if (this->numEntries) { + if (_numEntries) { cout << bedList[prev].chrom << "\t" << minStart << "\t" << maxEnd << "\t" << mergeCount << endl; } - else if (this->reportNames) { + else if (_reportNames) { cout << bedList[prev].chrom << "\t" << minStart << "\t" << maxEnd << "\t"; ReportMergedNames(names); cout << endl; @@ -151,10 +156,10 @@ void BedMerge::MergeBed() { } } else { - if (this->numEntries) { + if (_numEntries) { cout << bedList[prev].chrom << "\t" << bedList[prev].start << "\t" << bedList[prev].end << "\t" << mergeCount << endl; } - else if (this->reportNames) { + else if (_reportNames) { cout << bedList[prev].chrom << "\t" << bedList[prev].start << "\t" << bedList[prev].end << "\t" << bedList[prev].name << endl; } else { @@ -172,10 +177,10 @@ void BedMerge::MergeBedStranded() { // load the "B" bed file into a map so // that we can easily compare "A" to it for overlaps - bed->loadBedFileIntoMapNoBin(); + _bed->loadBedFileIntoMapNoBin(); // loop through each chromosome and merge their BED entries - for (masterBedMapNoBin::iterator m = bed->bedMapNoBin.begin(); m != bed->bedMapNoBin.end(); ++m) { + for (masterBedMapNoBin::iterator m = _bed->bedMapNoBin.begin(); m != _bed->bedMapNoBin.end(); ++m) { // bedList is already sorted by start position. vector<BED> bedList = m->second; @@ -221,7 +226,7 @@ void BedMerge::MergeBedStranded() { } if ( overlaps(bedList[prev].start, bedList[prev].end, - bedList[curr].start, bedList[curr].end) >= this->maxDistance) { + bedList[curr].start, bedList[curr].end) >= _maxDistance) { OIP = true; mergeCount++; minStart = min(bedList[prev].start, min(minStart, bedList[curr].start)); @@ -231,7 +236,7 @@ void BedMerge::MergeBedStranded() { names[bedList[curr].name] = true; } else if ( overlaps(minStart, maxEnd, - bedList[curr].start, bedList[curr].end) >= this->maxDistance) { + bedList[curr].start, bedList[curr].end) >= _maxDistance) { mergeCount++; minStart = min(minStart, bedList[curr].start); maxEnd = max(maxEnd, bedList[curr].end); @@ -241,10 +246,10 @@ void BedMerge::MergeBedStranded() { // was there an overlap before the current entry broke it? if (OIP) { - if (this->numEntries) { + if (_numEntries) { cout << bedList[prev].chrom << "\t" << minStart << "\t" << maxEnd << "\t" << mergeCount << "\t" << strands[s] << endl; } - else if (this->reportNames) { + else if (_reportNames) { cout << bedList[prev].chrom << "\t" << minStart << "\t" << maxEnd << "\t"; ReportMergedNames(names); cout << "\t" << strands[s] << endl; @@ -254,10 +259,10 @@ void BedMerge::MergeBedStranded() { } } else { - if ((this->numEntries) && (numOnStrand > 0)) { + if ((_numEntries) && (numOnStrand > 0)) { cout << bedList[prev].chrom << "\t" << bedList[prev].start << "\t" << bedList[prev].end << "\t" << mergeCount << "\t" << strands[s] << endl; } - else if (this->reportNames) { + else if (_reportNames) { cout << bedList[prev].chrom << "\t" << bedList[prev].start << "\t" << bedList[prev].end << "\t" << bedList[prev].name << "\t" << strands[s] << endl; } else if (numOnStrand > 0) { @@ -280,10 +285,10 @@ void BedMerge::MergeBedStranded() { // clean up based on the last entry for the current chromosome if (OIP) { - if (this->numEntries) { + if (_numEntries) { cout << bedList[prev].chrom << "\t" << minStart << "\t" << maxEnd << "\t" << mergeCount << "\t" << strands[s] << endl; } - else if (this->reportNames) { + else if (_reportNames) { cout << bedList[prev].chrom << "\t" << minStart << "\t" << maxEnd << "\t"; ReportMergedNames(names); cout << "\t" << strands[s] << endl; @@ -293,10 +298,10 @@ void BedMerge::MergeBedStranded() { } } else { - if ((this->numEntries) && (numOnStrand > 0)) { + if ((_numEntries) && (numOnStrand > 0)) { cout << bedList[prev].chrom << "\t" << bedList[prev].start << "\t" << bedList[prev].end << "\t" << mergeCount << "\t" << strands[s] << endl; } - else if ((this->reportNames) && (numOnStrand > 0)) { + else if ((_reportNames) && (numOnStrand > 0)) { cout << bedList[prev].chrom << "\t" << bedList[prev].start << "\t" << bedList[prev].end << "\t" << bedList[prev].name << "\t" << strands[s] << endl; } else if (numOnStrand > 0) { diff --git a/src/mergeBed/mergeBed.h b/src/mergeBed/mergeBed.h index 336c5d55..b6023801 100755 --- a/src/mergeBed/mergeBed.h +++ b/src/mergeBed/mergeBed.h @@ -29,7 +29,7 @@ class BedMerge { public: // constructor - BedMerge(string &, bool &, int&, bool &, bool &); + BedMerge(string &bedFile, bool &numEntries, int &maxDistance, bool &forceStrand, bool &reportNames); // destructor ~BedMerge(void); @@ -39,12 +39,12 @@ public: private: - string bedFile; - bool numEntries; - bool forceStrand; - bool reportNames; - int maxDistance; + string _bedFile; + bool _numEntries; + bool _forceStrand; + bool _reportNames; + int _maxDistance; // instance of a bed file class. - BedFile *bed; + BedFile *_bed; }; diff --git a/src/mergeBed/mergeMain.cpp b/src/mergeBed/mergeMain.cpp index 82e3dde4..43f3f653 100755 --- a/src/mergeBed/mergeMain.cpp +++ b/src/mergeBed/mergeMain.cpp @@ -100,13 +100,7 @@ int main(int argc, char* argv[]) { if (!showHelp) { BedMerge *bm = new BedMerge(bedFile, numEntries, maxDistance, forceStrand, reportNames); - - if (!forceStrand) { - bm->MergeBed(); - } - else { - bm->MergeBedStranded(); - } + delete bm; return 0; } else { diff --git a/src/pairToBed/pairToBed.cpp b/src/pairToBed/pairToBed.cpp index f7423189..3a52aa8c 100755 --- a/src/pairToBed/pairToBed.cpp +++ b/src/pairToBed/pairToBed.cpp @@ -35,16 +35,16 @@ bool IsCorrectMappingForBEDPE (const BamAlignment &bam) { BedIntersectPE::BedIntersectPE(string bedAFilePE, string bedBFile, float overlapFraction, string searchType, bool forceStrand, bool bamInput, bool bamOutput) { - this->bedAFilePE = bedAFilePE; - this->bedBFile = bedBFile; - this->overlapFraction = overlapFraction; - this->forceStrand = forceStrand; - this->searchType = searchType; - this->bamInput = bamInput; - this->bamOutput = bamOutput; + _bedAFilePE = bedAFilePE; + _bedBFile = bedBFile; + _overlapFraction = overlapFraction; + _forceStrand = forceStrand; + _searchType = searchType; + _bamInput = bamInput; + _bamOutput = bamOutput; - this->bedA = new BedFilePE(bedAFilePE); - this->bedB = new BedFile(bedBFile); + _bedA = new BedFilePE(bedAFilePE); + _bedB = new BedFile(bedBFile); } @@ -72,7 +72,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, this->forceStrand); + _bedB->FindOverlapsPerBin(a.chrom1, a.start1, a.end1, a.strand1, hits1, _forceStrand); vector<BED>::const_iterator h = hits1.begin(); vector<BED>::const_iterator hitsEnd = hits1.end(); @@ -84,12 +84,12 @@ void BedIntersectPE::FindOverlaps(const BEDPE &a, vector<BED> &hits1, vector<BED int aLength = (a.end1 - a.start1); // the length of a in b.p. // is there enough overlap relative to the user's request? (default ~ 1bp) - if ( ( (float) overlapBases / (float) aLength ) >= this->overlapFraction ) { + if ( ( (float) overlapBases / (float) aLength ) >= _overlapFraction ) { numOverlapsEnd1++; if (type == "either") { - bedA->reportBedPETab(a); - bedB->reportBedNewLine(*h); + _bedA->reportBedPETab(a); + _bedB->reportBedNewLine(*h); } else { qualityHits1.push_back(*h); @@ -102,7 +102,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, this->forceStrand); + _bedB->FindOverlapsPerBin(a.chrom2, a.start2, a.end2, a.strand2, hits2, _forceStrand); vector<BED>::const_iterator h = hits2.begin(); vector<BED>::const_iterator hitsEnd = hits2.end(); @@ -114,12 +114,12 @@ void BedIntersectPE::FindOverlaps(const BEDPE &a, vector<BED> &hits1, vector<BED int aLength = (a.end2 - a.start2); // the length of a in b.p. // is there enough overlap relative to the user's request? (default ~ 1bp) - if ( ( (float) overlapBases / (float) aLength ) >= this->overlapFraction ) { + if ( ( (float) overlapBases / (float) aLength ) >= _overlapFraction ) { numOverlapsEnd2++; if (type == "either") { - bedA->reportBedPETab(a); - bedB->reportBedNewLine(*h); + _bedA->reportBedPETab(a); + _bedB->reportBedNewLine(*h); } else { qualityHits2.push_back(*h); @@ -131,49 +131,49 @@ void BedIntersectPE::FindOverlaps(const BEDPE &a, vector<BED> &hits1, vector<BED // Now report the hits depending on what the user has requested. if (type == "neither") { if ( (numOverlapsEnd1 == 0) && (numOverlapsEnd2 == 0) ) { - bedA->reportBedPENewLine(a); + _bedA->reportBedPENewLine(a); } } else if (type == "notboth") { if ( (numOverlapsEnd1 == 0) && (numOverlapsEnd2 == 0) ) { - bedA->reportBedPENewLine(a); + _bedA->reportBedPENewLine(a); } else if ( (numOverlapsEnd1 > 0) && (numOverlapsEnd2 == 0) ) { for (vector<BED>::iterator q = qualityHits1.begin(); q != qualityHits1.end(); ++q) { - bedA->reportBedPETab(a); - bedB->reportBedNewLine(*q); + _bedA->reportBedPETab(a); + _bedB->reportBedNewLine(*q); } } else if ( (numOverlapsEnd1 == 0) && (numOverlapsEnd2 > 0) ) { for (vector<BED>::iterator q = qualityHits2.begin(); q != qualityHits2.end(); ++q) { - bedA->reportBedPETab(a); - bedB->reportBedNewLine(*q); + _bedA->reportBedPETab(a); + _bedB->reportBedNewLine(*q); } } } else if (type == "xor") { if ( (numOverlapsEnd1 > 0) && (numOverlapsEnd2 == 0) ) { for (vector<BED>::iterator q = qualityHits1.begin(); q != qualityHits1.end(); ++q) { - bedA->reportBedPETab(a); - bedB->reportBedNewLine(*q); + _bedA->reportBedPETab(a); + _bedB->reportBedNewLine(*q); } } else if ( (numOverlapsEnd1 == 0) && (numOverlapsEnd2 > 0) ) { for (vector<BED>::iterator q = qualityHits2.begin(); q != qualityHits2.end(); ++q) { - bedA->reportBedPETab(a); - bedB->reportBedNewLine(*q); + _bedA->reportBedPETab(a); + _bedB->reportBedNewLine(*q); } } } else if (type == "both") { if ( (numOverlapsEnd1 > 0) && (numOverlapsEnd2 > 0) ) { for (vector<BED>::iterator q = qualityHits1.begin(); q != qualityHits1.end(); ++q) { - bedA->reportBedPETab(a); - bedB->reportBedNewLine(*q); + _bedA->reportBedPETab(a); + _bedB->reportBedNewLine(*q); } for (vector<BED>::iterator q = qualityHits2.begin(); q != qualityHits2.end(); ++q) { - bedA->reportBedPETab(a); - bedB->reportBedNewLine(*q); + _bedA->reportBedPETab(a); + _bedB->reportBedNewLine(*q); } } } @@ -189,8 +189,8 @@ 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, - this->forceStrand, this->overlapFraction); + end1Found = _bedB->FindOneOrMoreOverlapsPerBin(a.chrom1, a.start1, a.end1, a.strand1, + _forceStrand, _overlapFraction); // can we bail out without checking end2? if ((type == "either") && (end1Found == true)) return true; @@ -201,8 +201,8 @@ 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, - this->forceStrand, this->overlapFraction); + end2Found = _bedB->FindOneOrMoreOverlapsPerBin(a.chrom2, a.start2, a.end2, a.strand2, + _forceStrand, _overlapFraction); if ((type == "either") && (end2Found == true)) return true; else if ((type == "neither") && (end2Found == true)) return false; @@ -263,7 +263,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, this->forceStrand); + _bedB->FindOverlapsPerBin(a.chrom1, spanStart, spanEnd, a.strand1, hits, _forceStrand); vector<BED>::const_iterator h = hits.begin(); vector<BED>::const_iterator hitsEnd = hits.end(); @@ -275,17 +275,17 @@ void BedIntersectPE::FindSpanningOverlaps(const BEDPE &a, vector<BED> &hits, con int spanLength = (spanEnd - spanStart); // the length of a in b.p. // is there enough overlap relative to the user's request? (default ~ 1bp) - if ( ( (float) overlapBases / (float) spanLength ) >= this->overlapFraction ) { + if ( ( (float) overlapBases / (float) spanLength ) >= _overlapFraction ) { numOverlaps++; if ((type == "ispan") || (type == "ospan")) { - bedA->reportBedPETab(a); - bedB->reportBedNewLine(*h); + _bedA->reportBedPETab(a); + _bedB->reportBedNewLine(*h); } } } if ( ( (type == "notispan") || (type == "notospan") ) && numOverlaps == 0 ) { - bedA->reportBedPENewLine(a); + _bedA->reportBedPENewLine(a); } } @@ -315,8 +315,8 @@ bool BedIntersectPE::FindOneOrMoreSpanningOverlaps(const BEDPE &a, const string } spanLength = spanEnd - spanStart; - overlapFound = bedB->FindOneOrMoreOverlapsPerBin(a.chrom1, spanStart, spanEnd, a.strand1, - this->forceStrand, this->overlapFraction); + overlapFound = _bedB->FindOneOrMoreOverlapsPerBin(a.chrom1, spanStart, spanEnd, a.strand1, + _forceStrand, _overlapFraction); return overlapFound; } @@ -327,7 +327,7 @@ void BedIntersectPE::IntersectBedPE(istream &bedInput) { // load the "B" bed file into a map so // that we can easily compare "A" to it for overlaps - bedB->loadBedFileIntoMap(); + _bedB->loadBedFileIntoMap(); string bedLine; int lineNum = 0; // current input line number @@ -348,16 +348,16 @@ void BedIntersectPE::IntersectBedPE(istream &bedInput) { BEDPE a; // find the overlaps with B if it's a valid BED entry. - if (bedA->parseBedPELine(a, bedFields, lineNum)) { - if ( (this->searchType == "ispan") || (this->searchType == "ospan") || - (this->searchType == "notispan") || (this->searchType == "notospan") ) { + if (_bedA->parseBedPELine(a, bedFields, lineNum)) { + if ( (_searchType == "ispan") || (_searchType == "ospan") || + (_searchType == "notispan") || (_searchType == "notospan") ) { if (a.chrom1 == a.chrom2) { - FindSpanningOverlaps(a, hits, this->searchType); + FindSpanningOverlaps(a, hits, _searchType); hits.clear(); } } else { - FindOverlaps(a, hits1, hits2, this->searchType); + FindOverlaps(a, hits1, hits2, _searchType); hits1.clear(); hits2.clear(); } @@ -373,7 +373,7 @@ void BedIntersectPE::IntersectBamPE(string bamFile) { // load the "B" bed file into a map so // that we can easily compare "A" to it for overlaps - bedB->loadBedFileIntoMap(); + _bedB->loadBedFileIntoMap(); // open the BAM file BamReader reader; @@ -385,7 +385,7 @@ void BedIntersectPE::IntersectBamPE(string bamFile) { RefVector refs = reader.GetReferenceData(); // open a BAM output to stdout if we are writing BAM - if (this->bamOutput == true) { + if (_bamOutput == true) { // open our BAM writer writer.Open("stdout", header, refs); } @@ -396,7 +396,7 @@ void BedIntersectPE::IntersectBamPE(string bamFile) { hits1.reserve(1000); hits2.reserve(1000); - bedA->bedType = 10; // it's a full BEDPE given it's BAM + _bedA->bedType = 10; // it's a full BEDPE given it's BAM BamAlignment bam; bool overlapsFound; @@ -409,72 +409,72 @@ void BedIntersectPE::IntersectBamPE(string bamFile) { cerr << "Encountered an unpaired alignment. Are you sure this is a paired BAM file? Exiting." << endl; exit(1); } - else if ((this->searchType == "ispan") || (this->searchType == "ospan")) { + else if ((_searchType == "ispan") || (_searchType == "ospan")) { // only look for ispan and ospan when both ends are mapped. if (bam.IsMapped() && bam.IsMateMapped()) { // only do an inspan or outspan check if the alignment is intrachromosomal if (bam.RefID == bam.MateRefID) { - if (this->bamOutput == true) { // BAM output + if (_bamOutput == true) { // BAM output BEDPE a; ConvertBamToBedPE(bam, refs, a); // look for overlaps, and write to BAM if >=1 were found - overlapsFound = FindOneOrMoreSpanningOverlaps(a, this->searchType); + overlapsFound = FindOneOrMoreSpanningOverlaps(a, _searchType); if (overlapsFound == true) writer.SaveAlignment(bam); } else if ( IsCorrectMappingForBEDPE(bam) ) { // BEDPE output BEDPE a; ConvertBamToBedPE(bam, refs, a); - FindSpanningOverlaps(a, hits, this->searchType); + FindSpanningOverlaps(a, hits, _searchType); } } } } - else if ((this->searchType == "notispan") || (this->searchType == "notospan")) { + else if ((_searchType == "notispan") || (_searchType == "notospan")) { // only look for notispan and notospan when both ends are mapped. if (bam.IsMapped() && bam.IsMateMapped()) { // only do an inspan or outspan if the alignment is intrachromosomal if (bam.RefID == bam.MateRefID) { - if (this->bamOutput == true) { // BAM output + if (_bamOutput == true) { // BAM output BEDPE a; ConvertBamToBedPE(bam, refs, a); // write to BAM if there were no overlaps - overlapsFound = FindOneOrMoreSpanningOverlaps(a, this->searchType); + overlapsFound = FindOneOrMoreSpanningOverlaps(a, _searchType); if (overlapsFound == false) writer.SaveAlignment(bam); } else if ( IsCorrectMappingForBEDPE(bam) ) { // BEDPE output BEDPE a; ConvertBamToBedPE(bam, refs, a); - FindSpanningOverlaps(a, hits, this->searchType); + FindSpanningOverlaps(a, hits, _searchType); } } // if inter-chromosomal or orphaned, we know it's not ispan and not ospan - else if (this->bamOutput == true) writer.SaveAlignment(bam); + else if (_bamOutput == true) writer.SaveAlignment(bam); } // if both ends aren't mapped, we know that it's notispan and not ospan - else if (this->bamOutput == true) writer.SaveAlignment(bam); + else if (_bamOutput == true) writer.SaveAlignment(bam); } - else if ( (this->searchType == "either") || (this->searchType == "xor") || - (this->searchType == "both") || (this->searchType == "notboth") || - (this->searchType == "neither") ) { + else if ( (_searchType == "either") || (_searchType == "xor") || + (_searchType == "both") || (_searchType == "notboth") || + (_searchType == "neither") ) { - if (this->bamOutput == true) { // BAM output + if (_bamOutput == true) { // BAM output BEDPE a; ConvertBamToBedPE(bam, refs, a); // write to BAM if correct hits found - overlapsFound = FindOneOrMoreOverlaps(a, this->searchType); + overlapsFound = FindOneOrMoreOverlaps(a, _searchType); if (overlapsFound == true) writer.SaveAlignment(bam); } else if ( IsCorrectMappingForBEDPE(bam) ) { // BEDPE output BEDPE a; ConvertBamToBedPE(bam, refs, a); - FindOverlaps(a, hits1, hits2, this->searchType); + FindOverlaps(a, hits1, hits2, _searchType); hits1.clear(); hits2.clear(); } } } reader.Close(); - if (this->bamOutput == true) { + if (_bamOutput == true) { writer.Close(); } } @@ -482,21 +482,21 @@ void BedIntersectPE::IntersectBamPE(string bamFile) { void BedIntersectPE::DetermineBedPEInput() { - if (bedA->bedFile != "stdin") { // process a file - if (this->bamInput == false) { // BEDPE - ifstream beds(bedA->bedFile.c_str(), ios::in); + if (_bedA->bedFile != "stdin") { // process a file + if (_bamInput == false) { // BEDPE + ifstream beds(_bedA->bedFile.c_str(), ios::in); if ( !beds ) { - cerr << "Error: The requested bed file (" << bedA->bedFile << ") could not be opened. Exiting!" << endl; + cerr << "Error: The requested bed file (" << _bedA->bedFile << ") could not be opened. Exiting!" << endl; exit (1); } IntersectBedPE(beds); } else { // bam - IntersectBamPE(bedA->bedFile); + IntersectBamPE(_bedA->bedFile); } } else { // process stdin - if (this->bamInput == false) { // BEDPE + if (_bamInput == false) { // BEDPE IntersectBedPE(cin); } else { diff --git a/src/pairToBed/pairToBed.h b/src/pairToBed/pairToBed.h index bc938f9d..565827ad 100755 --- a/src/pairToBed/pairToBed.h +++ b/src/pairToBed/pairToBed.h @@ -62,21 +62,22 @@ public: private: - string bedAFilePE; - string bedBFile; - float overlapFraction; - string searchType; - bool forceStrand; - bool bamInput; - bool bamOutput; + string _bedAFilePE; + string _bedBFile; + float _overlapFraction; + string _searchType; + bool _forceStrand; + bool _bamInput; + bool _bamOutput; // instance of a paired-end bed file class. - BedFilePE *bedA; + BedFilePE *_bedA; // instance of a bed file class. - BedFile *bedB; + BedFile *_bedB; - inline void ConvertBamToBedPE(const BamAlignment &bam, const RefVector &refs, BEDPE &a) { + inline + void ConvertBamToBedPE(const BamAlignment &bam, const RefVector &refs, BEDPE &a) { a.start1 = a.start2 = a.end1 = a.end2 = -1; a.chrom1 = a.chrom2 = a.strand1 = a.strand2 = "."; diff --git a/src/shuffleBed/shuffleBed.cpp b/src/shuffleBed/shuffleBed.cpp index cdcfa2f5..faa62d1e 100755 --- a/src/shuffleBed/shuffleBed.cpp +++ b/src/shuffleBed/shuffleBed.cpp @@ -15,33 +15,46 @@ BedShuffle::BedShuffle(string &bedFile, string &genomeFile, string &excludeFile, bool &haveSeed, bool &haveExclude, bool &sameChrom, int &seed) { - this->bedFile = bedFile; - this->genomeFile = genomeFile; - this->excludeFile = excludeFile; - this->sameChrom = sameChrom; - this->haveExclude = haveExclude; - this->haveSeed = haveSeed; + _bedFile = bedFile; + _genomeFile = genomeFile; + _excludeFile = excludeFile; + _sameChrom = sameChrom; + _haveExclude = haveExclude; + _haveSeed = haveSeed; // use the supplied seed for the random // number generation if given. else, // roll our own. - if (this->haveSeed) { - this->seed = seed; + if (_haveSeed) { + _seed = seed; srand(seed); } else { srand((unsigned)time(0)); } - this->bed = new BedFile(bedFile); - this->genome = new GenomeFile(genomeFile); - this->chroms = genome->getChromList(); - this->numChroms = genome->getNumberOfChroms(); + _bed = new BedFile(bedFile); + _genome = new GenomeFile(genomeFile); + _chroms = _genome->getChromList(); + _numChroms = _genome->getNumberOfChroms(); - if (this->haveExclude) { - this->exclude = new BedFile(excludeFile); - this->exclude->loadBedFileIntoMap(); + if (_haveExclude) { + _exclude = new BedFile(excludeFile); + _exclude->loadBedFileIntoMap(); + } + + if (_bed->bedFile != "stdin") { // process a file + if (_haveExclude) + ShuffleWithExclusions(); + else + Shuffle(); + } + else { // process stdin + if (_haveExclude) + ShuffleWithExclusions(); + else + Shuffle(); } } @@ -51,55 +64,68 @@ BedShuffle::~BedShuffle(void) { } -void BedShuffle::Shuffle(istream &bedInput) { +void BedShuffle::Shuffle() { int lineNum = 0; - string bedLine; // used to store the current (unparsed) line from the BED file. - vector<string> bedFields; - bedFields.reserve(12); - - while (getline(bedInput, bedLine)) { - - Tokenize(bedLine,bedFields); - lineNum++; - BED bedEntry; // used to store the current BED line from the BED file. - - if (bed->parseLine(bedEntry, bedFields, lineNum)) { - // choose a new locus for this feat - ChooseLocus(bedEntry); - bed->reportBedNewLine(bedEntry); - } - bedFields.clear(); + BED bedEntry; // used to store the current BED line from the BED file. + + _bed->Open(); + while (_bed->GetNextBed(bedEntry, lineNum)) { + ChooseLocus(bedEntry); + _bed->reportBedNewLine(bedEntry); } + _bed->Close(); } -void BedShuffle::ShuffleWithExclusions(istream &bedInput) { +void BedShuffle::ShuffleWithExclusions() { int lineNum = 0; - string bedLine; // used to store the current (unparsed) line from the BED file. - vector<string> bedFields; - bedFields.reserve(12); + BED bedEntry; // used to store the current BED line from the BED file. vector<BED> hits; hits.reserve(100); - while (getline(bedInput, bedLine)) { + _bed->Open(); + while (_bed->GetNextBed(bedEntry, lineNum)) { + + // choose a random locus + ChooseLocus(bedEntry); - Tokenize(bedLine,bedFields); - lineNum++; - BED bedEntry; // used to store the current BED line from the BED file. + // test to see if the chosen locus overlaps + // with an exclude region + _exclude->FindOverlapsPerBin(bedEntry.chrom, bedEntry.start, bedEntry.end, bedEntry.strand, hits, false); + + bool haveOverlap = false; + vector<BED>::const_iterator hitsItr = hits.begin(); + vector<BED>::const_iterator hitsEnd = hits.end(); + for (; hitsItr != hitsEnd; ++hitsItr) { - if (bed->parseLine(bedEntry, bedFields, lineNum)) { - - // choose a random locus - ChooseLocus(bedEntry); - - // test to see if the chosen locus overlaps - // with an exclude region - exclude->FindOverlapsPerBin(bedEntry.chrom, bedEntry.start, bedEntry.end, bedEntry.strand, hits, false); - - bool haveOverlap = false; + int s = max(bedEntry.start, hitsItr->start); + int e = min(bedEntry.end, hitsItr->end); + + if ( (e - s) > 0) { + haveOverlap = true; + break; /* stop looking. one overlap is enough*/ + } + } + + /* + keep looking as long as the chosen + locus happens to overlap with regions + that the user wishes to exclude. + */ + int tries = 0; + while ((haveOverlap == true) && (tries <= MAX_TRIES)) { + + // choose a new locus + ChooseLocus(bedEntry); + + vector<BED> hits; + _exclude->FindOverlapsPerBin(bedEntry.chrom, bedEntry.start, bedEntry.end, + bedEntry.strand, hits, false); + + haveOverlap = false; vector<BED>::const_iterator hitsItr = hits.begin(); vector<BED>::const_iterator hitsEnd = hits.end(); for (; hitsItr != hitsEnd; ++hitsItr) { @@ -109,49 +135,18 @@ void BedShuffle::ShuffleWithExclusions(istream &bedInput) { if ( (e - s) > 0) { haveOverlap = true; - break; /* stop looking. one overlap is enough*/ - } - } - - /* - keep looking as long as the chosen - locus happens to overlap with regions - that the user wishes to exclude. - */ - int tries = 0; - while ((haveOverlap == true) && (tries <= MAX_TRIES)) { - - // choose a new locus - ChooseLocus(bedEntry); - - vector<BED> hits; - exclude->FindOverlapsPerBin(bedEntry.chrom, bedEntry.start, bedEntry.end, - bedEntry.strand, hits, false); - - haveOverlap = false; - vector<BED>::const_iterator hitsItr = hits.begin(); - vector<BED>::const_iterator hitsEnd = hits.end(); - for (; hitsItr != hitsEnd; ++hitsItr) { - - int s = max(bedEntry.start, hitsItr->start); - int e = min(bedEntry.end, hitsItr->end); - - if ( (e - s) > 0) { - haveOverlap = true; - break; /* stop looking. one overlap is enough*/ - } + break; /* stop looking. one overlap is enough*/ } - tries++; - } - - if (tries > MAX_TRIES) { - cerr << "Error, line " << lineNum << ": tried " << MAX_TRIES << " potential loci for entry, but could not avoid excluded regions. Ignoring entry and moving on." << endl; - } - else { - bed->reportBedNewLine(bedEntry); } + tries++; + } + + if (tries > MAX_TRIES) { + cerr << "Error, line " << lineNum << ": tried " << MAX_TRIES << " potential loci for entry, but could not avoid excluded regions. Ignoring entry and moving on." << endl; + } + else { + _bed->reportBedNewLine(bedEntry); } - bedFields.clear(); } } @@ -168,16 +163,16 @@ void BedShuffle::ChooseLocus(BED &bedEntry) { int randomStart; int chromSize; - if (!this->sameChrom) { - randomChrom = chroms[rand() % this->numChroms]; - chromSize = genome->getChromSize(randomChrom); + if (_sameChrom == false) { + randomChrom = _chroms[rand() % _numChroms]; + chromSize = _genome->getChromSize(randomChrom); randomStart = rand() % chromSize; bedEntry.chrom = randomChrom; bedEntry.start = randomStart; bedEntry.end = randomStart + length; } else { - chromSize = genome->getChromSize(chrom); + chromSize = _genome->getChromSize(chrom); randomStart = rand() % chromSize; bedEntry.start = randomStart; bedEntry.end = randomStart + length; @@ -187,16 +182,16 @@ void BedShuffle::ChooseLocus(BED &bedEntry) { // the length of the chromosome. if so, keep looking // for a new spot. while (bedEntry.end > chromSize) { - if (!this->sameChrom) { - randomChrom = chroms[rand() % this->numChroms]; - chromSize = genome->getChromSize(randomChrom); + if (_sameChrom == false) { + randomChrom = _chroms[rand() % _numChroms]; + chromSize = _genome->getChromSize(randomChrom); randomStart = rand() % chromSize; bedEntry.chrom = randomChrom; bedEntry.start = randomStart; bedEntry.end = randomStart + length; } else { - chromSize = genome->getChromSize(chrom); + chromSize = _genome->getChromSize(chrom); randomStart = rand() % chromSize; bedEntry.start = randomStart; bedEntry.end = randomStart + length; @@ -204,29 +199,3 @@ void BedShuffle::ChooseLocus(BED &bedEntry) { } } - -void BedShuffle::DetermineBedInput() { - if (bed->bedFile != "stdin") { // process a file - ifstream beds(bed->bedFile.c_str(), ios::in); - if ( !beds ) { - cerr << "Error: The requested bed file (" << bed->bedFile << ") could not be opened. Exiting!" << endl; - exit (1); - } - if (this->haveExclude) { - ShuffleWithExclusions(beds); - } - else { - Shuffle(beds); - } - } - else { - // process stdin - if (this->haveExclude) { - ShuffleWithExclusions(cin); - } - else { - Shuffle(cin); - } - } -} - diff --git a/src/shuffleBed/shuffleBed.h b/src/shuffleBed/shuffleBed.h index 5bfad33d..3c015f7c 100755 --- a/src/shuffleBed/shuffleBed.h +++ b/src/shuffleBed/shuffleBed.h @@ -37,30 +37,29 @@ public: // destructor ~BedShuffle(void); - void Shuffle(istream &bedInput); - void ShuffleWithExclusions(istream &bedInput); - - void ChooseLocus(BED &); - - void DetermineBedInput(); - private: - string bedFile; - string genomeFile; - string excludeFile; - int seed; - bool sameChrom; - bool haveExclude; - bool haveSeed; + string _bedFile; + string _genomeFile; + string _excludeFile; + int _seed; + bool _sameChrom; + bool _haveExclude; + bool _haveSeed; // The BED file from which to compute coverage. - BedFile *bed; - BedFile *exclude; + BedFile *_bed; + BedFile *_exclude; - GenomeFile *genome; + GenomeFile *_genome; - vector<string> chroms; - int numChroms; + vector<string> _chroms; + int _numChroms; + + // methods + void Shuffle(); + void ShuffleWithExclusions(); + + void ChooseLocus(BED &); }; diff --git a/src/shuffleBed/shuffleBedMain.cpp b/src/shuffleBed/shuffleBedMain.cpp index b4ae12d8..2d51bb2d 100755 --- a/src/shuffleBed/shuffleBedMain.cpp +++ b/src/shuffleBed/shuffleBedMain.cpp @@ -105,9 +105,7 @@ int main(int argc, char* argv[]) { if (!showHelp) { BedShuffle *bc = new BedShuffle(bedFile, genomeFile, excludeFile, haveSeed, haveExclude, sameChrom, seed); - - bc->DetermineBedInput(); - + delete bc; return 0; } else { diff --git a/src/slopBed/slopBed.cpp b/src/slopBed/slopBed.cpp index 590bf2bc..118eb758 100755 --- a/src/slopBed/slopBed.cpp +++ b/src/slopBed/slopBed.cpp @@ -15,15 +15,17 @@ BedSlop::BedSlop(string &bedFile, string &genomeFile, bool &forceStrand, int &leftSlop, int &rightSlop) { - this->bedFile = bedFile; - this->genomeFile = genomeFile; - this->forceStrand = forceStrand; + _bedFile = bedFile; + _genomeFile = genomeFile; + _forceStrand = forceStrand; - this->leftSlop = leftSlop; - this->rightSlop = rightSlop; + _leftSlop = leftSlop; + _rightSlop = rightSlop; - this->bed = new BedFile(bedFile); - this->genome = new GenomeFile(genomeFile); + _bed = new BedFile(bedFile); + _genome = new GenomeFile(genomeFile); + + SlopBed(); } @@ -32,23 +34,17 @@ BedSlop::~BedSlop(void) { } -void BedSlop::SlopBed(istream &bedInput) { +void BedSlop::SlopBed() { int lineNum = 0; - string bedLine; // used to store the current (unparsed) line from the BED file. - - while (getline(bedInput, bedLine)) { - - vector<string> bedFields; - Tokenize(bedLine,bedFields); - lineNum++; - - BED bedEntry; // used to store the current BED line from the BED file. - if (this->bed->parseLine(bedEntry, bedFields, lineNum)) { - AddSlop(bedEntry); - bed->reportBedNewLine(bedEntry); - } + BED bedEntry; // used to store the current BED line from the BED file. + + _bed->Open(); + while (_bed->GetNextBed(bedEntry, lineNum)) { + AddSlop(bedEntry); + _bed->reportBedNewLine(bedEntry); } + _bed->Close(); } @@ -56,40 +52,26 @@ void BedSlop::AddSlop(BED &bed) { // special handling if the BED entry is on the negative // strand and the user cares about strandedness. - int chromSize = genome->getChromSize(bed.chrom); + int chromSize = _genome->getChromSize(bed.chrom); - if ( (this->forceStrand) && (bed.strand == "-") ) { + if ( (_forceStrand) && (bed.strand == "-") ) { // inspect the start - if ((bed.start - rightSlop) > 0) bed.start -= rightSlop; + if ((bed.start - _rightSlop) > 0) bed.start -= _rightSlop; else bed.start = 0; // inspect the start - if ((bed.end + leftSlop) <= chromSize) bed.end += leftSlop; + if ((bed.end + _leftSlop) <= chromSize) bed.end += _leftSlop; else bed.end = chromSize; } else { // inspect the start - if ((bed.start - leftSlop) > 0) bed.start -= leftSlop; + if ((bed.start - _leftSlop) > 0) bed.start -= _leftSlop; else bed.start = 0; // inspect the end - if ((bed.end + rightSlop) <= chromSize) bed.end += rightSlop; + if ((bed.end + _rightSlop) <= chromSize) bed.end += _rightSlop; else bed.end = chromSize; } } -void BedSlop::DetermineBedInput() { - - if (this->bedFile != "stdin") { // process a file - ifstream beds(this->bedFile.c_str(), ios::in); - if ( !beds ) { - cerr << "Error: The requested bed file (" << this->bedFile << ") could not be opened. Exiting!" << endl; - exit (1); - } - SlopBed(beds); - } - else { // process stdin - SlopBed(cin); - } -} diff --git a/src/slopBed/slopBed.h b/src/slopBed/slopBed.h index e6dbce0e..9e4baf17 100755 --- a/src/slopBed/slopBed.h +++ b/src/slopBed/slopBed.h @@ -30,27 +30,29 @@ class BedSlop { public: // constructor - BedSlop(string &, string &, bool &, int &, int &); + BedSlop(string &bedFile, string &genomeFile, bool &forceStrand, int &leftSlop, int &rightSlop) ; // destructor ~BedSlop(void); - void SlopBed(istream &bedInput); - - // method to add requested "slop" to a single BED entry - void AddSlop(BED &bed); - - void DetermineBedInput(); + private: - string bedFile; - string genomeFile; + string _bedFile; + string _genomeFile; - bool forceStrand; - int leftSlop; - int rightSlop; + bool _forceStrand; + int _leftSlop; + int _rightSlop; - BedFile *bed; - GenomeFile *genome; + BedFile *_bed; + GenomeFile *_genome; + + // methods + + void SlopBed(); + + // method to add requested "slop" to a single BED entry + void AddSlop(BED &bed); }; diff --git a/src/slopBed/slopBedMain.cpp b/src/slopBed/slopBedMain.cpp index e4f35fed..0b4af157 100755 --- a/src/slopBed/slopBedMain.cpp +++ b/src/slopBed/slopBedMain.cpp @@ -127,7 +127,7 @@ int main(int argc, char* argv[]) { if (!showHelp) { BedSlop *bc = new BedSlop(bedFile, genomeFile, forceStrand, leftSlop, rightSlop); - bc->DetermineBedInput(); + delete bc; return 0; } diff --git a/src/sortBed/sortBed.cpp b/src/sortBed/sortBed.cpp index f61b322d..dc79612d 100755 --- a/src/sortBed/sortBed.cpp +++ b/src/sortBed/sortBed.cpp @@ -16,8 +16,10 @@ // Constructor // BedSort::BedSort(string &bedFile) { - this->bedFile = bedFile; - this->bed = new BedFile(bedFile); + _bedFile = bedFile; + _bed = new BedFile(bedFile); + + SortBed(); } // @@ -31,16 +33,16 @@ void BedSort::SortBed() { // load the "B" bed file into a map so // that we can easily compare "A" to it for overlaps - bed->loadBedFileIntoMapNoBin(); + _bed->loadBedFileIntoMapNoBin(); // loop through each chromosome and merge their BED entries - for (masterBedMapNoBin::iterator m = bed->bedMapNoBin.begin(); m != bed->bedMapNoBin.end(); ++m) { + for (masterBedMapNoBin::iterator m = _bed->bedMapNoBin.begin(); m != _bed->bedMapNoBin.end(); ++m) { // bedList is already sorted by start position. vector<BED> bedList = m->second; for (unsigned int i = 0; i < bedList.size(); ++i) { - bed->reportBedNewLine(bedList[i]); + _bed->reportBedNewLine(bedList[i]); } } } @@ -50,13 +52,13 @@ void BedSort::SortBedBySizeAsc() { // load the "B" bed file into a map so // that we can easily compare "A" to it for overlaps - bed->loadBedFileIntoMapNoBin(); + _bed->loadBedFileIntoMapNoBin(); vector<BED> masterList; masterList.reserve(1000000); // loop through each chromosome and merge their BED entries - for (masterBedMapNoBin::iterator m = bed->bedMapNoBin.begin(); m != bed->bedMapNoBin.end(); ++m) { + for (masterBedMapNoBin::iterator m = _bed->bedMapNoBin.begin(); m != _bed->bedMapNoBin.end(); ++m) { // bedList is already sorted by start position. vector<BED> bedList = m->second; @@ -72,7 +74,7 @@ void BedSort::SortBedBySizeAsc() { // report the entries in ascending order for (unsigned int i = 0; i < masterList.size(); ++i) { - bed->reportBedNewLine(masterList[i]); + _bed->reportBedNewLine(masterList[i]); } } @@ -81,13 +83,13 @@ void BedSort::SortBedBySizeDesc() { // load the "B" bed file into a map so // that we can easily compare "A" to it for overlaps - bed->loadBedFileIntoMapNoBin(); + _bed->loadBedFileIntoMapNoBin(); vector<BED> masterList; masterList.reserve(1000000); // loop through each chromosome and merge their BED entries - for (masterBedMapNoBin::iterator m = bed->bedMapNoBin.begin(); m != bed->bedMapNoBin.end(); ++m) { + for (masterBedMapNoBin::iterator m = _bed->bedMapNoBin.begin(); m != _bed->bedMapNoBin.end(); ++m) { // bedList is already sorted by start position. vector<BED> bedList = m->second; @@ -103,7 +105,7 @@ void BedSort::SortBedBySizeDesc() { // report the entries in ascending order for (unsigned int i = 0; i < masterList.size(); ++i) { - bed->reportBedNewLine(masterList[i]); + _bed->reportBedNewLine(masterList[i]); } } @@ -111,17 +113,17 @@ void BedSort::SortBedByChromThenSizeAsc() { // load the "B" bed file into a map so // that we can easily compare "A" to it for overlaps - bed->loadBedFileIntoMapNoBin(); + _bed->loadBedFileIntoMapNoBin(); // loop through each chromosome and merge their BED entries - for (masterBedMapNoBin::iterator m = bed->bedMapNoBin.begin(); m != bed->bedMapNoBin.end(); ++m) { + for (masterBedMapNoBin::iterator m = _bed->bedMapNoBin.begin(); m != _bed->bedMapNoBin.end(); ++m) { // bedList is already sorted by start position. vector<BED> bedList = m->second; sort(bedList.begin(), bedList.end(), sortBySizeAsc); for (unsigned int i = 0; i < bedList.size(); ++i) { - bed->reportBedNewLine(bedList[i]); + _bed->reportBedNewLine(bedList[i]); } } } @@ -131,10 +133,10 @@ void BedSort::SortBedByChromThenSizeDesc() { // load the "B" bed file into a map so // that we can easily compare "A" to it for overlaps - bed->loadBedFileIntoMapNoBin(); + _bed->loadBedFileIntoMapNoBin(); // loop through each chromosome and merge their BED entries - for (masterBedMapNoBin::iterator m = bed->bedMapNoBin.begin(); m != bed->bedMapNoBin.end(); ++m) { + for (masterBedMapNoBin::iterator m = _bed->bedMapNoBin.begin(); m != _bed->bedMapNoBin.end(); ++m) { // bedList is already sorted by start position. vector<BED> bedList = m->second; @@ -142,7 +144,7 @@ void BedSort::SortBedByChromThenSizeDesc() { sort(bedList.begin(), bedList.end(), sortBySizeDesc); for (unsigned int i = 0; i < bedList.size(); ++i) { - bed->reportBedNewLine(bedList[i]); + _bed->reportBedNewLine(bedList[i]); } } } @@ -152,18 +154,18 @@ void BedSort::SortBedByChromThenScoreAsc() { // load the "B" bed file into a map so // that we can easily compare "A" to it for overlaps - bed->loadBedFileIntoMapNoBin(); + _bed->loadBedFileIntoMapNoBin(); - if (bed->bedType >= 5) { + if (_bed->bedType >= 5) { // loop through each chromosome and merge their BED entries - for (masterBedMapNoBin::iterator m = bed->bedMapNoBin.begin(); m != bed->bedMapNoBin.end(); ++m) { + for (masterBedMapNoBin::iterator m = _bed->bedMapNoBin.begin(); m != _bed->bedMapNoBin.end(); ++m) { // bedList is already sorted by start position. vector<BED> bedList = m->second; sort(bedList.begin(), bedList.end(), sortByScoreAsc); for (unsigned int i = 0; i < bedList.size(); ++i) { - bed->reportBedNewLine(bedList[i]); + _bed->reportBedNewLine(bedList[i]); } } } @@ -178,18 +180,18 @@ void BedSort::SortBedByChromThenScoreDesc() { // load the "B" bed file into a map so // that we can easily compare "A" to it for overlaps - bed->loadBedFileIntoMapNoBin(); + _bed->loadBedFileIntoMapNoBin(); - if (bed->bedType >= 5) { + if (_bed->bedType >= 5) { // loop through each chromosome and merge their BED entries - for (masterBedMapNoBin::iterator m = bed->bedMapNoBin.begin(); m != bed->bedMapNoBin.end(); ++m) { + for (masterBedMapNoBin::iterator m = _bed->bedMapNoBin.begin(); m != _bed->bedMapNoBin.end(); ++m) { // bedList is already sorted by start position. vector<BED> bedList = m->second; sort(bedList.begin(), bedList.end(), sortByScoreDesc); for (unsigned int i = 0; i < bedList.size(); ++i) { - bed->reportBedNewLine(bedList[i]); + _bed->reportBedNewLine(bedList[i]); } } } diff --git a/src/sortBed/sortBed.h b/src/sortBed/sortBed.h index 48125995..4d9dd256 100755 --- a/src/sortBed/sortBed.h +++ b/src/sortBed/sortBed.h @@ -31,9 +31,6 @@ public: // destructor ~BedSort(void); - // write BED to stdout - void reportBed(const BED &); - void SortBed(); // the default. sorts by chrom (asc.) then by start (asc.) void SortBedBySizeAsc(); void SortBedBySizeDesc(); @@ -43,9 +40,11 @@ public: void SortBedByChromThenScoreDesc(); private: - string bedFile; + string _bedFile; // instance of a bed file class. - BedFile *bed; + BedFile *_bed; + + // methods }; -- GitLab