forked from zhouqiansolab/KSNP
-
Notifications
You must be signed in to change notification settings - Fork 1
/
snp_dbg.h
110 lines (82 loc) · 2.04 KB
/
snp_dbg.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
//
// Created by ixiaohu on 2022/1/28.
//
#ifndef KSNP_SNP_DBG_H
#define KSNP_SNP_DBG_H
#include <vector>
#include "vcf_reader.h"
#include "phased_block.h"
struct SNP_DBG {
int snp_n;
int K;
int *node_cnt;
int *edge_cnt;
int *weight;
SNP_DBG (int k, int n) {
snp_n = n;
K = k;
node_cnt = (int*) calloc((1<<k) * n, sizeof(int));
edge_cnt = (int*) calloc((1<<(k+1)) * n, sizeof(int));
weight = (int*) calloc((1<<(k+1)) * n, sizeof(int));
}
void add_node(int p, uint32_t e) const {
(node_cnt + (1<<K) * p)[e]++;
}
void add_edge(int p, uint32_t e) const {
(edge_cnt + (1<<(K+1)) * p)[e]++;
}
void construct_graph(std::vector<SNP> &snps) const;
void input_graph_from_file(const char *fn, const std::vector<SNP> &snps) const;
inline bool filter_edge(int heaviest, int edge_weight) ;
void trim_graph();
void remove_tip();
void remove_bubble();
void remove_tip_again();
void check_graph_symmetry();
inline int out_degree(int p, int node) const {
if (p == snp_n-1) return 0;
int ret = 0;
if (weight[(p+1) * (1<<(K+1)) + ((node<<1) | 0)] != 0) ret++;
if (weight[(p+1) * (1<<(K+1)) + ((node<<1) | 1)] != 0) ret++;
return ret;
}
inline int in_degree(int p, int node) const {
if (p == 0) return 0;
int ret = 0;
if (weight[p * (1<<(K+1)) + ((0<<K) | node)] != 0) ret++;
if (weight[p * (1<<(K+1)) + ((1<<K) | node)] != 0) ret++;
return ret;
}
SNP_Block traversal_block(int p, int u);
std::vector<SNP_Block> snp_haplotype();
void output(const std::vector<SNP> &snps);
void destroy() const {
free(node_cnt);
free(edge_cnt);
free(weight);
}
};
// The SAM structure only keeps necessary fields
struct SAM_Record {
char *que_name;
int flag;
char *ref_name;
int ref_start;
char *cigar;
char *bases;
SAM_Record(char *s);
};
struct Parsed_CIGAR {
int n, m;
int *num;
char *op;
Parsed_CIGAR() {
n = 0;
m = 512;
num = (int*) malloc(m * sizeof(int));
op = (char*) malloc(m * sizeof(char));
}
void parse(const char *cigar);
void destroy() const { free(num); free(op); }
};
#endif //KSNP_SNP_DBG_H