static ajint prima_primalign(const AjPStr a, const AjPStr b) { ajint plen; ajint qlen; ajint limit; ajint i; ajint n = 0; ajint mm = 0; ajint j; const char *p; const char *q; ajint alen; ajint blen; alen = ajStrGetLen(a); blen = ajStrGetLen(b); if(alen > blen) { plen = alen; qlen = blen; p = ajStrGetPtr(a); q = ajStrGetPtr(b); } else { plen = blen; qlen = alen; p = ajStrGetPtr(b); q = ajStrGetPtr(a); } limit = plen-qlen+1; for(i=0; i<limit; ++i) { for(j=0; j<qlen; ++j) if(p[j]==q[j]) ++n; mm = AJMAX(mm, n); ++p; } return (ajint)(((float)mm/(float)qlen)*100.0); }
static PSilent silent_checktrans(const AjPStr seq,const EmbPMatMatch match, const PRinfo rlp, ajint begin, ajint radj, AjBool rev, ajint end) { PSilent ret; const char *p = NULL; const char *q = NULL; const char *s = NULL; char *t; const char *u; ajint matchpos; ajint framep; ajint count; AjPTrn table = NULL; AjPStr s1 = NULL; AjPStr s2 = NULL; char c; char rc; ajint min = INT_MAX; /* Reverse sense intentional! */ ajint max = -INT_MAX; ajint fpos; ajint rpos; ajint x; AjPStr tstr = NULL; matchpos = match->start; fpos = matchpos; rpos=radj-fpos-match->len; tstr = ajStrNewS(seq); t = ajStrGetuniquePtr(&tstr); p = t+fpos-(begin+1); u = q = ajStrGetPtr(rlp->site); /* Test here for whether cut site is within sequence substring */ if(rlp->ncuts==4) { min = AJMIN(rlp->cut1,rlp->cut2); max = AJMAX(rlp->cut3,rlp->cut4); } else if(rlp->ncuts==2) { min = AJMIN(rlp->cut1,rlp->cut2); max = AJMAX(rlp->cut1,rlp->cut2); } else { ajWarn("Possibly corrupt RE file"); ajStrDel(&tstr); return NULL; } if(!rev) /* forward strand */ { if(matchpos+min<0||matchpos+max>end+1) { /*Cut site not in sequence range*/ ajStrDel(&tstr); return NULL; } } else /* reverse strand */ { if(radj-matchpos-1-min>end+1||radj-matchpos-1-max<begin) { /*Cut site not in sequence range*/ ajStrDel(&tstr); return NULL; } } count=0; while(ajBaseAlphaToBin(*q++) & ajBaseAlphaToBin(*p++)) ++count; /* Changed base postion */ x = fpos+count-(begin+1); /* Where the frame starts on the reverse strand */ framep = (end-begin+1)%3; c = t[x]; rc = u[count]; if(!rev) /* forward strand */ s = t+x-x%3; else /* reverse strand */ s = t+x-(x-framep)%3; table = ajTrnNewI(0); /* translates codon pointed to by s (original seq) */ s1 = ajStrNewK(ajTrnCodonC(table,s)); t[x] = rc; /* translates codon pointed to by s (mutated base from RS pattern */ s2 = ajStrNewK(ajTrnCodonC(table,s)); t[x] = c; /* changes mutated base in seq back to original base */ AJNEW(ret); ret->obase = c; ret->nbase = rc; ret->code = ajStrNewC(ajStrGetPtr(rlp->code)); ret->site = ajStrNewC(ajStrGetPtr(rlp->site)); ret->seqaa = ajStrNewC(ajStrGetPtr(s1)); ret->reaa = ajStrNewC(ajStrGetPtr(s2)); if(ajStrMatchS(s1,s2)) ret->issilent = ajTrue; else ret->issilent = ajFalse; if(!rev) { ret->match = matchpos; ret->base = matchpos+count; } else { ret->match = rpos; ret->base = rpos+match->len-1-count; } ajStrDel(&tstr); ajStrDel(&s1); ajStrDel(&s2); ajTrnDel(&table); return ret; }
static void pscan_print_hits(AjPFile outf, AjPList l, ajuint nmotifs, ajuint begin) { EmbPMatMatch mm; ajuint i; ajuint j; AjBool found; ajuint nleft; ajuint maxelem = 0; ajuint maxhpm; ajuint hpm = 0; nleft = nmotifs; ajFmtPrintF(outf,"\n\nCLASS 1\n"); ajFmtPrintF(outf,"Fingerprints with all elements in order\n\n"); found = ajTrue; while(found && nleft) { found = ajFalse; maxelem = 0; for(i=0;i<nleft;++i) { ajListPop(l,(void **)&mm); if(mm->all && mm->ordered) { maxelem = AJMAX(maxelem,mm->n); found = ajTrue; } hpm = mm->hpm; ajListPushAppend(l,(void *)mm); for(j=1;j<hpm;++j) { ajListPop(l,(void **)&mm); ajListPushAppend(l,(void *)mm); } } if(found) { found = ajFalse; for(i=0;i<nleft;++i) { ajListPop(l,(void **)&mm); hpm = mm->hpm; if(mm->all && mm->ordered && maxelem==mm->n) break; ajListPushAppend(l,(void *)mm); for(j=1;j<hpm;++j) { ajListPop(l,(void **)&mm); ajListPushAppend(l,(void *)mm); } } if(mm->all && mm->ordered && maxelem==mm->n) { ajFmtPrintF(outf,"Fingerprint %s Elements %d\n", ajStrGetPtr(mm->cod),mm->n); ajFmtPrintF(outf," Accession number %s\n", ajStrGetPtr(mm->acc)); ajFmtPrintF(outf," %s\n",ajStrGetPtr(mm->tit)); ajFmtPrintF(outf," Element %d Threshold %d%% Score %d%%\n", mm->element+1, mm->thresh, mm->score); ajFmtPrintF(outf," Start position %d Length %d\n", mm->start+begin,mm->len); embMatMatchDel(&mm); } for(i=1;i<hpm;++i) { ajListPop(l,(void **)&mm); ajFmtPrintF(outf," Element %d Threshold %d%% Score %d%%\n", mm->element+1, mm->thresh, mm->score); ajFmtPrintF(outf," Start position %d Length %d\n", mm->start+begin,mm->len); embMatMatchDel(&mm); } --nleft; } } ajFmtPrintF(outf,"\n\nCLASS 2\n"); ajFmtPrintF(outf,"All elements match but not all in the " "correct order\n\n"); found = ajTrue; while(found && nleft) { found = ajFalse; maxelem = 0; for(i=0;i<nleft;++i) { ajListPop(l,(void **)&mm); if(mm->all) { maxelem = AJMAX(maxelem,mm->n); found = ajTrue; } hpm = mm->hpm; ajListPushAppend(l,(void *)mm); for(j=1;j<hpm;++j) { ajListPop(l,(void **)&mm); ajListPushAppend(l,(void *)mm); } } if(found) { found=ajFalse; for(i=0;i<nleft;++i) { ajListPop(l,(void **)&mm); hpm = mm->hpm; if(mm->all && maxelem==mm->n) break; ajListPushAppend(l,(void *)mm); for(j=1;j<hpm;++j) { ajListPop(l,(void **)&mm); ajListPushAppend(l,(void *)mm); } } if(mm->all && maxelem==mm->n) { ajFmtPrintF(outf,"Fingerprint %s Elements %d\n", ajStrGetPtr(mm->cod),mm->n); ajFmtPrintF(outf," Accession number %s\n", ajStrGetPtr(mm->acc)); ajFmtPrintF(outf," %s\n",ajStrGetPtr(mm->tit)); ajFmtPrintF(outf," Element %d Threshold %d%% Score %d%%\n", mm->element+1, mm->thresh, mm->score); ajFmtPrintF(outf," Start position %d Length %d\n", mm->start+begin,mm->len); embMatMatchDel(&mm); } for(i=1;i<hpm;++i) { ajListPop(l,(void **)&mm); ajFmtPrintF(outf," Element %d Threshold %d%% Score %d%%\n", mm->element+1, mm->thresh, mm->score); ajFmtPrintF(outf," Start position %d Length %d\n", mm->start+begin,mm->len); embMatMatchDel(&mm); } --nleft; } } ajFmtPrintF(outf,"\n\nCLASS 3\n"); ajFmtPrintF(outf, "Not all elements match but those that do are in order\n\n"); found = ajTrue; while(found && nleft) { found = ajFalse; maxhpm = 0; for(i=0;i<nleft;++i) { ajListPop(l,(void **)&mm); if(mm->ordered) { maxhpm = AJMAX(maxelem,mm->hpm); found = ajTrue; } hpm = mm->hpm; ajListPushAppend(l,(void *)mm); for(j=1;j<hpm;++j) { ajListPop(l,(void **)&mm); ajListPushAppend(l,(void *)mm); } } if(found) { found = ajFalse; for(i=0;i<nleft;++i) { ajListPop(l,(void **)&mm); hpm = mm->hpm; if(mm->ordered && maxhpm==mm->hpm) break; ajListPushAppend(l,(void *)mm); for(j=1;j<hpm;++j) { ajListPop(l,(void **)&mm); ajListPushAppend(l,(void *)mm); } } if(mm->ordered && maxhpm==mm->hpm) { ajFmtPrintF(outf,"Fingerprint %s Elements %d\n", ajStrGetPtr(mm->cod),mm->n); ajFmtPrintF(outf," Accession number %s\n", ajStrGetPtr(mm->acc)); ajFmtPrintF(outf," %s\n",ajStrGetPtr(mm->tit)); ajFmtPrintF(outf," Element %d Threshold %d%% Score %d%%\n", mm->element+1, mm->thresh, mm->score); ajFmtPrintF(outf," Start position %d Length %d\n", mm->start+begin,mm->len); embMatMatchDel(&mm); } for(i=1;i<hpm;++i) { ajListPop(l,(void **)&mm); ajFmtPrintF(outf," Element %d Threshold %d%% Score %d%%\n", mm->element+1, mm->thresh, mm->score); ajFmtPrintF(outf," Start position %d Length %d\n", mm->start+begin,mm->len); embMatMatchDel(&mm); } --nleft; } } ajFmtPrintF(outf,"\n\nCLASS 4\n"); ajFmtPrintF(outf, "Remaining partial matches\n\n"); found = ajTrue; while(found && nleft) { found = ajFalse; maxhpm = 0; for(i=0;i<nleft;++i) { ajListPop(l,(void **)&mm); maxhpm = AJMAX(maxelem,mm->hpm); found = ajTrue; hpm = mm->hpm; ajListPushAppend(l,(void *)mm); for(j=1;j<hpm;++j) { ajListPop(l,(void **)&mm); ajListPushAppend(l,(void *)mm); } } if(found) { found = ajFalse; for(i=0;i<nleft;++i) { ajListPop(l,(void **)&mm); hpm = mm->hpm; if(maxhpm==mm->hpm) break; ajListPushAppend(l,(void *)mm); for(j=1;j<hpm;++j) { ajListPop(l,(void **)&mm); ajListPushAppend(l,(void *)mm); } } if(maxhpm==mm->hpm) { ajFmtPrintF(outf,"Fingerprint %s Elements %d\n", ajStrGetPtr(mm->cod),mm->n); ajFmtPrintF(outf," Accession number %s\n", ajStrGetPtr(mm->acc)); ajFmtPrintF(outf," %s\n",ajStrGetPtr(mm->tit)); ajFmtPrintF(outf," Element %d Threshold %d%% Score %d%%\n", mm->element+1, mm->thresh, mm->score); ajFmtPrintF(outf," Start position %d Length %d\n", mm->start+begin,mm->len); embMatMatchDel(&mm); } for(i=1;i<hpm;++i) { ajListPop(l,(void **)&mm); ajFmtPrintF(outf," Element %d Threshold %d%% Score %d%%\n", mm->element+1, mm->thresh, mm->score); ajFmtPrintF(outf," Start position %d Length %d\n", mm->start+begin,mm->len); embMatMatchDel(&mm); } --nleft; } } while(ajListPop(l,(void **)&mm)) if(mm) embMatMatchDel(&mm); return; }