Beispiel #1
0
// Parse the user-provided filter graph, and populate the unlinked filter pads.
static void precreate_graph(struct lavfi *c, bool first_init)
{
    assert(!c->graph);

    c->failed = false;

    c->graph = avfilter_graph_alloc();
    if (!c->graph)
        abort();

    if (mp_set_avopts(c->log, c->graph, c->graph_opts) < 0)
        goto error;

    if (c->direct_filter) {
        AVFilterContext *filter = avfilter_graph_alloc_filter(c->graph,
                            avfilter_get_by_name(c->graph_string), "filter");
        if (!filter) {
            MP_FATAL(c, "filter '%s' not found or failed to allocate\n",
                     c->graph_string);
            goto error;
        }

        if (mp_set_avopts_pos(c->log, filter, filter->priv,
                              c->direct_filter_opts) < 0)
            goto error;

        if (avfilter_init_str(filter, NULL) < 0) {
            MP_FATAL(c, "filter failed to initialize\n");
            goto error;
        }

        add_pads_direct(c, MP_PIN_IN, filter, filter->input_pads,
                        filter->nb_inputs, first_init);
        add_pads_direct(c, MP_PIN_OUT, filter, filter->output_pads,
                        filter->nb_outputs, first_init);
    } else {
        AVFilterInOut *in = NULL, *out = NULL;
        if (avfilter_graph_parse2(c->graph, c->graph_string, &in, &out) < 0) {
            MP_FATAL(c, "parsing the filter graph failed\n");
            goto error;
        }
        add_pads(c, MP_PIN_IN, in, first_init);
        add_pads(c, MP_PIN_OUT, out, first_init);
        avfilter_inout_free(&in);
        avfilter_inout_free(&out);
    }

    for (int n = 0; n < c->num_all_pads; n++)
        c->failed |= !c->all_pads[n]->filter;

    if (c->failed)
        goto error;

    return;

error:
    free_graph(c);
    c->failed = true;
    mp_filter_internal_mark_failed(c->f);
    return;
}
Beispiel #2
0
static int align(EdStruct *xx0, int pos0, int len0,
		 EdStruct *xx1, int pos1, int len1)
{

    char *ol0,*ol1, *cons0, *cons1;
    int old_def_conf0 = xx0->default_conf_n;
    int old_def_conf1 = xx1->default_conf_n;
    OVERLAP *overlap;
    int ierr;
    char PAD_SYM = '.';
    int  *depad_to_pad0, *dp0, *depad_to_pad1, *dp1;
    int *S, *res;
    int off0 = 0, off1 = 0;
    int left0 = 0, left1 = 0;

    vfuncheader("Align contigs (join editor)");

    /* Memory allocation */
    ol0 = (char *) xmalloc(len0+1);
    ol1 = (char *) xmalloc(len1+1);
    cons0 = (char *) xmalloc(len0+1);
    cons1 = (char *) xmalloc(len1+1);
    dp0 = depad_to_pad0 = (int *)xmalloc((len0+1) * sizeof(int));
    dp1 = depad_to_pad1 = (int *)xmalloc((len1+1) * sizeof(int));

    /* Compute the consensus */
    DBcalcConsensus(xx0,pos0,len0,ol0,NULL,BOTH_STRANDS);
    DBcalcConsensus(xx1,pos1,len1,ol1,NULL,BOTH_STRANDS);

    memcpy(cons0, ol0, len0+1);
    memcpy(cons1, ol1, len1+1);

    /* Strip the pads from the consensus */
    depad_seq(ol0, &len0, depad_to_pad0);
    depad_seq(ol1, &len1, depad_to_pad1);

    if (NULL == (overlap = create_overlap())) return -1;
    init_overlap (overlap, ol0, ol1, len0, len1);

    if(-1 == (ierr =  align_contigs (overlap))) {
	xfree(ol0);
	xfree(ol1);
	destroy_overlap(overlap);
	return -1;
    }

    /*
    overlap->seq1_out[overlap->right+1] = 0;
    overlap->seq2_out[overlap->right+1] = 0;
    */

    S = res = rsalign2myers(overlap->seq1_out, strlen(overlap->seq1_out),
			    overlap->seq2_out, strlen(overlap->seq2_out),
			    PAD_SYM);

    /* Clip left end */
    if (*S != 0) {
	/* Pad at start, so shift contigs */
	if (*S < 0) {
	    left0 = -*S; /* used for display only */
	    depad_to_pad0 += -*S;
	    off0 = depad_to_pad0[0];
	    xx1->displayPos -= off0;
	    pos0 += off0;
	    len0 -= -*S;
	} else {
	    left1 = *S; /* used for display only */
	    depad_to_pad1 += *S;
	    off1 = depad_to_pad1[0];
	    xx0->displayPos -= off1;
	    pos1 += off1;
	    len1 -= *S;
	}
	S++;
	xx0->link->lockOffset = xx1->displayPos - xx0->displayPos;
    }

    /* Clip right end */
    {
	int pos0 = 0, pos1 = 0;
	int *s = S;

	while (pos0 < len0 && pos1 < len1) {
	    if (*s < 0) {
		pos0 -= *s;
	    } else if (*s > 0) {
		pos0 += *s;
	    } else {
		pos0++;
		pos1++;
	    }

	    s++;
	}

	if (*s < 0)
	    len0 += *s;
	else if (*s > 0)
	    len1 -= *s;
    }

    /* Display the alignment. */
    {
	char *exp0, *exp1;
	int exp_len0, exp_len1;
	char name0[100];
	char name1[100];

	exp0 = (char *) xmalloc(len0+len1+1);
	exp1 = (char *) xmalloc(len0+len1+1);

	sprintf(name0, "%d", xx0->DBi->DB_contigNum);
	sprintf(name1, "%d", xx1->DBi->DB_contigNum);
	cexpand(ol0+left0, ol1+left1, len0, len1,
		exp0, exp1, &exp_len0, &exp_len1, 
		ALIGN_J_SSH | ALIGN_J_PADS, S);
	list_alignment(exp0, exp1, name0, name1, pos0, pos1, "");

	xfree(exp0);
	xfree(exp1);
    }


    /*************************************************************************/
    /* Now actually make the edits, keeping track of old and new pads. */
    openUndo(DBI(xx0));
    openUndo(DBI(xx1));

    xx0->default_conf_n = -1;
    xx1->default_conf_n = -1;
    {
	int depad_pos0 = 0, depad_pos1 = 0;
	int curr_pad0;  /* Current padded position in seq 0 */
	int curr_pad1;  /* Current padded position in seq 1 */
	int extra_pads; /* Difference between padded positions */
	int last_pad0 = -1;
	int last_pad1 = -1;
	int inserted_bases0 = 0;
	int inserted_bases1 = 0;


	while (depad_pos0 < len0 && depad_pos1 < len1) {
	    if (*S < 0) {
		depad_pos0 -= *S;
	    } else if (*S > 0) {
		depad_pos1 += *S;
	    }

	    if (depad_pos0 >= len0 || depad_pos1 >= len1)
		break;

	    curr_pad0 = depad_to_pad0[depad_pos0]-off0;
	    curr_pad1 = depad_to_pad1[depad_pos1]-off1;

	    extra_pads = (curr_pad1 - last_pad1) - (curr_pad0 - last_pad0);

	    if (extra_pads < 0) { /* Add to seq 0 */
		add_pads(xx1, pos1 + curr_pad1 + inserted_bases1, -extra_pads);
		inserted_bases1 -= extra_pads;
	    } else if (extra_pads > 0) { /* Add to seq 1 */
		add_pads(xx0, pos0 + curr_pad0 + inserted_bases0,  extra_pads);
		inserted_bases0 += extra_pads;
	    }
	    
	    last_pad0 = curr_pad0;
	    last_pad1 = curr_pad1;

	    if (*S == 0) {
		depad_pos0++;
		depad_pos1++;
	    }

	    S++;
	}
    }
    xx0->default_conf_n = old_def_conf0;
    xx1->default_conf_n = old_def_conf1;
    /*************************************************************************/

    closeUndo(xx1, DBI(xx1));
    closeUndo(xx0, DBI(xx0));

    xfree(res);

    xx0->default_conf_n = old_def_conf0;
    xx1->default_conf_n = old_def_conf1;

    xfree(ol0);
    xfree(ol1);
    xfree(dp0);
    xfree(dp1);
    destroy_overlap(overlap);

    return(0);
}
Beispiel #3
0
static int align_old(EdStruct *xx0, int pos0, int len0,
		 EdStruct *xx1, int pos1, int len1)
{

    char *ol0,*ol1;
    int  *depad_to_pad0_m, *depad_to_pad1_m;
    int  *depad_to_pad0,   *depad_to_pad1;
    align_int *res, *S;
    int old_def_conf0 = xx0->default_conf_n;
    int old_def_conf1 = xx1->default_conf_n;
    int off0 = 0, off1 = 0;
    int left0 = 0, left1 = 0;

    vfuncheader("Align contigs (join editor)");

    /* Memory allocation */
    ol0 = (char *) xmalloc(len0+1);
    ol1 = (char *) xmalloc(len1+1);
    depad_to_pad0 = depad_to_pad0_m = (int *)xmalloc((len0+1) * sizeof(int));
    depad_to_pad1 = depad_to_pad1_m = (int *)xmalloc((len1+1) * sizeof(int));
    S = res = (align_int *) xmalloc((len0+len1+1)*sizeof(align_int));

    /* Compute the consensus */
    DBcalcConsensus(xx0,pos0,len0,ol0,NULL,BOTH_STRANDS);
    DBcalcConsensus(xx1,pos1,len1,ol1,NULL,BOTH_STRANDS);

    /* Strip the pads from the consensus */
    depad_seq(ol0, &len0, depad_to_pad0);
    depad_seq(ol1, &len1, depad_to_pad1);

    /* Do the actual alignment */
    (void)calign(ol0, ol1, len0, len1,
		 NULL, NULL, NULL, NULL,
		 0, 0, gopenval, gextendval, 3, 0, res);

    /* Clip left end */
    if (*S != 0) {
	/* Pad at start, so shift contigs */
	if (*S < 0) {
	    left0 = -*S; /* used for display only */
	    depad_to_pad0 += -*S;
	    off0 = depad_to_pad0[0];
	    xx1->displayPos -= off0;
	    pos0 += off0;
	    len0 -= off0;
	} else {
	    left1 = *S; /* used for display only */
	    depad_to_pad1 += *S;
	    off1 = depad_to_pad1[0];
	    xx0->displayPos -= off1;
	    pos1 += off1;
	    len1 -= off1;
	}
	S++;
	xx0->link->lockOffset = xx1->displayPos - xx0->displayPos;
    }

    /* Clip right end */
    {
	int i = 0, j = 0, op;
	align_int *S2 = S;

	while (i < len0 && j < len1) {
	    if ((op = *S2++) == 0)
		i++, j++;
	    else if (op > 0)
		j += op;
	    else
		i -= op;
	}
	
	len0 = i;
	len1 = j;
    }

    /* Display the alignment. */
    {
	char *exp0, *exp1;
	int exp_len0, exp_len1;
	char name0[100];
	char name1[100];

	exp0 = (char *) xmalloc(len0+len1+1);
	exp1 = (char *) xmalloc(len0+len1+1);

	sprintf(name0, "%d", xx0->DBi->DB_contigNum);
	sprintf(name1, "%d", xx1->DBi->DB_contigNum);
	cexpand(ol0+left0, ol1+left1, len0, len1,
		exp0, exp1, &exp_len0, &exp_len1, 
		ALIGN_J_SSH | ALIGN_J_PADS, S);
	list_alignment(exp0, exp1, name0, name1, pos0, pos1, "");

	xfree(exp0);
	xfree(exp1);
    }


    /*************************************************************************/
    /* Now actually make the edits, keeping track of old and new pads. */
    openUndo(DBI(xx0));
    openUndo(DBI(xx1));

    xx0->default_conf_n = -1;
    xx1->default_conf_n = -1;
    {
	int depad_pos0 = 0, depad_pos1 = 0;
	int curr_pad0;  /* Current padded position in seq 0 */
	int curr_pad1;  /* Current padded position in seq 1 */
	int extra_pads; /* Difference between padded positions */
	int last_pad0 = -1;
	int last_pad1 = -1;
	int inserted_bases0 = 0;
	int inserted_bases1 = 0;

	while (depad_pos0 < len0 || depad_pos1 < len1) {
	    if (*S < 0) {
		depad_pos0 -= *S;
	    } else if (*S > 0) {
		depad_pos1 += *S;
	    }

	    curr_pad0 = depad_to_pad0[depad_pos0]-off0;
	    curr_pad1 = depad_to_pad1[depad_pos1]-off1;
	    extra_pads = (curr_pad1 - last_pad1) - (curr_pad0 - last_pad0);

	    if (extra_pads < 0) { /* Add to seq 0 */
		add_pads(xx1, pos1 + curr_pad1 + inserted_bases1, -extra_pads);
		inserted_bases1 -= extra_pads;
	    } else if (extra_pads > 0) { /* Add to seq 1 */
		add_pads(xx0, pos0 + curr_pad0 + inserted_bases0,  extra_pads);
		inserted_bases0 += extra_pads;
	    }
	    
	    last_pad0 = curr_pad0;
	    last_pad1 = curr_pad1;

	    if (*S == 0) {
		depad_pos0++;
		depad_pos1++;
	    }

	    S++;
	}
    }
    xx0->default_conf_n = old_def_conf0;
    xx1->default_conf_n = old_def_conf1;
    /*************************************************************************/

    closeUndo(xx1, DBI(xx1));
    closeUndo(xx0, DBI(xx0));

    xfree(res);
    xfree(ol0);
    xfree(ol1);
    xfree(depad_to_pad0_m);
    xfree(depad_to_pad1_m);

    return(0);
}
Beispiel #4
0
static int align(EdStruct *xx0, int pos0, int len0,
		 EdStruct *xx1, int pos1, int len1)
{

    char *ol0,*ol1;
    int old_def_conf0 = xx0->default_conf_n;
    int old_def_conf1 = xx1->default_conf_n;
    OVERLAP *overlap;
    int ierr;
    int left0, left1;
    char name0[100];
    char name1[100];
    int i,pads;
    char PAD_SYM = '.';

    vfuncheader("Align contigs (join editor)");

    /* Memory allocation */
    ol0 = (char *) xmalloc(len0+1);
    ol1 = (char *) xmalloc(len1+1);

    /* Compute the consensus */
    DBcalcConsensus(xx0,pos0,len0,ol0,NULL,BOTH_STRANDS);
    DBcalcConsensus(xx1,pos1,len1,ol1,NULL,BOTH_STRANDS);

    if (NULL == (overlap = create_overlap())) return -1;
    init_overlap (overlap, ol0, ol1, len0, len1);

    if(1 > (ierr =  align_contigs (overlap))) {
	xfree(ol0);
	xfree(ol1);
	destroy_overlap(overlap);
	return -1;
    }
    
    /* Display the alignment. */

    sprintf(name0, "#%d", xx0->DBi->DB[1].number);
    sprintf(name1, "#%d", xx1->DBi->DB[1].number);
    overlap->seq1_out[overlap->right+1] = 0;
    overlap->seq2_out[overlap->right+1] = 0;
    left0 = left1 = 0;
    if(overlap->left1 == 0) left0 += overlap->left2;
    if(overlap->left2 == 0) left1 += overlap->left1;

    list_alignment(&overlap->seq1_out[overlap->left],
		   &overlap->seq2_out[overlap->left], 
		   name0, name1, pos0+left0, pos1+left1, "");

    xx1->displayPos -= left0;
    xx0->displayPos -= left1;
    xx0->link->lockOffset = xx1->displayPos - xx0->displayPos;

    /* do the edits */


    xx0->default_conf_n = -1;
    xx1->default_conf_n = -1;

    for(i=overlap->left,pads=0;i<=overlap->right;i++) {
	if(overlap->seq1_out[i] != PAD_SYM) {
	    if(pads) {
		add_pads(xx0, pos0-left1+i-pads, pads);
		pads = 0;
	    }
	}
	else {
	    pads++;
	}
    }
    if(pads) {
	add_pads(xx0, pos0-left1+i-pads-1, pads);
    }
    for(i=overlap->left,pads=0;i<=overlap->right;i++) {
	if(overlap->seq2_out[i] != PAD_SYM) {
	    if(pads) {
		add_pads(xx1, pos1-left0+i-pads, pads);
		pads = 0;
	    }
	}
	else {
	    pads++;
	}
    }
    if(pads) {
	add_pads(xx1, pos1-left0+i-pads-1, pads);
    }

    xx0->default_conf_n = old_def_conf0;
    xx1->default_conf_n = old_def_conf1;

    xfree(ol0);
    xfree(ol1);
    destroy_overlap(overlap);
    return(0);
}