| 0 | 1 /***************************************************************************** | 
|  | 2   intersectBed.h | 
|  | 3 | 
|  | 4   (c) 2009 - Aaron Quinlan | 
|  | 5   Hall Laboratory | 
|  | 6   Department of Biochemistry and Molecular Genetics | 
|  | 7   University of Virginia | 
|  | 8   aaronquinlan@gmail.com | 
|  | 9 | 
|  | 10   Licenced under the GNU General Public License 2.0 license. | 
|  | 11 ******************************************************************************/ | 
|  | 12 #ifndef INTERSECTBED_H | 
|  | 13 #define INTERSECTBED_H | 
|  | 14 | 
|  | 15 #include "bedFile.h" | 
|  | 16 // #include "BamReader.h" | 
|  | 17 // #include "BamWriter.h" | 
|  | 18 // #include "BamAncillary.h" | 
|  | 19 // #include "BamAux.h" | 
|  | 20 // using namespace BamTools; | 
|  | 21 | 
|  | 22 | 
|  | 23 #include <vector> | 
|  | 24 #include <queue> | 
|  | 25 #include <iostream> | 
|  | 26 #include <fstream> | 
|  | 27 #include <stdlib.h> | 
|  | 28 using namespace std; | 
|  | 29 | 
|  | 30 | 
|  | 31 | 
|  | 32 class BedIntersect { | 
|  | 33 | 
|  | 34 public: | 
|  | 35 | 
|  | 36     // constructor | 
|  | 37     BedIntersect(string bedAFile, string bedBFile, bool anyHit, | 
|  | 38                                bool writeA, bool writeB, bool writeOverlap, bool writeAllOverlap, | 
|  | 39                                float overlapFraction, bool noHit, bool writeCount, bool forceStrand, | 
|  | 40                                bool reciprocal, bool obeySplits, bool bamInput, bool bamOutput); | 
|  | 41 | 
|  | 42     // destructor | 
|  | 43     ~BedIntersect(void); | 
|  | 44 | 
|  | 45 private: | 
|  | 46 | 
|  | 47     //------------------------------------------------ | 
|  | 48     // private attributes | 
|  | 49     //------------------------------------------------ | 
|  | 50     string _bedAFile; | 
|  | 51     string _bedBFile; | 
|  | 52 | 
|  | 53     bool  _writeA;            // should the original A feature be reported? | 
|  | 54     bool  _writeB;            // should the original B feature be reported? | 
|  | 55     bool  _writeOverlap; | 
|  | 56     bool  _writeAllOverlap; | 
|  | 57 | 
|  | 58     bool  _forceStrand; | 
|  | 59     bool  _reciprocal; | 
|  | 60     float _overlapFraction; | 
|  | 61 | 
|  | 62     bool  _anyHit; | 
|  | 63     bool  _noHit; | 
|  | 64     bool  _writeCount;        // do we want a count of the number of overlaps in B? | 
|  | 65     bool  _obeySplits; | 
|  | 66     bool  _bamInput; | 
|  | 67     bool  _bamOutput; | 
|  | 68 | 
|  | 69     bool _printable; | 
|  | 70 | 
|  | 71     queue<BED*> _outputBuffer; | 
|  | 72     bool  _lastPick; | 
|  | 73 | 
|  | 74     map<string, vector<BED*> > _windowA; | 
|  | 75     map<string, vector<BED*> > _windowB; | 
|  | 76 | 
|  | 77     // instance of a bed file class. | 
|  | 78     BedFile *_bedA, *_bedB; | 
|  | 79 | 
|  | 80     //------------------------------------------------ | 
|  | 81     // private methods | 
|  | 82     //------------------------------------------------ | 
|  | 83     void IntersectBed(istream &bedInput); | 
|  | 84 | 
|  | 85     void Scan(BED *x, vector<BED *> *windowX, BedLineStatus xStatus, | 
|  | 86         const BED &y, vector<BED *> *windowY, BedLineStatus yStatus); | 
|  | 87 | 
|  | 88     void AddHits(BED *x, const BED &y); | 
|  | 89 | 
|  | 90     void FlushOutputBuffer(bool final = false); | 
|  | 91 | 
|  | 92     vector<BED*>* GetWindow(const string &chrom, bool isA); | 
|  | 93 | 
|  | 94     void ChromSwitch(const string &chrom); | 
|  | 95 | 
|  | 96     void IntersectBed(); | 
|  | 97 | 
|  | 98     void IntersectBam(string bamFile); | 
|  | 99 | 
|  | 100     bool processHits(BED &a, vector<BED> &hits); | 
|  | 101 | 
|  | 102     bool FindOverlaps(const BED &a, vector<BED> &hits); | 
|  | 103 | 
|  | 104     bool FindOneOrMoreOverlap(const BED &a); | 
|  | 105 | 
|  | 106     void ReportOverlapDetail(const int &overlapBases, const BED &a, const BED &b, | 
|  | 107                              const CHRPOS &s, const CHRPOS &e); | 
|  | 108     void ReportOverlapSummary(const BED &a, const int &numOverlapsFound); | 
|  | 109 | 
|  | 110     void ReportHits(set<BED> &A, set<BED> &B); | 
|  | 111 | 
|  | 112 }; | 
|  | 113 | 
|  | 114 #endif /* INTERSECTBED_H */ |