-
Notifications
You must be signed in to change notification settings - Fork 5
/
evo_recombUtils.h
214 lines (156 loc) · 4.79 KB
/
evo_recombUtils.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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
//
// evo_recombUtils.h
// process_vcf
//
// Created by Milan Malinsky on 29.07.22.
// Copyright © 2022 Milan Malinsky. All rights reserved.
//
#ifndef evo_recombUtils_h
#define evo_recombUtils_h
#include <stdio.h>
#include "process_vcf_utils.h"
#define SOFT_CLIP_CIGAR 'S'
#define HARD_CLIP_CIGAR 'H'
#define MATCH_CIGAR 'M'
#define INSERTION_CIGAR 'I'
#define DELETION_CIGAR 'D'
class HetInfo {
public:
HetInfo(int position, char readBase, int readBaseQuality, char phase0, char phase1, double phaseQuality, int phaseBlockIn) {
pos = position;
thisBase = readBase; thisBaseQuality = readBaseQuality;
thisHetPhase0 = phase0; thisHetPhase1 = phase1;
thisPhaseQuality = phaseQuality;
phaseBlock = phaseBlockIn;
if (thisBase != thisHetPhase0 && thisBase != thisHetPhase1) {
readPhaseBaseMismatch = true;
} else {
readPhaseBaseMismatch = false;
}
if (thisBase == thisHetPhase0) {
thisHetPhase01 = 0;
} else if (thisBase == thisHetPhase1) {
thisHetPhase01 = 1;
}
};
int pos;
int phaseBlock;
char thisBase;
int thisBaseQuality;
char thisHetPhase0;
char thisHetPhase1;
double thisPhaseQuality;
int thisHetPhase01;
bool readPhaseBaseMismatch;
};
class PhaseInfo {
public:
PhaseInfo() {};
PhaseInfo(int position, double qual, int cov, std::vector<char>& phasedVarsIn, int blockNumIn) {
pos = position; quality = qual;
coverage = cov;
phasedVars = phasedVarsIn;
blockNum = blockNumIn;
};
int pos;
std::vector<char> phasedVars;
double quality;
int coverage;
int blockNum;
};
class PhasePair {
public:
PhasePair(): phase1(NULL), phase2(NULL) {};
PhaseInfo* phase1;
PhaseInfo* phase2;
};
class ReadLinkSNPpair {
public:
ReadLinkSNPpair(int p1, int p2, char b1, char b2) {
pos1 = p1; pos2 = p2;
base1.push_back(b1); base2.push_back(b2);
};
int pos1; int pos2;
std::vector<char> base1; std::vector<char> base2;
};
class RecombRead {
public:
RecombRead(const std::vector<string> samRecVec) : usedLength(0) {
flag = atoi(samRecVec[1].c_str());
readStrand = assignStrandFromFlag();
readName = samRecVec[0]; readPos = atoi(samRecVec[3].c_str());
MQ = atoi(samRecVec[4].c_str()); CIGAR = samRecVec[5];
readSeq = samRecVec[9]; readQual = samRecVec[10];
generateCIGARvectors();
};
bool operator< (const RecombRead &other) const {
return readPos < other.readPos;
}
int flag;
string readStrand; string readName; int readPos; int adjustedReadPos;
string readSeq; string readQual;
int MQ; string CIGAR;
std::vector<int> GIGARnums; std::vector<char> GIGARtypes;
std::vector<int> GIGARnumsNoSI;
int usedLength;
std::vector<HetInfo*> hetSites;
std::map<int,std::vector<int>> BlockIDsToHetPos;
void findHetsInRead(const std::map<int,PhaseInfo*>& positionToPhase);
private:
string assignStrandFromFlag();
void generateCIGARvectors();
void findHetsInMatchingString(const string& matchSeq, int startPos, const std::map<int,PhaseInfo*>& positionToPhase);
};
class PhaseSwitch {
public:
PhaseSwitch(int left, int right, double qLeft, double qRight) {
posLeft = left;
posRight = right;
phaseQualLeft = qLeft;
phaseQualRight = qRight;
dist = abs(right - left);
};
int posLeft;
int posRight;
double phaseQualLeft;
double phaseQualRight;
int dist;
};
class RecombReadPair {
public:
RecombReadPair(RecombRead* r1, RecombRead* r2) {
if (r1 < r2) {
read1 = r1;
read2 = r2;
} else {
read1 = r2;
read2 = r1;
}
};
bool operator< (const RecombReadPair &other) const {
return read1->readPos < other.read1->readPos;
}
RecombRead* read1;
RecombRead* read2;
int pairSpan;
bool pairDiscordant;
std::vector<HetInfo*> hetSites;
//std::map<int,std::vector<int>> BlockIDsToHetPos;
//std::map<int> HetPosToBlockIDs;
void findAndCombinePairHets(const std::map<int,PhaseInfo*> & positionToPhase);
void filterHetsByQuality(int minQuality);
void filterHetsByBlock(int blockNum);
};
inline unsigned nChoosek( unsigned n, unsigned k )
{
if (k > n) return 0;
if (k * 2 > n) k = n-k;
if (k == 0) return 1;
int result = n;
for( int i = 2; i <= k; ++i ) {
result *= (n-i+1);
result /= i;
}
return result;
}
#endif /* evo_recombUtils_h */