-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCScoreHaplotype.cpp
More file actions
105 lines (85 loc) · 3.71 KB
/
CScoreHaplotype.cpp
File metadata and controls
105 lines (85 loc) · 3.71 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
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/cppFiles/class.cc to edit this template
*/
/*
* File: CScoreHaplotype.cpp
* Author: mwittig
*
* Created on December 1, 2023, 3:28 PM
*/
/**************************
NOT IN USE!!!
**************************/
#include <iostream>
#include <vector>
#include <cstdlib>
#include <vector>
#include <map>
#include <string>
#include <libgen.h>
#include <limits>
#include <regex>
#include "CIsbtVariant.h"
#include "CBigWigReader.h"
#include "CScoreHaplotype.h"
CScoreHaplotype::~CScoreHaplotype() {
}
int CScoreHaplotype::performAlignment(){
const int typicalGapPenalty = -1; // Typische Strafe für Lücken
const int specialGapPenalty = -2; // Höhere Strafe, wenn "A" involviert
const int matchScore = 2; // Punkte für Übereinstimmungen
const int typicalMismatchPenalty = -1; // Typische Strafe für Nicht-Übereinstimmungen
const int specialMismatchPenalty = -2; // Höhere Strafe, wenn "A" involviert
vector<CIsbtVariant> haplotype1,haplotype2;
haplotype1.assign(m_haplotype1.begin(), m_haplotype1.end());
haplotype2.assign(m_haplotype2.begin(), m_haplotype2.end());
const int rows = haplotype1.size() + 1;
const int cols = haplotype2.size() + 1;
// Initialisiere die Matrix für die dynamische Programmierung
std::vector<std::vector<int>> dp(rows, std::vector<int>(cols, 0));
int maxScore = 0;
[[maybe_unused]] int maxI = 0, maxJ = 0;
// Fülle die Matrix und finde den maximalen Score
for (int i = 1; i < rows; ++i) {
for (int j = 1; j < cols; ++j) {
int gapPenalty = (haplotype1[i - 1].isHighImpactSNP() || haplotype2[j - 1].isHighImpactSNP()) ? specialGapPenalty : typicalGapPenalty;
int mismatchPenalty = (haplotype1[i - 1].isHighImpactSNP() || haplotype2[j - 1].isHighImpactSNP()) ? specialMismatchPenalty : typicalMismatchPenalty;
int scoreDiagonal = dp[i - 1][j - 1] + (haplotype1[i - 1] == haplotype2[j - 1] ? matchScore : mismatchPenalty);
int scoreUp = dp[i - 1][j] + gapPenalty;
int scoreLeft = dp[i][j - 1] + gapPenalty;
dp[i][j] = std::max(0, std::max(scoreDiagonal, std::max(scoreUp, scoreLeft)));
if (dp[i][j] > maxScore) {
maxScore = dp[i][j];
maxI = i;
maxJ = j;
}
}
}
// Hier kannst du den maximalen Score oder die ausgerichteten Sequenzen weiterverarbeiten
std::cerr << "Maximaler Score: " << maxScore << std::endl;
/*
// Beispiel: Ausgabe der ausgerichteten Sequenzen
std::string alignedSequence1, alignedSequence2;
while (maxI > 0 && maxJ > 0 && dp[maxI][maxJ] != 0) {
if (dp[maxI][maxJ] == dp[maxI - 1][maxJ - 1] + (m_haplotype1[maxI - 1] == m_haplotype2[maxJ - 1] ? matchScore : mismatchPenalty)) {
alignedSequence1 = m_haplotype1[maxI - 1] + alignedSequence1;
alignedSequence2 = m_haplotype2[maxJ - 1] + alignedSequence2;
--maxI;
--maxJ;
} else if (dp[maxI][maxJ] == dp[maxI - 1][maxJ] + gapPenalty) {
alignedSequence1 = m_haplotype1[maxI - 1] + alignedSequence1;
alignedSequence2 = '-' + alignedSequence2;
--maxI;
} else {
alignedSequence1 = '-' + alignedSequence1;
alignedSequence2 = m_haplotype2[maxJ - 1] + alignedSequence2;
--maxJ;
}
}
std::cout << "Aligned Sequence 1: " << alignedSequence1 << std::endl;
std::cout << "Aligned Sequence 2: " << alignedSequence2 << std::endl;
std::cout << "Alignment durchgeführt." << std::endl;
*/
return maxScore;
}