int main(int argc, char **argv) { /* Variable Declarations */ AjPFile inf = NULL; AjPFile outf = NULL; AjPStr line = NULL; /* Line from inf */ AjPStr option = NULL; AjBool doall = AJFALSE; AjBool doend = AJFALSE; AjBool doexcess = AJFALSE; /* ACD File Processing */ embInit("nospace", argc, argv); inf = ajAcdGetInfile("infile"); outf = ajAcdGetOutfile("outfile"); option = ajAcdGetListSingle("menu"); if(ajStrMatchC(option, "all")) doall = ajTrue; else if(ajStrMatchC(option, "end")) doend = ajTrue; else if(ajStrMatchC(option, "excess")) doexcess = ajTrue; /* Application logic */ line = ajStrNew(); while(ajReadline(inf,&line)) { if(doall) ajStrRemoveWhite(&line); else if(doend) ajStrTrimWhiteEnd(&line); else if(doexcess) ajStrRemoveWhiteExcess(&line); ajFmtPrintF(outf, "%S\n", line); } /* Memory management and exit */ ajFileClose(&inf); ajFileClose(&outf); ajStrDel(&line); ajStrDel(&option); embExit(); return 0; }
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; }
/* @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; }
int main(int argc, char **argv) { AjPSeqall nucseq; /* input nucleic sequences */ AjPSeqset protseq; /* input aligned protein sequences */ AjPSeqout seqout; AjPSeq nseq; /* next nucleic sequence to align */ const AjPSeq pseq; /* next protein sequence use in alignment */ AjPTrn trnTable; AjPSeq pep; /* translation of nseq */ AjPStr tablelist; ajint table; AjPSeqset outseqset; /* set of aligned nucleic sequences */ ajint proteinseqcount = 0; AjPStr degapstr = NULL; /* used to check if it matches with START removed */ AjPStr degapstr2 = NULL; AjPStr codon = NULL; /* holds temporary codon to check if is START */ char aa; /* translated putative START codon */ ajint type; /* returned type of the putative START codon */ /* start position of guide protein in translation */ ajlong pos = 0; AjPSeq newseq = NULL; /* output aligned nucleic sequence */ ajint frame; embInit("tranalign", argc, argv); nucseq = ajAcdGetSeqall("asequence"); protseq = ajAcdGetSeqset("bsequence"); tablelist = ajAcdGetListSingle("table"); seqout = ajAcdGetSeqoutset("outseq"); outseqset = ajSeqsetNew(); degapstr = ajStrNew(); /* initialise the translation table */ ajStrToInt(tablelist, &table); trnTable = ajTrnNewI(table); ajSeqsetFill(protseq); while(ajSeqallNext(nucseq, &nseq)) { if((pseq = ajSeqsetGetseqSeq(protseq, proteinseqcount++)) == NULL) ajErr("No guide protein sequence available for " "nucleic sequence %S", ajSeqGetNameS(nseq)); ajDebug("Aligning %S and %S\n", ajSeqGetNameS(nseq), ajSeqGetNameS(pseq)); /* get copy of pseq string with no gaps */ ajStrAssignS(°apstr, ajSeqGetSeqS(pseq)); ajStrRemoveGap(°apstr); /* ** for each translation frame look for subset of pep that ** matches pseq */ for(frame = 1; frame <4; frame++) { ajDebug("trying frame %d\n", frame); pep = ajTrnSeqOrig(trnTable, nseq, frame); degapstr2 = ajStrNew(); ajStrAssignRef(°apstr2, degapstr); pos = ajStrFindCaseS(ajSeqGetSeqS(pep), degapstr); /* ** we might have a START codon that should be translated as 'M' ** we need to check if there is a match after a possible START ** codon */ if(pos == -1 && ajStrGetLen(degapstr) > 1 && (ajStrGetPtr(degapstr)[0] == 'M' || ajStrGetPtr(degapstr)[0] == 'm')) { /* see if pep minus the first character is a match */ ajStrCutStart(°apstr2, 1); pos = ajStrFindCaseS(ajSeqGetSeqS(pep), degapstr2); /* ** pos is >= 1 if we have a match that is after the first ** residue */ if(pos >= 1) { /* point back at the putative START Methionine */ pos--; /* test if first codon is a START */ codon = ajStrNew(); ajStrAssignSubS(&codon, ajSeqGetSeqS(nseq), (pos*3)+frame-1, (pos*3)+frame+2); type = ajTrnCodonstrTypeS(trnTable, codon, &aa); if(type != 1) { /* first codon is not a valid START, force a mismatch */ pos = -1; } ajStrDel(&codon); } else { /* force 'pos == 0' to be treated as a mismatch */ pos = -1; } } ajStrDel(°apstr2); ajSeqDel(&pep); if(pos != -1) break; } if(pos == -1) ajErr("Guide protein sequence %S not found in nucleic sequence %S", ajSeqGetNameS(pseq), ajSeqGetNameS(nseq)); else { ajDebug("got a match with frame=%d\n", frame); /* extract the coding region of nseq with gaps */ newseq = ajSeqNew(); ajSeqSetNuc(newseq); ajSeqAssignNameS(newseq, ajSeqGetNameS(nseq)); ajSeqAssignDescS(newseq, ajSeqGetDescS(nseq)); tranalign_AddGaps(newseq, nseq, pseq, (pos*3)+frame-1); /* output the gapped nucleic sequence */ ajSeqsetApp(outseqset, newseq); ajSeqDel(&newseq); } ajStrRemoveWhiteExcess(°apstr); } ajSeqoutWriteSet(seqout, outseqset); ajSeqoutClose(seqout); ajTrnDel(&trnTable); ajSeqsetDel(&outseqset); ajStrDel(°apstr); ajStrDel(°apstr2); ajSeqallDel(&nucseq); ajSeqDel(&nseq); ajSeqoutDel(&seqout); ajSeqsetDel(&protseq); ajStrDel(&tablelist); embExit(); return 0; }
AjPMatrixf ajMatrixfNewFile(const AjPStr filename) { AjPMatrixf ret = NULL; AjPStr *orderstring = NULL; AjPStr buffer = NULL; AjPStr firststring = NULL; AjPStr reststring = NULL; const AjPStr tok = NULL; ajint len = 0; ajint i = 0; ajint l = 0; ajint k = 0; ajint cols = 0; ajint rows = 0; const char *ptr = NULL; AjPFile file = NULL; AjBool first = ajTrue; float **matrix = NULL; float *templine = NULL; float minval = -1.0; AjPList rlabel_list = NULL; AjPStr *rlabel_arr = NULL; #ifndef WIN32 static const char *delimstr = " :\t\n"; #else static const char *delimstr = " :\t\n\r"; #endif rlabel_list = ajListNew(); firststring = ajStrNew(); reststring = ajStrNew(); file = ajDatafileNewInNameS(filename); if(!file) { ajStrDel(&firststring); ajStrDel(&reststring); return NULL; } /* Read row labels */ while(ajReadline(file,&buffer)) { ptr = ajStrGetPtr(buffer); #ifndef WIN32 if(*ptr != '#' && *ptr != '\n') #else if(*ptr != '#' && *ptr != '\n' && *ptr != '\r') #endif { if(first) first = ajFalse; else { ajFmtScanC(ptr, "%S", &firststring); ajListPushAppend(rlabel_list, firststring); firststring = ajStrNew(); } } } first = ajTrue; ajStrDel(&firststring); rows = ajListToarray(rlabel_list, (void ***) &rlabel_arr); ajFileSeek(file, 0, 0); while(ajReadline(file,&buffer)) { ajStrRemoveWhiteExcess(&buffer); ptr = ajStrGetPtr(buffer); if(*ptr && *ptr != '#') { if(first) { cols = ajStrParseCountC(buffer,delimstr); AJCNEW0(orderstring, cols); for(i=0; i<cols; i++) orderstring[i] = ajStrNew(); tok = ajStrParseC(buffer, " :\t\n"); ajStrAssignS(&orderstring[l++], tok); while((tok = ajStrParseC(NULL, " :\t\n"))) ajStrAssignS(&orderstring[l++], tok); first = ajFalse; ret = ajMatrixfNewAsym(orderstring, cols, rlabel_arr, rows, filename); matrix = ret->Matrixf; } else { ajFmtScanC(ptr, "%S", &firststring); /* JISON 19/7/4 k = ajSeqcvtGetCodeK(ret->Cvt, ajStrGetCharFirst(firststring)); */ k = ajSeqcvtGetCodeS(ret->Cvt, firststring); len = MAJSTRGETLEN(firststring); ajStrAssignSubC(&reststring, ptr, len, -1); /* ** Must discard the first string (label) and use ** reststring otherwise ajArrFloatLine would fail (it ** cannot convert a string to a float) ** ** Use cols,1,cols in below because although 2nd and ** subsequent lines have one more string in them (the ** residue label in the 1st column) we've discarded that ** from the string that's passed */ templine = ajArrFloatLine(reststring,delimstr,1,cols); for(i=0; i<cols; i++) { if(templine[i] < minval) minval = templine[i]; /* JISON 19/7/4 matrix[k][ajSeqcvtGetCodeK(ret->Cvt, ajStrGetCharFirst(orderstring[i]))] = templine[i]; */ matrix[k][ajSeqcvtGetCodeAsymS(ret->Cvt, orderstring[i])] = templine[i]; } AJFREE(templine); } } } ajDebug("fill rest with minimum value %d\n", minval); ajFileClose(&file); ajStrDel(&buffer); for(i=0; i<cols; i++) ajStrDel(&orderstring[i]); AJFREE(orderstring); ajDebug("read matrix file %S\n", filename); ajStrDel(&firststring); ajStrDel(&reststring); for(i=0; i<rows; i++) ajStrDel(&rlabel_arr[i]); AJFREE(rlabel_arr); ajListFree(&rlabel_list); return ret; }
AjPMatrix ajMatrixNewFile(const AjPStr filename) { AjPMatrix ret = NULL; AjPStr buffer = NULL; const AjPStr tok = NULL; AjPStr firststring = NULL; AjPStr *orderstring = NULL; AjPFile file = NULL; AjBool first = ajTrue; const char *ptr = NULL; ajint **matrix = NULL; ajint minval = -1; ajint i = 0; ajint l = 0; ajint k = 0; ajint cols = 0; ajint rows = 0; ajint *templine = NULL; AjPList rlabel_list = NULL; AjPStr *rlabel_arr = NULL; #ifndef WIN32 static const char *delimstr = " :\t\n"; #else static const char *delimstr = " :\t\n\r"; #endif rlabel_list = ajListNew(); firststring = ajStrNew(); file = ajDatafileNewInNameS(filename); if(!file) { ajStrDel(&firststring); ajListFree(&rlabel_list); return NULL; } /* Read row labels */ while(ajReadline(file,&buffer)) { ptr = ajStrGetPtr(buffer); #ifndef WIN32 if(*ptr != '#' && *ptr != '\n') #else if(*ptr != '#' && *ptr != '\n' && *ptr != '\r') #endif { if(first) first = ajFalse; else { ajFmtScanC(ptr, "%S", &firststring); ajListPushAppend(rlabel_list, firststring); firststring = ajStrNew(); } } } first = ajTrue; ajStrDel(&firststring); rows = ajListToarray(rlabel_list, (void ***) &rlabel_arr); ajFileSeek(file, 0, 0); while(ajReadline(file,&buffer)) { ajStrRemoveWhiteExcess(&buffer); ptr = ajStrGetPtr(buffer); if(*ptr && *ptr != '#') { if(first) { cols = ajStrParseCountC(buffer,delimstr); AJCNEW0(orderstring, cols); for(i=0; i<cols; i++) orderstring[i] = ajStrNew(); tok = ajStrParseC(buffer, " :\t\n"); ajStrAssignS(&orderstring[l++], tok); while((tok = ajStrParseC(NULL, " :\t\n"))) ajStrAssignS(&orderstring[l++], tok); first = ajFalse; ret = ajMatrixNewAsym(orderstring, cols, rlabel_arr, rows, filename); matrix = ret->Matrix; } else { ajFmtScanC(ptr, "%S", &firststring); /* JISON 19/7/4 k = ajSeqcvtGetCodeK(ret->Cvt, ajStrGetCharFirst(firststring)); */ k = ajSeqcvtGetCodeS(ret->Cvt, firststring); /* ** cols+1 is used below because 2nd and subsequent lines have ** one more string in them (the residue label) */ templine = ajArrIntLine(buffer,delimstr,2,cols+1); for(i=0; i<cols; i++) { if(templine[i] < minval) minval = templine[i]; /* JISON 19/7/4 matrix[k][ajSeqcvtGetCodeK(ret->Cvt, ajStrGetCharFirst(orderstring[i]))] = templine[i]; */ matrix[k][ajSeqcvtGetCodeAsymS(ret->Cvt, orderstring[i])] = templine[i]; } AJFREE(templine); } } } ajDebug("fill rest with minimum value %d\n", minval); ajFileClose(&file); ajStrDel(&buffer); for(i=0; i<cols; i++) ajStrDel(&orderstring[i]); AJFREE(orderstring); ajDebug("read matrix file %S\n", filename); ajStrDel(&firststring); for(i=0; i<rows; i++) ajStrDel(&rlabel_arr[i]); AJFREE(rlabel_arr); ajListFree(&rlabel_list); return ret; }
static AjBool resourceoutWriteWebpage(AjPFile outf, const AjPResource resource) { AjPResquery tmpqry = NULL; AjPResterm resterm = NULL; AjPStr snstr = NULL; AjPStr tmpstr = NULL; AjPStr tmpurl = NULL; AjPStr tmpid = NULL; AjPStr tmpname = NULL; AjPStr tmpqid = NULL; AjPStr tmpqname = NULL; AjPStr tmpqterm = NULL; AjIList iter = NULL; AjIList iterq = NULL; ajuint i = 0; AjPStrTok handle = NULL; AjPStrTok namehandle = NULL; AjPStrTok termhandle = NULL; const char* biourl = "http://bioportal.bioontology.org/ontologies/45846"; if(!outf) return ajFalse; ajFmtPrintF(outf, "<!DOCTYPE HTML PUBLIC " "\"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"); ajFmtPrintF(outf, "<html>\n"); ajFmtPrintF(outf, "<head>\n"); ajFmtPrintF(outf, "<meta http-equiv=\"Content-Type\" " "content=\"text/html;charset=UTF-8\" />\n"); ajFmtPrintF(outf, "<title>Bioinformatics Data Resource Catalogue</title>\n"); ajFmtPrintF(outf, "</head>\n\n\n"); ajFmtPrintF(outf, "<body bgcolor=\"#ffffff\">\n"); ajFmtPrintF(outf, "<!-- ID -->\n"); if(ajStrGetLen(resource->Url)) ajFmtPrintF(outf, "<center><h1><a href=\"%S\">%S</a></h1></center>\n", resource->Url, resource->Id); else ajFmtPrintF(outf, "<center><h1>%S</h1></center>\n", resource->Id); ajFmtPrintF(outf, "<!-- Name -->\n"); ajFmtPrintF(outf, "<center><h2>%S</h2> </center>\n", resource->Name); ajFmtPrintF(outf, "<!-- Desc -->\n"); ajFmtPrintF(outf, "<p><i>%S</i></p>\n", resource->Desc); ajFmtPrintF(outf, "<table>\n"); ajFmtPrintF(outf, "<!-- ID -->\n"); ajFmtPrintF(outf, " <tr align=\"left\"><th>ID</th><td>%S</td></tr>\n", resource->Id); ajFmtPrintF(outf, "<!-- IDalt or omit -->\n"); if(ajListGetLength(resource->Idalt)) { ajFmtPrintF(outf, " <tr align=\"left\"><th>IDalt</th><td>"); i = 0; iter = ajListIterNew(resource->Idalt); while((tmpstr = ajListstrIterGet(iter))) { if(i++) ajFmtPrintF(outf, ", "); ajFmtPrintF(outf, "%S", tmpstr); } ajListIterDel(&iter); ajFmtPrintF(outf, "</td></tr>\n"); } if(ajStrGetLen(resource->Acc)) { ajFmtPrintF(outf, "<!-- ACC or omit -->\n"); ajFmtPrintF(outf, " <tr align=\"left\"><th>Acc</th><td>%S</td></tr>\n", resource->Acc); } if(ajStrGetLen(resource->Url)) ajFmtPrintF(outf, " <tr align=\"left\"><th>Home</th><td>" "<a href=\"%S\">%S</a></td></tr>\n", resource->Url, resource->Url); if(ajListGetLength(resource->Edamtpc)) { ajFmtPrintF(outf, "<!-- EDAMtpc -->\n"); iter = ajListIterNew(resource->Edamtpc); while((resterm = ajListIterGet(iter))) { ajStrAssignS(&tmpid, resterm->Id); ajStrCutBraces(&tmpid); ajStrFmtPercentEncodeC(&tmpid, " /()"); ajFmtPrintF(outf, " <tr align=\"left\"><th>EDAM topic</th><td>" "<a href=\"%s?p=terms&conceptid=EDAM%%3A%S\">%S</a>" "</td></tr>\n", biourl, tmpid, resterm->Name); } ajListIterDel(&iter); } ajFmtPrintF(outf, "<!-- Cat or omit -->\n"); if(ajListGetLength(resource->Cat)) { iter = ajListIterNew(resource->Cat); while((tmpstr = ajListstrIterGet(iter))) ajFmtPrintF(outf, " <tr align=\"left\"><th>Category</th>" "<td>%S</td></tr>\n", tmpstr); ajListIterDel(&iter); } ajFmtPrintF(outf, "<!-- Taxon (comma-separated list) -->\n"); ajFmtPrintF(outf, " <tr align=\"left\"><th>Taxon</th><td>"); i = 0; iter = ajListIterNew(resource->Taxon); while((resterm = ajListIterGet(iter))) { if(i++) ajFmtPrintF(outf, ", "); ajFmtPrintF(outf, "<a href=\"http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/" "wwwtax.cgi?id=%S\">%S</a>", resterm->Id, resterm->Name); } ajListIterDel(&iter); ajFmtPrintF(outf, "</td></tr>\n"); ajFmtPrintF(outf, "<!-- URLlink or omit -->\n"); if(ajStrGetLen(resource->Urllink)) ajFmtPrintF(outf, "<tr align=\"left\"><th>Linking</th><td>" "<a href=\"%S\">%S</a></td></tr>\n", resource->Urllink, resource->Urllink); ajFmtPrintF(outf, "<!-- URLrest or omit -->\n"); if(ajStrGetLen(resource->Urlrest)) ajFmtPrintF(outf, "<tr align=\"left\"><th>REST</th><td>" "<a href=\"%S\">%S</a></td></tr>\n", resource->Urlrest, resource->Urlrest); ajFmtPrintF(outf, "<!-- URLsoap or omit -->\n"); if(ajStrGetLen(resource->Urlsoap)) ajFmtPrintF(outf, "<tr align=\"left\"><th>SOAP</th><td>" "<a href=\"%S\">%S</a></td></tr>\n", resource->Urlsoap, resource->Urlsoap); ajFmtPrintF(outf, "<!-- Xref - omit ! -->\n"); ajFmtPrintF(outf, "</table>\n"); ajFmtPrintF(outf, "<!-- Query or omit, free-text comments given in {} --> \n"); if(ajListGetLength(resource->Query)) { ajFmtPrintF(outf, "<h3>Available data</h3>\n"); ajFmtPrintF(outf, "<table>\n"); ajFmtPrintF(outf, " <thead>\n"); ajFmtPrintF(outf, " <tr align=\"left\">\n"); ajFmtPrintF(outf, " <th>Data</th>\n"); ajFmtPrintF(outf, " <th>Format</th>\n"); ajFmtPrintF(outf, " <th>Query</th>\n"); ajFmtPrintF(outf, " <th>Link</th>\n"); ajFmtPrintF(outf, " </tr>\n"); ajFmtPrintF(outf, " </thead>\n"); ajFmtPrintF(outf, " <tbody>\n"); iter = ajListIterNew(resource->Query); while((tmpqry = ajListIterGet(iter))) { ajStrAssignS(&tmpname, tmpqry->Datatype); ajStrCutBraces(&tmpname); ajStrFmtPercentEncodeC(&tmpname, " /()"); ajFmtPrintF(outf, " <tr>\n"); ajFmtPrintF(outf, " <td>" "<a href=\"%s?" "p=terms&conceptid=EDAM%%3A%S\">%S</a></td>\n", biourl, tmpname, tmpqry->Datatype); ajStrAssignS(&tmpname, tmpqry->Format); ajStrCutBraces(&tmpname); ajStrFmtPercentEncodeC(&tmpname, " /()"); ajFmtPrintF(outf, " <td>" "<a href=\"%s?" "p=terms&conceptid=EDAM%%3A%S\">%S</a></td>\n", biourl, tmpname, tmpqry->Format); ajStrAssignS(&tmpname, tmpqry->Term); ajStrCutBraces(&tmpname); ajStrFmtPercentEncodeC(&tmpname, " /()"); ajFmtPrintF(outf, " <td>" "<a href=\"%s?" "p=terms&conceptid=EDAM%%3A%S\">%S</a></td>\n", biourl, tmpname, tmpqry->Term); ajFmtPrintF(outf, " <td>%S</td>\n", tmpqry->Url); ajFmtPrintF(outf, " </tr>\n\n"); } ajListIterDel(&iter); ajFmtPrintF(outf, " </tbody>\n"); ajFmtPrintF(outf, "</table>\n"); } ajFmtPrintF(outf, "<!-- Example or omit -->\n"); if(ajListGetLength(resource->Example)) { ajFmtPrintF(outf, "<h3>Example queries</h3>\n"); ajFmtPrintF(outf, "<table>\n"); ajFmtPrintF(outf, " <thead>\n"); ajFmtPrintF(outf, " <tr align=\"left\">\n"); ajFmtPrintF(outf, " <th>Data</th>\n"); ajFmtPrintF(outf, " <th>Format</th>\n"); ajFmtPrintF(outf, " <th>Query</th>\n"); ajFmtPrintF(outf, " <th>Example</th>\n"); ajFmtPrintF(outf, " </tr>\n"); ajFmtPrintF(outf, " </thead>\n"); ajFmtPrintF(outf, " <tbody>\n"); iter = ajListIterNew(resource->Example); while((tmpstr = ajListstrIterGet(iter))) { ajStrTokenAssignC(&handle, tmpstr, "|"); ajStrTokenNextParse(handle, &tmpid); ajStrRemoveWhiteExcess(&tmpid); ajStrTokenNextParse(handle, &tmpname); ajStrRemoveWhiteExcess(&tmpname); iterq = ajListIterNew(resource->Query); while((tmpqry = ajListIterGet(iterq))) { if(!ajStrMatchS(tmpid, tmpqry->Term)) continue; ajStrAssignS(&tmpqid, tmpqry->Datatype); ajStrCutBraces(&tmpqid); ajStrFmtPercentEncodeC(&tmpqid, " /()"); ajFmtPrintF(outf, " <tr>\n"); ajFmtPrintF(outf, " <td>" "<a href=\"%s?" "p=terms&conceptid=EDAM%%3A%S\">%S</a></td>\n", biourl, tmpqid, tmpqry->Datatype); /* datatype */ ajStrAssignS(&tmpqid, tmpqry->Format); ajStrCutBraces(&tmpqid); ajStrFmtPercentEncodeC(&tmpqid, " /()"); ajFmtPrintF(outf, " <td>" "<a href=\"%s?" "p=terms&conceptid=EDAM%%3A%S\">%S</a></td>\n", biourl, tmpqid, tmpqry->Format); /* format */ ajStrAssignS(&tmpurl, tmpqry->Url); ajStrAssignS(&tmpqid, tmpqry->Term); ajStrCutBraces(&tmpqid); ajStrFmtPercentEncodeC(&tmpqid, " /()"); i = 0; ajStrTokenAssignC(&handle, tmpid, ";"); ajStrTokenAssignC(&namehandle, tmpname, ";"); ajStrTokenAssignC(&termhandle, tmpqry->Term, ";"); ajFmtPrintF(outf, " <td>"); while(ajStrTokenNextParse(handle, &tmpqid)) { ajStrTokenNextParse(namehandle, &tmpqname); ajStrTokenNextParse(termhandle, &tmpqterm); if(i) ajFmtPrintF(outf, "; "); ajStrRemoveWhiteExcess(&tmpqid); ajStrCutBraces(&tmpqid); ajFmtPrintF(outf, "<a href=\"%s?" "p=terms&conceptid=EDAM%%3A%S\">%S</a>", biourl, tmpqid, tmpqterm); /* id term */ ajFmtPrintS(&snstr, "%%s%u", (i+1)); ajStrExchangeSS(&tmpurl, snstr, tmpqname); i++; } ajFmtPrintF(outf, "</td>\n"); ajFmtPrintS(&snstr, "%%s"); ajStrExchangeSS(&tmpurl, snstr, tmpname); ajFmtPrintF(outf, " <td><a href=\"%S\">%S</a></td>\n", tmpurl, tmpname); /* url, exampleid */ ajFmtPrintF(outf, " </tr>\n"); } ajListIterDel(&iterq); } ajListIterDel(&iter); ajFmtPrintF(outf, " </tbody>\n"); ajFmtPrintF(outf, "</table>\n"); } ajFmtPrintF(outf, "\n\n</body></html>\n"); ajStrDel(&tmpid); ajStrDel(&tmpname); ajStrDel(&tmpurl); ajStrDel(&tmpqid); ajStrDel(&tmpqname); ajStrDel(&tmpqterm); ajStrDel(&snstr); ajStrTokenDel(&handle); ajStrTokenDel(&namehandle); ajStrTokenDel(&termhandle); return ajTrue; }
static AjBool dbxflat_ParseGenbank(EmbPBtreeEntry entry, AjPFile inf) { AjPStr line = NULL; ajlong pos = 0L; AjBool ret = ajTrue; AjPStr sumline = NULL; line = ajStrNewC(""); sumline = ajStrNew(); while(!ajStrPrefixC(line,"//") && ret) { if(ajStrPrefixC(line,"LOCUS")) { entry->fpos = pos; ajFmtScanS(line,"%*S%S",&entry->id); } if(svfield) if(ajStrPrefixC(line,"VERSION")) embBtreeGenBankAC(line,svfield->data); if(accfield) if(ajStrPrefixC(line,"ACCESSION")) embBtreeGenBankAC(line,accfield->data); if(keyfield) if(ajStrPrefixC(line,"KEYWORDS")) { ajStrAssignS(&sumline,line); ret = ajReadlineTrim(inf,&line); while(ret && *MAJSTRGETPTR(line)==' ') { ajStrAppendS(&sumline,line); ret = ajReadlineTrim(inf,&line); } ajStrRemoveWhiteExcess(&sumline); embBtreeGenBankKW(sumline,keyfield->data,keyfield->len); continue; } if(desfield) if(ajStrPrefixC(line,"DEFINITION")) { ajStrAssignS(&sumline,line); ret = ajReadlineTrim(inf,&line); while(ret && *MAJSTRGETPTR(line)==' ') { ajStrAppendS(&sumline,line); ret = ajReadlineTrim(inf,&line); } ajStrRemoveWhiteExcess(&sumline); embBtreeGenBankDE(sumline,desfield->data,desfield->len); continue; } if(orgfield) if(ajStrPrefixC(line,"SOURCE")) { ret = ajReadlineTrim(inf,&line); ajStrAppendC(&line,";"); while(ret && *MAJSTRGETPTR(line)==' ') { ajStrAppendS(&sumline,line); ret = ajReadlineTrim(inf,&line); } ajStrRemoveWhiteExcess(&sumline); embBtreeGenBankTX(sumline,orgfield->data,orgfield->len); continue; } pos = ajFileResetPos(inf); if(!ajReadlineTrim(inf,&line)) ret = ajFalse; } ajStrDel(&line); ajStrDel(&sumline); return ret; }
static AjBool dbxflat_ParseGenbank(EmbPBtreeEntry entry, AjPFile inf) { AjPStr line = NULL; ajlong pos = 0L; AjBool ret = ajTrue; AjPStr sumline = NULL; line = ajStrNewC(""); sumline = ajStrNew(); while(!ajStrPrefixC(line,"//") && ret) { if(ajStrPrefixC(line,"LOCUS")) { entry->fpos = pos; ajFmtScanS(line,"%*S%S",&entry->id); } if(entry->do_sv) if(ajStrPrefixC(line,"VERSION")) embBtreeGenBankAC(line,entry->sv); if(entry->do_accession) if(ajStrPrefixC(line,"ACCESSION")) embBtreeGenBankAC(line,entry->ac); if(entry->do_keyword) if(ajStrPrefixC(line,"KEYWORDS")) { ajStrAssignS(&sumline,line); ret = ajReadlineTrim(inf,&line); while(ret && *MAJSTRGETPTR(line)==' ') { ajStrAppendS(&sumline,line); ret = ajReadlineTrim(inf,&line); } ajStrRemoveWhiteExcess(&sumline); embBtreeGenBankKW(sumline,entry->kw,entry->kwlen); continue; } if(entry->do_description) if(ajStrPrefixC(line,"DEFINITION")) { ajStrAssignS(&sumline,line); ret = ajReadlineTrim(inf,&line); while(ret && *MAJSTRGETPTR(line)==' ') { ajStrAppendS(&sumline,line); ret = ajReadlineTrim(inf,&line); } ajStrRemoveWhiteExcess(&sumline); embBtreeGenBankDE(sumline,entry->de,entry->delen); continue; } if(entry->do_taxonomy) if(ajStrPrefixC(line,"SOURCE")) { ret = ajReadlineTrim(inf,&line); ajStrAppendC(&line,";"); while(ret && *MAJSTRGETPTR(line)==' ') { ajStrAppendS(&sumline,line); ret = ajReadlineTrim(inf,&line); } ajStrRemoveWhiteExcess(&sumline); embBtreeGenBankTX(sumline,entry->tx,entry->txlen); continue; } pos = ajFileResetPos(inf); if(!ajReadlineTrim(inf,&line)) ret = ajFalse; } ajStrDel(&line); ajStrDel(&sumline); return ret; }
EmbPPropAmino* embPropEaminoRead(AjPFile mfptr) { AjPStr line = NULL; AjPStr token = NULL; AjBool firstline; const char *p; ajuint i; ajint n; EmbPPropAmino *ret; line = ajStrNew(); token = ajStrNew(); firstline = ajTrue; AJCNEW0(ret,EMBPROPSIZE); for(i=0; i < EMBPROPSIZE; ++i) AJNEW0(ret[i]); while(ajReadline(mfptr, &line)) { ajStrRemoveWhiteExcess(&line); p = ajStrGetPtr(line); if(*p=='#' || *p=='!' || !*p) continue; if(firstline) { if(!ajStrPrefixC(line,"aa")) ajFatal("Incorrect (old?) format amino data file"); firstline = ajFalse; continue; } ajFmtScanS(line,"%S",&token); ajStrFmtUpper(&token); if(ajStrGetLen(token) != 1) ajFatal("Amino file line doesn't begin with a single character"); i = ajBasecodeToInt((ajint) *ajStrGetPtr(token)); if(i == 27) ajFatal("Amino file line doesn't begin with a single A->Z (%S)", line); n = ajFmtScanS(line,"%*s%d%d%d%d%d%d%f%d%d%d", &ret[i]->tiny, &ret[i]->sm_all, &ret[i]->aliphatic, &ret[i]->aromatic, &ret[i]->nonpolar, &ret[i]->polar, &ret[i]->charge, &ret[i]->pve, &ret[i]->nve, &ret[i]->extcoeff); if(n!= 10) ajFatal("Only %d columns in amino file - expected %d",n+1,11); } ajStrDel(&line); ajStrDel(&token); return ret; }
EmbPPropMolwt* embPropEmolwtRead(AjPFile mfptr) { AjPStr line = NULL; AjPStr token = NULL; AjBool firstline; const char *p; ajuint i; ajint n; EmbPPropMolwt *ret; line = ajStrNew(); token = ajStrNew(); firstline = ajTrue; AJCNEW0(ret,EMBPROPSIZE+2); for(i=0; i < EMBPROPSIZE+2; ++i) AJNEW0(ret[i]); while(ajReadline(mfptr, &line)) { ajStrRemoveWhiteExcess(&line); p = ajStrGetPtr(line); if(*p=='#' || *p=='!' || !*p) continue; if(firstline) { if(!ajStrPrefixC(line,"Mol")) ajFatal("Incorrect format molwt file: '%S'", line); firstline = ajFalse; continue; } ajFmtScanS(line,"%S",&token); ajStrFmtUpper(&token); if(ajStrGetLen(token) != 1) { if(ajStrPrefixC(token,"HYDROGEN")) { if(ajFmtScanS(line,"%*s%lf%lf", &ret[EMBPROPHINDEX]->average, &ret[EMBPROPHINDEX]->mono) != 2) ajFatal("Bad format hydrogen data line"); } else if(ajStrPrefixC(token,"OXYGEN")) { if(ajFmtScanS(line,"%*s%lf%lf", &ret[EMBPROPOINDEX]->average, &ret[EMBPROPOINDEX]->mono) != 2) ajFatal("Bad format oxygen data line"); } else if(ajStrPrefixC(token,"WATER")) { if(ajFmtScanS(line,"%*s%lf%lf", &ret[EMBPROPWINDEX]->average, &ret[EMBPROPWINDEX]->mono) != 2) ajFatal("Bad format water data line"); } else ajFatal("Unknown molwt token %S",token); continue; } i = ajBasecodeToInt((ajint) *ajStrGetPtr(token)); if(i == 27) ajFatal("Molwt file line doesn't begin with a single A->Z (%S)", line); n = ajFmtScanS(line,"%*s%lf%lf", &ret[i]->average, &ret[i]->mono); if(n != 2) ajFatal("Only %d columns in amino file - expected %d",n,3); } ajStrDel(&line); ajStrDel(&token); return ret; }