/* @funcstatic sigscanlig_score_ligands_site ********************************* ** ** Writes score data for ligands (Lighit objects) from individual hits to ** signatures (Hit objects). Site score method is used. List of hit objects ** must be sorted by ligand type and site number. ** ** @param [r] hits [const AjPList] List of hit objects. ** @return [AjBool] True on success ** @@ ******************************************************************************/ AjPList sigscanlig_score_ligands_site(AjPList hits) { AjPList ret = NULL; AjIList iter = NULL; /* Iterator. */ EmbPHit hit = NULL; AjPStr prev_ligand = NULL; SigPLighit lighit = NULL; ajint prevsn = -1; /* Previous site number */ float score = 0.0; /* Score for current ligand */ ajint nhits = 0; /* No. of hits (patches) for current ligand. */ ajint nsites = 0; /* No. of sites for current ligand */ float score_site = 0.0; /* Score for this site. */ ajint patch_cnt = 0; /* No. of patches in current site. */ ret = ajListNew(); prev_ligand = ajStrNew(); iter = ajListIterNew(hits); /* Hits are already sorted by ligid & site number */ while((hit = (EmbPHit) ajListIterGet(iter))) { /* ajFmtPrint("Current hit: %S (ligid: %S, sn: %d) score: %f\n", hit->Acc, hit->Sig->Ligid, hit->Sig->sn, hit->Score); */ /* New site */ if(hit->Sig->sn != prevsn) { if(patch_cnt) score_site /= patch_cnt; score += score_site; patch_cnt = 0; score_site = 0; } /* New ligand */ if((!ajStrMatchS(hit->Sig->Ligid, prev_ligand))) { if(nsites) score /= nsites; if(lighit) { /* lighit->ns = snarr_siz; */ lighit->ns = nsites; lighit->np = nhits; lighit->score = score; ajStrAssignS(&lighit->ligid, prev_ligand); ajListPushAppend(ret, lighit); } lighit = sigscanlig_LighitNew(); nsites = 0; nhits=0; prevsn = -1; score = 0; } /* Increment count of sites and hits/patches (for current ligand) and patches (for current site) */ if(hit->Sig->sn != prevsn) nsites++; score_site += hit->Score; nhits++; patch_cnt++; ajStrAssignS(&prev_ligand, hit->Sig->Ligid); prevsn = hit->Sig->sn; } /* Process last hit */ if(patch_cnt) score_site /= patch_cnt; score += score_site; if(nsites) score /= nsites; if(lighit) { /* lighit->ns = snarr_siz; */ lighit->ns = nsites; lighit->np = nhits; lighit->score = score; ajStrAssignS(&lighit->ligid, prev_ligand); ajListPushAppend(ret, lighit); } ajListSort(ret, sigscanlig_MatchinvScore); ajListIterDel(&iter); ajStrDel(&prev_ligand); return ret; }
int main(int argc, char **argv) { /* ** All pointers set to NULL for safety. ** Variables names and initialisation values aligned for clarity. */ AjBool boo = ajFalse; ajint n1 = 0; ajint n2 = 0; ajlong l1 = 0; /* long int */ float f1 = 0.0; double d1 = 0.0; /* there is no long double */ size_t size = 100; /* Reserved memory size. Could be any value you know in advance. */ embInit("demostringnew", argc, argv); demostringnew_msg("/* Starting string values */"); /* Functions with the prefix ajStr are for manipulating EMBOSS strings. Functions with the prefix ajChar are for manipulating C-type (char*) string See filesection and datasection sections in ajstr.c */ /* ** String constructor functions ** See "@section constructors" in ajstr.c */ /* Construct a new string with no starting value or reserved size. There is no equivlent function for C-type (char*) strings */ str0 = ajStrNew (); /* Construct a new string with a reserved size but no starting value */ txt1 = ajCharNewRes(size); str1 = ajStrNewRes (size); /* Construct a new C-type (char*) string with a starting value ... */ txt2 = ajCharNewC ("Starting value"); /* ... copied from a C-type (char*) string */ str2 = ajStrNewC (txt2); /* ... copied from a C-type (char*) string */ txt3 = ajCharNewS (str2); /* ... copied from a string */ str3 = ajStrNewS (str2); /* ... copied from a string */ /* Construct a new string with a reserved size and starting value ... */ txt4 = ajCharNewResC("Starting value, reserved size", size); /* ... copied from a C-type (char*) string)*/ str4 = ajStrNewResC (txt4, size); /* ... copied from a C-type (char*) string */ /* or str4 = ajStrNewResLenC(txt4, size, strlen(txt4)); to specify string length */ txt5 = ajCharNewResS(str4, size); /* ... copied from a string */ str5 = ajStrNewResS (str4, size); /* ... copied from a string */ demostringnew_msg("/* After string constructor functions */"); /* ** String destructor functions ** See "@section destructors" in ajstr.c) */ /* Destruct a string */ ajCharDel(&txt1); ajCharDel(&txt2); ajCharDel(&txt3); ajCharDel(&txt4); ajCharDel(&txt5); ajStrDel (&str0); ajStrDel (&str1); ajStrDel (&str3); ajStrDel (&str5); /* str2 & str4 still in memory */ demostringnew_msg("/* After string destructor functions */"); /* ** String (de)referencing functions ** See "@section destructors" in ajstr.c) */ str0 = ajStrNewRef(str2); /* or ajStrAssignRef(&str0, str2); */ demostringnew_msg("/* After string reference */"); ajStrDelStatic(&str0); demostringnew_msg("/* After string dereference */"); /* ** String assignment functions ** See "@section assignment" in ajstr.c) */ /* Still only str2 & str4 in memory */ /* Assign a string value using ... */ ajStrAssignC(&str1, "Assigned value"); /* ... a C-type (char*) string */ /* or ajStrAssignLenC(&str1, "Assigned value", strlen("Assigned value")); to specify string length. */ ajStrAssignS(&str3, str1); /* ... a string */ ajStrAssignK(&str5, 'A'); /* ... a character */ demostringnew_msg("/* After string assignment 1 */"); ajStrAssignSubC(&str1, "Assigned value", 0, 11); ajStrAssignSubS(&str3, str1, 0, 9); demostringnew_msg("/* After string assignment 2 */"); /* The assignment functions allocate memory if necessary so str1, str3 and str5 will be created for you. It's bad practice to use this mechanism however because it's not obvious the string has been allocated (and needs freeing). Much cleaner to call the construct (ajStrNew) explicitly. */ /* Assign a string with a reserved size and value using ... */ ajStrAssignResC(&str1, size, "Assigned value, reserved size"); /* ... a C-type (char*) string */ ajStrAssignResS(&str3, size, str1); /* ... a string */ demostringnew_msg("/* After string assignment 3 */"); /* Assign a string value only if the string is empty using ... */ str0 = ajStrNew(); ajStrAssignEmptyC(&str0, "New value if string was empty"); /* ... a C-type (char*) string */ ajStrAssignEmptyS(&str1, str0); /* ... a string */ demostringnew_msg("/* After string assignment 4 */"); /* Now str0-5 in memory. The above code is for illustrative purposes: it's much cleaner to put all the constructors / destructors at the top / bottom of the code where possible. */ /* Assign all strings intuitive values */ txt0 = ajCharNewResC("TEXT 0", 100); txt1 = ajCharNewResC("TEXT 1", 100); txt2 = ajCharNewResC("Text 2", 100); txt3 = ajCharNewResC("Text 3", 100); txt4 = ajCharNewResC("Text 4", 100); txt5 = ajCharNewResC("Text 5", 100); ajStrAssignC(&str0, "STRING 0"); ajStrAssignC(&str1, "STRING 1"); ajStrAssignC(&str2, "String 2"); ajStrAssignC(&str3, "String 3"); ajStrAssignC(&str4, "String 4 WITHSOMETEXTINABLOCK"); ajStrAssignC(&str5, "String 5 WITHSOMETEXTINABLOCK"); demostringnew_msg("/* After string assignment 5 */"); /* ** String formatting functions ** See "@section formatting" in ajstr.c */ ajCharFmtLower(txt0); ajCharFmtLower(txt1); ajStrFmtLower(&str0); ajStrFmtLowerSub(&str1, 0, 2); ajCharFmtUpper(txt2); ajCharFmtUpper(txt3); ajStrFmtUpper(&str2); ajStrFmtUpperSub(&str3, 0, 2); demostringnew_msg("/* After string formatting 1 */"); ajStrFmtTitle(&str0); ajStrFmtQuote(&str1); ajStrFmtBlock(&str4, 3); demostringnew_msg("/* After string formatting 2 */"); /* See also ajStrFmtWrap, ajStrFmtWrapLeft ... these need checking. */ /* ** String conversion functions ** See "@section datatype to string conversion" in ajstr.c */ n1 = n2 = l1 = 1; f1 = d1 = 0.5; ajStrFromBool( &str0, boo); ajStrFromInt(&str1, n1); ajStrFromLong(&str2, l1); ajStrFromFloat(&str3, f1, 5); ajStrFromDouble(&str4, d1, 5); ajStrFromDoubleExp(&str5, d1, 5); demostringnew_msg("/* After datatype to string conversion */"); /* ** String conversion functions ** See "@section string to datatype conversion" in ajstr.c */ ajStrToBool(str0, &boo); ajStrToInt(str1, &n1); ajStrToLong(str2, &l1); ajStrToDouble(str4, &d1); ajUser("/* After string to datatype conversion */\n" "boo (from str0): %B\nn1 (from str1): %d\nl1 (from str2): %d", boo, n1, l1); ajFmtPrint("f1 (from str3): %f\nd1 (from str4): %f\n", f1, d1); /* Check ajUser ... doesn't support %f */ /* See also ajStrToHex */ /* Assign all strings new values */ strcpy(txt0, "Text String"); strcpy(txt1, "TEXT STRING"); strcpy(txt2, "Text*"); strcpy(txt3, "Text"); strcpy(txt4, "Text String 4"); strcpy(txt5, "Text String 5"); ajStrAssignC(&str0, "String"); ajStrAssignC(&str1, "STRING"); ajStrAssignC(&str2, "String*"); ajStrAssignC(&str3, "*String"); ajStrAssignC(&str4, "String 4"); ajStrAssignC(&str5, "String 5"); demostringnew_msg("/* After resetting strings */"); /* ** String comparison functions ** See "@section comparison" in ajstr.c */ ajUserDumpC("/* String comparison functions */"); boo = ajCharMatchC(txt0, txt1); ajUser("ajCharMatchC(txt0 txt1); == %B", boo); boo = ajCharMatchCaseC(txt0, txt1); ajUser("ajCharMatchCaseC(txt0 txt1); == %B", boo); boo = ajCharMatchC(txt0, txt2); ajUser("ajCharMatchC(txt0,txt2); == %B", boo); boo = ajCharMatchWildC(txt0, txt2); ajUser("ajCharMatchWildC(txt0,txt2); == %B", boo); boo = ajCharMatchWildS(txt0, str2); ajUser("ajCharMatchWildS(txt0,str2); == %B", boo); /* See also ajCharMatchWildNextC, ajCharMatchWildWordC ... these need checking & documentation updated. */ boo = ajCharPrefixC(txt0, txt3); ajUser("ajCharPrefixC(txt0, txt3); == %B", boo); boo = ajCharPrefixS(txt0, str0); ajUser("ajCharPrefixS(txt0, str0); == %B", boo); boo = ajCharPrefixCaseC(txt5, txt1); ajUser("ajCharPrefixCaseC(txt5, txt1); == %B", boo); boo = ajCharPrefixCaseC(txt1, txt5); ajUser("ajCharPrefixCaseC(txt1, txt5); == %B", boo); boo = ajCharPrefixCaseS(txt0, str0); ajUser("ajCharPrefixCaseS(txt0, str0); == %B", boo); boo = ajCharSuffixC(txt0, txt3); ajUser("ajCharSuffixC(txt0, txt3); === %B", boo); boo = ajCharSuffixS(txt0, str0); ajUser("ajCharSuffixS(txt0, str0); == %B", boo); /* See also ajCharSuffixCaseC, ajCharSuffixCaseC, ajCharSuffixCaseS, ajCharSuffixCaseS ... these need checking. */ boo = ajStrMatchC (str0, txt0); ajUser("ajStrMatchC (str0, txt0); == %B", boo); boo = ajStrMatchS(str0, str1); ajUser("ajStrMatchS(str0, str1); == %B", boo); boo = ajStrMatchCaseC(str0, txt0); ajUser("ajStrMatchCaseC(str0, txt0); == %B", boo); boo = ajStrMatchCaseS(str0, str0); ajUser("ajStrMatchCaseS(str0, str0); == %B", boo); /* ajUser("== %B", boo); boo = ajStrMatchWildC(str2, const char* text); ajStrMatchWildS (const AjPStr thys, const AjPStr wild); ajStrMatchWildWordC (const AjPStr str, const char* text); ajStrMatchWildWordS (const AjPStr str, const AjPStr text); ajStrPrefixC(const AjPStr str, const char* txt2); ajStrPrefixS(const AjPStr str, const AjPStr str2); ajStrPrefixCaseC (const AjPStr str, const char* pref); ajStrPrefixCaseS (const AjPStr str, const AjPStr pref); ajStrSuffixC (const AjPStr thys, const char* suff); ajStrSuffixS (const AjPStr thys, const AjPStr suff); */ /**************************************************************************/ /* String substitution functions (See "@section substitution" in ajstr.c) */ /**************************************************************************/ /* AjBool ajStrExchangeCC(AjPStr* Pstr, const char* txt, const char* txtnew); AjBool ajStrExchangeCS(AjPStr* Pstr, const char* txt, const AjPStr strnew); AjBool ajStrExchangeKK(AjPStr* Pstr, char chr, char chrnew); AjBool ajStrExchangeSC(AjPStr* Pstr, const AjPStr str, const char* txtnew); AjBool ajStrExchangeSS(AjPStr* Pstr, const AjPStr str, const AjPStr strnew); AjBool ajStrExchangeSetCC(AjPStr* Pstr, const char* oldc, const char* newc); AjBool ajStrExchangeSetSS(AjPStr* Pstr, const AjPStr str, const AjPStr strnew); AjBool ajStrRandom(AjPStr *s); AjBool ajStrReverse(AjPStr* Pstr); */ embExit(); return 0; }
AjPList sigscanlig_score_ligands_patch(AjPList hits) { AjPList ret = NULL; AjIList iter = NULL; /* Iterator. */ EmbPHit hit = NULL; AjPStr prev_ligand = NULL; SigPLighit lighit = NULL; float score = 0.0; ajint nhits = 0; /* No. of hits (patches) for current ligand. */ ajint nsites = 0; /* No. of sites for current ligand. */ ajint prevsn = -1; /* Previous site number */ ret = ajListNew(); prev_ligand = ajStrNew(); iter = ajListIterNew(hits); while((hit = (EmbPHit) ajListIterGet(iter))) { /* New ligand */ if((!ajStrMatchS(hit->Sig->Ligid, prev_ligand))) { if(nhits) score /= nhits; if(lighit) { lighit->ns = nsites; lighit->np = nhits; lighit->score = score; ajStrAssignS(&lighit->ligid, prev_ligand); ajListPushAppend(ret, lighit); } lighit = sigscanlig_LighitNew(); nsites = 0; nhits=0; prevsn = -1; score = 0; } /* Increment count of sites and hits/patches (for current ligand) and patches (for current site) */ if(hit->Sig->sn != prevsn) nsites++; score+= hit->Score; nhits++; ajStrAssignS(&prev_ligand, hit->Sig->Ligid); prevsn = hit->Sig->sn; } /* Process last hit */ if(nhits) score /= nhits; if(lighit) { lighit->ns = nsites; lighit->np = nhits; lighit->score = score; ajStrAssignS(&lighit->ligid, prev_ligand); ajListPushAppend(ret, lighit); } ajListSort(ret, sigscanlig_MatchinvScore); ajListIterDel(&iter); ajStrDel(&prev_ligand); return ret; }
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 PSilent silent_checktrans(const AjPStr seq,const EmbPMatMatch match, const PRinfo rlp, ajint begin, ajint radj, AjBool rev, ajint end) { PSilent ret; const char *p = NULL; const char *q = NULL; const char *s = NULL; char *t; const char *u; ajint matchpos; ajint framep; ajint count; AjPTrn table = NULL; AjPStr s1 = NULL; AjPStr s2 = NULL; char c; char rc; ajint min = INT_MAX; /* Reverse sense intentional! */ ajint max = -INT_MAX; ajint fpos; ajint rpos; ajint x; AjPStr tstr = NULL; matchpos = match->start; fpos = matchpos; rpos=radj-fpos-match->len; tstr = ajStrNewS(seq); t = ajStrGetuniquePtr(&tstr); p = t+fpos-(begin+1); u = q = ajStrGetPtr(rlp->site); /* Test here for whether cut site is within sequence substring */ if(rlp->ncuts==4) { min = AJMIN(rlp->cut1,rlp->cut2); max = AJMAX(rlp->cut3,rlp->cut4); } else if(rlp->ncuts==2) { min = AJMIN(rlp->cut1,rlp->cut2); max = AJMAX(rlp->cut1,rlp->cut2); } else { ajWarn("Possibly corrupt RE file"); ajStrDel(&tstr); return NULL; } if(!rev) /* forward strand */ { if(matchpos+min<0||matchpos+max>end+1) { /*Cut site not in sequence range*/ ajStrDel(&tstr); return NULL; } } else /* reverse strand */ { if(radj-matchpos-1-min>end+1||radj-matchpos-1-max<begin) { /*Cut site not in sequence range*/ ajStrDel(&tstr); return NULL; } } count=0; while(ajBaseAlphaToBin(*q++) & ajBaseAlphaToBin(*p++)) ++count; /* Changed base postion */ x = fpos+count-(begin+1); /* Where the frame starts on the reverse strand */ framep = (end-begin+1)%3; c = t[x]; rc = u[count]; if(!rev) /* forward strand */ s = t+x-x%3; else /* reverse strand */ s = t+x-(x-framep)%3; table = ajTrnNewI(0); /* translates codon pointed to by s (original seq) */ s1 = ajStrNewK(ajTrnCodonC(table,s)); t[x] = rc; /* translates codon pointed to by s (mutated base from RS pattern */ s2 = ajStrNewK(ajTrnCodonC(table,s)); t[x] = c; /* changes mutated base in seq back to original base */ AJNEW(ret); ret->obase = c; ret->nbase = rc; ret->code = ajStrNewC(ajStrGetPtr(rlp->code)); ret->site = ajStrNewC(ajStrGetPtr(rlp->site)); ret->seqaa = ajStrNewC(ajStrGetPtr(s1)); ret->reaa = ajStrNewC(ajStrGetPtr(s2)); if(ajStrMatchS(s1,s2)) ret->issilent = ajTrue; else ret->issilent = ajFalse; if(!rev) { ret->match = matchpos; ret->base = matchpos+count; } else { ret->match = rpos; ret->base = rpos+match->len-1-count; } ajStrDel(&tstr); ajStrDel(&s1); ajStrDel(&s2); ajTrnDel(&table); return ret; }
static AjPList silent_mismatch(const AjPStr sstr, AjPList relist, AjPStr* tailstr, const AjPStr sname, ajint RStotal, ajint begin, ajint end, AjBool tshow) { PSilent res; AjPList results; AjPStr str; /*holds RS patterns*/ AjPStr tstr; AjBool dummy = ajFalse; /*need a bool for ajPatClassify*/ ajint mm; /*number of mismatches*/ ajint hits; /*number of pattern matches found*/ ajint i; ajint aw; ajint start; AjPList patlist = NULL; /*a list for pattern matches. a list of ..*/ EmbPMatMatch match; /*..AjMatMatch structures*/ PRinfo rlp = NULL; AjPStr pep = NULL; /*string to hold protein*/ AjPTrn table = NULL; /*object to hold translation table*/ AjBool rev = ajFalse; str = ajStrNew(); tstr = ajStrNew(); pep = ajStrNew(); table = ajTrnNewI(0); /*0 stands for standard DNA- see fuzztran.acd*/ results = ajListNew(); start = 1; ajTrnSeqFrameS(table,sstr,1,&pep); /*1 stands for frame number*/ if(tshow) { silent_fmt_sequence("TRANSLATED SEQUENCE", pep,tailstr,start,ajFalse); } for(aw=0;aw<RStotal;aw++) /* loop to read in restriction enzyme patterns */ { /* Pop off the first RE */ ajListPop(relist,(void **)&rlp); /* ignore unknown cut sites and zero cutters */ if(*ajStrGetPtr(rlp->site)=='?'||!rlp->ncuts) { ajListPushAppend(relist,(void*)rlp); continue; } ajStrFmtUpper(&rlp->site); /* convert all RS to upper case */ ajStrFmtUpper(&rlp->revsite); ajStrAssignS(&str,rlp->site); /* str now holds RS patterns */ rev = ajFalse; while (str) { patlist = ajListNew(); if(!embPatClassify(str,&str, &dummy,&dummy,&dummy,&dummy,&dummy,&dummy,0)) continue; mm = 0; hits=embPatBruteForce(sstr,str,ajFalse,ajFalse,patlist,begin+1,mm, sname); if(hits) while(ajListPop(patlist,(void**)&match)) embMatMatchDel(&match); else { mm = 1; hits = embPatBruteForce(sstr,str,ajFalse,ajFalse,patlist, begin+1,mm,sname); if(hits) for(i=0;i<hits;++i) { ajListPop(patlist,(void**)&match); res = silent_checktrans(sstr,match,rlp,begin,rev,end); if (res) ajListPushAppend(results,(void *)res); embMatMatchDel(&match); } } ajListFree(&patlist); if(!rev && !ajStrMatchS(rlp->site, rlp->revsite)) { ajStrAssignS(&str,rlp->revsite); rev = ajTrue; } else ajStrDel(&str); } ajListPushAppend(relist,(void *)rlp); } ajStrDel(&str); ajStrDel(&tstr); ajStrDel(&pep); ajTrnDel(&table); return (results); }
/* @funcstatic acdrelations_writerelations ************************************ ** ** Writes relations: attribute for an ACD data definition ** The relations: values given in knowntypes.standard have highest precedence, ** then the values given in edamtoacd.dat ** Attribute values for a given datatype in edamtoacd.dat are in order of ** increasing precedence, i.e. the last line is highest and the relations: ** value will be used if all conditions are met. ** ** @param [r] outf [AjPFile] ACD output file ** @param [r] acdtype [AjPStr ] ACD datatype, e.g. "align" ** @param [r] strarr [AjPStr*] All ACD attribute lines (whitespace removed) ** for the the current ACD data item (of type ** acdtype). One line per array element. ** @param [r] n [ajint] Size of strarr ** @param [r] P [PEdam] edam object to write ** @param [r] T [PKtype] ktype object to read ** @return [void] ** @@ ******************************************************************************/ static void acdrelations_writerelations (AjPFile outf, AjPStr acdtype, AjPStr *strarr, ajint n, PEdam P, PKtype T) { ajint i = 0; ajint j = 0; ajint k = 0; ajint nmatch = 0; AjPStr relations = NULL; AjPStr ktype = NULL; /* Value of knowntype: attribute */ AjBool done = ajFalse; AjBool donetype = ajFalse; AjPStr tmpstr = NULL; if(!outf || !acdtype || !strarr || !n || !P) ajFatal("NULL args passed to acdrelations_writerelations"); /* Memory allocation */ relations = ajStrNew(); ktype = ajStrNew(); tmpstr = ajStrNew(); /* Loop through all lines in edamtoacd.dat */ for(i=0; i<P->n ;i++) { /* Found matching datatype */ if(ajStrMatchS(acdtype, P->dat[i]->acdtype)) { /* Copy first relations: string defined for this datatype (default) */ ajStrAssignS(&relations, P->dat[i]->edam); done = ajTrue; i++; /* Check next line in edamtoacd.dat */ for( ; i<P->n; i++) { /* Datatype still matches */ if(ajStrMatchS(acdtype, P->dat[i]->acdtype)) { /* Loop through all required attributes for this datatype */ for(nmatch=0, j=0; j<P->dat[i]->n; j++) { /* Loop through all attribute lines for the data defininition */ for(k=0; k<n; k++) if(ajStrMatchS(P->dat[i]->acdattr[j], strarr[k])) { nmatch++; /* ajFmtPrint("Found match %d: %S:%S\n", nmatch, P->dat[i]->acdattr[j], strarr[k]); */ break; } } /* All attribute values match */ if(nmatch == P->dat[i]->n) ajStrAssignS(&relations, P->dat[i]->edam); /* Should never happen */ else if (nmatch > P->dat[i]->n) ajFatal("Terminal weirdness in acdrelations_writerelations"); } else break; } break; } } /* Check for match of knowntype: attribute against knowntypes.standard. These have higher precedence than the rules defined in edamtoacd.dat */ for(donetype=ajFalse, i=0; i<n; i++) { if(ajStrPrefixC(strarr[i], "knowntype:")) { for(j=0;j<T->n; j++) { /* No check is made on the "Type" column in knowntypes.standard as these are not proper ACD datatype names To check these add if(ajStrMatchS(acdtype, T->dat[j]->acdtype)) */ ajFmtPrintS(&tmpstr, "knowntype:\"%S\"", T->dat[j]->ktype); if(ajStrMatchS(tmpstr, strarr[i])) { ajStrAssignS(&relations, T->dat[j]->edam); donetype=ajTrue; break; } } if(donetype) break; } else continue; } if(!done) ajFatal("No matching datatype (%S) in acdrelations_writerelations", acdtype); /* Write relations: attribute line to file */ ajFmtPrintF(outf, " relations:%S\n", relations); /* Free memory */ ajStrDel(&relations); ajStrDel(&ktype); ajStrDel(&tmpstr); return; }
int main(ajint argc, char **argv) { AjPList ccfin = NULL; /* List of CCF (input) files. */ AjPDir pdbin = NULL; /* Path of pdb input files. */ AjPStr pdbprefix = NULL; /* Prefix of pdb input files. */ AjPStr pdb_name = NULL; /* Full name (path/name/extension) of pdb format input file. */ AjPDirout ccfout = NULL; /* Path of coordinate output file. */ AjPStr randomname = NULL; /* Name for temp file tempf. */ AjPStr ccf_this = NULL; AjPStr exec = NULL; AjPStr naccess_str = NULL; AjPStr line = NULL; AjPStr syscmd = NULL; /* Command line arguments. */ AjPStr *mode = NULL; /* Mode of operation from acd. */ AjPFile errf = NULL; /* pdbplus error file pointer. */ AjPFile serrf = NULL; /* stride error file pointer. */ AjPFile nerrf = NULL; /* stride error file pointer. */ AjPFile tempf = NULL; /* Temp file for holding STRIDE output. */ AjPFile ccf_inf = NULL; /* Protein coordinate input file. */ AjPFile ccf_outf = NULL; /* Protein coordinate output file. */ AjIList iter = NULL; AjBool done_naccess= ajFalse; AjBool done_stride = ajFalse; AjBool found = ajFalse; AjPResidue temp_res = NULL; /* Pointer to Residue object. */ AjPPdb pdb_old = NULL; /* Pointer to PDB object - without new stride elements. */ AjPPdb pdb = NULL; /* Pointer to PDB object. */ ajint idn = 0; /* Chain identifier as a number (1,2,...) */ ajint chain_num = 0; /* Chain identifier index (0,1,...). */ ajint tS = 0; /* User-defined threshold size for SSEs. */ ajint nostride = 0; /* No. times stride failed */ ajint nonaccess = 0; /* No. times naccess failed */ ajint nofile = 0; /* No. times of file error */ /* Variables for each item that will be parsed from the ASG line. */ AjPStr res = NULL; /* Residue id from STRIDE ASG line (ALA etc). */ AjPStr res_num = NULL; /* PDB residue number from STRIDE ASG line. */ char pcid = ' '; /* Protein chain identifier from STRIDE or NACESS output (A,B, etc). */ char ss = ' '; /* One-letter secondary structure code from STRIDE ASG line. */ float ph = 0.0; /* Phi angle from STRIDE ASG line. */ float ps = 0.0; /* Psi angle from STRIDE ASG line. */ float sa = 0.0; /* Residue solvent accessible area from STRIDE ASG line. */ float f1 = 0; float f2 = 0; float f3 = 0; float f4 = 0; float f5 = 0; float f6 = 0; float f7 = 0; float f8 = 0; float f9 = 0; float f10 = 0; /* Allocate strings; this section is used for variables that are allocated once only. */ pdb_name = ajStrNew(); res = ajStrNew(); res_num = ajStrNew(); randomname = ajStrNew(); syscmd = ajStrNew(); line = ajStrNew(); naccess_str = ajStrNew(); exec = ajStrNew(); /* Read data from acd. */ embInitPV("pdbplus",argc,argv,"STRUCTURE",VERSION); ccfin = ajAcdGetDirlist("ccfinpath"); pdbin = ajAcdGetDirectory("pdbindir"); pdbprefix = ajAcdGetString("pdbprefix"); ccfout = ajAcdGetOutdir("ccfoutdir"); mode = ajAcdGetList("mode"); errf = ajAcdGetOutfile("logfile"); if(ajStrGetCharFirst(*mode) != '2') serrf = ajAcdGetOutfile("slogfile"); if(ajStrGetCharFirst(*mode) != '1') nerrf = ajAcdGetOutfile("nlogfile"); tS = ajAcdGetInt("thresholdsize"); ajRandomSeed(); ajFilenameSetTempname(&randomname); /* ** Start of main application loop. ** Process each PDB/ protein coordinate file (EMBL format) in turn. */ while(ajListPop(ccfin,(void **)&ccf_this)) { /* Open protein coordinate file. If it cannot be opened, write a message to the error file, delete ccf_this and continue. */ if((ccf_inf = ajFileNewInNameS(ccf_this)) == NULL) { ajWarn("%s%S\n//\n", "clean coordinate file not found: ", ccf_this); ajFmtPrintF(errf, "%s%S\n//\n", "clean coordinate file not found: ", ccf_this); ajStrDel(&ccf_this); nofile++; continue; } ajFmtPrint("Processing %S\n", ccf_this); fflush(stdout); /* Parse protein coordinate data (from clean format file) into AjPPdb object. ajPdbReadAllModelsNew will create the AjPPdb object. */ if(!(pdb_old=ajPdbReadAllModelsNew(ccf_inf))) { ajWarn("ERROR Clean coordinate file read" "error: %S\n//\n", ccf_this); ajFmtPrintF(errf, "ERROR Clean coordinate file read" "error: %S\n//\n", ccf_this); ajFileClose(&ccf_inf); ajStrDel(&ccf_this); nofile++; continue; } ajFileClose(&ccf_inf); ajPdbCopy(&pdb, pdb_old); ajPdbDel(&pdb_old); /* Construct name of corresponding PDB file. NACCESS does *not* generate an output file if the path is './' e.g. naccess ./1rbp.ent , therefore replace './' with null. */ ajStrAssignS(&pdb_name, ajDirGetPath(pdbin)); if(ajStrMatchC(pdb_name, "./") || ajStrMatchC(pdb_name, ".")) ajStrAssignC(&pdb_name, ""); ajStrAppendS(&pdb_name, pdbprefix); ajStrFmtLower(&pdb->Pdb); ajStrAppendS(&pdb_name, pdb->Pdb); ajStrAppendC(&pdb_name, "."); ajStrAppendS(&pdb_name, ajDirGetExt(pdbin)); /* Check corresponding PDB file exists for reading using ajFileStat. */ if(!(ajFilenameExistsRead(pdb_name))) { ajFmtPrintF(errf, "%s%S\n//\n", "PDB file not found: ", pdb_name); ajWarn("%s%S\n//\n", "PDB file not found: ", pdb_name); ajStrDel(&ccf_this); ajPdbDel(&pdb); nofile++; continue; } if(ajStrGetCharFirst(*mode) != '2') { /* ** Create a string containing the STRIDE command line (it needs ** PDB file name & name of temp output file). ** Call STRIDE by using ajSystem. */ ajFmtPrintS(&syscmd, "%S %S -f%S >> %s 2>&1", ajAcdGetpathC("stride"), pdb_name, randomname, ajFileGetNameC(serrf)); ajFmtPrint("%S %S -f%S >> %s 2>&1\n", ajAcdGetpathC("stride"), pdb_name, randomname,ajFileGetNameC(serrf)); system(ajStrGetPtr(syscmd)); /* Open the stride output file */ if (((tempf = ajFileNewInNameS(randomname)) == NULL)) { ajWarn("%s%S\n//\n", "no stride output for: ", pdb_name); ajFmtPrintF(errf, "%s%S\n//\n", "no stride output for: ", pdb_name); nostride++; ajStrDel(&ccf_this); ajPdbDel(&pdb); continue; } else ajFmtPrintF(errf, "%s%S\n//\n", "stride output for: ", pdb_name); done_stride = ajFalse; /* Parse STRIDE output from temp output file a line at a time. */ while(ajReadlineTrim(tempf,&line)) { if(ajStrPrefixC(line,"ASG")) { ajFmtScanS(line, "%*S %S %c %S %*d %c %*S %f %f %f %*S", &res, &pcid, &res_num, &ss, &ph, &ps, &sa); /* ** Populate pdbplus object with the data from this parsed ** line. This means first identifying the chain, then ** finding the residue. */ /* Determine the chain number. ajDmxPdbplusChain does not recognise '-', so change '-' to '.' */ if (pcid == '-') pcid = '.'; /* Get chain number from the chain identifier. */ if(!ajPdbChnidToNum(pcid, pdb, &idn)) { ajWarn("Could not convert chain id %c to chain" " number in pdb file %S\n//\n", pcid, pdb_name); ajFmtPrintF(errf, "Could not convert chain id %c " "to chain number in pdb file %S\n//\n", pcid, pdb_name); continue; } /* ** The chain number that will get written starts at 1, but ** we want an index into an array which must start at 0, ** so subtract 1 from the chain number to get the index. */ chain_num = idn-1; /* ** Iiterate through the list of residues in the Pdb object, ** found switches to true when first residue corresponding ** to the line is found. */ /* iter = ajListIterNewread(pdb->Chains[chain_num]->Atoms); */ iter = ajListIterNewread(pdb->Chains[chain_num]->Residues); found = ajFalse; while((temp_res = (AjPResidue)ajListIterGet(iter))) { /* If we have found the residue we want */ if((ajStrMatchS(res_num, temp_res->Pdb) && ajStrMatchS(res, temp_res->Id3))) { done_stride = ajTrue; found = ajTrue; temp_res->eStrideType = ss; temp_res->Phi = ph; temp_res->Psi = ps; temp_res->Area = sa; } /* If the matching residue has been processed move on to next ASG line, next residue. */ else if(found == ajTrue) break; else /* Matching residue not found yet. */ continue; } ajListIterDel(&iter); } /* End of if ASG loop. */ } /* End of while line loop. */ if(done_stride) ajFmtPrintF(errf, "%s%S\n//\n", "stride data for: ", pdb_name); else { ajFmtPrintF(errf, "%s%S\n//\n", "no stride data for: ", pdb_name); ajWarn("%s%S\n//\n", "no stride data for: ", pdb_name); nostride++; } /* Close STRIDE temp file. & tidy up. */ ajFileClose(&tempf); /* Remove temporary file (stride output file). */ ajFmtPrintS(&exec, "rm %S", randomname); ajSysSystem(exec); /* ** Calculate element serial numbers (eStrideNum)& ammend residue ** objects, count no's of elements and ammend chain object ** (numHelices, num Strands). */ pdbplus_sort(pdb, tS); } if(ajStrGetCharFirst(*mode) != '1') { /* ** Create a string containing the NACCESS command line (it needs ** PDB file name & name of temp output file) & call NACCESS. ** If e.g. /data/structure/pdbfred.ent was parsed and the program ** was run from /stuff, then /stuff/fred.asa and /stuff/fred.rsa ** would be written. These must be deleted once parsed (only ** use the .rsa file here). */ ajFmtPrintS(&syscmd, "%S %S >> %s 2>&1", ajAcdGetpathC("naccess"), pdb_name, ajFileGetNameC(nerrf)); ajFmtPrint("%S %S >> %s 2>&1\n", ajAcdGetpathC("naccess"), pdb_name, ajFileGetNameC(nerrf)); system(ajStrGetPtr(syscmd)); ajStrAssignS(&naccess_str, pdbprefix); ajStrAppendS(&naccess_str, pdb->Pdb); ajStrAppendC(&naccess_str, ".rsa"); /* Open the NACCESS output file. */ if (((tempf = ajFileNewInNameS(naccess_str)) == NULL)) { ajFmtPrintF(errf, "%s%S\n//\n", "no naccess output for: ", pdb_name); ajWarn("%s%S\n//\n", "no naccess output for: ", pdb_name); nonaccess++; ajStrDel(&ccf_this); ajPdbDel(&pdb); continue; } else ajFmtPrintF(errf, "%s%S\n//\n", "naccess output for: ", pdb_name); done_naccess = ajFalse; /* Parse NACCESS output from temp output file a line at a time. */ while(ajReadlineTrim(tempf,&line)) { if(ajStrPrefixC(line,"RES")) { /* Read data from lines. */ if((pcid = line->Ptr[8]) == ' ') ajFmtScanS(line, "%*S %S %S %f %f %f " "%f %f %f %f %f %f %f", &res, &res_num, &f1, &f2, &f3, &f4, &f5, &f6, &f7, &f8, &f9, &f10); else ajFmtScanS(line, "%*S %S %*c %S %f %f " "%f %f %f %f %f %f %f %f", &res, &res_num, &f1, &f2, &f3, &f4, &f5, &f6, &f7, &f8, &f9, &f10); /* Identify the chain, then finding all the residues corresponding to the residue. */ /* Get the chain number from the chain identifier. */ if(!ajPdbChnidToNum(pcid, pdb, &idn)) { ajWarn("Could not convert chain id %c to chain" " number in pdb file %S\n//\n", pcid, pdb_name); ajFmtPrintF(errf, "Could not convert chain id" " %c to chain number in pdb file %S\n//\n", pcid, pdb_name); continue; } /* ** Chain number will start at 1, but we want an index ** into an array which must start at 0, so subtract 1 ** from the chain number to get the index. */ chain_num = idn-1; /* ** Iiterate through the list of residues in the Pdb object, ** temp_res is an AjPResidue used to point to the current ** residue. ** ajBool found switches to true when first residue ** corresponding to the line is found. */ iter = ajListIterNewread(pdb->Chains[chain_num]->Residues); found = ajFalse; while((temp_res = (AjPResidue)ajListIterGet(iter))) { /* If we have found the residue we want, write the residue object. */ if((ajStrMatchS(res_num, temp_res->Pdb) && ajStrMatchS(res, temp_res->Id3))) { found = ajTrue; done_naccess = ajTrue; temp_res->all_abs = f1; temp_res->all_rel = f2; temp_res->side_abs = f3; temp_res->side_rel = f4; temp_res->main_abs = f5; temp_res->main_rel = f6; temp_res->npol_abs = f7; temp_res->npol_rel = f8; temp_res->pol_abs = f9; temp_res->pol_rel = f10; } /* If the matching residues have all been processed. move on to next ASG line, next residue. */ else if(found == ajTrue) break; else /* Matching residues not found yet, move on to next residue. */ continue; } ajListIterDel(&iter); } } if(done_naccess) ajFmtPrintF(errf, "%s%S\n//\n", "naccess data for: ", pdb_name); else { ajFmtPrintF(errf, "%s%S\n//\n", "no naccess data for: ", pdb_name); ajWarn("%s%S\n//\n", "no naccess data for: ", pdb_name); nonaccess++; } /* Remove temporary file (naccess output files). */ ajFileClose(&tempf); ajFmtPrintS(&exec, "rm %S", naccess_str); ajSysSystem(exec); ajStrAssignS(&naccess_str, pdbprefix); ajStrAppendS(&naccess_str, pdb->Pdb); ajStrAppendC(&naccess_str, ".asa"); ajFmtPrintS(&exec, "rm %S", naccess_str); ajSysSystem(exec); ajStrAssignS(&naccess_str, pdbprefix); ajStrAppendS(&naccess_str, pdb->Pdb); ajStrAppendC(&naccess_str, ".log"); ajFmtPrintS(&exec, "rm %S", naccess_str); ajSysSystem(exec); } /* Open CCF (output) file. */ ccf_outf = ajFileNewOutNameDirS(pdb->Pdb, ccfout); /* Write AjPPdb object to the output file in clean format. */ if(!ajPdbWriteAll(ccf_outf, pdb)) { ajWarn("%s%S\n//\n","Could not write results file for: ", pdb->Pdb); ajFmtPrintF(errf,"%s%S\n//\n","Could not write results file for ", pdb->Pdb); } ajFileClose(&ccf_outf); ajPdbDel(&pdb); ajStrDel(&ccf_this); } /* End of main application loop. */ ajFmtPrint("STRIDE failures: %d\n", nostride); ajFmtPrint("NACCESS failures: %d\n", nonaccess); ajFmtPrintF(errf, "\n\nSTRIDE failures: %d\nNACCESS failures: %d\n", nostride, nonaccess); ajListFree(&ccfin); ajDirDel(&pdbin); ajStrDel(&pdbprefix); ajStrDel(&pdb_name); ajDiroutDel(&ccfout); ajStrDel(&res); ajStrDel(&res_num); ajStrDel(&randomname); ajStrDel(&line); ajStrDel(&naccess_str); ajStrDel(&exec); ajStrDel(&syscmd); ajFileClose(&errf); if(ajStrGetCharFirst(*mode) != '2') ajFileClose(&serrf); if(ajStrGetCharFirst(*mode) != '1') ajFileClose(&nerrf); ajStrDel(&mode[0]); AJFREE(mode); ajExit(); return 0; }
int main(int argc, char **argv) { /* Variable declarations */ AjPOutfile outfile = NULL; AjPStr* ranks = NULL; AjBool hidden = ajFalse; AjPTax tax = NULL; AjPTax taxparent = NULL; AjPTaxall taxall = NULL; AjPTaxin taxinparent = NULL; AjPStr taxqryup = NULL; AjPTable foundtable = NULL; const AjPStr taxrank = NULL; ajuint up; AjPList uplist = NULL; ajuint i; /* ACD processing */ embInit("taxgetrank", argc, argv); taxall = ajAcdGetTaxonall("taxons"); ranks = ajAcdGetList("rank"); outfile = ajAcdGetOuttaxon("outfile"); hidden = ajAcdGetBoolean("hidden"); for(i=0; ranks[i]; i++) { ajStrExchangeKK(&ranks[i], '_', ' '); } taxinparent = ajTaxinNew(); taxparent = ajTaxNew(); uplist = ajListNew(); foundtable = ajTablestrNew(600); while(ajTaxallNext(taxall, &tax)) { up = ajTaxGetParent(tax); while (up > 1) { ajFmtPrintS(&taxqryup, "%S-id:%u", ajTaxGetDb(tax), up); ajTaxinQryS(taxinparent, taxqryup); if(!ajTaxinRead(taxinparent, taxparent)) break; if(hidden || !ajTaxIsHidden(taxparent)) { taxrank = ajTaxGetRank(taxparent); for(i=0; ranks[i]; i++) { if(ajStrMatchS(taxrank, ranks[i])) { if(!ajTableMatchS(foundtable, taxparent->Id)) { ajTaxoutWrite(outfile, taxparent); ajTablePut(foundtable, ajStrNewS(taxparent->Id), (void *) 1); } } } } up = ajTaxGetParent(taxparent); } } /* Memory clean-up and exit */ ajTaxallDel(&taxall); ajTaxinDel(&taxinparent); ajTaxDel(&tax); ajTaxDel(&taxparent); ajListFree(&uplist); ajTablestrFreeKey(&foundtable); ajStrDel(&taxqryup); ajStrDelarray(&ranks); ajOutfileClose(&outfile); embExit(); return 0; }
int main(int argc, char **argv) { /* Variable declarations */ AjPStr dbname = NULL; AjPStr svrname = NULL; AjPFile outfile = NULL; AjPResource resource = NULL; AjPResourcein resourcein = NULL; AjPStr resourceqry = NULL; AjPStr type = NULL; AjBool id; AjBool qry; AjBool all; AjBool verbose; AjPStr methods = NULL; AjPStr release = NULL; AjPStr comment = NULL; AjPStr defined = NULL; AjPList list = NULL; AjPTagval tagval = NULL; AjIList iter = NULL; ajuint space = 0; AjPList aliaslist = NULL; AjIList aliter = NULL; const AjPStr alias = NULL; ajuint maxlen; AjPStr truedbname = NULL; AjBool isalias = ajFalse; /* ACD processing */ embInit("dbtell", argc, argv); dbname = ajAcdGetString("database"); svrname = ajAcdGetString("server"); verbose = ajAcdGetBoolean("full"); outfile = ajAcdGetOutfile("outfile"); ajStrAssignS(&truedbname, dbname); ajNamAliasDatabase(&truedbname); ajStrFmtLower(&truedbname); if(!ajStrMatchS(dbname, truedbname)) isalias = ajTrue; /* Application logic */ /* Check EMBOSS database information. Write output file */ if(ajNamDbDetailsSvr(truedbname, svrname, &type, &id, &qry, &all, &comment, &release, &methods, &defined)) { if(isalias) ajFmtPrintF(outfile, "# %S is an alias for %S defined in %S\n", dbname, truedbname, defined); else ajFmtPrintF(outfile, "# %S is defined in %S\n", truedbname, defined); ajFmtPrintF(outfile, "# access levels id: %B query: %B all: %B\n\n", id, qry, all); ajFmtPrintF(outfile, "DBNAME %S [\n", truedbname); if(ajStrGetLen(svrname)) list = ajNamDbGetAttrlistSvr(truedbname, svrname); else list = ajNamDbGetAttrlist(truedbname); iter = ajListIterNewread(list); while(!ajListIterDone(iter)) { tagval = ajListIterGet(iter); space = 15 - ajStrGetLen(ajTagvalGetTag(tagval)); ajFmtPrintF(outfile, " %S:%.*s\"%S\"\n", ajTagvalGetTag(tagval), space, " ", ajTagvalGetValue(tagval)); ajTagvalDel(&tagval); } ajListIterDel(&iter); ajListFree(&list); ajFmtPrintF(outfile, "]\n"); if(verbose) { aliaslist = ajListNew(); ajNamListFindAliases(truedbname, aliaslist); if(ajListGetLength(aliaslist)) { ajFmtPrintF(outfile, "\n"); aliter = ajListIterNewread(aliaslist); maxlen = 1; while(!ajListIterDone(aliter)) { alias = ajListIterGet(aliter); if(MAJSTRGETLEN(alias) > maxlen) maxlen = MAJSTRGETLEN(alias); } ajListIterDel(&aliter); aliter = ajListIterNewread(aliaslist); while(!ajListIterDone(aliter)) { alias = ajListIterGet(aliter); if(ajStrFindK(alias, ':') < 0) ajFmtPrintF(outfile, "ALIAS %-*S %S\n", maxlen, alias, truedbname); } ajListIterDel(&aliter); } ajListstrFree(&aliaslist); } ajStrDel(&type); ajStrDel(&methods); ajStrDel(&release); ajStrDel(&comment); ajStrDel(&defined); } else { /* try looking in DRCAT */ resourcein = ajResourceinNew(); resource = ajResourceNew(); ajFmtPrintS(&resourceqry, "drcat:%S", dbname); ajResourceinQryS(resourcein, resourceqry); if(ajResourceinRead(resourcein, resource)) { ajFmtPrintF(outfile, "DBNAME %S [\n", dbname); ajFmtPrintF(outfile, " comment: \"defined in DRCAT\"\n"); ajFmtPrintF(outfile, "]\n"); } ajResourceinDel(&resourcein); ajResourceDel(&resource); ajStrDel(&resourceqry); } /* Memory clean-up and exit */ ajFileClose(&outfile); ajStrDel(&truedbname); ajStrDel(&dbname); ajStrDel(&svrname); embExit(); return 0; }