-
Notifications
You must be signed in to change notification settings - Fork 8
/
indexFunction.cpp
66 lines (60 loc) · 1.79 KB
/
indexFunction.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
#include <stdio.h>
#include <string.h>
#include "indexFunction.h"
unsigned int getAmbPos(unsigned short chr_id, unsigned int offset,
unsigned int *ambiguityMap, Translate *translate,
unsigned int dnaLength) {
long long low = 0;
long long high = dnaLength - 1;
int loop_count = 0;
while (low <= high) {
loop_count++;
if (loop_count == LOOP_BOUND) {
break;
}
unsigned int ambPos = (low + high) / 2;
unsigned int approxIndex, approxValue;
unsigned int correctPosition = ambPos;
approxIndex = ambPos >> GRID_SAMPLING_FACTOR_2_POWER;
approxValue = ambiguityMap[approxIndex];
while (translate[approxValue].startPos > ambPos) {
approxValue--;
}
correctPosition -= translate[approxValue].correction;
unsigned short chr = translate[approxValue].chrID;
if (chr < chr_id || (chr == chr_id && correctPosition < offset)) {
low = ambPos + 1;
} else if (chr > chr_id || (chr == chr_id && correctPosition > offset)) {
high = ambPos - 1;
} else {
return ambPos;
}
}
return dnaLength + 2;
}
unsigned int getChrIDFromName(Annotation *annotation, unsigned int numOfSeq, const char *chrName) {
unsigned int i;
for (i = 0; i < numOfSeq; ++i) {
if (strcmp(annotation[i].text, chrName) == 0) {
return i + 1;
}
}
if (strlen(chrName) >= 3 && chrName[0] == 'c' && chrName[1] == 'h' && chrName[2] == 'r') {
for (i = 0; i < numOfSeq; ++i) {
if (strcmp(annotation[i].text, chrName + 3) == 0) {
return i + 1;
}
}
} else {
char tmp[1000];
tmp[0] = 0;
strcat(tmp, "chr");
strcat(tmp, chrName);
for (i = 0; i < numOfSeq; ++i) {
if (strcmp(annotation[i].text, chrName) == 0) {
return i + 1;
}
}
}
return i + 1;
}