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; }
void biolib_getorf(AjPSeq seq, AjPTrn table, unsigned int minsize) { ORFrec record; /* ORF number to append to name of sequence to create unique name */ ajint orf_no; AjBool sense; /* ajTrue = forward sense */ ajint len; orf_no = 1; /* number of the next ORF */ sense = ajTrue; /* forward sense initially */ /* get the length of the sequence */ len = ajSeqGetLen(seq); /* find the ORFs */ getorf_FindORFs(seq, len, trnTable, minsize/3, 10000, seqout, sense, circular, find, &orf_no, methionine, around, &record); /* now reverse complement the sequence and do it again */ sense = ajFalse; ajSeqReverseForce(seq); // getorf_FindORFs(seq, len, trnTable, minsize, maxsize, seqout, sense, // circular, find, &orf_no, methionine, // around); }
static void supermatcher_findendpoints(const EmbPWordMatch max, const AjPSeq trgseq, const AjPSeq qryseq, ajint *trgstart, ajint *qrystart, ajint *trgend, ajint *qryend) { ajint amax; ajint bmax; ajint offset; *trgstart = max->seq1start; *qrystart = max->seq2start; offset = *trgstart - *qrystart; if(offset > 0) { *trgstart = offset; *qrystart = 0; } else { *qrystart = 0-offset; *trgstart = 0; } amax = ajSeqGetLen(trgseq)-1; bmax = ajSeqGetLen(qryseq)-1; *trgend = *trgstart; *qryend = *qrystart; ajDebug("++ end1 %d -> %d end2 %d -> %d\n", *trgend, amax, *qryend, bmax); while(*trgend<amax && *qryend<bmax) { (*trgend)++; (*qryend)++; } ajDebug("++ end1 %d end2 %d\n", *trgend, *qryend); ajDebug("supermatcher_findendpoints: %d..%d [%d] %d..%d [%d]\n", trgstart, *trgend, ajSeqGetLen(trgseq), qrystart, *qryend, ajSeqGetLen(qryseq)); return; }
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; }
int main(int argc, char **argv) { AjPSeq seq = NULL; AjPFile outf = NULL; embInitPV("myseq", argc, argv, "myemboss",VERSION); seq = ajAcdGetSeq("sequence"); outf = ajAcdGetOutfile("outfile"); ajFmtPrintF(outf, "Sequence properties\n"); ajFmtPrintF(outf, "===================\n"); ajFmtPrintF(outf, "Name: %S\n", ajSeqGetNameS(seq)); ajFmtPrintF(outf, "Usa: %S\n", ajSeqGetUsaS(seq)); ajFmtPrintF(outf, "Length: %d\n", ajSeqGetLen(seq)); ajFileClose(&outf); embExit(); return 0; }
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) { AjPSeqset seqset; AjPSeqall seqall; AjPSeq queryseq; const AjPSeq targetseq; ajint wordlen; AjPTable wordsTable = NULL; AjPList* matchlist = NULL; AjPFile logfile; AjPFeattable* seqsetftables = NULL; AjPFeattable seqallseqftable = NULL; AjPFeattabOut ftoutforseqsetseq = NULL; AjPFeattabOut ftoutforseqallseq = NULL; AjPAlign align = NULL; AjIList iter = NULL; ajint targetstart; ajint querystart; ajint len; ajuint i, j; ajulong nAllMatches = 0; ajulong sumAllScore = 0; AjBool dumpAlign = ajTrue; AjBool dumpFeature = ajTrue; AjBool checkmode = ajFalse; EmbPWordRK* wordsw = NULL; ajuint npatterns = 0; ajuint seqsetsize; ajuint nmatches; ajuint* nmatchesseqset; ajuint* lastlocation; /* Cursors for Rabin-Karp search. */ /* Shows until what point the query sequence was * scanned for a pattern sequences in the seqset. */ char* paddedheader = NULL; const char* header; AjPStr padding; header = "Pattern %S #pat-sequences #all-matches avg-match-length\n"; padding = ajStrNew(); embInit("wordmatch", argc, argv); wordlen = ajAcdGetInt("wordsize"); seqset = ajAcdGetSeqset("asequence"); seqall = ajAcdGetSeqall("bsequence"); logfile = ajAcdGetOutfile("logfile"); dumpAlign = ajAcdGetToggle("dumpalign"); dumpFeature = ajAcdGetToggle("dumpfeat"); if(dumpAlign) { align = ajAcdGetAlign("outfile"); ajAlignSetExternal(align, ajTrue); } seqsetsize = ajSeqsetGetSize(seqset); ajSeqsetTrim(seqset); AJCNEW0(matchlist, seqsetsize); AJCNEW0(seqsetftables, seqsetsize); AJCNEW0(nmatchesseqset, seqsetsize); if (dumpFeature) { ftoutforseqsetseq = ajAcdGetFeatout("aoutfeat"); ftoutforseqallseq = ajAcdGetFeatout("boutfeat"); } checkmode = !dumpFeature && !dumpAlign; embWordLength(wordlen); ajFmtPrintF(logfile, "Small sequence/file for constructing" " target patterns: %S\n", ajSeqsetGetUsa(seqset)); ajFmtPrintF(logfile, "Large sequence/file to be scanned" " for patterns: %S\n", ajSeqallGetUsa(seqall)); ajFmtPrintF(logfile, "Number of sequences in the patterns file: %u\n", seqsetsize); ajFmtPrintF(logfile, "Pattern/word length: %u\n", wordlen); for(i=0;i<seqsetsize;i++) { targetseq = ajSeqsetGetseqSeq(seqset, i); embWordGetTable(&wordsTable, targetseq); } AJCNEW0(lastlocation, seqsetsize); if(ajTableGetLength(wordsTable)>0) { npatterns = embWordRabinKarpInit(wordsTable, &wordsw, wordlen, seqset); ajFmtPrintF(logfile, "Number of patterns/words found: %u\n", npatterns); while(ajSeqallNext(seqall,&queryseq)) { for(i=0;i<seqsetsize;i++) { lastlocation[i]=0; if (!checkmode) matchlist[i] = ajListstrNew(); } nmatches = embWordRabinKarpSearch( ajSeqGetSeqS(queryseq), seqset, (EmbPWordRK const *)wordsw, wordlen, npatterns, matchlist, lastlocation, checkmode); nAllMatches += nmatches; if (checkmode) continue; for(i=0;i<seqsetsize;i++) { if(ajListGetLength(matchlist[i])>0) { iter = ajListIterNewread(matchlist[i]) ; while(embWordMatchIter(iter, &targetstart, &querystart, &len, &targetseq)) { if(dumpAlign) { ajAlignDefineSS(align, targetseq, queryseq); ajAlignSetScoreI(align, len); /* ungapped alignment means same length * for both sequences */ ajAlignSetSubRange(align, targetstart, 1, len, ajSeqIsReversed(targetseq), ajSeqGetLen(targetseq), querystart, 1, len, ajSeqIsReversed(queryseq), ajSeqGetLen(queryseq)); } } if(dumpAlign) { ajAlignWrite(align); ajAlignReset(align); } if(ajListGetLength(matchlist[i])>0 && dumpFeature) { embWordMatchListConvToFeat(matchlist[i], &seqsetftables[i], &seqallseqftable, targetseq, queryseq); ajFeattableWrite(ftoutforseqallseq, seqallseqftable); ajFeattableDel(&seqallseqftable); } ajListIterDel(&iter); } embWordMatchListDelete(&matchlist[i]); } } /* search completed, now report statistics */ for(i=0;i<npatterns;i++) { sumAllScore += wordsw[i]->lenMatches; for(j=0;j<wordsw[i]->nseqs;j++) nmatchesseqset[wordsw[i]->seqindxs[j]] += wordsw[i]->nSeqMatches[j]; } ajFmtPrintF(logfile, "Number of sequences in the file scanned " "for patterns: %u\n", ajSeqallGetCount(seqall)); ajFmtPrintF(logfile, "Number of all matches: %Lu" " (wordmatch finds exact matches only)\n", nAllMatches); if(nAllMatches>0) { ajFmtPrintF(logfile, "Sum of match lengths: %Lu\n", sumAllScore); ajFmtPrintF(logfile, "Average match length: %.2f\n", sumAllScore*1.0/nAllMatches); ajFmtPrintF(logfile, "\nDistribution of the matches among pattern" " sequences:\n"); ajFmtPrintF(logfile, "-----------------------------------------" "-----------\n"); for(i=0;i<ajSeqsetGetSize(seqset);i++) { if (nmatchesseqset[i]>0) ajFmtPrintF(logfile, "%-42s: %8u\n", ajSeqGetNameC(ajSeqsetGetseqSeq(seqset, i)), nmatchesseqset[i]); ajFeattableWrite(ftoutforseqsetseq, seqsetftables[i]); ajFeattableDel(&seqsetftables[i]); } ajFmtPrintF(logfile, "\nPattern statistics:\n"); ajFmtPrintF(logfile, "-------------------\n"); if(wordlen>7) ajStrAppendCountK(&padding, ' ', wordlen-7); paddedheader = ajFmtString(header,padding); ajFmtPrintF(logfile, paddedheader); for(i=0;i<npatterns;i++) if (wordsw[i]->nMatches>0) ajFmtPrintF(logfile, "%-7s: %12u %12u %17.2f\n", wordsw[i]->word->fword, wordsw[i]->nseqs, wordsw[i]->nMatches, wordsw[i]->lenMatches*1.0/wordsw[i]->nMatches); } } for(i=0;i<npatterns;i++) { for(j=0;j<wordsw[i]->nseqs;j++) AJFREE(wordsw[i]->locs[j]); AJFREE(wordsw[i]->locs); AJFREE(wordsw[i]->seqindxs); AJFREE(wordsw[i]->nnseqlocs); AJFREE(wordsw[i]->nSeqMatches); AJFREE(wordsw[i]); } embWordFreeTable(&wordsTable); AJFREE(wordsw); AJFREE(matchlist); AJFREE(lastlocation); AJFREE(nmatchesseqset); AJFREE(seqsetftables); if(dumpAlign) { ajAlignClose(align); ajAlignDel(&align); } if(dumpFeature) { ajFeattabOutDel(&ftoutforseqsetseq); ajFeattabOutDel(&ftoutforseqallseq); } ajFileClose(&logfile); ajSeqallDel(&seqall); ajSeqsetDel(&seqset); ajSeqDel(&queryseq); ajStrDel(&padding); AJFREE(paddedheader); embExit(); return 0; }
int main(int argc, char **argv) { AjPSeqset seq1; AjPSeqset seq2; AjPFile list; ajint n1; ajint n2; ajint *lengths1; ajint *lengths2; ajuint *order1; ajuint *order2; ajint *hits1; ajint *hits2; ajint curr1; ajint curr2; ajint tmp1; ajint tmp2 = 0; ajint i; AjPStr operator; ajint OperatorCode=0; embInit("listor", argc, argv); seq1 = ajAcdGetSeqset("firstsequences"); seq2 = ajAcdGetSeqset("secondsequences"); list = ajAcdGetOutfile("outfile"); operator = ajAcdGetListSingle("operator"); /* get the operator value */ switch(ajStrGetCharFirst(operator)) { case 'O': OperatorCode = L_OR; break; case 'A': OperatorCode = L_AND; break; case 'X': OperatorCode = L_XOR; break; case 'N': OperatorCode = L_NOT; break; default: ajFatal("Invalid operator type: %S", operator); embExitBad(); } /* get the order of seqset 1 by length */ n1 = ajSeqsetGetSize(seq1); /* lengths of seq1 entries */ lengths1 = AJCALLOC0(n1, sizeof(ajint)); /* seq1 entries which match seq2 */ hits1 = AJCALLOC0(n1, sizeof(ajint)); /* seq1 entries in length order */ order1 = AJCALLOC0(n1, sizeof(ajint)); for(i=0; i<n1; i++) { lengths1[i] = ajSeqGetLen(ajSeqsetGetseqSeq(seq1, i)); order1[i] = i; hits1[i] = -1; } ajSortIntIncI(lengths1, order1, n1); /* get the order of seqset 2 by length */ n2 = ajSeqsetGetSize(seq2); lengths2 = AJCALLOC0(n2, sizeof(ajint)); hits2 = AJCALLOC0(n2, sizeof(ajint)); order2 = AJCALLOC0(n2, sizeof(ajint)); for(i=0; i<n2; i++) { lengths2[i] = ajSeqGetLen(ajSeqsetGetseqSeq(seq2, i)); order2[i] = i; hits2[i] = -1; } ajSortIntIncI(lengths2, order2, n2); /* ** go down the two sequence sets, by size order, looking for identical **lengths */ curr1 = 0; curr2 = 0; while(curr1 < n1 && curr2 < n2) { if(lengths1[order1[curr1]] < lengths2[order2[curr2]]) /* seq1 is shorter - increment curr1 index */ curr1++; else if(lengths1[order1[curr1]] > lengths2[order2[curr2]]) /* seq2 is shorter - increment curr2 index */ curr2++; else { /* identical lengths - check all seq1/seq2 entries of this len */ for(tmp1=curr1; tmp1<n1 && lengths1[order1[tmp1]] == lengths2[order2[curr2]]; tmp1++) for(tmp2=curr2; tmp2<n2 && lengths2[order2[tmp2]] == lengths2[order2[curr2]]; tmp2++) /* check to see if the sequences are identical */ if(!ajStrCmpCaseS(ajSeqGetSeqS(ajSeqsetGetseqSeq(seq1, order1[tmp1])), ajSeqGetSeqS(ajSeqsetGetseqSeq(seq2, order2[tmp2])))) { hits1[order1[tmp1]] = order2[tmp2]; hits2[order2[tmp2]] = order1[tmp1]; } curr1 = tmp1; curr2 = tmp2; } } /* output the required entries to the list file */ listor_Output(list, OperatorCode, seq1, seq2, hits1, hits2, n1, n2); AJFREE(lengths1); AJFREE(lengths2); AJFREE(order1); AJFREE(order2); AJFREE(hits1); AJFREE(hits2); ajFileClose(&list); ajStrDel(&operator); ajSeqsetDel(&seq1); ajSeqsetDel(&seq2); embExit(); return 0; }
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) { 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; }
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; }
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) { 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; }
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; }
static void primersearch_store_hits(const Primer primdata, AjPList fhits, AjPList rhits, const AjPSeq seq, AjBool reverse) { ajint amplen = 0; AjIList fi; AjIList ri; PHit primerhit = NULL; fi = ajListIterNewread(fhits); while(!ajListIterDone(fi)) { EmbPMatMatch fm = NULL; EmbPMatMatch rm = NULL; amplen = 0; fm = ajListIterGet(fi); ri = ajListIterNewread(rhits); while(!ajListIterDone(ri)) { ajint seqlen = ajSeqGetLen(seq); ajint s = (fm->start); ajint e; rm = ajListIterGet(ri); e = (rm->start-1); amplen = seqlen-(s-1)-e; if (amplen > 0) /* no point making a hit if -ve length! */ { primerhit = NULL; AJNEW(primerhit); primerhit->desc=NULL; /* must be NULL for ajStrAss */ primerhit->seqname=NULL; /* must be NULL for ajStrAss */ primerhit->acc=NULL; primerhit->forward=NULL; primerhit->reverse=NULL; ajStrAssignC(&primerhit->seqname,ajSeqGetNameC(seq)); ajStrAssignS(&primerhit->desc, ajSeqGetDescS(seq)); ajStrAssignS(&primerhit->acc, ajSeqGetAccS(seq)); primerhit->forward_pos = fm->start; primerhit->reverse_pos = rm->start; primerhit->forward_mismatch = fm->mm; primerhit->reverse_mismatch = rm->mm; primerhit->amplen = amplen; if(!reverse) { ajStrAssignS(&primerhit->forward, primdata->forward->patstr); ajStrAssignS(&primerhit->reverse, primdata->reverse->patstr); } else { ajStrAssignS(&primerhit->forward, primdata->reverse->patstr); ajStrAssignS(&primerhit->reverse, primdata->forward->patstr); } ajListPushAppend(primdata->hitlist, primerhit); } } /* ** clean up rListIter here as it will be new'ed again next ** time through */ ajListIterDel(&ri); } ajListIterDel(&fi); return; }
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) { AjPSeqset seqset; const AjPSeq seq1; const AjPSeq seq2; ajint wordlen; AjPTable seq1MatchTable = NULL; AjPList matchlist ; AjPGraph graph = 0; ajuint i; ajuint j; float total=0; ajuint acceptableticks[]= { 1,10,50,100,200,500,1000,1500,10000,50000, 100000,500000,1000000,5000000 }; ajint numbofticks = 10; ajint gap,tickgap; AjBool boxit = AJTRUE; AjBool dumpfeat = AJFALSE; float xmargin; float ymargin; float k; char ptr[10]; float ticklen; float onefifth; AjPFeattable *tabptr = NULL; AjPFeattabOut seq1out = NULL; AjPStr sajb = NULL; float flen1; float flen2; ajuint tui; embInit("polydot", argc, argv); wordlen = ajAcdGetInt("wordsize"); seqset = ajAcdGetSeqset("sequences"); graph = ajAcdGetGraph("graph"); gap = ajAcdGetInt("gap"); boxit = ajAcdGetBoolean("boxit"); seq1out = ajAcdGetFeatout("outfeat"); dumpfeat = ajAcdGetToggle("dumpfeat"); sajb = ajStrNew(); embWordLength(wordlen); AJCNEW(lines,ajSeqsetGetSize(seqset)); AJCNEW(pts,ajSeqsetGetSize(seqset)); AJCNEW(tabptr,ajSeqsetGetSize(seqset)); for(i=0;i<ajSeqsetGetSize(seqset);i++) { seq1 = ajSeqsetGetseqSeq(seqset, i); total += ajSeqGetLen(seq1); } total +=(float)(gap*(ajSeqsetGetSize(seqset)-1)); xmargin = total*(float)0.15; ymargin = total*(float)0.15; ticklen = xmargin*(float)0.1; onefifth = xmargin*(float)0.2; i = 0; while(acceptableticks[i]*numbofticks < ajSeqsetGetLen(seqset)) i++; if(i<=13) tickgap = acceptableticks[i]; else tickgap = acceptableticks[13]; ajGraphAppendTitleS(graph, ajSeqsetGetUsa(seqset)); ajGraphOpenWin(graph, (float)0.0-xmargin,(total+xmargin)*(float)1.35, (float)0.0-ymargin, total+ymargin); ajGraphicsSetCharscale((float)0.3); for(i=0;i<ajSeqsetGetSize(seqset);i++) { which = i; seq1 = ajSeqsetGetseqSeq(seqset, i); tui = ajSeqGetLen(seq1); flen1 = (float) tui; if(embWordGetTable(&seq1MatchTable, seq1)){ /* get table of words */ for(j=0;j<ajSeqsetGetSize(seqset);j++) { seq2 = ajSeqsetGetseqSeq(seqset, j); tui = ajSeqGetLen(seq2); flen2 = (float) tui; if(boxit) ajGraphicsDrawposRect(xstart,ystart, xstart+flen1, ystart+flen2); matchlist = embWordBuildMatchTable(seq1MatchTable, seq2, ajTrue); if(matchlist) polydot_plotMatches(matchlist); if(i<j && dumpfeat) embWordMatchListConvToFeat(matchlist,&tabptr[i], &tabptr[j],seq1, seq2); if(matchlist) /* free the match structures */ embWordMatchListDelete(&matchlist); if(j==0) { for(k=0.0;k<ajSeqGetLen(seq1);k+=tickgap) { ajGraphicsDrawposLine(xstart+k,ystart,xstart+k, ystart-ticklen); sprintf(ptr,"%d",(ajint)k); ajGraphicsDrawposTextAtmid(xstart+k, ystart-(onefifth), ptr); } ajGraphicsDrawposTextAtmid( xstart+(flen1/(float)2.0), ystart-(3*onefifth), ajStrGetPtr(ajSeqsetGetseqNameS(seqset, i))); } if(i==0) { for(k=0.0;k<ajSeqGetLen(seq2);k+=tickgap) { ajGraphicsDrawposLine(xstart,ystart+k,xstart-ticklen, ystart+k); sprintf(ptr,"%d",(ajint)k); ajGraphicsDrawposTextAtend(xstart-(onefifth), ystart+k, ptr); } ajGraphicsDrawposTextAtlineJustify( xstart-(3*onefifth), ystart+(flen2/(float)2.0), xstart-(3*onefifth),ystart+flen2, ajStrGetPtr(ajSeqsetGetseqNameS(seqset, j)),0.5); } ystart += flen2+(float)gap; } } embWordFreeTable(&seq1MatchTable); seq1MatchTable = NULL; xstart += flen1+(float)gap; ystart = 0.0; } ajGraphicsDrawposTextAtstart(total+onefifth,total-(onefifth), "No. Length Lines Points Sequence"); for(i=0;i<ajSeqsetGetSize(seqset);i++) { seq1 = ajSeqsetGetseqSeq(seqset, i); ajFmtPrintS(&sajb,"%3u %6d %5d %6d %s",i+1, ajSeqGetLen(seq1),lines[i], pts[i],ajSeqGetNameC(seq1)); ajGraphicsDrawposTextAtstart(total+onefifth,total-(onefifth*(i+2)), ajStrGetPtr(sajb)); } if(dumpfeat && seq1out) { for(i=0;i<ajSeqsetGetSize(seqset);i++) { ajFeattableWrite(seq1out, tabptr[i]); ajFeattableDel(&tabptr[i]); } } ajGraphicsClose(); ajGraphxyDel(&graph); ajStrDel(&sajb); AJFREE(lines); AJFREE(pts); AJFREE(tabptr); ajSeqsetDel(&seqset); ajFeattabOutDel(&seq1out);; 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; }
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) { 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 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; }
static void extractfeat_GetRegionPad(const AjPSeq seq, AjPStr *featstr, ajint start, ajint end, AjBool sense, AjBool beginning) { ajint tmp; ajint pad; AjPStr result; ajDebug("In extractfeat_GetRegionPad start=%d, end=%d\n", start, end); result = ajStrNew(); if(start > end) return; if(start < 0) { pad = -start; if(ajSeqIsNuc(seq)) ajStrAppendCountK(&result, 'N', pad); else ajStrAppendCountK(&result, 'X', pad); start = 0; } if(end > (ajint) ajSeqGetLen(seq)-1) tmp = ajSeqGetLen(seq)-1; else tmp = end; if(start <= (ajint) ajSeqGetLen(seq) && tmp >= 0) { ajDebug("Get subsequence %d-%d\n", start, tmp); ajStrAppendSubS(&result, ajSeqGetSeqS(seq), start, tmp); ajDebug("result=%S\n", result); } if(end > (ajint) ajSeqGetLen(seq)-1) { pad = end - ajSeqGetLen(seq)+1; if(ajSeqIsNuc(seq)) ajStrAppendCountK(&result, 'N', pad); else ajStrAppendCountK(&result, 'X', pad); ajDebug("result=%S\n", result); } /* if feature was in reverse sense, then get reverse complement */ if(!sense) { ajDebug("get reverse sense of subsequence\n"); ajSeqstrReverse(&result); ajDebug("result=%S\n", result); } if(beginning) { ajDebug("Prepend to featstr: %S\n", result); ajStrInsertS(featstr, 0, result); } else { ajDebug("Append to featstr: %S\n", result); ajStrAppendS(featstr, result); } ajDebug("featstr=%S\n", *featstr); ajStrDel(&result); return; }
int main(int argc, char **argv) { AjPSeqall seqall; AjPSeqout seqout; AjPSeq seq = NULL; AjPStr str = NULL; AjPStr desc = NULL; ajint tail3; ajint tail5 = 0; ajint minlength; ajint mismatches; AjBool reverse; AjBool fiveprime; AjBool cvttolower; embInit("trimest", argc, argv); seqall = ajAcdGetSeqall("sequence"); seqout = ajAcdGetSeqoutall("outseq"); minlength = ajAcdGetInt("minlength"); mismatches = ajAcdGetInt("mismatches"); reverse = ajAcdGetBoolean("reverse"); fiveprime = ajAcdGetBoolean("fiveprime"); cvttolower = ajAcdGetToggle("tolower"); str = ajStrNew(); while(ajSeqallNext(seqall, &seq)) { /* get sequence description */ ajStrAssignS(&desc, ajSeqGetDescS(seq)); /* get positions to cut in 5' poly-T and 3' poly-A tails */ if(fiveprime) tail5 = trimest_get_tail(seq, 5, minlength, mismatches); tail3 = trimest_get_tail(seq, 3, minlength, mismatches); /* get a COPY of the sequence string */ ajStrAssignS(&str, ajSeqGetSeqS(seq)); /* cut off longest of 3' or 5' tail */ if(tail5 > tail3) { /* if 5' poly-T tail, then reverse the sequence */ ajDebug("Tail=%d\n", tail5); if(cvttolower) trimest_tolower(&str, 0, tail5-1); else ajStrKeepRange(&str, tail5, ajSeqGetLen(seq)-1); ajStrAppendC(&desc, " [poly-T tail removed]"); } else if(tail3 > tail5) { /* remove 3' poly-A tail */ ajDebug("Tail=%d\n", tail3); if(cvttolower) trimest_tolower(&str, ajSeqGetLen(seq)-tail3, ajSeqGetLen(seq)); else ajStrKeepRange(&str, 0, ajSeqGetLen(seq)-tail3-1); ajStrAppendC(&desc, " [poly-A tail removed]"); } /* write sequence out */ ajSeqAssignSeqS(seq, str); /* reverse complement if poly-T found */ if(tail5 > tail3 && reverse) { ajSeqReverseForce(seq); ajStrAppendC(&desc, " [reverse complement]"); } /* set description */ ajSeqAssignDescS(seq, desc); ajSeqoutWriteSeq(seqout, seq); } ajSeqoutClose(seqout); ajStrDel(&str); ajStrDel(&desc); ajSeqallDel(&seqall); ajSeqDel(&seq); ajSeqoutDel(&seqout); embExit(); return 0; }
static ajint supermatcher_findstartpoints(AjPTable seq1MatchTable, const AjPSeq b, const AjPSeq a, ajint *start1, ajint *start2, ajint *end1, ajint *end2) { ajint max = -10; ajint offset = 0; AjPList matchlist = NULL; AjPList ordered = NULL; ajint amax; ajint bmax; ajint bega; ajint begb; amax = ajSeqGetLen(a)-1; bmax = ajSeqGetLen(b)-1; bega = ajSeqGetOffset(a); begb = ajSeqGetOffset(b); ajDebug("supermatcher_findstartpoints len %d %d off %d %d\n", amax, bmax, bega, begb); matchlist = embWordBuildMatchTable(seq1MatchTable, b, ajTrue); if(!matchlist) return 0; else if(!matchlist->Count) { embWordMatchListDelete(&matchlist); return 0; } /* order and add if the gap is gapmax or less */ /* create list header bit*/ ordered = ajListNew(); supermatcher_orderandconcat(matchlist, ordered); /* this sets global structure conmax to point to a matchlist element */ ajListMap(ordered,supermatcher_findmax, &max); ajDebug("findstart conmax off:%d count:%d total:%d\n", conmax->offset, conmax->count, conmax->total, ajListGetLength(conmax->list)); offset = conmax->offset; /* the offset is all we needed! we can delete everything */ ajListMap(ordered,supermatcher_removelists, NULL); ajListFree(&ordered); embWordMatchListDelete(&matchlist); /* free the match structures */ if(offset > 0) { *start1 = offset; *start2 = 0; } else { *start2 = 0-offset; *start1 = 0; } *end1 = *start1; *end2 = *start2; ajDebug("++ end1 %d -> %d end2 %d -> %d\n", *end1, amax, *end2, bmax); while(*end1<amax && *end2<bmax) { (*end1)++; (*end2)++; } ajDebug("++ end1 %d end2 %d\n", *end1, *end2); ajDebug("supermatcher_findstartpoints has %d..%d [%d] %d..%d [%d]\n", *start1, *end1, ajSeqGetLen(a), *start2, *end2, ajSeqGetLen(b)); return 1; }
void embPatternRegexSearch (AjPFeattable ftable, const AjPSeq seq, const AjPPatternRegex pat, AjBool reverse) { ajint pos=0; ajint off; ajint len; AjPFeature sf = NULL; AjPStr substr = NULL; AjPStr seqstr = NULL; AjPStr tmpstr = NULL; AjPStr tmp = ajStrNew(); AjPRegexp patexp = ajPatternRegexGetCompiled(pat); ajint adj; AjBool isreversed; AjPSeq revseq; ajint seqlen; seqlen = ajSeqGetLen(seq); if(!seqlen) return; isreversed = ajSeqIsReversedTrue(seq); if(isreversed) seqlen += ajSeqGetOffset(seq); pos = ajSeqGetBeginTrue(seq); adj = ajSeqGetEndTrue(seq); if(!ajStrGetLen(featMotifProt)) ajStrAssignC(&featMotifProt, "SO:0001067"); if(!ajStrGetLen(featMotifNuc)) ajStrAssignC(&featMotifNuc, "SO:0000714"); /*ajDebug("embPatternRegexSearch pos: %d adj: %d reverse: %B\n", pos, adj, reverse, isreversed);*/ /*ajDebug("seqlen:%d len: %d offset: %d offend: %d begin: %d end: %d\n", seqlen , ajSeqGetLen(seq), ajSeqGetOffset(seq), ajSeqGetOffend(seq), ajSeqGetBegin(seq), ajSeqGetEnd(seq));*/ if (reverse) { revseq = ajSeqNewSeq(seq); ajStrAssignSubS(&seqstr, ajSeqGetSeqS(revseq), pos-1, adj-1); ajSeqstrReverse(&seqstr); } ajStrAssignSubS(&seqstr, ajSeqGetSeqS(seq), pos-1, adj-1); ajStrFmtUpper(&seqstr); while(ajStrGetLen(seqstr) && ajRegExec(patexp, seqstr)) { off = ajRegOffset(patexp); len = ajRegLenI(patexp, 0); if(off || len) { ajRegSubI(patexp, 0, &substr); ajRegPost(patexp, &tmp); ajStrAssignS(&seqstr, substr); ajStrAppendS(&seqstr, tmp); pos += off; /*ajDebug("match pos: %d adj: %d len: %d off:%d\n", pos, adj, len, off);*/ if (reverse) sf = ajFeatNew(ftable, NULL, featMotifNuc, adj - pos - len + 2, adj - pos + 1, 0.0, '-', 0); else { if(ajSeqIsProt(seq) || ajFeattableIsProt(ftable)) sf = ajFeatNewProt(ftable, NULL, featMotifProt, pos, pos + len - 1, 0.0); else sf = ajFeatNew(ftable, NULL, featMotifNuc, pos, pos + len - 1, 0.0, '.', 0); } if(isreversed) ajFeatReverse(sf, seqlen); ajFmtPrintS (&tmpstr,"*pat %S: %S", ajPatternRegexGetName(pat), ajPatternRegexGetPattern(pat)); ajFeatTagAdd (sf,NULL,tmpstr); pos += 1; ajStrCutStart(&seqstr, 1); } else { pos++; ajStrCutStart(&seqstr, 1); } } ajStrDel(&tmpstr); ajStrDel(&tmp); ajStrDel(&substr); ajStrDel(&seqstr); if(reverse) ajSeqDel(&revseq); return; }
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; }
void embPatternSeqSearch (AjPFeattable ftable, const AjPSeq seq, const AjPPatternSeq pat, AjBool reverse) { const void *tidy; ajuint hits; ajuint i; AjPPatComp pattern; EmbPMatMatch m = NULL; AjPFeature sf = NULL; AjPSeq revseq = NULL; AjPList list = ajListNew(); AjPStr seqstr = ajStrNew(); AjPStr seqname = ajStrNew(); AjPStr tmp = ajStrNew(); ajint adj; ajint begin; AjBool isreversed; ajint seqlen; seqlen = ajSeqGetLen(seq); if(!seqlen) return; isreversed = ajSeqIsReversedTrue(seq); if(isreversed) seqlen += ajSeqGetOffset(seq); begin = ajSeqGetBeginTrue(seq); adj = ajSeqGetEndTrue(seq); if(!ajStrGetLen(featMotifProt)) ajStrAssignC(&featMotifProt, "SO:0001067"); if(!ajStrGetLen(featMotifNuc)) ajStrAssignC(&featMotifNuc, "SO:0000714"); ajStrAssignS(&seqname,ajSeqGetNameS(seq)); pattern = ajPatternSeqGetCompiled(pat); if (reverse) { revseq = ajSeqNewSeq(seq); ajStrAssignSubS(&seqstr, ajSeqGetSeqS(revseq), begin-1,adj-1); ajSeqstrReverse(&seqstr); } else ajStrAssignSubS(&seqstr, ajSeqGetSeqS(seq), begin-1,adj-1); ajStrFmtUpper(&seqstr); /*ajDebug("seqlen:%d len: %d offset: %d offend: %d begin: %d end: %d\n" "'%S'\n", seqlen , ajSeqGetLen(seq), ajSeqGetOffset(seq), ajSeqGetOffend(seq), ajSeqGetBegin(seq), ajSeqGetEnd(seq), seqstr);*/ ajDebug("embPatternSeqSearch '%S' protein: %B reverse: %B\n", pattern->pattern, pat->Protein, reverse); embPatFuzzSearchII(pattern,begin,seqname,seqstr,list, ajPatternSeqGetMismatch(pat),&hits,&tidy); ajDebug ("embPatternSeqSearch: found %d hits\n",hits); if(!reverse) ajListReverse(list); for(i=0;i<hits;++i) { ajListPop(list,(void **)&m); if (reverse) sf = ajFeatNew(ftable, NULL, featMotifNuc, adj - m->start - m->len + begin + 1, adj - m->start + begin, 0.0, '-', 0); else { if(ajSeqIsProt(seq) || ajFeattableIsProt(ftable)) sf = ajFeatNewProt(ftable, NULL, featMotifProt, m->start, m->start + m->len - 1, 0.0); else sf = ajFeatNew(ftable, NULL, featMotifNuc, m->start, m->start + m->len - 1, 0.0, '.', 0); } if(isreversed) ajFeatReverse(sf, seqlen); /* ajUser("isrev: %B reverse: %B begin: %d adj: %d " "start: %d len: %d seqlen: %d %d..%d '%c'\n", isreversed, reverse, begin, adj, m->start, m->len, seqlen, sf->Start, sf->End, sf->Strand); */ ajFeatSetScore(sf, (float) (m->len - m->mm)); ajFmtPrintS(&tmp, "*pat %S: %S", ajPatternSeqGetName(pat), ajPatternSeqGetPattern(pat)); ajFeatTagAdd(sf,NULL,tmp); if(m->mm) { ajFmtPrintS(&tmp, "*mismatch %d", m->mm); ajFeatTagAdd(sf, NULL, tmp); } embMatMatchDel(&m); } ajStrDel(&seqname); ajStrDel(&seqstr); ajStrDel(&tmp); ajListFree(&list); if (reverse) ajSeqDel(&revseq); return; }
int main(int argc, char **argv) { AjPSeqall seqall; AjPSeqout seqout; AjPSeq seq; ajint size; ajint overlap; ajint len; ajint pos; AjBool addover; AjBool feature; AjPStr outseq_name = ajStrNew(); ajint start; ajint end; embInit("splitter", argc, argv); seqout = ajAcdGetSeqoutall("outseq"); seqall = ajAcdGetSeqall("sequence"); size = ajAcdGetInt("size"); overlap = ajAcdGetInt("overlap"); addover = ajAcdGetBoolean("addoverlap"); feature = ajAcdGetBoolean("feature"); while(ajSeqallNext(seqall, &seq)) { ajSeqTrim(seq); len = ajSeqGetLen(seq); pos = 0; ajStrAssignC(&outseq_name, ""); if (!addover) { while(pos+size <= len-1) { start = pos; end = pos+size-1; splitter_MakeSubSeqName (&outseq_name, seq, start, end); splitter_ProcessChunk (seqout, seq, start, end, outseq_name, feature); pos += size-overlap; } } else { while(pos+size+overlap < len-1) { start = pos; end = pos+size+overlap-1; splitter_MakeSubSeqName (&outseq_name, seq, start, end); splitter_ProcessChunk (seqout, seq, start, end, outseq_name, feature); pos += size; } } splitter_MakeSubSeqName(&outseq_name, seq, pos, len-1); splitter_ProcessChunk (seqout, seq, pos, len-1, outseq_name, feature); } ajSeqoutClose(seqout); ajSeqallDel(&seqall); ajSeqoutDel(&seqout); ajSeqDel(&seq); ajStrDel(&outseq_name); 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; }