/
align_utils.h
63 lines (43 loc) · 1.18 KB
/
align_utils.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
#ifndef __align_utils_h__
#define __align_utils_h__
#include <cassert>
#include <vector>
#include <stdint.h>
namespace align_utils {
void trace_to_position_map( const std::vector< uint8_t >& gaps, std::vector< int > *map) {
int seq_ptr = 0;
for ( std::vector<uint8_t>::const_reverse_iterator git = gaps.rbegin(); git != gaps.rend(); ++git ) {
if ( *git == 1) {
++seq_ptr;
} else if ( *git == 0 ) {
map->push_back(seq_ptr);
++seq_ptr;
} else {
map->push_back(seq_ptr);
}
}
}
uint8_t decode_dna( int s ) {
assert( s >= 0 && s < 4 );
const static uint8_t map[4] = {'A','C','G','T'};
return map[size_t(s)];
}
void realize_trace( const std::vector<uint8_t> &seq, const std::vector<uint8_t> &tb, std::vector<uint8_t> *out ) {
assert( out != 0 );
std::vector<uint8_t>::const_reverse_iterator tb_it;
std::vector<uint8_t>::const_iterator seq_it;
for( tb_it = tb.rbegin(), seq_it = seq.begin(); tb_it != tb.rend(); ++tb_it ) {
if( *tb_it == 0 ) {
assert( seq_it != seq.end() );
out->push_back(decode_dna(*seq_it));
++seq_it;
} else if( *tb_it == 2 ) {
assert( seq_it != seq.end() );
++seq_it;
} else {
out->push_back('-');
}
}
}
}
#endif