-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDeeZAPI.h
126 lines (107 loc) · 3.44 KB
/
DeeZAPI.h
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#ifndef DeeZAPI_H
#define DeeZAPI_H
#include "Common.h"
#include "Parsers/BAMParser.h"
#include "Parsers/SAMParser.h"
#include "Parsers/Record.h"
#include "Sort.h"
#include "Common.h"
#include "Decompress.h"
#include "Legacy/v1.1/Decompress.h"
class DeeZFile {
public:
struct SAMRecord {
string rname;
int flag;
string chr;
unsigned long loc;
int mapqual;
string cigar;
string pchr;
unsigned long ploc;
int tlen;
string seq;
string qual;
string opt;
};
private:
class FDv11 : public Legacy::v11::FileDecompressor {
std::vector<std::vector<SAMRecord>> &records;
virtual inline void printRecord(const string &rname, int flag, const string &chr, const Legacy::v11::EditOperation &eo, int mqual, const string &qual, const string &optional, const Legacy::v11::PairedEndInfo &pe, int file, int thread) {
records[thread].push_back({rname, flag, chr, eo.start, mqual, eo.op, pe.chr, pe.pos, pe.tlen, eo.seq, qual, optional});
}
virtual inline void printComment(int file) {
}
public:
FDv11 (std::vector<std::vector<SAMRecord>> &rec, const std::string &inFile, const std::string &genomeFile = ""):
Legacy::v11::FileDecompressor(inFile, "", genomeFile, optBlock), records(rec)
{
}
};
class FDv20 : public FileDecompressor {
std::vector<std::vector<SAMRecord>> &records;
virtual inline void printRecord(const string &rname, int flag, const string &chr, const EditOperation &eo, int mqual, const string &qual, const string &optional, const PairedEndInfo &pe, int file, int thread) {
records[thread].push_back({rname, flag, chr, eo.start, mqual, eo.op, pe.chr, pe.pos, pe.tlen, eo.seq, qual, optional});
}
virtual inline void printComment(int file) {
}
public:
FDv20 (std::vector<std::vector<SAMRecord>> &rec, const std::string &inFile, const std::string &genomeFile = ""):
FileDecompressor(inFile, "", genomeFile, optBlock, true), records(rec)
{
}
};
std::vector<std::vector<SAMRecord>> records;
std::string prev_range;
int prev_filter_flag;
shared_ptr<IFileDecompressor> dec;
public:
DeeZFile (const std::string &inFile, const std::string &genomeFile = ""):
records(4)
{
auto file = File::Open(inFile.c_str(), "rb");
if (file == NULL) {
throw DZException("Cannot open the file %s", inFile.c_str());
}
uint32_t magic = file->readU32();
if ((magic & 0xff) < 0x20) {
LOG("Using old DeeZ v1.1 engine");
dec = make_shared<FDv11>(records, inFile, genomeFile);
} else {
dec = make_shared<FDv20>(records, inFile, genomeFile);
}
}
~DeeZFile (void) {}
public:
void setLogLevel (int level) {
if (level < 0 || level > 2) {
throw DZException("Log level must be 0, 1 or 2");
}
optLogLevel = level;
}
int getFileCount () {
return dec->comments.size();
}
std::string getComment (int file) {
if (file < 0 || file >= dec->comments.size()) {
throw DZException("Invalid file index");
}
return dec->comments[file];
}
std::vector<SAMRecord> &getRecords (const std::string &range = "", int filterFlag = 0, bool overlap = true) {
for (auto &r: records)
r.clear();
optOverlap = overlap;
if (range != "") {
prev_range = range;
prev_filter_flag = filterFlag;
dec->decompress2(prev_range, prev_filter_flag, false);
} else {
dec->decompress2(prev_range, prev_filter_flag, true);
for (size_t i = 1; i < records.size(); i++)
records[0].insert(records[0].end(), records[i].begin(), records[i].end());
}
return records[0];
}
};
#endif // DeeZAPI_H