1 /* 2 * BamFileReader.h 3 * 4 * Created on: Dec 4, 2012 5 * Author: nek3d 6 */ 7 8 #ifndef BAMFILEREADER_H_ 9 #define BAMFILEREADER_H_ 10 11 #include "FileReader.h" 12 #include "string.h" 13 #include "api/BamReader.h" 14 #include "api/BamAux.h" 15 16 class BamFileReader : public FileReader { 17 public: 18 BamFileReader(); 19 virtual ~BamFileReader(); 20 virtual bool open(); //open the file 21 virtual bool isOpen() const; 22 virtual void close(); eof()23 virtual bool eof() const { 24 return _eof; 25 } 26 27 //setUseTags will tell the BamReader to give us all 28 //the extra tag information in a BAM record. By default, 29 //this is set to false, so not using them, which reduces 30 //the run time of reading a BAM file by more than half. setUseTags(bool flag)31 virtual void setUseTags(bool flag) { _useTags = flag; } setBamReader(BamTools::BamReader * bamReader)32 void setBamReader(BamTools::BamReader *bamReader) { _bamReader = bamReader; } 33 virtual bool readEntry(); 34 hasHeader()35 virtual bool hasHeader() const { return _bamReader->IsOpen(); } //any open Bam file automatically has a header getHeader()36 virtual const string &getHeader() const { return _bamHeader; } getReferences()37 const BamTools::RefVector &getReferences() const { return _references; } 38 getAlignment()39 const BamTools::BamAlignment &getAlignment() const { return _bamAlignment; } 40 41 42 void getChrName(string &) const; 43 int getBamChrId() const; 44 int getStartPos() const; 45 int getEndPos() const; 46 void getName(string &) const; 47 void getScore(string &) const; 48 char getStrand() const; 49 void getMateChrName(string &str) const; getNumFields()50 virtual int getNumFields() const { return MINIMUM_VALID_BAM_FIELDS; } 51 getCramRefs()52 refs_t* getCramRefs() { return _bamReader->GetReference(); } 53 54 protected: 55 56 BamTools::BamReader *_bamReader; 57 BamTools::BamAlignment _bamAlignment; 58 bool _eof; 59 string _bamHeader; 60 BamTools::RefVector _references; 61 bool _useTags; 62 63 static const int MINIMUM_PRINTABLE_BAM_FIELDS = 6; 64 static const int MINIMUM_VALID_BAM_FIELDS = 11; 65 void extractNameFromCore(); 66 }; 67 68 69 #endif /* BAMFILEREADER_H_ */ 70