BamReader.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // ***************************************************************************
  2. // BamReader.h (c) 2009 Derek Barnett, Michael Strömberg
  3. // Marth Lab, Department of Biology, Boston College
  4. // All rights reserved.
  5. // ---------------------------------------------------------------------------
  6. // Last modified: 8 December 2009 (DB)
  7. // ---------------------------------------------------------------------------
  8. // Uses BGZF routines were adapted from the bgzf.c code developed at the Broad
  9. // Institute.
  10. // ---------------------------------------------------------------------------
  11. // Provides the basic functionality for reading BAM files
  12. // ***************************************************************************
  13. #ifndef BAMREADER_H
  14. #define BAMREADER_H
  15. // C++ includes
  16. #include <string>
  17. // BamTools includes
  18. #include "BamAux.h"
  19. namespace BamTools {
  20. class BamReader {
  21. // constructor / destructor
  22. public:
  23. BamReader(void);
  24. ~BamReader(void);
  25. // public interface
  26. public:
  27. // ----------------------
  28. // BAM file operations
  29. // ----------------------
  30. // close BAM file
  31. void Close(void);
  32. // performs random-access jump to reference, position
  33. bool Jump(int refID, int position = 0);
  34. // opens BAM file (and optional BAM index file, if provided)
  35. void Open(const std::string& filename, const std::string& indexFilename = "");
  36. // returns file pointer to beginning of alignments
  37. bool Rewind(void);
  38. // ----------------------
  39. // access alignment data
  40. // ----------------------
  41. // retrieves next available alignment (returns success/fail)
  42. bool GetNextAlignment(BamAlignment& bAlignment);
  43. // ----------------------
  44. // access auxiliary data
  45. // ----------------------
  46. // returns SAM header text
  47. const std::string GetHeaderText(void) const;
  48. // returns number of reference sequences
  49. const int GetReferenceCount(void) const;
  50. // returns vector of reference objects
  51. const BamTools::RefVector GetReferenceData(void) const;
  52. // returns reference id (used for BamReader::Jump()) for the given reference name
  53. const int GetReferenceID(const std::string& refName) const;
  54. // ----------------------
  55. // BAM index operations
  56. // ----------------------
  57. // creates index for BAM file, saves to file (default = bamFilename + ".bai")
  58. bool CreateIndex(void);
  59. // private implementation
  60. private:
  61. struct BamReaderPrivate;
  62. BamReaderPrivate* d;
  63. };
  64. } // namespace BamTools
  65. #endif // BAMREADER_H