-
Notifications
You must be signed in to change notification settings - Fork 1
/
ReadOutput.hpp
58 lines (51 loc) · 1.77 KB
/
ReadOutput.hpp
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
/**
* shark - Mapping-free filtering of useless RNA-Seq reads
* Copyright (C) 2019 Tamara Ceccato, Luca Denti, Yuri Pirola, Marco Previtali
*
* This file is part of shark.
*
* shark 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.
*
* shark 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 shark; see the file LICENSE. If not, see
* <https://www.gnu.org/licenses/>.
**/
#ifndef READOUTPUT__HPP
#define READOUTPUT__HPP
#include <iostream>
#include <vector>
#include <mutex>
#include "common.hpp"
class ReadOutput {
public:
ReadOutput(FILE* const _out1 = nullptr, FILE* const _out2 = nullptr)
: out1(_out1), out2(_out2)
{ }
void operator()(const std::vector<assoc_t>& associations) {
std::lock_guard<std::mutex> lock(mtx);
string previd = "";
for(const auto & a : associations) {
const sharseq_t& s1 = a.second.first;
const sharseq_t& s2 = a.second.second;
printf("%s %s\n", s1.id.c_str(), a.first.c_str());
if (out1 != nullptr && previd != s1.id)
fprintf(out1, "@%s\n%s\n+\n%s\n", s1.id.c_str(), s1.seq.c_str(), s1.qual.c_str());
if (out2 != nullptr && previd != s1.id)
fprintf(out2, "@%s\n%s\n+\n%s\n", s2.id.c_str(), s2.seq.c_str(), s2.qual.c_str());
previd = std::move(s1.id);
}
}
private:
FILE* const out1;
FILE* const out2;
std::mutex mtx;
};
#endif