| 1 |
#ifndef ABPOA_ALIGN_H |
| 2 |
#define ABPOA_ALIGN_H |
| 3 |
|
| 4 |
#include "abpoa.h" |
| 5 |
#include "abpoa_graph.h" |
| 6 |
|
| 7 |
#define CHUNK_READ_N 1024 |
| 8 |
|
| 9 |
#define ABPOA_MATCH 2 |
| 10 |
#define ABPOA_MISMATCH 4 |
| 11 |
#define ABPOA_GAP_OPEN1 4 |
| 12 |
#define ABPOA_GAP_OPEN2 24 |
| 13 |
#define ABPOA_GAP_EXT1 2 |
| 14 |
#define ABPOA_GAP_EXT2 1 |
| 15 |
|
| 16 |
#define ABPOA_MMK 19 |
| 17 |
#define ABPOA_MMW 10 |
| 18 |
#define ABPOA_MIN_POA_WIN 500 |
| 19 |
|
| 20 |
#define ABPOA_M_OP 0x1 |
| 21 |
#define ABPOA_E1_OP 0x2 |
| 22 |
#define ABPOA_E2_OP 0x4 |
| 23 |
#define ABPOA_E_OP 0x6 |
| 24 |
#define ABPOA_F1_OP 0x8 |
| 25 |
#define ABPOA_F2_OP 0x10 |
| 26 |
#define ABPOA_F_OP 0x18 |
| 27 |
#define ABPOA_ALL_OP 0x1f |
| 28 |
|
| 29 |
#define MULTIP_MIN_FREQ 0.25 |
| 30 |
|
| 31 |
// start and end of each band: |
| 32 |
// range: (min_of_two(max_left, qlen-remain), max_of_two(max_right, qlen-remain)) |
| 33 |
// with extra band width: (range_min-w, range_max+w) |
| 34 |
#define GET_AD_DP_BEGIN(graph, w, id, end_id, qlen) MAX_OF_TWO(0, MIN_OF_TWO(abpoa_graph_node_id_to_max_pos_left(graph, id), qlen-(abpoa_graph_node_id_to_max_remain(graph,id)-abpoa_graph_node_id_to_max_remain(graph,end_id)-1)) - w) |
| 35 |
#define GET_AD_DP_END(graph, w, id, end_id, qlen) MIN_OF_TWO(qlen, MAX_OF_TWO(abpoa_graph_node_id_to_max_pos_right(graph, id), qlen-(abpoa_graph_node_id_to_max_remain(graph,id)-abpoa_graph_node_id_to_max_remain(graph,end_id)-1)) + w) |
| 36 |
|
| 37 |
#ifdef __cplusplus |
| 38 |
extern "C" { |
| 39 |
#endif |
| 40 |
|
| 41 |
static inline void abpoa_res_copy(abpoa_res_t *dest, abpoa_res_t *src) { |
| 42 |
int i; |
| 43 |
if (dest->n_cigar) free(dest->graph_cigar); |
| 44 |
dest->n_cigar = src->n_cigar; |
| 45 |
dest->graph_cigar = (abpoa_cigar_t*)_err_malloc(src->n_cigar * sizeof(abpoa_cigar_t)); |
| 46 |
for (i = 0; i < src->n_cigar; ++i) dest->graph_cigar[i] = src->graph_cigar[i]; |
| 47 |
dest->node_s = src->node_s, dest->node_e = src->node_e; |
| 48 |
dest->query_s = src->query_s, dest->query_e = src->query_e; |
| 49 |
dest->n_aln_bases = src->n_aln_bases, dest->n_matched_bases = src->n_matched_bases; |
| 50 |
dest->best_score = src->best_score; |
| 51 |
// dest->is_rc = src->is_rc; |
| 52 |
} |
| 53 |
|
| 54 |
static inline abpoa_cigar_t *abpoa_push_cigar(int *n_cigar, int *m_cigar, abpoa_cigar_t *cigar, int op, int len, int32_t node_id, int32_t query_id) { |
| 55 |
abpoa_cigar_t l = len; |
| 56 |
if (*n_cigar == 0 || (op != ABPOA_CINS && op != ABPOA_CSOFT_CLIP && op != ABPOA_CHARD_CLIP) || op != (int)(cigar[(*n_cigar)-1] & 0xf)) { |
| 57 |
if (*n_cigar == *m_cigar) { |
| 58 |
*m_cigar = *m_cigar? (*m_cigar)<<1 : 4; |
| 59 |
cigar = (abpoa_cigar_t*)_err_realloc(cigar, (*m_cigar) * sizeof(abpoa_cigar_t)); |
| 60 |
} |
| 61 |
abpoa_cigar_t n_id = node_id, q_id = query_id; |
| 62 |
if (op == ABPOA_CMATCH || op == ABPOA_CDIFF) |
| 63 |
cigar[(*n_cigar)++] = n_id << 34 | q_id << 4 | op; |
| 64 |
else if (op == ABPOA_CINS || op == ABPOA_CSOFT_CLIP || op == ABPOA_CHARD_CLIP) |
| 65 |
cigar[(*n_cigar)++] = q_id << 34 | l << 4 | op; |
| 66 |
else if (op == ABPOA_CDEL) |
| 67 |
cigar[(*n_cigar)++] = n_id << 34 | l << 4 | op; |
| 68 |
else |
| 69 |
err_fatal(__func__, "Unknown cigar operation: %s\n", op); |
| 70 |
} else cigar[(*n_cigar)-1] += l << 4; |
| 71 |
|
| 72 |
return cigar; |
| 73 |
} |
| 74 |
|
| 75 |
static inline int abpoa_push_whole_cigar(int *dest_n_cigar, int *dest_m_cigar, abpoa_cigar_t **dest_cigar, int src_n_cigar, abpoa_cigar_t *src_cigar) { |
| 76 |
int i, dest_n_c = *dest_n_cigar; |
| 77 |
*dest_n_cigar += src_n_cigar; |
| 78 |
if (*dest_n_cigar > *dest_m_cigar) { |
| 79 |
*dest_m_cigar = MAX_OF_TWO((*dest_m_cigar) << 1, *dest_n_cigar); |
| 80 |
*dest_cigar = (abpoa_cigar_t*)_err_realloc(*dest_cigar, *dest_m_cigar * sizeof(abpoa_cigar_t)); |
| 81 |
} |
| 82 |
for (i = 0; i < src_n_cigar; ++i) { |
| 83 |
(*dest_cigar)[dest_n_c+i] = src_cigar[i]; |
| 84 |
} |
| 85 |
return 0; |
| 86 |
} |
| 87 |
|
| 88 |
static inline abpoa_cigar_t *abpoa_reverse_cigar(int n_cigar, abpoa_cigar_t *cigar) { |
| 89 |
int i; abpoa_cigar_t tmp; |
| 90 |
for (i = 0; i < n_cigar >> 1; ++i) { |
| 91 |
tmp = cigar[i]; |
| 92 |
cigar[i] = cigar[n_cigar-1-i]; |
| 93 |
cigar[n_cigar-1-i] = tmp; |
| 94 |
} |
| 95 |
return cigar; |
| 96 |
} |
| 97 |
|
| 98 |
static inline void abpoa_print_cigar(int n_cigar, abpoa_cigar_t *cigar, abpoa_graph_t *graph) { |
| 99 |
int i, node_id, query_id, index_i; int op, len; |
| 100 |
int n[6] = {0, 0, 0, 0, 0, 0}; |
| 101 |
for (i = 0; i < n_cigar; ++i) { |
| 102 |
op = cigar[i] & 0xf; node_id = (int)(cigar[i] >> 34); |
| 103 |
len = query_id = (int)(cigar[i] >> 4) & 0x3fffffff; |
| 104 |
if (op == ABPOA_CMATCH || op == ABPOA_CDIFF) { |
| 105 |
index_i = abpoa_graph_node_id_to_index(graph, node_id); |
| 106 |
printf("1%c:%d,%d\t", ABPOA_CIGAR_STR[op], index_i, query_id); |
| 107 |
n[op] += 1; |
| 108 |
} else if (op == ABPOA_CDEL) { |
| 109 |
index_i = abpoa_graph_node_id_to_index(graph, node_id); |
| 110 |
printf("%d%c:%d\t", len, ABPOA_CIGAR_STR[op], index_i); |
| 111 |
n[op] += len; |
| 112 |
} else if (op == ABPOA_CINS || op == ABPOA_CSOFT_CLIP || op == ABPOA_CHARD_CLIP) { |
| 113 |
query_id = node_id; |
| 114 |
printf("%d%c:%d\t", len, ABPOA_CIGAR_STR[op], query_id); |
| 115 |
n[op] += len; |
| 116 |
} else { |
| 117 |
err_fatal(__func__, "Unknown cigar operation: %s\n", op); |
| 118 |
} |
| 119 |
} printf("\n"); |
| 120 |
for (i = 0; i < 6; ++i) |
| 121 |
printf("%d%c ", n[i], ABPOA_CIGAR_STR[i]); |
| 122 |
printf("\n"); |
| 123 |
} |
| 124 |
|
| 125 |
#ifdef __cplusplus |
| 126 |
} |
| 127 |
#endif |
| 128 |
|
| 129 |
#endif |