-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamicMatrix.cpp
More file actions
107 lines (89 loc) · 3.51 KB
/
Copy pathDynamicMatrix.cpp
File metadata and controls
107 lines (89 loc) · 3.51 KB
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
#include "DynamicMatrix.h"
#include<bits/stdc++.h>
/*// adds a row filled by 0s
* this method can be useful in the case a read sequence is generated at runtime, inside the execution of the
* hmm pair forward algorithm, for instance in the case a new characters of the read needs to be generated inside the
* for loop of the algorithm.
* In such a case, a new row needs to be added to the M, I and D matrices.
* In the current implementation we consider the haplotype and read sequences already defined before the execution of the algorithm
* * For this reason this method has been commented
void DynamicMatrix::addRow() {
vector<float> values;
values.reserve(matrix.size());
if(!matrix[0].empty()) {
for (int i = 0; i < matrix[0].size(); i++)
values.push_back(0);
}
else
values.push_back(0);
matrix.push_back(values);
}
// add a column filled by 0s
* this method can be useful in the case a haplotype sequence is generated at runtime, inside the execution of the
* hmm pair forward algorithm, for instance in the case a new character of the haplotype needs to be generated inside the
* for loop of the algorithm.
* In such a case, a new column needs to be added to the M, I and D matrices.
* In the current implementation we consider the haplotype and read sequences already defined before the execution of the algorithm
* For this reason this method has been commented
void DynamicMatrix::addColumn() {
if(!matrix.empty()) {
for (int i = 0; i < matrix.size(); i++)
matrix[i].push_back(0);
}
else {
vector<float> values;
values.push_back(0);
matrix.push_back(values);
}
}*/
// returns the i+1, j+1 value of the matrix, hiding the user the fact that elements:
// - [0,0];
// - [0,j] for 1 <= j < length of the haplotype sequence;
// - [i,0] for 1 <= i < length of the read sequence
// are all reserved for initialization purposes, and do not logically belong to the matrix
float DynamicMatrix::getValue(int pos1, int pos2) {
return this->getProbability(pos1 + 1, pos2 + 1);
}
ostream& operator<<(ostream& out, const DynamicMatrix& dm) {
out << " |";
for (int i = 0; i < dm.matrix[0].size(); i++) {
if(i>0)
out<< " ";
out << " " << i-1 << " |";
}
out << endl;
for(int i=0; i < dm.matrix.size(); i++){
out << "|";
if(i>0)
out<< " ";
out << " " << i-1 << " |";
for(float value : dm.matrix[i]){
out << " " << fixed << setprecision(10) << value << " |";
}
out << "\n";
}
return out;
}
// sets the i+1, j+1 value of the matrix, hiding the user the fact that elements:
// - [0,0];
// - [0,j] for 1 <= j < length of the haplotype sequence;
// - [i,0] for 1 <= i < length of the read sequence
// are all reserved for initialization purposes, and do not logically belong to the matrix
void DynamicMatrix::setValue(int pos1, int pos2, float value) {
matrix[pos1 + 1][pos2 + 1] = value;
}
/*
* Sets the dimension of the matrix such that:
* - number of rows = length of the read + 1;
* - number of columns = length of the haplotype + 1
* the additional column and row are reserved for initialization purposes
*/
void DynamicMatrix::setDimension(int readLength, int haplotypeLength) {
vector<float> values;
for(int i = 0; i<readLength + 1; i++) {
for (int j = 0; j < haplotypeLength + 1; j++)
values.push_back(-1);
matrix.push_back(values);
values.clear();
}
}