-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathalign_utils.cpp
76 lines (58 loc) · 2.13 KB
/
align_utils.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
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* Copyright (C) 2009-2012 Simon A. Berger
*
* This file is part of papara.
*
* papara 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.
*
* papara 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 papara. If not, see <http://www.gnu.org/licenses/>.
*/
#include <cassert>
#include <cstdlib>
#include <stdint.h>
#include <vector>
#include "align_utils.h"
void align_utils::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 align_utils::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 align_utils::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('-');
}
}
}