BamReader.h

Go to the documentation of this file.
00001 // ***************************************************************************
00002 // BamReader.h (c) 2009 Derek Barnett, Michael Str�mberg
00003 // Marth Lab, Department of Biology, Boston College
00004 // ---------------------------------------------------------------------------
00005 // Last modified: 10 October 2011 (DB)
00006 // ---------------------------------------------------------------------------
00007 // Provides read access to BAM files.
00008 // ***************************************************************************
00009 
00010 #ifndef BAMREADER_H
00011 #define BAMREADER_H
00012 
00013 #include "api/api_global.h"
00014 #include "api/BamAlignment.h"
00015 #include "api/BamIndex.h"
00016 #include "api/SamHeader.h"
00017 #include <string>
00018 
00019 namespace BamTools {
00020   
00021 namespace Internal {
00022     class BamReaderPrivate;
00023 } // namespace Internal
00024 
00025 class API_EXPORT BamReader {
00026 
00027     // constructor / destructor
00028     public:
00029         BamReader(void);
00030         ~BamReader(void);
00031 
00032     // public interface
00033     public:
00034 
00035         // ----------------------
00036         // BAM file operations
00037         // ----------------------
00038 
00039         // closes the current BAM file
00040         bool Close(void);
00041         // returns filename of current BAM file
00042         const std::string GetFilename(void) const;
00043         // returns true if a BAM file is open for reading
00044         bool IsOpen(void) const;
00045         // performs random-access jump within BAM file
00046         bool Jump(int refID, int position = 0);
00047         // opens a BAM file
00048         bool Open(const std::string& filename);
00049         // returns internal file pointer to beginning of alignment data
00050         bool Rewind(void);
00051         // sets the target region of interest
00052         bool SetRegion(const BamRegion& region);
00053         // sets the target region of interest
00054         bool SetRegion(const int& leftRefID,
00055                        const int& leftPosition,
00056                        const int& rightRefID,
00057                        const int& rightPosition);
00058 
00059         // ----------------------
00060         // access alignment data
00061         // ----------------------
00062 
00063         // retrieves next available alignment
00064         bool GetNextAlignment(BamAlignment& alignment);
00065         // retrieves next available alignmnet (without populating the alignment's string data fields)
00066         bool GetNextAlignmentCore(BamAlignment& alignment);
00067 
00068         // ----------------------
00069         // access header data
00070         // ----------------------
00071 
00072         // returns SAM header data
00073         SamHeader GetHeader(void) const;
00074         // returns SAM header data, as SAM-formatted text
00075         std::string GetHeaderText(void) const;
00076 
00077         // ----------------------
00078         // access reference data
00079         // ----------------------
00080 
00081         // returns the number of reference sequences
00082         int GetReferenceCount(void) const;
00083         // returns all reference sequence entries
00084         const RefVector& GetReferenceData(void) const;
00085         // returns the ID of the reference with this name
00086         int GetReferenceID(const std::string& refName) const;
00087 
00088         // ----------------------
00089         // BAM index operations
00090         // ----------------------
00091 
00092         // creates an index file for current BAM file, using the requested index type
00093         bool CreateIndex(const BamIndex::IndexType& type = BamIndex::STANDARD);
00094         // returns true if index data is available
00095         bool HasIndex(void) const;
00096         // looks in BAM file's directory for a matching index file
00097         bool LocateIndex(const BamIndex::IndexType& preferredType = BamIndex::STANDARD);
00098         // opens a BAM index file
00099         bool OpenIndex(const std::string& indexFilename);
00100         // sets a custom BamIndex on this reader
00101         void SetIndex(BamIndex* index);
00102 
00103         // ----------------------
00104         // error handling
00105         // ----------------------
00106 
00107         // returns a human-readable description of the last error that occurred
00108         std::string GetErrorString(void) const;
00109         
00110     // private implementation
00111     private:
00112         Internal::BamReaderPrivate* d;
00113 };
00114 
00115 } // namespace BamTools
00116 
00117 #endif // BAMREADER_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Wed Aug 29 17:43:46 2012 for BamTools by  doxygen 1.6.3