-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathUtil.cpp
53 lines (43 loc) · 1.5 KB
/
Util.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
#include "Util.h"
void ReadVariant::sort(){
std::sort(variantVec.begin(), variantVec.end(), less_than_key());
}
void mergeAllChrPhasingResult(const ChrPhasingResult& allChrPhasingResults, PhasingResult& mergedPhasingResult) {
for(const auto& chrPair : allChrPhasingResults){
const PhasingResult& singlePhasingResult = chrPair.second;
mergedPhasingResult.insert(singlePhasingResult.begin(), singlePhasingResult.end());
}
}
std::string getTargetString(std::string line, std::string start_sign, std::string end_sign){
int start = line.find(start_sign) + 1;
int end = line.find(end_sign);
int target_length = end - start;
return line.substr(start,target_length);
}
int homopolymerLength(int snp_pos, const std::string &ref_string){
int homopolymer_length = 1;
int ref_len = ref_string.length();
if( snp_pos + 1 >= ref_len ){
return homopolymer_length;
}
char element = ref_string.at(snp_pos);
int pos = snp_pos-1;
while( ref_string.at(pos) == element ){
pos--;
homopolymer_length++;
if(homopolymer_length>=10 || pos < 0 )
break;
}
pos = snp_pos+1;
if( pos < ref_len ){
while( ref_string.at(pos) == element ){
pos++;
homopolymer_length++;
if( pos >= ref_len)
break;
if(homopolymer_length>=10)
break;
}
}
return homopolymer_length;
}