File: MultithreadedBAMParser.hpp

package info (click to toggle)
salmon 0.7.2%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,352 kB
  • ctags: 5,243
  • sloc: cpp: 42,341; ansic: 6,252; python: 228; makefile: 207; sh: 190
file content (68 lines) | stat: -rw-r--r-- 1,857 bytes parent folder | download
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
/**
>HEADER
    Copyright (c) 2013 Rob Patro robp@cs.cmu.edu

    This file is part of Sailfish.

    Sailfish is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Sailfish is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Sailfish.  If not, see <http://www.gnu.org/licenses/>.
<HEADER
**/


#ifndef __MULTITHREADED_BAM_PARSER__
#define __MULTITHREADED_BAM_PARSER__

#include <cstdio>
#include <cstdlib>
#include <vector>
#include <thread>
#include <atomic>
#include <iostream>

#include "api/BamReader.h"
#include "api/BamAlignment.h"

#include <boost/filesystem.hpp>
#include <boost/range/irange.hpp>
#include "tbb/concurrent_queue.h"

namespace bfs = boost::filesystem;

struct ReadSeq {
    char* seq = nullptr;
    size_t len = 0;
    char* name = nullptr;
    size_t nlen = 0;
};

class MultithreadedBAMParser {
public:
    MultithreadedBAMParser( std::vector<bfs::path>& files );
    ~MultithreadedBAMParser();
    bool start();
    bool nextAlignment(BamTools::BamAlignment*& seq);
    void finishedWithAlignment(BamTools::BamAlignment*& s);

private:
    std::vector<bfs::path>& inputStreams_;
    bool parsing_;
    std::thread* parsingThread_;
    tbb::concurrent_bounded_queue<BamTools::BamAlignment*> alnQueue_, seqContainerQueue_;
    BamTools::BamAlignment* alnStructs_;
    const size_t queueCapacity_ = 5000000;
};

//#include "Parser.cpp"

#endif // __MULTITHREADED_BAM_PARSER__