source: trunk/yat/omic/BamPairBuffer.h @ 4057

Last change on this file since 4057 was 4057, checked in by Peter, 7 months ago

closes #798; new classes BamPairBuffer? and a more general SortedBuffer?.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1#ifndef _theplu_yat_omic_bam_pair_buffer_
2#define _theplu_yat_omic_bam_pair_buffer_
3
4// $Id: BamPairBuffer.h 4057 2021-03-31 05:46:00Z peter $
5
6/*
7  Copyright (C) 2021 Peter Johansson
8
9  This file is part of the yat library, http://dev.thep.lu.se/yat
10
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 3 of the
14  License, or (at your option) any later version.
15
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with yat. If not, see <http://www.gnu.org/licenses/>.
23*/
24
25#include "BamRead.h"
26
27#include <yat/utility/SortedBuffer.h>
28#include <yat/utility/yat_assert.h>
29
30namespace theplu {
31namespace yat {
32namespace omic {
33
34  /**
35     Bam read pairs can be added to this class and it handles to sort
36     reads (according to the genomic position, see BamLessPos) and
37     copy to an output iterator. It is assumed that the inserted read
38     pairs are sorted with respect to their first read. This can be
39     accomplished with e.g. BapPairIterator2.
40
41     \see BamPairIterator2
42
43     \since New in yat 0.19
44   */
45  template<typename OutputIterator>
46  class BamPairBuffer
47  {
48  public:
49    /**
50       \brief Constructor
51
52       Creates a buffer that flush elements to \c out.
53     */
54    BamPairBuffer(OutputIterator out)
55      : buffer_(out) {}
56
57    /**
58       Position of \c first read is less (or equal) than position of
59       \c second.
60
61       It is assumed that read pairs are pushed in a sorted order such
62       that first is not less than the previous first.
63     */
64    void push(const BamRead& first, const BamRead& second)
65    {
66      // first <= second within each pair
67      YAT_ASSERT(BamLessPos()(second, first) == false);
68      // read pairs come sorted wrt first, i.e., all future ::first
69      // are greater (or equal) than current first, and thus all
70      // future reads are greater (or equal) than first.
71      buffer_.flush(first);
72      buffer_.push(first);
73      buffer_.push(second);
74    }
75  private:
76    utility::SortedBuffer<BamRead, OutputIterator, BamLessPos> buffer_;
77  };
78
79}}}
80#endif
Note: See TracBrowser for help on using the repository browser.