Exemplo n.º 1
0
mem_opt_t *mem_opt_init()
{
	mem_opt_t *o;
	o = calloc(1, sizeof(mem_opt_t));
	o->flag = 0;
	o->a = 1; o->b = 4;
	o->o_del = o->o_ins = 6;
	o->e_del = o->e_ins = 1;
	o->w = 100;
	o->T = 30;
	o->zdrop = 100;
	o->pen_unpaired = 17;
	o->pen_clip5 = o->pen_clip3 = 5;
	o->min_seed_len = 19;
	o->split_width = 10;
	o->max_occ = 500;
	o->max_chain_gap = 10000;
	o->max_ins = 10000;
	o->mask_level = 0.50;
	o->drop_ratio = 0.50;
	o->XA_drop_ratio = 0.80;
	o->split_factor = 1.5;
	o->chunk_size = 10000000;
	o->n_threads = 1;
	o->max_hits = 5;
	o->max_matesw = 50;
	o->mask_level_redun = 0.95;
	o->min_chain_weight = 0;
	o->max_chain_extend = 1<<30;
	o->mapQ_coef_len = 50; o->mapQ_coef_fac = log(o->mapQ_coef_len);
	bwa_fill_scmat(o->a, o->b, o->mat);
	return o;
}
Exemplo n.º 2
0
void bsw2_extend_rght(const bsw2opt_t *opt, bwtsw2_t *b, uint8_t *query, int lq, uint8_t *pac, bwtint_t l_pac, uint8_t *_mem)
{
	int i;
	bwtint_t k;
	uint8_t *target;
	int8_t mat[25];

	bwa_fill_scmat(opt->a, opt->b, mat);
	target = calloc(((lq + 1) / 2 * opt->a + opt->r) / opt->r + lq, 1);
	for (i = 0; i < b->n; ++i) {
		bsw2hit_t *p = b->hits + i;
		int lt = ((lq - p->beg + 1) / 2 * opt->a + opt->r) / opt->r + lq;
		int j, score, qle, tle;
		if (p->l) continue;
		for (k = p->k, j = 0; k < p->k + lt && k < l_pac; ++k)
			target[j++] = pac[k>>2] >> (~k&3)*2 & 0x3;
		lt = j;
		score = ksw_extend(lq - p->beg, &query[p->beg], lt, target, 5, mat, opt->q, opt->r, opt->bw, 0, -1, 1, &qle, &tle, 0, 0, 0) - 1;
//		if (score < p->G) fprintf(stderr, "[bsw2_extend_hits] %d < %d\n", score, p->G);
		if (score >= p->G) {
			p->G = score;
			p->len = tle;
			p->end = p->beg + qle;
		}
	}
	free(target);
}
Exemplo n.º 3
0
void bsw2_extend_left(const bsw2opt_t *opt, bwtsw2_t *b, uint8_t *_query, int lq, uint8_t *pac, bwtint_t l_pac, uint8_t *_mem)
{
	int i;
	bwtint_t k;
	uint8_t *target = 0, *query;
	int8_t mat[25];

	bwa_fill_scmat(opt->a, opt->b, mat);
	query = calloc(lq, 1);
	// sort according to the descending order of query end
	ks_introsort(hit, b->n, b->hits);
	target = calloc(((lq + 1) / 2 * opt->a + opt->r) / opt->r + lq, 1);
	// reverse _query
	for (i = 0; i < lq; ++i) query[lq - i - 1] = _query[i];
	// core loop
	for (i = 0; i < b->n; ++i) {
		bsw2hit_t *p = b->hits + i;
		int lt = ((p->beg + 1) / 2 * opt->a + opt->r) / opt->r + lq;
		int score, j, qle, tle;
		p->n_seeds = 1;
		if (p->l || p->k == 0) continue;
		for (j = score = 0; j < i; ++j) {
			bsw2hit_t *q = b->hits + j;
			if (q->beg <= p->beg && q->k <= p->k && q->k + q->len >= p->k + p->len) {
				if (q->n_seeds < (1<<13) - 2) ++q->n_seeds;
				++score;
			}
		}
		if (score) continue;
		if (lt > p->k) lt = p->k;
		for (k = p->k - 1, j = 0; k > 0 && j < lt; --k) // FIXME: k=0 not considered!
			target[j++] = pac[k>>2] >> (~k&3)*2 & 0x3;
		lt = j;
		score = ksw_extend(p->beg, &query[lq - p->beg], lt, target, 5, mat, opt->q, opt->r, opt->bw, 0, -1, p->G, &qle, &tle, 0, 0, 0);
		if (score > p->G) { // extensible
			p->G = score;
			p->k -= tle;
			p->len += tle;
			p->beg -= qle;
		}
	}
	free(query); free(target);
}
Exemplo n.º 4
0
/* generate CIGAR array(s) in b->cigar[] */
static void gen_cigar(const bsw2opt_t *opt, int lq, uint8_t *seq[2], int64_t l_pac, const uint8_t *pac, bwtsw2_t *b, const char *name)
{
	int i;
	int8_t mat[25];

	bwa_fill_scmat(opt->a, opt->b, mat);
	for (i = 0; i < b->n; ++i) {
		bsw2hit_t *p = b->hits + i;
		bsw2aux_t *q = b->aux + i;
		uint8_t *query;
		int beg, end, score;
		if (p->l) continue;
		beg = (p->flag & 0x10)? lq - p->end : p->beg;
		end = (p->flag & 0x10)? lq - p->beg : p->end;
		query = seq[(p->flag & 0x10)? 1 : 0] + beg;
		q->cigar = bwa_gen_cigar(mat, opt->q, opt->r, opt->bw, l_pac, pac, end - beg, query, p->k, p->k + p->len, &score, &q->n_cigar, &q->nm);
#if 0
		if (name && score != p->G) { // debugging only
			int j, glen = 0;
			for (j = 0; j < q->n_cigar; ++j)
				if ((q->cigar[j]&0xf) == 1 || (q->cigar[j]&0xf) == 2)
					glen += q->cigar[j]>>4;
			fprintf(stderr, "[E::%s] %s - unequal score: %d != %d; (qlen, aqlen, arlen, glen, bw) = (%d, %d, %d, %d, %d)\n",
					__func__, name, score, p->G, lq, end - beg, p->len, glen, opt->bw);
		}
#endif
		if (q->cigar && (beg != 0 || end < lq)) { // write soft clipping
			q->cigar = realloc(q->cigar, 4 * (q->n_cigar + 2));
			if (beg != 0) {
				memmove(q->cigar + 1, q->cigar, q->n_cigar * 4);
				q->cigar[0] = beg<<4 | 4;
				++q->n_cigar;
			}
			if (end < lq) {
				q->cigar[q->n_cigar] = (lq - end)<<4 | 4;
				++q->n_cigar;
			}
		}
	}