23#include "SamFileHeader.h"
25#include "GenericSamInterface.h"
27#include "SamStatistics.h"
263 bool overlap =
true);
278 bool SetReadSection(
const char* refName, int32_t start, int32_t end,
279 bool overlap =
true);
291 void SetReadFlags(uint16_t requiredFlags, uint16_t excludedFlags);
343 return(
iftell(myFilePtr));
349 if(myFilePtr != NULL)
385 bool ensureIndexedReadPosition();
393 bool checkRecordInSection(
SamRecord& record);
427 bool myOverlapSection;
431 uint64_t myCurrentChunkEnd;
439 std::string myRefName;
442 bool myAttemptRecovery;
444 uint16_t myRequiredFlags;
445 uint16_t myExcludedFlags;
449 bool attemptRecoverySync(
bool (*checkSignature)(
void *data) ,
int length);
451 void setAttemptRecovery(
bool flag =
false)
453 myAttemptRecovery = flag;
HandlingType
This specifies how this class should respond to errors.
Create/Access/Modify/Load Genome Sequences stored as binary mapped files.
Child class of SamFile for reading files.
SamFileReader()
Default Constructor.
Child class of SamFile for writing files.
SamFileWriter()
Default Constructor.
Allows the user to easily read/write a SAM/BAM file.
bool ReadHeader(SamFileHeader &header)
Reads the header section from the file and stores it in the passed in header.
bool IsOpen()
Returns whether or not the file has been opened successfully.
int32_t getNumUnMappedReadsFromIndex(int32_t refID)
Get the number of unmapped reads in the specified reference id.
void Close()
Close the file if there is one open.
void resetFile()
Resets the file prepping for a new file.
int32_t myPrevCoord
Previous values used for checking if the file is sorted.
bool myIsOpenForRead
Flag to indicate if a file is open for reading.
bool ReadBamIndex()
Read the bam index file using the BAM filename as a base.
bool SetReadSection(int32_t refID)
Sets which reference id (index into the BAM list of reference information) of the BAM file should be ...
SortedType
Enum for indicating the type of sort expected in the file.
@ UNSORTED
file is not sorted.
@ FLAG
SO flag from the header indicates the sort type.
@ QUERY_NAME
file is sorted by queryname.
@ COORDINATE
file is sorted by coordinate.
bool ReadRecord(SamFileHeader &header, SamRecord &record)
Reads the next record from the file & stores it in the passed in record.
bool IsStream()
Returns whether or not the file has been opened for streaming input/output.
void SetReadFlags(uint16_t requiredFlags, uint16_t excludedFlags)
Specify which reads should be returned by ReadRecord.
void SetReference(GenomeSequence *reference)
Sets the reference to the specified genome sequence object.
OpenType
Enum for indicating whether to open the file for read or write.
void GenerateStatistics(bool genStats)
Whether or not statistics should be generated for this file.
const BamIndex * GetBamIndex()
Return the bam index if one has been opened.
void PrintStatistics()
Print the statistics that have been recorded due to a call to GenerateStatistics.
uint32_t GetNumOverlaps(SamRecord &samRecord)
Returns the number of bases in the passed in read that overlap the region that is currently set.
bool OpenForRead(const char *filename, SamFileHeader *header=NULL)
Open a sam/bam file for reading with the specified filename, determing the type of file and SAM/BAM b...
bool IsEOF()
Returns whether or not the end of the file has been reached.
int32_t getNumMappedReadsFromIndex(int32_t refID)
Get the number of mapped reads in the specified reference id.
SamStatus::Status GetStatus()
Get the Status of the last call that sets status.
int64_t GetCurrentPosition()
Get the current file position.
SamStatus::Status GetFailure()
Deprecated, get the Status of the last call that sets status.
bool OpenForWrite(const char *filename, SamFileHeader *header=NULL)
Open a sam/bam file for writing with the specified filename, determining SAM/BAM from the extension (...
bool WriteHeader(SamFileHeader &header)
Writes the specified header into the file.
bool myIsOpenForWrite
Flag to indicate if a file is open for writing.
void DisableBuffering()
Turn off file read buffering.
bool myIsBamOpenForRead
Values for reading Sorted BAM files via the index.
bool myHasHeader
Flag to indicate if a header has been read/written - required before being able to read/write a recor...
virtual ~SamFile()
Destructor.
SamFile()
Default Constructor, initializes the variables, but does not open any files.
void SetWriteSequenceTranslation(SamRecord::SequenceTranslation translation)
Set the type of sequence translation to use when writing the sequence.
void SetReadSequenceTranslation(SamRecord::SequenceTranslation translation)
Set the type of sequence translation to use when reading the sequence.
bool validateSortOrder(SamRecord &record, SamFileHeader &header)
Validate that the record is sorted compared to the previously read record if there is one,...
bool WriteRecord(SamFileHeader &header, SamRecord &record)
Writes the specified record into the file.
uint32_t myRecordCount
Keep a count of the number of records that have been read/written so far.
SamStatus myStatus
The status of the last SamFile command.
const char * GetStatusMessage()
Get the Status Message of the last call that sets status.
uint32_t GetCurrentRecordCount()
Return the number of records that have been read/written so far.
void setSortedValidation(SortedType sortType)
Set the flag to validate that the file is sorted as it is read/written.
SamStatistics * myStatistics
Pointer to the statistics for this file.
Class providing an easy to use interface to get/set/operate on the fields in a SAM/BAM record.
SequenceTranslation
Enum containing the settings on how to translate the sequence if a reference is available.
This class is used to track the status results of some methods in the BAM classes.
const char * getStatusMessage() const
Return the status message for this object.
Status
Return value enum for StatGenFile methods.
Status getStatus() const
Return the enum for this status object.