File: PbiFilterZmwGroupQuery.cpp

package info (click to toggle)
pbseqlib 0~20161219-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,924 kB
  • ctags: 5,123
  • sloc: cpp: 82,727; makefile: 305; python: 239; sh: 8
file content (77 lines) | stat: -rw-r--r-- 2,412 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "../../pbdata/libconfig.h"
#ifdef USE_PBBAM
#include "PbiFilterZmwGroupQuery.h"
#include <pbbam/CompositeBamReader.h>
#include <boost/optional.hpp>
#include <cassert>
using namespace PacBio;
using namespace PacBio::BAM;
using namespace PacBio::BAM::internal;
using namespace std;

struct PbiFilterZmwGroupQuery::PbiFilterZmwGroupQueryPrivate
{
    /// TODO: To ensure that BamRecords of a zmw are always stored 
    /// sequentially in bam files, such as in movie.subreads.bam.
public:
    PbiFilterZmwGroupQueryPrivate(const PbiFilter& filter, const DataSet& dataset)
        : reader_(new PbiFilterCompositeBamReader<Compare::None>(filter, dataset))
        , nextRecord_(boost::none)
    { }

    bool GetNext(vector<BamRecord>& records)
    {
        records.clear();

        string movieName;
        int32_t holeNumber;

        if (nextRecord_.is_initialized()) {
            BamRecord r = nextRecord_.get();
            movieName = r.MovieName();
            holeNumber = r.HoleNumber();
            records.push_back(std::move(r));
            nextRecord_ = boost::none;
        }

        BamRecord record;
        while (reader_->GetNext(record)) {
            if (records.empty()) {
                movieName = record.MovieName();
                holeNumber = record.HoleNumber();
                records.push_back(record);
            }
            else {
                assert(!records.empty());
                if (record.MovieName() == movieName and record.HoleNumber() == holeNumber)
                    records.push_back(record);
                else {
                    nextRecord_ = record;
                    return true;
                }
            }
        }
        return !records.empty();
    }

public:
    unique_ptr<PbiFilterCompositeBamReader<Compare::None>> reader_;

    boost::optional<BamRecord> nextRecord_;
};

PbiFilterZmwGroupQuery::PbiFilterZmwGroupQuery(const DataSet& dataset)
    : internal::IGroupQuery()
    , d_(new PbiFilterZmwGroupQueryPrivate(PbiFilter::FromDataSet(dataset),dataset)) 
{ }

PbiFilterZmwGroupQuery::PbiFilterZmwGroupQuery(const PbiFilter& filter, const DataSet& dataset)
    : internal::IGroupQuery()
    , d_(new PbiFilterZmwGroupQueryPrivate(filter, dataset))
{ }

PbiFilterZmwGroupQuery::~PbiFilterZmwGroupQuery(void) { }

bool PbiFilterZmwGroupQuery::GetNext(vector<BamRecord>& records)
{ return d_->GetNext(records); }
#endif