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