int main(int argc, char **argv) { AjPSeqall seqall; AjPSeq seq = NULL; AjPFile primerFile; /* read the primer pairs from a file */ AjPFile outf; AjPList primerList; ajint mmp = 0; embInit("primersearch", argc, argv); seqall = ajAcdGetSeqall("seqall"); outf = ajAcdGetOutfile("outfile"); primerFile = ajAcdGetInfile("infile"); mmp = ajAcdGetInt("mismatchpercent"); /* build list of forward/reverse primer pairs as read from primerfile */ primerList = ajListNew(); /* read in primers from primerfile, classify and compile them */ primersearch_read_primers(&primerList,primerFile, mmp); /* check there are primers to be searched */ if(!ajListGetLength(primerList)) { ajErr("No suitable primers found - exiting"); embExitBad(); return 0; } /* query sequences one by one */ while(ajSeqallNext(seqall,&seq)) primersearch_primer_search(primerList, seq); /* output the results */ primersearch_print_hits(primerList, outf); /* delete all nodes of list, then the list itself */ ajListMap(primerList, primersearch_free_primer, NULL); ajListFree(&primerList); ajListFree(&primerList); ajFileClose(&outf); ajSeqallDel(&seqall); ajSeqDel(&seq); ajFileClose(&primerFile); embExit(); return 0; }
static void assemblyexceptionadaptorClearIdentifierCache(void **key, void **value, void *cl) { EnsPAssemblyexception ae = NULL; if(!key) return; if(!*key) return; if(!value) return; if(!*value) return; (void) cl; AJFREE(*key); while(ajListPop(*((AjPList *) value), (void **) &ae)) ensAssemblyexceptionDel(&ae); ajListFree((AjPList *) value); return; }
static void jaspscan_GetFileList(const AjPStr dir, const AjPStr jaspdir, const char *wild, AjPList list) { AjPList tlist = NULL; AjPStr jdir = NULL; AjPStr wstr = NULL; AjPStr str = NULL; tlist = ajListNew(); jdir = ajStrNew(); wstr = ajStrNew(); ajFmtPrintS(&jdir,"%S%S",dir,jaspdir); if(!ajDirnameFixExists(&jdir)) ajFatal("EMBOSS_DATA undefined or 'jaspextract' needs to be run"); ajFmtPrintS(&wstr,"%s%s",wild,J_EXT); ajFilelistAddPathWild(tlist,jdir,wstr); if(!ajListGetLength(tlist)) ajWarn("Matrix file(s) %S not found",wstr); while(ajListPop(tlist,(void **)&str)) ajListPushAppend(list,(void *)str); ajStrDel(&wstr); ajStrDel(&jdir); ajListFree(&tlist); return; }
static void primersearch_clean_hitlist(AjPList* hlist) { AjIList lIter; lIter = ajListIterNewread(*hlist); while(!ajListIterDone(lIter)) { EmbPMatMatch fm = ajListIterGet(lIter); embMatMatchDel(&fm); } ajListFree(hlist); ajListFree(hlist); ajListIterDel(&lIter); return; }
void ajRefseqDel(AjPRefseq *Prefseq) { AjPRefseq refseq; AjPSeqRange tmprange; if(!Prefseq) return; if(!(*Prefseq)) return; refseq = *Prefseq; ajStrDel(&refseq->Id); ajStrDel(&refseq->Db); ajStrDel(&refseq->Setdb); ajStrDel(&refseq->Full); ajStrDel(&refseq->Qry); ajStrDel(&refseq->Formatstr); ajStrDel(&refseq->Filename); ajStrDel(&refseq->TextPtr); ajStrDel(&refseq->Desc); ajStrDel(&refseq->Seq); while(ajListPop(refseq->Seqlist,(void **)&tmprange)) ajSeqrangeDel(&tmprange); ajListFree(&refseq->Seqlist); AJFREE(*Prefseq); *Prefseq = NULL; return; }
static void prima_TwoSortscorepos(AjPList *pairlist) { PPair tmp = NULL; AjPList intlist = NULL; AjPList filist = NULL; PPair save = NULL; float score = 0.0; ajListSort(*pairlist,prima_Compare); intlist = ajListNew(); filist = ajListNew(); score = (float) -1.0; while(ajListPop(*pairlist,(void **)&tmp)) { if(tmp->f->score == score) { ajListPush(intlist,(void *)tmp); continue; } save = tmp; ajListSort(intlist,prima_PosCompare); score = tmp->f->score; prima_RevSort(&intlist); while(ajListPop(intlist,(void **)&tmp)) ajListPushAppend(filist,(void *)tmp); ajListPush(intlist,(void *)save); } ajListSort(intlist,prima_PosCompare); prima_RevSort(&intlist); while(ajListPop(intlist,(void **)&tmp)) ajListPushAppend(filist,(void *)tmp); ajListFree(&intlist); ajListFree(pairlist); *pairlist = filist; return; }
static void acdrelations_readtypefile (AjPFile inf, PKtype *T) { AjPStr line = NULL; PKtypedat dattmp = NULL; AjPList datlist = NULL; if(!T) ajFatal("Null arg error 1 in acdrelations_readtypefile"); if(!inf) ajFatal("Null arg error 3 in acdrelations_readtypefile"); /* Allocate memory */ line = ajStrNew(); datlist = ajListNew(); /* Read data from file */ while(ajReadline(inf,&line)) { /* Discard comment lines */ if(ajStrPrefixC(line,"#")) continue; /* Create object for holding line */ dattmp = ajKtypedatNew(); /* Tokenise line delimited by '|' Parse first token (value of knowntype: attribute) */ ajStrAssignS(&dattmp->ktype, ajStrParseC(line, "|")); ajStrRemoveSetC(&dattmp->ktype, "_"); ajStrRemoveWhite(&dattmp->ktype); /* Parse second token (ACD datatype) */ ajStrAssignS(&dattmp->acdtype, ajStrParseC(NULL, "|")); /* Parse third token (EDAM relations: value ) */ ajStrAssignS(&dattmp->edam, ajStrParseC(NULL, "|")); /* Push line onto list */ ajListPushAppend(datlist, dattmp); } /* Write PKtype structure */ ((*T)->n) = ajListToarray(datlist, (void***) &((*T)->dat)); /* Free memory */ ajStrDel(&line); ajListFree(&datlist); return; }
/* @prog scopparse ************************************************************ ** ** Converts raw scop classification files to a file in embl-like format. ** ******************************************************************************/ int main(int argc, char **argv) { AjPFile inf1 = NULL; AjPFile inf2 = NULL; AjPFile outf = NULL; AjPList list = NULL; AjPScop tmp = NULL; AjBool nosegments = ajFalse; AjBool nomultichain = ajFalse; AjBool nominor = ajFalse; /* Read data from acd. */ embInitPV("scopparse", argc, argv, "DOMAINATRIX",VERSION); inf1 = ajAcdGetInfile("classfile"); inf2 = ajAcdGetInfile("desinfile"); outf = ajAcdGetOutfile("dcffile"); nosegments = ajAcdGetBoolean("nosegments"); nomultichain = ajAcdGetBoolean("nomultichain"); nominor = ajAcdGetBoolean("nominor"); /* ajFmtPrint("nosegments: %B\n", nosegments); ajFmtPrint("nomultichain: %B\n", nomultichain); ajFmtPrint("nominor: %B\n", nominor); */ /* Main body of code. */ list = ajScopReadAllRawNew(inf1, inf2, nomultichain); while(ajListPop(list, (void **) &tmp)) { if(((!nosegments) || (tmp->N == 1)) && ((!nominor) || ((tmp->Sunid_Class == 46456) || /* All alpha*/ (tmp->Sunid_Class == 48724) || /* All beta */ (tmp->Sunid_Class == 51349) || /* a/b */ (tmp->Sunid_Class == 53931)))) /* a+b */ ajScopWrite(outf, tmp); ajScopDel(&tmp); } /* Memory management. */ ajFileClose(&outf); ajFileClose(&inf1); ajFileClose(&inf2); ajListFree(&list); ajExit(); return 0; }
static void jaspextract_writematrixfile(const AjPTable mtable, const AjPStr directory) { AjPStr wild = NULL; AjPList flist = NULL; AjPStr key = NULL; AjPStr fname = NULL; AjPStr dest = NULL; const AjPStr value = NULL; AjPFile outf = NULL; const char *p = NULL; char *q = NULL; wild = ajStrNewC("*.pfm"); flist = ajListNew(); key = ajStrNew(); dest = ajStrNew(); ajFmtPrintS(&dest,"%S%c%s",directory,SLASH_CHAR,MATRIXFILE); outf = ajFileNewOutNameS(dest); if(!outf) ajFatal("Cannot open output file %S",dest); ajFilelistAddPathWild(flist, directory, wild); while(ajListPop(flist,(void**)&fname)) { ajFilenameTrimPath(&fname); p = ajStrGetPtr(fname); q = strrchr(p,(int)'.'); ajStrAssignSubC(&key,p,0,q-p-1); value = ajTableFetchS(mtable, key); if(value) ajFmtPrintF(outf,"%S",value); ajStrDel(&fname); } ajFileClose(&outf); ajStrDel(&wild); ajStrDel(&dest); ajStrDel(&key); ajListFree(&flist); return; }
static void prima_RevSort(AjPList *alist) { PPair tmp = NULL; AjPList intlist = NULL; AjPList filist = NULL; PPair save = NULL; ajint pos = -1; intlist = ajListNew(); filist = ajListNew(); pos = -1; while(ajListPop(*alist,(void **)&tmp)) { if(tmp->f->start+tmp->f->primerlen == pos) { ajListPush(intlist,(void *)tmp); continue; } save = tmp; ajListSort(intlist,prima_PosEndCompare); pos = tmp->f->start+tmp->f->primerlen; while(ajListPop(intlist,(void **)&tmp)) ajListPushAppend(filist,(void *)tmp); ajListPush(intlist,(void *)save); } ajListSort(intlist,prima_PosEndCompare); while(ajListPop(intlist,(void **)&tmp)) ajListPushAppend(filist,(void *)tmp); ajListFree(&intlist); ajListFree(alist); *alist = filist; return; }
static void silent_relistdel(AjPList* relist) { PRinfo rlp = NULL; while(ajListPop(*relist,(void **)&rlp)) { ajStrDel(&rlp->code); ajStrDel(&rlp->site); AJFREE(rlp); } ajListFree(relist); }
static void supermatcher_removelists(void **x,void *cl) { concat *p; (void) cl; /* make it used */ p = (concat *)*x; ajListFree(&(p)->list); AJFREE(p); return; }
static void primersearch_free_primer(void **x, void *cl) { Primer* p; Primer primdata; AjIList lIter; (void) cl; /* make it used */ p = (Primer*) x; primdata = *p; primersearch_free_pguts(&primdata->forward); primersearch_free_pguts(&primdata->reverse); ajStrDel(&primdata->Name); /* clean up hitlist */ lIter = ajListIterNewread(primdata->hitlist); while(!ajListIterDone(lIter)) { PHit phit = ajListIterGet(lIter); ajStrDel(&phit->forward); ajStrDel(&phit->reverse); ajStrDel(&phit->seqname); ajStrDel(&phit->acc); ajStrDel(&phit->desc); AJFREE(phit); } ajListFree(&primdata->hitlist); ajListFree(&primdata->hitlist); ajListIterDel(&lIter); AJFREE(primdata); return; }
void ajPatlistSeqDel (AjPPatlistSeq* pthys) { AjPPatlistSeq thys = NULL; AjPPatternSeq patternseq = NULL; thys = *pthys; while (ajListPop(thys->Patlist, (void **)&patternseq)) ajPatternSeqDel(&patternseq); if (thys->Iter) ajListIterDel(&thys->Iter); ajListFree(&thys->Patlist); AJFREE(*pthys); return; }
void ajRefseqClear(AjPRefseq refseq) { AjPSeqRange tmprange = NULL; if(MAJSTRGETLEN(refseq->Id)) ajStrSetClear(&refseq->Id); if(MAJSTRGETLEN(refseq->Db)) ajStrSetClear(&refseq->Db); if(MAJSTRGETLEN(refseq->Setdb)) ajStrSetClear(&refseq->Setdb); if(MAJSTRGETLEN(refseq->Full)) ajStrSetClear(&refseq->Full); if(MAJSTRGETLEN(refseq->Qry)) ajStrSetClear(&refseq->Qry); if(MAJSTRGETLEN(refseq->Formatstr)) ajStrSetClear(&refseq->Formatstr); if(MAJSTRGETLEN(refseq->Filename)) ajStrSetClear(&refseq->Filename); ajStrDel(&refseq->TextPtr); ajStrDel(&refseq->Desc); ajStrDel(&refseq->Seq); while(ajListPop(refseq->Seqlist,(void **)&tmprange)) ajSeqrangeDel(&tmprange); ajListFree(&refseq->Seqlist); refseq->Count = 0; refseq->Fpos = 0L; refseq->Format = 0; return; }
int main(int argc, char **argv) { AjPSeqall seqall; AjPFile outf; AjPSeq seq = NULL; AjPList xrefs = NULL; ajuint nrefs; AjPSeqXref xref = NULL; embInit("seqxref", argc, argv); outf = ajAcdGetOutfile("outfile"); seqall = ajAcdGetSeqall("sequence"); xrefs = ajListNew(); while(ajSeqallNext(seqall, &seq)) { nrefs = ajSeqGetXrefs(seq, xrefs); ajSeqxreflistSort(xrefs); ajFmtPrintF(outf, "#%S: %u\n", ajSeqGetUsaS(seq), nrefs); while(ajListPop(xrefs, (void**)&xref)) { ajFmtPrintF(outf, "%S:%S\n", xref->Db, xref->Id); ajSeqxrefDel(&xref); } } ajListFree(&xrefs); ajSeqDel(&seq); ajFileClose(&outf); ajSeqallDel(&seqall); embExit(); return 0; }
int main(int argc, char **argv) { AjPFile listf = NULL; /* File to be read - caths.list.v2.4. */ AjPFile domf = NULL; /* File to be read - domlist.v2.4. */ AjPFile namesf = NULL; /* File to be read - CAT.names.all.v2.4. */ AjPFile outf = NULL; /* Output file. */ AjPFile logf = NULL; /* Log file. */ AjPList list = NULL; /* List of CATH objects. */ AjPCath tmp = NULL; /* Temp. pointer. */ embInitPV("cathparse", argc, argv, "DOMAINATRIX",VERSION); listf = ajAcdGetInfile("listfile"); domf = ajAcdGetInfile("domfile"); namesf = ajAcdGetInfile("namesfile"); outf = ajAcdGetOutfile("outfile"); logf = ajAcdGetOutfile("logfile"); list = ajCathReadAllRawNew(listf, domf, namesf, logf); while(ajListPop(list, (void **) &tmp)) { ajCathWrite(outf, tmp); ajCathDel(&tmp); } /* Close CATH parsable files and output file */ ajFileClose(&listf); ajFileClose(&domf); ajFileClose(&namesf); ajFileClose(&outf); ajFileClose(&logf); ajListFree(&list); ajExit(); return 0; }
void ajPatlistRegexDel (AjPPatlistRegex* pthys) { AjPPatlistRegex thys = NULL; AjPPatternRegex patternregex = NULL; thys = *pthys; while (ajListPop(thys->Patlist, (void **)&patternregex)) { ajDebug("ajPatlistRegexDel list size: %d\n", ajListGetLength(thys->Patlist)); ajPatternRegexDel(&patternregex); } if (thys->Iter) ajListIterDel(&thys->Iter); ajListFree(&thys->Patlist); AJFREE(*pthys); return; }
int main(int argc, char **argv) { AjPStr directory = NULL; AjPTable mtable = NULL; AjPList jdirlist = NULL; AjPStr jdirloc = NULL; embInit("jaspextract",argc,argv); directory = ajAcdGetDirectoryName("directory"); mtable = ajTablestrNewLen(PFMNUMGUESS); jdirlist = ajListNew(); jaspextract_openoutdirs(); jaspextract_copyfiles(directory); jaspextract_readmatrixlist(mtable, directory); jaspextract_getjaspdirs(jdirlist); while(ajListPop(jdirlist,(void **)&jdirloc)) { jaspextract_writematrixfile(mtable, jdirloc); ajStrDel(&jdirloc); } ajTablestrFree(&mtable); ajStrDel(&directory); ajListFree(&jdirlist); embExit(); return 0; }
static void jaspextract_copyfiles(AjPStr directory) { AjPStr matrixfile = NULL; AjPList flist = NULL; AjPStr wild = NULL; AjPStr entry = NULL; AjPStr bname = NULL; AjPStr line = NULL; AjPStr dest = NULL; const AjPStr datadir = NULL; ajuint preflen = 0; ajuint i = 0; const char *p = NULL; AjPFile inf = NULL; AjPFile outf = NULL; matrixfile = ajStrNew(); flist = ajListNew(); wild = ajStrNewC("*.pfm"); bname = ajStrNew(); line = ajStrNew(); dest = ajStrNew(); datadir = ajDatafileValuePath(); if(!datadir) ajFatal("jaspextract: Cannot determine the EMBOSS data directory"); ajFmtPrintS(&matrixfile,"%S%s",directory,MATRIXFILE); if(!ajFilenameExistsRead(matrixfile)) ajFatal("jaspextract: Directory (%S) doesn't appear to be a JASPAR " "one\nNo matrix_list.txt file found",directory); ajFilelistAddPathWild(flist, directory, wild); while(ajListPop(flist,(void **)&entry)) { ajStrAssignS(&bname,entry); ajFilenameTrimPath(&bname); i = 0; while(Jprefix[i].Prefix) { if(!ajStrPrefixC(bname,Jprefix[i].Prefix)) { ++i; continue; } preflen = strlen(Jprefix[i].Prefix); p = ajStrGetPtr(bname); if(p[preflen]>='0' && p[preflen]<='9') break; ++i; } if(!Jprefix[i].Prefix) { ajStrDel(&entry); continue; } ajFmtPrintS(&dest,"%S%s%c%S",datadir,Jprefix[i].Directory,SLASH_CHAR, bname); outf = ajFileNewOutNameS(dest); if(!outf) ajFatal("Cannot open output file %S",dest); /* Avoid UNIX copy for portability */ inf = ajFileNewInNameS(entry); if(!inf) ajFatal("Cannot open input file: %S",entry); while(ajReadlineTrim(inf,&line)) ajFmtPrintF(outf,"%S\n",line); ajFileClose(&inf); ajFileClose(&outf); ajStrDel(&entry); } ajListFree(&flist); ajStrDel(&wild); ajStrDel(&dest); ajStrDel(&line); ajStrDel(&bname); ajStrDel(&matrixfile); return; }
int main(int argc, char **argv) { /* Variable Declarations */ AjPSeqset seqset = NULL; AjPMatrixf fmat = NULL; float thresh; float threshlow; float threshup; float gapopen; float gapextend; AjPSeqout seqout = NULL; AjPSeqout seqoutred = NULL; AjPStr mode = NULL; ajint moden; ajuint i; /* toggle "feature" from ACD not retrieved ... no need */ const AjPSeq seq = NULL; AjPList list = NULL; /* List for redundancy removal. */ AjPUint keep = NULL; /* 1: Sequence in list was non-redundant, 0: redundant. */ ajuint nseq = 0; /* No. seqs. in list. */ ajint nseqnr = 0; /* No. non-redundant seqs. in list. */ /* ACD File Processing */ embInit("skipredundant", argc, argv); seqset = ajAcdGetSeqset("sequences"); mode = ajAcdGetListSingle("mode"); fmat = ajAcdGetMatrixf("datafile"); thresh = ajAcdGetFloat("threshold"); threshlow = ajAcdGetFloat("minthreshold"); threshup = ajAcdGetFloat("maxthreshold"); gapopen = ajAcdGetFloat("gapopen"); gapextend = ajAcdGetFloat("gapextend"); seqout = ajAcdGetSeqoutall("outseq"); seqoutred = ajAcdGetSeqoutall("redundantoutseq"); /* Application logic */ list = ajListNew(); skipredundant_SeqsetToList(list, seqset); keep = ajUintNew(); ajStrToInt(mode, &moden); if(moden == 1) /* Remove redundancy at a single threshold % sequence similarity */ { if((!embDmxSeqNR(list, &keep, &nseqnr, fmat, gapopen, gapextend, thresh, ajFalse))) ajFatal("embDmxSeqNR unexpected failure!"); } else if (moden == 2) /* 2: Remove redundancy outside a range of acceptable threshold % similarity */ { if((!embDmxSeqNRRange(list, &keep, &nseqnr, fmat, gapopen, gapextend, threshlow, threshup, ajFalse))) ajFatal("embDmxSeqNRRange unexpected failure!"); } else ajFatal("Invalid mode (not 1 or 2) which should never occur (check ACD file!)"); nseq = ajSeqsetGetSize(seqset); for(i=0; i<nseq; i++) { seq = ajSeqsetGetseqSeq(seqset, i); if(ajUintGet(keep, i)) ajSeqoutWriteSeq(seqout, seq); else if(seqoutred) ajSeqoutWriteSeq(seqoutred, seq); } /* Memory management and exit */ ajSeqsetDel(&seqset); ajMatrixfDel(&fmat); ajStrDel(&mode); ajSeqoutClose(seqout); ajSeqoutDel(&seqout); if(seqoutred) { ajSeqoutClose(seqoutred); ajSeqoutDel(&seqoutred); } skipredundant_ClearList(list); ajListFree(&list); ajUintDel(&keep); embExit(); return 0; }
int main(int argc, char **argv) { ajint begin, end; AjPSeqall seqall; AjPSeq seq; EmbPShow ss; AjPFile outfile; AjPStr tablename; ajint table; AjPRange uppercase; AjPRange highlight; AjBool threeletter; AjBool numberseq; AjBool nameseq; ajint width; ajint length; ajint margin; AjBool description; ajint offset; AjBool html; AjPStr descriptionline; ajint orfminsize; AjPTrn trnTable; AjBool translation; AjBool reverse; AjBool cutlist; AjBool flat; EmbPMatMatch mm = NULL; AjPStr *framelist; AjBool frames[6]; /* frames to be translated 1 to 3, -1 to -3 */ /* stuff for tables and lists of enzymes and hits */ ajint default_mincuts = 1; ajint default_maxcuts = 2000000000; AjPTable hittable; /* enzyme hits */ /* stuff lifted from Alan's 'restrict.c' */ AjPStr enzymes = NULL; ajint mincuts; ajint maxcuts; ajint sitelen; AjBool single; AjBool blunt; AjBool sticky; AjBool ambiguity; AjBool plasmid; AjBool commercial; AjBool limit; AjBool methyl; AjPFile enzfile = NULL; AjPFile equfile = NULL; AjPFile methfile = NULL; AjPTable retable = NULL; ajint hits; AjPList restrictlist = NULL; embInit("remap", argc, argv); seqall = ajAcdGetSeqall("sequence"); outfile = ajAcdGetOutfile("outfile"); tablename = ajAcdGetListSingle("table"); uppercase = ajAcdGetRange("uppercase"); highlight = ajAcdGetRange("highlight"); threeletter = ajAcdGetBoolean("threeletter"); numberseq = ajAcdGetBoolean("number"); width = ajAcdGetInt("width"); length = ajAcdGetInt("length"); margin = ajAcdGetInt("margin"); nameseq = ajAcdGetBoolean("name"); description = ajAcdGetBoolean("description"); offset = ajAcdGetInt("offset"); html = ajAcdGetBoolean("html"); orfminsize = ajAcdGetInt("orfminsize"); translation = ajAcdGetBoolean("translation"); reverse = ajAcdGetBoolean("reverse"); cutlist = ajAcdGetBoolean("cutlist"); flat = ajAcdGetBoolean("flatreformat"); framelist = ajAcdGetList("frame"); /* restriction enzyme stuff */ mincuts = ajAcdGetInt("mincuts"); maxcuts = ajAcdGetInt("maxcuts"); sitelen = ajAcdGetInt("sitelen"); single = ajAcdGetBoolean("single"); blunt = ajAcdGetBoolean("blunt"); sticky = ajAcdGetBoolean("sticky"); ambiguity = ajAcdGetBoolean("ambiguity"); plasmid = ajAcdGetBoolean("plasmid"); commercial = ajAcdGetBoolean("commercial"); limit = ajAcdGetBoolean("limit"); enzymes = ajAcdGetString("enzymes"); methfile = ajAcdGetDatafile("mfile"); methyl = ajAcdGetBoolean("methylation"); if(!blunt && !sticky) ajFatal("Blunt/Sticky end cutters shouldn't both be disabled."); /* get the number of the genetic code used */ ajStrToInt(tablename, &table); trnTable = ajTrnNewI(table); /* read the local file of enzymes names */ remap_read_file_of_enzyme_names(&enzymes); /* get the frames to be translated */ remap_GetFrames(framelist, frames); while(ajSeqallNext(seqall, &seq)) { /* get begin and end positions */ begin = ajSeqGetBegin(seq)-1; end = ajSeqGetEnd(seq)-1; /* do the name and description */ if(nameseq) { if(html) ajFmtPrintF(outfile, "<H2>%S</H2>\n", ajSeqGetNameS(seq)); else ajFmtPrintF(outfile, "%S\n", ajSeqGetNameS(seq)); } if(description) { /* ** wrap the description line at the width of the sequence ** plus margin */ if(html) ajFmtPrintF(outfile, "<H3>%S</H3>\n", ajSeqGetDescS(seq)); else { descriptionline = ajStrNew(); ajStrAssignS(&descriptionline, ajSeqGetDescS(seq)); ajStrFmtWrap(&descriptionline, width+margin); ajFmtPrintF(outfile, "%S\n", descriptionline); ajStrDel(&descriptionline); } } /* get the restriction cut sites */ /* ** most of this is lifted from the program 'restrict.c' by Alan ** Bleasby */ if(single) maxcuts=mincuts=1; retable = ajTablestrNew(EQUGUESS); enzfile = ajDatafileNewInNameC(ENZDATA); if(!enzfile) ajFatal("Cannot locate enzyme file. Run REBASEEXTRACT"); if(limit) { equfile = ajDatafileNewInNameC(EQUDATA); if(!equfile) limit = ajFalse; else remap_read_equiv(&equfile, &retable, commercial); } ajFileSeek(enzfile, 0L, 0); restrictlist = ajListNew(); /* search for hits, but don't use mincuts and maxcuts criteria yet */ hits = embPatRestrictMatch(seq, begin+1, end+1, enzfile, methfile, enzymes, sitelen,plasmid, ambiguity, default_mincuts, default_maxcuts, blunt, sticky, commercial, methyl, restrictlist); ajDebug("Remap found %d hits\n", hits); if(hits) { /* this bit is lifted from printHits */ embPatRestrictRestrict(restrictlist, hits, !limit, ajFalse); if(limit) remap_RestrictPreferred(restrictlist,retable); } ajFileClose(&enzfile); ajFileClose(&methfile); /* ** Remove those violating the mincuts and maxcuts ** criteria, but save them in hittable for printing out later. ** Keep a count of how many hits each enzyme gets in hittable. */ hittable = ajTablestrNewCase(TABLEGUESS); remap_RemoveMinMax(restrictlist, hittable, mincuts, maxcuts); /* make the Show Object */ ss = embShowNew(seq, begin, end, width, length, margin, html, offset); if(html) ajFmtPrintF(outfile, "<PRE>"); /* create the format to display */ embShowAddBlank(ss); embShowAddRE(ss, 1, restrictlist, plasmid, flat); embShowAddSeq(ss, numberseq, threeletter, uppercase, highlight); if(!numberseq) embShowAddTicknum(ss); embShowAddTicks(ss); if(reverse) { embShowAddComp(ss, numberseq); embShowAddRE(ss, -1, restrictlist, plasmid, flat); } if(translation) { if(reverse) embShowAddBlank(ss); if(frames[0]) embShowAddTran(ss, trnTable, 1, threeletter, numberseq, NULL, orfminsize, AJFALSE, AJFALSE, AJFALSE, AJFALSE); if(frames[1]) embShowAddTran(ss, trnTable, 2, threeletter, numberseq, NULL, orfminsize, AJFALSE, AJFALSE, AJFALSE, AJFALSE); if(frames[2]) embShowAddTran(ss, trnTable, 3, threeletter, numberseq, NULL, orfminsize, AJFALSE, AJFALSE, AJFALSE, AJFALSE); if(reverse) { embShowAddTicks(ss); if(frames[5]) embShowAddTran(ss, trnTable, -3, threeletter, numberseq, NULL, orfminsize, AJFALSE, AJFALSE, AJFALSE, AJFALSE); if(frames[4]) embShowAddTran(ss, trnTable, -2, threeletter, numberseq, NULL, orfminsize, AJFALSE, AJFALSE, AJFALSE, AJFALSE); if(frames[3]) embShowAddTran(ss, trnTable, -1, threeletter, numberseq, NULL, orfminsize, AJFALSE, AJFALSE, AJFALSE, AJFALSE); } } embShowPrint(outfile, ss); /* display a list of the Enzymes that cut and don't cut */ if(cutlist) { remap_CutList(outfile, hittable, limit, html, mincuts, maxcuts); remap_NoCutList(outfile, hittable, html, enzymes, blunt, sticky, sitelen, commercial, ambiguity, limit, retable); } /* add a gratuitous newline at the end of the sequence */ ajFmtPrintF(outfile, "\n"); /* tidy up */ embShowDel(&ss); while(ajListPop(restrictlist,(void **)&mm)) embMatMatchDel(&mm); ajListFree(&restrictlist); remap_DelTable(&hittable); ajTablestrFree(&retable); } ajTrnDel(&trnTable); ajSeqallDel(&seqall); ajSeqDel(&seq); ajFileClose(&outfile); ajStrDel(&tablename); ajStrDel(&enzymes); ajStrDelarray(&framelist); ajRangeDel(&uppercase); ajRangeDel(&highlight); 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; }
void ajResourceDel(AjPResource *Presource) { AjPResource thys; AjPReslink reslink; AjPResquery resqry; AjPResterm resterm; AjIList iter; if(!Presource) return; if(!(*Presource)) return; thys = *Presource; ajStrDel(&thys->Id); ajListstrFreeData(&thys->Idalt); ajStrDel(&thys->Acc); ajStrDel(&thys->Name); ajStrDel(&thys->Desc); ajStrDel(&thys->Url); ajStrDel(&thys->Urllink); ajStrDel(&thys->Urlrest); ajStrDel(&thys->Urlsoap); ajListstrFreeData(&thys->Cat); iter = ajListIterNewread(thys->Taxon); while(!ajListIterDone(iter)) { resterm = ajListIterGet(iter); ajRestermDel(&resterm); } ajListIterDel(&iter); ajListFree(&thys->Taxon); iter = ajListIterNewread(thys->Edamdat); while(!ajListIterDone(iter)) { resterm = ajListIterGet(iter); ajRestermDel(&resterm); } ajListIterDel(&iter); ajListFree(&thys->Edamdat); iter = ajListIterNewread(thys->Edamfmt); while(!ajListIterDone(iter)) { resterm = ajListIterGet(iter); ajRestermDel(&resterm); } ajListIterDel(&iter); ajListFree(&thys->Edamfmt); iter = ajListIterNewread(thys->Edamid); while(!ajListIterDone(iter)) { resterm = ajListIterGet(iter); ajRestermDel(&resterm); } ajListIterDel(&iter); ajListFree(&thys->Edamid); iter = ajListIterNewread(thys->Edamtpc); while(!ajListIterDone(iter)) { resterm = ajListIterGet(iter); ajRestermDel(&resterm); } ajListIterDel(&iter); ajListFree(&thys->Edamtpc); iter = ajListIterNewread(thys->Xref); while(!ajListIterDone(iter)) { reslink = ajListIterGet(iter); ajReslinkDel(&reslink); } ajListIterDel(&iter); ajListFree(&thys->Xref); iter = ajListIterNewread(thys->Query); while(!ajListIterDone(iter)) { resqry = ajListIterGet(iter); ajResqueryDel(&resqry); } ajListIterDel(&iter); ajListFree(&thys->Query); ajListstrFreeData(&thys->Example); ajStrDel(&thys->Db); ajStrDel(&thys->Setdb); ajStrDel(&thys->Full); ajStrDel(&thys->Qry); ajStrDel(&thys->Formatstr); ajStrDel(&thys->Filename); ajStrDel(&thys->TextPtr); AJFREE(*Presource); *Presource = NULL; return; }
int main(int argc, char **argv) { AjPList sigin = NULL; /* Signature input file names. */ AjPStr signame = NULL; /* Name of signature file. */ AjPFile sigf = NULL; /* Signature input file. */ EmbPSignature sig = NULL; /* Signature. */ AjPList siglist = NULL; /* List of signatures. */ AjIList sigiter = NULL; /* Iterator for siglist. */ AjBool sigok = ajFalse; /* True if signature processed ok. */ EmbPHit hit = NULL; /* Hit to store signature-sequence match. */ AjPList hits = NULL; /* List of hits */ AjPList ligands = NULL; /* List of top-scoring ligands. */ AjPSeqall database=NULL; /* Protein sequences to match signature against. */ AjPSeq seq = NULL; /* Current sequence. */ AjPMatrixf sub =NULL; /* Residue substitution matrix. */ float gapo =0.0; /* Gap insertion penalty. */ float gape =0.0; /* Gap extension penalty. */ AjPStr nterm=NULL; /* Holds N-terminal matching options from acd. */ ajint ntermi=0; /* N-terminal option as int. */ AjPFile hitsf =NULL; /* Hits output file. sequence matches. */ AjPDirout hitsdir=NULL; /* Directory of hits files (output). */ AjPFile alignf =NULL; /* Alignment output file. */ AjPDirout aligndir=NULL; /* Directory of alignment files (output). */ AjPFile resultsf =NULL; /* Results file (output). */ AjPDirout resultsdir=NULL; /* Directory of results files (output). */ AjPStr mode = NULL; /* Mode, 1: Patch score mode, 2: Site score mode. */ ajint modei = 0; /* Selected mode as integer. */ SigPLighit lighit = NULL; embInitPV("sigscanlig", argc, argv, "SIGNATURE",VERSION); /* GET VALUES FROM ACD */ sigin = ajAcdGetDirlist("siginfilesdir"); database = ajAcdGetSeqall("dbseqall"); sub = ajAcdGetMatrixf("sub"); gapo = ajAcdGetFloat("gapo"); gape = ajAcdGetFloat("gape"); nterm = ajAcdGetListSingle("nterm"); hitsdir = ajAcdGetOutdir("hitsoutdir"); aligndir = ajAcdGetOutdir("alignoutdir"); resultsdir = ajAcdGetOutdir("resultsoutdir"); mode = ajAcdGetListSingle("mode"); /*Assign N-terminal matching option etc. */ ajFmtScanS(nterm, "%d", &ntermi); modei = (ajint) ajStrGetCharFirst(mode)-48; /* READ & PROCESS SIGNATURES */ siglist = ajListNew(); while(ajListPop(sigin, (void **) &signame)) { /* Read signature files, compile signatures and populate list. */ sigok = ajFalse; if((sigf = ajFileNewInNameS(signame))) if((sig = embSignatureReadNew(sigf))) if(embSignatureCompile(&sig, gapo, gape, sub)) { sigok=ajTrue; ajListPushAppend(siglist, sig); /* ajFmtPrint("Id: %S\nDomid: %S\nLigid: %S\nns: %d\n" "sn: %d\nnp: %d\npn: %d\nminpatch: %d\n" "maxgap: %d\n", sig->Id, sig->Domid, sig->Ligid, sig->ns, sig->sn, sig->np, sig->pn, sig->minpatch, sig->maxgap); */ } if(!sigok) { ajWarn("Could not process %S", signame); embSignatureDel(&sig); ajFileClose(&sigf); ajStrDel(&signame); continue; } ajFileClose(&sigf); ajStrDel(&signame); } ajListFree(&sigin); /* ALIGN EACH QUERY SEQUENCE TO LIST OF SIGNATURE */ while(ajSeqallNext(database, &seq)) { /* Do sequence-signature alignment and save results */ hits = ajListNew(); sigiter = ajListIterNew(siglist); while((sig = (EmbPSignature) ajListIterGet(sigiter))) { if(embSignatureAlignSeq(sig, seq, &hit, ntermi)) { hit->Sig = sig; ajListPushAppend(hits, hit); hit=NULL; /* To force reallocation by embSignatureAlignSeq */ } /* There has to be a hit for each signature for correct generation of the LHF by sigscanlig_WriteFasta. So push an empty hit if necessary. 'hit'=NULL forces reallocation by embSignatureAlignSeq. */ /* else { hit = embHitNew(); ajListPushAppend(hits, hit); hit=NULL; } */ } ajListIterDel(&sigiter); /* Rank-order the list of hits by score */ ajListSort(hits, embMatchinvScore); /* Write ligand hits & alignment files (output) */ hitsf = ajFileNewOutNameDirS(ajSeqGetNameS(seq), hitsdir); alignf = ajFileNewOutNameDirS(ajSeqGetNameS(seq), aligndir); resultsf = ajFileNewOutNameDirS(ajSeqGetNameS(seq), resultsdir); /* if((!sigscanlig_WriteFasta(hitsf, siglist, hits))) ajFatal("Bad args to sigscanlig_WriteFasta"); */ if((!sigscanlig_WriteFasta(hitsf, hits))) ajFatal("Bad args to sigscanlig_WriteFasta"); if((!sigscanlig_SignatureAlignWriteBlock(alignf, hits))) ajFatal("Bad args to sigscanlig_SignatureAlignWriteBlock"); /* if((!sigscanlig_SignatureAlignWriteBlock(alignf, siglist, hits))) ajFatal("Bad args to sigscanlig_SignatureAlignWriteBlock"); */ /* Sort list of hits by ligand type and site number. Process list of ligands and print out. */ ajListSortTwo(hits, embMatchLigid, embMatchSN); if(modei==1) ligands = sigscanlig_score_ligands_patch(hits); else if(modei==2) ligands = sigscanlig_score_ligands_site(hits); else ajFatal("Unrecognised mode"); sigscanlig_WriteResults(ligands, resultsf); ajFileClose(&hitsf); ajFileClose(&alignf); ajFileClose(&resultsf); /* Memory management */ while(ajListPop(hits, (void **) &hit)) embHitDel(&hit); ajListFree(&hits); while(ajListPop(ligands, (void **) &lighit)) sigscanlig_LigHitDel(&lighit); ajListFree(&ligands); } /* MEMORY MANAGEMENT */ while(ajListPop(siglist, (void **) &sig)) embSignatureDel(&sig); ajListFree(&siglist); ajSeqallDel(&database); ajMatrixfDel(&sub); ajStrDel(&nterm); ajDiroutDel(&hitsdir); ajDiroutDel(&aligndir); ajDiroutDel(&resultsdir); ajStrDel(&mode); embExit(); return 0; }
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) { 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 seqall; AjPSeq seq = NULL; AjPReport outf = NULL; AjPFile inf = NULL; ajint begin; ajint end; AjPList l = NULL; AjPStr strand = NULL; AjPStr substr = NULL; AjPStr line = NULL; AjPStr name = NULL; AjPStr acc = NULL; AjPStr bf = NULL; AjPStr menu; AjPStr pattern = NULL; AjPStr opattern = NULL; AjPStr pname = NULL; AjPStr key = NULL; AjPStr value = NULL; AjPTable atable = NULL; AjPTable btable = NULL; ajint mismatch; ajint minlength; ajint sum; ajint v; char cp; const char *p; embInit("tfscan", argc, argv); seqall = ajAcdGetSeqall("sequence"); outf = ajAcdGetReport("outfile"); mismatch = ajAcdGetInt("mismatch"); minlength = ajAcdGetInt("minlength"); menu = ajAcdGetListSingle("menu"); pname = ajStrNew(); cp=ajStrGetCharFirst(menu); if(cp=='F') ajStrAssignC(&pname,"tffungi"); else if(cp=='I') ajStrAssignC(&pname,"tfinsect"); else if(cp=='O') ajStrAssignC(&pname,"tfother"); else if(cp=='P') ajStrAssignC(&pname,"tfplant"); else if(cp=='V') ajStrAssignC(&pname,"tfvertebrate"); else if(cp=='C') inf = ajAcdGetDatafile("custom"); if(cp!='C') { inf = ajDatafileNewInNameS(pname); if(!inf) ajFatal("Either EMBOSS_DATA undefined or TFEXTRACT needs running"); } name = ajStrNew(); acc = ajStrNew(); bf = ajStrNewC(""); substr = ajStrNew(); line = ajStrNew(); pattern = ajStrNewC("AA"); opattern = ajStrNew(); while(ajSeqallNext(seqall, &seq)) { begin=ajSeqallGetseqBegin(seqall); end=ajSeqallGetseqEnd(seqall); ajStrAssignC(&name,ajSeqGetNameC(seq)); strand=ajSeqGetSeqCopyS(seq); ajStrAssignSubC(&substr,ajStrGetPtr(strand),begin-1,end-1); ajStrFmtUpper(&substr); l=ajListNew(); atable = ajTablestrNew(1000); btable = ajTablestrNew(1000); sum=0; while(ajReadlineTrim(inf,&line)) { p = ajStrGetPtr(line); if(!*p || *p=='#' || *p=='\n' || *p=='!') continue; ajFmtScanS(line,"%S%S%S",&pname,&pattern,&acc); p += ajStrGetLen(pname); while(*p && *p==' ') ++p; p += ajStrGetLen(pattern); while(*p && *p==' ') ++p; p += ajStrGetLen(acc); while(*p && *p==' ') ++p; ajStrAssignS(&opattern,pattern); ajStrAssignC(&bf,p); /* rest of line */ v = embPatVariablePattern(pattern,substr,pname,l,0, mismatch,begin); if(v) { key = ajStrNewS(pname); value = ajStrNewS(acc); ajTablePut(atable,(void *)key,(void *)value); key = ajStrNewS(pname); value = ajStrNewS(bf); ajTablePut(btable,(void *)key,(void *)value); } sum += v; } if(sum) tfscan_print_hits(&l,sum,outf,atable,seq,minlength, btable); ajFileSeek(inf,0L,0); ajListFree(&l); ajTablestrFree(&atable); ajTablestrFree(&btable); ajStrDel(&strand); } ajStrDel(&line); ajStrDel(&name); ajStrDel(&acc); ajStrDel(&pname); ajStrDel(&opattern); ajStrDel(&bf); ajStrDel(&pattern); ajStrDel(&substr); ajSeqDel(&seq); ajFileClose(&inf); ajReportClose(outf); ajReportDel(&outf); ajSeqallDel(&seqall); ajSeqDel(&seq); ajStrDel(&menu); 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; }
int main(int argc, char **argv) { /* Variable declarations */ AjPOutfile outfile = NULL; AjBool obsolete = ajTrue; AjPObo obo = NULL; AjPObo oboanc = NULL; AjPObo oboparent = NULL; AjPOboall oboall = NULL; AjPOboin oboin = NULL; AjPStr oboqryup = NULL; AjPStr oboqryanc = NULL; AjPTable alltable = NULL; AjPTable newtable = NULL; AjPStr up = NULL; AjPList uplist = NULL; ajuint iterms = 0; AjPStr topid = NULL; AjPStr obodb = NULL; AjBool saved = ajFalse; /* ACD processing */ embInit("ontogetcommon", argc, argv); oboall = ajAcdGetOboall("oboterms"); outfile = ajAcdGetOutobo("outfile"); obsolete = ajAcdGetBoolean("obsolete"); oboin = ajOboinNew(); oboparent = ajOboNew(); oboanc = ajOboNew(); uplist = ajListNew(); alltable = ajTablestrNew(600); newtable = ajTablestrNew(600); while(ajOboallNext(oboall, &obo)) { saved = ajFalse; if(!obsolete && ajOboIsObsolete(obo)) continue; if(!iterms) { ajDebug("store id '%S'\n", ajOboGetId(obo)); ajStrAssignS(&obodb, ajOboGetDb(obo)); ajTablePut(alltable, ajStrNewS(ajOboGetId(obo)), NULL); saved = ajTrue; } else { ajDebug("test id '%S'\n", ajOboGetId(obo)); if(ajTableMatchS(alltable, ajOboGetId(obo))) { ajDebug("keep id '%S'\n", ajOboGetId(obo)); ajTablePut(newtable, ajStrNewS(ajOboGetId(obo)), NULL); saved = ajTrue; } } if(saved) ajStrAssignS(&topid, ajOboGetId(obo)); if(ajOboGetParents(obo, uplist)) /* that was the root */ { while(ajListstrPop(uplist, &up)) { ajDebug("up: '%S'\n", up); ajFmtPrintS(&oboqryup, "%S-id:%S", ajOboGetDb(obo), up); ajOboinQryS(oboin, oboqryup); while(ajOboinRead(oboin, oboparent)) { if(!obsolete && ajOboIsObsolete(oboparent)) continue; if(!iterms) { ajDebug("store parent '%S'\n", ajOboGetId(oboparent)); ajTablePut(alltable, ajStrNewS(ajOboGetId(oboparent)), NULL); } else { ajDebug("test parent '%S'\n", ajOboGetId(oboparent)); if(ajTableMatchS(alltable, ajOboGetId(oboparent))) { ajDebug("keep parent '%S'\n", ajOboGetId(oboparent)); ajTablePut(newtable, ajStrNewS(ajOboGetId(oboparent)), NULL); if(!saved) { ajStrAssignS(&topid, ajOboGetId(oboparent)); saved = ajTrue; } } } if(!ajOboGetParents(oboparent, uplist)) continue; } ajStrDel(&up); } } if(iterms) ajTableMergeAnd(alltable, newtable); ajDebug("id: '%S' saved %u\n", ajOboGetId(obo), ajTableGetLength(alltable)); if(!ajTableGetLength(alltable)) ajDie("Query '%S' no matching ancestor found for obo term '%S:%S'", ajOboallGetQryS(oboall), ajOboGetDb(obo), ajOboGetId(obo)); iterms++; } ajFmtPrintS(&oboqryanc, "%S-id:%S", obodb, topid); ajOboinQryS(oboin, oboqryanc); while(ajOboinRead(oboin, oboanc)) { ajObooutWrite(outfile, oboanc); } /* Memory clean-up and exit */ ajOboallDel(&oboall); ajOboinDel(&oboin); ajOboDel(&oboanc); ajOboDel(&oboparent); ajListFree(&uplist); ajTablestrFreeKey(&alltable); ajTablestrFreeKey(&newtable); ajStrDel(&oboqryup); ajStrDel(&oboqryanc); ajStrDel(&obodb); ajStrDel(&topid); ajOutfileClose(&outfile); embExit(); return 0; }