Example #1
0
int edview_search_cons_discrep(edview *xx, int dir, int strand, char *value) {
    int start, end;
    int found = 0, at_end = 0;
    int fpos, i;
    double qval = atof(value);
    consensus_t cons[WIN_WIDTH+1];
    contig_t *c;

    /* Set initial start positions */
    if (dir) {
	start = xx->cursor_apos + (dir ? 1 : -1);
	end   = start + (WIN_WIDTH-1);
    } else {
	end   = xx->cursor_apos + (dir ? 1 : -1);
	start = end - (WIN_WIDTH-1);
    }
    fpos = xx->cursor_apos;

    /* Loop WIN_WIDTH block at a time */
    c = cache_search(xx->io, GT_Contig, xx->cnum);
    cache_incr(xx->io, c);
    do {
	calculate_consensus(xx->io, xx->cnum, start, end, cons);

	if (dir) {
	    for (i = 0; i < WIN_WIDTH; i++) {
		if (cons[i].discrep >= qval) {
		    found = 1;
		    break;
		}
	    }
	} else {
	    for (i = WIN_WIDTH-1; i; i--) {
		if (cons[i].discrep >= qval) {
		    found = 1;
		    break;
		}
	    }
	}

	if (found) {
	    fpos = start + i;
	    break;
	}

	/* Next search region - overlapping by patlen+pads */
	if (dir) {
	    start += WIN_WIDTH;
	    end   += WIN_WIDTH;

	    if (start > c->end)
		at_end = 1;
	} else {
	    start -= WIN_WIDTH;
	    end   -= WIN_WIDTH;

	    if (end < c->start)
		at_end = 1;
	}
    } while (!at_end);
    cache_decr(xx->io, c);

    if (found) {
	edSetCursorPos(xx, GT_Contig, xx->cnum, fpos, 1);
	return 0;
    }

    return -1;
}
Example #2
0
/*
 * ----------------------------------------------------------------------
 * Remove Pad Columns. Sometimes we don't want to realign data, we just
 * want to remove (aligned) columns of pads.
 * ----------------------------------------------------------------------
 */
int remove_pad_columns(GapIO *io, int ncontigs, contig_list_t *contigs,
		       int percent_pad, int quiet) {
    int i;
    consensus_t *cons = NULL;
    size_t max_alloc = 0;

    for (i = 0; i < ncontigs; i++) {
	tg_rec cnum = contigs[i].contig;
	size_t len, j;
	int ndel = 0;
	contig_t *c;

	if (!quiet) {
	    vmessage("Processing contig %d of %d (#%"PRIrec")\n",
		     i+1, ncontigs, cnum);
	    UpdateTextOutput();
	}

	c = cache_search(io, GT_Contig, cnum);
	if (!c)
	    return -1;

	cache_incr(io, c);
	
	len = contigs[i].end - contigs[i].start + 1;
	if (max_alloc < len) {
	    max_alloc = len;
	    cons = realloc(cons, max_alloc * sizeof(*cons));
	}
	
	if (0 != calculate_consensus(io, cnum,
				     contigs[i].start, contigs[i].end,
				     cons)) {
	    free(cons);
	    cache_decr(io, c);
	    return -1;
	}

	for (j = 0; j < len; j++) {
	    if (cons[j].call != 4)
		continue;

	    if (100 * cons[j].counts[4] / cons[j].depth < percent_pad)
		continue;

	    if (!quiet)
		vmessage("  Removing column %d %d%% pad (%d of %d), conf. %f)\n",
			 (int)j+contigs[i].start,
			 100 * cons[j].counts[4] / cons[j].depth,
			 cons[j].counts[4], cons[j].depth,
			 cons[j].scores[cons[j].call]);

	    contig_delete_base(io, &c, contigs[i].start + j - ndel);
	    ndel++;
	}

	cache_decr(io, c);
    }

    if (cons)
	free(cons);

    return 0;
}