static void splitter_ProcessChunk (AjPSeqout seqout, const AjPSeq seq, ajuint start, ajuint end, const AjPStr name, AjBool feature) { AjPStr str; AjPFeattable new_feattable = NULL; AjPSeq subseq; ajDebug("splitter_ProcessChunk %d..%d '%S' %B\n", start, end, name, feature); str = ajStrNew(); subseq = ajSeqNew(); new_feattable = ajFeattableNew(name); subseq->Fttable = new_feattable; ajFeattableSetNuc(new_feattable); ajStrAssignSubC(&str,ajSeqGetSeqC(seq),start,end); ajSeqAssignSeqS(subseq,str); if(feature) splitter_AddSubSeqFeat(subseq->Fttable,start,end,seq); ajSeqAssignNameS(subseq, name); splitter_write(seqout,subseq,seq); ajStrDel(&str); ajSeqDel(&subseq); return; }
static void tranalign_AddGaps(AjPSeq newseq, const AjPSeq nseq, const AjPSeq pseq, ajlong npos) { AjPStr newstr = NULL; ajuint ppos = 0; newstr = ajStrNew(); for(; ppos<ajSeqGetLen(pseq); ppos++) if(ajSeqGetSeqC(pseq)[ppos] == '-') ajStrAppendC(&newstr, "---"); else { ajStrAppendSubS(&newstr, ajSeqGetSeqS(nseq), npos, npos+2); npos+=3; } ajDebug("aligned seq=%S\n", newstr); ajSeqAssignSeqS(newseq, newstr); ajStrDel(&newstr); return; }
AjPStr embPropProt1to3(AjPSeq seq, ajint pad) { const char *p; const char *p3; AjPStr temp; ajint i; temp = ajStrNewRes(ajSeqGetLen(seq)*3 + pad+1); /* put any required padding spaces at the start */ for(i=0; i<pad; i++) ajStrAppendC(&temp, " "); for(p=ajSeqGetSeqC(seq); *p; p++) { if(*p == '*') ajStrAppendC(&temp, "***"); else if(*p == '.') ajStrAppendC(&temp, "..."); else if(*p == '-') ajStrAppendC(&temp, "---"); else if(!isalpha((ajint)*p)) ajStrAppendC(&temp, "???"); else { p3 = embPropCharToThree(*p); ajStrAppendK(&temp, *p3); ajStrAppendK(&temp, *(p3+1)); ajStrAppendK(&temp, *(p3+2)); } } return temp; }
int main(int argc, char **argv) { AjPSeqall seqall; AjPSeq a; AjPSeqout outf; AjPStr substr; AjPStr back; AjPStr gctable; AjPCod codon = NULL; ajint gctablenum; ajint beg; ajint end; embInit("backtranambig", argc, argv); seqall = ajAcdGetSeqall("sequence"); outf = ajAcdGetSeqoutall("outfile"); gctable = ajAcdGetListSingle("table"); ajStrToInt(gctable, &gctablenum); codon = ajCodNewCodenum(gctablenum); while(ajSeqallNext(seqall, &a)) { substr = ajStrNew(); beg = ajSeqGetBegin(a); end = ajSeqGetEnd(a); ajStrAssignSubC(&substr,ajSeqGetSeqC(a),beg-1,end-1); back = ajStrNew(); ajCodBacktranslateAmbig(&back,substr,codon); ajSeqAssignSeqS (a, back); ajSeqSetNuc(a); ajSeqoutWriteSeq(outf,a); } ajSeqoutClose(outf); ajStrDel(&back); ajStrDel(&substr); ajSeqoutDel(&outf); ajCodDel(&codon); ajStrDel(&gctable); ajSeqallDel(&seqall); ajSeqDel(&a); embExit(); return 0; }
AjPStr embPropProt1to3Rev(AjPSeq seq, ajint pad) { const char *p; const char *p3; AjPStr temp; ajint i=0; temp = ajStrNewRes(ajSeqGetLen(seq)*3 + pad+1); for(p=ajSeqGetSeqC(seq); *p; p++) { if(*p == '*') ajStrAppendC(&temp, "***"); else if(*p == '.') ajStrAppendC(&temp, "..."); else if(*p == '-') ajStrAppendC(&temp, "---"); else if(!isalpha((ajint)*p)) ajStrAppendC(&temp, "???"); else { p3 = embPropCharToThree(*p); if(i++) { ajStrAppendK(&temp, *(p3+2)); ajStrAppendK(&temp, *(p3+1)); ajStrAppendK(&temp, *p3); } else { if(pad >= 2) ajStrAppendK(&temp, *(p3+2)); if(pad >= 1) ajStrAppendK(&temp, *(p3+1)); ajStrAppendK(&temp, *p3); } } } return temp; }
AjPStr embPropProtGaps(AjPSeq seq, ajint pad) { const char *p; AjPStr temp; ajint i; temp = ajStrNewRes(ajSeqGetLen(seq)*3 + pad+1); /* put any required padding spaces at the start */ for(i=0; i<pad; i++) ajStrAppendC(&temp, " "); for(p=ajSeqGetSeqC(seq); *p; p++) { ajStrAppendK(&temp, *p); ajStrAppendC(&temp, " "); } return temp; }
int main(int argc, char *argv[]) { char *string/*, *line*/; char *structure=NULL, *cstruc=NULL; /*char fname[53], ffname[60]; */ /*char *ParamFile=NULL; */ char *ns_bases=NULL, *c; char *Concfile; int i, length, l, sym/*, r*/; double min_en; double kT, sfact=1.07; int pf=0, istty; int noconv=0; int doT=0; /*compute dimere free energies etc.*/ int doC=0; /*toggle to compute concentrations*/ int doQ=0; /*toggle to compute prob of base being paired*/ int cofi=0; /*toggle concentrations stdin / file*/ struct plist *prAB; struct plist *prAA; /*pair probabilities of AA dimer*/ struct plist *prBB; struct plist *prA; struct plist *prB; struct plist *mfAB; struct plist *mfAA; /*pair mfobabilities of AA dimer*/ struct plist *mfBB; struct plist *mfA; struct plist *mfB; double *ConcAandB; AjPSeq seq1 = NULL; AjPFile confile1 = NULL; AjPSeq seq2 = NULL; AjPFile confile2 = NULL; AjPFile concfile = NULL; AjPFile paramfile = NULL; AjPFile outf = NULL; AjPFile essfile = NULL; AjPFile dotfile = NULL; AjPFile aoutf = NULL; AjPFile aaoutf = NULL; AjPFile boutf = NULL; AjPFile bboutf = NULL; AjPFile aboutf = NULL; AjPStr seqstring1 = NULL; AjPStr constring1 = NULL; AjPStr constring2 = NULL; float eT = 0.; AjBool eGU; AjBool eclose; AjBool lonely; AjBool convert; AjPStr ensbases = NULL; AjBool etloop; AjPStr eenergy = NULL; char ewt = '\0'; float escale = 0.; AjPStr edangles = NULL; char edangle = '\0'; /* AjBool dimers; */ /* AjBool paired; */ embInitPV("vrnacofold",argc,argv,"VIENNA",VERSION); seqstring1 = ajStrNew(); constring1 = ajStrNew(); constring2 = ajStrNew(); seq1 = ajAcdGetSeq("asequence"); confile1 = ajAcdGetInfile("aconstraintfile"); seq2 = ajAcdGetSeq("bsequence"); confile2 = ajAcdGetInfile("bconstraintfile"); paramfile = ajAcdGetInfile("paramfile"); eT = ajAcdGetFloat("temperature"); eGU = ajAcdGetBoolean("gu"); eclose = ajAcdGetBoolean("closegu"); lonely = ajAcdGetBoolean("lp"); convert = ajAcdGetBoolean("convert"); ensbases = ajAcdGetString("nsbases"); etloop = ajAcdGetBoolean("tetraloop"); eenergy = ajAcdGetListSingle("energy"); escale = ajAcdGetFloat("scale"); edangles = ajAcdGetListSingle("dangles"); /* dimers = ajAcdGetBoolean("dimers"); */ /* paired = ajAcdGetBoolean("paired"); */ outf = ajAcdGetOutfile("outfile"); essfile = ajAcdGetOutfile("ssoutfile"); /* concfile = ajAcdGetInfile("concentrationfile"); */ /* dotfile = ajAcdGetOutfile("dotoutfile"); */ /* aoutf = ajAcdGetOutfile("aoutfile"); aaoutf = ajAcdGetOutfile("aaoutfile"); boutf = ajAcdGetOutfile("boutfile"); bboutf = ajAcdGetOutfile("bboutfile"); aboutf = ajAcdGetOutfile("aboutfile"); */ do_backtrack = 1; pf = 0; doT = 0; doC = 0; cofi = 0; doQ = 0; string = NULL; Concfile = NULL; istty = 0; temperature = (double) eT; noGU = (eGU) ? 0 : 1; no_closingGU = (eclose) ? 0 : 1; noLonelyPairs = (lonely) ? 0 : 1; noconv = (convert) ? 0 : 1; ns_bases = (ajStrGetLen(ensbases)) ? MAJSTRGETPTR(ensbases) : NULL; tetra_loop = !!etloop; ewt = *ajStrGetPtr(eenergy); if(ewt == '0') energy_set = 0; else if(ewt == '1') energy_set = 1; else if(ewt == '2') energy_set = 2; sfact = (double) escale; edangle = *ajStrGetPtr(edangles); if(edangle == '0') dangles = 0; else if(edangle == '1') dangles = 1; else if(edangle == '2') dangles = 2; else if(edangle == '3') dangles = 3; if(paramfile) read_parameter_file(paramfile); if (ns_bases != NULL) { nonstandards = space(33); c=ns_bases; i=sym=0; if (*c=='-') { sym=1; c++; } while (*c!='\0') { if (*c!=',') { nonstandards[i++]=*c++; nonstandards[i++]=*c; if ((sym)&&(*c!=*(c-1))) { nonstandards[i++]=*c; nonstandards[i++]=*(c-1); } } c++; } } cut_point = -1; ajFmtPrintS(&seqstring1,"%s&%s",ajSeqGetSeqC(seq1),ajSeqGetSeqC(seq2)); string = tokenize(MAJSTRGETPTR(seqstring1)); /* frees line */ length = (int) strlen(string); if (doC) { ConcAandB = read_concentrations(concfile); } structure = (char *) space((unsigned) length+1); if(confile1) { vienna_GetConstraints(confile1,&constring1); vienna_GetConstraints(confile2,&constring2); ajStrAppendK(&constring1,'&'); ajStrAppendS(&constring1,constring2); cstruc = tokenize(MAJSTRGETPTR(constring1)); if (cstruc!=NULL) strncpy(structure, cstruc, length); else ajFatal("Constraints missing\n"); } for (l = 0; l < length; l++) { string[l] = toupper(string[l]); if (!noconv && string[l] == 'T') string[l] = 'U'; } /*compute mfe of AB dimer*/ min_en = cofold(string, structure); mfAB=(struct plist *) space(sizeof(struct plist) * (length+1)); mfAB=get_mfe_plist(mfAB); if (cut_point == -1) ajFmtPrintF(outf,"%s\n%s", string, structure); /*no cofold*/ else { char *pstring, *pstruct; pstring = costring(string); pstruct = costring(structure); ajFmtPrintF(outf,"%s\n%s", pstring, pstruct); free(pstring); free(pstruct); } ajFmtPrintF(outf," (%6.2f)\n", min_en); if (length<2000) (void) PS_rna_plot(string, structure, essfile); else { ajWarn("Structure too long, not doing xy_plot\n"); free_co_arrays(); } /*compute partition function*/ if (pf) { cofoldF AB, AA, BB; if (dangles==1) { dangles=2; /* recompute with dangles as in pf_fold() */ min_en = energy_of_struct(string, structure); dangles=1; } kT = (temperature+273.15)*1.98717/1000.; /* in Kcal */ pf_scale = exp(-(sfact*min_en)/kT/length); if (length>2000) ajWarn("scaling factor %f\n", pf_scale); init_co_pf_fold(length); if (cstruc!=NULL) strncpy(structure, cstruc, length+1); AB = co_pf_fold(string, structure); if (do_backtrack) { char *costruc; costruc = (char *) space(sizeof(char)*(strlen(structure)+2)); if (cut_point<0) ajFmtPrintF(outf,"%s", structure); else { strncpy(costruc, structure, cut_point-1); strcat(costruc, "&"); strcat(costruc, structure+cut_point-1); ajFmtPrintF(outf,"%s", costruc); } ajFmtPrintF(outf," [%6.2f]\n", AB.FAB); } if ((istty)||(!do_backtrack)) ajFmtPrintF(outf," free energy of ensemble = %6.2f kcal/mol\n", AB.FAB); ajFmtPrintF(outf," frequency of mfe structure in ensemble %g", exp((AB.FAB-min_en)/kT)); ajFmtPrintF(outf," , delta G binding=%6.2f\n", AB.FcAB - AB.FA - AB.FB); prAB=(struct plist *) space(sizeof(struct plist) * (2*length)); prAB=get_plist(prAB, length,0.00001); /* if (doQ) make_probsum(length,fname); */ /*compute prob of base paired*/ /* free_co_arrays(); */ if (doT) { /* cofold of all dimers, monomers */ int Blength, Alength; char *Astring, *Bstring; char *Newstring; /*char Newname[30];*/ char comment[80]; if (cut_point<0) { free(mfAB); free(prAB); ajFatal("Sorry, I cannot do that with only one molecule, " "please give me two\n"); } if (dangles==1) dangles=2; Alength=cut_point-1; /*length of first molecule*/ Blength=length-cut_point+1; /*length of 2nd molecule*/ /*Sequence of first molecule*/ Astring=(char *)space(sizeof(char)*(Alength+1)); /*Sequence of second molecule*/ Bstring=(char *)space(sizeof(char)*(Blength+1)); strncat(Astring,string,Alength); strncat(Bstring,string+Alength,Blength); /* compute AA dimer */ prAA=(struct plist *) space(sizeof(struct plist) * (4*Alength)); mfAA=(struct plist *) space(sizeof(struct plist) * (Alength+1)); AA=do_partfunc(Astring, Alength, 2, &prAA, &mfAA); /* compute BB dimer */ prBB=(struct plist *) space(sizeof(struct plist) * (4*Blength)); mfBB=(struct plist *) space(sizeof(struct plist) * (Blength+1)); BB=do_partfunc(Bstring, Blength, 2, &prBB, &mfBB); /*free_co_pf_arrays();*/ /* compute A monomer */ prA=(struct plist *) space(sizeof(struct plist) * (2*Alength)); mfA=(struct plist *) space(sizeof(struct plist) * (Alength+1)); do_partfunc(Astring, Alength, 1, &prA, &mfA); /* compute B monomer */ prB=(struct plist *) space(sizeof(struct plist) * (2*Blength)); mfB=(struct plist *) space(sizeof(struct plist) * (Blength+1)); do_partfunc(Bstring, Blength, 1, &prB, &mfB); compute_probabilities(AB.F0AB, AB.FA, AB.FB, prAB, prA, prB, Alength); compute_probabilities(AA.F0AB, AA.FA, AA.FA, prAA, prA, prA, Alength); compute_probabilities(BB.F0AB, BB.FA, BB.FA, prBB, prA, prB, Blength); ajFmtPrintF(outf,"Free Energies:\nAB\t\tAA\t\tBB\t\tA\t\tB\n%.6f" "\t%6f\t%6f\t%6f\t%6f\n", AB.FcAB, AA.FcAB, BB.FcAB, AB.FA, AB.FB); if (doC) { do_concentrations(AB.FcAB, AA.FcAB, BB.FcAB, AB.FA, AB.FB, ConcAandB, outf); free(ConcAandB);/*freeen*/ } /*AB dot_plot*/ /*write Free Energy into comment*/ sprintf(comment,"\n%%Heterodimer AB FreeEnergy= %.9f\n", AB.FcAB); /*reset cut_point*/ cut_point=Alength+1; (void)PS_dot_plot_list(string, aboutf, prAB, mfAB, comment); /*AA dot_plot*/ sprintf(comment,"\n%%Homodimer AA FreeEnergy= %.9f\n",AA.FcAB); /*write AA sequence*/ Newstring=(char*)space((2*Alength+1)*sizeof(char)); strcpy(Newstring,Astring); strcat(Newstring,Astring); (void)PS_dot_plot_list(Newstring, aaoutf, prAA, mfAA, comment); free(Newstring); /*BB dot_plot*/ sprintf(comment,"\n%%Homodimer BB FreeEnergy= %.9f\n",BB.FcAB); /*write BB sequence*/ Newstring=(char*)space((2*Blength+1)*sizeof(char)); strcpy(Newstring,Bstring); strcat(Newstring,Bstring); /*reset cut_point*/ cut_point=Blength+1; (void)PS_dot_plot_list(Newstring, bboutf, prBB, mfBB, comment); free(Newstring); /*A dot plot*/ /*reset cut_point*/ cut_point=-1; sprintf(comment,"\n%%Monomer A FreeEnergy= %.9f\n",AB.FA); /*write A sequence*/ (void)PS_dot_plot_list(Astring, aoutf, prA, mfA, comment); /*B monomer dot plot*/ sprintf(comment,"\n%%Monomer B FreeEnergy= %.9f\n",AB.FB); /*write B sequence*/ (void)PS_dot_plot_list(Bstring, boutf, prB, mfB, comment); free(Astring); free(Bstring); free(prAB); free(prAA); free(prBB); free(prA); free(prB); free(mfAB); free(mfAA); free(mfBB); free(mfA); free(mfB); } /*end if(doT)*/ }/*end if(pf)*/ if (do_backtrack) { if (!doT) { if (pf) { (void) PS_dot_plot_list(string, dotfile, prAB, mfAB, "doof"); free(prAB); } free(mfAB); } } if (!doT) free_co_pf_arrays(); if (cstruc!=NULL) free(cstruc); free(string); free(structure); ajStrDel(&seqstring1); ajStrDel(&constring1); ajStrDel(&constring2); ajSeqDel(&seq1); ajSeqDel(&seq2); ajStrDel(&ensbases); ajStrDel(&eenergy); ajStrDel(&edangles); ajFileClose(&confile1); ajFileClose(&confile2); ajFileClose(¶mfile); ajFileClose(&outf); ajFileClose(&essfile); if (length<2000) free_co_arrays(); embExit(); return 0; }
void getorf_FindORFs(const AjPSeq seq, ajint len, const AjPTrn trnTable, ajuint minsize, ajuint maxsize, AjPSeqout seqout, AjBool sense, AjBool circular, ajint find, ajint *orf_no, AjBool methionine, ajint around, ORFrec *record) { AjBool ORF[3]; /* true if found an ORF */ AjBool LASTORF[3]; /* true if hit the end of an ORF past the end on the genome in this frame */ AjBool GOTSTOP[3]; /* true if found a STOP in a circular genome's frame when find = P_STOP2STOP or N_STOP2STOP */ ajint start[3]; /* possible starting position of the three frames */ ajint pos; ajint codon; char aa; ajint frame; AjPStr newstr[3]; /* strings of the three frames of ORF sequences that we are growing */ AjPSeq pep = NULL; ajint i; ajint seqlen; const char *chrseq; seqlen = ajSeqGetLen(seq); chrseq = ajSeqGetSeqC(seq); /* initialise the ORF sequences */ newstr[0] = NULL; newstr[1] = NULL; newstr[2] = NULL; /* ** initialise flags for found the last ORF past the end of a circular ** genome */ LASTORF[0] = ajFalse; LASTORF[1] = ajFalse; LASTORF[2] = ajFalse; /* initialise flags for found at least one STOP codon in a frame */ GOTSTOP[0] = ajFalse; GOTSTOP[1] = ajFalse; GOTSTOP[2] = ajFalse; if (circular || find == P_START2STOP || find == N_START2STOP || find == AROUND_START) { ORF[0] = ajFalse; ORF[1] = ajFalse; ORF[2] = ajFalse; } else { /* ** assume already in a ORF so we get ORFs at the start of the ** sequence */ ORF[0] = ajTrue; ORF[1] = ajTrue; ORF[2] = ajTrue; start[0] = 0; start[1] = 1; start[2] = 2; } for (pos=0; pos<seqlen-2; pos++) { codon = ajTrnStartStopC(trnTable, &chrseq[pos], &aa); frame = pos % 3; ajDebug("len=%d, Pos=%d, Frame=%d start/stop=%d, aa=%c", len, pos, frame, codon, aa); /* don't want to find extra ORFs when already been round circ */ if (LASTORF[frame]) continue; if (find == P_STOP2STOP || find == N_STOP2STOP || find == AROUND_INIT_STOP || find == AROUND_END_STOP) { /* look for stop codon to begin reporting ORF */ /* note that there was at least one STOP in a circular genome */ if (codon == STOP) { GOTSTOP[frame] = ajTrue; } /* write details if a STOP is hit or the end of the sequence */ if (codon == STOP || pos >= seqlen-5) { /* ** End of the sequence? If so, append any ** last codon to the sequence - otherwise, ignore the STOP ** codon */ if (codon != STOP) getorf_AppORF(find, &newstr[frame], chrseq, pos, aa); /* Already have a sequence to write out? */ if (ORF[frame]) { if (ajStrGetLen(newstr[frame]) >= minsize && ajStrGetLen(newstr[frame]) <= maxsize) { /* create a new sequence */ if (codon == STOP) getorf_WriteORF(seq, len, seqlen, sense, find, orf_no, start[frame], pos-1, newstr[frame], seqout, around); else getorf_WriteORF(seq, len, seqlen, sense, find, orf_no, start[frame], pos+2, newstr[frame], seqout, around); } ajStrSetClear(&newstr[frame]); } /* ** if its a circular genome and the STOP codon hits past ** the end of the genome in all frames, then break */ if (circular && pos >= len) { ORF[frame] = ajFalse; /* past the end of the genome */ LASTORF[frame] = ajTrue; /* finished getting ORFs */ if (LASTORF[0] && LASTORF[1] && LASTORF[2]) break; } else { /* ** hit a STOP, therefore a potential ORF to write ** out next time, even if the genome is circular */ ORF[frame] = ajTrue; start[frame] = pos+3; /* next start of the ORF */ } } else if (ORF[frame]) /* append sequence to newstr if in an ORF */ getorf_AppORF(find, &newstr[frame], chrseq, pos, aa); } else { /* Look for start: P_START2STOP N_START2STOP AROUND_START */ if (codon == START && !ORF[frame]) { /* not in a ORF already and found a START */ if (pos < len) { /* ** reset the newstr to zero length to enable ** storing the ORF for this */ ajStrSetClear(&newstr[frame]); ORF[frame] = ajTrue; /* now in an ORF */ start[frame] = pos; /* start of the ORF for this frame */ if (methionine) getorf_AppORF(find, &newstr[frame], chrseq, pos, 'M'); else getorf_AppORF(find, &newstr[frame], chrseq, pos, aa); } } else if (codon == STOP) { /* hit a STOP */ /* Already have a sequence to write out? */ if (ORF[frame]) { ORF[frame] = ajFalse; /* not in an ORF */ if (ajStrGetLen(newstr[frame]) >= minsize && ajStrGetLen(newstr[frame]) <= maxsize) { /* create a new sequence */ getorf_WriteORF(seq, len, seqlen, sense, find, orf_no, start[frame], pos-1, newstr[frame], seqout, around); } } /* ** if a circular genome and hit the STOP past ** the end of the genome in all frames, then break */ if (circular && pos >= len) { LASTORF[frame] = ajTrue; /* finished getting ORFs */ if (LASTORF[0] && LASTORF[1] && LASTORF[2]) break; } ajStrSetClear(&newstr[frame]); } else if (pos >= seqlen-5) { /* hit the end of the sequence without a stop */ /* Already have a sequence to write out? */ if (ORF[frame]) { ORF[frame] = ajFalse; /* not in an ORF */ /* ** End of the sequence? If so, append any ** last codon to the sequence - otherwise, ignore the ** STOP codon */ if (pos >= seqlen-5 && pos < seqlen-2) getorf_AppORF(find, &newstr[frame], chrseq, pos, aa); if (ajStrGetLen(newstr[frame]) >= minsize && ajStrGetLen(newstr[frame]) <= maxsize) { /* create a new sequence */ getorf_WriteORF(seq, len, seqlen, sense, find, orf_no, start[frame], pos+2, newstr[frame], seqout, around); } } /* ** if a circular genome and hit the STOP past ** the end of the genome in all frames, then break */ if (circular && pos >= len) { LASTORF[frame] = ajTrue; /* finished getting ORFs */ if (LASTORF[0] && LASTORF[1] && LASTORF[2]) break; } ajStrSetClear(&newstr[frame]); } else if (ORF[frame]) getorf_AppORF(find, &newstr[frame], chrseq, pos, aa); } } /* ** Currently miss reporting a STOP-to-STOP ORF that is ** the full length of a circular genome when there are no STOP codons in ** that frame */ if ((find == P_STOP2STOP || find == N_STOP2STOP) && circular) { if (!GOTSTOP[0]) { /* translate frame 1 into pep */ pep = ajTrnSeqOrig(trnTable, seq, 1); if (ajSeqGetLen(pep) >= minsize && ajSeqGetLen(pep) <= maxsize) getorf_WriteORF(seq, len, seqlen, sense, find, orf_no, 0, seqlen-1, ajSeqGetSeqS(pep), seqout, around); ajSeqDel(&pep); } if (!GOTSTOP[1]) { /* translate frame 2 into pep */ pep = ajTrnSeqOrig(trnTable, seq, 2); if (ajSeqGetLen(pep) >= minsize && ajSeqGetLen(pep) <= maxsize) getorf_WriteORF(seq, len, seqlen, sense, find, orf_no, 1, seqlen-1, ajSeqGetSeqS(pep), seqout, around); ajSeqDel(&pep); } if (!GOTSTOP[2]) { /* translate frame 3 into pep */ pep = ajTrnSeqOrig(trnTable, seq, 3); if (ajSeqGetLen(pep) >= minsize && ajSeqGetLen(pep) >= maxsize) getorf_WriteORF(seq, len, seqlen, sense, find, orf_no, 2, seqlen-1, ajSeqGetSeqS(pep), seqout, around); ajSeqDel(&pep); } } for (i=0;i<3;++i) ajStrDel(&newstr[i]); return; }
int main(int argc, char **argv) { AjPDasServer server = NULL; AjPDasSource source = NULL; AjPDasSegment segment = NULL; AjPStr host = NULL; AjPStr path = NULL; AjPFile outf = NULL; ajint port = 80; AjBool sequencesourcesonly; AjBool entrypoints; AjBool showtestqueries; AjBool runtestqueries = ajTrue; AjBool quickexit = ajFalse; ajint itest=0; ajint j=0; ajint maxtests=0; ajint maxfeatures=0; ajint maxsegments=0; AjIList iter = NULL; AjIList coordsi = NULL; AjIList itereps = NULL; AjPFilebuff buff = NULL; AjPUrlref uo = NULL; AjPList segments = NULL; AjPStr ffname = NULL; AjPStr url = NULL; AjPStr dbhttpver = ajStrNew(); AjPStr dbname = ajStrNew(); AjPStr dbproxy = ajStrNew(); AjPStr servername = NULL; AjPTable titlecount = NULL; const ajuint* count; int k=0; embInit("dastest", argc, argv); host = ajAcdGetString("host"); path = ajAcdGetString("path"); port = ajAcdGetInt("port"); sequencesourcesonly = ajAcdGetBoolean("sequencesourcesonly"); entrypoints = ajAcdGetBoolean("entrypoints"); showtestqueries = ajAcdGetBoolean("showtestqueries"); runtestqueries = ajAcdGetBoolean("runtestqueries"); servername = ajAcdGetString("servername"); outf = ajAcdGetOutfile("outfile"); maxtests = ajAcdGetInt("maxtests"); maxfeatures = ajAcdGetInt("maxfeatures"); maxsegments = ajAcdGetInt("maxsegments"); server = ajDasServerNew(); if(runtestqueries) { url = ajStrNew(); if(!ajNamServer(servername)) { ajWarn("following das server is required to be defined " "for test queries..."); ajWarn("\nSERVER %S [\n" " type: \"sequence\"\n" " method: \"das\"\n" " url: \"http://%S%S\"\n" "]\n",servername, host,path); ajWarn("ignoring -runtestqueries option..."); runtestqueries = ajFalse; } else { ajNamSvrGetUrl(servername, &url); ajHttpUrlDeconstruct(url, &port, &host, &path); ajStrDel(&url); } } ajDasServerSethostS(server,host); ajDasServerSetport(server,port); if(ajStrGetCharLast(path)!='/') ajStrAppendK(&path,'/'); ajStrAppendC(&path,"sources"); ajDasServerSetpathS(server,path); ajFmtPrintF(outf,"host = %S\npath = %S\nport = %d\n", server->host, server->path, server->port); /* * TODO: stop using http-read but instead use * ajNamSvrListListDatabases(svrname, dbnames); */ buff = ajHttpRead(dbhttpver, dbname, dbproxy, host, port, path); if(!buff) ajExitAbort(); ajFilebuffHtmlNoheader(buff); ajDasParseRegistry(buff, server->sources); ajFmtPrintF(outf,"DAS sources and descriptions\n\n"); titlecount = dastestGetTitleCount(server); iter = ajListIterNew(server->sources); while(!ajListIterDone(iter) && !quickexit) { source = ajListIterGet(iter); if ((sequencesourcesonly && !source->sequence) || ajStrMatchC(source->title,"cath") || k++ <50) continue; ajFmtPrintF(outf,"%-30S %-50S\n%S\n",source->uri,source->title, source->description); if(entrypoints && source->entry_points) { uo = ajHttpUrlrefNew(); ajHttpUrlrefParseC(&uo, ajStrGetPtr(source->entry_points_uri)); if(ajStrGetLen(uo->Port)) ajStrToInt(uo->Port, &port); else port = 80; ajFilebuffDel(&buff); buff = ajHttpRead(dbhttpver, dbname, dbproxy, uo->Host, port, uo->Absolute); ajHttpUrlrefDel(&uo); if(!buff) continue; ajFilebuffHtmlNoheader(buff); segments = ajListNew(); ajDasParseEntrypoints(buff, segments); itereps = ajListIterNew(segments); ajFmtPrintF(outf, "Number of entry points %d\n", ajListGetLength(segments)); j=0; while(!ajListIterDone(itereps)) { segment = ajListIterGet(itereps); if (j++ < maxsegments) ajFmtPrintF(outf, "segment id:%S orientation:%S start:%d stop:%d\n", segment->id, segment->orientation, segment->start, segment->stop); ajDasSegmentDel(&segment); } ajListIterDel(&itereps); ajListFree(&segments); } if(showtestqueries || runtestqueries) { AjPDasCoordinate coord; coordsi = ajListIterNew(source->coordinates); while(!ajListIterDone(coordsi) && !quickexit) { coord = ajListIterGet(coordsi); ajDebug("coordinate uri:%S taxid:%S source:%S test_range:%S\n", coord->uri, coord->taxid, coord->source, coord->test_range); if(showtestqueries) { if(source->sequence) ajFmtPrintF(outf, "example/test entry = '%S?segment=%S'\n", source->sequence_query_uri,coord->test_range); if(source->features) ajFmtPrintF(outf, "example/test entry = '%S?segment=%S'\n", source->features_query_uri,coord->test_range); } if(runtestqueries) { AjPStr idqry = ajStrNew(); AjPStr entry = NULL; AjPSeq seq = NULL; ajint ibegin = 0; ajint iend = 0; AjPStr example = NULL; example = ajDasTestrangeParse(coord->test_range, &entry, &ibegin, &iend); if(ajStrGetLen(entry)) { count = ajTableFetchS(titlecount, source->title); dbname = ajDasSourceGetDBname(source, *count>1); if (source->features) { AjPStr qpath=NULL; uo = ajHttpUrlrefNew(); ajFmtPrintS(&idqry,"dasgff::%S:%S:%S", servername, dbname, entry); ajFmtPrintF(outf, "feature query: %S start:%d end:%d\n", idqry, ibegin, iend); ajHttpUrlrefParseC(&uo, ajStrGetPtr(source->features_query_uri)); ajHttpUrlrefSplitPort(uo); ajFmtPrintS(&qpath,"%S?segment=%S", uo->Absolute,entry); if(iend>0) ajFmtPrintAppS(&qpath,":%d,%d",ibegin, iend); if(ajStrGetLen(uo->Port)) ajStrToInt(uo->Port, &port); else port = 80; ajDebug("calling ajHttpRead to get the raw" " output; host:%S port:%d path:%S\n", uo->Host, port, qpath); ajFilebuffDel(&buff); buff = ajHttpRead(dbhttpver, dbname, dbproxy, uo->Host, port, qpath); if(buff) { AjPFeattable ft; ajFmtPrintS(&ffname, "%S.%S", source->uri, entry); ajFilebuffHtmlNoheader(buff); dastestSaveRawFeatures(buff, ffname); ajDebug("now using EMBOSS feature queries\n"); ft = dastestFeatureQuery(idqry, ibegin, iend); dastestSaveMappedFeatures(ft, ffname, outf, maxfeatures); ajStrDel(&ffname); ajFeattableDel(&ft); } ajHttpUrlrefDel(&uo); ajStrDel(&qpath); if(++itest>=maxtests) quickexit = ajTrue; } else if(source->sequence) { seq = ajSeqNewRes(iend-ibegin+1); ajFmtPrintS(&idqry,"%S:%S:%S", servername, dbname, entry); ajFmtPrintF(outf, "sequence query: %S start:%d end:%d\n", idqry, ibegin, iend); ajSeqGetFromUsaRange(idqry, ajFalse, ibegin, iend, seq); ajFmtPrintF(outf, "length of sequence returned: %d\n", ajSeqGetLen(seq)); if(ajSeqGetLen(seq)>0) ajFmtPrintF(outf, "sequence returned (first 100 bases):" " %-100.100s\n", ajSeqGetSeqC(seq)); ajSeqDel(&seq); } ajStrDel(&dbname); } ajStrDel(&entry); ajStrDel(&idqry); ajStrDel(&example); } } ajListIterDel(&coordsi); } } ajListIterDel(&iter); ajDasServerDel(&server); ajFilebuffDel(&buff); ajStrDel(&host); ajStrDel(&path); ajStrDel(&servername); ajStrDel(&dbhttpver); ajStrDel(&dbname); ajStrDel(&dbproxy); ajFileClose(&outf); ajTableDelValdel(&titlecount, ajMemFree); embExit(); return 0; }
int main(int argc, char **argv) { AjPAlign align; AjPSeqall seqall; AjPSeq a; AjPSeq b; AjPStr alga; AjPStr algb; AjPStr ss; ajuint lena; ajuint lenb; const char *p; const char *q; ajint start1 = 0; ajint start2 = 0; float *path; ajint *compass; float* ix; float* iy; float* m; AjPMatrixf matrix; AjPSeqCvt cvt = 0; float **sub; float gapopen; float gapextend; float endgapopen; float endgapextend; ajulong maxarr = 1000; /* arbitrary. realloc'd if needed */ ajulong len; float score; AjBool dobrief = ajTrue; AjBool endweight = ajFalse; /* whether end gap penalties should be applied */ float id = 0.; float sim = 0.; float idx = 0.; float simx = 0.; AjPStr tmpstr = NULL; size_t stlen; embInit("needle", argc, argv); matrix = ajAcdGetMatrixf("datafile"); a = ajAcdGetSeq("asequence"); ajSeqTrim(a); seqall = ajAcdGetSeqall("bsequence"); gapopen = ajAcdGetFloat("gapopen"); gapextend = ajAcdGetFloat("gapextend"); endgapopen = ajAcdGetFloat("endopen"); endgapextend = ajAcdGetFloat("endextend"); dobrief = ajAcdGetBoolean("brief"); endweight = ajAcdGetBoolean("endweight"); align = ajAcdGetAlign("outfile"); gapopen = ajRoundFloat(gapopen, 8); gapextend = ajRoundFloat(gapextend, 8); AJCNEW(path, maxarr); AJCNEW(compass, maxarr); AJCNEW(m, maxarr); AJCNEW(ix, maxarr); AJCNEW(iy, maxarr); alga = ajStrNew(); algb = ajStrNew(); ss = ajStrNew(); sub = ajMatrixfGetMatrix(matrix); cvt = ajMatrixfGetCvt(matrix); lena = ajSeqGetLen(a); while(ajSeqallNext(seqall,&b)) { ajSeqTrim(b); lenb = ajSeqGetLen(b); if(lenb > (ULONG_MAX/(ajulong)(lena+1))) ajFatal("Sequences too big. Try 'stretcher' or 'supermatcher'"); len = lena*lenb; if(len>maxarr) { stlen = (size_t) len; AJCRESIZETRY(path,stlen); if(!path) ajDie("Sequences too big. Try 'stretcher'"); AJCRESIZETRY(compass,stlen); if(!compass) ajDie("Sequences too big. Try 'stretcher'"); AJCRESIZETRY(m,stlen); if(!m) ajDie("Sequences too big. Try 'stretcher'"); AJCRESIZETRY(ix,stlen); if(!ix) ajDie("Sequences too big. Try 'stretcher'"); AJCRESIZETRY(iy,stlen); if(!iy) ajDie("Sequences too big. Try 'stretcher'"); maxarr=len; } p = ajSeqGetSeqC(a); q = ajSeqGetSeqC(b); ajStrAssignC(&alga,""); ajStrAssignC(&algb,""); score = embAlignPathCalcWithEndGapPenalties(p, q, lena, lenb, gapopen, gapextend, endgapopen, endgapextend, &start1, &start2, path, sub, cvt, m, ix, iy, compass, ajTrue, endweight); embAlignWalkNWMatrixUsingCompass(p, q, &alga, &algb, lena, lenb, &start1, &start2, compass); embAlignReportGlobal(align, a, b, alga, algb, start1, start2, gapopen, gapextend, score, matrix, ajSeqGetOffset(a), ajSeqGetOffset(b)); if(!dobrief) { embAlignCalcSimilarity(alga,algb,sub,cvt,lena,lenb,&id,&sim,&idx, &simx); ajFmtPrintS(&tmpstr,"Longest_Identity = %5.2f%%\n", id); ajFmtPrintAppS(&tmpstr,"Longest_Similarity = %5.2f%%\n", sim); ajFmtPrintAppS(&tmpstr,"Shortest_Identity = %5.2f%%\n", idx); ajFmtPrintAppS(&tmpstr,"Shortest_Similarity = %5.2f%%", simx); ajAlignSetSubHeaderApp(align, tmpstr); } ajAlignWrite(align); ajAlignReset(align); } ajAlignClose(align); ajAlignDel(&align); ajSeqallDel(&seqall); ajSeqDel(&a); ajSeqDel(&b); AJFREE(compass); AJFREE(path); AJFREE(ix); AJFREE(iy); AJFREE(m); ajStrDel(&alga); ajStrDel(&algb); ajStrDel(&ss); ajStrDel(&tmpstr); embExit(); return 0; }
void emboss_copy(AjPSeqset seqset, char ***retseqs, AINFO *info) { ajint n; ajint maxlen; ajint len; char **seqs; const AjPSeq seq = NULL; ajint i=0; const AjPStr fmt=NULL; const char *p=NULL; char c='\0'; /* char *q=NULL; AjPSelexseq sqdata=NULL; AjPSelexdata sdata=NULL; */ ajint cnt=0; info->name = NULL; info->rf=NULL; info->cs=NULL; info->desc=NULL; info->acc=NULL; info->au=NULL; info->flags=0; AjPStr tmpstr = NULL; ajSeqsetFill(seqset); fmt = ajSeqsetGetFormat(seqset); n = ajSeqsetGetSize(seqset); ajSeqsetFmtUpper(seqset); maxlen = ajSeqsetGetLen(seqset); /* First allocate and copy sequences */ AJCNEW0(seqs,n); for(i=0; i<n; ++i) { seqs[i] = ajCharNewRes(maxlen+1); strcpy(seqs[i],ajSeqGetSeqC(ajSeqsetGetseqSeq(seqset,i))); } info->sqinfo = (SQINFO *) calloc (sizeof(SQINFO), n); for(i=0; i<n; ++i) { info->sqinfo[i].flags = 0; strcpy(info->sqinfo[i].name,""); strcpy(info->sqinfo[i].id,""); strcpy(info->sqinfo[i].acc,""); strcpy(info->sqinfo[i].desc,""); info->sqinfo[i].len = 0; info->sqinfo[i].start = 0; info->sqinfo[i].stop = 0; info->sqinfo[i].olen = 0; info->sqinfo[i].type = 0; info->sqinfo[i].ss = NULL; info->sqinfo[i].sa =NULL; } AJCNEW0(info->wgt,n); for(i=0; i<n; ++i) { info->sqinfo[i].flags = 0; info->wgt[i] = ajSeqsetGetseqWeight(seqset,i); } info->nseq = n; info->alen = maxlen; for(i=0; i<n; ++i) { seq = ajSeqsetGetseqSeq(seqset,i); if((len=ajStrGetLen(ajSeqGetNameS(seq)))) { if(len>= SQINFO_NAMELEN) len = SQINFO_NAMELEN - 1; ajStrAssignSubS(&tmpstr, ajSeqGetNameS(seq), 0, len); strcpy(info->sqinfo[i].id,ajStrGetPtr(tmpstr)); info->sqinfo[i].flags |= SQINFO_ID; strcpy(info->sqinfo[i].name,ajStrGetPtr(tmpstr)); info->sqinfo[i].flags |= SQINFO_NAME; } if((len=ajStrGetLen(ajSeqGetAccS(seq)))) { if(len>= SQINFO_NAMELEN) len = SQINFO_NAMELEN - 1; ajStrAssignSubS(&tmpstr, ajSeqGetAccS(seq), 0, len); strcpy(info->sqinfo[i].acc,ajStrGetPtr(tmpstr)); info->sqinfo[i].flags |= SQINFO_ACC; } } seq = ajSeqsetGetseqSeq(seqset,0); info->cs = ajCharNewS(ajSeqGetSeqS(seq)); info->name = ajCharNewS(ajSeqGetNameS(seq)); info->acc = ajCharNewS(ajSeqGetAccS(seq)); info->desc = ajCharNewS(ajSeqGetDescS(seq)); info->rf = ajCharNewS(ajSeqGetSeqS(seq)); /* info->rf = ajCharNewS(seq); len = ajStrGetLen(seq->Selexdata->name); info->name = ajCharNewRes(len+1); strcpy(info->name,ajStrGetPtr(seq->Selexdata->name)); len = ajStrGetLen(seq->Selexdata->de); info->desc = ajCharNewRes(len+1); sdata = seq->Selexdata; strcpy(info->desc,ajStrGetPtr(sdata->de)); len = ajStrGetLen(sdata->ac); info->acc = ajCharNewRes(len+1); strcpy(info->acc,ajStrGetPtr(sdata->ac)); len = ajStrGetLen(sdata->au); info->au = ajCharNewRes(len+1); strcpy(info->au,ajStrGetPtr(sdata->au)); if(sdata->tc[0] || sdata->tc[1]) { info->flags |= AINFO_TC; info->tc1 = sdata->tc[0]; info->tc2 = sdata->tc[1]; } if(sdata->nc[0] || sdata->nc[1]) { info->flags |= AINFO_NC; info->nc1 = sdata->nc[0]; info->nc2 = sdata->nc[1]; } if(sdata->ga[0] || sdata->ga[1]) { info->flags |= AINFO_GA; info->ga1 = sdata->ga[0]; info->ga2 = sdata->ga[1]; } for(i=0;i<n;++i) { seq = ajSeqsetGetseqSeq(seqset,i); sqdata = seq->Selexdata->sq; if((len=ajStrGetLen(sqdata->name))) { if(len<64) strcpy(info->sqinfo[i].name,ajStrGetPtr(sqdata->name)); else strncpy(info->sqinfo[i].name,ajStrGetPtr(sqdata->name),63); info->sqinfo[i].name[63]='\0'; info->sqinfo[i].flags |= SQINFO_NAME; } / * if((len=ajStrGetLen(sqdata->id))) { if(len<64) strcpy(info->sqinfo[i].id,ajStrGetPtr(sqdata->id)); else strncpy(info->sqinfo[i]->id,ajStrGetPtr(sqdata->id),63); info->sqinfo[i].id[63]='\0'; info->sqinfo[i].flags |= SQINFO_ID; } * / strcpy(info->sqinfo[i].id,info->sqinfo[i].name); info->sqinfo[i].flags |= SQINFO_ID; if((len=ajStrGetLen(sqdata->ac))) { if(len<64) strcpy(info->sqinfo[i].acc,ajStrGetPtr(sqdata->ac)); else strncpy(info->sqinfo[i].acc,ajStrGetPtr(sqdata->ac),63); info->sqinfo[i].acc[63]='\0'; info->sqinfo[i].flags |= SQINFO_ACC; } if((len=ajStrGetLen(sqdata->de))) { if(len<127) strcpy(info->sqinfo[i].desc,ajStrGetPtr(sqdata->de)); else strncpy(info->sqinfo[i].desc,ajStrGetPtr(sqdata->de),127); info->sqinfo[i].desc[127]='\0'; info->sqinfo[i].flags |= SQINFO_DESC; } if(sqdata->start || sqdata->stop || sqdata ->len) { info->sqinfo[i].start = sqdata->start; info->sqinfo[i].stop = sqdata->stop; info->sqinfo[i].olen = sqdata->len; info->sqinfo[i].flags |= SQINFO_START; info->sqinfo[i].flags |= SQINFO_STOP; info->sqinfo[i].flags |= SQINFO_OLEN; } if(ajStrGetLen(seq->Selexdata->ss)) { info->sqinfo[i].ss = ajCharNewRes(maxlen+1); p = ajStrGetPtr(seq->Selexdata->ss); q = info->sqinfo[i].ss; while((c==*p)) { if(c=='.' || c==' ' || c=='_' || c=='-') *q++ = c; ++p; } *q = '\0'; info->sqinfo[i].flags |= SQINFO_SS; } } } / * } */ for(i=0; i<n; ++i) { info->sqinfo[i].type = kOtherSeq; if(ajSeqsetIsDna(seqset)) info->sqinfo[i].type = kDNA; if(ajSeqsetIsRna(seqset)) info->sqinfo[i].type = kRNA; if(ajSeqsetIsProt(seqset)) info->sqinfo[i].type = kAmino; info->sqinfo[i].flags |= SQINFO_TYPE; seq = ajSeqsetGetseqSeq(seqset,i); p = ajSeqGetSeqC(seq); cnt = 0; while((c=*p)) { if(!(c=='.' || c==' ' || c=='_' || c=='-' || c=='~')) ++cnt; ++p; } info->sqinfo[i].len = cnt; info->sqinfo[i].flags |= SQINFO_LEN; } *retseqs = seqs; ajStrDel(&tmpstr); return; }
int main(int argc, char **argv) { AjPSeqall seqall; AjPSeq sequence; AjPFile outfile; ajint minLen; ajint maxLen; ajint maxGap; ajint beginPos; ajint endPos; ajint maxmismatches; AjPStr seqstr; ajint current; ajint rev; ajint count; ajint gap; ajint begin; ajint end; ajint mismatches; ajint mismatchAtEnd; ajint istart; ajint iend; ajint ic; ajint ir; AjBool alln; /* TRUE if all of palindrome is N's */ Palindrome pfirstpal; Palindrome plastpal = NULL; Palindrome ppal = NULL; Palindrome pnext = NULL; AjBool found = AJFALSE; embInit("palindrome", argc, argv); seqall = ajAcdGetSeqall("sequence"); minLen = ajAcdGetInt("minpallen"); maxLen = ajAcdGetInt("maxpallen"); maxGap = ajAcdGetInt("gaplimit"); outfile = ajAcdGetOutfile("outfile"); maxmismatches = ajAcdGetInt("nummismatches"); overlap = ajAcdGetBoolean("overlap"); while(ajSeqallNext(seqall, &sequence)) { beginPos = ajSeqallGetseqBegin(seqall); endPos = ajSeqallGetseqEnd(seqall); /* set to NULL to indicate that we have no first palindrome find yet */ pfirstpal = NULL; /* write header to file */ ajFmtPrintF(outfile, "Palindromes of: %s \n", ajSeqGetNameC(sequence)); ajFmtPrintF(outfile, "Sequence length is: %d \n", ajSeqGetLen(sequence)); ajFmtPrintF(outfile, "Start at position: %d\nEnd at position: %d\n", beginPos, endPos); ajFmtPrintF(outfile,"Minimum length of Palindromes is: %d \n", minLen); ajFmtPrintF(outfile,"Maximum length of Palindromes is: %d \n", maxLen); ajFmtPrintF(outfile,"Maximum gap between elements is: %d \n", maxGap); ajFmtPrintF(outfile,"Number of mismatches allowed in Palindrome: %d\n", maxmismatches); ajFmtPrintF(outfile, "\n\n\n"); ajFmtPrintF(outfile, "Palindromes:\n"); /* set vars in readiness to enter loop */ seqstr = ajStrNewC(ajSeqGetSeqC(sequence)); begin = beginPos - 1; end = endPos - 1; ajStrFmtLower(&seqstr); /* make comparisons case independent */ /* loop to look for inverted repeats */ for(current = begin; current < end; current++) { iend = current + 2*(maxLen) + maxGap; if(iend > end) iend = end; istart = current + minLen; for(rev = iend; rev > istart; rev--) { count = 0; mismatches = 0; mismatchAtEnd = 0; alln = ajTrue; ic = current; ir = rev; if(ajStrGetCharPos(seqstr, ic) == ajBaseAlphacharComp(ajStrGetCharPos(seqstr, ir))) while(mismatches <= maxmismatches && ic < ir) { if(ajStrGetCharPos(seqstr, ic++) == ajBaseAlphacharComp(ajStrGetCharPos(seqstr, ir--))) { mismatchAtEnd = 0; if(ajStrGetCharPos(seqstr, ic-1) != 'n') alln = ajFalse; } else { mismatches++; mismatchAtEnd++; } count++; } count -= mismatchAtEnd; gap = rev - current - count - count + 1; /* Find out if there's a reverse repeat long enough */ if(count >= minLen && gap <= maxGap && !alln) { /* create new struct to hold palindrome data */ ppal = palindrome_New(current,(current+count),rev, (rev-count)); /* ** if it is the first palindrome find then save it as start ** of palindrome list */ if(pfirstpal == NULL) { pfirstpal = ppal; plastpal = ppal; } else { /* Is it a subset of a palindrome already met */ pnext = pfirstpal; found = AJFALSE; while(pnext != NULL) { if(overlap && palindrome_AInB(ppal, pnext)) { found = AJTRUE; break; } if(!overlap && palindrome_AOverB(ppal, pnext)) { if(palindrome_Longer(ppal, pnext)) { palindrome_Swap(ppal, pnext); } found = AJTRUE; break; } pnext = pnext->next; } /* if new palindrome add to end of list */ if(!found) { plastpal->next = ppal; plastpal = ppal; } else AJFREE(ppal); } } } } /* Print out palindromes */ ppal = pfirstpal; while(ppal != NULL) { palindrome_Print(outfile, seqstr, ppal, maxLen); ppal = ppal->next; } /* make a gap beween outputs of different sequences */ ajFmtPrintF(outfile, "\n\n\n"); /* free memory used for palindrome list */ ppal = pfirstpal; while(ppal != NULL) { pnext = ppal->next; AJFREE(ppal); ppal = pnext; } ajStrDel(&seqstr); } ajFileClose(&outfile); ajSeqallDel(&seqall); ajSeqDel(&sequence); ajStrDel(&seqstr); embExit(); return 0; }
int main(int argc, char *argv[]) { char *start; char *structure; char *rstart; char *str2; char *line; int i; int length; int l; int hd; double energy = 0.; double kT; int pf = 0; int mfe = 0; int istty; int repeat; int found; AjPFile inf = NULL; AjPSeq seq = NULL; AjPFile paramfile = NULL; AjPFile outf = NULL; float eT = 0.; AjBool eGU; AjBool eclose; AjBool lonely; AjBool etloop; AjPStr eenergy = NULL; char ewt = '\0'; AjPStr edangles = NULL; AjPStr method = NULL; AjPStr ealpha = NULL; AjBool showfails = ajFalse; AjBool succeed = ajFalse; char edangle = '\0'; ajint len; FILE *fp; embInitPV("vrnainverse",argc,argv,"VIENNA",VERSION); inf = ajAcdGetInfile("structuresfile"); seq = ajAcdGetSeq("sequence"); paramfile = ajAcdGetInfile("paramfile"); eT = ajAcdGetFloat("temperature"); eGU = ajAcdGetBoolean("gu"); eclose = ajAcdGetBoolean("closegu"); lonely = ajAcdGetBoolean("lp"); etloop = ajAcdGetBoolean("tetraloop"); eenergy = ajAcdGetListSingle("energy"); edangles = ajAcdGetListSingle("dangles"); method = ajAcdGetListSingle("folding"); ealpha = ajAcdGetString("alphabet"); final_cost = ajAcdGetFloat("final"); repeat = ajAcdGetInt("repeats"); showfails = ajAcdGetBoolean("showfails"); succeed = ajAcdGetBoolean("succeed"); outf = ajAcdGetOutfile("outfile"); do_backtrack = 0; structure = NULL; istty = 0; temperature = (double) eT; noGU = (eGU) ? 0 : 1; no_closingGU = (eclose) ? 0 : 1; noLonelyPairs = (lonely) ? 0 : 1; tetra_loop = !!etloop; ewt = *ajStrGetPtr(eenergy); if(ewt == '0') energy_set = 0; else if(ewt == '1') energy_set = 1; else if(ewt == '2') energy_set = 2; edangle = *ajStrGetPtr(edangles); if(edangle == '0') dangles = 0; else if(edangle == '1') dangles = 1; else if(edangle == '2') dangles = 2; else if(edangle == '3') dangles = 3; if(ajStrMatchC(method,"mp")) { mfe = 1; pf = 1; } else if(ajStrMatchC(method,"m")) { mfe = 1; pf = 0; } else if(ajStrMatchC(method,"p")) { mfe = 0; pf = 1; } len = ajStrGetLen(ealpha); symbolset = (char *) space(len + 1); strcpy(symbolset, ajStrGetPtr(ealpha)); for (l = 0; l < len; l++) symbolset[l] = toupper(symbolset[l]); inv_verbose = !!showfails; fp = ajFileGetFileptr(inf); init_rand(); kT = (temperature+273.15)*1.98717/1000.0; istty = (isatty(fileno(stdout))&&isatty(fileno(stdin))); if (paramfile) read_parameter_file(paramfile); give_up = succeed; do { if ((line = get_line(fp))==NULL) break; /* read structure, skipping over comment lines */ while ((*line=='*')||(*line=='\0')||(*line=='>')) { free(line); if ((line = get_line(fp))==NULL) break; } /* stop at eof or '@' */ if (line==NULL) break; if (strcmp(line, "@") == 0) { free(line); break; } structure = (char *) space(strlen(line)+1); /* scanf gets rid of trailing junk */ (void) sscanf(line,"%s",structure); free(line); length = (int) strlen(structure); str2 = (char *) space((unsigned)length+1); /* now look for a sequence to match the structure */ /* if ((line = get_line(fp))!=NULL) if (strcmp(line, "@") == 0) { free(line); break; } */ start = (char *) space((unsigned) length+1); if(seq) (void) strncpy(start, ajSeqGetSeqC(seq), length); if (repeat!=0) found = repeat; else found = 1; initialize_fold(length); rstart = (char *) space((unsigned)length+1); while(found>0) { char *string; string = (char *) space((unsigned)length+1); strcpy(string, start); for (i=0; i<length; i++) { /* lower case characters are kept fixed, any other character not in symbolset is replaced by a random character */ if (islower(string[i])) continue; if (string[i]=='\0' || (strchr(symbolset,string[i])==NULL)) string[i]=symbolset[int_urn(0,strlen(symbolset)-1)]; } strcpy(rstart, string); /* remember start string */ if (mfe) { energy = inverse_fold(string, structure); if( (!succeed) || (energy<=0.0) ) { found--; hd = hamming(rstart, string); ajFmtPrintF(outf,"%s %3d", string, hd); if (energy>0) { /* no solution found */ ajFmtPrintF(outf," d = %f\n", energy); } else ajFmtPrintF(outf,"\n"); } } if (pf) { if (!(mfe && give_up && (energy>0))) { /* unless we gave up in the mfe part */ double prob, min_en, sfact=1.07; /* get a reasonable pf_scale */ min_en = fold(string,str2); pf_scale = exp(-(sfact*min_en)/kT/length); init_pf_fold(length); energy = inverse_pf_fold(string, structure); prob = exp(-energy/kT); hd = hamming(rstart, string); ajFmtPrintF(outf,"%s %3d (%f)\n", string, hd, prob); free_pf_arrays(); } if (!mfe) found--; } free(string); } free(rstart); free_arrays(); free(structure); free(str2); free(start); } while (1); ajSeqDel(&seq); ajStrDel(&eenergy); ajStrDel(&edangles); ajStrDel(&method); ajStrDel(&ealpha); ajFileClose(&inf); ajFileClose(¶mfile); ajFileClose(&outf); AJFREE(symbolset); embExit(); return 0; }
int main(ajint argc, char **argv) { AjPFile datafile; AjPFile outf = NULL; AjPSeqall seqall; AjPSeq ajseq = NULL; ajuint i; ajint verb; ajint window; ajint pt; ajint which; ajint weighted; ajint t = 0; ajint tc = 0; ajint mode; ajint min_seg; const AjPStr seqdes; float min_P; struct hept_pref *h; embInit("newcoils",argc,argv); window = ajAcdGetInt("window"); weighted = ajAcdGetInt("weighted"); verb = ajAcdGetInt("verb"); mode = ajAcdGetInt("mode"); min_P = ajAcdGetFloat("minp"); min_seg = ajAcdGetInt("minseg"); outf = ajAcdGetOutfile("outfile"); datafile = ajAcdGetDatafile("datafile"); seqall = ajAcdGetSeqall("sequence"); ajseq = ajSeqNew(); h = newcoils_read_matrix(datafile); if(verb) { for(i=0; i<strlen(NCAAs); ++i) if(NCAAs[i] != '_') { pt = (int)(NCAAs[i]-'A'); ajFmtPrintF(outf,"AA %c %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f " "%4.2f\n",NCAAs[i],h->m[pt][0],h->m[pt][1], h->m[pt][2],h->m[pt][3],h->m[pt][4], h->m[pt][5],h->m[pt][6]); } for(i=0; i<(ajuint)h->n; ++i) ajFmtPrintF(outf,"Window %4d %1d %f %f %f %f %f\n",h->f[i].win, h->f[i].w,h->f[i].m_cc,h->f[i].sd_cc,h->f[i].m_g, h->f[i].sd_g,h->f[i].sc); } /* See if there is a file for the chosen window length/weight scheme */ which = -1; for(i=0; i<(ajuint)h->n; ++i) { if((h->f[i].win == window) && (h->f[i].w == weighted)) { /* match */ if(verb) ajFmtPrintF(outf,"Found fitting data for win %4d w %d\n", window,weighted); which = i; } } while(ajSeqallNext(seqall, &ajseq)) { seqdes = ajSeqGetDescS(ajseq); newcoils_pred_coils(outf,ajSeqGetSeqC(ajseq),ajSeqGetNameC(ajseq), seqdes,h,window, which,weighted,mode,min_P,&t,&tc,min_seg); } if (outf) ajFileClose(&outf); ajSeqDel(&ajseq); embExit(); return 0; }
int main(int argc, char *argv[]) { char *sequence; char *structure = NULL; char *ns_bases = NULL, *c; int i, length, l, sym; int istty; double deltap=0.; int delta=100; int n_back = 0; int noconv=0; int circ=0; int dos=0; AjPSeq seq = NULL; AjPFile confile = NULL; AjPFile paramfile = NULL; AjPFile outf = NULL; AjPStr constring = NULL; float eT = 0.; AjBool eGU; AjBool eclose; AjBool lonely; AjBool convert; AjPStr ensbases = NULL; AjBool etloop; AjPStr edangles = NULL; char edangle = '\0'; ajint len; float erange; float prange; embInitPV("vrnasubopt",argc,argv,"VIENNA",VERSION); constring = ajStrNew(); seq = ajAcdGetSeq("sequence"); confile = ajAcdGetInfile("constraintfile"); paramfile = ajAcdGetInfile("paramfile"); eT = ajAcdGetFloat("temperature"); circ = !!ajAcdGetBoolean("circular"); dos = !!ajAcdGetBoolean("dos"); eGU = ajAcdGetBoolean("gu"); eclose = ajAcdGetBoolean("closegu"); lonely = ajAcdGetBoolean("lp"); convert = ajAcdGetBoolean("convert"); ensbases = ajAcdGetString("nsbases"); etloop = ajAcdGetBoolean("tetraloop"); erange = ajAcdGetFloat("erange"); prange = ajAcdGetFloat("prange"); subopt_sorted = !!ajAcdGetBoolean("sort"); logML = !!ajAcdGetBoolean("logml"); n_back = ajAcdGetInt("nrandom"); edangles = ajAcdGetListSingle("dangles"); outf = ajAcdGetOutfile("outfile"); if(dos) print_energy = -999999; do_backtrack = 1; istty = 0; temperature = (double) eT; noGU = (eGU) ? 0 : 1; no_closingGU = (eclose) ? 0 : 1; noLonelyPairs = (lonely) ? 0 : 1; noconv = (convert) ? 0 : 1; ns_bases = (ajStrGetLen(ensbases)) ? MAJSTRGETPTR(ensbases) : NULL; tetra_loop = !!etloop; delta = (int) (0.1 + erange * 100); deltap = prange; edangle = *ajStrGetPtr(edangles); if(edangle == '0') dangles = 0; else if(edangle == '1') dangles = 1; else if(edangle == '2') dangles = 2; else if(edangle == '3') dangles = 3; if(paramfile) read_parameter_file(paramfile); if (ns_bases != NULL) { nonstandards = space(33); c=ns_bases; i=sym=0; if (*c=='-') { sym=1; c++; } while (*c) { if (*c!=',') { nonstandards[i++]=*c++; nonstandards[i++]=*c; if ((sym)&&(*c!=*(c-1))) { nonstandards[i++]=*c; nonstandards[i++]=*(c-1); } } c++; } } if(confile) vienna_GetConstraints(confile,&constring); if(n_back) init_rand(); sequence = NULL; structure = NULL; length = ajSeqGetLen(seq); sequence = (char *) space(length+1); strcpy(sequence,ajSeqGetSeqC(seq)); len = ajStrGetLen(constring); structure = (char *) space(length+1); if(len) { fold_constrained = 1; strcpy(structure,ajStrGetPtr(constring)); } istty = 0; if (fold_constrained) { for (i=0; i<length; i++) if (structure[i]=='|') ajFatal("Constraints of type '|' are not allowed\n"); } for (l = 0; l < length; l++) { sequence[l] = toupper(sequence[l]); if (!noconv && sequence[l] == 'T') sequence[l] = 'U'; } if ((logML!=0 || dangles==1 || dangles==3) && dos==0) if (deltap<=0) deltap=delta/100. +0.001; if (deltap>0) print_energy = deltap; /* first lines of output (suitable for sort +1n) */ ajFmtPrintF(outf,"> %s [%d]\n", ajSeqGetNameC(seq), delta); if(n_back>0) { int i; double mfe, kT; char *ss; st_back=1; ss = (char *) space(strlen(sequence)+1); strncpy(ss, structure, length); mfe = (circ) ? circfold(sequence, ss) : fold(sequence, ss); kT = (temperature+273.15)*1.98717/1000.; /* in Kcal */ pf_scale = exp(-(1.03*mfe)/kT/length); strncpy(ss, structure, length); /* ** we are not interested in the free energy but in the bppm, so we ** drop free energy into the void */ (circ) ? (void) pf_circ_fold(sequence, ss) : (void) pf_fold(sequence, ss); free(ss); for (i=0; i<n_back; i++) { char *s; s = (circ) ? pbacktrack_circ(sequence) : pbacktrack(sequence); ajFmtPrintF(outf,"%s\n", s); free(s); } free_pf_arrays(); } else { (circ) ? subopt_circ(sequence, structure, delta, ajFileGetFileptr(outf)) : subopt(sequence, structure, delta, ajFileGetFileptr(outf)); } free(sequence); free(structure); ajSeqDel(&seq); ajStrDel(&ensbases); ajStrDel(&edangles); ajFileClose(&confile); ajFileClose(&outf); ajFileClose(¶mfile); embExit(); return 0; }
int main(int argc, char **argv) { AjPSeqall queryseqs; AjPSeqset targetseqs; AjPSeq queryseq; const AjPSeq targetseq; AjPStr queryaln = 0; AjPStr targetaln = 0; AjPFile errorf; AjBool show = ajFalse; const char *queryseqc; const char *targetseqc; AjPMatrixf matrix; AjPSeqCvt cvt = 0; float **sub; ajint *compass = NULL; float *path = NULL; float gapopen; float gapextend; float score; float minscore; ajuint j, k; ajint querystart = 0; ajint targetstart = 0; ajint queryend = 0; ajint targetend = 0; ajint width = 0; AjPTable kmers = 0; ajint wordlen = 6; ajint oldmax = 0; ajint newmax = 0; ajuint ntargetseqs; ajuint nkmers; AjPAlign align = NULL; EmbPWordMatch maxmatch; /* match with maximum score */ /* Cursors for the current sequence being scanned, ** i.e., until which location it was scanned. ** Separate cursor/location entries for each sequence in the seqset. */ ajuint* lastlocation; EmbPWordRK* wordsw = NULL; AjPList* matchlist = NULL; embInit("supermatcher", argc, argv); matrix = ajAcdGetMatrixf("datafile"); queryseqs = ajAcdGetSeqall("asequence"); targetseqs= ajAcdGetSeqset("bsequence"); gapopen = ajAcdGetFloat("gapopen"); gapextend = ajAcdGetFloat("gapextend"); wordlen = ajAcdGetInt("wordlen"); align = ajAcdGetAlign("outfile"); errorf = ajAcdGetOutfile("errorfile"); width = ajAcdGetInt("width"); /* width for banded Smith-Waterman */ minscore = ajAcdGetFloat("minscore"); gapopen = ajRoundFloat(gapopen, 8); gapextend = ajRoundFloat(gapextend, 8); sub = ajMatrixfGetMatrix(matrix); cvt = ajMatrixfGetCvt(matrix); embWordLength(wordlen); /* seqset sequence is the reference sequence for SAM format */ ajAlignSetRefSeqIndx(align, 1); ajSeqsetTrim(targetseqs); ntargetseqs = ajSeqsetGetSize(targetseqs); AJCNEW0(matchlist, ntargetseqs); /* get tables of words */ for(k=0;k<ntargetseqs;k++) { targetseq = ajSeqsetGetseqSeq(targetseqs, k); embWordGetTable(&kmers, targetseq); ajDebug("Number of distinct kmers found so far: %d\n", ajTableGetLength(kmers)); } AJCNEW0(lastlocation, ntargetseqs); if(ajTableGetLength(kmers)<1) ajErr("no kmers found"); nkmers = embWordRabinKarpInit(kmers, &wordsw, wordlen, targetseqs); while(ajSeqallNext(queryseqs,&queryseq)) { ajSeqTrim(queryseq); queryaln = ajStrNewRes(1+ajSeqGetLen(queryseq)); ajDebug("Read '%S'\n", ajSeqGetNameS(queryseq)); for(k=0;k<ntargetseqs;k++) { lastlocation[k]=0; matchlist[k] = ajListstrNew(); } embWordRabinKarpSearch(ajSeqGetSeqS(queryseq), targetseqs, (const EmbPWordRK*)wordsw, wordlen, nkmers, matchlist, lastlocation, ajFalse); for(k=0;k<ajSeqsetGetSize(targetseqs);k++) { targetseq = ajSeqsetGetseqSeq(targetseqs, k); ajDebug("Processing '%S'\n", ajSeqGetNameS(targetseq)); if(ajListGetLength(matchlist[k])==0) { ajFmtPrintF(errorf, "No wordmatch start points for " "%s vs %s. No alignment\n", ajSeqGetNameC(queryseq),ajSeqGetNameC(targetseq)); embWordMatchListDelete(&matchlist[k]); continue; } /* only the maximum match is used as seed * (if there is more than one location with the maximum match * only the first one is used) * TODO: we should add a new option to make above limit optional */ maxmatch = embWordMatchFirstMax(matchlist[k]); supermatcher_findendpoints(maxmatch,targetseq, queryseq, &targetstart, &querystart, &targetend, &queryend); targetaln=ajStrNewRes(1+ajSeqGetLen(targetseq)); queryseqc = ajSeqGetSeqC(queryseq); targetseqc = ajSeqGetSeqC(targetseq); ajStrAssignC(&queryaln,""); ajStrAssignC(&targetaln,""); ajDebug("++ %S v %S start:%d %d end:%d %d\n", ajSeqGetNameS(targetseq), ajSeqGetNameS(queryseq), targetstart, querystart, targetend, queryend); newmax = (targetend-targetstart+2)*width; if(newmax > oldmax) { AJCRESIZE0(path,oldmax,newmax); AJCRESIZE0(compass,oldmax,newmax); oldmax=newmax; ajDebug("++ memory re/allocation for path/compass arrays" " to size: %d\n", newmax); } else { AJCSET0(path,newmax); AJCSET0(compass,newmax); } ajDebug("Calling embAlignPathCalcSWFast " "%d..%d [%d/%d] %d..%d [%d/%d] width:%d\n", querystart, queryend, (queryend - querystart + 1), ajSeqGetLen(queryseq), targetstart, targetend, (targetend - targetstart + 1), ajSeqGetLen(targetseq), width); score = embAlignPathCalcSWFast(&targetseqc[targetstart], &queryseqc[querystart], targetend-targetstart+1, queryend-querystart+1, 0,width, gapopen,gapextend, path,sub,cvt, compass,show); if(score>minscore) { embAlignWalkSWMatrixFast(path,compass,gapopen,gapextend, targetseq,queryseq, &targetaln,&queryaln, targetend-targetstart+1, queryend-querystart+1, 0,width, &targetstart,&querystart); if(!ajAlignFormatShowsSequences(align)) { ajAlignDefineCC(align, ajStrGetPtr(targetaln), ajStrGetPtr(queryaln), ajSeqGetNameC(targetseq), ajSeqGetNameC(queryseq)); ajAlignSetScoreR(align, score); } else { ajDebug(" queryaln:%S \ntargetaln:%S\n", queryaln,targetaln); embAlignReportLocal(align, queryseq, targetseq, queryaln, targetaln, querystart, targetstart, gapopen, gapextend, score, matrix, 1 + ajSeqGetOffset(queryseq), 1 + ajSeqGetOffset(targetseq) ); } ajAlignWrite(align); ajAlignReset(align); } ajStrDel(&targetaln); embWordMatchListDelete(&matchlist[k]); } ajStrDel(&queryaln); } for(k=0;k<nkmers;k++) { AJFREE(wordsw[k]->seqindxs); AJFREE(wordsw[k]->nSeqMatches); for(j=0;j<wordsw[k]->nseqs;j++) AJFREE(wordsw[k]->locs[j]); AJFREE(wordsw[k]->nnseqlocs); AJFREE(wordsw[k]->locs); AJFREE(wordsw[k]); } embWordFreeTable(&kmers); if(!ajAlignFormatShowsSequences(align)) ajMatrixfDel(&matrix); AJFREE(path); AJFREE(compass); AJFREE(kmers); AJFREE(wordsw); AJFREE(matchlist); AJFREE(lastlocation); ajAlignClose(align); ajAlignDel(&align); ajSeqallDel(&queryseqs); ajSeqDel(&queryseq); ajSeqsetDel(&targetseqs); ajFileClose(&errorf); embExit(); return 0; }
static void infoalign_Compare(const AjPSeq ref, const AjPSeq seq, ajint * const *sub, const AjPSeqCvt cvt, ajint *seqlength, ajint *alignlength, ajint *gaps, ajint *gapcount, ajint *idcount, ajint *simcount, ajint *difcount, float *change) { ajint i; ajint lenseq; ajint lenref; const char *s; const char *r; AjBool inGap = ajFalse; /* true if in a gap in 'seq' */ ajint begin; ajint end; lenseq = ajSeqGetLen(seq); lenref = ajSeqGetLen(ref); s = ajSeqGetSeqC(seq); r = ajSeqGetSeqC(ref); /* initialise counts */ *seqlength = 0; *alignlength = 0; *gaps = 0; *gapcount = 0; *idcount = 0; *simcount = 0; *difcount = 0; *change = 0.0; /* ignore gaps at the ends of the sequence */ for(begin = 0; s[begin] == '-'; begin++); for(end = lenseq-1; s[end] == '-'; end--); for(i=begin; i<=end; i++) { /* count gaps and their length */ if(s[i] == '-') { if(!inGap) { inGap = ajTrue; (*gaps)++; } (*gapcount)++; } else { inGap = ajFalse; /* ** count identity, similarity, differences ** Past the end of the reference sequence ? */ if(i >= lenref) (*difcount)++; else { /* identity */ if((toupper((int)r[i]) == toupper((int)s[i]))) (*idcount)++; /* similarity */ else if(sub[ajSeqcvtGetCodeK(cvt, r[i])][ajSeqcvtGetCodeK(cvt, s[i])] > 0) (*simcount)++; /* difference */ else (*difcount)++; } } } *seqlength = *idcount + *simcount + *difcount; *alignlength = end-begin+1; *change = (float)(*alignlength - *idcount)*(float)100.0/ (float)(*alignlength); return; }
int main(int argc, char *argv[]) { char *string; char *structure=NULL; char *cstruc=NULL; char *ns_bases=NULL; char *c; int n_seq; int i; int length; int sym; int endgaps = 0; int mis = 0; double min_en; double real_en; double sfact = 1.07; int pf = 0; int istty; char *AS[MAX_NUM_NAMES]; /* aligned sequences */ char *names[MAX_NUM_NAMES]; /* sequence names */ AjPSeqset seq = NULL; AjPFile confile = NULL; AjPFile alifile = NULL; AjPFile paramfile = NULL; AjPFile outf = NULL; AjPFile essfile = NULL; AjPFile dotfile = NULL; AjPStr constring = NULL; float eT = 0.; AjBool eGU; AjBool eclose; AjBool lonely; AjPStr ensbases = NULL; AjBool etloop; AjPStr eenergy = NULL; char ewt = '\0'; float escale = 0.; AjPStr edangles = NULL; char edangle = '\0'; ajint len; AjPSeq tseq = NULL; AjPStr tname = NULL; int circ = 0; int doAlnPS = 0; int doColor = 0; embInitPV("vrnaalifoldpf",argc,argv,"VIENNA",VERSION); constring = ajStrNew(); seq = ajAcdGetSeqset("sequence"); confile = ajAcdGetInfile("constraintfile"); paramfile = ajAcdGetInfile("paramfile"); eT = ajAcdGetFloat("temperature"); eGU = ajAcdGetBoolean("gu"); eclose = ajAcdGetBoolean("closegu"); lonely = ajAcdGetBoolean("lp"); ensbases = ajAcdGetString("nsbases"); etloop = ajAcdGetBoolean("tetraloop"); eenergy = ajAcdGetListSingle("energy"); escale = ajAcdGetFloat("scale"); edangles = ajAcdGetListSingle("dangles"); mis = !!ajAcdGetBoolean("most"); endgaps = !!ajAcdGetBoolean("endgaps"); nc_fact = (double) ajAcdGetFloat("nspenalty"); cv_fact = (double) ajAcdGetFloat("covariance"); outf = ajAcdGetOutfile("outfile"); essfile = ajAcdGetOutfile("ssoutfile"); alifile = ajAcdGetOutfile("alignoutfile"); circ = !!ajAcdGetBoolean("circular"); doColor = !!ajAcdGetBoolean("colour"); dotfile = ajAcdGetOutfile("dotoutfile"); do_backtrack = 1; pf = 1; string = NULL; istty = 0; dangles = 2; temperature = (double) eT; noGU = (eGU) ? 0 : 1; no_closingGU = (eclose) ? 0 : 1; noLonelyPairs = (lonely) ? 0 : 1; ns_bases = (ajStrGetLen(ensbases)) ? MAJSTRGETPTR(ensbases) : NULL; tetra_loop = !!etloop; ewt = *ajStrGetPtr(eenergy); if(ewt == '0') energy_set = 0; else if(ewt == '1') energy_set = 1; else if(ewt == '2') energy_set = 2; sfact = (double) escale; edangle = *ajStrGetPtr(edangles); if(edangle == '0') dangles = 0; else if(edangle == '1') dangles = 1; else if(edangle == '2') dangles = 2; else if(edangle == '3') dangles = 3; if(paramfile) read_parameter_file(paramfile); if (ns_bases != NULL) { nonstandards = space(33); c=ns_bases; i=sym=0; if (*c=='-') { sym=1; c++; } while (*c!='\0') { if (*c!=',') { nonstandards[i++]=*c++; nonstandards[i++]=*c; if ((sym)&&(*c!=*(c-1))) { nonstandards[i++]=*c; nonstandards[i++]=*(c-1); } } c++; } } if(alifile) doAlnPS = 1; if(confile) vienna_GetConstraints(confile,&constring); n_seq = ajSeqsetGetSize(seq); if(n_seq > MAX_NUM_NAMES - 1) ajFatal("[e]RNAalifold is restricted to %d sequences\n", MAX_NUM_NAMES - 1); if (n_seq==0) ajFatal("No sequences found"); for(i=0;i<n_seq;++i) { tseq = (AjPSeq) ajSeqsetGetseqSeq(seq,i); ajSeqGapStandard(tseq, '-'); tname = (AjPStr) ajSeqsetGetseqNameS(seq,i); len = ajSeqGetLen(tseq); AS[i] = (char *) space(len+1); names[i] = (char *) space(ajStrGetLen(tname)+1); strcpy(AS[i],ajSeqGetSeqC(tseq)); strcpy(names[i],ajStrGetPtr(tname)); } AS[n_seq] = NULL; names[n_seq] = NULL; if (endgaps) for (i=0; i<n_seq; i++) mark_endgaps(AS[i], '~'); length = (int) strlen(AS[0]); structure = (char *) space((unsigned) length+1); if(confile) { fold_constrained = 1; strcpy(structure,ajStrGetPtr(constring)); } if (circ && noLonelyPairs) ajWarn( "warning, depending on the origin of the circular sequence, " "some structures may be missed when using -noLP\n" "Try rotating your sequence a few times\n"); if (circ) min_en = circalifold((const char **)AS, structure); else min_en = alifold(AS, structure); { int i; double s=0; extern int eos_debug; eos_debug=-1; /* shut off warnings about nonstandard pairs */ for (i=0; AS[i]!=NULL; i++) if (circ) s += energy_of_circ_struct(AS[i], structure); else s += energy_of_struct(AS[i], structure); real_en = s/i; } string = (mis) ? consens_mis((const char **) AS) : consensus((const char **) AS); ajFmtPrintF(outf,"%s\n%s", string, structure); ajFmtPrintF(outf," (%6.2f = %6.2f + %6.2f) \n", min_en, real_en, min_en-real_en ); if (length<=2500) { char **A; A = annote(structure, (const char**) AS); if (doColor) (void) PS_rna_plot_a(string, structure, essfile, A[0], A[1]); else (void) PS_rna_plot_a(string, structure, essfile, NULL, A[1]); free(A[0]); free(A[1]);free(A); } else ajWarn("INFO: structure too long, not doing xy_plot\n"); if (doAlnPS) PS_color_aln(structure, alifile, AS, names); { /* free mfe arrays but preserve base_pair for PS_dot_plot */ struct bond *bp; bp = base_pair; base_pair = space(16); free_alifold_arrays(); /* free's base_pair */ free_alipf_arrays(); base_pair = bp; } if (pf) { double energy, kT; pair_info *pi; char * mfe_struc; mfe_struc = strdup(structure); kT = (temperature+273.15)*1.98717/1000.; /* in Kcal */ pf_scale = exp(-(sfact*min_en)/kT/length); if (length>2000) ajWarn("scaling factor %f\n", pf_scale); /* init_alipf_fold(length); */ if (confile) strncpy(structure, ajStrGetPtr(constring), length+1); energy = (circ) ? alipf_circ_fold(AS, structure, &pi) : alipf_fold(AS, structure, &pi); if (do_backtrack) { ajFmtPrintF(outf,"%s", structure); ajFmtPrintF(outf," [%6.2f]\n", energy); } if ((istty)||(!do_backtrack)) ajFmtPrintF(outf," free energy of ensemble = %6.2f kcal/mol\n", energy); ajFmtPrintF(outf," frequency of mfe structure in ensemble %g\n", exp((energy-min_en)/kT)); if (do_backtrack) { FILE *aliout; cpair *cp; short *ptable; int k; ptable = make_pair_table(mfe_struc); ajFmtPrintF(outf,"\n# Alignment section\n\n"); aliout = ajFileGetFileptr(outf); fprintf(aliout, "%d sequences; length of alignment %d\n", n_seq, length); fprintf(aliout, "alifold output\n"); for (k=0; pi[k].i>0; k++) { pi[k].comp = (ptable[pi[k].i] == pi[k].j) ? 1:0; print_pi(pi[k], aliout); } fprintf(aliout, "%s\n", structure); free(ptable); cp = make_color_pinfo(pi); (void) PS_color_dot_plot(string, cp, dotfile); free(cp); free(mfe_struc); free(pi); } } if (cstruc!=NULL) free(cstruc); free(base_pair); (void) fflush(stdout); free(string); free(structure); for (i=0; AS[i]; i++) { free(AS[i]); free(names[i]); } ajSeqsetDel(&seq); ajStrDel(&constring); ajStrDel(&eenergy); ajStrDel(&edangles); ajStrDel(&ensbases); ajFileClose(&confile); ajFileClose(¶mfile); ajFileClose(&outf); ajFileClose(&essfile); ajFileClose(&alifile); ajFileClose(&dotfile); embExit(); return 0; }
int main(int argc, char *argv[]) { char *string/*, *line*/; char *structure=NULL, *cstruc=NULL; /*char fname[13], ffname[20], gfname[20];*/ /*char *ParamFile=NULL;*/ char *ns_bases=NULL, *c; int i, length, l, sym/*, r*/; double energy, min_en; double kT, sfact=1.07; int pf=0, noPS=0, istty; int noconv=0; int circ=0; AjPSeq seq = NULL; AjPFile confile = NULL; AjPFile paramfile = NULL; AjPFile outf = NULL; AjPFile essfile = NULL; AjPFile dotfilea = NULL; AjPFile dotfileb = NULL; AjPStr seqstring = NULL; AjPStr constring = NULL; AjPStr seqname = NULL; float eT = 0.; AjBool eGU; AjBool ecirc = ajFalse; AjBool eclose; AjBool lonely; AjBool convert; AjPStr ensbases = NULL; AjBool etloop; AjPStr eenergy = NULL; char ewt = '\0'; float escale = 0.; AjPStr edangles = NULL; char edangle = '\0'; ajint len; embInitPV("vrnafold",argc,argv,"VIENNA",VERSION); seqstring = ajStrNew(); constring = ajStrNew(); seqname = ajStrNew(); seq = ajAcdGetSeq("sequence"); confile = ajAcdGetInfile("constraintfile"); paramfile = ajAcdGetInfile("paramfile"); eT = ajAcdGetFloat("temperature"); ecirc = ajAcdGetBoolean("circular"); eGU = ajAcdGetBoolean("gu"); eclose = ajAcdGetBoolean("closegu"); lonely = ajAcdGetBoolean("lp"); convert = ajAcdGetBoolean("convert"); ensbases = ajAcdGetString("nsbases"); etloop = ajAcdGetBoolean("tetraloop"); eenergy = ajAcdGetListSingle("energy"); escale = ajAcdGetFloat("scale"); edangles = ajAcdGetListSingle("dangles"); outf = ajAcdGetOutfile("outfile"); essfile = ajAcdGetOutfile("ssoutfile"); /* dotfilea = ajAcdGetOutfile("adotoutfile"); dotfileb = ajAcdGetOutfile("bdotoutfile"); */ do_backtrack = 2; pf = 0; string = NULL; istty = 0; temperature = (double) eT; circ = !!ecirc; noGU = (eGU) ? 0 : 1; no_closingGU = (eclose) ? 0 : 1; noLonelyPairs = (lonely) ? 0 : 1; noconv = (convert) ? 0 : 1; ns_bases = (ajStrGetLen(ensbases)) ? MAJSTRGETPTR(ensbases) : NULL; tetra_loop = !!etloop; ewt = *ajStrGetPtr(eenergy); if(ewt == '0') energy_set = 0; else if(ewt == '1') energy_set = 1; else if(ewt == '2') energy_set = 2; sfact = (double) escale; edangle = *ajStrGetPtr(edangles); if(edangle == '0') dangles = 0; else if(edangle == '1') dangles = 1; else if(edangle == '2') dangles = 2; else if(edangle == '3') dangles = 3; if(circ && noLonelyPairs) { ajWarn("Depending on the origin of the circular sequence\n" "some structures may be missed when using -noLP\nTry " "rotating your sequence a few times\n"); } if(paramfile) read_parameter_file(paramfile); if (ns_bases != NULL) { nonstandards = space(33); c=ns_bases; i=sym=0; if (*c=='-') { sym=1; c++; } while (*c!='\0') { if (*c!=',') { nonstandards[i++]=*c++; nonstandards[i++]=*c; if ((sym)&&(*c!=*(c-1))) { nonstandards[i++]=*c; nonstandards[i++]=*(c-1); } } c++; } } if(confile) vienna_GetConstraints(confile,&constring); string = NULL; structure = NULL; length = ajSeqGetLen(seq); string = (char *) space(length+1); strcpy(string,ajSeqGetSeqC(seq)); len = ajStrGetLen(constring); structure = (char *) space(length+1); if(len) { fold_constrained = 1; strcpy(structure,ajStrGetPtr(constring)); } for (l = 0; l < length; l++) { string[l] = toupper(string[l]); if (!noconv && string[l] == 'T') string[l] = 'U'; } /* initialize_fold(length); */ if (circ) min_en = circfold(string, structure); else min_en = fold(string, structure); ajFmtPrintF(outf,"%s\n%s", string, structure); if (istty) printf("\n minimum free energy = %6.2f kcal/mol\n", min_en); else ajFmtPrintF(outf," (%6.2f)\n", min_en); if (!noPS) { if (length<2000) (void) PS_rna_plot(string, structure, essfile); else ajWarn("Structure too long, not doing xy_plot\n"); } if (length>=2000) free_arrays(); if (pf) { char *pf_struc; pf_struc = (char *) space((unsigned) length+1); if (dangles==1) { dangles=2; /* recompute with dangles as in pf_fold() */ min_en = (circ) ? energy_of_circ_struct(string, structure) : energy_of_struct(string, structure); dangles=1; } kT = (temperature+273.15)*1.98717/1000.; /* in Kcal */ pf_scale = exp(-(sfact*min_en)/kT/length); if (length>2000) ajWarn("scaling factor %f\n", pf_scale); (circ) ? init_pf_circ_fold(length) : init_pf_fold(length); if (cstruc!=NULL) strncpy(pf_struc, cstruc, length+1); energy = (circ) ? pf_circ_fold(string, pf_struc) : pf_fold(string, pf_struc); if (do_backtrack) { ajFmtPrintF(outf,"%s", pf_struc); ajFmtPrintF(outf," [%6.2f]\n", energy); } if ((istty)||(!do_backtrack)) ajFmtPrintF(outf," free energy of ensemble = %6.2f kcal/mol\n", energy); if (do_backtrack) { plist *pl1,*pl2; char *cent; double dist, cent_en; cent = centroid(length, &dist); cent_en = (circ) ? energy_of_circ_struct(string, cent) : energy_of_struct(string, cent); ajFmtPrintF(outf,"%s {%6.2f d=%.2f}\n", cent, cent_en, dist); free(cent); pl1 = make_plist(length, 1e-5); pl2 = b2plist(structure); (void) PS_dot_plot_list(string, dotfilea, pl1, pl2, ""); free(pl2); if (do_backtrack==2) { pl2 = stackProb(1e-5); PS_dot_plot_list(string, dotfileb, pl1, pl2, "Probabilities for stacked pairs (i,j)(i+1,j-1)"); free(pl2); } free(pl1); free(pf_struc); } ajFmtPrintF(outf," frequency of mfe structure in ensemble %g; ", exp((energy-min_en)/kT)); if (do_backtrack) ajFmtPrintF(outf,"ensemble diversity %-6.2f", mean_bp_dist(length)); ajFmtPrintF(outf,"\n"); free_pf_arrays(); } if (cstruc!=NULL) free(cstruc); free(string); free(structure); ajStrDel(&seqstring); ajStrDel(&constring); ajStrDel(&seqname); ajStrDel(&ensbases); ajStrDel(&eenergy); ajStrDel(&edangles); ajSeqDel(&seq); ajFileClose(&confile); ajFileClose(¶mfile); ajFileClose(&outf); ajFileClose(&essfile); /* ajFileClose(&dotfilea); ajFileClose(&dotfileb); */ if (length<2000) free_arrays(); embExit(); return 0; }
int main(int argc, char **argv) { AjPSeq seq = NULL; AjPReport report = NULL; AjPFeattable feat=NULL; AjPStr sstr = NULL; const AjPStr sname = NULL; AjPStr revcomp = NULL; ajint RStotal; AjPStr enzymes = NULL; /* string for RE selection */ AjPList relist = NULL; ajint begin; ajint end; ajint radj; ajint start; AjBool sshow; AjBool tshow; AjBool allmut; AjPList results1 = NULL; /* for forward strand */ AjPList results2 = NULL; /* for reverse strand */ AjPList shits; AjPList nshits; AjPStr tailstr = NULL; embInit("silent", argc, argv); seq = ajAcdGetSeq("sequence"); enzymes = ajAcdGetString("enzymes"); sshow = ajAcdGetBoolean("sshow"); tshow = ajAcdGetBoolean("tshow"); allmut = ajAcdGetBoolean("allmut"); report = ajAcdGetReport ("outfile"); shits = ajListNew(); nshits = ajListNew(); /*calling function to read in RE info*/ RStotal = silent_restr_read(&relist,enzymes); begin = ajSeqGetBegin(seq); /* returns the seq start posn, or 1 if no start has been set */ end = ajSeqGetEnd(seq); /* returns the seq end posn, or seq length if no end has been set */ radj=begin+end+1; /* posn adjustment for complementary strand */ ajStrAssignSubC(&sstr,ajSeqGetSeqC(seq),--begin,--end); ajStrFmtUpper(&sstr); sname = ajSeqGetNameS(seq); ajStrAssignC(&revcomp,ajStrGetPtr(sstr)); ajSeqstrReverse(&revcomp); start = begin+1; feat = ajFeattableNewDna(ajSeqGetNameS(seq)); if(sshow) { silent_fmt_sequence("SEQUENCE", sstr,&tailstr,start,ajTrue); } results1 = silent_mismatch(sstr,relist,&tailstr,sname,RStotal,begin,radj, ajFalse,end,tshow); silent_split_hits(&results1,&shits,&nshits,allmut); ajReportSetHeaderC(report, "KEY:\n" "EnzymeName: Enzyme name\n" "RS-Pattern: Restriction enzyme recognition site " "pattern\n" "Base-Posn: Position of base to be mutated\n" "AAs: Amino acid. Original sequence(.)After mutation\n" "Silent: Yes for unchanged amino acid\n" "Mutation: The base mutation to perform\n\n" "Creating silent and non-silent mutations\n"); silent_fmt_hits(shits,feat, ajTrue, ajFalse); if(allmut) { silent_fmt_hits(nshits,feat, ajFalse, ajFalse); } if(sshow) { silent_fmt_sequence("REVERSE SEQUENCE", revcomp,&tailstr,start,ajTrue); } results2 = silent_mismatch(revcomp,relist,&tailstr, sname,RStotal,begin,radj, ajTrue,end,tshow); silent_split_hits(&results2,&shits,&nshits,allmut); silent_fmt_hits(shits,feat, ajTrue, ajTrue); if(allmut) { silent_fmt_hits(nshits,feat, ajFalse, ajTrue); } ajReportSetStatistics(report, 1, ajSeqGetLenTrimmed(seq)); ajReportSetTailS(report, tailstr); (void) ajReportWrite (report,feat,seq); ajFeattableDel(&feat); ajStrDel(&revcomp); ajStrDel(&enzymes); ajListFree(&results1); ajListFree(&results2); ajListFree(&shits); ajListFree(&nshits); ajReportClose(report); ajReportDel(&report); ajSeqDel(&seq); ajStrDel(&sstr); silent_relistdel(&relist); ajStrDel(&tailstr); embExit(); return 0; }
int main(int argc, char **argv) { AjPAlign align; AjPSeq a; AjPSeq b; AjPSeqout seqout; AjPStr m; AjPStr n; AjPStr merged = NULL; ajuint lena; ajuint lenb; const char *p; const char *q; ajint start1 = 0; ajint start2 = 0; float *path; ajint *compass; AjPMatrixf matrix; AjPSeqCvt cvt = 0; float **sub; float gapopen; float gapextend; ajulong maxarr = 1000; ajulong len; /* arbitrary. realloc'd if needed */ size_t stlen; float score; ajint begina; ajint beginb; embInit("merger", argc, argv); a = ajAcdGetSeq("asequence"); b = ajAcdGetSeq("bsequence"); seqout = ajAcdGetSeqout("outseq"); matrix = ajAcdGetMatrixf("datafile"); gapopen = ajAcdGetFloat("gapopen"); gapextend = ajAcdGetFloat("gapextend"); align = ajAcdGetAlign("outfile"); gapopen = ajRoundFloat(gapopen, 8); gapextend = ajRoundFloat(gapextend, 8); AJCNEW(path, maxarr); AJCNEW(compass, maxarr); /* ** make the two sequences lowercase so we can show which one we are ** using in the merge by uppercasing it */ ajSeqFmtLower(a); ajSeqFmtLower(b); m = ajStrNew(); n = ajStrNew(); sub = ajMatrixfGetMatrix(matrix); cvt = ajMatrixfGetCvt(matrix); begina = ajSeqGetBegin(a); beginb = ajSeqGetBegin(b); lena = ajSeqGetLen(a); lenb = ajSeqGetLen(b); if(lenb > (ULONG_MAX/(ajulong)(lena+1))) ajFatal("Sequences too big. Try 'supermatcher'"); len = lena*lenb; if(len>maxarr) { ajDebug("merger: resize path, len to %d (%d * $d)\n", len, lena, lenb); stlen = (size_t) len; AJCRESIZE(path,stlen); AJCRESIZE(compass,stlen); maxarr=len; } p = ajSeqGetSeqC(a); q = ajSeqGetSeqC(b); ajStrAssignC(&m,""); ajStrAssignC(&n,""); score = embAlignPathCalc(p,q,lena,lenb,gapopen,gapextend,path,sub,cvt, compass, ajFalse); /*score = embAlignScoreNWMatrix(path,compass,gapopen,gapextend, a,b,lena,lenb,sub,cvt, &start1,&start2);*/ embAlignWalkNWMatrix(path,a,b,&m,&n,lena,lenb, &start1,&start2,gapopen, gapextend,compass); /* ** now construct the merged sequence, uppercase the bits of the two ** input sequences which are used in the merger */ merger_Merge(align, &merged,p,q,m,n,start1,start2, ajSeqGetNameC(a),ajSeqGetNameC(b)); embAlignReportGlobal(align, a, b, m, n, start1, start2, gapopen, gapextend, score, matrix, begina, beginb); ajAlignWrite(align); ajAlignReset(align); /* write the merged sequence */ ajSeqAssignSeqS(a, merged); ajSeqoutWriteSeq(seqout, a); ajSeqoutClose(seqout); ajSeqoutDel(&seqout); ajSeqDel(&a); ajSeqDel(&b); ajAlignClose(align); ajAlignDel(&align); ajStrDel(&merged); AJFREE(compass); AJFREE(path); ajStrDel(&n); ajStrDel(&m); embExit(); return 0; }
static AjBool ssematch_NWScore(AjPScop temp_scop, AjPSeq pseq, ajint mode, AjPMatrixf matrix, float gapopen, float gapextend) { ajint start1 =0; /* Start of seq 1, passed as arg but not used.*/ ajint start2 =0; /* Start of seq 2, passed as arg but not used.*/ ajint maxarr =300; /* Initial size for matrix. */ ajint len; ajint *compass; const char *p; /* Query sequence. */ const char *q; /* Subject sequence from scop object. */ float **sub; float id =0.; /* Passed as arg but not used here. */ float sim =0.; float idx =0.; /* Passed as arg but not used here. */ float simx =0.; /* Passed as arg but not used here. */ float *path; AjPStr pstr = NULL; /* m walk alignment for first sequence Passed as arg but not used here. */ AjPStr qstr = NULL; /* n walk alignment for second sequence Passed as arg but not used here. */ AjPSeq qseq = NULL; /* Subject sequence. */ ajint lenp; /* Length of query sequence. */ ajint lenq; /* Length of subject sequence. */ AjPSeqCvt cvt = 0; AjBool show = ajFalse; /*Passed as arg but not used here. */ AJCNEW(path, maxarr); AJCNEW(compass, maxarr); pstr = ajStrNew(); qstr = ajStrNew(); gapopen = ajRoundFloat(gapopen,8); gapextend = ajRoundFloat(gapextend,8); sub = ajMatrixfGetMatrix(matrix); cvt = ajMatrixfGetCvt(matrix); /* Extract subject sequence from scop object, convert to 3 letter code. */ if (mode == 0) qseq = ssematch_convertbases(temp_scop->Sse); else if (mode == 1) qseq = ssematch_convertbases(temp_scop->Sss); lenp = ajSeqGetLen(pseq); /* Length of query sequence. */ lenq = ajSeqGetLen(qseq); /* Length of subject sequence. */ /* Start of main application loop */ /* Intitialise variables for use by alignment functions*/ len = (lenp * lenq); if(len>maxarr) { AJCRESIZE(path,len); AJCRESIZE(compass,len); maxarr=len; } p = ajSeqGetSeqC(pseq); q = ajSeqGetSeqC(qseq); ajStrAssignC(&pstr,""); ajStrAssignC(&qstr,""); /* Check that no sequence length is 0. */ if((lenp == 0)||(lenq == 0)) { AJFREE(compass); AJFREE(path); ajStrDel(&pstr); ajStrDel(&qstr); } /* Call alignment functions. */ embAlignPathCalc(p,q,lenp,lenq, gapopen, gapextend,path,sub,cvt,compass,show); /*embAlignScoreNWMatrix(path,compass,gapopen,gapextend, pseq, qseq, lenp,lenq,sub,cvt, &start1,&start2);*/ embAlignWalkNWMatrix(path,pseq,qseq,&pstr,&qstr, lenp,lenq,&start1,&start2, gapopen,gapextend,compass); embAlignCalcSimilarity(pstr,qstr,sub,cvt,lenp, lenq,&id,&sim,&idx, &simx); /* Assign score. */ temp_scop->Score = sim; /* Tidy up */ AJFREE(compass); AJFREE(path); ajStrDel(&pstr); ajStrDel(&qstr); ajSeqDel(&qseq); /* Bye Bye */ return ajTrue; }
int main(int argc, char **argv) { AjPSeqall seq1; AjPSeqset seq2; AjPSeq a; const AjPSeq b; AjPStr m = 0; AjPStr n = 0; AjPFile errorf; AjBool show = ajFalse; ajint lena = 0; ajint lenb = 0; const char *p; const char *q; AjPMatrixf matrix; AjPSeqCvt cvt = 0; float **sub; ajint *compass = NULL; float *path = NULL; float gapopen; float gapextend; float score; ajint begina; ajint i; ajuint k; ajint beginb; ajint start1 = 0; ajint start2 = 0; ajint end1 = 0; ajint end2 = 0; ajint width = 0; AjPTable seq1MatchTable = 0; ajint wordlen = 6; ajint oldmax = 0; AjPAlign align = NULL; embInit("supermatcher", argc, argv); matrix = ajAcdGetMatrixf("datafile"); seq1 = ajAcdGetSeqall("asequence"); seq2 = ajAcdGetSeqset("bsequence"); gapopen = ajAcdGetFloat("gapopen"); gapextend = ajAcdGetFloat("gapextend"); wordlen = ajAcdGetInt("wordlen"); align = ajAcdGetAlign("outfile"); errorf = ajAcdGetOutfile("errorfile"); width = ajAcdGetInt("width"); /* not the same as awidth */ gapopen = ajRoundFloat(gapopen, 8); gapextend = ajRoundFloat(gapextend, 8); sub = ajMatrixfGetMatrix(matrix); cvt = ajMatrixfGetCvt(matrix); embWordLength(wordlen); ajSeqsetTrim(seq2); while(ajSeqallNext(seq1,&a)) { ajSeqTrim(a); begina = 1 + ajSeqGetOffset(a); m = ajStrNewRes(1+ajSeqGetLen(a)); lena = ajSeqGetLen(a); ajDebug("Read '%S'\n", ajSeqGetNameS(a)); if(!embWordGetTable(&seq1MatchTable, a)) /* get table of words */ ajErr("Could not generate table for %s\n", ajSeqGetNameC(a)); for(k=0;k<ajSeqsetGetSize(seq2);k++) { b = ajSeqsetGetseqSeq(seq2, k); lenb = ajSeqGetLen(b); beginb = 1 + ajSeqGetOffset(b); ajDebug("Processing '%S'\n", ajSeqGetNameS(b)); p = ajSeqGetSeqC(a); q = ajSeqGetSeqC(b); if(!supermatcher_findstartpoints(seq1MatchTable,b,a, &start1, &start2, &end1, &end2)) { ajFmtPrintF(errorf, "No wordmatch start points for " "%s vs %s. No alignment\n", ajSeqGetNameC(a),ajSeqGetNameC(b)); continue; } n=ajStrNewRes(1+ajSeqGetLen(b)); ajStrAssignC(&m,""); ajStrAssignC(&n,""); ajDebug("++ %S v %S start:%d %d end:%d %d\n", ajSeqGetNameS(a), ajSeqGetNameS(b), start1, start2, end1, end2); if(end1-start1+1 > oldmax) { oldmax = ((end1-start1)+1); AJRESIZE(path,oldmax*width*sizeof(float)); AJRESIZE(compass,oldmax*width*sizeof(ajint)); ajDebug("++ resize to oldmax: %d\n", oldmax); } for(i=0;i<((end1-start1)+1)*width;i++) path[i] = 0.0; ajDebug("Calling embAlignPathCalcFast " "%d..%d [%d/%d] %d..%d [%d/%d]\n", start1, end1, (end1 - start1 + 1), lena, start2, end2, (end2 - start2 + 1), lenb); score = embAlignPathCalcSWFast(&p[start1],&q[start2], end1-start1+1,end2-start2+1, 0,width, gapopen,gapextend, path,sub,cvt, compass,show); embAlignWalkSWMatrixFast(path,compass,gapopen,gapextend,a,b, &m,&n,end1-start1+1,end2-start2+1, 0,width, &start1,&start2); if(!ajAlignFormatShowsSequences(align)) { ajAlignDefineCC(align, ajStrGetPtr(m), ajStrGetPtr(n), ajSeqGetNameC(a), ajSeqGetNameC(b)); ajAlignSetScoreR(align, score); } else { embAlignReportLocal(align, a, b, m,n,start1,start2, gapopen, gapextend, score,matrix, begina, beginb); } ajAlignWrite(align); ajAlignReset(align); ajStrDel(&n); } embWordFreeTable(&seq1MatchTable); /* free table of words */ seq1MatchTable=0; ajStrDel(&m); } if(!ajAlignFormatShowsSequences(align)) { ajMatrixfDel(&matrix); } AJFREE(path); AJFREE(compass); ajAlignClose(align); ajAlignDel(&align); ajSeqallDel(&seq1); ajSeqDel(&a); ajSeqsetDel(&seq2); ajFileClose(&errorf); embExit(); return 0; }
static ajint trimest_get_tail(const AjPSeq seq, ajint direction, ajint minlength, ajint mismatches) { char t; const char *s; char c; ajint inc; ajint start; ajint end; ajint i; ajint mismatchcount; /* number of contiguous mismatches */ ajint polycount; /* length of poly-A/T since end/last mismatch */ ajint length; /* length of tail looked at so far */ ajint result; /* resulting length of tail */ if(direction == 5) { t = 'T'; inc = 1; start = 0; end = ajSeqGetLen(seq); } else { t = 'A'; inc = -1; start = ajSeqGetLen(seq)-1; end = -1; } s = ajSeqGetSeqC(seq); mismatchcount = 0; polycount = 0; length = 0; result = 0; for(i = start; i != end; i += inc, length++) { c = toupper((int)s[i]); ajDebug("end = %d, c=%c\n", direction, c); if(c == t) { polycount++; mismatchcount = 0; } else if(c != 'N') { /* ** There is a mismatch ** N is ignored - it is not a poly-tail or a mismatch */ polycount = 0; mismatchcount++; } if(polycount >= minlength) result = length+1; ajDebug("end = %d, polycount = %d, so far tail=%d\n", direction, polycount, result); if(mismatchcount > mismatches) break; } return result; }
int main(int argc, char **argv) { AjPList list = NULL; AjPSeq seq; AjPSeq seq2; AjPStr aa0str = 0; AjPStr aa1str = 0; const char *s1; const char *s2; char *strret = NULL; ajuint i; ajuint j; ajuint k; ajint l; ajint abovethresh; ajint total; ajint starti = 0; ajint startj = 0; ajint windowsize; float thresh; AjPGraph graph = NULL; AjPGraph xygraph = NULL; float flen1; float flen2; ajuint len1; ajuint len2; AjPTime ajtime = NULL; time_t tim; AjBool boxit=AJTRUE; /* Different ticks as they need to be different for x and y due to length of string being important on x */ ajuint acceptableticksx[]= { 1,10,50,100,500,1000,1500,10000, 500000,1000000,5000000 }; ajuint acceptableticks[]= { 1,10,50,100,200,500,1000,2000,5000,10000,15000, 500000,1000000,5000000 }; ajint numbofticks = 10; float xmargin; float ymargin; float ticklen; float tickgap; float onefifth; float k2; float max; char ptr[10]; AjPMatrix matrix = NULL; ajint** sub; AjPSeqCvt cvt; AjPStr subt = NULL; ajint b1; ajint b2; ajint e1; ajint e2; AjPStr se1; AjPStr se2; ajint ithresh; AjBool stretch; PPoint ppt = NULL; float xa[1]; float ya[1]; AjPGraphdata gdata=NULL; AjPStr tit = NULL; AjIList iter = NULL; float x1 = 0.; float x2 = 0.; float y1 = 0.; float y2 = 0.; ajuint tui; se1 = ajStrNew(); se2 = ajStrNew(); embInit("dotmatcher", argc, argv); seq = ajAcdGetSeq("asequence"); seq2 = ajAcdGetSeq("bsequence"); stretch = ajAcdGetToggle("stretch"); graph = ajAcdGetGraph("graph"); xygraph = ajAcdGetGraphxy("xygraph"); windowsize = ajAcdGetInt("windowsize"); ithresh = ajAcdGetInt("threshold"); matrix = ajAcdGetMatrix("matrixfile"); sub = ajMatrixGetMatrix(matrix); cvt = ajMatrixGetCvt(matrix); thresh = (float)ithresh; ajtime = ajTimeNew(); tim = time(0); ajTimeSetLocal(ajtime, tim); b1 = ajSeqGetBegin(seq); b2 = ajSeqGetBegin(seq2); e1 = ajSeqGetEnd(seq); e2 = ajSeqGetEnd(seq2); len1 = ajSeqGetLen(seq); len2 = ajSeqGetLen(seq2); tui = ajSeqGetLen(seq); flen1 = (float) tui; tui = ajSeqGetLen(seq2); flen2 = (float) tui; ajStrAssignSubC(&se1,ajSeqGetSeqC(seq),b1-1,e1-1); ajStrAssignSubC(&se2,ajSeqGetSeqC(seq2),b2-1,e2-1); ajSeqAssignSeqS(seq,se1); ajSeqAssignSeqS(seq2,se2); s1 = ajStrGetPtr(ajSeqGetSeqS(seq)); s2 = ajStrGetPtr(ajSeqGetSeqS(seq2)); aa0str = ajStrNewRes(1+len1); /* length plus trailing blank */ aa1str = ajStrNewRes(1+len2); list = ajListNew(); for(i=0;i<len1;i++) ajStrAppendK(&aa0str,(char)ajSeqcvtGetCodeK(cvt, *s1++)); for(i=0;i<len2;i++) ajStrAppendK(&aa1str,(char)ajSeqcvtGetCodeK(cvt, *s2++)); max = (float)len1; if(len2 > max) max = (float) len2; xmargin = ymargin = max *(float)0.15; ticklen = xmargin*(float)0.1; onefifth = xmargin*(float)0.2; subt = ajStrNewC((strret= ajFmtString("(windowsize = %d, threshold = %3.2f %D)", windowsize,thresh,ajtime))); if(!stretch) { if( ajStrGetLen(ajGraphGetSubtitleS(graph)) <=1) ajGraphSetSubtitleS(graph,subt); ajGraphOpenWin(graph, (float)0.0-ymargin,(max*(float)1.35)+ymargin, (float)0.0-xmargin,(float)max+xmargin); ajGraphicsDrawposTextAtmid(flen1*(float)0.5, (float)0.0-(xmargin/(float)2.0), ajGraphGetXlabelC(graph)); ajGraphicsDrawposTextAtlineJustify((float)0.0-(xmargin*(float)0.75), flen2*(float)0.5, (float)0.0-(xmargin*(float)0.75),flen1, ajGraphGetYlabelC(graph),0.5); ajGraphicsSetCharscale(0.5); } s1= ajStrGetPtr(aa0str); s2 = ajStrGetPtr(aa1str); for(j=0; (ajint)j < (ajint)len2-windowsize;j++) { i =0; total = 0; abovethresh =0; k = j; for(l=0;l<windowsize;l++) total = total + sub[(ajint)s1[i++]][(ajint)s2[k++]]; if(total >= thresh) { abovethresh=1; starti = i-windowsize; startj = k-windowsize; } while(i < len1 && k < len2) { total = total - sub[(ajint)s1[i-windowsize]] [(ajint)s2[k-windowsize]]; total = total + sub[(ajint)s1[i]][(ajint)s2[k]]; if(abovethresh) { if(total < thresh) { abovethresh = 0; /* draw the line */ dotmatcher_pushpoint(&list,(float)starti,(float)startj, (float)i-1,(float)k-1,stretch); } } else if(total >= thresh) { starti = i-windowsize; startj = k-windowsize; abovethresh= 1; } i++; k++; } if(abovethresh) /* draw the line */ dotmatcher_pushpoint(&list,(float)starti,(float)startj, (float)i-1,(float)k-1, stretch); } for(i=0; (ajint)i < (ajint)len1-windowsize;i++) { j = 0; total = 0; abovethresh =0; k = i; for(l=0;l<windowsize;l++) total = total + sub[(ajint)s1[k++]][(ajint)s2[j++]]; if(total >= thresh) { abovethresh=1; starti = k-windowsize; startj = j-windowsize; } while(k < len1 && j < len2) { total = total - sub[(ajint)s1[k-windowsize]] [(ajint)s2[j-windowsize]]; total = total + sub[(ajint)s1[k]][(ajint)s2[j]]; if(abovethresh) { if(total < thresh) { abovethresh = 0; /* draw the line */ dotmatcher_pushpoint(&list,(float)starti,(float)startj, (float)k-1,(float)j-1,stretch); } } else if(total >= thresh) { starti = k-windowsize; startj = j-windowsize; abovethresh= 1; } j++; k++; } if(abovethresh) /* draw the line */ dotmatcher_pushpoint(&list,(float)starti,(float)startj, (float)k-1,(float)j-1, stretch); } if(boxit && !stretch) { ajGraphicsDrawposRect(0.0,0.0,flen1, flen2); i=0; while(acceptableticksx[i]*numbofticks < len1) i++; if(i<=13) tickgap = (float)acceptableticksx[i]; else tickgap = (float)acceptableticksx[10]; ticklen = xmargin*(float)0.1; onefifth = xmargin*(float)0.2; if(len2/len1 > 10 ) { /* if a lot smaller then just label start and end */ ajGraphicsDrawposLine((float)0.0,(float)0.0,(float)0.0,(float)0.0-ticklen); sprintf(ptr,"%d",b1-1); ajGraphicsDrawposTextAtmid((float)0.0,(float)0.0-(onefifth),ptr); ajGraphicsDrawposLine(flen1,(float)0.0, flen1,(float)0.0-ticklen); sprintf(ptr,"%d",len1+b1-1); ajGraphicsDrawposTextAtmid(flen1,(float)0.0-(onefifth),ptr); } else for(k2=0.0;k2<len1;k2+=tickgap) { ajGraphicsDrawposLine(k2,(float)0.0,k2,(float)0.0-ticklen); sprintf(ptr,"%d",(ajint)k2+b1-1); ajGraphicsDrawposTextAtmid(k2,(float)0.0-(onefifth),ptr); } i = 0; while(acceptableticks[i]*numbofticks < len2) i++; tickgap = (float)acceptableticks[i]; ticklen = ymargin*(float)0.01; onefifth = ymargin*(float)0.02; if(len1/len2 > 10 ) { /* if a lot smaller then just label start and end */ ajGraphicsDrawposLine((float)0.0,(float)0.0,(float)0.0-ticklen,(float)0.0); sprintf(ptr,"%d",b2-1); ajGraphicsDrawposTextAtend((float)0.0-(onefifth),(float)0.0,ptr); ajGraphicsDrawposLine((float)0.0,flen2,(float)0.0-ticklen, flen2); sprintf(ptr,"%d",len2+b2-1); ajGraphicsDrawposTextAtend((float)0.0-(onefifth),flen2,ptr); } else for(k2=0.0;k2<len2;k2+=tickgap) { ajGraphicsDrawposLine((float)0.0,k2,(float)0.0-ticklen,k2); sprintf(ptr,"%d",(ajint)k2+b2-1); ajGraphicsDrawposTextAtend((float)0.0-(onefifth),k2,ptr); } } if(!stretch) ajGraphicsClose(); else /* the xy graph for -stretch */ { tit = ajStrNew(); ajFmtPrintS(&tit,"%S",ajGraphGetTitleS(xygraph)); gdata = ajGraphdataNewI(1); xa[0] = (float)b1; ya[0] = (float)b2; ajGraphSetTitleC(xygraph,ajStrGetPtr(tit)); ajGraphSetXlabelC(xygraph,ajSeqGetNameC(seq)); ajGraphSetYlabelC(xygraph,ajSeqGetNameC(seq2)); ajGraphdataSetTypeC(gdata,"2D Plot Float"); ajGraphdataSetTitleS(gdata,subt); ajGraphdataSetMinmax(gdata,(float)b1,(float)e1,(float)b2, (float)e2); ajGraphdataSetTruescale(gdata,(float)b1,(float)e1,(float)b2, (float)e2); ajGraphxySetXstartF(xygraph,(float)b1); ajGraphxySetXendF(xygraph,(float)e1); ajGraphxySetYstartF(xygraph,(float)b2); ajGraphxySetYendF(xygraph,(float)e2); ajGraphxySetXrangeII(xygraph,b1,e1); ajGraphxySetYrangeII(xygraph,b2,e2); if(list) { iter = ajListIterNewread(list); while((ppt = ajListIterGet(iter))) { x1 = ppt->x1+b1-1; y1 = ppt->y1+b2-1; x2 = ppt->x2+b1-1; y2 = ppt->y2+b2-1; ajGraphAddLine(xygraph,x1,y1,x2,y2,0); AJFREE(ppt); } ajListIterDel(&iter); } ajGraphdataAddXY(gdata,xa,ya); ajGraphDataReplace(xygraph,gdata); ajGraphxyDisplay(xygraph,ajFalse); ajGraphicsClose(); ajStrDel(&tit); } ajListFree(&list); ajSeqDel(&seq); ajSeqDel(&seq2); ajGraphxyDel(&graph); ajGraphxyDel(&xygraph); ajMatrixDel(&matrix); ajTimeDel(&ajtime); /* deallocate memory */ ajStrDel(&aa0str); ajStrDel(&aa1str); ajStrDel(&se1); ajStrDel(&se2); ajStrDel(&subt); AJFREE(strret); /* created withing ajFmtString */ embExit(); return 0; }
int main(int argc, char **argv) { AjPSeq seq = NULL; AjPFile angles = NULL; AjPFile energies = NULL; AjPFile result = NULL; AjPTable angletable = NULL; AjPTable energytable = NULL; AjPStr nucs = NULL; const AjPStr valstr = NULL; const char * dinuc = NULL; ajint len; ajint begin; ajint end; ajint i; float val; float anglesum = 0.0; float energysum = 0.0; float twists = 0.0; float basesperturn = 0.0; float energyperbase = 0.0; embInit ("btwisted", argc, argv); seq = ajAcdGetSeq ("sequence"); angles = ajAcdGetDatafile("angledata"); energies = ajAcdGetDatafile("energydata"); result = ajAcdGetOutfile ("outfile"); nucs = ajStrNew(); angletable = btwisted_getdinucdata(angles); energytable = btwisted_getdinucdata(energies); ajFileClose(&angles); ajFileClose(&energies); begin = ajSeqGetBegin(seq); end = ajSeqGetEnd(seq); len = end-begin+1; dinuc = ajSeqGetSeqC(seq); for(i=begin-1; i<end-1; ++i) { ajStrAssignSubC(&nucs,dinuc,i,i+1); if(!(valstr = ajTableFetchS(angletable, nucs))) ajFatal("Incomplete table"); ajStrToFloat(valstr,&val); anglesum += val; if(!(valstr = ajTableFetchS(energytable, nucs))) ajFatal("Incomplete table"); ajStrToFloat(valstr,&val); energysum += val; } twists = anglesum / (float)360.0 ; basesperturn = (float) len * (float)360.0 /anglesum; energyperbase = energysum/(float) (len-1); ajFmtPrintF(result, "# Output from BTWISTED\n"); ajFmtPrintF(result, "# Twisting calculated from %d to %d of %s\n", begin, end, ajSeqGetNameC(seq)); ajFmtPrintF(result,"Total twist (degrees): %.1f\n", anglesum); ajFmtPrintF(result,"Total turns : %.2f\n", twists); ajFmtPrintF(result,"Average bases per turn: %.2f\n", basesperturn); ajFmtPrintF(result,"Total stacking energy : %.2f\n", energysum); ajFmtPrintF(result,"Average stacking energy per dinucleotide: %.2f\n", energyperbase); ajTablestrFree(&angletable); ajTablestrFree(&energytable); ajStrDel(&nucs); ajFileClose(&result); ajSeqDel(&seq); embExit (); return 0; }
int main(int argc, char **argv) { AjPSeqall seqall; AjPSeq seq = NULL; AjPReport report = NULL; AjPStr jaspdir = NULL; AjPStr menu = NULL; AjPStr substr = NULL; AjPStr mats = NULL; AjPStr excl = NULL; float thresh = 0.; ajuint recurs = 0; AjPStr dir = NULL; AjPStr mfname = NULL; AjPList flist = NULL; AjPList hits = NULL; AjPStr head = NULL; ajint begin; ajint end; ajuint mno; char cp; ajuint i; AjPTable mattab = NULL; AjPFeattable TabRpt = NULL; AjBool both = ajFalse; embInit("jaspscan", argc, argv); seqall = ajAcdGetSeqall("sequence"); menu = ajAcdGetListSingle("menu"); mats = ajAcdGetString("matrices"); excl = ajAcdGetString("exclude"); thresh = ajAcdGetFloat("threshold"); report = ajAcdGetReport("outfile"); both = ajAcdGetBoolean("both"); jaspdir = ajStrNew(); substr = ajStrNew(); flist = ajListNew(); hits = ajListNew(); dir = ajStrNew(); head = ajStrNew(); cp = ajStrGetCharFirst(menu); if(cp=='C') ajStrAssignC(&jaspdir,J_COR); else if(cp=='F') ajStrAssignC(&jaspdir,J_FAM); else if(cp=='P') ajStrAssignC(&jaspdir,J_PHY); else if(cp=='N') ajStrAssignC(&jaspdir,J_CNE); else if(cp=='O') ajStrAssignC(&jaspdir,J_POL); else if(cp=='S') ajStrAssignC(&jaspdir,J_SPL); else ajFatal("Invalid JASPAR database selection"); ajStrAssignS(&dir, ajDatafileValuePath()); if(!ajStrGetLen(dir)) ajFatal("EMBOSS DATA directory couldn't be determined"); jaspscan_ParseInput(dir, jaspdir, mats, excl, &recurs, flist); mno = ajListGetLength(flist); if(cp == 'C') mattab = jaspscan_ReadCoreList(jaspdir); if(cp == 'F') mattab = jaspscan_ReadFamList(jaspdir); if(cp == 'P') mattab = jaspscan_ReadCoreList(jaspdir); if(cp == 'N') mattab = jaspscan_ReadCoreList(jaspdir); if(cp == 'O') mattab = jaspscan_ReadCoreList(jaspdir); if(cp == 'S') mattab = jaspscan_ReadCoreList(jaspdir); ajFmtPrintS(&head,"Database scanned: %S Threshold: %.3f",jaspdir,thresh); ajReportSetHeaderS(report,head); while(ajSeqallNext(seqall, &seq)) { begin = ajSeqallGetseqBegin(seqall); end = ajSeqallGetseqEnd(seqall); ajStrAssignSubC(&substr,ajSeqGetSeqC(seq),begin-1,end-1); ajStrFmtUpper(&substr); TabRpt = ajFeattableNewSeq(seq); for(i=0; i < mno; ++i) { ajListPop(flist,(void **)&mfname); jaspscan_scan(substr,begin,mfname, cp, thresh, both, hits); ajListPushAppend(flist, (void **)mfname); } jaspscan_ReportHits(TabRpt,mattab,hits); ajReportWrite(report, TabRpt, seq); ajFeattableDel(&TabRpt); } while(ajListPop(flist,(void **)&mfname)) ajStrDel(&mfname); ajStrDel(&dir); ajStrDel(&menu); ajStrDel(&excl); ajStrDel(&substr); ajStrDel(&mats); ajStrDel(&head); ajStrDel(&jaspdir); ajSeqDel(&seq); ajTableMapDel(mattab,jaspscan_ClearTable,NULL); ajTableFree(&mattab); ajListFree(&flist); ajListFree(&hits); ajSeqallDel(&seqall); ajReportDel(&report); embExit(); return 0; }
int main(int argc, char **argv) { AjPSeqall seqall; AjPSeq a; AjPStr substr; AjPStr rname; ajint be; ajint en; ajint len; AjBool unfavoured; AjBool overlap; AjBool allpartials; AjPStr menu; AjPStr rag; ajint n = 0; ajint r = 0; AjPFile outf = NULL; AjPReport report = NULL; AjPFeattable TabRpt = NULL; AjPStr tmpStr = NULL; AjPList l; AjPList pa; AjPFile mfptr = NULL; AjBool nterm = ajFalse; AjBool cterm = ajFalse; AjBool dorag = ajFalse; ajint ncomp; ajint npart; EmbPPropMolwt *mwdata = NULL; AjBool mono; embInit("digest", argc, argv); seqall = ajAcdGetSeqall("seqall"); menu = ajAcdGetListSingle("menu"); dorag = ajAcdGetBoolean("ragging"); rag = ajAcdGetListSingle("termini"); unfavoured = ajAcdGetBoolean("unfavoured"); overlap = ajAcdGetBoolean("overlap"); allpartials = ajAcdGetBoolean("allpartials"); report = ajAcdGetReport("outfile"); mfptr = ajAcdGetDatafile("mwdata"); mono = ajAcdGetBoolean("mono"); /* obsolete. Can be uncommented in acd file and here to reuse */ /* outf = ajAcdGetOutfile("originalfile"); */ ajStrToInt(menu, &n); --n; ajStrToInt(rag, &r); if(r==2 || r==4) nterm = ajTrue; if(r==3 || r==4) cterm = ajTrue; mwdata = embPropEmolwtRead(mfptr); while(ajSeqallNext(seqall, &a)) { substr = ajStrNew(); be = ajSeqGetBegin(a); en = ajSeqGetEnd(a); ajStrAssignSubC(&substr,ajSeqGetSeqC(a),be-1,en-1); ajStrFmtUpper(&substr); len = en-be+1; l = ajListNew(); pa = ajListNew(); rname = ajStrNew(); TabRpt = ajFeattableNewSeq(a); embPropCalcFragments(ajStrGetPtr(substr),n,&l,&pa, unfavoured,overlap, allpartials,&ncomp,&npart,&rname, nterm, cterm, dorag, mwdata, mono); if(outf) ajFmtPrintF(outf,"DIGEST of %s from %d to %d Molwt=%10.3f\n\n", ajSeqGetNameC(a),be,en, embPropCalcMolwt(ajSeqGetSeqC(a),0,len-1,mwdata,mono)); if(!ncomp) { if(outf) ajFmtPrintF(outf, "Is not proteolytically digested using %s\n", ajStrGetPtr(rname)); } else { if(outf) { ajFmtPrintF(outf,"Complete digestion with %s " "yields %d fragments:\n", ajStrGetPtr(rname),ncomp); digest_print_hits(l,outf,be,ajStrGetPtr(substr)); } ajFmtPrintS(&tmpStr, "Complete digestion with %S yields %d fragments", rname,ncomp); ajReportSetHeaderS(report, tmpStr); digest_report_hits(TabRpt,l,be, ajStrGetPtr(substr)); ajReportWrite(report, TabRpt, a); ajFeattableClear(TabRpt); } if(overlap && !allpartials && npart) { if(outf) { ajFmtPrintF(outf, "\n\nPartial digest with %s yields %d extras.\n", ajStrGetPtr(rname),npart); ajFmtPrintF(outf,"Only overlapping partials shown:\n"); digest_print_hits(pa,outf,be,ajStrGetPtr(substr)); } ajFmtPrintS(&tmpStr, "\n\nPartial digest with %S yields %d extras.\n", rname,npart); ajFmtPrintAppS(&tmpStr,"Only overlapping partials shown:\n"); ajReportSetHeaderS(report, tmpStr); digest_report_hits(TabRpt, pa,be,ajStrGetPtr(substr)); ajReportWrite(report, TabRpt, a); ajFeattableClear(TabRpt); } if(allpartials && npart) { if(outf) { ajFmtPrintF(outf, "\n\nPartial digest with %s yields %d extras.\n", ajStrGetPtr(rname),npart); ajFmtPrintF(outf,"All partials shown:\n"); digest_print_hits(pa,outf,be,ajStrGetPtr(substr)); } ajFmtPrintS(&tmpStr, "\n\nPartial digest with %S yields %d extras.\n", rname,npart); ajFmtPrintAppS(&tmpStr,"All partials shown:\n"); ajReportSetHeaderS(report, tmpStr); digest_report_hits(TabRpt, pa,be, ajStrGetPtr(substr)); ajReportWrite(report, TabRpt, a); ajFeattableClear(TabRpt); } } embPropMolwtDel(&mwdata); ajReportDel(&report); ajFeattableDel(&TabRpt); ajSeqDel(&a); ajSeqallDel(&seqall); ajStrDel(&rname); ajStrDel(&substr); ajListFree(&pa); ajListFree(&l); ajStrDel(&menu); ajStrDel(&rag); if(outf) ajFileClose(&outf); ajFileClose(&mfptr); ajStrDel(&tmpStr); embExit(); return 0; }