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(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(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; }