void overlapping_grid_input<COARSEG,FINEG,OVLP>::init(COARSEG const& cg, std::string const& basenm_) { the_coarse_grid = &cg; basenm = basenm_; the_fine_grid.init(basenm + ".grid"); init_overlap(); }
static void bdinit (struct spotstr *bp) { _movenum = 1; // mark the borders as such struct spotstr* sp = bp; for (int i = BSZ2; --i >= 0; ++sp) { sp->s_occ = BORDER; // top border sp->s_flg = BFLAGALL; } // fill entire board with EMPTY spots memset(_frames, 0, sizeof(_frames)); struct combostr* cbp = _frames; for (unsigned j = 0; ++j < BSZ1; ++sp) { // for each row for (unsigned i = 0; ++i < BSZ1; ++sp) { // for each column sp->s_occ = EMPTY; sp->s_flg = 0; sp->s_wval = 0; if (j < 5) { // directions 1, 2, 3 are blocked sp->s_flg |= (BFLAG << 1) | (BFLAG << 2) | (BFLAG << 3); sp->s_fval[BLACK][1].s = MAXCOMBO; sp->s_fval[BLACK][2].s = MAXCOMBO; sp->s_fval[BLACK][3].s = MAXCOMBO; sp->s_fval[WHITE][1].s = MAXCOMBO; sp->s_fval[WHITE][2].s = MAXCOMBO; sp->s_fval[WHITE][3].s = MAXCOMBO; } else if (j == 5) { // five spaces, blocked on one side sp->s_fval[BLACK][1].s = 0x500; sp->s_fval[BLACK][2].s = 0x500; sp->s_fval[BLACK][3].s = 0x500; sp->s_fval[WHITE][1].s = 0x500; sp->s_fval[WHITE][2].s = 0x500; sp->s_fval[WHITE][3].s = 0x500; } else { // six spaces, not blocked sp->s_fval[BLACK][1].s = 0x401; sp->s_fval[BLACK][2].s = 0x401; sp->s_fval[BLACK][3].s = 0x401; sp->s_fval[WHITE][1].s = 0x401; sp->s_fval[WHITE][2].s = 0x401; sp->s_fval[WHITE][3].s = 0x401; } if (i > BSZ-4) { // directions 0, 1 are blocked sp->s_flg |= BFLAG | (BFLAG << 1); sp->s_fval[BLACK][0].s = MAXCOMBO; sp->s_fval[BLACK][1].s = MAXCOMBO; sp->s_fval[WHITE][0].s = MAXCOMBO; sp->s_fval[WHITE][1].s = MAXCOMBO; } else if (i == BSZ-4) { // if direction 1 is not blocked sp->s_fval[BLACK][0].s = 0x500; sp->s_fval[WHITE][0].s = 0x500; if (!(sp->s_flg & (BFLAG << 1))) { sp->s_fval[BLACK][1].s = 0x500; sp->s_fval[WHITE][1].s = 0x500; } } else { // direction 3 is blocked sp->s_fval[BLACK][0].s = 0x401; sp->s_fval[WHITE][0].s = 0x401; if (i < 5) { sp->s_flg |= BFLAG << 3; sp->s_fval[BLACK][3].s = MAXCOMBO; sp->s_fval[WHITE][3].s = MAXCOMBO; } else if (i == 5 && !(sp->s_flg & (BFLAG << 3))) { sp->s_fval[BLACK][3].s = 0x500; sp->s_fval[WHITE][3].s = 0x500; } } // Allocate a frame structure for non blocked frames. for (int r = 4; --r >= 0;) { if (sp->s_flg & (BFLAG << r)) continue; cbp->c_combo.s = sp->s_fval[BLACK][r].s; cbp->c_vertex = sp - _board; cbp->c_nframes = 1; cbp->c_dir = r; sp->s_frame[r] = cbp; ++cbp; } } sp->s_occ = BORDER; // left & right border sp->s_flg = BFLAGALL; } // mark the borders as such for (int i = BSZ1; --i >= 0; ++sp) { sp->s_occ = BORDER; // bottom border sp->s_flg = BFLAGALL; } _sortframes[BLACK] = NULL; _sortframes[WHITE] = NULL; init_overlap(); }
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); }
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); }