Пример #1
0
int main(void) {
    char s[MAX_LEN], t[MAX_LEN], val;
    int i = 0;
    while((val = getchar()) != '\n') s[i++] = val;
    s[i] = '\0';

    i = 0;
    while((val = getchar()) != '\n') t[i++] = val;
    t[i] = '\0';  

    edit_sequence(s, t); 
    return 0;
}
Пример #2
0
/*
 * Enters a reading. This does not perform any linking of neighbours and
 * updating of the contig. If an alignment buffer 'res' is non NULL then
 * it is used as a list of edits. See the calign() code for details of
 * the format for this buffer.
 *
 * It does however edit and enter the tags (on both the reading and
 * consensus).
 *
 * Returns reading number for success, -1 for failure.
 */
int enter_reading(GapIO *io, SeqInfo *si, int comp, align_info *ai,
		  int contig, int position) {
    GReadings r;
    int reading;
    char *name;
    int start, end, length, alength;
    char *seq = NULL;
    int1 *conf = NULL;
    int2 *opos = NULL;
    anno_info *anno_r, *anno_c;
    int anno_rl, anno_cl;
    int retcode = -1;
    int i;

    /*
     * Allocate
     */
    io_init_reading(io, NumReadings(io)+1);
    reading = NumReadings(io);


    /*
     * Write the reading name
     */
    if (NULL == (name = read_sequence_name(si)))
	goto end;
    write_rname(io, reading, name);


    /*
     * length, start, end, sense
     */
    length = si->length;
    start = si->start;
    end = si->end;
    alength = length + 100;

    /* Allocate temporary buffers */
    seq = (char *)xmalloc(alength * sizeof(*seq));
    conf = (int1 *)xmalloc(alength * sizeof(*conf));
    opos = (int2 *)xmalloc(alength * sizeof(*opos));
    if (!seq || !conf || !opos)
	goto end;
    
    /*
     * Obtain the sequence, original positions, and confidence values.
     */
    strcpy(seq, exp_get_entry(si->e, EFLT_SQ));
    SeqInfo_opos(si, opos, length);
    SeqInfo_conf(si, conf, length);


    /*
     * Complement if necessary
     */
    if (comp)
	io_complement_seq(&length, &start, &end, seq, conf, opos);


    /*
     * Load the tags into memory
     */
    anno_r = create_anno_list(si, EFLT_TG, &anno_rl, length);
    anno_c = create_anno_list(si, EFLT_TC, &anno_cl, 0);
    
    /*
     * Edit the sequence, consensus and tags
     */
    if (ai)
	edit_sequence(io, ai, &alength, &length, &start, &end,
		      &seq, &conf, &opos, contig,
		      comp, anno_r, anno_rl, anno_c, anno_cl);


    /*
     * write sequence to file
     */
    if (io_write_seq(io, reading, &length, &start, &end, seq, conf, opos)) {
	verror(ERR_WARN, "enter_reading",
	       "Problem writing new sequence to database: %s", name);
	return -1;
    }
    /* Shouldn't this be in io_write_seq? */
    gel_read(io, reading, r);
    r.sequence_length = end - start - 1;
    if (comp) {
	io_length(io, reading) = -r.sequence_length;
	r.sense = GAP_SENSE_REVERSE;
    } else {
	io_length(io, reading) = r.sequence_length;
	r.sense = GAP_SENSE_ORIGINAL;
    }
    gel_write(io, reading, r);


    /*
     * write raw data info
     */
    if (exp_Nentries(si->e, EFLT_LT) &&
	exp_Nentries(si->e, EFLT_LN)) {
	if (io_write_rd(io,
			reading,
			exp_get_entry(si->e, EFLT_LN),
			strlen(exp_get_entry(si->e, EFLT_LN)),
			exp_get_entry(si->e, EFLT_LT),
			strlen(exp_get_entry(si->e, EFLT_LT)))) {
	    verror(ERR_WARN, "enter_reading",
		   "Problem writing raw data information to database: %s",
		   name);
	    return -1;
	}
    }

    /*
     * Write the tag data
     */
    write_anno_list(io, anno_r, anno_rl, reading, 0, comp,
		    start, end, length);
    write_anno_list(io, anno_c, anno_cl, -contig, position-1-r.start,
		    comp, start, end, length);
    free_anno_list(anno_r, anno_rl);
    free_anno_list(anno_c, anno_cl);


    /*
     * Add NoTes
     */
    for(i = 0; i < exp_Nentries(si->e, EFLT_NT); i++) {
	create_note_for_gel(io, reading,
			    arr(char *, si->e->entries[EFLT_NT], i));
    }

    /*
     * write everything else
     */
    retcode = add_seq_details(io, reading, si) ? -1 : reading;

 end:
    if (seq)
	xfree(seq);
    if (conf)
	xfree(conf);
    if (opos)
	xfree(opos);

    return retcode;
}