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 const char* TimeFormat(const char *timefmt, AjBool* makeupper) { ajint i; AjBool ok = ajFalse; const char *format = NULL ; for(i=0; timeFormat[i].Name; i++) if(ajCharMatchCaseC(timefmt, timeFormat[i].Name)) { ok = ajTrue; break; } if(ok) { format = timeFormat[i].Format; *makeupper = timeFormat[i].Uppercase; } else { *makeupper = ajFalse; ajWarn("Unknown date/time format %s", timefmt); } return format; }
AjBool ajRegExecC(AjPRegexp prog, const char* str) { int startoffset = 0; int options = 0; int status = 0; status = pcre_exec(prog->pcre, prog->extra, str, strlen(str), startoffset, options, prog->ovector, 3*prog->ovecsize); if(status >= 0) { prog->orig = str; if(status == 0) ajWarn("ajRegExecC too many substrings"); return ajTrue; } if(status < -1) /* -1 is a simple fail to match */ { /* others are recursion limits etc. */ ajDebug("ajRegExecC returned unexpected status '%d'\n", status); prog->orig = str; /* needed for the trace */ ajRegTrace(prog); } prog->orig = NULL; return ajFalse; }
static void dastestSaveMappedFeatures(const AjPFeattable fttable, const AjPStr ffname, AjPFile outf, ajint maxfeatures) { AjPFeature feature = NULL; AjIList iterfts = NULL; AjPFeattabOut ftout = NULL; AjPFile ffile = NULL; AjPStr ffnamee = ajStrNew(); ajint i=0; if (fttable == NULL) { ajWarn("null feature table, %S", ffname); return; } ajFmtPrintS(&ffnamee, "%S.mapped.dasgff", ffname); ffile = ajFileNewOutNameS(ffnamee); iterfts = ajListIterNew(fttable->Features); ftout= ajFeattabOutNewCSF("gff3",NULL,"",ffile); ajFmtPrintF(outf, "Number of features %d\n", ajListGetLength(fttable->Features)); while(!ajListIterDone(iterfts) && i++ < maxfeatures) { feature = ajListIterGet(iterfts); ajFmtPrintF(outf, "feature id:%S orientation:%c start:%d stop:%d\n", feature->Label, feature->Strand, feature->Start, feature->End); } ajListIterDel(&iterfts); ajFeattableWriteDasgff(ftout, fttable); ajFeattabOutDel(&ftout); ajFileClose(&ffile); ajStrDel(&ffnamee); return; }
static void cacheNodeDel(const EnsPCache cache, CachePNode* Pnode) { if(!cache) return; if(!Pnode) return; if(!*Pnode) return; switch(cache->Type) { case ensECacheTypeNumeric: /* Delete AJAX unsigned integer key data. */ AJFREE((*Pnode)->Key); break; case ensECacheTypeAlphaNumeric: /* Delete AJAX String key data. */ ajStrDel((AjPStr *) &((*Pnode)->Key)); break; default: ajWarn("cacheNodeDel got unexpected Cache type %d.\n", cache->Type); } /* Delete the value data. */ if(cache->Delete && (*Pnode)->Value) (*cache->Delete)(&((*Pnode)->Value)); AJFREE(*Pnode); *Pnode = NULL; return; }
/* @func ajCall *************************************************************** ** ** Call a function by its name. If it does not exist then give ** an error message saying so. ** ** @param [r] name [const char*] name of the function to call. ** @param [v] [...] Optional arguments ** @return [void*] NULL if function call not found. ** @@ ******************************************************************************/ void* ajCall(const char *name, ...) { va_list args; CallFunc rec; CallFunc recold; void *retval = NULL; ajuint *icount; if(!callTable) { ajMessCrash("Calls to %s not registered. For graphics devices use " "ajGraphInit in main function first",name); return retval; } rec = (CallFunc) ajTableFetch(callTable, name); recold = (CallFunc) ajTableFetch(oldcallTable, name); if(rec) { va_start(args, name); retval = (*(rec))(name, args); va_end(args); } else if(recold) { icount = (ajuint*) ajTableFetch(oldcallCount, name); if(!(*icount)++) ajWarn("Obsolete graphics call '%s' called via ajCall", name); va_start(args, name); retval = (*(recold))(name, args); va_end(args); } else { ajMessCrash("Graphics call %s not found. " "Use ajGraphInit in main function first",name); } return retval; }
void ajAssemoutprintWiki(AjPFile outf) { ajint i = 0; ajint j = 0; AjPStr namestr = NULL; ajFmtPrintF(outf, "{| class=\"wikitable sortable\" border=\"2\"\n"); ajFmtPrintF(outf, "|-\n"); ajFmtPrintF(outf, "!Format!!" "class=\"unsortable\"|Description\n"); for(i=0; assemoutFormatDef[i].Name; i++) { ajFmtPrintF(outf, "|-\n"); ajStrAssignC(&namestr, assemoutFormatDef[i].Name); for(j=i+1; assemoutFormatDef[j].Name; j++) { if(assemoutFormatDef[j].Write == assemoutFormatDef[i].Write) { ajFmtPrintAppS(&namestr, "<br>%s", assemoutFormatDef[j].Name); ajWarn("Assembly output format '%s' same as '%s' " "but not alias", assemoutFormatDef[j].Name, assemoutFormatDef[i].Name); } } ajFmtPrintF(outf, "|%S||%s\n", namestr, assemoutFormatDef[i].Desc); } ajFmtPrintF(outf, "|}\n"); ajStrDel(&namestr); return; }
void ajCallTableRegister(AjPTable table, const char *name, void *func) { void *rec; char* keyname = NULL; if(!table) ajFatal("ajCallTableRegister called for undefined table with name '%s'", name); rec = ajTableFetch(table, name); /* does it exist already */ if(!rec) { keyname = ajCharNewC(name); ajTablePut(table, keyname, (void *) func); } else { ajWarn("ajCallTableRegister duplicate name '%s'", name); } return; }
AjBool ajRegExecall(AjPRegexp prog, const AjPStr str) { int startoffset = 0; int options = 0; if(!regDfaWorkspace) AJCNEW(regDfaWorkspace, regDfaWsCount); prog->matches = pcre_dfa_exec(prog->pcre, prog->extra, ajStrGetPtr(str), ajStrGetLen(str), startoffset, options, prog->ovector, 3*prog->ovecsize, regDfaWorkspace, regDfaWsCount); if(prog->matches >= 0) { prog->orig = ajStrGetPtr(str); if(prog->matches == 0) ajWarn("ajRegExecall too many substrings"); return ajTrue; } if(prog->matches < -1) /* -1 is a simple fail to match */ { /* others are recursion limits etc. */ ajDebug("ajRegExecall returned unexpected status '%d'\n", prog->matches); prog->orig = ajStrGetPtr(str); /* needed for the trace */ ajRegTrace(prog); } prog->orig = NULL; return ajFalse; }
int main(int argc, char *argv[]) { embInitPV("gbasezvalue", argc, argv, "GEMBASSY", "1.0.3"); AjPSeqall seqall; AjPSeq seq; AjPStr inseq = NULL; AjPStr position = NULL; ajint limit = 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; AjPFile outf = NULL; seqall = ajAcdGetSeqall("sequence"); position = ajAcdGetSelectSingle("position"); limit = ajAcdGetInt("limit"); PatLen = ajAcdGetInt("patlen"); upstream = ajAcdGetInt("upstream"); downstream = ajAcdGetInt("downstream"); 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/base_z_value/position=%S/PatLen=%d" "upstream=%d/downstream=%d/limit=%d/output=f/tag=gene", base, restid, position, PatLen, upstream, downstream, limit); ajFmtPrintF(outf, "Sequence: %S\n", seqid); if(!gFileOutURLS(url, &outf)) { ajDie("Failed to download result from:\n%S\n", url); } ajStrDel(&url); ajStrDel(&restid); ajStrDel(&seqid); ajStrDel(&inseq); } ajFileClose(&outf); ajSeqallDel(&seqall); ajSeqDel(&seq); ajStrDel(&base); ajStrDel(&position); embExit(); return 0; }
AjBool ajReadlinePos(AjPFile file, AjPStr* Pdest, ajlong* Ppos) { const char *cp; char *buff; ajint isize; ajint ilen; ajint jlen; ajint ipos; ajuint buffsize; size_t iread; const char* pnewline = NULL; MAJSTRDEL(Pdest); if(file->Buffsize) buffsize = file->Buffsize; else buffsize = ajFileValueBuffsize(); if(!file->Buff) ajStrAssignResC(&file->Buff, buffsize, ""); else if(buffsize > MAJSTRGETRES(file->Buff)) ajStrSetRes(&file->Buff, buffsize); if(MAJSTRGETUSE(file->Buff) == 1) buff = MAJSTRGETPTR(file->Buff); else buff = ajStrGetuniquePtr(&file->Buff); isize = MAJSTRGETRES(file->Buff); ilen = 0; ipos = 0; if(!file->fp) ajWarn("ajFileGets file not found"); *Ppos = file->Filepos; while(buff) { if(file->End) { ajStrAssignClear(Pdest); ajDebug("at EOF: File already read to end %F\n", file); return ajFalse; } #ifndef __ppc__ if(file->Readblock) { if(file->Blockpos >= file->Blocklen) { iread = fread(file->Readblock, 1, file->Blocksize, file->fp); if(!iread && ferror(file->fp)) ajFatal("fread failed with error:%d '%s'", ferror(file->fp), strerror(ferror(file->fp))); file->Blockpos = 0; file->Blocklen = iread; file->Readblock[iread] = '\0'; /*ajDebug("++ fread %u Ppos:%Ld\n", iread, *Ppos);*/ } if(file->Blockpos < file->Blocklen) { /* we know we have something in Readblock to process */ pnewline = strchr(&file->Readblock[file->Blockpos], '\n'); if(pnewline) jlen = pnewline - &file->Readblock[file->Blockpos] + 1; else jlen = file->Blocklen - file->Blockpos; /*ajDebug("ipos:%d jlen:%d pnewline:%p " "Readblock:%p blockpos:%d blocklen:%d\n", ipos, jlen, pnewline, file->Readblock, file->Blockpos, file->Blocklen);*/ memmove(&buff[ipos], &file->Readblock[file->Blockpos], jlen); buff[ipos+jlen]='\0'; cp = &buff[ipos]; file->Blockpos += jlen; } else { jlen = 0; cp = NULL; } } else { cp = fgets(&buff[ipos], isize, file->fp); jlen = strlen(&buff[ipos]); } #else cp = ajSysFuncFgets(&buff[ipos], isize, file->fp); jlen = strlen(&buff[ipos]); #endif if(!cp && !ipos) { if(feof(file->fp)) { file->End = ajTrue; ajStrAssignClear(Pdest); ajDebug("EOF ajFileGetsL file %F\n", file); return ajFalse; } else ajFatal("Error reading from file '%S'\n", ajFileGetNameS(file)); } ilen += jlen; file->Filepos += jlen; /* ** We need to read again if: ** We have read the entire buffer ** and we don't have a newline at the end ** (must be careful about that - we may just have read enough) */ if(((file->Readblock && !pnewline) ||(jlen == (isize-1))) && (buff[ilen-1] != '\n')) { MAJSTRSETVALIDLEN(&file->Buff, ilen); /* fix before resizing! */ ajStrSetResRound(&file->Buff, ilen+buffsize+1); /*ajDebug("more to do: jlen: %d ipos: %d isize: %d ilen: %d " "Size: %d\n", jlen, ipos, isize, ilen, ajStrGetRes(file->Buff));*/ ipos += jlen; buff = ajStrGetuniquePtr(&file->Buff); isize = ajStrGetRes(file->Buff) - ipos; /*ajDebug("expand to: ipos: %d isize: %d Size: %d\n", ipos, isize, ajStrGetRes(file>Buff));*/ } else buff = NULL; } MAJSTRSETVALIDLEN(&file->Buff, ilen); if (ajStrGetCharLast(file->Buff) != '\n') { /*ajDebug("Appending missing newline to '%S'\n", file->Buff);*/ ajStrAppendK(&file->Buff, '\n'); } ajStrAssignRef(Pdest, file->Buff); /* if(file->Readblock) ajDebug("ajFileGetsL done blocklen:%d blockpos:%d readlen:%u\n", file->Blocklen, file->Blockpos, ajStrGetLen(file->Buff)); */ return ajTrue; }
void embIepCompC(const char *s, ajint amino, ajint carboxyl, ajint sscount, ajint modlysine, ajint *c) { ajint i; ajint j; const char *p; for(i=0;i<EMBIEPSIZE;++i) c[i]=0; p=s; while(*p) { ++c[ajBasecodeToInt(ajSysCastItoc(toupper((ajint)*p)))]; ++p; } if(c[1]) /* B = D or N use Dayhoff freq */ { j = (int) (0.5 + ((float)c[1]) * 5.5 / 9.8); c[3] += j; c[13] += c[1] - j; ajDebug("embIepCompC B:%d => D:%d N:%d\n", c[1], j, c[1]-j); c[1] = 0; } if(c[25]) /* Z = E or Q use Dayhoff freq */ { j = (int) (0.5 + ((float)c[25]) * 6.0 / 9.9); c[4] += j; c[16] += c[25] - j; ajDebug("embIepCompC Z:%d => E:%d Q:%d\n", c[25], j, c[25]-j); c[25] = 0; } c[EMBIEPAMINO] = amino; c[EMBIEPCARBOXYL] = carboxyl; if (sscount > 0) { if(c[EMBIEPCYSTEINE] < 2*sscount) { ajWarn("embIepCompC %d disulphides but only %d cysteines\n", sscount, c[EMBIEPCYSTEINE]+2*sscount); c[EMBIEPCYSTEINE] = 0; } else { c[EMBIEPCYSTEINE] -= 2*sscount; } } if (modlysine > 0) { if(c[EMBIEPLYSINE] < modlysine) { ajWarn("embIepCompC %d modified lysines but only %d lysines\n", sscount, c[EMBIEPLYSINE]); c[EMBIEPLYSINE] = 0; } else { c[EMBIEPLYSINE] -= modlysine; } } return; }
int main(int argc, char **argv) { AjPDasServer server = NULL; AjPDasSource source = NULL; AjPDasSegment segment = NULL; AjPStr host = NULL; AjPStr path = NULL; AjPFile outf = NULL; ajint port = 80; AjBool sequencesourcesonly; AjBool entrypoints; AjBool showtestqueries; AjBool runtestqueries = ajTrue; AjBool quickexit = ajFalse; ajint itest=0; ajint j=0; ajint maxtests=0; ajint maxfeatures=0; ajint maxsegments=0; AjIList iter = NULL; AjIList coordsi = NULL; AjIList itereps = NULL; AjPFilebuff buff = NULL; AjPUrlref uo = NULL; AjPList segments = NULL; AjPStr ffname = NULL; AjPStr url = NULL; AjPStr dbhttpver = ajStrNew(); AjPStr dbname = ajStrNew(); AjPStr dbproxy = ajStrNew(); AjPStr servername = NULL; AjPTable titlecount = NULL; const ajuint* count; int k=0; embInit("dastest", argc, argv); host = ajAcdGetString("host"); path = ajAcdGetString("path"); port = ajAcdGetInt("port"); sequencesourcesonly = ajAcdGetBoolean("sequencesourcesonly"); entrypoints = ajAcdGetBoolean("entrypoints"); showtestqueries = ajAcdGetBoolean("showtestqueries"); runtestqueries = ajAcdGetBoolean("runtestqueries"); servername = ajAcdGetString("servername"); outf = ajAcdGetOutfile("outfile"); maxtests = ajAcdGetInt("maxtests"); maxfeatures = ajAcdGetInt("maxfeatures"); maxsegments = ajAcdGetInt("maxsegments"); server = ajDasServerNew(); if(runtestqueries) { url = ajStrNew(); if(!ajNamServer(servername)) { ajWarn("following das server is required to be defined " "for test queries..."); ajWarn("\nSERVER %S [\n" " type: \"sequence\"\n" " method: \"das\"\n" " url: \"http://%S%S\"\n" "]\n",servername, host,path); ajWarn("ignoring -runtestqueries option..."); runtestqueries = ajFalse; } else { ajNamSvrGetUrl(servername, &url); ajHttpUrlDeconstruct(url, &port, &host, &path); ajStrDel(&url); } } ajDasServerSethostS(server,host); ajDasServerSetport(server,port); if(ajStrGetCharLast(path)!='/') ajStrAppendK(&path,'/'); ajStrAppendC(&path,"sources"); ajDasServerSetpathS(server,path); ajFmtPrintF(outf,"host = %S\npath = %S\nport = %d\n", server->host, server->path, server->port); /* * TODO: stop using http-read but instead use * ajNamSvrListListDatabases(svrname, dbnames); */ buff = ajHttpRead(dbhttpver, dbname, dbproxy, host, port, path); if(!buff) ajExitAbort(); ajFilebuffHtmlNoheader(buff); ajDasParseRegistry(buff, server->sources); ajFmtPrintF(outf,"DAS sources and descriptions\n\n"); titlecount = dastestGetTitleCount(server); iter = ajListIterNew(server->sources); while(!ajListIterDone(iter) && !quickexit) { source = ajListIterGet(iter); if ((sequencesourcesonly && !source->sequence) || ajStrMatchC(source->title,"cath") || k++ <50) continue; ajFmtPrintF(outf,"%-30S %-50S\n%S\n",source->uri,source->title, source->description); if(entrypoints && source->entry_points) { uo = ajHttpUrlrefNew(); ajHttpUrlrefParseC(&uo, ajStrGetPtr(source->entry_points_uri)); if(ajStrGetLen(uo->Port)) ajStrToInt(uo->Port, &port); else port = 80; ajFilebuffDel(&buff); buff = ajHttpRead(dbhttpver, dbname, dbproxy, uo->Host, port, uo->Absolute); ajHttpUrlrefDel(&uo); if(!buff) continue; ajFilebuffHtmlNoheader(buff); segments = ajListNew(); ajDasParseEntrypoints(buff, segments); itereps = ajListIterNew(segments); ajFmtPrintF(outf, "Number of entry points %d\n", ajListGetLength(segments)); j=0; while(!ajListIterDone(itereps)) { segment = ajListIterGet(itereps); if (j++ < maxsegments) ajFmtPrintF(outf, "segment id:%S orientation:%S start:%d stop:%d\n", segment->id, segment->orientation, segment->start, segment->stop); ajDasSegmentDel(&segment); } ajListIterDel(&itereps); ajListFree(&segments); } if(showtestqueries || runtestqueries) { AjPDasCoordinate coord; coordsi = ajListIterNew(source->coordinates); while(!ajListIterDone(coordsi) && !quickexit) { coord = ajListIterGet(coordsi); ajDebug("coordinate uri:%S taxid:%S source:%S test_range:%S\n", coord->uri, coord->taxid, coord->source, coord->test_range); if(showtestqueries) { if(source->sequence) ajFmtPrintF(outf, "example/test entry = '%S?segment=%S'\n", source->sequence_query_uri,coord->test_range); if(source->features) ajFmtPrintF(outf, "example/test entry = '%S?segment=%S'\n", source->features_query_uri,coord->test_range); } if(runtestqueries) { AjPStr idqry = ajStrNew(); AjPStr entry = NULL; AjPSeq seq = NULL; ajint ibegin = 0; ajint iend = 0; AjPStr example = NULL; example = ajDasTestrangeParse(coord->test_range, &entry, &ibegin, &iend); if(ajStrGetLen(entry)) { count = ajTableFetchS(titlecount, source->title); dbname = ajDasSourceGetDBname(source, *count>1); if (source->features) { AjPStr qpath=NULL; uo = ajHttpUrlrefNew(); ajFmtPrintS(&idqry,"dasgff::%S:%S:%S", servername, dbname, entry); ajFmtPrintF(outf, "feature query: %S start:%d end:%d\n", idqry, ibegin, iend); ajHttpUrlrefParseC(&uo, ajStrGetPtr(source->features_query_uri)); ajHttpUrlrefSplitPort(uo); ajFmtPrintS(&qpath,"%S?segment=%S", uo->Absolute,entry); if(iend>0) ajFmtPrintAppS(&qpath,":%d,%d",ibegin, iend); if(ajStrGetLen(uo->Port)) ajStrToInt(uo->Port, &port); else port = 80; ajDebug("calling ajHttpRead to get the raw" " output; host:%S port:%d path:%S\n", uo->Host, port, qpath); ajFilebuffDel(&buff); buff = ajHttpRead(dbhttpver, dbname, dbproxy, uo->Host, port, qpath); if(buff) { AjPFeattable ft; ajFmtPrintS(&ffname, "%S.%S", source->uri, entry); ajFilebuffHtmlNoheader(buff); dastestSaveRawFeatures(buff, ffname); ajDebug("now using EMBOSS feature queries\n"); ft = dastestFeatureQuery(idqry, ibegin, iend); dastestSaveMappedFeatures(ft, ffname, outf, maxfeatures); ajStrDel(&ffname); ajFeattableDel(&ft); } ajHttpUrlrefDel(&uo); ajStrDel(&qpath); if(++itest>=maxtests) quickexit = ajTrue; } else if(source->sequence) { seq = ajSeqNewRes(iend-ibegin+1); ajFmtPrintS(&idqry,"%S:%S:%S", servername, dbname, entry); ajFmtPrintF(outf, "sequence query: %S start:%d end:%d\n", idqry, ibegin, iend); ajSeqGetFromUsaRange(idqry, ajFalse, ibegin, iend, seq); ajFmtPrintF(outf, "length of sequence returned: %d\n", ajSeqGetLen(seq)); if(ajSeqGetLen(seq)>0) ajFmtPrintF(outf, "sequence returned (first 100 bases):" " %-100.100s\n", ajSeqGetSeqC(seq)); ajSeqDel(&seq); } ajStrDel(&dbname); } ajStrDel(&entry); ajStrDel(&idqry); ajStrDel(&example); } } ajListIterDel(&coordsi); } } ajListIterDel(&iter); ajDasServerDel(&server); ajFilebuffDel(&buff); ajStrDel(&host); ajStrDel(&path); ajStrDel(&servername); ajStrDel(&dbhttpver); ajStrDel(&dbname); ajStrDel(&dbproxy); ajFileClose(&outf); ajTableDelValdel(&titlecount, ajMemFree); embExit(); return 0; }
int main(ajint argc, char **argv) { AjPList pdb_path =NULL; /* Path of pdb files */ AjPStr pdb_name =NULL; /* Name of pdb file */ AjPDirout ccf_path =NULL; /* Path of ccf files */ AjPStr ccf_name =NULL; /* Name of ccf file */ AjPStr pdbid =NULL; /* PDB code */ AjPStr pdbid_temp =NULL; /* PDB code */ AjBool ccfnaming =ajFalse; /* True == use the pdbid code to name the output file, False== use the name of the original pdb file*/ /* Mask non-amino acid groups in protein chains that do not contain a C-alpha atom. The group will not appear in either the CO or SQ records of the clean coordinate file */ AjBool camask =ajFalse; /* Mask amino acids in protein chains that do not contain a C-alpha atom. The amino acid will appear not appear in the CO record but will still be present in the SQ record of the clean coordinate file */ AjBool camask1 =ajFalse; /* Mask residues or groups in protein chains with a single atom only */ AjBool atommask =ajFalse; AjPStr temp =NULL; /* Temp string */ AjPStr msg =NULL; /* Error message */ AjPStr base_name =NULL; /* Name of pdb file w/o path or extension */ AjPFile pdb_inf =NULL; /* pdb input file pointer */ AjPFile ccf_outf =NULL; /* ccf output file pointer */ AjPFile logf =NULL; /* log file pointer*/ AjPPdb pdb =NULL; /* Pdb structure (for parsed data) */ ajint min_chain_size=0; /* Minimum length of a SEQRES chain for it to be parsed */ ajint max_mismatch=0; /* Max. no. residues to trim when checking for missing C-terminal SEQRES residues. */ ajint max_trim=0; /* Maximum number of permissible mismatches between the ATOM and SEQRES sequences */ ajint pos =0; /* Location of the file extension in the pdb file name */ /* THIS_DIAGNOSTIC tempstr=ajStrNew(); ajStrAssignC(&tempstr, "diagnostics"); tempfile=ajFileNewOutNameS(tempstr); ajStrDel(&tempstr);*/ /* Initialise strings */ ccf_name = ajStrNew(); pdb_name = ajStrNew(); temp = ajStrNew(); msg = ajStrNew(); base_name = ajStrNew(); pdbid = ajStrNew(); pdbid_temp = ajStrNew(); /* Read data from acd */ embInitPV("pdbparse",argc,argv,"STRUCTURE",VERSION); pdb_path = ajAcdGetDirlist("pdbpath"); ccf_path = ajAcdGetOutdir("ccfoutdir"); logf = ajAcdGetOutfile("logfile"); min_chain_size=ajAcdGetInt("chnsiz"); max_mismatch =ajAcdGetInt("maxmis"); max_trim =ajAcdGetInt("maxtrim"); ccfnaming = ajAcdGetBoolean("ccfnaming"); camask = ajAcdGetBoolean("camask"); camask1 = ajAcdGetBoolean("camaska"); atommask = ajAcdGetBoolean("atommask"); /* Check directories*/ /*Start of main application loop*/ while(ajListPop(pdb_path,(void **)&temp)) { ajFmtPrint("Processing %S\n", temp); ajFmtPrintF(logf, "%S\n", temp); /* Read pdb file*/ if((pdb_inf=ajFileNewInNameS(temp))==NULL) { ajFmtPrintS(&msg, "Could not open for reading %S ", temp); ajWarn(ajStrGetPtr(msg)); ajFmtPrintF(logf, "%-15s%S\n//\n", "FILE_OPEN", temp); ajStrDel(&temp); continue; } /* Assign pdb id code from file name */ ajStrAssignS(&pdbid, temp); ajFilenameTrimPathExt(&pdbid); if(MAJSTRGETLEN(pdbid)>4) { /* The file name is longer than expected (and probably contains a prefix). Take the last four characters to be the pdbid code */ ajStrAssignSubS(&pdbid_temp, pdbid, pos-4, pos-1); ajStrAssignS(&pdbid, pdbid_temp); } else if(MAJSTRGETLEN(pdbid)<4) ajFatal("Could not determine pdbid code from file name (%S)", pdbid); /* Parse pdb file and write pdb structure */ if(!(pdb=ajPdbReadRawNew(pdb_inf, pdbid, min_chain_size, max_mismatch, max_trim, camask, camask1, atommask, logf))) { ajFmtPrintS(&msg, "Clean coordinate file not generated for %S", temp); ajWarn(ajStrGetPtr(msg)); ajFmtPrintF(logf, "%-15s%S\n//\n", "NO_OUTPUT", temp); ajFileClose(&pdb_inf); ajStrDel(&temp); continue; } /* Open clean coordinate file for writing*/ if(ccfnaming) ajStrAssignS(&ccf_name, pdb->Pdb); else ajStrAssignS(&ccf_name, temp); ajStrFmtLower(&ccf_name); if(!(ccf_outf=ajFileNewOutNameDirS(ccf_name, ccf_path))) { ajFmtPrintS(&msg, "Could not open %S for writing", ccf_name); ajWarn(ajStrGetPtr(msg)); ajFmtPrintF(logf, "%-15s%S\n//\n", "FILE_OPEN", ccf_name); ajFileClose(&pdb_inf); ajPdbDel(&pdb); ajStrDel(&temp); continue; } /* Write pdb file */ if(!ajPdbWriteAll(ccf_outf, pdb)) { ajFmtPrintS(&msg, "Could not write file %S", ccf_name); ajWarn(ajStrGetPtr(msg)); ajFmtPrintF(logf, "%-15s%S\n//\n", "FILE_WRITE", ccf_name); ajFmtPrintS(&temp, "rm %S", ccf_name); ajFmtPrint("%S", temp); ajSysSystem(temp); ajFileClose(&pdb_inf); ajFileClose(&ccf_outf); ajPdbDel(&pdb); ajStrDel(&temp); continue; } /* Tidy up*/ ajFileClose(&pdb_inf); ajFileClose(&ccf_outf); ajPdbDel(&pdb); ajStrDel(&temp); ajFmtPrintF(logf, "//\n"); } /*End of main application loop*/ /*Tidy up */ ajListFree(&pdb_path); ajStrDel(&pdb_name); ajDiroutDel(&ccf_path); ajStrDel(&ccf_name); ajStrDel(&base_name); ajStrDel(&pdbid); ajStrDel(&pdbid_temp); ajStrDel(&msg); ajFileClose(&logf); /* DIAGNOSTIC ajFileClose(&tempfile); */ /* Return */ ajExit(); return 0; }
static void extractfeat_BeforeAfter(const AjPSeq seq, AjPStr * featstr, ajint firstpos, ajint lastpos, ajint before, ajint after, AjBool sense) { ajint start; ajint end; ajint featlen; ajint len; /* ** There is now: ** A complete set of joined features in featstr. ** 'sense' is FALSE if any feature was reverse sense (ignore 'compall' ** in this routine). ** 'firstpos' and 'lastpos' set to the first and last positions ** of the feature */ /* ** get start and end positions to truncate featstr at or to ** extract from seq */ /* do negative values of before/after */ featlen = ajStrGetLen(*featstr)-1; start = 0; end = featlen; if(before < 0) /* negative, so before end */ start = end + before+1; if(after < 0) /* negative, so after start */ end = start - after-1; if(end < start) { ajWarn("Extraction region end less than start for %S [%d-%d]", ajSeqGetNameS(seq), firstpos+1, lastpos+1); return; } /* ** truncate the featstr ** if start or end are past start/end of featstr, use 0 or featlen */ if(before < 0 || after < 0) { ajDebug("truncating featstr to %d-%d\n", start < 0 ? 0 : start, end>featlen ? featlen : end); ajDebug("featstr len=%d bases\n", ajStrGetLen(*featstr)); ajStrKeepRange(featstr, start<0 ? 0 : start, end>featlen ? featlen :end); ajDebug("featstr len=%d bases\n", ajStrGetLen(*featstr)); } /* ** add surrounding sequence if past 0/featlen when before/after ** are negative */ if(start < 0) { ajDebug("start < 0\n"); len = -start; if(sense) extractfeat_GetRegionPad(seq, featstr, firstpos-len, firstpos-1, sense, ajTrue); else extractfeat_GetRegionPad(seq, featstr, lastpos+1, lastpos+len, sense, ajTrue); } if(end > featlen) { /* NB use the original length of featstr */ ajDebug("end > featlen\n"); len = end-featlen; ajDebug("len=%d, end=%d\n", len, end); if(sense) extractfeat_GetRegionPad(seq, featstr, lastpos+1, lastpos+len, sense, ajFalse); else extractfeat_GetRegionPad(seq, featstr, firstpos-len, firstpos-1, sense, ajFalse); } /* add surrounding sequence if have positive values of before/after */ if(before > 0) { ajDebug("before > 0\n"); if(sense) { ajDebug("get Before firstpos=%d\n", firstpos); extractfeat_GetRegionPad(seq, featstr, firstpos-before, firstpos-1, sense, ajTrue); } else { ajDebug("get Before (reverse sense) lastpos=%d\n", lastpos); extractfeat_GetRegionPad(seq, featstr, lastpos+1, lastpos+before, sense, ajTrue); } } if(after > 0) { ajDebug("after > 0\n"); if(sense) { ajDebug("get After lastpos=%d\n", lastpos); extractfeat_GetRegionPad(seq, featstr, lastpos+1, lastpos+after, sense, ajFalse); } else { ajDebug("get After (reverse sense) firstpos=%d\n", firstpos); extractfeat_GetRegionPad(seq, featstr, firstpos-after, firstpos-1, sense, ajFalse); } } return; }
/* @funcstatic seqwords_TermsRead ********************************************* ** ** Read the next Terms object from a file in embl-like format. The search ** terms are modified with a leading and trailing space. ** ** @param [r] inf [AjPFile] Input file stream ** @param [w] thys [AjPTerms*] Terms object ** ** @return [AjBool] True on succcess ** @@ *****************************************************************************/ static AjBool seqwords_TermsRead(AjPFile inf, AjPTerms *thys) { AjPStr line =NULL; /* Line of text. */ AjPStr temp =NULL; AjPList list_terms =NULL; /* List of keywords for a scop node*/ AjBool ok =ajFalse; AjPStr type = NULL; /* Memory management */ (*thys)=seqwords_TermsNew(); list_terms = ajListstrNew(); line = ajStrNew(); type = ajStrNew(); /* Read first line. */ ok = ajReadlineTrim(inf,&line); while(ok && !ajStrPrefixC(line,"//")) { if(ajStrPrefixC(line,"XX")) { ok = ajReadlineTrim(inf,&line); continue; } else if(ajStrPrefixC(line,"TY")) { ajFmtScanS(line, "%*s %S", &type); if(ajStrMatchC(type, "SCOP")) (*thys)->Type = ajSCOP; else if(ajStrMatchC(type, "CATH")) (*thys)->Type = ajCATH; } else if(ajStrPrefixC(line,"CL")) { ajStrAssignC(&(*thys)->Class,ajStrGetPtr(line)+3); ajStrRemoveWhiteExcess(&(*thys)->Class); } else if(ajStrPrefixC(line,"AR")) { ajStrAssignC(&(*thys)->Architecture,ajStrGetPtr(line)+3); ajStrRemoveWhiteExcess(&(*thys)->Architecture); } else if(ajStrPrefixC(line,"TP")) { ajStrAssignC(&(*thys)->Topology,ajStrGetPtr(line)+3); ajStrRemoveWhiteExcess(&(*thys)->Topology); } else if(ajStrPrefixC(line,"FO")) { ajStrAssignC(&(*thys)->Fold,ajStrGetPtr(line)+3); while(ajReadlineTrim(inf,&line)) { if(ajStrPrefixC(line,"XX")) break; ajStrAppendC(&(*thys)->Fold,ajStrGetPtr(line)+3); } ajStrRemoveWhiteExcess(&(*thys)->Fold); } else if(ajStrPrefixC(line,"SF")) { ajStrAssignC(&(*thys)->Superfamily,ajStrGetPtr(line)+3); while(ajReadlineTrim(inf,&line)) { if(ajStrPrefixC(line,"XX")) break; ajStrAppendC(&(*thys)->Superfamily,ajStrGetPtr(line)+3); } ajStrRemoveWhiteExcess(&(*thys)->Superfamily); } else if(ajStrPrefixC(line,"FA")) { ajStrAssignC(&(*thys)->Family,ajStrGetPtr(line)+3); while(ajReadlineTrim(inf,&line)) { if(ajStrPrefixC(line,"XX")) break; ajStrAppendC(&(*thys)->Family,ajStrGetPtr(line)+3); } ajStrRemoveWhiteExcess(&(*thys)->Family); } else if(ajStrPrefixC(line,"TE")) { /* Copy and clean up term. */ temp = ajStrNew(); ajStrAssignC(&temp,ajStrGetPtr(line)+3); ajStrRemoveWhiteExcess(&temp); /* Append a leading and trailing space to search term*/ ajStrAppendK(&temp, ' '); ajStrInsertC(&temp, 0, " "); /* Add the current term to the list. */ ajListstrPush(list_terms,temp); } ok = ajReadlineTrim(inf,&line); } if(!ok) { /* Clean up. */ ajListstrFree(&list_terms); ajStrDel(&line); /* Return. */ return ajFalse; } /* Convert the AjPList of terms to array of AjPSeq's. */ if(!((*thys)->N=ajListstrToarray((AjPList)list_terms,&(*thys)->Keywords))) ajWarn("Zero sized list of terms passed into seqwords_TermsRead"); /* Clean up. Free the list (not the nodes!). */ ajListstrFree(&list_terms); ajStrDel(&line); ajStrDel(&type); return ajTrue; }
static AjBool dbiblast_parseSimple(const AjPStr line, AjPFile * alistfile, AjBool systemsort, AjPStr const * fields, ajint* maxFieldLen, ajuint* countfield, AjPStr* myid, AjPList* myfdl) { static AjPRegexp idexp = NULL; static AjPStr mytmpac = NULL; char* ac; static ajint numFields; static ajint accfield = -1; static AjBool reset = AJTRUE; if(!fields) { reset = ajTrue; accfield = -1; return ajFalse; } if(reset) { numFields = 0; while(fields[numFields]) { if(ajStrMatchCaseC(fields[numFields], "acc")) accfield=numFields; else if(!ajStrMatchCaseC(fields[numFields], "sv") && !ajStrMatchCaseC(fields[numFields], "des")) ajWarn("Simple ID parsing unknown field '%S' ignored", fields[numFields]); numFields++; } reset = ajFalse; } if(!idexp) idexp = ajRegCompC("^([^ ]+)( +([A-Za-z][A-Za-z0-9]+[0-9]))"); if(!ajRegExec(idexp, line)) return ajFalse; ajRegSubI(idexp, 1, myid); ajRegSubI(idexp, 3, &mytmpac); ajStrFmtUpper(myid); ajStrFmtUpper(&mytmpac); /* GCG mixes case on new SwissProt acnums */ if(accfield >= 0) { embDbiMaxlen(&mytmpac, &maxFieldLen[accfield]); countfield[accfield]++; if(systemsort) ajFmtPrintF(alistfile[accfield], "%S %S\n", *myid, mytmpac); else { ac = ajCharNewS(mytmpac); ajListPushAppend(myfdl[accfield], ac); } } ajDebug("parseSimple '%S' '%S'\n", *myid, mytmpac); return ajTrue; }
int main(int argc, char *argv[]) { embInitPV("ggeneskew", argc, argv, "GEMBASSY", "1.0.3"); AjPSeqall seqall; AjPSeq seq; AjPStr inseq = NULL; ajint window = 0; ajint slide = 0; AjBool cumulative = ajFalse; AjBool gc3 = ajFalse; AjPStr basetype = NULL; 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"); window = ajAcdGetInt("window"); slide = ajAcdGetInt("slide"); cumulative = ajAcdGetBoolean("cumulative"); gc3 = ajAcdGetBoolean("gctri"); basetype = ajAcdGetSelectSingle("base"); accid = ajAcdGetBoolean("accid"); plot = ajAcdGetToggle("plot"); outf = ajAcdGetOutfile("outfile"); mult = ajAcdGetGraphxy("graph"); if(ajStrMatchC(base, "none")) basetype = ajStrNewC(""); 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; } } 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/geneskew/window=%d/slide=%d/" "cumulative=%d/gc3=%d/base=%S/output=f/tag=gene", base, restid, window, slide, cumulative, gc3, basetype); if(plot) { title = ajStrNew(); ajStrAppendC(&title, argv[0]); ajStrAppendC(&title, " of "); ajStrAppendS(&title, seqid); gpp.title = ajStrNewS(title); gpp.xlab = ajStrNewC("gene skew"); gpp.ylab = ajStrNewC("bp"); 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); ajStrDel(&inseq); } ajFileClose(&outf); ajSeqallDel(&seqall); ajSeqDel(&seq); ajStrDel(&base); embExit(); return 0; }
EnsPCache ensCacheNew(AjEnum type, ajuint maxbytes, ajuint maxcount, ajuint maxsize, void* Freference(void* value), void Fdelete(void** value), ajuint Fsize(const void* value), void* Fread(const void* key), AjBool Fwrite(const void* value), AjBool synchron, const char *label) { AjBool debug = AJFALSE; EnsPCache cache = NULL; debug = ajDebugTest("ensCacheNew"); if(debug) ajDebug("ensCacheNew\n" " type %d\n" " maxbytes %u\n" " maxcount %u\n" " maxsize %u\n" " Freference %p\n" " Fdelete %p\n" " Fsize %p\n" " Fread %p\n" " Fwrite %p\n" " synchron '%B'\n" " label '%s'\n", type, maxbytes, maxcount, maxsize, Freference, Fdelete, Fsize, Fread, Fwrite, synchron, label); if((type < ensECacheTypeNumeric) || (type > ensECacheTypeAlphaNumeric)) ajFatal("ensCacheNew requires a valid type.\n"); if((!maxbytes) && (!maxcount)) ajFatal("ensCacheNew requires either a " "maximum bytes or maximum count limit.\n"); if(!maxsize) maxsize = maxbytes ? maxbytes / 10 + 1 : 0; if(maxbytes && (!maxsize)) ajFatal("ensCacheNew requires a maximum size limit, " "when a maximum bytes limit is set."); /* TODO: Find and set a sensible value here! */ if(debug) ajDebug("ensCacheNew maxbytes %u, maxcount %u, maxsize %u.\n", maxbytes, maxcount, maxsize); if(maxbytes && (maxbytes < 1000)) ajFatal("ensCacheNew cannot set a maximum bytes limit (%u) under " "1000, as each Cache Node requires %u bytes alone.", maxbytes, sizeof(CachePNode)); /* TODO: Find and set a sensible value here! */ if(maxsize && (maxsize < 3)) ajFatal("ensCacheNew cannot set a maximum size limit (%u) under " "3 bytes. maximum bytes %u maximum count %u.", maxsize, maxbytes, maxcount); /* ** Pointers to functions for automatic reading of data not yet in the ** cache and writing of data modified in cache are not mandatory. ** If not specified the cache will simply lack this functionality. ** However, the specification of a function deleting stale cache entries ** and a function calculating the size of value data are required. */ if(!(void*)Freference) ajFatal("ensCacheNew requires a referencing function."); if(!(void*)Fdelete) ajFatal("ensCacheNew requires a deletion function."); if(maxsize && (!(void*)Fsize)) ajFatal("ensCacheNew requires a memory sizing function " "when a maximum size limit has been defined."); if(!label) ajFatal("ensCacheNew requires a label."); AJNEW0(cache); cache->Label = ajStrNewC(label); cache->List = ajListNew(); switch(type) { case ensECacheTypeNumeric: cache->Table = ajTableNewFunctionLen(0, ensTableCmpUint, ensTableHashUint); break; case ensECacheTypeAlphaNumeric: cache->Table = ajTablestrNewLen(0); break; default: ajWarn("ensCacheNew got unexpected Cache type %d.\n", cache->Type); } cache->Reference = Freference; cache->Delete = Fdelete; cache->Size = Fsize; cache->Read = Fread; cache->Write = Fwrite; cache->Type = type; cache->Synchron = synchron; cache->MaxBytes = maxbytes; cache->MaxCount = maxcount; cache->MaxSize = maxsize; cache->Bytes = 0; cache->Count = 0; cache->Dropped = 0; cache->Removed = 0; cache->Stored = 0; cache->Hit = 0; cache->Miss = 0; return cache; }
int main(int argc, char *argv[]) { embInitPV("gcircularmap", argc, argv, "GEMBASSY", "1.0.1"); struct soap soap; struct ns1__circular_USCOREmapInputParams params; AjPSeqall seqall; AjPSeq seq; AjPStr inseq = NULL; AjPStr seqid = NULL; AjBool accid = ajFalse; AjPFile outf = NULL; AjPStr filename = NULL; AjPStr outfname = NULL; AjPStr format = NULL; ajint i; char *in0; char *result; seqall = ajAcdGetSeqall("sequence"); filename = ajAcdGetString("goutfile"); accid = ajAcdGetBoolean("accid"); format = ajAcdGetString("format"); params.gmap = 0; i = 0; while(ajSeqallNext(seqall, &seq)) { soap_init(&soap); soap.send_timeout = 0; soap.recv_timeout = 0; inseq = NULL; ajStrAssignS(&seqid, ajSeqGetAccS(seq)); if(!ajStrGetLen(seqid)) ajStrAssignS(&seqid, ajSeqGetNameS(seq)); if(!ajStrGetLen(seqid)) { ajWarn("No valid header information\n"); } if(accid || !gFormatGenbank(seq, &inseq)) { if(!accid) ajWarn("Sequence does not have features\n" "Proceeding with sequence accession ID:%S\n", seqid); if(!gValID(seqid)) { ajDie("Invalid accession ID:%S, exiting\n", seqid); } ajStrAssignS(&inseq, seqid); } in0 = ajCharNewS(inseq); if(soap_call_ns1__circular_USCOREmap( &soap, NULL, NULL, in0, ¶ms, &result ) == SOAP_OK) { ++i; outfname = ajStrNewS(ajFmtStr("%S.%d.%S", filename, i, format)); outf = ajFileNewOutNameS(outfname); if(!outf) { ajDie("File open error\n"); } if(!ajStrMatchC(format, "svg")) { if(!gHttpConvertC(result, &outf, ajStrNewC("svg"), format)) { ajDie("File downloading error from:\n%s\n", result); } else { ajFmtPrint("Created %S\n", outfname); } } else { if(!gHttpGetBinC(result, &outf)) { ajDie("File downloading error from:\n%s\n", result); } else { ajFmtPrint("Created %S\n", outfname); } } ajStrDel(&outfname); } 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); ajStrDel(&filename); embExit(); return 0; }
int main(int argc, char **argv) { const char *hmmfile; /* file to read HMMs from */ FILE *fp; /* output file handle */ HMMFILE *hmmfp; /* opened hmmfile for reading */ struct plan7_s *hmm; /* HMM to generate from */ int L; /* length of a sequence */ int i; /* counter over sequences */ char *ofile; /* output sequence file */ int nseq; /* number of seqs to sample */ int seed; /* random number generator seed */ int be_quiet; /* TRUE to silence header/footer */ int do_alignment; /* TRUE to output in aligned format */ int do_consensus; /* TRUE to do a single consensus seq */ AjBool ajselex; AjBool ajcons; AjPFile inf=NULL; AjPFile outf=NULL; AjPStr instr=NULL; AjPStr outstr=NULL; #ifdef MEMDEBUG unsigned long histid1, histid2, orig_size, current_size; orig_size = malloc_inuse(&histid1); fprintf(stderr, "[... memory debugging is ON ...]\n"); #endif /*********************************************** * Parse command line ***********************************************/ nseq = 10; be_quiet = FALSE; do_alignment = FALSE; do_consensus = FALSE; ofile = NULL; embInitPV("ohmmemit",argc,argv,"HMMER",VERSION); ajselex = ajAcdGetBoolean("selex"); ajcons = ajAcdGetBoolean("consensus"); nseq = ajAcdGetInt("number"); seed = ajAcdGetInt("seed"); inf = ajAcdGetInfile("infile"); outf = ajAcdGetOutfile("outfile"); if(!seed) seed = time ((time_t *) NULL); if(ajselex) do_alignment=TRUE; else do_alignment=FALSE; if(ajcons) do_consensus=TRUE; else do_consensus=FALSE; instr = ajStrNewC((char *)ajFileGetNameC(inf)); outstr = ajStrNewC((char *)ajFileGetNameC(outf)); hmmfile = ajStrGetPtr(instr); sre_srandom(seed); if (do_alignment && do_consensus) ajFatal("Sorry, -selex and -consensus are incompatible.\n"); if (nseq != 10 && do_consensus) ajWarn("-consensus overrides -number (# of sampled seqs)"); /*********************************************** * Open HMM file (might be in HMMERDB or current directory). * Read a single HMM from it. ***********************************************/ if ((hmmfp = HMMFileOpen(hmmfile, "HMMERDB")) == NULL) ajFatal("Failed to open HMM file %s\n", hmmfile); if (!HMMFileRead(hmmfp, &hmm)) ajFatal("Failed to read any HMMs from %s\n", hmmfile); HMMFileClose(hmmfp); if (hmm == NULL) ajFatal("HMM file %s corrupt or in incorrect format? Parse failed", hmmfile); /* Configure the HMM to shut off N,J,C emission: so we * do a simple single pass through the model. */ Plan7NakedConfig(hmm); Plan7Renormalize(hmm); /*********************************************** * Open the output file, or stdout ***********************************************/ fp = ajFileGetFileptr(outf); /*********************************************** * Show the options banner ***********************************************/ be_quiet=TRUE; if (! be_quiet) { printf("HMM file: %s\n", hmmfile); if (! do_consensus) { printf("Number of seqs: %d\n", nseq); printf("Random seed: %d\n", seed); } printf("- - - - - - - - - - - - - - - - - - - - - - - - - " "- - - - - - -\n\n"); } /*********************************************** * Do the work. * If we're generating an alignment, we have to collect * all our traces, then output. If we're generating unaligned * sequences, we can emit one at a time. ***********************************************/ if (do_consensus) { char *seq; SQINFO sqinfo; /* info about sequence (name/desc) */ EmitConsensusSequence(hmm, &seq, NULL, &L, NULL); strcpy(sqinfo.name, "consensus"); sqinfo.len = L; sqinfo.flags = SQINFO_NAME | SQINFO_LEN; WriteSeq(fp, kPearson, seq, &sqinfo); free(seq); } else if (do_alignment) { struct p7trace_s **tr; char **dsq; SQINFO *sqinfo; char **aseq; AINFO ainfo; float *wgt; dsq = MallocOrDie(sizeof(char *) * nseq); tr = MallocOrDie(sizeof(struct p7trace_s *) * nseq); sqinfo = MallocOrDie(sizeof(SQINFO) * nseq); wgt = MallocOrDie(sizeof(float) * nseq); FSet(wgt, nseq, 1.0); for (i = 0; i < nseq; i++) { EmitSequence(hmm, &(dsq[i]), &L, &(tr[i])); sprintf(sqinfo[i].name, "seq%d", i+1); sqinfo[i].len = L; sqinfo[i].flags = SQINFO_NAME | SQINFO_LEN; } P7Traces2Alignment(dsq, sqinfo, wgt, nseq, hmm->M, tr, FALSE, &aseq, &ainfo); /* Output the alignment */ WriteSELEX(fp, aseq, &ainfo, 50); if (ofile != NULL && !be_quiet) printf("Alignment saved in file %s\n", ofile); /* Free memory */ for (i = 0; i < nseq; i++) { P7FreeTrace(tr[i]); free(dsq[i]); } FreeAlignment(aseq, &ainfo); free(sqinfo); free(dsq); free(wgt); free(tr); } else /* unaligned sequence output */ { struct p7trace_s *tr; char *dsq; char *seq; SQINFO sqinfo; for (i = 0; i < nseq; i++) { EmitSequence(hmm, &dsq, &L, &tr); sprintf(sqinfo.name, "seq%d", i+1); sqinfo.len = L; sqinfo.flags = SQINFO_NAME | SQINFO_LEN; seq = DedigitizeSequence(dsq, L); WriteSeq(fp, kPearson, seq, &sqinfo); P7FreeTrace(tr); free(dsq); free(seq); } } ajFileClose(&outf); FreePlan7(hmm); SqdClean(); #ifdef MEMDEBUG current_size = malloc_inuse(&histid2); if (current_size != orig_size) malloc_list(2, histid1, histid2); else fprintf(stderr, "[No memory leaks.]\n"); #endif ajStrDel(&instr); ajStrDel(&outstr); ajFileClose(&inf); ajFileClose(&outf); embExit(); return 0; }
int main(int argc, char *argv[]) { char *string/*, *line*/; char *structure=NULL, *cstruc=NULL; /*char fname[13], ffname[20], gfname[20];*/ /*char *ParamFile=NULL;*/ char *ns_bases=NULL, *c; int i, length, l, sym/*, r*/; double energy, min_en; double kT, sfact=1.07; int pf=0, noPS=0, istty; int noconv=0; int circ=0; AjPSeq seq = NULL; AjPFile confile = NULL; AjPFile paramfile = NULL; AjPFile outf = NULL; AjPFile essfile = NULL; AjPFile dotfilea = NULL; AjPFile dotfileb = NULL; AjPStr seqstring = NULL; AjPStr constring = NULL; AjPStr seqname = NULL; float eT = 0.; AjBool eGU; AjBool ecirc = ajFalse; AjBool eclose; AjBool lonely; AjBool convert; AjPStr ensbases = NULL; AjBool etloop; AjPStr eenergy = NULL; char ewt = '\0'; float escale = 0.; AjPStr edangles = NULL; char edangle = '\0'; ajint len; embInitPV("vrnafold",argc,argv,"VIENNA",VERSION); seqstring = ajStrNew(); constring = ajStrNew(); seqname = ajStrNew(); seq = ajAcdGetSeq("sequence"); confile = ajAcdGetInfile("constraintfile"); paramfile = ajAcdGetInfile("paramfile"); eT = ajAcdGetFloat("temperature"); ecirc = ajAcdGetBoolean("circular"); eGU = ajAcdGetBoolean("gu"); eclose = ajAcdGetBoolean("closegu"); lonely = ajAcdGetBoolean("lp"); convert = ajAcdGetBoolean("convert"); ensbases = ajAcdGetString("nsbases"); etloop = ajAcdGetBoolean("tetraloop"); eenergy = ajAcdGetListSingle("energy"); escale = ajAcdGetFloat("scale"); edangles = ajAcdGetListSingle("dangles"); outf = ajAcdGetOutfile("outfile"); essfile = ajAcdGetOutfile("ssoutfile"); /* dotfilea = ajAcdGetOutfile("adotoutfile"); dotfileb = ajAcdGetOutfile("bdotoutfile"); */ do_backtrack = 2; pf = 0; string = NULL; istty = 0; temperature = (double) eT; circ = !!ecirc; noGU = (eGU) ? 0 : 1; no_closingGU = (eclose) ? 0 : 1; noLonelyPairs = (lonely) ? 0 : 1; noconv = (convert) ? 0 : 1; ns_bases = (ajStrGetLen(ensbases)) ? MAJSTRGETPTR(ensbases) : NULL; tetra_loop = !!etloop; ewt = *ajStrGetPtr(eenergy); if(ewt == '0') energy_set = 0; else if(ewt == '1') energy_set = 1; else if(ewt == '2') energy_set = 2; sfact = (double) escale; edangle = *ajStrGetPtr(edangles); if(edangle == '0') dangles = 0; else if(edangle == '1') dangles = 1; else if(edangle == '2') dangles = 2; else if(edangle == '3') dangles = 3; if(circ && noLonelyPairs) { ajWarn("Depending on the origin of the circular sequence\n" "some structures may be missed when using -noLP\nTry " "rotating your sequence a few times\n"); } if(paramfile) read_parameter_file(paramfile); if (ns_bases != NULL) { nonstandards = space(33); c=ns_bases; i=sym=0; if (*c=='-') { sym=1; c++; } while (*c!='\0') { if (*c!=',') { nonstandards[i++]=*c++; nonstandards[i++]=*c; if ((sym)&&(*c!=*(c-1))) { nonstandards[i++]=*c; nonstandards[i++]=*(c-1); } } c++; } } if(confile) vienna_GetConstraints(confile,&constring); string = NULL; structure = NULL; length = ajSeqGetLen(seq); string = (char *) space(length+1); strcpy(string,ajSeqGetSeqC(seq)); len = ajStrGetLen(constring); structure = (char *) space(length+1); if(len) { fold_constrained = 1; strcpy(structure,ajStrGetPtr(constring)); } for (l = 0; l < length; l++) { string[l] = toupper(string[l]); if (!noconv && string[l] == 'T') string[l] = 'U'; } /* initialize_fold(length); */ if (circ) min_en = circfold(string, structure); else min_en = fold(string, structure); ajFmtPrintF(outf,"%s\n%s", string, structure); if (istty) printf("\n minimum free energy = %6.2f kcal/mol\n", min_en); else ajFmtPrintF(outf," (%6.2f)\n", min_en); if (!noPS) { if (length<2000) (void) PS_rna_plot(string, structure, essfile); else ajWarn("Structure too long, not doing xy_plot\n"); } if (length>=2000) free_arrays(); if (pf) { char *pf_struc; pf_struc = (char *) space((unsigned) length+1); if (dangles==1) { dangles=2; /* recompute with dangles as in pf_fold() */ min_en = (circ) ? energy_of_circ_struct(string, structure) : energy_of_struct(string, structure); dangles=1; } kT = (temperature+273.15)*1.98717/1000.; /* in Kcal */ pf_scale = exp(-(sfact*min_en)/kT/length); if (length>2000) ajWarn("scaling factor %f\n", pf_scale); (circ) ? init_pf_circ_fold(length) : init_pf_fold(length); if (cstruc!=NULL) strncpy(pf_struc, cstruc, length+1); energy = (circ) ? pf_circ_fold(string, pf_struc) : pf_fold(string, pf_struc); if (do_backtrack) { ajFmtPrintF(outf,"%s", pf_struc); ajFmtPrintF(outf," [%6.2f]\n", energy); } if ((istty)||(!do_backtrack)) ajFmtPrintF(outf," free energy of ensemble = %6.2f kcal/mol\n", energy); if (do_backtrack) { plist *pl1,*pl2; char *cent; double dist, cent_en; cent = centroid(length, &dist); cent_en = (circ) ? energy_of_circ_struct(string, cent) : energy_of_struct(string, cent); ajFmtPrintF(outf,"%s {%6.2f d=%.2f}\n", cent, cent_en, dist); free(cent); pl1 = make_plist(length, 1e-5); pl2 = b2plist(structure); (void) PS_dot_plot_list(string, dotfilea, pl1, pl2, ""); free(pl2); if (do_backtrack==2) { pl2 = stackProb(1e-5); PS_dot_plot_list(string, dotfileb, pl1, pl2, "Probabilities for stacked pairs (i,j)(i+1,j-1)"); free(pl2); } free(pl1); free(pf_struc); } ajFmtPrintF(outf," frequency of mfe structure in ensemble %g; ", exp((energy-min_en)/kT)); if (do_backtrack) ajFmtPrintF(outf,"ensemble diversity %-6.2f", mean_bp_dist(length)); ajFmtPrintF(outf,"\n"); free_pf_arrays(); } if (cstruc!=NULL) free(cstruc); free(string); free(structure); ajStrDel(&seqstring); ajStrDel(&constring); ajStrDel(&seqname); ajStrDel(&ensbases); ajStrDel(&eenergy); ajStrDel(&edangles); ajSeqDel(&seq); ajFileClose(&confile); ajFileClose(¶mfile); ajFileClose(&outf); ajFileClose(&essfile); /* ajFileClose(&dotfilea); ajFileClose(&dotfileb); */ if (length<2000) free_arrays(); embExit(); return 0; }
int main(int argc, char *argv[]) { 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; }
static void jaspscan_ReportHits(AjPFeattable TabRpt, const AjPTable mattab, AjPList hits) { PJsphits hit = NULL; PJspmat info = NULL; AjPFeature feat = NULL; AjPStr str = NULL; float fnum = 0.; str = ajStrNew(); while(ajListPop(hits,(void **)&hit)) { if(hit->start <= hit->end) feat = ajFeatNewII(TabRpt,hit->start,hit->end); else feat = ajFeatNewIIRev(TabRpt,hit->start,hit->end); ajFmtPrintS(&str,"*pc %.3f",hit->scorepc); ajFeatTagAdd(feat, NULL, str); ajFmtPrintS(&str,"*id %S",hit->matname); ajFeatTagAdd(feat, NULL, str); info = ajTableFetch(mattab,hit->matname); if(!info) ajWarn("No info for matrix %S",hit->matname); if(ajStrGetLen(info->name)) { ajFmtPrintS(&str,"*name %S",info->name); ajFeatTagAdd(feat, NULL, str); } if(ajStrGetLen(info->species)) { ajFmtPrintS(&str,"*species %S",info->species); ajFeatTagAdd(feat, NULL, str); } if(ajStrGetLen(info->klass)) { ajFmtPrintS(&str,"*class %S",info->klass); ajFeatTagAdd(feat, NULL, str); } if(ajStrGetLen(info->sgroup)) { ajFmtPrintS(&str,"*supergroup %S",info->sgroup); ajFeatTagAdd(feat, NULL, str); } if(ajStrGetLen(info->protseq)) { ajFmtPrintS(&str,"*pseq %S",info->protseq); ajFeatTagAdd(feat, NULL, str); } if(ajStrGetLen(info->exp)) { ajFmtPrintS(&str,"*exp %S",info->exp); ajFeatTagAdd(feat, NULL, str); } if(ajStrGetLen(info->pmid)) { ajFmtPrintS(&str,"*pmid %S",info->pmid); ajFeatTagAdd(feat, NULL, str); } if(ajStrGetLen(info->num)) { ajStrToFloat(info->num,&fnum); ajFmtPrintS(&str,"*info %.3f",fnum); ajFeatTagAdd(feat, NULL, str); } if(ajStrGetLen(info->jaspar)) { ajFmtPrintS(&str,"*jaspar %S",info->jaspar); ajFeatTagAdd(feat, NULL, str); } if(ajStrGetLen(info->transfac)) { ajFmtPrintS(&str,"*transfac %S",info->transfac); ajFeatTagAdd(feat, NULL, str); } if(ajStrGetLen(info->mcs)) { ajStrToFloat(info->mcs,&fnum); ajFmtPrintS(&str,"*mcs %.3f",fnum); ajFeatTagAdd(feat, NULL, str); } if(ajStrGetLen(info->models)) { ajFmtPrintS(&str,"*built %S",info->models); ajFeatTagAdd(feat, NULL, str); } jaspscan_hitsdel(&hit); } ajStrDel(&str); return; }
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 AjBool dbiblast_parseNcbi(const AjPStr line, AjPFile * alistfile, AjBool systemsort, AjPStr const * fields, ajint* maxFieldLen, ajuint* countfield, AjPStr* myid, AjPList* fdlist) { char* fd; static ajint numFields; static ajint accfield = -1; static ajint desfield = -1; static ajint svnfield = -1; static AjBool reset = AJTRUE; if(!fields) { reset = ajTrue; accfield = svnfield = desfield = -1; return ajFalse; } if(reset) { numFields = 0; while(fields[numFields]) { if(ajStrMatchCaseC(fields[numFields], "acc")) accfield=numFields; else if(ajStrMatchCaseC(fields[numFields], "sv")) svnfield=numFields; else if(ajStrMatchCaseC(fields[numFields], "des")) desfield=numFields; else ajWarn("EMBL parsing unknown field '%S' ignored", fields[numFields]); numFields++; } reset = ajFalse; } if(!wrdexp) wrdexp = ajRegCompC("([A-Za-z0-9]+)"); ajStrAssignC(&tmpdes,""); ajStrAssignC(&t,""); ajStrAssignC(&tmpac,""); ajStrAssignC(&tmpsv,""); ajStrAssignC(&tmpgi,""); ajStrAssignC(&tmpdb,""); ajFmtPrintS(&t,">%S",line); if(!ajSeqParseNcbi(t,myid,&tmpac,&tmpsv,&tmpgi,&tmpdb,&tmpdes)) return ajFalse; if(ajStrGetLen(tmpac)) ajStrFmtUpper(&tmpac); if(accfield >= 0) embDbiMaxlen(&tmpac, &maxFieldLen[accfield]); if(svnfield >= 0) { embDbiMaxlen(&tmpsv, &maxFieldLen[svnfield]); embDbiMaxlen(&tmpgi, &maxFieldLen[svnfield]); } ajStrFmtUpper(myid); /* ajDebug("parseNCBI success\n"); */ if(systemsort) { if(accfield >= 0 && ajStrGetLen(tmpac)) { countfield[accfield]++; ajFmtPrintF(alistfile[accfield], "%S %S\n", *myid, tmpac); } if(svnfield >= 0 && ajStrGetLen(tmpsv)) { countfield[svnfield]++; ajFmtPrintF(alistfile[svnfield], "%S %S\n", *myid, tmpsv); } if(svnfield >= 0 && ajStrGetLen(tmpgi)) { countfield[svnfield]++; ajFmtPrintF(alistfile[svnfield], "%S %S\n", *myid, tmpgi); } if(desfield >= 0 && ajStrGetLen(tmpdes)) while(ajRegExec(wrdexp, tmpdes)) { ajRegSubI(wrdexp, 1, &tmpfd); embDbiMaxlen(&tmpfd, &maxFieldLen[desfield]); ajStrFmtUpper(&tmpfd); ajDebug("++des '%S'\n", tmpfd); countfield[desfield]++; ajFmtPrintF(alistfile[desfield], "%S %S\n", *myid, tmpfd); ajRegPost(wrdexp, &tmpdes); } } else { if(accfield >= 0 && ajStrGetLen(tmpac)) { fd = ajCharNewS(tmpac); countfield[accfield]++; ajListPushAppend(fdlist[accfield], fd); } if(svnfield >= 0 && ajStrGetLen(tmpsv)) { fd = ajCharNewS(tmpsv); countfield[svnfield]++; ajListPushAppend(fdlist[svnfield], fd); } if(svnfield >= 0 && ajStrGetLen(tmpgi)) { fd = ajCharNewS(tmpgi); ajListPushAppend(fdlist[svnfield], fd); } if(desfield >= 0 && ajStrGetLen(tmpdes)) { while(ajRegExec(wrdexp, tmpdes)) { ajRegSubI(wrdexp, 1, &tmpfd); embDbiMaxlen(&tmpfd, &maxFieldLen[desfield]); ajStrFmtUpper(&tmpfd); ajDebug("++des '%S'\n", tmpfd); fd = ajCharNewS(tmpfd); countfield[desfield]++; ajListPushAppend(fdlist[desfield], fd); ajRegPost(wrdexp, &tmpdes); } } } /* ajDebug("parseNCBI '%S' '%S'\n", *myid, tmpac); */ return ajTrue; }
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; }
static void extractfeat_WriteOut(AjPSeqout seqout, AjPStr *featstr, AjBool compall, AjBool sense, ajint firstpos, ajint lastpos, ajint before, ajint after, const AjPSeq seq, AjBool remote, const AjPStr type, AjBool featinname, const AjPStr describestr) { AjPSeq newseq = NULL; AjPStr name = NULL; /* new name of the sequence */ AjPStr value = NULL; /* string value of start or end position */ AjPStr desc = NULL; /* sequence description */ AjBool forward = sense; if(compall) forward = ajFalse; ajDebug("WriteOut %S_%d_%d [%S] %d all:%B fwd:%B remote:%B\n", ajSeqGetNameS(seq), firstpos+1, lastpos+1, type, ajStrGetLen(*featstr), compall, sense, remote); /* see if there is a sequence to be written out */ if(!ajStrGetLen(*featstr)) { ajWarn("feature %S_%d_%d [%S] " "not written out because it has zero length\n", ajSeqGetNameS(seq), firstpos+1, lastpos+1, type); ajDebug("feature not written out because it has length=0 " "(probably first time round)\n"); return; } /* see if must abort because there were Remote IDs in the features */ if(remote) { ajWarn("feature not written out because it has Remote IDs\n"); ajDebug("feature not written out because it has Remote IDs\n"); return; } ajDebug("feature = %d bases\n", ajStrGetLen(*featstr)); /* featstr may be edited, so it is a AjPStr* */ extractfeat_BeforeAfter (seq, featstr, firstpos, lastpos, before, after, forward); ajDebug("feature+before/after = %d bases\n", ajStrGetLen(*featstr)); /* set the extracted sequence */ newseq = ajSeqNew(); ajSeqAssignSeqS(newseq, *featstr); /* create a nice name for the new sequence */ name = ajStrNew(); ajStrAppendS(&name, ajSeqGetNameS(seq)); ajStrAppendC(&name, "_"); value = ajStrNew(); ajStrFromInt(&value, firstpos+1); ajStrAppendS(&name, value); ajStrAppendC(&name, "_"); ajStrFromInt(&value, lastpos+1); ajStrAppendS(&name, value); /* add the type of feature to the name, if required */ if(featinname) { ajStrAppendC(&name, "_"); ajStrAppendS(&name, type); } ajSeqAssignNameS(newseq, name); /* set the sequence description with the 'type' added */ desc = ajStrNew(); ajStrAppendC(&desc, "["); ajStrAppendS(&desc, type); ajStrAppendC(&desc, "] "); if(ajStrGetLen(describestr)) ajStrAppendS(&desc, describestr); ajStrAppendS(&desc, ajSeqGetDescS(seq)); ajSeqAssignDescS(newseq, desc); /* set the type */ if(ajSeqIsNuc(seq)) ajSeqSetNuc(newseq); else ajSeqSetProt(newseq); /* write the new sequence */ ajSeqoutWriteSeq(seqout, newseq); ajSeqDel(&newseq); ajStrDel(&name); ajStrDel(&value); ajStrDel(&desc); return; }
int main(int argc, char *argv[]) { embInitPV("goligomersearch", argc, argv, "GEMBASSY", "1.0.3"); AjPSeqall seqall; AjPSeq seq; AjPStr inseq = NULL; AjPStr oligomer = NULL; AjPStr restid = NULL; AjPStr seqid = NULL; AjPStr base = NULL; AjPStr url = NULL; AjPStr _return = NULL; AjPStr tmpname = NULL; AjPSeqout tmpout = NULL; AjPFilebuff tmp = NULL; AjPStr line = NULL; AjPFile outfile = NULL; seqall = ajAcdGetSeqall("sequence"); oligomer = ajAcdGetString("oligomer"); _return = ajAcdGetSelectSingle("return"); outfile = ajAcdGetOutfile("outfile"); base = ajStrNewC("rest.g-language.org"); gAssignUniqueName(&tmpname); ajStrAppendC(&tmpname, ".fasta"); while(ajSeqallNext(seqall, &seq)) { inseq = NULL; 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/oligomer_search/%S/return=%S", base, restid, oligomer, _return); if(!gFilebuffURLS(url, &tmp)) { ajDie("Failed to download result from:\n%S\n", url); } ajBuffreadLine(tmp, &line); ajStrRemoveSetC(&line, "\n"); ajFmtPrintF(outfile, "Sequence: %S Oligomer: %S Return: %S\n", seqid, oligomer, line); ajStrDel(&url); ajStrDel(&restid); ajStrDel(&seqid); ajStrDel(&inseq); } ajFileClose(&outfile); ajSeqallDel(&seqall); ajSeqDel(&seq); ajStrDel(&base); ajStrDel(&oligomer); embExit(); return 0; }
static CachePNode cacheNodeNew(const EnsPCache cache, void* key, void* value) { ajuint *Puintkey = NULL; CachePNode node = NULL; if(!cache) return NULL; if(!key) return NULL; if(!value) return NULL; AJNEW0(node); /* Add the size of the Ensembl Cache Node itself. */ node->Bytes += (ajuint) sizeof (CacheONode); switch(cache->Type) { case ensECacheTypeNumeric: /* Reference AJAX unsigned integer key data. */ AJNEW0(Puintkey); *Puintkey = *((ajuint *) key); node->Key = (void *) Puintkey; /* Add the size of unsigned integer key data. */ node->Bytes += (ajuint) sizeof (ajuint); break; case ensECacheTypeAlphaNumeric: /* Reference AJAX String key data. */ node->Key = (void *) ajStrNewS((AjPStr) key); /* Add the size of AJAX String key data. */ node->Bytes += (ajuint) sizeof (AjOStr); node->Bytes += ajStrGetRes((AjPStr) node->Key); break; default: ajWarn("cacheNodeNew got unexpected Cache type %d.\n", cache->Type); } /* Reference the value data. */ if(cache->Reference && value) node->Value = (*cache->Reference)(value); /* Calculate the size of the value data. */ if(cache->Size && node->Value) node->Bytes += (*cache->Size)(node->Value); node->Dirty = ajFalse; return node; }