AjBool ajAssemoutformatFind(const AjPStr format, ajint* iformat) { AjPStr tmpformat = NULL; ajuint i = 0; /* ajDebug("ajAssemoutformatFind '%S'\n", format); */ if(!ajStrGetLen(format)) return ajFalse; ajStrAssignS(&tmpformat, format); ajStrFmtLower(&tmpformat); for(i=0; assemoutFormatDef[i].Name; i++) { /* ajDebug("test %d '%s' \n", i, assemoutFormatDef[i].Name); */ if(ajStrMatchCaseC(tmpformat, assemoutFormatDef[i].Name)) { *iformat = i; ajStrDel(&tmpformat); /* ajDebug("found '%s' at %d\n", assemoutFormatDef[i].Name, i); */ return ajTrue; } } ajErr("Unknown output format '%S'", format); ajStrDel(&tmpformat); *iformat = 0; return ajFalse; }
static void makeprotseq_parse_pepstats(AjPList* list,AjPFile data) { AjPStr line = ajStrNew(); AjPStr ch; AjPStr chcopy = NULL; const AjPStr tok; double value = 0.0; ajint count = 0; ajint i = 0; ajDebug("Parsing pepstats file.\n"); /* skip the lines before residues */ while(ajReadline(data,&line)) { if(ajStrFindC(line,"Residue") == 0) break; } /* parse residue part */ while(ajReadlineTrim(data,&line)) { if(ajStrParseCountC(line," \t") == 0) break; ch = ajStrNew(); tok = ajStrParseWhite(line); ajStrAppendS(&ch,tok); ajStrFmtLower(&ch); for(count = 1; count < 5; count++) tok = ajStrParseWhite(NULL); ajStrToDouble(tok,&value); count = (ajint) (value * 100) + ((value - (int) value ) >= 0.5 ? 1 : 0); for(i=0; i<count; i++) { chcopy = ajStrNewS(ch); ajListstrPush(*list,chcopy); } ajStrDel(&ch); } ajStrDel(&line); return; }
static void trimest_tolower(AjPStr *strng, ajint start, ajint end) { AjPStr substr; substr = ajStrNew(); /* extract the region and lowercase */ ajStrAppendSubS(&substr, *strng, start, end); ajStrFmtLower(&substr); /* remove and replace the lowercased region */ ajStrCutRange(strng, start, end); ajStrInsertS(strng, start, substr); ajStrDel(&substr); return; }
AjPPatlistRegex ajPatlistRegexRead (const AjPStr patspec, const AjPStr patname, const AjPStr fmt, ajuint type, AjBool upper, AjBool lower) { AjPPatlistRegex patlist = NULL; AjPStr line = NULL; AjPStr pat = NULL; AjPStr name = NULL; AjPFilebuff infile = NULL; AjPStr patstr = NULL; ajuint ifmt; ajuint npat = 0; AjPStr namestr = NULL; ajStrAssignS(&namestr, patname); ajStrAssignEmptyC(&namestr, "regex"); ajStrAssignS(&patstr, patspec); patlist = ajPatlistRegexNewType(type); ifmt = patternRegexFormat(fmt); if(ajStrGetCharFirst(patspec) == '@') { ajStrCutStart(&patstr, 1); infile = ajFilebuffNewNameS(patstr); if(!infile) { ajErr("Unable to open regular expression file '%S'", patstr); return NULL; } line = ajStrNew(); pat = ajStrNew(); name = ajStrNew(); if(!ifmt) { ajBuffreadLineTrim(infile,&line); if(ajStrPrefixC(line, ">")) ifmt = 2; else ifmt = 1; ajFilebuffReset(infile); } switch(ifmt) { case 1: while (ajBuffreadLineTrim(infile,&line)) { npat++; ajStrAppendS (&pat,line); if(lower) ajStrFmtLower(&pat); if(upper) ajStrFmtUpper(&pat); ajFmtPrintS(&name, "%S%u", namestr, npat); ajPatternRegexNewList(patlist,name,pat); ajStrSetClear(&pat); } break; default: while (ajBuffreadLineTrim(infile,&line)) { if (ajStrFindC(line,">")>-1) { npat++; if (ajStrGetLen(name)) { if(lower) ajStrFmtLower(&pat); if(upper) ajStrFmtUpper(&pat); ajPatternRegexNewList(patlist,name,pat); ajStrSetClear(&name); ajStrSetClear(&pat); } ajStrCutStart(&line,1); ajStrAssignS (&name,line); if(!ajStrGetLen(name)) ajFmtPrintS(&name, "%S%u", namestr, npat); } else ajStrAppendS (&pat,line); } ajStrAssignEmptyS(&name, patname); ajPatternRegexNewList(patlist,name,pat); ajStrSetClear(&pat); break; } ajFilebuffDel(&infile); } else { ajStrAssignS(&pat, patspec); if(lower) ajStrFmtLower(&pat); if(upper) ajStrFmtUpper(&pat); ajStrAssignS(&name, namestr); ajPatternRegexNewList(patlist,name,pat); } ajStrDel(&name); ajStrDel(&namestr); ajStrDel(&patstr); ajStrDel(&line); ajStrDel(&pat); return patlist; }
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; }
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; }
int main(int argc, char **argv) { ajint famn = 0; /* Counter for the families. */ ajint nset = 0; /* No. entries in family. */ ajint last_nodeid = 0; /* SCOP Sunid of last family that was processed. */ AjPStr last_node = NULL; /* Last family that was processed. */ AjPStr exec = NULL; /* The UNIX command line to be executed. */ AjPStr out = NULL; /* Name of stamp alignment file. */ AjPStr align = NULL; /* Name of sequence alignment file. */ AjPStr alignc = NULL; /* Name of structure alignment file. */ AjPStr log = NULL; /* Name of STAMP log file. */ AjPStr dom = NULL; /* Name of file containing single domain. */ AjPStr set = NULL; /* Name of file containing set of domains. */ AjPStr scan = NULL; /* Name of temp. file used by STAMP. */ AjPStr sort = NULL; /* Name of temp. file used by STAMP. */ AjPStr name = NULL; /* Base name of STAMP temp files. */ AjPStr pdbnames = NULL; /* Names of domain pdb files to be passed to TCOFFEEE. */ AjPDir pdb = NULL; /* Path of domain coordinate files (pdb format input). */ AjPDirout daf = NULL; /* Path of sequence alignment files for output. */ AjPDirout super = NULL; /* Path of structure alignment files for output. */ AjPDirout singlets = NULL; /* Path of FASTA singlet sequence files for output. */ AjPStr temp1 = NULL; /* A temporary string. */ AjPFile dcfin = NULL; /* File pointer for original Escop.dat file.*/ AjPFile domf = NULL; /* File pointer for single domain file. */ AjPFile setf = NULL; /* File pointer for domain set file. */ AjPFile logf = NULL; /* Log file. */ AjPDomain domain = NULL; /* Pointer to domain structure. */ AjPDomain prevdomain = NULL; /* Pointer to previous domain structure. */ ajint type = 0; /* Type of domain (ajSCOP or ajCATH) in the DCF file. */ AjPStr *node = NULL; /* Node of alignment . */ ajint noden = 0; /*1: Class (SCOP), 2: Fold (SCOP) etc, see ACD file. */ AjPStr *mode = NULL; /* Mode of operation from acd*/ ajint moden = 0; /* Program mode, 1: MODE_STAMP, 2: MODE_TCOFFEE (not yet implemented). */ AjBool keepsinglets= ajFalse; /*Whether to retain sequences of singlet families and write them to an output file. */ AjPStr temp = NULL; /* A temporary string. */ AjPStr cmd = NULL; /* The command line to execute t-coffee. */ /* Initialise strings etc*/ last_node = ajStrNew(); exec = ajStrNew(); out = ajStrNew(); align = ajStrNew(); alignc = ajStrNew(); log = ajStrNew(); dom = ajStrNew(); set = ajStrNew(); scan = ajStrNew(); sort = ajStrNew(); name = ajStrNew(); temp = ajStrNew(); temp1 = ajStrNew(); cmd = ajStrNew(); pdbnames = ajStrNew(); /* Read data from acd. */ embInitPV("domainalign",argc,argv,"DOMALIGN",VERSION); dcfin = ajAcdGetInfile("dcfinfile"); pdb = ajAcdGetDirectory("pdbdir"); daf = ajAcdGetOutdir("dafoutdir"); super = ajAcdGetOutdir("superoutdir"); singlets = ajAcdGetOutdir("singletsoutdir"); node = ajAcdGetList("node"); mode = ajAcdGetList("mode"); keepsinglets = ajAcdGetToggle("keepsinglets"); logf = ajAcdGetOutfile("logfile"); /* Convert the selected node and mode to an integer. */ if(!(ajStrToInt(node[0], &noden))) ajFatal("Could not parse ACD node option"); if(!(ajStrToInt(mode[0], &moden))) ajFatal("Could not parse ACD node option"); /* Initialise random number generator for naming of temp. files. */ ajRandomSeed(); ajFilenameSetTempname(&name); /* Create names for temp. files. */ ajStrAssignS(&log, name); ajStrAppendC(&log, ".log"); ajStrAssignS(&dom, name); ajStrAppendC(&dom, ".dom"); ajStrAssignS(&set, name); ajStrAppendC(&set, ".set"); ajStrAssignS(&scan, name); ajStrAppendC(&scan, ".scan"); ajStrAssignS(&sort, name); ajStrAppendC(&sort, ".sort"); ajStrAssignS(&out, name); ajStrAppendC(&out, ".out"); /* Initialise last_node with something that is not in SCOP. */ ajStrAssignC(&last_node,"!!!!!"); /* Open STAMP domain set file. */ if(moden == MODE_STAMP) { if(!(setf=ajFileNewOutNameS(set))) ajFatal("Could not open domain set file\n"); } /* Get domain type. */ type = ajDomainDCFType(dcfin); /* Start of main application loop. */ while((domain=(ajDomainReadCNew(dcfin, "*", type)))) { /* A new family. */ if(((domain->Type == ajSCOP) && (((noden==1) && (last_nodeid != domain->Scop->Sunid_Class)) || ((noden==2) && (last_nodeid != domain->Scop->Sunid_Fold)) || ((noden==3) && (last_nodeid != domain->Scop->Sunid_Superfamily))|| ((noden==4) && (last_nodeid != domain->Scop->Sunid_Family)))) || ((domain->Type == ajCATH) && (((noden==5) && (last_nodeid != domain->Cath->Class_Id)) || ((noden==6) && (last_nodeid != domain->Cath->Arch_Id)) || ((noden==7) && (last_nodeid != domain->Cath->Topology_Id)) || ((noden==8) && (last_nodeid != domain->Cath->Superfamily_Id)) || ((noden==9) && (last_nodeid != domain->Cath->Family_Id))))) { /* If we have done the first family. */ if(famn) { /* Create the output file for the alignment - the name will be the same as the Sunid for the DOMAIN family. */ domainalign_writeid(prevdomain, noden, daf, super, &align, &alignc); if(moden == MODE_STAMP) { /* Close domain set file. */ ajFileClose(&setf); /* Call STAMP. */ /* Family with 2 or more entries. */ if(nset > 1) { domainalign_stamp(prevdomain, domain, daf, super, singlets, align, alignc, dom, name, set, scan, sort, log, out, keepsinglets, moden, noden, nset, logf); } else if(keepsinglets) /* Singlet family. */ domainalign_keepsinglets(prevdomain, noden, singlets, logf); /* Open STAMP domain set file. */ if(!(setf=ajFileNewOutNameS(set))) ajFatal("Could not open domain set file\n"); } else { /* Call TCOFEE. */ if(nset > 1) domainalign_tcoffee(prevdomain, out, align, alignc, pdbnames, noden, logf); else if(keepsinglets) /* Singlet family. */ domainalign_keepsinglets(prevdomain, noden, singlets, logf); } /* Set the number of members of the new family to zero. */ nset = 0; /* Clear TCOFFEE argument. */ ajStrSetClear(&pdbnames); } /* Open, write and close STAMP domain file. */ if(moden == MODE_STAMP) { if(!(domf=ajFileNewOutNameS(dom))) ajFatal("Could not open domain file\n"); ajStrAssignS(&temp, ajDomainGetId(domain)); ajStrFmtLower(&temp); ajFmtPrintF(domf, "%S %S { ALL }\n", temp, temp); ajFileClose(&domf); } /* Copy current family name to last_node. */ domainalign_writelast(domain, noden, &last_node, &last_nodeid); /* Copy current domain pointer to prevdomain. */ ajDomainDel(&prevdomain); prevdomain=NULL; ajDomainCopy(&prevdomain, domain); /* Increment family counter. */ famn++; } ajStrAssignS(&temp, ajDomainGetId(domain)); ajStrFmtLower(&temp); /* Write STAMP domain set file. */ if(moden == MODE_STAMP) ajFmtPrintF(setf, "%S %S { ALL }\n", temp, temp); /* Write TCOFFEE argument. */ else { ajStrAppendS(&pdbnames, ajDirGetPath(pdb)); ajStrAppendS(&pdbnames, temp); ajStrAppendC(&pdbnames, "."); ajStrAppendS(&pdbnames, ajDirGetExt(pdb)); ajStrAppendC(&pdbnames, " "); } ajDomainDel(&domain); /* Increment number of members in family. */ nset++; } /* End of main application loop. */ domain=prevdomain; ajFmtPrint("\nProcessing node %d\n", last_nodeid); /* Create the output file for the alignment - the name will be the same as the Sunid for the DOMAIN family. */ domainalign_writeid(prevdomain, noden, daf, super, &align, &alignc); /* Code to process last family. */ if(moden == MODE_STAMP) { /*Close domain set file. */ ajFileClose(&setf); /* ajFmtPrint("\n***** SECOND CALL\n");. */ if(nset > 1) { domainalign_stamp(prevdomain, domain, daf, super, singlets, align, alignc, dom, name, set, scan, sort, log, out, keepsinglets, moden, noden, nset, logf); } else if(keepsinglets) /* Singlet family. */ domainalign_keepsinglets(prevdomain, noden, singlets, logf); } else { /* Call TCOFEE. */ if(nset > 1) domainalign_tcoffee(prevdomain, out, align, alignc, pdbnames, noden, logf); else if(keepsinglets) /* Singlet family. */ domainalign_keepsinglets(prevdomain, noden, singlets, logf); } /* Remove all temporary files. */ ajSysFileUnlinkS(log); ajSysFileUnlinkS(dom); ajSysFileUnlinkS(set); ajSysFileUnlinkS(scan); ajSysFileUnlinkS(sort); ajSysFileUnlinkS(out); ajStrAssignS(&temp, name); ajStrAppendC(&temp, ".mat"); ajSysFileUnlinkS(temp); /* Tidy up*/ ajDomainDel(&domain); ajFileClose(&dcfin); ajStrDel(&last_node); ajStrDel(&exec); ajStrDel(&log); ajStrDel(&dom); ajStrDel(&set); ajStrDel(&scan); ajStrDel(&sort); ajStrDel(&name); ajStrDel(&out); ajStrDel(&align); ajStrDel(&alignc); ajStrDel(&pdbnames); ajDirDel(&pdb); ajDiroutDel(&daf); ajDiroutDel(&super); ajDiroutDel(&singlets); ajStrDel(&temp); ajStrDel(&temp1); ajStrDel(&node[0]); AJFREE(node); ajStrDel(&mode[0]); AJFREE(mode); ajFileClose(&logf); ajExit(); return 0; }
int main(int argc, char** argv) { AjPFile outf = NULL; AjPFile cachef = NULL; AjIList iterator = NULL; AjPList aliases = NULL; AjPList dbas = NULL; AjPList species = NULL; AjPStr alias = NULL; AjPStr dbname = NULL; AjPStr spname = NULL; AjPStr svrname = NULL; AjPStr svrurl = NULL; AjPStr dbcurl = NULL; AjPTime svrtime = NULL; EnsEDatabaseadaptorGroup dbag = ensEDatabaseadaptorGroupNULL; EnsPDatabaseadaptor dba = NULL; EnsPDatabaseconnection dbc = NULL; embInit("cacheensembl", argc, argv); ensInit(); svrname = ajAcdGetString("servername"); outf = ajAcdGetOutfile("outfile"); cachef = ajAcdGetOutfile("cachefile"); dbcurl = ajStrNew(); svrurl = ajStrNew(); dbname = ajStrNew(); ajNamSvrGetUrl(svrname, &svrurl); if(!svrurl) ajFatal("Could not resolve server name '%S'.", svrname); dbc = ensDatabaseconnectionNewUrl(svrurl); ensRegistryLoadDatabaseconnection(dbc); ensDatabaseconnectionDel(&dbc); /* Write the server file header. */ svrtime = ajTimeNewTodayFmt("cachefile"); ajFmtPrintF(cachef, "# %S %D\n", ajFileGetNameS(cachef), svrtime); ajTimeDel(&svrtime); ajFmtPrintF(cachef, "# Automatically generated by cacheensembl " "for server '%S'.\n\n", svrname); /* ** Get all Ensembl Database Adaptor objects and write them as ** EMBOSS Database definitions. */ aliases = ajListstrNew(); dbas = ajListNew(); species = ajListstrNew(); ensRegistryRetrieveAllSpecies(species); while(ajListstrPop(species, &spname)) { ensRegistryGetAllDatabaseadaptors(ensEDatabaseadaptorGroupNULL, spname, dbas); while(ajListPop(dbas, (void**) &dba)) { dbag = ensDatabaseadaptorGetGroup(dba); if(dbag == ensEDatabaseadaptorGroupNULL) { ajDebug("cacheensembl main got unexpected " "Ensembl Database Adaptor Group %d.\n", dbag); continue; } ajStrAssignS(&dbname, ensDatabaseadaptorGetSpecies(dba)); if(dbag != ensEDatabaseadaptorGroupCore) { ajStrAppendC(&dbname, "_"); ajStrAppendC(&dbname, ensDatabaseadaptorGroupToChar(dbag)); } dbc = ensDatabaseadaptorGetDatabaseconnection(dba); ensDatabaseconnectionFetchUrl(dbc, &dbcurl); if(outf) ajFmtPrintF(outf, "%S\n", dbname); ajFmtPrintF(cachef, "DBNAME %S [\n", dbname); ajFmtPrintF(cachef, " release: \"%s\"\n", ensSoftwareGetVersion()); ajFmtPrintF(cachef, " server: \"%S\"\n", svrname); ajFmtPrintF(cachef, " url: \"%S\"\n", dbcurl); ajFmtPrintF(cachef, "]\n"); ajFmtPrintF(cachef, "\n"); if(dbag != ensEDatabaseadaptorGroupCore) continue; ensRegistryAliasFetchAllbySpecies( ensDatabaseadaptorGetSpecies(dba), aliases); /* ** Format all aliases to lower case, ** sort them alphabetically and remove duplicates. */ iterator = ajListIterNew(aliases); while(!ajListIterDone(iterator)) { alias = ajListstrIterGet(iterator); ajStrFmtLower(&alias); } ajListIterDel(&iterator); ajListSortUnique(aliases, cacheensembl_stringcompare, cacheensembl_stringdelete); alias = NULL; if(ajListGetLength(aliases) > 0) { while(ajListstrPop(aliases, &alias)) { /* ** Reject any aliases with other than alpha-numeric ** characters like white space. */ if(ajStrIsAlnum(alias)) ajFmtPrintF(cachef, "ALIAS %S %S\n", alias, ensDatabaseadaptorGetSpecies(dba)); ajStrDel(&alias); } ajFmtPrintF(cachef, "\n"); } /* Ensembl Database Adaptor objects *must not* be deleted. */ } ajStrDel(&spname); } ajListstrFree(&aliases); ajListFree(&dbas); ajStrDel(&dbcurl); ajStrDel(&svrurl); ajStrDel(&dbname); ajStrDel(&svrname); ajFileClose(&outf); ajFileClose(&cachef); embExit(); return EXIT_SUCCESS; }
int main(int argc, char **argv) { EmbPBtreeEntry entry = NULL; AjPStr dbname = NULL; AjPStr dbrs = NULL; AjPStr release = NULL; AjPStr datestr = NULL; AjBool statistics; AjBool compressed; AjPStr directory; AjPStr indexdir; AjPStr filename; AjPStr exclude; AjPStr dbtype = NULL; AjPFile outf = NULL; AjPStr *fieldarray = NULL; ajint nfields; ajint nfiles; AjPStr tmpstr = NULL; AjPStr thysfile = NULL; ajint i; AjPFile inf = NULL; AjPStr word = NULL; AjPBtId idobj = NULL; AjPBtPri priobj = NULL; AjPBtHybrid hyb = NULL; ajulong nentries = 0L; ajulong ientries = 0L; AjPTime starttime = NULL; AjPTime begintime = NULL; AjPTime nowtime = NULL; ajlong startclock = 0; ajlong beginclock = 0; ajlong nowclock = 0; ajulong idcache=0L, idread = 0L, idwrite = 0L, idsize= 0L; ajulong accache=0L, acread = 0L, acwrite = 0L, acsize= 0L; ajulong svcache=0L, svread = 0L, svwrite = 0L, svsize= 0L; ajulong kwcache=0L, kwread = 0L, kwwrite = 0L, kwsize= 0L; ajulong decache=0L, deread = 0L, dewrite = 0L, desize= 0L; ajulong txcache=0L, txread = 0L, txwrite = 0L, txsize= 0L; double tdiff = 0.0; ajint days = 0; ajint hours = 0; ajint mins = 0; embInit("dbxflat", argc, argv); dbtype = ajAcdGetListSingle("idformat"); fieldarray = ajAcdGetList("fields"); directory = ajAcdGetDirectoryName("directory"); outf = ajAcdGetOutfile("outfile"); indexdir = ajAcdGetOutdirName("indexoutdir"); filename = ajAcdGetString("filenames"); exclude = ajAcdGetString("exclude"); dbname = ajAcdGetString("dbname"); dbrs = ajAcdGetString("dbresource"); release = ajAcdGetString("release"); datestr = ajAcdGetString("date"); statistics = ajAcdGetBoolean("statistics"); compressed = ajAcdGetBoolean("compressed"); entry = embBtreeEntryNew(); if(compressed) embBtreeEntrySetCompressed(entry); tmpstr = ajStrNew(); idobj = ajBtreeIdNew(); priobj = ajBtreePriNew(); hyb = ajBtreeHybNew(); nfields = embBtreeSetFields(entry,fieldarray); embBtreeSetDbInfo(entry,dbname,dbrs,datestr,release,dbtype,directory, indexdir); for(i=0; i< nfields; i++) { if(ajStrMatchC(fieldarray[i], "acc")) { accfield = embBtreeGetFieldS(entry, fieldarray[i]); if(compressed) embBtreeFieldSetCompressed(accfield); } else if(ajStrMatchC(fieldarray[i], "sv")) { svfield = embBtreeGetFieldS(entry, fieldarray[i]); if(compressed) embBtreeFieldSetCompressed(svfield); } else if(ajStrMatchC(fieldarray[i], "des")) { desfield = embBtreeGetFieldS(entry, fieldarray[i]); if(compressed) embBtreeFieldSetCompressed(desfield); } else if(ajStrMatchC(fieldarray[i], "key")) { keyfield = embBtreeGetFieldS(entry, fieldarray[i]); if(compressed) embBtreeFieldSetCompressed(keyfield); } else if(ajStrMatchC(fieldarray[i], "org")) { orgfield = embBtreeGetFieldS(entry, fieldarray[i]); if(compressed) embBtreeFieldSetCompressed(orgfield); } else if(!ajStrMatchC(fieldarray[i], "id")) ajErr("Unknown field '%S' specified for indexing", fieldarray[i]); } embBtreeGetRsInfo(entry); nfiles = embBtreeGetFiles(entry,directory,filename,exclude); if(!nfiles) ajDie("No input files in '%S' matched filename '%S'", directory, filename); embBtreeWriteEntryFile(entry); embBtreeOpenCaches(entry); starttime = ajTimeNewToday(); ajFmtPrintF(outf, "Processing directory: %S\n", directory); for(i=0;i<nfiles;++i) { begintime = ajTimeNewToday(); beginclock = ajClockNow(); ajListPop(entry->files,(void **)&thysfile); ajListPushAppend(entry->files,(void *)thysfile); ajFmtPrintS(&tmpstr,"%S%S",entry->directory,thysfile); if(!(inf=ajFileNewInNameS(tmpstr))) ajFatal("Cannot open input file %S\n",tmpstr); ajFilenameTrimPath(&tmpstr); ajFmtPrintF(outf,"Processing file: %S",tmpstr); ientries = 0L; while(dbxflat_NextEntry(entry,inf)) { ++ientries; if(entry->do_id) { if(ajStrGetLen(entry->id) > entry->idlen) { if(ajStrGetLen(entry->id) > maxidlen) { ajWarn("id '%S' too long, truncating to idlen %d", entry->id, entry->idlen); maxidlen = ajStrGetLen(entry->id); } idtrunc++; ajStrKeepRange(&entry->id,0,entry->idlen-1); } ajStrFmtLower(&entry->id); ajStrAssignS(&hyb->key1,entry->id); hyb->dbno = i; hyb->offset = entry->fpos; hyb->dups = 0; ajBtreeHybInsertId(entry->idcache,hyb); ++idtot; } if(accfield) { while(ajListPop(accfield->data,(void **)&word)) { ajStrFmtLower(&word); ajStrAssignS(&hyb->key1,word); hyb->dbno = i; hyb->offset = entry->fpos; hyb->dups = 0; ajBtreeHybInsertId(accfield->cache,hyb); ++acctot; ajStrDel(&word); } } if(svfield) { while(ajListPop(svfield->data,(void **)&word)) { ajStrFmtLower(&word); ajStrAssignS(&hyb->key1,word); hyb->dbno = i; hyb->offset = entry->fpos; hyb->dups = 0; ajBtreeHybInsertId(svfield->cache,hyb); ++svtot; ajStrDel(&word); } } if(keyfield) { while(ajListPop(keyfield->data,(void **)&word)) { ajStrFmtLower(&word); ajStrAssignS(&priobj->id,entry->id); ajStrAssignS(&priobj->keyword,word); priobj->treeblock = 0; ajBtreeInsertKeyword(keyfield->cache, priobj); ++keytot; ajStrDel(&word); } } if(desfield) { while(ajListPop(desfield->data,(void **)&word)) { ajStrFmtLower(&word); ajStrAssignS(&priobj->id,entry->id); ajStrAssignS(&priobj->keyword,word); priobj->treeblock = 0; if(ajBtreeInsertKeyword(desfield->cache, priobj)) ++destot; ajStrDel(&word); } } if(orgfield) { while(ajListPop(orgfield->data,(void **)&word)) { ajStrFmtLower(&word); ajStrAssignS(&priobj->id,entry->id); ajStrAssignS(&priobj->keyword,word); priobj->treeblock = 0; ajBtreeInsertKeyword(orgfield->cache, priobj); ++orgtot; ajStrDel(&word); } } } ajFileClose(&inf); nentries += ientries; nowtime = ajTimeNewToday(); nowclock = ajClockNow(); ajFmtPrintF(outf, " entries: %Lu (%Lu) time: %.1f/%.1fs (%.1f/%.1fs)\n", nentries, ientries, ajClockDiff(startclock,nowclock), ajTimeDiff(starttime, nowtime), ajClockDiff(beginclock,nowclock), ajTimeDiff(begintime, nowtime)); if(statistics) { if(entry->do_id) ajBtreeCacheStatsOut(outf, entry->idcache, &idcache, &idread, &idwrite, &idsize); if(accfield) ajBtreeCacheStatsOut(outf, accfield->cache, &accache, &acread, &acwrite, &acsize); if(svfield) ajBtreeCacheStatsOut(outf, svfield->cache, &svcache, &svread, &svwrite, &svsize); if(keyfield) ajBtreeCacheStatsOut(outf, keyfield->cache, &kwcache, &kwread, &kwwrite, &kwsize); if(desfield) ajBtreeCacheStatsOut(outf, desfield->cache, &decache, &deread, &dewrite, &desize); if(orgfield) ajBtreeCacheStatsOut(outf, orgfield->cache, &txcache, &txread, &txwrite, &txsize); } ajTimeDel(&begintime); ajTimeDel(&nowtime); } embBtreeDumpParameters(entry); embBtreeCloseCaches(entry); nowtime = ajTimeNewToday(); tdiff = ajTimeDiff(starttime, nowtime); days = (ajint) (tdiff/(24.0*3600.0)); tdiff -= (24.0*3600.0)*(double)days; hours = (ajint) (tdiff/3600.0); tdiff -= 3600.0*(double)hours; mins = (ajint) (tdiff/60.0); tdiff -= 60.0 * (double) mins; if(days) ajFmtPrintF(outf, "Total time: %d %02d:%02d:%04.1f\n", days, hours, mins, tdiff); else if (hours) ajFmtPrintF(outf, "Total time: %d:%02d:%04.1f\n", hours, mins, tdiff); else ajFmtPrintF(outf, "Total time: %d:%04.1f\n", mins, tdiff); ajTimeDel(&nowtime); ajTimeDel(&starttime); if(maxidlen) { ajFmtPrintF(outf, "Resource idlen truncated %u IDs. " "Maximum ID length was %u.", idtrunc, maxidlen); ajWarn("Resource idlen truncated %u IDs. Maximum ID length was %u.", idtrunc, maxidlen); } ajFileClose(&outf); embBtreeEntryDel(&entry); ajStrDel(&tmpstr); ajStrDel(&filename); ajStrDel(&exclude); ajStrDel(&dbname); ajStrDel(&dbrs); ajStrDel(&release); ajStrDel(&datestr); ajStrDel(&directory); ajStrDel(&indexdir); ajStrDel(&dbtype); nfields = 0; while(fieldarray[nfields]) ajStrDel(&fieldarray[nfields++]); AJFREE(fieldarray); ajBtreeIdDel(&idobj); ajBtreePriDel(&priobj); ajBtreeHybDel(&hyb); ajRegFree(&dbxflat_wrdexp); embExit(); return 0; }
int main(int argc, char **argv) { EmbPBtreeEntry entry = NULL; AjPStr dbname = NULL; AjPStr dbrs = NULL; AjPStr release = NULL; AjPStr datestr = NULL; AjPStr directory; AjPStr indexdir; AjPStr filename; AjPStr exclude; AjPStr dbtype = NULL; AjPFile outf = NULL; AjPStr *fieldarray = NULL; ajint nfields; ajint nfiles; AjPStr tmpstr = NULL; AjPStr thysfile = NULL; ajint i; AjPFile inf = NULL; AjPStr word = NULL; AjPBtId idobj = NULL; AjPBtPri priobj = NULL; AjPBtHybrid hyb = NULL; ajulong nentries = 0L; ajulong ientries = 0L; AjPTime starttime = NULL; AjPTime begintime = NULL; AjPTime nowtime = NULL; ajlong startclock = 0; ajlong beginclock = 0; ajlong nowclock = 0; embInit("dbxflat", argc, argv); dbtype = ajAcdGetListSingle("idformat"); fieldarray = ajAcdGetList("fields"); directory = ajAcdGetDirectoryName("directory"); outf = ajAcdGetOutfile("outfile"); indexdir = ajAcdGetOutdirName("indexoutdir"); filename = ajAcdGetString("filenames"); exclude = ajAcdGetString("exclude"); dbname = ajAcdGetString("dbname"); dbrs = ajAcdGetString("dbresource"); release = ajAcdGetString("release"); datestr = ajAcdGetString("date"); entry = embBtreeEntryNew(); tmpstr = ajStrNew(); idobj = ajBtreeIdNew(); priobj = ajBtreePriNew(); hyb = ajBtreeHybNew(); nfields = embBtreeSetFields(entry,fieldarray); embBtreeSetDbInfo(entry,dbname,dbrs,datestr,release,dbtype,directory, indexdir); embBtreeGetRsInfo(entry); nfiles = embBtreeGetFiles(entry,directory,filename,exclude); embBtreeWriteEntryFile(entry); embBtreeOpenCaches(entry); starttime = ajTimeNewToday(); ajFmtPrintF(outf, "Processing directory: %S\n", directory); for(i=0;i<nfiles;++i) { begintime = ajTimeNewToday(); beginclock = ajClockNow(); ajListPop(entry->files,(void **)&thysfile); ajListPushAppend(entry->files,(void *)thysfile); ajFmtPrintS(&tmpstr,"%S%S",entry->directory,thysfile); if(!(inf=ajFileNewInNameS(tmpstr))) ajFatal("Cannot open input file %S\n",tmpstr); ajFilenameTrimPath(&tmpstr); ajFmtPrintF(outf,"Processing file: %S",tmpstr); ientries = 0L; while(dbxflat_NextEntry(entry,inf)) { ++ientries; if(entry->do_id) { if(ajStrGetLen(entry->id) > entry->idlen) { if(ajStrGetLen(entry->id) > maxidlen) { ajWarn("id '%S' too long, truncating to idlen %d", entry->id, entry->idlen); maxidlen = ajStrGetLen(entry->id); } idtrunc++; ajStrKeepRange(&entry->id,0,entry->idlen-1); } ajStrFmtLower(&entry->id); ajStrAssignS(&hyb->key1,entry->id); hyb->dbno = i; hyb->offset = entry->fpos; hyb->dups = 0; ajBtreeHybInsertId(entry->idcache,hyb); } if(entry->do_accession) { while(ajListPop(entry->ac,(void **)&word)) { ajStrFmtLower(&word); ajStrAssignS(&hyb->key1,word); hyb->dbno = i; hyb->offset = entry->fpos; hyb->dups = 0; ajBtreeHybInsertId(entry->accache,hyb); ajStrDel(&word); } } if(entry->do_sv) { while(ajListPop(entry->sv,(void **)&word)) { ajStrFmtLower(&word); ajStrAssignS(&hyb->key1,word); hyb->dbno = i; hyb->offset = entry->fpos; hyb->dups = 0; ajBtreeHybInsertId(entry->svcache,hyb); ajStrDel(&word); } } if(entry->do_keyword) { while(ajListPop(entry->kw,(void **)&word)) { ajStrFmtLower(&word); ajStrAssignS(&priobj->id,entry->id); ajStrAssignS(&priobj->keyword,word); priobj->treeblock = 0; ajBtreeInsertKeyword(entry->kwcache, priobj); ajStrDel(&word); } } if(entry->do_description) { while(ajListPop(entry->de,(void **)&word)) { ajStrFmtLower(&word); ajStrAssignS(&priobj->id,entry->id); ajStrAssignS(&priobj->keyword,word); priobj->treeblock = 0; ajBtreeInsertKeyword(entry->decache, priobj); ajStrDel(&word); } } if(entry->do_taxonomy) { while(ajListPop(entry->tx,(void **)&word)) { ajStrFmtLower(&word); ajStrAssignS(&priobj->id,entry->id); ajStrAssignS(&priobj->keyword,word); priobj->treeblock = 0; ajBtreeInsertKeyword(entry->txcache, priobj); ajStrDel(&word); } } } ajFileClose(&inf); nentries += ientries; nowtime = ajTimeNewToday(); nowclock = ajClockNow(); ajFmtPrintF(outf, " entries: %Lu (%Lu) time: %.1f/%.1fs (%.1f/%.1fs)\n", nentries, ientries, ajClockDiff(startclock,nowclock), ajTimeDiff(starttime, nowtime), ajClockDiff(beginclock,nowclock), ajTimeDiff(begintime, nowtime)); ajTimeDel(&begintime); ajTimeDel(&nowtime); } embBtreeDumpParameters(entry); embBtreeCloseCaches(entry); nowtime = ajTimeNewToday(); ajFmtPrintF(outf, "Total time: %.1fs\n", ajTimeDiff(starttime, nowtime)); ajTimeDel(&nowtime); ajTimeDel(&starttime); if(maxidlen) { ajFmtPrintF(outf, "Resource idlen truncated %u IDs. " "Maximum ID length was %u.", idtrunc, maxidlen); ajWarn("Resource idlen truncated %u IDs. Maximum ID length was %u.", idtrunc, maxidlen); } ajFileClose(&outf); embBtreeEntryDel(&entry); ajStrDel(&tmpstr); ajStrDel(&filename); ajStrDel(&exclude); ajStrDel(&dbname); ajStrDel(&dbrs); ajStrDel(&release); ajStrDel(&datestr); ajStrDel(&directory); ajStrDel(&indexdir); ajStrDel(&dbtype); nfields = 0; while(fieldarray[nfields]) ajStrDel(&fieldarray[nfields++]); AJFREE(fieldarray); ajBtreeIdDel(&idobj); ajBtreePriDel(&priobj); ajBtreeHybDel(&hyb); ajRegFree(&dbxflat_wrdexp); embExit(); return 0; }
int main(int argc, char **argv) { AjPSeqall seqall; AjPSeq sequence; AjPFile outfile; ajint minLen; ajint maxLen; ajint maxGap; ajint beginPos; ajint endPos; ajint maxmismatches; AjPStr seqstr; ajint current; ajint rev; ajint count; ajint gap; ajint begin; ajint end; ajint mismatches; ajint mismatchAtEnd; ajint istart; ajint iend; ajint ic; ajint ir; AjBool alln; /* TRUE if all of palindrome is N's */ Palindrome pfirstpal; Palindrome plastpal = NULL; Palindrome ppal = NULL; Palindrome pnext = NULL; AjBool found = AJFALSE; embInit("palindrome", argc, argv); seqall = ajAcdGetSeqall("sequence"); minLen = ajAcdGetInt("minpallen"); maxLen = ajAcdGetInt("maxpallen"); maxGap = ajAcdGetInt("gaplimit"); outfile = ajAcdGetOutfile("outfile"); maxmismatches = ajAcdGetInt("nummismatches"); overlap = ajAcdGetBoolean("overlap"); while(ajSeqallNext(seqall, &sequence)) { beginPos = ajSeqallGetseqBegin(seqall); endPos = ajSeqallGetseqEnd(seqall); /* set to NULL to indicate that we have no first palindrome find yet */ pfirstpal = NULL; /* write header to file */ ajFmtPrintF(outfile, "Palindromes of: %s \n", ajSeqGetNameC(sequence)); ajFmtPrintF(outfile, "Sequence length is: %d \n", ajSeqGetLen(sequence)); ajFmtPrintF(outfile, "Start at position: %d\nEnd at position: %d\n", beginPos, endPos); ajFmtPrintF(outfile,"Minimum length of Palindromes is: %d \n", minLen); ajFmtPrintF(outfile,"Maximum length of Palindromes is: %d \n", maxLen); ajFmtPrintF(outfile,"Maximum gap between elements is: %d \n", maxGap); ajFmtPrintF(outfile,"Number of mismatches allowed in Palindrome: %d\n", maxmismatches); ajFmtPrintF(outfile, "\n\n\n"); ajFmtPrintF(outfile, "Palindromes:\n"); /* set vars in readiness to enter loop */ seqstr = ajStrNewC(ajSeqGetSeqC(sequence)); begin = beginPos - 1; end = endPos - 1; ajStrFmtLower(&seqstr); /* make comparisons case independent */ /* loop to look for inverted repeats */ for(current = begin; current < end; current++) { iend = current + 2*(maxLen) + maxGap; if(iend > end) iend = end; istart = current + minLen; for(rev = iend; rev > istart; rev--) { count = 0; mismatches = 0; mismatchAtEnd = 0; alln = ajTrue; ic = current; ir = rev; if(ajStrGetCharPos(seqstr, ic) == ajBaseAlphacharComp(ajStrGetCharPos(seqstr, ir))) while(mismatches <= maxmismatches && ic < ir) { if(ajStrGetCharPos(seqstr, ic++) == ajBaseAlphacharComp(ajStrGetCharPos(seqstr, ir--))) { mismatchAtEnd = 0; if(ajStrGetCharPos(seqstr, ic-1) != 'n') alln = ajFalse; } else { mismatches++; mismatchAtEnd++; } count++; } count -= mismatchAtEnd; gap = rev - current - count - count + 1; /* Find out if there's a reverse repeat long enough */ if(count >= minLen && gap <= maxGap && !alln) { /* create new struct to hold palindrome data */ ppal = palindrome_New(current,(current+count),rev, (rev-count)); /* ** if it is the first palindrome find then save it as start ** of palindrome list */ if(pfirstpal == NULL) { pfirstpal = ppal; plastpal = ppal; } else { /* Is it a subset of a palindrome already met */ pnext = pfirstpal; found = AJFALSE; while(pnext != NULL) { if(overlap && palindrome_AInB(ppal, pnext)) { found = AJTRUE; break; } if(!overlap && palindrome_AOverB(ppal, pnext)) { if(palindrome_Longer(ppal, pnext)) { palindrome_Swap(ppal, pnext); } found = AJTRUE; break; } pnext = pnext->next; } /* if new palindrome add to end of list */ if(!found) { plastpal->next = ppal; plastpal = ppal; } else AJFREE(ppal); } } } } /* Print out palindromes */ ppal = pfirstpal; while(ppal != NULL) { palindrome_Print(outfile, seqstr, ppal, maxLen); ppal = ppal->next; } /* make a gap beween outputs of different sequences */ ajFmtPrintF(outfile, "\n\n\n"); /* free memory used for palindrome list */ ppal = pfirstpal; while(ppal != NULL) { pnext = ppal->next; AJFREE(ppal); ppal = pnext; } ajStrDel(&seqstr); } ajFileClose(&outfile); ajSeqallDel(&seqall); ajSeqDel(&sequence); ajStrDel(&seqstr); embExit(); return 0; }
int main(int argc, char **argv) { AjPSeqout outseq = NULL; AjPList list = NULL; AjPSeq seq = NULL; AjPStr insert = NULL; AjPStr seqstr = NULL; AjPStr* seqr = NULL; AjPFile data = NULL; ajint start = 0; ajint length = 0; ajint amount = 0; ajint scmax = 0; ajint extra = 0; embInit("makeprotseq", argc, argv); data = ajAcdGetInfile("pepstatsfile"); insert = ajAcdGetString("insert"); start = ajAcdGetInt("start"); length = ajAcdGetInt("length"); amount = ajAcdGetInt("amount"); outseq = ajAcdGetSeqoutall("outseq"); list = ajListstrNew(); /* this is checked by acd if(amount <=0 || length <= 0) ajFatal("Amount or length is 0 or less. " "Unable to create any sequences"); */ /* if insert, make sure sequence is large enough */ if(ajStrGetLen(insert)) { length -= ajStrGetLen(insert); /* start= start <= 1 ? 0 : --start; */ /* checked in acd */ start--; if(length <= 0) ajFatal("Sequence smaller than inserted part. " "Unable to create sequences."); } /* make the list of AjPStr to be used in sequence creation */ if(data) { ajDebug("Distribution datafile '%s' given checking type\n", ajFileGetPrintnameC(data)); seqstr = ajStrNew(); ajReadlineTrim(data,&seqstr); if(ajStrFindC(seqstr,"PEPSTATS") == 0) { makeprotseq_parse_pepstats(&list,data); } else { ajWarn("Not pepstats file. Making completely random sequences."); makeprotseq_default_chars(&list); } ajStrDel(&seqstr); ajFileClose(&data); } else makeprotseq_default_chars(&list); /* if insert, make sure type is correct */ /* typecheking code is not working, uncomment and test after it is if(ajStrGetLen(insert)) { seqstr = ajStrNew(); if(prot) ajStrAssignC(&seqstr,"pureprotein"); if(!ajSeqTypeCheckS(&insert,seqstr)) ajFatal("Insert not the same sequence type as sequence itself."); ajStrDel(&seqstr); } */ /* array allows fast creation of a sequences */ scmax = (ajuint) ajListstrToarray(list,&seqr); if(!scmax) ajFatal("No strings in list. No characters to make the sequence."); ajDebug("Distribution array done.\nscmax '%d', extra '%d', first '%S'\n", scmax,extra,seqr[0]); ajRandomSeed(); while(amount-- > 0) { seqstr = makeprotseq_random_sequence(seqr,scmax,length); if(ajStrGetLen(insert)) ajStrInsertS(&seqstr,start,insert); ajStrFmtLower(&seqstr); seq = ajSeqNew(); ajSeqAssignSeqS(seq, seqstr); ajSeqSetProt(seq); ajSeqoutWriteSeq(outseq, seq); ajSeqDel(&seq); ajStrDel(&seqstr); } ajSeqoutClose(outseq); ajSeqoutDel(&outseq); ajListstrFreeData(&list); ajStrDel(&insert); AJFREE(seqr); embExit(); return 0; }
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 */ 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; }