void isap(int s,int t){ bfs(t); int u = s; for(int i = 1;i<=node;++i) cur[i] = st[i]; while(d[s] < node){ if(u == t) u = aug(t); int adv = 0; FIND(x,u) if(BAL(x)>0 && d[lk[x].v]+1 == d[u]) { cur[u] = x;u = lk[x].v;pre[u] = x; adv = 1; break; } if(!adv){ GAP(u); int md = node; TRA(x,u) if(BAL(x)>0) md = min(md,d[lk[x].v]); d[u] = md+1;cur[u]=st[u];++num[d[u]]; if(u != s) u = lk[pre[u]^1].v; } }
double mafScoreRangeMultiz(struct mafAli *maf, int start, int size) /* Return score of a subset of an alignment. Parameters are: * maf - the alignment * start - the (zero based) offset to start calculating score * size - the size of the subset * The following relationship should hold: * scoreRange(maf,start,size) = * scoreRange(maf,0,start+size) - scoreRange(maf,0,start) */ { uchar ai, ar, bi, br; int i; double score; struct mafComp *c1, *c2; if (start < 0 || size <= 0 || start+size > maf->textSize) { errAbort( "mafScoreRange: start = %d, size = %d, textSize = %d\n", start, size, maf->textSize); } if (ss['A']['A'] != HOXD70_sym[0][0]) { DNA_scores(ss); ds.E = 30; ds.O = 400; for (i = 0; i < 128; ++i) ss[i][DASH] = ss[DASH][i] = -ds.E; ss[DASH][DASH] = 0; gap_costs(gop, gtype, ds.O); /* quasi-natural gap costs */ } score = 0.0; for (i = start; i < start+size; ++i) { for (c1 = maf->components; c1 != NULL; c1 = c1->next) { if (c1->size == 0) continue; br = c1->text[i]; for (c2 = c1->next; c2 != NULL; c2 = c2->next) { if (c2->size == 0) continue; bi = c2->text[i]; score += SS(br, bi); if (i > 0) { ar = c1->text[i-1]; ai = c2->text[i-1]; score -= GAP(ar,ai,br,bi); } } } } return score; }
static void init_scores(const int s[4][4], int **ss, int *gop, int filler, int gap_op, int gap_ex) { int i, j, a, b, A, B, X, D; // first, fill in ss, the substitution-score matrix for (i = 0; i < NACHARS; ++i) for (j = 0; j < NACHARS; ++j) ss[i][j] = filler; for (i = 0; i < (signed)CLEN(nchars); ++i) { A = nchars[i]; a = tolower(A); for (j = 0; j < (signed)CLEN(nchars); ++j) { B = nchars[j]; b = tolower(B); ss[A][B] = ss[a][B] = ss[A][b] = ss[a][b] = s[i][j]; } } for (i = 0; i < NACHARS; ++i) ss['-'][i] = ss[i]['-'] = -gap_ex; ss['-']['-'] = 0; // initialize the "gap-open penalty" array, for quasi-natural gap costs for (i = 0; i < 16; ++i) gop[i] = 0; D = 1; // dash X = 0; // anything other than '-' /* The six gap-open configurations are: xx x- x- -x -x -- x- xx -x x- -- -x 1 2 3 4 5 6 The last two may result in a gap being counted twice, as with: xx-xx x---x 1 5 (A digit indicates the second column of a column-pair that conforms to the indicated rule, 1-6.) However, it permits a gap to be detected by inspection of adjacent columns in a case like: x-----xx x------x 5 GAP's arguments give column 1, followed by column 2. */ GAP(X,X,X,D) = GAP(X,X,D,X) = GAP(X,D,D,X) = GAP(D,X,X,D) = GAP(D,D,X,D) = GAP(D,D,D,X) = gap_op; gap_extend = gap_ex; }
static void gap_costs(int *gop, int *gtype, int gap_open) { int i, X, D; for (i = 0; i < 128; ++i) gtype[i] = 0; D = DASH; gtype[D] = 1; for (i = 0; i < 256; ++i) gop[i] = 0; X = (uchar)'A'; GAP(X,X,X,D) = gap_open; GAP(X,X,D,X) = gap_open; GAP(X,D,D,X) = gap_open; GAP(D,X,X,D) = gap_open; GAP(D,D,X,D) = gap_open; GAP(D,D,D,X) = gap_open; }
/* * s_print - print the strip for debugging */ static void s_print(struct re_guts *g, FILE *d) { sop *s; cset *cs; int done = 0; sop opnd; int col = 0; ssize_t last; sopno offset = 2; # define GAP() { if (offset % 5 == 0) { \ if (col > 40) { \ fprintf(d, "\n\t"); \ col = 0; \ } else { \ fprintf(d, " "); \ col++; \ } \ } else \ col++; \ offset++; \ } if (OP(g->strip[0]) != OEND) fprintf(d, "missing initial OEND!\n"); for (s = &g->strip[1]; !done; s++) { opnd = OPND(*s); switch (OP(*s)) { case OEND: fprintf(d, "\n"); done = 1; break; case OCHAR: if (strchr("\\|()^$.[+*?{}!<> ", (char)opnd) != NULL) fprintf(d, "\\%c", (char)opnd); else fprintf(d, "%s", regchar((char)opnd)); break; case OBOL: fprintf(d, "^"); break; case OEOL: fprintf(d, "$"); break; case OBOW: fprintf(d, "\\{"); break; case OEOW: fprintf(d, "\\}"); break; case OANY: fprintf(d, "."); break; case OANYOF: fprintf(d, "[(%ld)", (long)opnd); #ifdef __NetBSD__ cs = &g->sets[opnd]; last = -1; for (size_t i = 0; i < g->csetsize+1; i++) /* +1 flushes */ if (CHIN(cs, i) && i < g->csetsize) { if (last < 0) { fprintf(d, "%s", regchar(i)); last = i; } } else { if (last >= 0) { if (last != (ssize_t)i - 1) fprintf(d, "-%s", regchar(i - 1)); last = -1; } } #endif fprintf(d, "]"); break; case OBACK_: fprintf(d, "(\\<%ld>", (long)opnd); break; case O_BACK: fprintf(d, "<%ld>\\)", (long)opnd); break; case OPLUS_: fprintf(d, "(+"); if (OP(*(s+opnd)) != O_PLUS) fprintf(d, "<%ld>", (long)opnd); break; case O_PLUS: if (OP(*(s-opnd)) != OPLUS_) fprintf(d, "<%ld>", (long)opnd); fprintf(d, "+)"); break; case OQUEST_: fprintf(d, "(?"); if (OP(*(s+opnd)) != O_QUEST) fprintf(d, "<%ld>", (long)opnd); break; case O_QUEST: if (OP(*(s-opnd)) != OQUEST_) fprintf(d, "<%ld>", (long)opnd); fprintf(d, "?)"); break; case OLPAREN: fprintf(d, "((<%ld>", (long)opnd); break; case ORPAREN: fprintf(d, "<%ld>))", (long)opnd); break; case OCH_: fprintf(d, "<"); if (OP(*(s+opnd)) != OOR2) fprintf(d, "<%ld>", (long)opnd); break; case OOR1: if (OP(*(s-opnd)) != OOR1 && OP(*(s-opnd)) != OCH_) fprintf(d, "<%ld>", (long)opnd); fprintf(d, "|"); break; case OOR2: fprintf(d, "|"); if (OP(*(s+opnd)) != OOR2 && OP(*(s+opnd)) != O_CH) fprintf(d, "<%ld>", (long)opnd); break; case O_CH: if (OP(*(s-opnd)) != OOR1) fprintf(d, "<%ld>", (long)opnd); fprintf(d, ">"); break; default: #ifdef __FreeBSD__ fprintf(d, "!%ld(%ld)!", OP(*s), opnd); #else fprintf(d, "!%d(%d)!", OP(*s), opnd); #endif break; } if (!done) GAP(); } }