/* @funcstatic domainalign_writeid ******************************************** ** ** House-keeping function. ** ** @param [r] domain [AjPDomain] Domain. ** @param [r] noden [ajint] Node number. ** @param [r] daf [AjPDirout] Domain alignment files. ** @param [r] super [AjPDirout] Structural superimposition files. ** @param [r] align [AjPStr *] Align. ** @param [r] alignc [AjPStr *] Alignc. ** ** @return [void] ** ** @@ ****************************************************************************/ static void domainalign_writeid(AjPDomain domain, ajint noden, AjPDirout daf, AjPDirout super, AjPStr *align, AjPStr *alignc) { AjPStr temp=NULL; temp=ajStrNew(); if(noden==1) ajStrFromInt(&temp, domain->Scop->Sunid_Class); else if (noden==2) ajStrFromInt(&temp, domain->Scop->Sunid_Fold); else if (noden==3) ajStrFromInt(&temp, domain->Scop->Sunid_Superfamily); else if (noden==4) ajStrFromInt(&temp, domain->Scop->Sunid_Family); else if (noden==5) ajStrFromInt(&temp, domain->Cath->Class_Id ); else if (noden==6) ajStrFromInt(&temp, domain->Cath->Arch_Id); else if (noden==7) ajStrFromInt(&temp, domain->Cath->Topology_Id); else if (noden==8) ajStrFromInt(&temp, domain->Cath->Superfamily_Id); else if (noden==9) ajStrFromInt(&temp, domain->Cath->Family_Id); ajStrAssignS(align, temp); ajStrInsertS(align, 0, ajDiroutGetPath(daf)); ajStrAppendC(align, "."); ajStrAppendS(align, ajDiroutGetExt(daf)); ajStrAssignS(alignc, temp); ajStrInsertS(alignc, 0, ajDiroutGetPath(super)); ajStrAppendC(alignc, "."); ajStrAppendS(alignc, ajDiroutGetExt(super)); ajDebug("daf file '%S' super file '%S'\n", *align, *alignc); ajStrDel(&temp); return; }
AjPResquery ajResqueryNewResquery(const AjPResquery qry) { AjPResquery ret; AJNEW0(ret); if(!qry) return ret; ajStrAssignS(&ret->Datatype, qry->Datatype); ajStrAssignS(&ret->Format, qry->Format); ajStrAssignS(&ret->FormatTerm, qry->FormatTerm); ajStrAssignS(&ret->Term, qry->Term); ajStrAssignS(&ret->Url, qry->Url); ret->Nterms = qry->Nterms; return ret; }
/* @funcstatic domainalign_writelast ****************************************** ** ** House-keeping function. ** ** @param [r] domain [AjPDomain] Domain. ** @param [r] noden [ajint] Node number. ** @param [r] last_node [AjPStr *] Last node. ** @param [r] last_nodeid [ajint *] Id of last node. ** ** @return [void] ** ** @@ ****************************************************************************/ static void domainalign_writelast(AjPDomain domain, ajint noden, AjPStr *last_node, ajint *last_nodeid) { if(noden==1) { ajStrAssignS(last_node, domain->Scop->Class); *last_nodeid = domain->Scop->Sunid_Class; } else if (noden==2) { ajStrAssignS(last_node, domain->Scop->Fold); *last_nodeid = domain->Scop->Sunid_Fold; } else if (noden==3) { ajStrAssignS(last_node, domain->Scop->Superfamily); *last_nodeid = domain->Scop->Sunid_Superfamily; } else if (noden==4) { ajStrAssignS(last_node, domain->Scop->Family); *last_nodeid = domain->Scop->Sunid_Family; } else if (noden==5) { ajStrAssignS(last_node, domain->Cath->Class); *last_nodeid = domain->Cath->Class_Id ; } else if (noden==6) { ajStrAssignS(last_node, domain->Cath->Architecture); *last_nodeid = domain->Cath->Arch_Id; } else if (noden==7) { ajStrAssignS(last_node, domain->Cath->Topology); *last_nodeid = domain->Cath->Topology_Id; } else if (noden==8) { ajStrAssignS(last_node, domain->Cath->Superfamily); *last_nodeid = domain->Cath->Superfamily_Id; } else if (noden==9) { /* There is no text describing the CATH families. */ ajFmtPrintS(last_node, "%d", domain->Cath->Family_Id); *last_nodeid = domain->Cath->Family_Id; } }
static void jaspextract_readmatrixlist(AjPTable mtable, const AjPStr directory) { const AjPStr datadir = NULL; AjPStr matrixfile = NULL; AjPFile inf = NULL; AjPStr line = NULL; AjPStr key = NULL; AjPStr value = NULL; matrixfile = 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); inf = ajFileNewInNameS(matrixfile); if(!inf) ajFatal("Cannot open input file: %S",matrixfile); while(ajReadline(inf,&line)) { key = ajStrNew(); if(ajFmtScanS(line,"%S",&key) != 1) { ajStrDel(&key); continue; } value = ajStrNew(); ajStrAssignS(&value,line); ajTablePut(mtable,(void *)key, (void *)value); } ajFileClose(&inf); ajStrDel(&matrixfile); ajStrDel(&line); return; }
static void dbiblast_newname(AjPStr* nname, const AjPStr oname, const char *suff) { ajStrAssignS(nname, oname); if(ajStrGetCharFirst(oname)=='@') ajStrCutStart(nname, 1); ajStrAppendK(nname, '.'); ajStrAppendC(nname, suff); return; }
static void notseq_readfile(const AjPStr exclude, AjPStr *pattern) { AjPFile file = NULL; AjPStr line; AjPStr filename = NULL; const char *p = NULL; if(ajStrFindC(exclude, "@") != 0) { ajStrAssignS(pattern, exclude); } else { ajStrAssignS(&filename, exclude); ajStrTrimC(&filename, "@"); /* remove the @ */ file = ajFileNewInNameS(filename); if(file == NULL) ajFatal("Cannot open the file of sequence names: '%S'", filename); /* blank off the file name and replace with the sequence names */ ajStrSetClear(pattern); line = ajStrNew(); while(ajReadlineTrim(file, &line)) { p = ajStrGetPtr(line); if(!*p || *p == '#' || *p == '!') continue; ajStrAppendS(pattern, line); ajStrAppendC(pattern, ","); } ajStrDel(&line); ajStrDel(&filename); ajFileClose(&file); } return; }
static void eprimer3_write_primer(AjPFile outfile, const char *tag, const AjPStr pos, const AjPStr tm, const AjPStr gc, const AjPStr seq, AjBool rev, ajint begin) { ajint startint; ajint lenint; float tmfloat; float gcfloat; AjPStr start = NULL; AjPStr lenstr = NULL; ajlong comma; if(ajStrGetLen(pos)) { ajStrToFloat(tm, &tmfloat); ajStrToFloat(gc, &gcfloat); comma = ajStrFindC(pos, ","); ajStrAssignS(&start, pos); ajStrCutRange(&start, comma, ajStrGetLen(start)-1); ajStrToInt(start, &startint); startint += begin; ajStrAssignS(&lenstr, pos); ajStrCutRange(&lenstr, 0, comma); ajStrToInt(lenstr, &lenint); if(rev) startint = startint - lenint + 1; ajFmtPrintF(outfile, " %s %6d %4d %2.2f %2.2f %S\n\n", tag, startint, lenint, tmfloat, gcfloat, seq); } ajStrDel(&start); ajStrDel(&lenstr); return; }
void ajHistSetmultiXlabelS(AjPHist thys, ajuint indexnum, const AjPStr str) { if(indexnum >= thys->numofdatapoints) { ajErr("Histograms can only be allocated from 0 to %d. NOT %u", thys->numofdatapoints-1,indexnum); return; } ajStrAssignS(&thys->hists[indexnum]->xaxis, str); return; }
static void splitter_MakeSubSeqName (AjPStr * name_ptr, const AjPSeq seq, ajuint start, ajuint end) { AjPStr value = ajStrNew(); /* create a nice name for the subsequence */ ajStrAssignS(name_ptr, ajSeqGetNameS(seq)); ajStrAppendC(name_ptr, "_"); ajStrFromUint(&value, ajSeqGetBegin(seq)+start); ajStrAppendS(name_ptr, value); ajStrAppendC(name_ptr, "-"); ajStrFromUint(&value, ajSeqGetBegin(seq)+end); ajStrAppendS(name_ptr, value); ajStrDel(&value); }
static void emira_dobools(AjPStr *cl, AjPTable table) { ajuint i; AjBool bqual = ajFalse; AjBool def = ajFalse; AjPStr prefix = NULL; AjPStr key = NULL; AjPStr value = NULL; prefix = ajStrNew(); key = ajStrNew(); i = 0; while(mirabools[i].qname) { bqual = ajAcdGetBoolean(mirabools[i].qname); ajStrAssignC(&key,mirabools[i].qname); ajStrAssignC(&prefix,""); value = ajTableFetch(table, key); if(value) ajStrAssignS(&prefix,value); def = ajCharMatchC(mirabools[i].def,"N") ? ajFalse : ajTrue; if(bqual != def) { ajFmtPrintAppS(cl," -%S%s=",prefix,mirabools[i].mname); if(bqual) ajFmtPrintAppS(cl,"yes"); else ajFmtPrintAppS(cl,"no"); } ++i; } ajStrDel(&key); ajStrDel(&prefix); return; }
static void emira_doinfiles(AjPStr *cl, AjPTable table) { ajuint i; AjPStr squal = NULL; AjPStr prefix = NULL; AjPStr key = NULL; AjPStr value = NULL; AjPFile infile = NULL; prefix = ajStrNew(); key = ajStrNew(); i = 0; while(mirainfiles[i].qname) { infile = ajAcdGetInfile(mirainfiles[i].qname); if(infile) squal = ajStrNewS(ajFileGetName(infile)); else squal = ajStrNewS(ajAcdGetValueDefault(mirainfiles[i].qname)); ajStrAssignC(&key,mirainfiles[i].mname); ajStrAssignC(&prefix,""); value = ajTableFetch(table, key); if(value) ajStrAssignS(&prefix,value); if(!ajStrMatchC(squal,mirainfiles[i].def)) ajFmtPrintAppS(cl," -%S%s=%S",prefix,mirainfiles[i].mname, squal); ajStrDel(&squal); ajFileClose(&infile); ++i; } ajStrDel(&key); ajStrDel(&prefix); return; }
static void filebuffLineAdd(AjPFilebuff buff, const AjPStr line) { /* ajDebug("fileBuffLineAdd '%S'\n", line);*/ if(buff->Freelines) { if(!buff->Lines) { /* Need to set first line in list */ buff->Lines = buff->Freelines; } else buff->Last->Next = buff->Freelines; buff->Last = buff->Freelines; buff->Freelines = buff->Freelines->Next; if(!buff->Freelines) { /* Free list now empty */ buff->Freelast = NULL; } } else { /* No Free list, make a new string */ if(!buff->Lines) buff->Lines = AJNEW0(buff->Last); else buff->Last = AJNEW0(buff->Last->Next); } ajStrAssignS(&buff->Last->Line, line); buff->Prev = buff->Curr; buff->Curr = buff->Last; buff->Last->Next = NULL; buff->Last->Fpos = buff->Fpos; buff->Pos++; buff->Size++; return; }
static PMemFile dbiblast_memfopenfile(const AjPStr name) { PMemFile ret; AjPFile fp; fp = ajFileNewInNameS(name); if(!fp) return NULL; AJNEW0(ret); ajStrAssignS(&ret->Name, name); ret->IsMem = 0; ret->File = fp; ret->Size = 0; ret->Mem = NULL; ajDebug("fopened '%S'\n", name); return ret; }
static void emira_dointegers(AjPStr *cl, AjPTable table) { ajuint i; ajint iqual; int dval = 0; AjPStr prefix = NULL; AjPStr key = NULL; AjPStr value = NULL; prefix = ajStrNew(); key = ajStrNew(); i = 0; while(miraintegers[i].qname) { iqual = ajAcdGetInt(miraintegers[i].qname); ajStrAssignC(&key,miraintegers[i].qname); ajStrAssignC(&prefix,""); value = ajTableFetch(table, key); if(value) ajStrAssignS(&prefix,value); if(sscanf(miraintegers[i].def,"%d",&dval) != 1) ajFatal("Dval conversion error in emira_dointegers()"); if(iqual != dval) ajFmtPrintAppS(cl," -%S%s=%d",prefix,miraintegers[i].mname,iqual); ++i; } ajStrDel(&key); ajStrDel(&prefix); return; }
static void dbiblast_dbname(AjPStr* dbname, const AjPStr oname, const char *suff) { AjPStr suffix = NULL; ajFmtPrintS(&suffix, ".%s", suff); ajStrAssignS(dbname, oname); if(ajStrGetCharFirst(oname)=='@') ajStrCutStart(dbname, 1); if(!ajStrSuffixS(*dbname, suffix)) { ajStrDel(&suffix); return; } ajStrCutEnd(dbname, ajStrGetLen(suffix)); ajStrDel(&suffix); return; }
static void jaspscan_ParseInput(const AjPStr dir, const AjPStr jaspdir, const AjPStr mats, const AjPStr excl, ajuint *recurs, AjPList ret) { ajuint nm = 0; ajuint ne = 0; AjPStr *carr = NULL; AjPStr *earr = NULL; AjPFile inf = NULL; AjPStr line = NULL; AjPStr comm = NULL; AjPStr val = NULL; ajuint i; ajuint j; char c; ajuint rlen = 0; if(*recurs > JASPSCAN_RECURS) ajFatal("Too many recursion levels in matrix list files"); line = ajStrNew(); comm = ajStrNew(); if(mats) { nm = ajArrCommaList(mats,&carr); for(i=0; i < nm; ++i) { if(ajStrGetCharFirst(carr[i]) != '@') ajStrFmtUpper(&carr[i]); if(ajStrMatchC(carr[i],"ALL")) { jaspscan_GetFileList(dir, jaspdir, "*", ret); ajListSortUnique(ret, ajStrVcmp, jaspscan_strdel); } else if(ajStrGetCharFirst(carr[i]) == '@') { ajStrTrimStartC(&carr[i],"@"); inf = ajFileNewInNameS(carr[i]); if(!inf) ajFatal("Cannot open list file %S",carr[i]); while(ajReadlineTrim(inf,&line)) { ajStrRemoveWhite(&line); c = ajStrGetCharFirst(line); if(c == '#' || c== '!') continue; if(ajStrGetLen(comm)) ajStrAppendC(&comm,","); ajStrFmtUpper(&line); ajStrAppendS(&comm,line); } *recurs += 1; jaspscan_ParseInput(dir,jaspdir,comm,NULL,recurs,ret); *recurs -= 1; ajListSortUnique(ret, ajStrVcmp, jaspscan_strdel); ajFileClose(&inf); } else { jaspscan_GetFileList(dir,jaspdir,ajStrGetPtr(carr[i]),ret); ajListSortUnique(ret, ajStrVcmp, jaspscan_strdel); } } for(i=0; i < nm; ++i) ajStrDel(&carr[i]); AJFREE(carr); } if(excl) { ne = ajArrCommaList(excl,&earr); for(i=0; i < ne; ++i) { if(ajStrGetCharFirst(earr[i]) != '@') ajStrFmtUpper(&earr[i]); if(ajStrGetCharFirst(earr[i]) == '@') { ajStrTrimStartC(&earr[i],"@"); inf = ajFileNewInNameS(earr[i]); if(!inf) ajFatal("Cannot open list file %S",earr[i]); while(ajReadlineTrim(inf,&line)) { ajStrRemoveWhite(&line); c = ajStrGetCharFirst(line); if(c == '#' || c== '!') continue; if(ajStrGetLen(comm)) ajStrAppendC(&comm,","); ajStrFmtUpper(&line); ajStrAppendS(&comm,line); } *recurs += 1; jaspscan_ParseInput(dir,jaspdir,NULL,comm,recurs,ret); *recurs -= 1; ajListSortUnique(ret, ajStrVcmp, jaspscan_strdel); ajFileClose(&inf); } else { ajStrAssignS(&line,earr[i]); ajStrAppendC(&line,J_EXT); rlen = ajListGetLength(ret); for(j=0; j < rlen; ++j) { ajListPop(ret,(void **)&val); if(ajStrSuffixS(val,line)) ajStrDel(&val); else ajListPushAppend(ret,(void *)val); } } } for(i=0; i < ne; ++i) ajStrDel(&earr[i]); AJFREE(earr); } ajStrDel(&line); ajStrDel(&comm); return; }
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; }
static void jaspscan_coretoken(PJspmat info, const AjPStr str) { const char *p; const char *q; AjPStr key = NULL; AjPStr value = NULL; value = ajStrNew(); key = ajStrNew(); p = ajStrGetPtr(str); q = p; while(*q != '"' && *q != '\t') ++q; --q; ajStrAssignSubC(&key,p,0,q-p-1); while(*q != '"') ++q; if(*(q+1) != '"') { p = q + 1; ++q; while(*q != '"') ++q; ajStrAssignSubC(&value,p,0,q-p-1); if(ajStrMatchC(key,"acc")) ajStrAssignS(&info->protseq,value); if(ajStrMatchC(key,"medline")) ajStrAssignS(&info->pmid,value); if(ajStrMatchC(key,"species")) ajStrAssignS(&info->species,value); if(ajStrMatchC(key,"sysgroup")) ajStrAssignS(&info->sgroup,value); if(ajStrMatchC(key,"total_ic")) ajStrAssignS(&info->content,value); if(ajStrMatchC(key,"type")) ajStrAssignS(&info->exp,value); if(ajStrMatchC(key,"included_models")) ajStrAssignS(&info->models,value); if(ajStrMatchC(key,"MCS")) ajStrAssignS(&info->mcs,value); if(ajStrMatchC(key,"jaspar")) ajStrAssignS(&info->jaspar,value); if(ajStrMatchC(key,"transfac")) ajStrAssignS(&info->transfac,value); if(ajStrMatchC(key,"Description")) ajStrAssignS(&info->desc,value); if(ajStrMatchC(key,"description")) ajStrAssignS(&info->desc,value); if(ajStrMatchC(key,"comment")) ajStrAssignS(&info->comment,value); if(ajStrMatchC(key,"End relative to TSS")) ajStrAssignS(&info->erttss,value); if(ajStrMatchC(key,"Start relative to TSS")) ajStrAssignS(&info->srttss,value); if(ajStrMatchC(key,"consensus")) ajStrAssignS(&info->consens,value); } ajStrDel(&key); ajStrDel(&value); return; }
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; }
static void remap_NoCutList(AjPFile outfile, const AjPTable hittable, AjBool html, const AjPStr enzymes, AjBool blunt, AjBool sticky, ajuint sitelen, AjBool commercial, AjBool ambiguity, AjBool limit, const AjPTable retable) { /* for iterating over hittable */ PValue value; void **keyarray = NULL; /* array for table */ void **valarray = NULL; /* array for table */ ajint i; /* list of enzymes that cut */ AjPList cutlist; AjIList citer; /* iterator for cutlist */ AjPStr cutname = NULL; AjBool found; /* for parsing value->iso string */ AjPStrTok tok; char tokens[] = " ,"; AjPStr code = NULL; const char *p; /* for reading in enzymes names */ AjPFile enzfile = NULL; AjPStr *ea; ajint ne; /* number of enzymes */ AjBool isall = ajTrue; /* list of enzymes that don't cut */ AjPList nocutlist; AjIList niter; /* iterator for nocutlist */ AjPStr nocutname = NULL; /* count of rejected enzymes not matching criteria */ ajint rejected_count = 0; EmbPPatRestrict enz; /* for renaming preferred isoschizomers */ AjPList newlist; /* ** ** Make a list of enzymes('cutlist') that hit ** including the isoschizomer names ** */ ajDebug("Make a list of all enzymes that cut\n"); cutlist = ajListstrNew(); nocutlist = ajListstrNew(); ajTableToarrayKeysValues(hittable, &keyarray, &valarray); for(i = 0; keyarray[i]; i++) { value = (PValue) valarray[i]; cutname = ajStrNew(); ajStrAssignRef(&cutname, keyarray[i]); ajListstrPushAppend(cutlist, cutname); /* Add to cutlist all isoschizomers of enzymes that cut */ ajDebug("Add to cutlist all isoschizomers of enzymes that cut\n"); /* start token to parse isoschizomers names */ tok = ajStrTokenNewC(value->iso, tokens); while(ajStrTokenNextParseC(&tok, tokens, &code)) { cutname = ajStrNew(); ajStrAssignS(&cutname, code); ajListstrPushAppend(cutlist, cutname); } ajStrTokenDel(&tok); } ajStrDel(&code); AJFREE(keyarray); AJFREE(valarray); /* ** Read in list of enzymes ('nocutlist') - either all or ** the input enzyme list. ** Exclude those that don't match the selection criteria - count these. */ ajDebug("Read in a list of all input enzyme names\n"); ne = 0; if(!enzymes) isall = ajTrue; else { /* get input list of enzymes into ea[] */ ne = ajArrCommaList(enzymes, &ea); if(ajStrMatchCaseC(ea[0], "all")) isall = ajTrue; else { isall = ajFalse; for(i=0; i<ne; ++i) ajStrRemoveWhite(&ea[i]); } } enzfile = ajDatafileNewInNameC(ENZDATA); /* push all enzyme names without the required criteria onto nocutlist */ enz = embPatRestrictNew(); while(!ajFileIsEof(enzfile)) { if(!embPatRestrictReadEntry(enz, enzfile)) continue; /* ** If user entered explicit enzyme list, then check to see if ** this is one of that explicit list */ if(!isall) { found = AJFALSE; for(i=0; i<ne; ++i) if(ajStrMatchCaseS(ea[i], enz->cod)) { found = AJTRUE; break; } if(!found) /* not in the explicit list */ continue; ajDebug("RE %S is in the input explicit list of REs\n", enz->cod); } /* ignore ncuts==0 as they are unknown */ if(!enz->ncuts) { /* number of cut positions */ ajDebug("RE %S has an unknown number of cut positions\n", enz->cod); continue; } ajDebug("RE %S has a known number of cut sites\n", enz->cod); if(enz->len < sitelen) { /* recognition site length */ ajDebug("RE %S does not have a long enough recognition site\n", enz->cod); rejected_count++; continue; } if(!blunt && enz->blunt) { /* blunt/sticky */ ajDebug("RE %S is blunt\n", enz->cod); rejected_count++; continue; } if(!sticky && !enz->blunt) { /* blunt/sticky */ ajDebug("RE %S is sticky\n", enz->cod); rejected_count++; continue; } /* commercially available enzymes have uppercase patterns */ p = ajStrGetPtr(enz->pat); /* ** The -commercial qualifier is only used if we are searching ** through 'all' of the REBASE database - if we have specified an ** explicit list of enzymes then they are searched for whether or ** not they are commercially available */ if((*p >= 'a' && *p <= 'z') && commercial && isall) { ajDebug("RE %S is not commercial\n", enz->cod); rejected_count++; continue; } if(!ambiguity && remap_Ambiguous(enz->pat)) { ajDebug("RE %S is ambiguous\n", enz->cod); rejected_count++; continue; } ajDebug("RE %S matches all required criteria\n", enz->cod); code = ajStrNew(); ajStrAssignS(&code, enz->cod); ajListstrPushAppend(nocutlist, code); } embPatRestrictDel(&enz); ajFileClose(&enzfile); for(i=0; i<ne; ++i) if(ea[i]) ajStrDel(&ea[i]); if(ne) AJFREE(ea); /* ** Change names of enzymes in the non-cutter list ** to that of preferred (prototype) ** enzyme name so that the isoschizomers of cutters ** will be removed from the ** non-cutter list in the next bit. ** Remove duplicate prototype names. */ if(limit) { newlist = ajListstrNew(); remap_RenamePreferred(nocutlist, retable, newlist); ajListstrFreeData(&nocutlist); nocutlist = newlist; ajListSortUnique(nocutlist, remap_cmpcase, remap_strdel); } /* ** Iterate through the list of input enzymes removing those that are in ** the cutlist. */ ajDebug("Remove from the nocutlist all enzymes and isoschizomers " "that cut\n"); /* ** This steps down both lists at the same time, comparing names and ** iterating to the next name in whichever list whose name compares ** alphabetically before the other. Where a match is found, the ** nocutlist item is deleted. */ ajListSort(nocutlist, remap_cmpcase); ajListSort(cutlist, remap_cmpcase); citer = ajListIterNewread(cutlist); niter = ajListIterNew(nocutlist); /* while((cutname = (AjPStr)ajListIterGet(citer)) != NULL) ajDebug("dbg cutname = %S\n", cutname); */ nocutname = (AjPStr)ajListIterGet(niter); cutname = (AjPStr)ajListIterGet(citer); ajDebug("initial cutname, nocutname: '%S' '%S'\n", cutname, nocutname); while(nocutname != NULL && cutname != NULL) { i = ajStrCmpCaseS(cutname, nocutname); ajDebug("compare cutname, nocutname: %S %S ", cutname, nocutname); ajDebug("ajStrCmpCase=%d\n", i); if(i == 0) { /* match - so remove from nocutlist */ ajDebug("ajListstrRemove %S\n", nocutname); ajListstrIterRemove(niter); nocutname = (AjPStr)ajListIterGet(niter); /* ** Don't increment the cutname list pointer here ** - there may be more than one entry in the nocutname ** list with the same name because we have converted ** isoschizomers to their preferred name */ /* cutname = (AjPStr)ajListIterGet(citer); */ } else if(i == -1) /* cutlist name sorts before nocutlist name */ cutname = (AjPStr)ajListIterGet(citer); else if(i == 1) /* nocutlist name sorts before cutlist name */ nocutname = (AjPStr)ajListIterGet(niter); } ajListIterDel(&citer); ajListIterDel(&niter); ajListstrFreeData(&cutlist); /* Print the resulting list of those that do not cut*/ ajDebug("Print out the list\n"); /* print the title */ if(html) ajFmtPrintF(outfile, "<H2>"); ajFmtPrintF(outfile, "\n\n# Enzymes that do not cut\n\n"); if(html) ajFmtPrintF(outfile, "</H2>\n"); if(html) ajFmtPrintF(outfile, "<PRE>"); /* ajListSort(nocutlist, ajStrVcmp);*/ niter = ajListIterNewread(nocutlist); i = 0; while((nocutname = (AjPStr)ajListIterGet(niter)) != NULL) { ajFmtPrintF(outfile, "%-10S", nocutname); /* new line after every 7 names printed */ if(i++ == 7) { ajFmtPrintF(outfile, "\n"); i = 0; } } ajListIterDel(&niter); /* end the output */ ajFmtPrintF(outfile, "\n"); if(html) {ajFmtPrintF(outfile, "</PRE>\n");} /* ** Print the count of rejected enzymes ** N.B. This is the count of ALL rejected enzymes including all ** isoschizomers */ if(html) ajFmtPrintF(outfile, "<H2>"); ajFmtPrintF(outfile, "\n\n# No. of cutting enzymes which do not match the\n" "# SITELEN, BLUNT, STICKY, COMMERCIAL, AMBIGUOUS criteria\n\n"); if(html) ajFmtPrintF(outfile, "</H2>\n"); ajFmtPrintF(outfile, "%d\n", rejected_count); ajDebug("Tidy up\n"); ajListstrFreeData(&nocutlist); ajListstrFreeData(&cutlist); return; }
static void remap_RestrictPreferred(const AjPList l, const AjPTable t) { AjIList iter = NULL; EmbPMatMatch m = NULL; const AjPStr value = NULL; AjPStr newiso = NULL; AjBool found; /* name found in isoschizomer list */ /* for parsing value->iso string */ AjPStrTok tok = NULL; char tokens[] = " ,"; AjPStr code = NULL; iter = ajListIterNewread(l); while((m = (EmbPMatMatch)ajListIterGet(iter))) { found = ajFalse; /* get prototype name */ value = ajTableFetchS(t, m->cod); if(value) { ajStrAssignC(&newiso, ""); /* parse isoschizomer names from m->iso */ ajStrTokenDel(&tok); tok = ajStrTokenNewC(m->iso, tokens); while(ajStrTokenNextParseC(&tok, tokens, &code)) { if(ajStrGetLen(newiso) > 0) ajStrAppendC(&newiso, ","); /* found the prototype name? */ if(!ajStrCmpCaseS(code, value)) { ajStrAppendS(&newiso, m->cod); found = ajTrue; } else ajStrAppendS(&newiso, code); } ajStrTokenDel(&tok); /* if the name was not replaced, then add it in now */ if(!found) { if(ajStrGetLen(newiso) > 0) ajStrAppendC(&newiso, ","); ajStrAppendS(&newiso, m->cod); } ajDebug("RE: %S -> %S iso=%S newiso=%S\n", m->cod, value, m->iso, newiso); /* replace the old iso string with the new one */ ajStrAssignS(&m->iso, newiso); /* rename the enzyme to the prototype name */ ajStrAssignS(&m->cod, value); } } ajListIterDel(&iter); ajStrDel(&newiso); ajStrDel(&code); ajStrTokenDel(&tok); return; }
int main(int argc, char *argv[]) { embInitPV("gseqinfo", argc, argv, "GEMBASSY", "1.0.1"); struct soap soap; AjPSeqall seqall; AjPSeq seq; AjPStr inseq = NULL; AjPStr seqid = NULL; AjPStr tmp = NULL; AjPStr parse = NULL; AjPStr numA = NULL; AjPStr numT = NULL; AjPStr numG = NULL; AjPStr numC = NULL; AjPStrTok handle = NULL; ajint n; char *in0; char *result; AjBool show = 0; AjPFile outf = NULL; seqall = ajAcdGetSeqall("sequence"); outf = ajAcdGetOutfile("outfile"); while(ajSeqallNext(seqall, &seq)) { soap_init(&soap); inseq = NULL; ajStrAppendC(&inseq, ">"); ajStrAppendS(&inseq, ajSeqGetNameS(seq)); ajStrAppendC(&inseq, "\n"); ajStrAppendS(&inseq, ajSeqGetSeqS(seq)); ajStrAssignS(&seqid, ajSeqGetAccS(seq)); in0 = ajCharNewS(inseq); if(soap_call_ns1__seqinfo( &soap, NULL, NULL, in0, &result ) == SOAP_OK) { tmp = ajStrNewC(result); ajStrExchangeCC(&tmp, "<", "\n"); ajStrExchangeCC(&tmp, ">", "\n"); handle = ajStrTokenNewC(tmp, "\n"); while(ajStrTokenNextParse(handle, &parse)) { if(ajStrIsInt(parse)) if(!numA) numA = ajStrNewS(parse); else if(!numT) numT = ajStrNewS(parse); else if(!numG) numG = ajStrNewS(parse); else if(!numC) numC = ajStrNewS(parse); } if(show) ajFmtPrint("Sequence: %S A: %S T: %S G: %S C: %S\n", seqid, numA, numT, numG, numC); else ajFmtPrintF(outf, "Sequence: %S A: %S T: %S G: %S C: %S\n", seqid, numA, numT, numG, numC); } else { soap_print_fault(&soap, stderr); } soap_destroy(&soap); soap_end(&soap); soap_done(&soap); AJFREE(in0); ajStrDel(&inseq); } ajSeqallDel(&seqall); ajSeqDel(&seq); ajStrDel(&seqid); embExit(); return 0; }
int main(int argc, char *argv[]) { embInitPV("gp2", argc, argv, "GEMBASSY", "1.0.1"); AjPSeqall seqall; AjPSeq seq; AjPStr inseq = NULL; AjBool accid = ajFalse; AjPStr restid = NULL; AjPStr seqid = NULL; AjPStr base = NULL; AjPStr url = NULL; AjPFile tmpfile = NULL; AjPStr tmpname = NULL; AjPFile outf = NULL; seqall = ajAcdGetSeqall("sequence"); accid = ajAcdGetBoolean("accid"); outf = ajAcdGetOutfile("outfile"); base = ajStrNewC("rest.g-language.org"); gAssignUniqueName(&tmpname); while(ajSeqallNext(seqall, &seq)) { inseq = NULL; if(!accid) { if(gFormatGenbank(seq, &inseq)) { tmpfile = ajFileNewOutNameS(tmpname); if(!tmpfile) { ajDie("Output file (%S) open error\n", tmpname); } ajFmtPrintF(tmpfile, "%S", inseq); ajFileClose(&tmpfile); ajFmtPrintS(&url, "http://%S/upload/upl.pl", base); gFilePostSS(url, tmpname, &restid); ajStrDel(&url); ajSysFileUnlinkS(tmpname); } else { ajDie("Sequence does not have features\n" "Proceeding with sequence accession ID\n"); accid = ajTrue; } } if(accid) { ajStrAssignS(&restid, ajSeqGetAccS(seq)); if(!ajStrGetLen(restid)) { ajStrAssignS(&restid, ajSeqGetNameS(seq)); } if(!ajStrGetLen(restid)) { ajDie("No valid header information\n"); } } ajStrAssignS(&seqid, ajSeqGetAccS(seq)); url = ajStrNew(); ajFmtPrintS(&url, "http://%S/%S/P2/output=f/tag=gene", base, restid); ajFmtPrintF(outf, "Sequence: %S\n", seqid); if(!gFileOutURLS(url, &outf)) { ajDie("Failed to download result from:\n%S\n", url); } ajStrDel(&url); ajStrDel(&inseq); } ajFileClose(&outf); ajSeqallDel(&seqall); ajSeqDel(&seq); ajStrDel(&seqid); embExit(); return 0; }
/* @funcstatic sigscanlig_score_ligands_site ********************************* ** ** Writes score data for ligands (Lighit objects) from individual hits to ** signatures (Hit objects). Site score method is used. List of hit objects ** must be sorted by ligand type and site number. ** ** @param [r] hits [const AjPList] List of hit objects. ** @return [AjBool] True on success ** @@ ******************************************************************************/ AjPList sigscanlig_score_ligands_site(AjPList hits) { AjPList ret = NULL; AjIList iter = NULL; /* Iterator. */ EmbPHit hit = NULL; AjPStr prev_ligand = NULL; SigPLighit lighit = NULL; ajint prevsn = -1; /* Previous site number */ float score = 0.0; /* Score for current ligand */ ajint nhits = 0; /* No. of hits (patches) for current ligand. */ ajint nsites = 0; /* No. of sites for current ligand */ float score_site = 0.0; /* Score for this site. */ ajint patch_cnt = 0; /* No. of patches in current site. */ ret = ajListNew(); prev_ligand = ajStrNew(); iter = ajListIterNew(hits); /* Hits are already sorted by ligid & site number */ while((hit = (EmbPHit) ajListIterGet(iter))) { /* ajFmtPrint("Current hit: %S (ligid: %S, sn: %d) score: %f\n", hit->Acc, hit->Sig->Ligid, hit->Sig->sn, hit->Score); */ /* New site */ if(hit->Sig->sn != prevsn) { if(patch_cnt) score_site /= patch_cnt; score += score_site; patch_cnt = 0; score_site = 0; } /* New ligand */ if((!ajStrMatchS(hit->Sig->Ligid, prev_ligand))) { if(nsites) score /= nsites; if(lighit) { /* lighit->ns = snarr_siz; */ lighit->ns = nsites; lighit->np = nhits; lighit->score = score; ajStrAssignS(&lighit->ligid, prev_ligand); ajListPushAppend(ret, lighit); } lighit = sigscanlig_LighitNew(); nsites = 0; nhits=0; prevsn = -1; score = 0; } /* Increment count of sites and hits/patches (for current ligand) and patches (for current site) */ if(hit->Sig->sn != prevsn) nsites++; score_site += hit->Score; nhits++; patch_cnt++; ajStrAssignS(&prev_ligand, hit->Sig->Ligid); prevsn = hit->Sig->sn; } /* Process last hit */ if(patch_cnt) score_site /= patch_cnt; score += score_site; if(nsites) score /= nsites; if(lighit) { /* lighit->ns = snarr_siz; */ lighit->ns = nsites; lighit->np = nhits; lighit->score = score; ajStrAssignS(&lighit->ligid, prev_ligand); ajListPushAppend(ret, lighit); } ajListSort(ret, sigscanlig_MatchinvScore); ajListIterDel(&iter); ajStrDel(&prev_ligand); return ret; }
AjPList sigscanlig_score_ligands_patch(AjPList hits) { AjPList ret = NULL; AjIList iter = NULL; /* Iterator. */ EmbPHit hit = NULL; AjPStr prev_ligand = NULL; SigPLighit lighit = NULL; float score = 0.0; ajint nhits = 0; /* No. of hits (patches) for current ligand. */ ajint nsites = 0; /* No. of sites for current ligand. */ ajint prevsn = -1; /* Previous site number */ ret = ajListNew(); prev_ligand = ajStrNew(); iter = ajListIterNew(hits); while((hit = (EmbPHit) ajListIterGet(iter))) { /* New ligand */ if((!ajStrMatchS(hit->Sig->Ligid, prev_ligand))) { if(nhits) score /= nhits; if(lighit) { lighit->ns = nsites; lighit->np = nhits; lighit->score = score; ajStrAssignS(&lighit->ligid, prev_ligand); ajListPushAppend(ret, lighit); } lighit = sigscanlig_LighitNew(); nsites = 0; nhits=0; prevsn = -1; score = 0; } /* Increment count of sites and hits/patches (for current ligand) and patches (for current site) */ if(hit->Sig->sn != prevsn) nsites++; score+= hit->Score; nhits++; ajStrAssignS(&prev_ligand, hit->Sig->Ligid); prevsn = hit->Sig->sn; } /* Process last hit */ if(nhits) score /= nhits; if(lighit) { lighit->ns = nsites; lighit->np = nhits; lighit->score = score; ajStrAssignS(&lighit->ligid, prev_ligand); ajListPushAppend(ret, lighit); } ajListSort(ret, sigscanlig_MatchinvScore); ajListIterDel(&iter); ajStrDel(&prev_ligand); return ret; }
int main(int argc, char *argv[]) { embInitPV("gbaseinformationcontent", argc, argv, "GEMBASSY", "1.0.1"); AjPSeqall seqall; AjPSeq seq; AjPStr inseq = NULL; AjPStr position = 0; ajint PatLen = 0; ajint upstream = 0; ajint downstream = 0; AjBool accid = ajFalse; AjPStr restid = NULL; AjPStr seqid = NULL; AjPStr base = NULL; AjPStr url = NULL; AjPFile tmpfile = NULL; AjPStr tmpname = NULL; AjBool plot = 0; AjPFile outf = NULL; AjPFilebuff buff = NULL; AjPGraph mult = NULL; gPlotParams gpp; AjPStr title = NULL; seqall = ajAcdGetSeqall("sequence"); position = ajAcdGetSelectSingle("position"); PatLen = ajAcdGetInt("patlen"); upstream = ajAcdGetInt("upstream"); downstream = ajAcdGetInt("downstream"); accid = ajAcdGetBoolean("accid"); plot = ajAcdGetToggle("plot"); outf = ajAcdGetOutfile("outfile"); mult = ajAcdGetGraphxy("graph"); base = ajStrNewC("rest.g-language.org"); gAssignUniqueName(&tmpname); while(ajSeqallNext(seqall, &seq)) { inseq = NULL; if(!accid) { if(gFormatGenbank(seq, &inseq)) { gAssignUniqueName(&tmpname); tmpfile = ajFileNewOutNameS(tmpname); if(!tmpfile) { ajFmtError("Output file (%S) open error\n", tmpname); embExitBad(); } ajFmtPrintF(tmpfile, "%S", inseq); ajFileClose(&tmpfile); ajFmtPrintS(&url, "http://%S/upload/upl.pl", base); gFilePostSS(url, tmpname, &restid); ajStrDel(&url); ajSysFileUnlinkS(tmpname); } else { ajFmtError("Sequence does not have features\n" "Proceeding with sequence accession ID\n"); accid = ajTrue; } } if(accid) { ajStrAssignS(&seqid, ajSeqGetAccS(seq)); if(!ajStrGetLen(seqid)) { ajStrAssignS(&seqid, ajSeqGetNameS(seq)); } if(!ajStrGetLen(seqid)) { ajFmtError("No valid header information\n"); embExitBad(); } ajStrAssignS(&restid, seqid); } ajStrAssignS(&seqid, ajSeqGetAccS(seq)); url = ajStrNew(); ajFmtPrintS(&url, "http://%S/%S/base_information_content/position=%S/" "PatLen=%d/upstream=%d/downstream=%d/output=f/tag=gene", base, restid, position, PatLen, upstream, downstream); if(plot) { title = ajStrNew(); ajStrAppendC(&title, argv[0]); ajStrAppendC(&title, " of "); ajStrAppendS(&title, seqid); gpp.title = ajStrNewS(title); gpp.xlab = ajStrNewC("position"); gpp.ylab = ajStrNewC("information content"); if(!gFilebuffURLS(url, &buff)) { ajDie("File downloading error from:\n%S\n", url); } if(!gPlotFilebuff(buff, mult, &gpp)) { ajDie("Error in plotting\n"); } AJFREE(gpp.title); AJFREE(gpp.xlab); AJFREE(gpp.ylab); ajStrDel(&title); ajFilebuffDel(&buff); } else { ajFmtPrintF(outf, "Sequence: %S\n", seqid); if(!gFileOutURLS(url, &outf)) { ajDie("File downloading error from:\n%S\n", url); } } } ajFileClose(&outf); ajSeqallDel(&seqall); ajSeqDel(&seq); ajStrDel(&seqid); ajStrDel(&position); embExit(); return 0; }
int main(int argc, char *argv[]) { embInitPV("ggcskew", argc, argv, "GEMBASSY", "1.0.3"); AjPSeqall seqall; AjPSeq seq; AjPStr inseq = NULL; AjBool accid = ajFalse; AjPStr restid = NULL; AjPStr seqid = NULL; AjPStr base = NULL; AjPStr url = NULL; AjPStr tmpname = NULL; AjPSeqout tmpout = NULL; ajint window = 0; ajint slide = 0; AjBool cumulative = 0; AjBool at = 0; AjBool purine = 0; AjBool keto = 0; AjBool plot = 0; AjPFile outf = NULL; AjPFilebuff buff = NULL; AjPGraph mult = NULL; gPlotParams gpp; AjPStr title = NULL; seqall = ajAcdGetSeqall("sequence"); window = ajAcdGetInt("window"); slide = ajAcdGetInt("slide"); cumulative = ajAcdGetBoolean("cumulative"); at = ajAcdGetBoolean("at"); purine = ajAcdGetBoolean("purine"); keto = ajAcdGetBoolean("keto"); plot = ajAcdGetToggle("plot"); outf = ajAcdGetOutfile("outfile"); mult = ajAcdGetGraphxy("graph"); base = ajStrNewC("rest.g-language.org"); gAssignUniqueName(&tmpname); ajStrAppendC(&tmpname, ".fasta"); while(ajSeqallNext(seqall, &seq)) { tmpout = ajSeqoutNew(); if(!ajSeqoutOpenFilename(tmpout, tmpname)) { embExitBad(); } ajSeqoutSetFormatS(tmpout,ajStrNewC("fasta")); ajSeqoutWriteSeq(tmpout, seq); ajSeqoutClose(tmpout); ajSeqoutDel(&tmpout); ajFmtPrintS(&url, "http://%S/upload/upl.pl", base); gFilePostSS(url, tmpname, &restid); ajStrDel(&url); ajSysFileUnlinkS(tmpname); ajStrAssignS(&seqid, ajSeqGetAccS(seq)); if(ajStrGetLen(seqid) == 0) { ajStrAssignS(&seqid, ajSeqGetNameS(seq)); } if(ajStrGetLen(seqid) == 0) { ajWarn("No valid header information\n"); } url = ajStrNew(); ajFmtPrintS(&url, "http://%S/%S/gcskew/window=%d/slide=%d/cumulative=%d/" "at=%d/purine=%d/keto=%d/output=f/", base, restid, window, slide, cumulative, at, purine, keto); if(plot) { title = ajStrNew(); ajStrAppendC(&title, argv[0]); ajStrAppendC(&title, " of "); ajStrAppendS(&title, seqid); gpp.title = ajStrNewS(title); gpp.xlab = ajStrNewC("location"); gpp.ylab = ajStrNewC("GC skew"); if(!gFilebuffURLS(url, &buff)) { ajDie("File downloading error from:\n%S\n", url); } if(!gPlotFilebuff(buff, mult, &gpp)) { ajDie("Error in plotting\n"); } AJFREE(gpp.title); AJFREE(gpp.xlab); AJFREE(gpp.ylab); ajStrDel(&title); ajFilebuffDel(&buff); } else { ajFmtPrintF(outf, "Sequence: %S\n", seqid); if(!gFileOutURLS(url, &outf)) { ajDie("File downloading error from:\n%S\n", url); } } ajStrDel(&url); ajStrDel(&restid); ajStrDel(&seqid); } ajFileClose(&outf); ajSeqallDel(&seqall); ajSeqDel(&seq); ajStrDel(&base); embExit(); return 0; }
static void jaspscan_scan(const AjPStr seq, const ajuint begin, const AjPStr mfname, const char type, const float threshold, const AjBool both, AjPList hits) { PJsphits val = NULL; AjPStr mname = NULL; float **matrix = NULL; ajuint cols; ajuint i; ajuint rc; ajuint cc; ajuint limit; ajuint slen; const char *p; char schar; float sum = 0.; float rmax = 0.; float scorepc = 0.; float maxscore = 0.; cols = jaspscan_readmatrix(mfname, &matrix); maxscore = 0.; for(cc = 0; cc < cols; ++cc) { rmax = 0.; for(rc = 0; rc < 4; ++rc) rmax = (rmax > matrix[rc][cc]) ? rmax : matrix[rc][cc]; maxscore += rmax; } slen = ajStrGetLen(seq); limit = (slen - cols) + 1; if(limit <= 0) return; mname = ajStrNew(); ajStrAssignS(&mname,mfname); ajFilenameTrimPath(&mname); ajFilenameTrimExt(&mname); p = ajStrGetPtr(seq); for(i=0; i < limit; ++i) { sum = 0.; schar = p[i]; for(cc = 0; cc < cols; ++cc) { schar = p[i+cc]; if(schar == 'A') sum += matrix[0][cc]; else if(schar == 'C') sum += matrix[1][cc]; else if(schar == 'G') sum += matrix[2][cc]; else if(schar == 'T') sum += matrix[3][cc]; } scorepc = (sum * (float)100.) / maxscore; if(scorepc >= threshold) { val = jaspscan_hitsnew(); val->type = type; ajStrAssignS(&val->matname,mname); val->start = i + begin; val->end = val->start + cols - 1; val->score = sum; val->threshold = threshold; val->scorepc = scorepc; val->maxscore = maxscore; ajListPushAppend(hits,(void *)val); } } if(both) { jaspscan_CompMat(matrix, cols); p = ajStrGetPtr(seq); for(i=0; i < limit; ++i) { sum = 0.; schar = p[i]; for(cc = 0; cc < cols; ++cc) { schar = p[i+cc]; if(schar == 'A') sum += matrix[0][cc]; else if(schar == 'C') sum += matrix[1][cc]; else if(schar == 'G') sum += matrix[2][cc]; else if(schar == 'T') sum += matrix[3][cc]; } scorepc = (sum * (float)100.) / maxscore; if(scorepc >= threshold) { val = jaspscan_hitsnew(); val->type = type; ajStrAssignS(&val->matname,mname); val->end = i + begin; val->start = val->end + cols - 1; val->score = sum; val->threshold = threshold; val->scorepc = scorepc; val->maxscore = maxscore; ajListPushAppend(hits,(void *)val); } } } for(i = 0; i < 4; ++i) AJFREE(matrix[i]); AJFREE(matrix); ajStrDel(&mname); return; }
static AjPTable jaspscan_ReadFamList(const AjPStr jaspdir) { AjPTable ret = NULL; AjPStr lfile = NULL; AjPStr line = NULL; AjPStr key = NULL; AjPStr str = NULL; PJspmat info = NULL; AjPFile inf = NULL; const char *p = NULL; const char *q = NULL; lfile = ajStrNew(); line = ajStrNew(); str = ajStrNew(); ajFmtPrintS(&lfile,"%S%s%s",jaspdir,SLASH_STRING,J_LIST); inf = ajDatafileNewInNameS(lfile); if(!inf) ajFatal("Matrix list file %S not found",lfile); ret = ajTablestrNewLen(JASPTAB_GUESS); while(ajReadlineTrim(inf,&line)) { info = jaspscan_infonew(); ajFmtScanS(line,"%S%S",&info->id,&info->num); p = ajStrGetPtr(line); while(*p !='\t') ++p; ++p; while(*p != '\t') ++p; ++p; q = p; while(*q != '\t') ++q; ajStrAssignSubC(&info->name,p,0,q-p-1); ++q; p = q; while(*q != ';') ++q; ajStrAssignSubC(&info->klass,p,0,q-p-1); ajStrRemoveWhiteExcess(&info->klass); p = q+1; while(*p) { q = p; while(* q && *q != ';') ++q; ajStrAssignSubC(&str,p,0,q-p-1); ajStrRemoveWhiteExcess(&str); jaspscan_coretoken(info, str); if(!*q) p = q; else p = q +1; } key = ajStrNew(); ajStrAssignS(&key,info->id); ajTablePut(ret,(void *)key,(void *) info); } ajFileClose(&inf); ajStrDel(&lfile); ajStrDel(&line); ajStrDel(&str); return ret; }
int main(int argc, char *argv[]) { embInitPV("gdeltagcskew", argc, argv, "GEMBASSY", "1.0.3"); AjPSeqall seqall; AjPSeq seq; AjPStr inseq = NULL; AjBool at = 0; AjBool purine = 0; AjBool keto = 0; AjPStr method = 0; AjBool accid = ajFalse; AjPStr restid = NULL; AjPStr seqid = NULL; AjPStr base = NULL; AjPStr url = NULL; AjPFile tmpfile = NULL; AjPStr tmpname = NULL; AjPFilebuff tmp = NULL; AjPStr line = NULL; AjPFile outf = NULL; seqall = ajAcdGetSeqall("sequence"); at = ajAcdGetBoolean("at"); purine = ajAcdGetBoolean("purine"); keto = ajAcdGetBoolean("keto"); method = ajAcdGetSelectSingle("method"); accid = ajAcdGetBoolean("accid"); outf = ajAcdGetOutfile("outfile"); base = ajStrNewC("rest.g-language.org"); gAssignUniqueName(&tmpname); while(ajSeqallNext(seqall, &seq)) { inseq = NULL; if(!accid) { if(gFormatGenbank(seq, &inseq)) { tmpfile = ajFileNewOutNameS(tmpname); if(!tmpfile) { ajDie("Output file (%S) open error\n", tmpname); } ajFmtPrintF(tmpfile, "%S", inseq); ajFileClose(&tmpfile); ajFmtPrintS(&url, "http://%S/upload/upl.pl", base); gFilePostSS(url, tmpname, &restid); ajStrDel(&url); ajSysFileUnlinkS(tmpname); } else { ajWarn("Sequence does not have features\n" "Proceeding with sequence accession ID\n"); accid = ajTrue; } } ajStrAssignS(&seqid, ajSeqGetAccS(seq)); if(ajStrGetLen(seqid) == 0) { ajStrAssignS(&seqid, ajSeqGetNameS(seq)); } if(ajStrGetLen(seqid) == 0) { ajWarn("No valid header information\n"); } if(accid) { ajStrAssignS(&restid, seqid); if(ajStrGetLen(seqid) == 0) { ajDie("Cannot proceed without header with -accid\n"); } if(!gValID(seqid)) { ajDie("Invalid accession ID:%S, exiting\n", seqid); } } url = ajStrNew(); ajFmtPrintS(&url, "http://%S/%S/delta_gcskew/", base, restid); if(!gFilebuffURLS(url, &tmp)) { ajDie("Failed to download result from:\n%S\n", url); } ajBuffreadLine(tmp, &line); ajStrRemoveSetC(&line, "\n"); ajFmtPrintF(outf, "Sequence: %S DELTA-GCskew %S\n", seqid, line); ajStrDel(&url); ajStrDel(&restid); ajStrDel(&seqid); ajStrDel(&inseq); } ajFileClose(&outf); ajSeqallDel(&seqall); ajSeqDel(&seq); ajStrDel(&base); embExit(); return 0; }