-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathhit_set.cpp
63 lines (57 loc) · 1.48 KB
/
hit_set.cpp
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
/*
* hit_set.cpp
*
* Created on: Jul 31, 2009
* Author: Ben Langmead
*/
#include <iostream>
#include "alphabet.h"
#include "ds.h"
#include "hit_set.h"
#include "sstring.h"
using namespace std;
/**
* Report up to 'khits' hits from this HitSet.
*/
void HitSet::reportUpTo(ostream& os, int khits) {
khits = min(khits, (int)size());
BTDnaString seqrc;
BTString qualr;
for(int i = 0; i < khits; i++) {
const HitSetEnt& h = ents[i];
if(!h.fw && seqrc.empty()) {
// Lazily initialize seqrc and qualr
seqrc = seq;
reverseComplementInPlace(seqrc);
assert_eq(seqrc.length(), seq.length());
qualr = qual;
reverseInPlace(qualr);
assert_eq(qualr.length(), qual.length());
}
os << name << '\t'
<< (h.fw ? '+' : '-') << '\t'
<< h.h.first << '\t'
<< h.h.second << '\t'
<< (h.fw ? seq : seqrc) << '\t'
<< (h.fw ? qual : qualr) << '\t'
<< h.oms << '\t';
for(size_t i = 0; i < h.edits.size(); i++) {
const Edit& e = h.edits[i];
os << e.pos;
if(e.type == EDIT_TYPE_SNP) os << "S";
os << ":" << (char)e.chr << ">" << (e.qchr != 0 ? (char)e.qchr : (char)seq[e.pos]);
if(i < h.edits.size()-1) os << ",";
}
os << endl;
}
}
ostream& operator << (ostream& os, const HitSetEnt& hs) {
os << "\t" << hs.h.first << ":" << hs.h.second;
return os;
}
ostream& operator << (ostream& os, const HitSet& hs) {
os << hs.name << ":" << hs.seq << ":" << hs.qual << endl;
for (size_t i = 0; i < hs.ents.size(); i++)
os << hs.ents[i];
return os;
}