libStatGen Software  1
SamCoordOutput.h
1 /*
2  * Copyright (C) 2011 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_COORD_OUTPUT_H__
19 #define __SAM_COORD_OUTPUT_H__
20 
21 #include "SamFile.h"
22 #include "SamRecordPool.h"
23 
24 /// Class for buffering up output reads to ensure that it is sorted.
25 /// They are added in almost sorted order.
26 /// Flush writes any records that start at/before the specified position.
28 {
29 public:
30  /// Create an output buffer returning any written records to the specified pool.
31  /// \param pool pool that any written records should be returned to, a pointer
32  /// to this pool is stored, so it should not go out of scope until the output buffer
33  /// has written all the records.
35  ~SamCoordOutput();
36 
37  /// Set the already opened output file to write to when flushed.
38  /// The user should not close/delete the SamFile until this class is done
39  /// with it. This class does NOT close/delete the SamFile.
40  /// \param outFile pointer to an already opened (and header written)
41  /// SAM/BAM output file.
42  /// \param header pointer to an already written header that should be
43  /// used for writing the records.
44  void setOutputFile(SamFile* outFile, SamFileHeader* header);
45 
46  /// Add the specified record to this read buffer.
47  bool add(SamRecord* record);
48 
49  /// Flush the entire buffer, writing all records.
50  /// If no output buffer is set, the files cannot be written, but the
51  /// flushed records are removed/freed.
52  bool flushAll();
53 
54  /// Flush the buffer based on the specified chromosome id/position, writing
55  /// any records that start at/before the specified chromosome id/position.
56  /// If no output buffer is set, the files cannot be written, but the
57  /// flushed records are removed/freed.
58  /// A chromID of -1 will flush everything regardless of pos0Based.
59  bool flush(int32_t chromID, int32_t pos0Based);
60 
61 protected:
62 
63 
64 private:
65  // Require a sam record pool, so make the constructor with
66  // no parameters private.
68 
69  SamFile* myOutputFile;
70  SamFileHeader* myHeader;
71  std::multimap<uint64_t, SamRecord*> myReadBuffer;
72  SamRecordPool* myPool;
73 };
74 
75 
76 #endif
void setOutputFile(SamFile *outFile, SamFileHeader *header)
Set the already opened output file to write to when flushed.
Allows the user to easily read/write a SAM/BAM file.
Definition: SamFile.h:35
bool add(SamRecord *record)
Add the specified record to this read buffer.
bool flush(int32_t chromID, int32_t pos0Based)
Flush the buffer based on the specified chromosome id/position, writing any records that start at/bef...
This class allows a user to get/set the fields in a SAM/BAM Header.
Definition: SamFileHeader.h:34
bool flushAll()
Flush the entire buffer, writing all records.
Class providing an easy to use interface to get/set/operate on the fields in a SAM/BAM record...
Definition: SamRecord.h:51
Class for buffering up output reads to ensure that it is sorted.