libStatGen Software  1
SamFile.h
1 /*
2  * Copyright (C) 2010 Regents of the University of Michigan
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef __SAM_FILE_H__
19 #define __SAM_FILE_H__
20 
21 #include "SamStatus.h"
22 #include "InputFile.h"
23 #include "SamFileHeader.h"
24 #include "SamRecord.h"
25 #include "GenericSamInterface.h"
26 #include "BamIndex.h"
27 #include "SamStatistics.h"
28 
29 /// Allows the user to easily read/write a SAM/BAM file.
30 /// The SamFile class contains additional functionality that allows a user
31 /// to read specific sections of sorted & indexed BAM files. In order to
32 /// take advantage of this capability, the index file must be read prior to
33 /// setting the read section. This logic saves the time of having to read
34 /// the entire file and takes advantage of the seeking capability of BGZF.
35 class SamFile
36 {
37 public:
38  /// Enum for indicating whether to open the file for read or write.
39  enum OpenType {
40  READ, ///< open for reading.
41  WRITE ///< open for writing.
42  };
43 
44 
45  /// Enum for indicating the type of sort expected in the file.
46  enum SortedType {
47  UNSORTED = 0, ///< file is not sorted.
48  FLAG, ///< SO flag from the header indicates the sort type.
49  COORDINATE, ///< file is sorted by coordinate.
50  QUERY_NAME ///< file is sorted by queryname.
51  };
52 
53  /// Default Constructor, initializes the variables, but does not open
54  /// any files.
55  SamFile();
56 
57  /// Constructor that sets the error handling type.
58  /// \param errorHandlingType how to handle errors.
59  SamFile(ErrorHandler::HandlingType errorHandlingType);
60 
61  /// Constructor that opens the specified file based on the specified mode
62  /// (READ/WRITE), aborts if the file could not be opened.
63  /// \param filename name of the file to open.
64  /// \param mode mode to use for opening the file.
65  SamFile(const char* filename, OpenType mode);
66 
67  /// Constructor that opens the specified file based on the specified mode
68  /// (READ/WRITE) and handles errors per the specified handleType.
69  /// \param filename name of the file to open.
70  /// \param mode mode to use for opening the file.
71  /// \param errorHandlingType how to handle errors.
72  SamFile(const char* filename, OpenType mode,
73  ErrorHandler::HandlingType errorHandlingType);
74 
75  /// Constructor that opens the specified file based on the specified mode
76  /// (READ/WRITE) and reads the header, aborts if the file could not be
77  /// opened or the header not read.
78  /// \param filename name of the file to open.
79  /// \param mode mode to use for opening the file.
80  /// \param header to read into or write from
81  SamFile(const char* filename, OpenType mode, SamFileHeader* header);
82 
83  /// Constructor that opens the specified file based on the specified mode
84  /// (READ/WRITE) and reads the header, handling errors per the specified
85  /// handleType.
86  /// \param filename name of the file to open.
87  /// \param mode mode to use for opening the file.
88  /// \param errorHandlingType how to handle errors.
89  /// \param header to read into or write from
90  SamFile(const char* filename, OpenType mode,
91  ErrorHandler::HandlingType errorHandlingType,
92  SamFileHeader* header);
93 
94  /// Destructor
95  virtual ~SamFile();
96 
97  /// Open a sam/bam file for reading with the specified filename,
98  /// determing the type of file and SAM/BAM by reading the file
99  /// (if not stdin).
100  /// \param filename the sam/bam file to open for reading.
101  /// \param header to read into or write from (optional)
102  /// \return true = success; false = failure.
103  bool OpenForRead(const char * filename, SamFileHeader* header = NULL);
104 
105  /// Open a sam/bam file for writing with the specified filename,
106  /// determining SAM/BAM from the extension (.bam = BAM).
107  /// \param filename the sam/bam file to open for writing.
108  /// \param header to read into or write from (optional)
109  /// \return true = success; false = failure.
110  bool OpenForWrite(const char * filename, SamFileHeader* header = NULL);
111 
112  /// Read the specified bam index file. It must be read prior to setting a
113  /// read section, for seeking and reading portions of a bam file.
114  /// \param filename the name of the bam index file to be read.
115  /// \return true = success; false = failure.
116  bool ReadBamIndex(const char * filename);
117 
118  /// Read the bam index file using the BAM filename as a base.
119  /// It must be read prior to setting a read section, for seeking
120  /// and reading portions of a bam file.
121  /// Must be read after opening the BAM file since it uses the
122  /// BAM filename as a base name for the index file.
123  /// First it tries filename.bam.bai. If that fails, it tries
124  /// it without the .bam extension, filename.bai.
125  /// \return true = success; false = failure.
126  bool ReadBamIndex();
127 
128  /// Sets the reference to the specified genome sequence object.
129  /// \param reference pointer to the GenomeSequence object.
130  void SetReference(GenomeSequence* reference);
131 
132  /// Set the type of sequence translation to use when reading
133  /// the sequence. Passed down to the SamRecord when it is read.
134  /// The default type (if this method is never called) is
135  /// NONE (the sequence is left as-is).
136  /// \param translation type of sequence translation to use.
138 
139  /// Set the type of sequence translation to use when writing
140  /// the sequence. Passed down to the SamRecord when it is written.
141  /// The default type (if this method is never called) is
142  /// NONE (the sequence is left as-is).
143  /// \param translation type of sequence translation to use.
145 
146  /// Close the file if there is one open.
147  void Close();
148 
149  /// Returns whether or not the file has been opened successfully.
150  /// \return true = open; false = not open.
151  bool IsOpen();
152 
153  /// Returns whether or not the end of the file has been reached.
154  /// \return true = EOF; false = not eof.
155  /// If the file is not open, true is returned.
156  bool IsEOF();
157 
158  /// Reads the header section from the file and stores it in
159  /// the passed in header.
160  /// \return true = success; false = failure.
161  bool ReadHeader(SamFileHeader& header);
162 
163  /// Writes the specified header into the file.
164  /// \return true = success; false = failure.
165  bool WriteHeader(SamFileHeader& header);
166 
167  /// Reads the next record from the file & stores it in the passed in record.
168  ///
169  /// If it is an indexed BAM file and SetReadSection was called,
170  /// only alignments in the section specified by SetReadSection are read.
171  /// If they all have already been read, this method returns false.
172  ///
173  /// Validates that the record is sorted according to the value set by
174  /// setSortedValidation. No sorting validation is done if specified to be
175  /// unsorted, or setSortedValidation was never called.
176  /// \return true = record was successfully set (and sorted if applicable),
177  /// false = record was not successfully set
178  /// (or not sorted as expected).
179  bool ReadRecord(SamFileHeader& header, SamRecord& record);
180 
181  /// Writes the specified record into the file.
182  /// Validates that the record is sorted according to the value set by
183  /// setSortedValidation. No sorting validation is done if specified to
184  /// be unsorted, or setSortedValidation was never called. Returns false
185  /// and does not write the record if the record was not properly sorted.
186  /// \return true = success; false = failure.
187  bool WriteRecord(SamFileHeader& header, SamRecord& record);
188 
189  /// Set the flag to validate that the file is sorted as it is read/written.
190  /// Must be called after the file has been opened.
191  /// Sorting validation is reset everytime SetReadPosition is called since
192  /// it can jump around in the file.
193  /// \param sortType specifies the type of sort to be checked for.
194  void setSortedValidation(SortedType sortType);
195 
196  /// Return the number of records that have been read/written so far.
197  uint32_t GetCurrentRecordCount();
198 
199  /// Deprecated, get the Status of the last call that sets status.
200  /// To remain backwards compatable - will be removed later.
202  {
203  return(GetStatus());
204  }
205 
206  /// Get the Status of the last call that sets status.
208  {
209  return(myStatus.getStatus());
210  }
211 
212  /// Get the Status Message of the last call that sets status.
213  inline const char* GetStatusMessage()
214  {
215  return(myStatus.getStatusMessage());
216  }
217 
218  /// Sets which reference id (index into the BAM list of reference
219  /// information) of the BAM file should be read. The records
220  /// for that reference id will be retrieved on each ReadRecord call.
221  /// Reference ids start at 0, and -1 indicates reads with no reference.
222  /// When all records have been retrieved for the specified reference id,
223  /// ReadRecord will return failure until a new read section is set.
224  /// Must be called only after the file has been opened for reading.
225  /// Sorting validation is reset everytime SetReadPosition is called since
226  /// it can jump around in the file.
227  /// \param refID the reference ID of the records to read from the file.
228  /// \return true = success; false = failure.
229  bool SetReadSection(int32_t refID);
230 
231  /// Sets which reference name of the BAM file should be read. The records
232  /// for that reference name will be retrieved on each ReadRecord call.
233  /// Specify "" or "*" to read records not associated with a reference.
234  /// When all records have been retrieved for the specified reference name,
235  /// ReadRecord will return failure until a new read section is set.
236  /// Must be called only after the file has been opened for reading.
237  /// Sorting validation is reset everytime SetReadPosition is called since
238  /// it can jump around in the file.
239  /// \param refName the reference name of the records to read from the file.
240  /// \return true = success; false = failure.
241  bool SetReadSection(const char* refName);
242 
243  /// Sets which reference id (index into the BAM list of reference
244  /// information) & start/end positions of the BAM file should be read.
245  /// The records for that reference id and positions will be retrieved on
246  /// each ReadRecord call. Reference ids start at 0, and -1 indicates
247  /// reads with no reference. When all records have been retrieved for the
248  /// specified reference id, ReadRecord will return failure until a new read
249  /// section is set. Must be called only after the file has been opened
250  /// for reading. Sorting validation is reset everytime SetReadPosition is
251  /// called since it can jump around in the file.
252  /// \param refID the reference ID of the records to read from the file.
253  /// \param start inclusive 0-based start position of records that should be read for this refID.
254  /// \param end exclusive 0-based end position of records that should be read for this refID.
255  /// \param overlap When true (default), return reads that just overlap the region; when false, only return reads that fall completely within the region
256  /// \return true = success; false = failure.
257  bool SetReadSection(int32_t refID, int32_t start, int32_t end,
258  bool overlap = true);
259 
260  /// Sets which reference name & start/end positions of the BAM file should
261  /// be read. The records for this reference name & positions will be
262  /// retrieved on each ReadRecord call. Specify "" or "*" to indicate
263  /// reads with no reference. When all records have been retrieved for
264  /// the specified section, ReadRecord will return failure until a new read
265  /// section is set. Must be called only after the file has been opened for
266  /// reading. Sorting validation is reset everytime SetReadSection is
267  /// called since it can jump around in the file.
268  /// \param refName the reference name of the records to read from the file.
269  /// \param start inclusive 0-based start position of records that should be read for this refID.
270  /// \param end exclusive 0-based end position of records that should be read for this refID.
271  /// \param overlap When true (default), return reads that just overlap the region; when false, only return reads that fall completely within the region
272  /// \return true = success; false = failure.
273  bool SetReadSection(const char* refName, int32_t start, int32_t end,
274  bool overlap = true);
275 
276  /// Specify which reads should be returned by ReadRecord.
277  /// Reads will only be returned by ReadRecord that contain the specified
278  /// required flags and that do not contain any of the specified excluded
279  /// flags. ReadRecord will continue to read from the file until a record
280  /// that complies with these flag settings is found or until the end of the
281  /// file/region.
282  /// \param requiredFlags flags that are required to be in records
283  /// returned by ReadRecord (set to 0x0 if there are no required flags).
284  /// \param excludedFlags flags that are required to not be in records
285  /// returned by ReadRecord (set to 0x0 if there are no excluded flags).
286  void SetReadFlags(uint16_t requiredFlags, uint16_t excludedFlags);
287 
288  /// Get the number of mapped reads in the specified reference id.
289  /// Returns -1 for out of range refIDs.
290  /// \param refID reference ID for which to extract the number of mapped reads.
291  /// \return number of mapped reads for the specified reference id.
292  int32_t getNumMappedReadsFromIndex(int32_t refID);
293 
294  /// Get the number of unmapped reads in the specified reference id.
295  /// Returns -1 for out of range refIDs.
296  /// \param refID reference ID for which to extract the number of unmapped reads.
297  /// \return number of unmapped reads for the specified reference id.
298  int32_t getNumUnMappedReadsFromIndex(int32_t refID);
299 
300  /// Get the number of mapped reads in the specified reference name.
301  /// Returns -1 for unknown reference names.
302  /// \param refName reference name for which to extract the number of mapped reads.
303  /// \param header header object containing the map from refName to refID
304  /// \return number of mapped reads for the specified reference name.
305  int32_t getNumMappedReadsFromIndex(const char* refName,
306  SamFileHeader& header);
307 
308  /// Get the number of unmapped reads in the specified reference name.
309  /// Returns -1 for unknown reference names.
310  /// \param refName reference name for which to extract the number of unmapped reads.
311  /// \param header header object containing the map from refName to refID
312  /// \return number of unmapped reads for the specified reference name.
313  int32_t getNumUnMappedReadsFromIndex(const char* refName,
314  SamFileHeader& header);
315 
316  /// Returns the number of bases in the passed in read that overlap the
317  /// region that is currently set. Overlapping means that the bases occur
318  /// in both the read and the reference as either matches or mismatches.
319  /// This does not count insertions, deletions, clips, pads, or skips.
320  /// \param samRecord to check for overlapping bases.
321  /// \return number of bases that overlap region that is currently set.
322  uint32_t GetNumOverlaps(SamRecord& samRecord);
323 
324  /// Whether or not statistics should be generated for this file.
325  /// The value is carried over between files and is not reset, but
326  /// the statistics themselves are reset between files.
327  /// \param genStats set to true if statistics should be generated, false if not.
328  void GenerateStatistics(bool genStats);
329 
330  /// Return the bam index if one has been opened.
331  /// \return const pointer to the bam index, or null if one has not been opened.
332  const BamIndex* GetBamIndex();
333 
334  /// Get the current file position.
335  /// \return current position in the file.
336  inline int64_t GetCurrentPosition()
337  {
338  return(iftell(myFilePtr));
339  }
340 
341  /// Turn off file read buffering.
342  inline void DisableBuffering()
343  {
344  if(myFilePtr != NULL)
345  {
346  myFilePtr->disableBuffering();
347  }
348  }
349 
350  /// Print the statistics that have been recorded due to a call to
351  /// GenerateStatistics.
352  inline void PrintStatistics() {if(myStatistics != NULL) myStatistics->print();}
353 
354 protected:
355  void init();
356  void init(const char* filename, OpenType mode, SamFileHeader* header);
357 
358  /// Resets the file prepping for a new file.
359  void resetFile();
360 
361  /// Validate that the record is sorted compared to the previously read
362  /// record if there is one, according to the specified sort order.
363  /// If the sort order is UNSORTED, true is returned.
364  /// Sorting validation is reset everytime SetReadPosition is called since
365  /// it can jump around in the file.
366  bool validateSortOrder(SamRecord& record, SamFileHeader& header);
367 
368  // Return the sort order as defined by the header. If it is undefined
369  // or set to an unknown value, UNSORTED is returned.
370  SortedType getSortOrderFromHeader(SamFileHeader& header);
371 
372  bool processNewSection(SamFileHeader &header);
373 
374  // Check if there is more to read in the current chunk, if not,
375  // move to the next chunk.
376  // If no sections are specified or it successfully found a chunk to read,
377  // return true.
378  // Sets the status and returns false if it was unable to move to a new chunk
379  // or there are no more chunks to read, otherwise returns true.
380  bool ensureIndexedReadPosition();
381 
382  // Check whether or not the record falls within the specified section.
383  // If no sections are specified or this read falls within the
384  // specified sections, return true.
385  // If it does not, return false.
386  // If the record position indicates there will be no more records within the
387  // region, return false AND set the sam status to indicate NO_MORE_RECS.
388  bool checkRecordInSection(SamRecord& record);
389 
390  IFILE myFilePtr;
391  GenericSamInterface* myInterfacePtr;
392 
393  /// Flag to indicate if a file is open for reading.
395  /// Flag to indicate if a file is open for writing.
397  /// Flag to indicate if a header has been read/written - required before
398  /// being able to read/write a record.
400 
401  SortedType mySortedType;
402 
403  /// Previous values used for checking if the file is sorted.
404  int32_t myPrevCoord;
405  int32_t myPrevRefID;
406  String myPrevReadName;
407 
408  /// Keep a count of the number of records that have been read/written so far.
409  uint32_t myRecordCount;
410 
411  /// Pointer to the statistics for this file.
413 
414  /// The status of the last SamFile command.
416 
417  /// Values for reading Sorted BAM files via the index.
419  bool myNewSection;
420  // whether to return reads that overlap (true) the section or
421  // are fully enclosed (false) in the section.
422  bool myOverlapSection;
423  int32_t myRefID;
424  int32_t myStartPos;
425  int32_t myEndPos;
426  uint64_t myCurrentChunkEnd;
427  SortedChunkList myChunksToRead;
428  BamIndex* myBamIndex;
429 
430  GenomeSequence* myRefPtr;
431  SamRecord::SequenceTranslation myReadTranslation;
432  SamRecord::SequenceTranslation myWriteTranslation;
433 
434  std::string myRefName;
435 
436 private:
437  bool myAttemptRecovery;
438 
439  uint16_t myRequiredFlags;
440  uint16_t myExcludedFlags;
441 
442 public:
443 
444  bool attemptRecoverySync(bool (*checkSignature)(void *data) , int length);
445 
446  void setAttemptRecovery(bool flag = false)
447  {
448  myAttemptRecovery = flag;
449  }
450 
451 };
452 
453 
454 /// Child class of SamFile for reading files.
455 class SamFileReader : public SamFile
456 {
457 public:
458 
459  /// Default Constructor.
460  SamFileReader();
461 
462  /// Constructor that opens the specified file for read.
463  SamFileReader(const char* filename);
464 
465  /// Constructor that opens the specified file for read.
466  SamFileReader(const char* filename,
467  ErrorHandler::HandlingType errorHandlingType);
468 
469  /// Constructor that opens the specified file for read and reads
470  /// the header from the file.
471  SamFileReader(const char* filename,
472  SamFileHeader* header);
473 
474  /// Constructor that opens the specified file for read and reads
475  /// the header from the file.
476  SamFileReader(const char* filename,
477  ErrorHandler::HandlingType errorHandlingType,
478  SamFileHeader* header);
479 
480  virtual ~SamFileReader();
481 };
482 
483 
484 /// Child class of SamFile for writing files.
485 class SamFileWriter : public SamFile
486 {
487 public:
488  /// Default Constructor.
489  SamFileWriter();
490 
491  /// Constructor that opens the specified file for write.
492  SamFileWriter(const char* filename);
493 
494  /// Constructor that opens the specified file for write.
495  SamFileWriter(const char* filename,
496  ErrorHandler::HandlingType errorHandlingType);
497 
498  /// Constructor that opens the specified file for write and write
499  /// the specified header into the file.
500  SamFileWriter(const char* filename,
501  SamFileHeader* header);
502 
503  /// Constructor that opens the specified file for write and write
504  /// the specified header into the file.
505  SamFileWriter(const char* filename,
506  ErrorHandler::HandlingType errorHandlingType,
507  SamFileHeader* header);
508 
509  virtual ~SamFileWriter();
510 };
511 
512 #endif
SamFile::myIsOpenForWrite
bool myIsOpenForWrite
Flag to indicate if a file is open for writing.
Definition: SamFile.h:396
SamFile::COORDINATE
@ COORDINATE
file is sorted by coordinate.
Definition: SamFile.h:49
SortedChunkList
Definition: IndexBase.h:49
BamIndex
Definition: BamIndex.h:32
SamFile::FLAG
@ FLAG
SO flag from the header indicates the sort type.
Definition: SamFile.h:48
SamFile::IsEOF
bool IsEOF()
Returns whether or not the end of the file has been reached.
Definition: SamFile.cpp:424
SamRecord::SequenceTranslation
SequenceTranslation
Enum containing the settings on how to translate the sequence if a reference is available.
Definition: SamRecord.h:57
SamFile::ReadBamIndex
bool ReadBamIndex()
Read the bam index file using the BAM filename as a base.
Definition: SamFile.cpp:328
SamFile::myPrevCoord
int32_t myPrevCoord
Previous values used for checking if the file is sorted.
Definition: SamFile.h:404
SamFile::WriteRecord
bool WriteRecord(SamFileHeader &header, SamRecord &record)
Writes the specified record into the file.
Definition: SamFile.cpp:619
String
Definition: StringBasics.h:39
SamFile::READ
@ READ
open for reading.
Definition: SamFile.h:40
SamFile::GetStatusMessage
const char * GetStatusMessage()
Get the Status Message of the last call that sets status.
Definition: SamFile.h:213
SamFile::myIsOpenForRead
bool myIsOpenForRead
Flag to indicate if a file is open for reading.
Definition: SamFile.h:394
SamFile::resetFile
void resetFile()
Resets the file prepping for a new file.
Definition: SamFile.cpp:953
SamFile::GetStatus
SamStatus::Status GetStatus()
Get the Status of the last call that sets status.
Definition: SamFile.h:207
SamFile::getNumUnMappedReadsFromIndex
int32_t getNumUnMappedReadsFromIndex(int32_t refID)
Get the number of unmapped reads in the specified reference id.
Definition: SamFile.cpp:805
GenomeSequence
Create/Access/Modify/Load Genome Sequences stored as binary mapped files.
Definition: GenomeSequence.h:100
SamFile::PrintStatistics
void PrintStatistics()
Print the statistics that have been recorded due to a call to GenerateStatistics.
Definition: SamFile.h:352
SamFile::IsOpen
bool IsOpen()
Returns whether or not the file has been opened successfully.
Definition: SamFile.cpp:410
SamFile::ReadRecord
bool ReadRecord(SamFileHeader &header, SamRecord &record)
Reads the next record from the file & stores it in the passed in record.
Definition: SamFile.cpp:501
SamFile::WRITE
@ WRITE
open for writing.
Definition: SamFile.h:41
SamFile::QUERY_NAME
@ QUERY_NAME
file is sorted by queryname.
Definition: SamFile.h:50
SamFileReader::SamFileReader
SamFileReader()
Default Constructor.
Definition: SamFile.cpp:1360
SamFile::OpenType
OpenType
Enum for indicating whether to open the file for read or write.
Definition: SamFile.h:39
SamFile::GenerateStatistics
void GenerateStatistics(bool genStats)
Whether or not statistics should be generated for this file.
Definition: SamFile.cpp:878
StatGenStatus::getStatus
Status getStatus() const
Return the enum for this status object.
Definition: StatGenStatus.cpp:142
SamFile::getNumMappedReadsFromIndex
int32_t getNumMappedReadsFromIndex(int32_t refID)
Get the number of mapped reads in the specified reference id.
Definition: SamFile.cpp:790
ErrorHandler::HandlingType
HandlingType
This specifies how this class should respond to errors.
Definition: ErrorHandler.h:29
SamFile::SortedType
SortedType
Enum for indicating the type of sort expected in the file.
Definition: SamFile.h:46
SamFile::myStatistics
SamStatistics * myStatistics
Pointer to the statistics for this file.
Definition: SamFile.h:412
StatGenStatus
This class is used to track the status results of some methods in the BAM classes.
Definition: StatGenStatus.h:27
SamFile::myHasHeader
bool myHasHeader
Flag to indicate if a header has been read/written - required before being able to read/write a recor...
Definition: SamFile.h:399
SamFile::SetReadFlags
void SetReadFlags(uint16_t requiredFlags, uint16_t excludedFlags)
Specify which reads should be returned by ReadRecord.
Definition: SamFile.cpp:781
SamFile::OpenForWrite
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 (...
Definition: SamFile.cpp:223
SamFile::DisableBuffering
void DisableBuffering()
Turn off file read buffering.
Definition: SamFile.h:342
SamFileWriter
Child class of SamFile for writing files.
Definition: SamFile.h:486
SamFile::SamFile
SamFile()
Default Constructor, initializes the variables, but does not open any files.
Definition: SamFile.cpp:26
SamFile::myRecordCount
uint32_t myRecordCount
Keep a count of the number of records that have been read/written so far.
Definition: SamFile.h:409
StatGenStatus::Status
Status
Return value enum for StatGenFile methods.
Definition: StatGenStatus.h:32
SamFile::GetFailure
SamStatus::Status GetFailure()
Deprecated, get the Status of the last call that sets status.
Definition: SamFile.h:201
SamFile::myIsBamOpenForRead
bool myIsBamOpenForRead
Values for reading Sorted BAM files via the index.
Definition: SamFile.h:418
SamFile::SetReadSection
bool SetReadSection(int32_t refID)
Sets which reference id (index into the BAM list of reference information) of the BAM file should be ...
Definition: SamFile.cpp:683
InputFile.h
StatGenStatus::getStatusMessage
const char * getStatusMessage() const
Return the status message for this object.
Definition: StatGenStatus.cpp:149
SamFileHeader
This class allows a user to get/set the fields in a SAM/BAM Header.
Definition: SamFileHeader.h:35
SamFile::UNSORTED
@ UNSORTED
file is not sorted.
Definition: SamFile.h:47
SamFile::setSortedValidation
void setSortedValidation(SortedType sortType)
Set the flag to validate that the file is sorted as it is read/written.
Definition: SamFile.cpp:669
SamRecord
Class providing an easy to use interface to get/set/operate on the fields in a SAM/BAM record.
Definition: SamRecord.h:52
SamFile::~SamFile
virtual ~SamFile()
Destructor.
Definition: SamFile.cpp:82
GenericSamInterface
Definition: GenericSamInterface.h:27
SamFile::OpenForRead
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...
Definition: SamFile.cpp:93
SamStatistics
Definition: SamStatistics.h:25
SamFile::WriteHeader
bool WriteHeader(SamFileHeader &header)
Writes the specified header into the file.
Definition: SamFile.cpp:467
SamFile::GetNumOverlaps
uint32_t GetNumOverlaps(SamRecord &samRecord)
Returns the number of bases in the passed in read that overlap the region that is currently set.
Definition: SamFile.cpp:864
InputFile
Class for easily reading/writing files without having to worry about file type (uncompressed,...
Definition: InputFile.h:37
SamFile::GetCurrentRecordCount
uint32_t GetCurrentRecordCount()
Return the number of records that have been read/written so far.
Definition: SamFile.cpp:676
SamFileWriter::SamFileWriter
SamFileWriter()
Default Constructor.
Definition: SamFile.cpp:1406
SamFile::ReadHeader
bool ReadHeader(SamFileHeader &header)
Reads the header section from the file and stores it in the passed in header.
Definition: SamFile.cpp:437
SamFile::SetReadSequenceTranslation
void SetReadSequenceTranslation(SamRecord::SequenceTranslation translation)
Set the type of sequence translation to use when reading the sequence.
Definition: SamFile.cpp:387
InputFile::disableBuffering
void disableBuffering()
Disable read buffering.
Definition: InputFile.h:121
SamFile::GetBamIndex
const BamIndex * GetBamIndex()
Return the bam index if one has been opened.
Definition: SamFile.cpp:903
SamFile::Close
void Close()
Close the file if there is one open.
Definition: SamFile.cpp:400
SamFile::validateSortOrder
bool validateSortOrder(SamRecord &record, SamFileHeader &header)
Validate that the record is sorted compared to the previously read record if there is one,...
Definition: SamFile.cpp:1006
SamFile::GetCurrentPosition
int64_t GetCurrentPosition()
Get the current file position.
Definition: SamFile.h:336
SamFile
Allows the user to easily read/write a SAM/BAM file.
Definition: SamFile.h:36
SamFile::SetReference
void SetReference(GenomeSequence *reference)
Sets the reference to the specified genome sequence object.
Definition: SamFile.cpp:380
SamFile::SetWriteSequenceTranslation
void SetWriteSequenceTranslation(SamRecord::SequenceTranslation translation)
Set the type of sequence translation to use when writing the sequence.
Definition: SamFile.cpp:394
SamFileReader
Child class of SamFile for reading files.
Definition: SamFile.h:456
SamFile::myStatus
SamStatus myStatus
The status of the last SamFile command.
Definition: SamFile.h:415
iftell
int64_t iftell(IFILE file)
Get current position in the file.
Definition: InputFile.h:682