minibwa 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +119 -0
- data/ext/minibwa/extconf.rb +105 -0
- data/ext/minibwa/mb_buffer.c +113 -0
- data/ext/minibwa/mb_hit.c +192 -0
- data/ext/minibwa/mb_index.c +462 -0
- data/ext/minibwa/mb_index_build.c +174 -0
- data/ext/minibwa/mb_options.c +301 -0
- data/ext/minibwa/minibwa/LICENSE.txt +37 -0
- data/ext/minibwa/minibwa/align.c +930 -0
- data/ext/minibwa/minibwa/bseq.h +45 -0
- data/ext/minibwa/minibwa/bwt.c +715 -0
- data/ext/minibwa/minibwa/bwt.h +86 -0
- data/ext/minibwa/minibwa/cs.c +161 -0
- data/ext/minibwa/minibwa/format.c +356 -0
- data/ext/minibwa/minibwa/index.c +342 -0
- data/ext/minibwa/minibwa/kalloc.c +224 -0
- data/ext/minibwa/minibwa/kalloc.h +54 -0
- data/ext/minibwa/minibwa/ketopt.h +123 -0
- data/ext/minibwa/minibwa/kommon.c +374 -0
- data/ext/minibwa/minibwa/kommon.h +85 -0
- data/ext/minibwa/minibwa/kseq.h +256 -0
- data/ext/minibwa/minibwa/ksort.h +163 -0
- data/ext/minibwa/minibwa/ksw2.h +220 -0
- data/ext/minibwa/minibwa/ksw2_extd2_sse.c +403 -0
- data/ext/minibwa/minibwa/ksw2_extz2_sse.c +296 -0
- data/ext/minibwa/minibwa/ksw2_ll_sse.c +341 -0
- data/ext/minibwa/minibwa/kthread.h +15 -0
- data/ext/minibwa/minibwa/l2bit.c +479 -0
- data/ext/minibwa/minibwa/l2bit.h +72 -0
- data/ext/minibwa/minibwa/lchain.c +231 -0
- data/ext/minibwa/minibwa/libsais.c +6985 -0
- data/ext/minibwa/minibwa/libsais.h +106 -0
- data/ext/minibwa/minibwa/libsais64.c +7064 -0
- data/ext/minibwa/minibwa/libsais64.h +81 -0
- data/ext/minibwa/minibwa/map-algo.c +769 -0
- data/ext/minibwa/minibwa/mbpriv.h +148 -0
- data/ext/minibwa/minibwa/minibwa.h +176 -0
- data/ext/minibwa/minibwa/options.c +116 -0
- data/ext/minibwa/minibwa/pe.c +559 -0
- data/ext/minibwa/minibwa/s2n-lite.h +59 -0
- data/ext/minibwa/minibwa/seed.c +354 -0
- data/ext/minibwa/minibwa.c +67 -0
- data/ext/minibwa/minibwa.h +51 -0
- data/lib/minibwa/hit.rb +110 -0
- data/lib/minibwa/index.rb +77 -0
- data/lib/minibwa/options.rb +235 -0
- data/lib/minibwa/sam.rb +85 -0
- data/lib/minibwa/version.rb +6 -0
- data/lib/minibwa.rb +11 -0
- metadata +88 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
#ifndef MBPRIV_H
|
|
2
|
+
#define MBPRIV_H
|
|
3
|
+
|
|
4
|
+
#include "minibwa.h"
|
|
5
|
+
#include "l2bit.h"
|
|
6
|
+
#include "bwt.h"
|
|
7
|
+
#include "kommon.h"
|
|
8
|
+
#include "bseq.h"
|
|
9
|
+
|
|
10
|
+
#define MB_DBG_ALN_SEQ (0x1LL)
|
|
11
|
+
#define MB_DBG_ANCHOR (0x2LL)
|
|
12
|
+
#define MB_DBG_SEED (0x4LL)
|
|
13
|
+
#define MB_DBG_QNAME (0x8LL)
|
|
14
|
+
#define MB_DBG_ALN_PE (0x10LL)
|
|
15
|
+
#define MB_DBG_AN_POS (0x20LL)
|
|
16
|
+
|
|
17
|
+
#define MB_SEED_LONG_JOIN 0x1
|
|
18
|
+
#define MB_SEED_IGNORE 0x2
|
|
19
|
+
|
|
20
|
+
struct mb_idx_s {
|
|
21
|
+
int32_t is_meth;
|
|
22
|
+
l2b_t *l2b;
|
|
23
|
+
mb_bwt_t *bwt;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
typedef struct {
|
|
27
|
+
int32_t sid; // tid<<1|rev
|
|
28
|
+
int32_t len; // length of the anchor
|
|
29
|
+
int32_t qpos; // the query coordinate of the last base in the anchor; the start base is qpos+1-len; flipped by rev
|
|
30
|
+
uint32_t flag:31, flt:1;
|
|
31
|
+
int64_t tpos; // target/contig coordinate
|
|
32
|
+
} mb_anchor_t;
|
|
33
|
+
|
|
34
|
+
typedef struct { int64_t n, m; mb_anchor_t *a; } mb_anchor_v;
|
|
35
|
+
|
|
36
|
+
typedef struct {
|
|
37
|
+
int lo, hi; // lower and upper bounds within which a read pair is considered to be properly paired
|
|
38
|
+
int failed; // non-zero if the orientation is not supported by sufficient data
|
|
39
|
+
double avg, std; // mean and stddev of the insert size distribution
|
|
40
|
+
} mb_pestat_t;
|
|
41
|
+
|
|
42
|
+
typedef struct { uint64_t x, y; } mb128_t;
|
|
43
|
+
void radix_sort_mb128x(mb128_t *beg, mb128_t *end);
|
|
44
|
+
|
|
45
|
+
#ifdef __cplusplus
|
|
46
|
+
extern "C" {
|
|
47
|
+
#endif
|
|
48
|
+
|
|
49
|
+
// defined in options.c
|
|
50
|
+
void mb_opt_adap(const mb_opt_t *opt0, int32_t len, mb_opt_t *opt);
|
|
51
|
+
|
|
52
|
+
// defined in bwtgen.c
|
|
53
|
+
void mb_bwtgen(const char *fn_pac, const char *fn_bwt, int block_size);
|
|
54
|
+
|
|
55
|
+
// defined in seed.c
|
|
56
|
+
void mb_seed_intv(void *km, const mb_bwt_t *bwt, int32_t len, const uint8_t *seq, int32_t min_len, int32_t max_sub_occ, mb_sai_v *v);
|
|
57
|
+
void mb_seed_intv_batch(void *km, const mb_bwt_t *bwt, int32_t n_seq, const int32_t *len, uint8_t *const* seq, int32_t min_len, int32_t max_sub_occ, mb_sai_v *v);
|
|
58
|
+
double mb_anchor(void *km, const mb_idx_t *idx, mb_sai_v *u, int32_t min_len, int32_t qlen, const uint8_t *qseq, l2b_meth_t mt, int32_t max_occ, mb_anchor_v *v);
|
|
59
|
+
void mb_anchor_sort(const l2b_t *l2b, int64_t n_a, mb_anchor_t *a);
|
|
60
|
+
|
|
61
|
+
// defined in lchain.c
|
|
62
|
+
mb_anchor_t *mb_lchain_dp(void *km, const l2b_t *l2b, int max_dist_x, int max_dist_y, int bw, int max_skip, int max_iter, int min_sc, float chn_pen_gap,
|
|
63
|
+
int64_t n, mb_anchor_t *a, int *n_u_, uint64_t **_u);
|
|
64
|
+
|
|
65
|
+
// defined in map-algo.c
|
|
66
|
+
void *mb_tbuf_km(mb_tbuf_t *b);
|
|
67
|
+
int32_t mb_cal_mblen(int32_t n, const mb_anchor_t *a, int32_t *blen_);
|
|
68
|
+
mb_hit_t *mb_gen_hit(void *km, uint32_t hash, int qlen, const l2b_t *l2b, int n_u, uint64_t *u, mb_anchor_t *a);
|
|
69
|
+
void mb_sync_high_cov(int32_t n, mb_hit_t *h);
|
|
70
|
+
void mb_set_parent(void *km, float mask_level, int mask_len, int n, mb_hit_t *r, int sub_diff, int hard_mask_level);
|
|
71
|
+
void mb_set_sam_pri(int32_t n, mb_hit_t *r, int32_t is_primary5);
|
|
72
|
+
void mb_hit_sort(void *km, int *n_regs, mb_hit_t *r);
|
|
73
|
+
void mb_sync_hits(void *km, int n_regs, mb_hit_t *regs);
|
|
74
|
+
void mb_select_sub(void *km, float pri_ratio, int min_diff, int best_n, int *n_, mb_hit_t *r);
|
|
75
|
+
void mb_filter_hits(const mb_opt_t *opt, int qlen, int *n_regs, mb_hit_t *regs);
|
|
76
|
+
int mb_squeeze_a(void *km, int n_regs, mb_hit_t *regs, mb_anchor_t *a);
|
|
77
|
+
void mb_split_hit(mb_hit_t *r, mb_hit_t *r2, int n, int qlen, mb_anchor_t *a, const l2b_t *l2b);
|
|
78
|
+
void mb_set_mapq(void *km, int32_t qlen, int n_regs, mb_hit_t *regs, int min_chain_sc, int match_sc, int is_sr, int max_sr_len);
|
|
79
|
+
|
|
80
|
+
mb_hit_t *mb_map_sai(const mb_opt_t *opt, const mb_idx_t *idx, int64_t qlen, const char *seq, l2b_meth_t mt, mb_sai_v *u, int32_t *n_hit_, mb_tbuf_t *b, const char *qname);
|
|
81
|
+
|
|
82
|
+
void radix_sort_mb64(uint64_t *st, uint64_t *en);
|
|
83
|
+
void radix_sort_mb128x(mb128_t *st, mb128_t *en);
|
|
84
|
+
|
|
85
|
+
// in cs.c
|
|
86
|
+
void mb_write_cs_ds(void *km, kstring_t *s, const uint8_t *tseq, const uint8_t *qseq, const mb_hit_t *r, int is_ds);
|
|
87
|
+
void mb_write_MD(void *km, kstring_t *s, const uint8_t *tseq, const uint8_t *qseq, const mb_hit_t *r);
|
|
88
|
+
|
|
89
|
+
// defined in format.c
|
|
90
|
+
void mb_fmt_paf(kstring_t *s, const l2b_t *l2b, const mb_bseq1_t *t, const mb_hit_t *p, uint64_t opt_flag, int n_seg, int seg_idx);
|
|
91
|
+
int mb_fmt_sam_hdr(kstring_t *str, const l2b_t *idx, const char *rg, const char *ver, int argc, char *argv[]);
|
|
92
|
+
void mb_format(void *km, kstring_t *s, const l2b_t *l2b, const mb_bseq1_t *t, int32_t n_seg, const int32_t *n_hit, mb_hit_t *const*hit, int32_t hit_idx, const mb_opt_t *opt, int seg_idx, int32_t mate_qlen);
|
|
93
|
+
char *mb_escape(char *s);
|
|
94
|
+
|
|
95
|
+
// defined in align.c
|
|
96
|
+
mb_hit_t *mb_align_skeleton(void *km, const mb_opt_t *opt, const mb_idx_t *mi, int qlen, const uint8_t *seq, l2b_meth_t mt, int *n_regs_, mb_hit_t *regs, mb_anchor_t *a);
|
|
97
|
+
void mb_append_cigar(mb_hit_t *r, uint32_t n_cigar, const uint32_t *cigar);
|
|
98
|
+
void mb_update_extra(void *km, mb_hit_t *r, const uint8_t *qseq, const uint8_t *tseq, const int8_t *mat, int8_t q, int8_t e, uint64_t opt_flag, int log_gap);
|
|
99
|
+
|
|
100
|
+
// defined in pe.c
|
|
101
|
+
void mb_pestat(void *km, const mb_opt_t *opt, int32_t n_seg, const int32_t *seg_off, const int32_t *seg_cnt, const int32_t *n_hit, mb_hit_t *const *hit, mb_pestat_t pes[4]);
|
|
102
|
+
void mb_pair(void *km, const mb_opt_t *opt, const l2b_t *l2b, int32_t n_hit[2], mb_hit_t *hit[2], const mb_pestat_t pes[4], int32_t qlen[2], char *const qseq[2]);
|
|
103
|
+
|
|
104
|
+
// Fast log2 approximation (from minimap2)
|
|
105
|
+
static inline float mb_log2(float x) // NB: this doesn't work when x<2
|
|
106
|
+
{
|
|
107
|
+
union { float f; uint32_t i; } z = { x };
|
|
108
|
+
float log_2 = ((z.i >> 23) & 255) - 128;
|
|
109
|
+
z.i &= ~(255 << 23);
|
|
110
|
+
z.i += 127 << 23;
|
|
111
|
+
log_2 += (-0.34484843f * z.f + 2.02466578f) * z.f - 0.67487759f;
|
|
112
|
+
return log_2;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
static inline uint64_t mb_hash64(uint64_t x)
|
|
116
|
+
{
|
|
117
|
+
x ^= x >> 30;
|
|
118
|
+
x *= 0xbf58476d1ce4e5b9ULL;
|
|
119
|
+
x ^= x >> 27;
|
|
120
|
+
x *= 0x94d049bb133111ebULL;
|
|
121
|
+
x ^= x >> 31;
|
|
122
|
+
return x;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
static inline uint32_t mb_hash_str(const char *s)
|
|
126
|
+
{
|
|
127
|
+
uint32_t h = 2166136261U;
|
|
128
|
+
const unsigned char *t = (const unsigned char*)s;
|
|
129
|
+
for (; *t; ++t)
|
|
130
|
+
h ^= *t, h *= 16777619;
|
|
131
|
+
return h;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
static inline void mb_seq_rev(uint32_t len, uint8_t *seq)
|
|
135
|
+
{
|
|
136
|
+
kom_reverse(uint8_t, len, seq);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
static inline int32_t mb_is_sr_mode(const mb_opt_t *opt, int32_t qlen)
|
|
140
|
+
{
|
|
141
|
+
return (opt->flag & MB_F_LONG) || ((opt->flag & MB_F_ADAP) && qlen > opt->max_sr_len)? 0 : 1;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
#ifdef __cplusplus
|
|
145
|
+
}
|
|
146
|
+
#endif
|
|
147
|
+
|
|
148
|
+
#endif
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
#ifndef MINIBWA_H
|
|
2
|
+
#define MINIBWA_H
|
|
3
|
+
|
|
4
|
+
#include <stdint.h>
|
|
5
|
+
|
|
6
|
+
#define MB_VERSION "0.6-r416"
|
|
7
|
+
|
|
8
|
+
#define MB_F_PAF (0x1LL) // output in the PAF format
|
|
9
|
+
#define MB_F_NO_UNMAP (0x2LL) // output unmapped query sequences
|
|
10
|
+
#define MB_F_COPY_COMMENT (0x4LL) // copy FASTX comments to output
|
|
11
|
+
#define MB_F_PE (0x8LL) // paired-end mode
|
|
12
|
+
#define MB_F_LONG (0x10LL) // long-sequence mode
|
|
13
|
+
#define MB_F_EQX (0x20LL) // = in CIGAR
|
|
14
|
+
#define MB_F_NO_KALLOC (0x40LL) // disable kalloc
|
|
15
|
+
#define MB_F_NO_ALN (0x80LL) // skip base alignment
|
|
16
|
+
#define MB_F_PE_PREDEF (0x100LL) // use predefined PE
|
|
17
|
+
#define MB_F_WRITE_DS (0x200LL) // write ds:Z
|
|
18
|
+
#define MB_F_WRITE_CS (0x400LL) // write cs:Z
|
|
19
|
+
#define MB_F_WRITE_MD (0x800LL) // write MD:Z
|
|
20
|
+
#define MB_F_2ND_SEQ (0x1000LL) // in SAM, write SEQ for secondary alignments
|
|
21
|
+
#define MB_F_SUPP_SOFT (0x2000LL) // in SAM, use soft-clips for supplementary alignments
|
|
22
|
+
#define MB_F_ADAP (0x4000LL) // adaptive mode
|
|
23
|
+
#define MB_F_PRIMARY5 (0x8000LL) // for Hi-C
|
|
24
|
+
#define MB_F_NO_PAIRING (0x10000LL) // don't pair reads
|
|
25
|
+
#define MB_F_METH (0x20000LL) // methylation mode
|
|
26
|
+
|
|
27
|
+
#define MB_CIGAR_MATCH 0
|
|
28
|
+
#define MB_CIGAR_INS 1
|
|
29
|
+
#define MB_CIGAR_DEL 2
|
|
30
|
+
#define MB_CIGAR_N_SKIP 3
|
|
31
|
+
#define MB_CIGAR_SOFTCLIP 4
|
|
32
|
+
#define MB_CIGAR_HARDCLIP 5
|
|
33
|
+
#define MB_CIGAR_PADDING 6
|
|
34
|
+
#define MB_CIGAR_EQ_MATCH 7
|
|
35
|
+
#define MB_CIGAR_X_MISMATCH 8
|
|
36
|
+
|
|
37
|
+
#define MB_CIGAR_STR "MIDNSHP=XB"
|
|
38
|
+
|
|
39
|
+
typedef struct {
|
|
40
|
+
uint64_t flag;
|
|
41
|
+
// seeding options
|
|
42
|
+
int32_t min_len; // min seed length
|
|
43
|
+
int32_t max_sub_occ; // look for shorter seed if smem occ below this value
|
|
44
|
+
int32_t max_occ; // max interval occurrence
|
|
45
|
+
// general algorithm options
|
|
46
|
+
int32_t bw, bw_long; // bandwidth
|
|
47
|
+
int32_t max_gap; // break a chain if there are no seeds in a max_gap window
|
|
48
|
+
int32_t max_sr_len; // in the adaptive sr mode, treat reads longer than this as long reads
|
|
49
|
+
// chaining options
|
|
50
|
+
int32_t max_chain_skip;
|
|
51
|
+
int32_t max_chain_iter;
|
|
52
|
+
int32_t min_chain_score; // min chaining score
|
|
53
|
+
float chain_gap_scale;
|
|
54
|
+
// hit processing options
|
|
55
|
+
float mask_level;
|
|
56
|
+
int32_t mask_len;
|
|
57
|
+
float pri_ratio;
|
|
58
|
+
int32_t best_n;
|
|
59
|
+
// alignment options
|
|
60
|
+
int32_t a, b; // match, mismatch
|
|
61
|
+
int32_t b_ts; // transition mismatch
|
|
62
|
+
int32_t b_ambi; // ambiguous mismatch
|
|
63
|
+
int32_t q, q2; // gap open, long gap open
|
|
64
|
+
int32_t e, e2; // gap extension, long gap extension
|
|
65
|
+
int32_t end_bonus;
|
|
66
|
+
int32_t min_dp_max; // min_dp_max*a is the min score
|
|
67
|
+
int32_t zdrop;
|
|
68
|
+
int32_t zdrop_inv;
|
|
69
|
+
int32_t min_ksw_len;
|
|
70
|
+
// pairing options
|
|
71
|
+
int32_t max_pe_ins;
|
|
72
|
+
int32_t max_rescue;
|
|
73
|
+
int32_t pen_unpair;
|
|
74
|
+
int32_t pe_avg, pe_std, pe_lo, pe_hi;
|
|
75
|
+
// input/output options
|
|
76
|
+
int32_t sb_len; // number of bases for batch smem
|
|
77
|
+
int32_t sb_seq; // number of sequences for batch smem
|
|
78
|
+
int32_t n_thread; // number of worker threads, excluding I/O threads
|
|
79
|
+
int32_t out_n; // max number of secondary alignments to output
|
|
80
|
+
float out_s;
|
|
81
|
+
int32_t seed;
|
|
82
|
+
int32_t xa_max;
|
|
83
|
+
int64_t mb_size; // mini-batch size
|
|
84
|
+
int64_t max_mb_size;
|
|
85
|
+
int64_t max_sw_mat;
|
|
86
|
+
int64_t cap_kalloc;
|
|
87
|
+
} mb_opt_t;
|
|
88
|
+
|
|
89
|
+
struct mb_idx_s;
|
|
90
|
+
typedef struct mb_idx_s mb_idx_t;
|
|
91
|
+
|
|
92
|
+
typedef struct {
|
|
93
|
+
uint32_t cap; // the capacity of cigar[]
|
|
94
|
+
int32_t dp_score, dp_max0; // DP score; score of the max-scoring segment
|
|
95
|
+
int32_t dp_max, dp_max2; // adjusted score and second best score for mapQ
|
|
96
|
+
uint32_t n_ambi:31, cs:1; // number of ambiguous bases;
|
|
97
|
+
int32_t n_cigar; // number of cigar operations in cigar[]
|
|
98
|
+
uint32_t cigar[]; // cs/MD is appended at the end
|
|
99
|
+
} mb_extra_t;
|
|
100
|
+
|
|
101
|
+
#define MB_PARENT_UNSET (-1)
|
|
102
|
+
#define MB_PARENT_TMP_PRI (-2)
|
|
103
|
+
|
|
104
|
+
typedef struct {
|
|
105
|
+
int64_t tid; // target ID (the original tid, NOT stranded)
|
|
106
|
+
int64_t ts, te; // target start and end
|
|
107
|
+
int32_t id; // ID for internal uses
|
|
108
|
+
int32_t cnt; // number of anchors
|
|
109
|
+
int32_t score, score0; // chaining score; score0 is the original chaining score
|
|
110
|
+
int32_t as; // offset in the a[] array (for internal uses only)
|
|
111
|
+
int32_t qs, qe; // query start and end
|
|
112
|
+
int32_t parent, n_sub, subsc;
|
|
113
|
+
int32_t mlen, blen;
|
|
114
|
+
int32_t mapq;
|
|
115
|
+
uint32_t hash;
|
|
116
|
+
uint32_t rev:1, proper_pair:1, sam_pri:1, flt:1, inv:1, split:2, split_inv:1, rescued:1, frac_high:8, seed_ratio:8, dummy:7;
|
|
117
|
+
mb_extra_t *p;
|
|
118
|
+
} mb_hit_t;
|
|
119
|
+
|
|
120
|
+
struct mb_tbuf_s;
|
|
121
|
+
typedef struct mb_tbuf_s mb_tbuf_t;
|
|
122
|
+
|
|
123
|
+
#ifdef __cplusplus
|
|
124
|
+
extern "C" {
|
|
125
|
+
#endif
|
|
126
|
+
|
|
127
|
+
mb_idx_t *mb_idx_load(const char *prefix, int32_t is_meth);
|
|
128
|
+
mb_idx_t *mb_idx_load_mmap(const char *prefix, int32_t is_meth, int preload);
|
|
129
|
+
void mb_idx_destroy(mb_idx_t *idx);
|
|
130
|
+
const char *mb_idx_ctg_name(const mb_idx_t *idx, int32_t tid);
|
|
131
|
+
int64_t mb_idx_ctg_len(const mb_idx_t *idx, int32_t tid);
|
|
132
|
+
|
|
133
|
+
void mb_opt_init(mb_opt_t *opt);
|
|
134
|
+
int mb_opt_preset(mb_opt_t *opt, const char *preset);
|
|
135
|
+
|
|
136
|
+
mb_tbuf_t *mb_tbuf_init(int no_kalloc);
|
|
137
|
+
void mb_tbuf_destroy(mb_tbuf_t *b);
|
|
138
|
+
int32_t mb_tbuf_reset(mb_tbuf_t *b, int64_t max_block_size);
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Align one sequence
|
|
142
|
+
*
|
|
143
|
+
* @param opt options, typically initialized by mb_opt_init()
|
|
144
|
+
* @param idx index
|
|
145
|
+
* @param qlen query length
|
|
146
|
+
* @param seq query sequence, ASCII or 01/2/3 encoded
|
|
147
|
+
* @param mt methylation type: 0 for unmethylated, 1 for read1 (C-to-T) and 2 for read2 (G-to-A)
|
|
148
|
+
* @param n_hit (out) number of hits
|
|
149
|
+
* @param b thread buffer; can be NULL
|
|
150
|
+
* @param qname query name
|
|
151
|
+
*
|
|
152
|
+
* @return hit array
|
|
153
|
+
*/
|
|
154
|
+
mb_hit_t *mb_map(const mb_opt_t *opt, const mb_idx_t *idx, int32_t qlen, const char *seq, int32_t mt, int32_t *n_hit, mb_tbuf_t *b, const char *qname);
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Align a set of sequences in batch
|
|
158
|
+
*
|
|
159
|
+
* @param opt options, typically initialized by mb_opt_init()
|
|
160
|
+
* @param idx index
|
|
161
|
+
* @param n_seq number of sequences
|
|
162
|
+
* @param qlen query lengths, of size n_seq
|
|
163
|
+
* @param seq query sequences, ASCII or 01/2/3 encoded, of size n_seq
|
|
164
|
+
* @param n_hit (out) number of hits, of size n_seq
|
|
165
|
+
* @param b thread buffer; can be NULL
|
|
166
|
+
* @param qname query name, of size n_seq
|
|
167
|
+
*
|
|
168
|
+
* @return hits, of size n_seq
|
|
169
|
+
*/
|
|
170
|
+
mb_hit_t **mb_map_batch(const mb_opt_t *opt, const mb_idx_t *idx, int32_t n_seq, const int32_t *qlen, const char **seq, int32_t *n_hit, mb_tbuf_t *b, const char **qname);
|
|
171
|
+
|
|
172
|
+
#ifdef __cplusplus
|
|
173
|
+
}
|
|
174
|
+
#endif
|
|
175
|
+
|
|
176
|
+
#endif
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#include <string.h>
|
|
2
|
+
#include <math.h>
|
|
3
|
+
#include "minibwa.h"
|
|
4
|
+
|
|
5
|
+
static void mb_opt_reset(mb_opt_t *opt)
|
|
6
|
+
{
|
|
7
|
+
memset(opt, 0, sizeof(mb_opt_t));
|
|
8
|
+
opt->min_len = 19;
|
|
9
|
+
opt->max_sr_len = 325;
|
|
10
|
+
// seeding options
|
|
11
|
+
opt->max_sub_occ = 10;
|
|
12
|
+
opt->max_occ = 250;
|
|
13
|
+
// chaining options
|
|
14
|
+
opt->max_chain_skip = 25;
|
|
15
|
+
opt->max_chain_iter = 5000;
|
|
16
|
+
opt->chain_gap_scale = 0.8f;
|
|
17
|
+
opt->bw_long = 20000;
|
|
18
|
+
opt->pri_ratio = 0.5f;
|
|
19
|
+
// hit processing options
|
|
20
|
+
opt->mask_level = 0.5f;
|
|
21
|
+
opt->mask_len = 0x7fffffff;
|
|
22
|
+
// alignment options
|
|
23
|
+
opt->a = 2, opt->b = 8;
|
|
24
|
+
opt->q = 12, opt->q2 = 23;
|
|
25
|
+
opt->e = 2, opt->e2 = 1;
|
|
26
|
+
opt->b_ambi = 1;
|
|
27
|
+
// pairing options
|
|
28
|
+
opt->max_pe_ins = 10000;
|
|
29
|
+
opt->max_rescue = 10;
|
|
30
|
+
opt->pen_unpair = 17;
|
|
31
|
+
opt->pe_avg = 400, opt->pe_std = 100;
|
|
32
|
+
opt->pe_lo = 50, opt->pe_hi = 800;
|
|
33
|
+
// I/O options
|
|
34
|
+
opt->sb_len = 1000000;
|
|
35
|
+
opt->sb_seq = 24;
|
|
36
|
+
opt->n_thread = 1;
|
|
37
|
+
opt->seed = 11;
|
|
38
|
+
opt->out_s = 0.8f;
|
|
39
|
+
opt->xa_max = 5;
|
|
40
|
+
opt->max_sw_mat = 100000000;
|
|
41
|
+
opt->cap_kalloc = 1UL<<28;
|
|
42
|
+
opt->max_mb_size = 1000000000;
|
|
43
|
+
#ifndef HAVE_KALLOC
|
|
44
|
+
opt->flag |= MB_F_NO_KALLOC;
|
|
45
|
+
#endif
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
void mb_opt_init(mb_opt_t *opt)
|
|
49
|
+
{
|
|
50
|
+
mb_opt_reset(opt);
|
|
51
|
+
mb_opt_preset(opt, "adap");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
int mb_opt_preset(mb_opt_t *opt, const char *preset)
|
|
55
|
+
{
|
|
56
|
+
mb_opt_reset(opt);
|
|
57
|
+
if (strcmp(preset, "sr") == 0 || strcmp(preset, "adap") == 0) {
|
|
58
|
+
opt->flag |= MB_F_PE;
|
|
59
|
+
if (strcmp(preset, "adap") == 0) opt->flag |= MB_F_ADAP;
|
|
60
|
+
opt->min_dp_max = 30;
|
|
61
|
+
opt->flag |= MB_F_ADAP;
|
|
62
|
+
opt->bw = 100;
|
|
63
|
+
opt->max_gap = 100;
|
|
64
|
+
opt->zdrop = 80;
|
|
65
|
+
opt->zdrop_inv = 80;
|
|
66
|
+
opt->best_n = 50;
|
|
67
|
+
opt->end_bonus = 10;
|
|
68
|
+
opt->min_chain_score = 25;
|
|
69
|
+
opt->min_ksw_len = 20;
|
|
70
|
+
opt->mb_size = 100000000;
|
|
71
|
+
} else if (strcmp(preset, "lr") == 0) {
|
|
72
|
+
opt->flag |= MB_F_LONG;
|
|
73
|
+
opt->flag &= ~MB_F_PE;
|
|
74
|
+
opt->min_dp_max = 50;
|
|
75
|
+
opt->bw = 500;
|
|
76
|
+
opt->max_gap = 5000;
|
|
77
|
+
opt->zdrop = 400;
|
|
78
|
+
opt->zdrop_inv = 240;
|
|
79
|
+
opt->best_n = 5;
|
|
80
|
+
opt->end_bonus = -1;
|
|
81
|
+
opt->min_chain_score = 40;
|
|
82
|
+
opt->min_ksw_len = 200;
|
|
83
|
+
opt->mb_size = 500000000;
|
|
84
|
+
} else {
|
|
85
|
+
return -1;
|
|
86
|
+
}
|
|
87
|
+
return 0;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
void mb_opt_adap(const mb_opt_t *opt0, int32_t len, mb_opt_t *opt)
|
|
91
|
+
{
|
|
92
|
+
const int32_t min_len = 100, mid_len = 2000;
|
|
93
|
+
double a, b;
|
|
94
|
+
*opt = *opt0;
|
|
95
|
+
if (!(opt0->flag & MB_F_ADAP)) return;
|
|
96
|
+
a = -log(0.5) / (mid_len - min_len);
|
|
97
|
+
b = exp(-a * ((len > min_len? len : min_len) - min_len));
|
|
98
|
+
if (opt0->max_gap < 5000) {
|
|
99
|
+
opt->max_gap = (int32_t)(5000 - (5000 - opt0->max_gap) * b + .499);
|
|
100
|
+
if (opt->max_gap > len) opt->max_gap = len;
|
|
101
|
+
}
|
|
102
|
+
if (opt0->bw < 500)
|
|
103
|
+
opt->bw = (int32_t)(500 - (500 - opt0->bw) * b + .499);
|
|
104
|
+
if (opt->bw_long > len * 5) opt->bw_long = len * 5;
|
|
105
|
+
if (opt->bw_long < opt->bw) opt->bw_long = opt->bw;
|
|
106
|
+
if (opt0->zdrop < 400)
|
|
107
|
+
opt->zdrop = (int32_t)(400 - (400 - opt0->zdrop) * b + .499);
|
|
108
|
+
if (opt0->zdrop_inv < 240)
|
|
109
|
+
opt->zdrop_inv = (int32_t)(240 - (240 - opt0->zdrop_inv) * b + .499);
|
|
110
|
+
if (opt0->best_n > 5)
|
|
111
|
+
opt->best_n = (int32_t)((opt0->best_n - 5) * b + 5 + .499);
|
|
112
|
+
if (opt0->min_dp_max < 50)
|
|
113
|
+
opt->min_dp_max = (int32_t)(50 - (50 - opt0->min_dp_max) * b + .499);
|
|
114
|
+
if (opt0->min_chain_score < 40)
|
|
115
|
+
opt->min_chain_score = (int32_t)(40 - (40 - opt0->min_chain_score) * b + .499);
|
|
116
|
+
}
|