static AjPTable btwisted_getdinucdata(AjPFile inf) { AjPStr valstr = NULL; AjPStr key = NULL; AjPStr line = NULL; AjPStrTok token = NULL; AjPTable table = NULL; valstr = ajStrNew(); line = ajStrNew(); table = ajTablestrNewCase(20); while(ajReadlineTrim(inf,&line)) { if(*ajStrGetPtr(line)=='#') continue; token = ajStrTokenNewC(line," \n\t\r"); key = ajStrNew(); ajStrTokenNextParseC(&token," \n\t\r",&key); valstr = ajStrNew(); ajStrTokenNextParseC(&token," \n\t\r",&valstr); ajTablePut(table,(void *)key,(void *) valstr); ajStrTokenDel(&token); } ajStrDel(&line); return table; }
static ajint prophet_getType(AjPFile inf, AjPStr *tname) { AjPStr line = NULL; const char *p = NULL; ajint ret = 0; line = ajStrNew(); while(ajReadlineTrim(inf,&line)) { p = ajStrGetPtr(line); if(!*p || *p=='#' || *p=='!' || *p=='\n') continue; break; } if(!strncmp(p,"Gribskov",8)) ret = 1; if(!strncmp(p,"Henikoff",8)) ret = 2; ajStrAssignC(tname,p); ajStrDel(&line); return ret; }
static void restover_read_equiv(AjPFile equfile, AjPTable table) { AjPStr line; AjPStr key; AjPStr value; const char *p; line = ajStrNew(); while(ajReadlineTrim(equfile,&line)) { p=ajStrGetPtr(line); if(!*p || *p=='#' || *p=='!') continue; p=ajSysFuncStrtok(p," \t\n"); key=ajStrNewC(p); p=ajSysFuncStrtok(NULL," \t\n"); value=ajStrNewC(p); ajTablePut(table,(void *)key, (void *)value); } ajStrDel(&line); return; }
static void remap_read_equiv(AjPFile *equfile, AjPTable *table, AjBool commercial) { AjPStr line; AjPStr key; AjPStr value; const char *p; line = ajStrNew(); while(ajReadlineTrim(*equfile,&line)) { p = ajStrGetPtr(line); if(!*p || *p=='#' || *p=='!') continue; p = ajSysFuncStrtok(p," \t\n"); key = ajStrNewC(p); p = ajSysFuncStrtok(NULL," \t\n"); value = ajStrNewC(p); if(!commercial) ajStrTrimEndC(&value,"*"); ajTablePut(*table,(void *)key, (void *)value); } ajFileClose(equfile); ajStrDel(&line); return; }
static void remap_read_file_of_enzyme_names(AjPStr *enzymes) { AjPFile file = NULL; AjPStr line; const char *p = NULL; if(ajStrFindC(*enzymes, "@") == 0) { ajStrTrimC(enzymes, "@"); /* remove the @ */ file = ajFileNewInNameS(*enzymes); if(file == NULL) ajFatal("Cannot open the file of enzyme names: '%S'", enzymes); /* blank off the enzyme file name and replace with the enzyme names */ ajStrSetClear(enzymes); line = ajStrNew(); while(ajReadlineTrim(file, &line)) { p = ajStrGetPtr(line); if(!*p || *p == '#' || *p == '!') continue; ajStrAppendS(enzymes, line); ajStrAppendC(enzymes, ","); } ajStrDel(&line); ajFileClose(&file); } return; }
static ajuint jaspscan_readmatrix(const AjPStr mfname, float ***matrix) { AjPFile inf = NULL; AjPStr line = NULL; ajuint i = 0; ajuint cols = 0; AJCNEW0(*matrix,4); line = ajStrNew(); inf = ajFileNewInNameS(mfname); if(!inf) ajFatal("Cannot open matrix file %S",mfname); i = 0; while(ajReadlineTrim(inf,&line)) { if(!i) cols = ajStrParseCountC(line," \n"); (*matrix)[i++] = ajArrFloatLine(line," \n",1,cols); } ajStrDel(&line); ajFileClose(&inf); return cols;; }
static AjBool dbxflat_ParseEmbl(EmbPBtreeEntry entry, AjPFile inf) { AjPStr line = NULL; ajlong pos = 0L; line = ajStrNewC(""); while(!ajStrPrefixC(line,"//")) { pos = ajFileResetPos(inf); if(!ajReadlineTrim(inf,&line)) { ajStrDel(&line); return ajFalse; } if(ajStrPrefixC(line,"ID")) { entry->fpos = pos; ajFmtScanS(line,"%*S%S",&entry->id); ajStrTrimEndC(&entry->id, ";"); /* ++global; printf("%d. %s\n",global,ajStrGetPtr(entry->id)); */ if(entry->do_sv) embBtreeEmblSV(line,entry->sv); } if(entry->do_sv) if(ajStrPrefixC(line,"SV") || ajStrPrefixC(line,"IV")) /* emblcds database format */ embBtreeEmblAC(line,entry->sv); if(entry->do_accession) if(ajStrPrefixC(line,"AC") || ajStrPrefixC(line,"PA")) /* emblcds database format */ embBtreeEmblAC(line,entry->ac); if(entry->do_keyword) if(ajStrPrefixC(line,"KW")) embBtreeEmblKW(line,entry->kw,entry->kwlen); if(entry->do_description) if(ajStrPrefixC(line,"DE")) embBtreeEmblDE(line,entry->de,entry->delen); if(entry->do_taxonomy) if(ajStrPrefixC(line,"OC") || ajStrPrefixC(line,"OS")) embBtreeEmblTX(line,entry->tx,entry->txlen); } ajStrDel(&line); return ajTrue; }
static AjBool dbxflat_ParseEmbl(EmbPBtreeEntry entry, AjPFile inf) { AjPStr line = NULL; ajlong pos = 0L; line = ajStrNewC(""); while(!ajStrPrefixC(line,"//")) { pos = ajFileResetPos(inf); if(!ajReadlineTrim(inf,&line)) { ajStrDel(&line); return ajFalse; } if(ajStrPrefixC(line,"ID")) { entry->fpos = pos; ajFmtScanS(line,"%*S%S",&entry->id); ajStrTrimEndC(&entry->id, ";"); /* ++global; printf("%d. %s\n",global,ajStrGetPtr(entry->id)); */ if(svfield) embBtreeEmblSV(line,svfield->data); } if(svfield) if(ajStrPrefixC(line,"SV") || ajStrPrefixC(line,"IV")) /* emblcds database format */ embBtreeEmblAC(line,svfield->data); if(accfield) if(ajStrPrefixC(line,"AC") || ajStrPrefixC(line,"PA")) /* emblcds database format */ embBtreeEmblAC(line,accfield->data); if(keyfield) if(ajStrPrefixC(line,"KW")) embBtreeEmblKW(line,keyfield->data,keyfield->len); if(desfield) if(ajStrPrefixC(line,"DE")) embBtreeEmblDE(line,desfield->data,desfield->len); if(orgfield) if(ajStrPrefixC(line,"OC") || ajStrPrefixC(line,"OS")) embBtreeEmblTX(line,orgfield->data,orgfield->len); } ajStrDel(&line); return ajTrue; }
static ajint cutgextract_readcodons(AjPFile inf, AjBool allrecords, ajint *count) { static int cutidx[] = { 42,43,46,41,45,44,26,30,31,29,27,28,48,51,47,50, 52,49,55,56,53,54,36,38,35,37, 4, 6, 3, 5,17,18, 16,15,57,59,60,58,24,25,34,33,39,40,20,19,11,12, 10, 9,63,62, 8, 7,14,13,21,23,22,32,61, 1, 0, 2 }; AjPStr line = NULL; AjPStr value = NULL; ajint thiscount[64]; AjPStrTok token = NULL; ajint i; ajint n = 0; ajint nstops = 0; if(!line) { line = ajStrNew(); value = ajStrNew(); } if(!ajReadlineTrim(inf,&line)) ajFatal("Premature end of file"); token = ajStrTokenNewC(line," \n\t\r"); for(i=0;i<CODONS;++i) { ajStrTokenNextParseC(&token," \n\t\r",&value); ajStrToInt(value,&n); thiscount[cutidx[i]] = n; if(i>60) nstops += n; } ajStrDel(&line); ajStrDel(&value); ajStrTokenDel(&token); if(!allrecords) if(nstops > 1) return -1; for(i=0;i<CODONS;++i) { count[i] += thiscount[i]; } return nstops; }
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 notseq_readfile(const AjPStr exclude, AjPStr *pattern) { AjPFile file = NULL; AjPStr line; AjPStr filename = NULL; const char *p = NULL; if(ajStrFindC(exclude, "@") != 0) { ajStrAssignS(pattern, exclude); } else { ajStrAssignS(&filename, exclude); ajStrTrimC(&filename, "@"); /* remove the @ */ file = ajFileNewInNameS(filename); if(file == NULL) ajFatal("Cannot open the file of sequence names: '%S'", filename); /* blank off the file name and replace with the sequence names */ ajStrSetClear(pattern); line = ajStrNew(); while(ajReadlineTrim(file, &line)) { p = ajStrGetPtr(line); if(!*p || *p == '#' || *p == '!') continue; ajStrAppendS(pattern, line); ajStrAppendC(pattern, ","); } ajStrDel(&line); ajStrDel(&filename); ajFileClose(&file); } return; }
static AjBool dbxflat_ParseFastq(EmbPBtreeEntry entry, AjPFile inf) { AjPStr line = NULL; ajlong pos = 0L; ajuint seqlen = 0; ajuint qlen = 0; AjPStr tmpfd = NULL; AjPStr str = NULL; AjPStr de = NULL; AjBool ok; if(!dbxflat_wrdexp) dbxflat_wrdexp = ajRegCompC("([A-Za-z0-9.:=]+)"); line = ajStrNewC(""); pos = ajFileResetPos(inf); if(!ajReadlineTrim(inf,&line)) { ajStrDel(&line); return ajFalse; } /* first line of entry */ if(!ajStrPrefixC(line,"@")) return ajFalse; entry->fpos = pos; ajStrCutStart(&line, 1); ajStrExtractFirst(line, &de, &entry->id); if(desfield && ajStrGetLen(de)) { while(ajRegExec(dbxflat_wrdexp,de)) { ajRegSubI(dbxflat_wrdexp, 1, &tmpfd); str = ajStrNew(); ajStrAssignS(&str,tmpfd); ajListPush(desfield->data,(void *)str); ajRegPost(dbxflat_wrdexp, &de); } } /* now read sequence */ ok = ajReadlineTrim(inf,&line); while(ok && !ajStrPrefixC(line, "+")) { ajStrRemoveWhite(&line); seqlen += MAJSTRGETLEN(line); ok = ajReadlineTrim(inf,&line); } if(!ok) return ajFalse; ok = ajReadlineTrim(inf,&line); while(ok) { qlen += MAJSTRGETLEN(line); if(qlen < seqlen) ok = ajReadlineTrim(inf,&line); else ok = ajFalse; } ajStrDel(&de); ajStrDel(&tmpfd); ajStrDel(&line); return ajTrue; }
/* @funcstatic seqwords_keysearch ******************************************** ** ** Search swissprot with terms structure and writes a hitlist structure ** ** @param [r] inf [AjPFile] File pointer to swissprot database ** @param [r] terms [AjPTerms] Terms object pointer ** @param [w] hits [EmbPHitlist*] Hitlist object pointer ** ** @return [AjBool] True on success ** @@ ******************************************************************************/ static AjBool seqwords_keysearch(AjPFile inf, AjPTerms terms, EmbPHitlist *hits) { AjPStr line =NULL; /* Line of text. */ AjPStr id =NULL; /* Line of text. */ AjPStr temp =NULL; ajint s =0; /* Temp. start of hit value. */ ajint e =0; /* Temp. end of hit value. */ AjPInt start =NULL; /* Array of start of hit(s). */ AjPInt end =NULL; /* Array of end of hit(s). */ ajint nhits =0; /* Number of hits. */ ajint x =0; AjBool foundkw =ajFalse; AjBool foundft =ajFalse; /* Check for valid args. */ if(!inf) return ajFalse; /* Allocate strings and arrays. */ line = ajStrNew(); id = ajStrNew(); start = ajIntNew(); end = ajIntNew(); /* Start of main loop. */ while((ajReadlineTrim(inf,&line))) { /* Parse the AC line. */ if(ajStrPrefixC(line,"AC")) { /* Copy accesion number and remove the ';' from the end. */ ajFmtScanS(line, "%*s %S", &id); ajStrExchangeCC(&id, ";", "\0"); /* Reset flags & no. hits. */ foundkw=ajFalse; foundft=ajFalse; nhits=0; } /* Search the description and keyword lines with search terms. */ else if((ajStrPrefixC(line,"DE") || (ajStrPrefixC(line,"KW")))) { /* ** Search terms have a leading and trailing space to prevent ** them being found as substrings within other words. To ** catch cases where a DE or KW line begins with a search ** term, we must add a leading and trailing space to line. ** We must first remove punctation from the line to be parsed. */ ajStrExchangeSetCC(&line, ".,;:", " "); ajStrAppendK(&line, ' '); ajStrInsertC(&line, 0, " "); for (x = 0; x < terms->N; x++) /* Search term is found. */ if((ajStrFindCaseS(line, terms->Keywords[x])!=-1)) { foundkw=ajTrue; break; } } /* Search the feature table line with search terms. */ else if((ajStrPrefixC(line,"FT DOMAIN"))) { /* ** Search terms have a leading and trailing space to prevent ** them being found as substrings within other words. To ** catch cases where a FT line ends with a search ** term, we must add a trailing space to line ** We must first remove punctation from the line to be parsed. */ ajStrExchangeSetCC(&line, ".,;:", " "); ajStrAppendK(&line, ' '); for (x = 0; x < terms->N; x++) if((ajStrFindCaseS(line, terms->Keywords[x])!=-1)) { /* Search term is found. */ foundft = ajTrue; nhits++; /* Assign start and end of hit. */ ajFmtScanS(line, "%*s %*s %d %d", &s, &e); ajIntPut(&start, nhits-1, s); ajIntPut(&end, nhits-1, e); break; } } /* Parse the sequence. */ else if((ajStrPrefixC(line,"SQ") && ((foundkw == ajTrue) || (foundft == ajTrue)))) { /* Allocate memory for temp. sequence. */ temp = ajStrNew(); /* Read the sequence into hitlist structure. */ while((ajReadlineTrim(inf,&line)) && !ajStrPrefixC(line,"//")) /* Read sequence line into temp. */ ajStrAppendC(&temp,ajStrGetPtr(line)+3); /* Clean up temp. sequence. */ ajStrRemoveWhite(&temp); /*Priority is given to domain (rather than full length) sequence.*/ if(foundft) { for(x=0;x<nhits;x++) { /* Increment counter of hits for subsequent hits*/ (*hits)->N++; /* Reallocate memory for array of hits in hitlist structure. */ AJCRESIZE((*hits)->hits, (*hits)->N); (*hits)->hits[(*hits)->N-1]=embHitNew(); ajStrAssignC(&(*hits)->hits[(*hits)->N-1]->Model, "KEYWORD"); /* Assign start and end of hit. */ (*hits)->hits[(*hits)->N-1]->Start = ajIntGet(start, x); (*hits)->hits[(*hits)->N-1]->End = ajIntGet(end, x); /* Extract sequence within specified range */ ajStrAssignSubS(&(*hits)->hits[(*hits)->N - 1]->Seq, temp, (*hits)->hits[(*hits)->N - 1]->Start - 1, (*hits)->hits[(*hits)->N - 1]->End - 1); /* Put id into structure */ ajStrAssignRef(&(*hits)->hits[(*hits)->N - 1]->Acc, id); } } else { /* Increment counter of hits */ (*hits)->N++; /* Reallocate memory for array of hits in hitlist structure */ AJCRESIZE((*hits)->hits, (*hits)->N); (*hits)->hits[(*hits)->N-1]=embHitNew(); ajStrAssignC(&(*hits)->hits[(*hits)->N-1]->Model, "KEYWORD"); /* Extract whole sequence */ ajStrAssignRef(&(*hits)->hits[(*hits)->N - 1]->Seq, temp); (*hits)->hits[(*hits)->N - 1]->Start = 1; (*hits)->hits[(*hits)->N - 1]->End = ajStrGetLen((*hits)->hits[(*hits)->N - 1]->Seq); /* Put id into structure */ ajStrAssignRef(&(*hits)->hits[(*hits)->N - 1]->Acc, id); } /* Free temp. sequence */ ajStrDel(&temp); } } /* Clean up */ ajStrDel(&line); ajStrDel(&id); ajIntDel(&start); ajIntDel(&end); return ajTrue; }
/* @funcstatic seqwords_TermsRead ********************************************* ** ** Read the next Terms object from a file in embl-like format. The search ** terms are modified with a leading and trailing space. ** ** @param [r] inf [AjPFile] Input file stream ** @param [w] thys [AjPTerms*] Terms object ** ** @return [AjBool] True on succcess ** @@ *****************************************************************************/ static AjBool seqwords_TermsRead(AjPFile inf, AjPTerms *thys) { AjPStr line =NULL; /* Line of text. */ AjPStr temp =NULL; AjPList list_terms =NULL; /* List of keywords for a scop node*/ AjBool ok =ajFalse; AjPStr type = NULL; /* Memory management */ (*thys)=seqwords_TermsNew(); list_terms = ajListstrNew(); line = ajStrNew(); type = ajStrNew(); /* Read first line. */ ok = ajReadlineTrim(inf,&line); while(ok && !ajStrPrefixC(line,"//")) { if(ajStrPrefixC(line,"XX")) { ok = ajReadlineTrim(inf,&line); continue; } else if(ajStrPrefixC(line,"TY")) { ajFmtScanS(line, "%*s %S", &type); if(ajStrMatchC(type, "SCOP")) (*thys)->Type = ajSCOP; else if(ajStrMatchC(type, "CATH")) (*thys)->Type = ajCATH; } else if(ajStrPrefixC(line,"CL")) { ajStrAssignC(&(*thys)->Class,ajStrGetPtr(line)+3); ajStrRemoveWhiteExcess(&(*thys)->Class); } else if(ajStrPrefixC(line,"AR")) { ajStrAssignC(&(*thys)->Architecture,ajStrGetPtr(line)+3); ajStrRemoveWhiteExcess(&(*thys)->Architecture); } else if(ajStrPrefixC(line,"TP")) { ajStrAssignC(&(*thys)->Topology,ajStrGetPtr(line)+3); ajStrRemoveWhiteExcess(&(*thys)->Topology); } else if(ajStrPrefixC(line,"FO")) { ajStrAssignC(&(*thys)->Fold,ajStrGetPtr(line)+3); while(ajReadlineTrim(inf,&line)) { if(ajStrPrefixC(line,"XX")) break; ajStrAppendC(&(*thys)->Fold,ajStrGetPtr(line)+3); } ajStrRemoveWhiteExcess(&(*thys)->Fold); } else if(ajStrPrefixC(line,"SF")) { ajStrAssignC(&(*thys)->Superfamily,ajStrGetPtr(line)+3); while(ajReadlineTrim(inf,&line)) { if(ajStrPrefixC(line,"XX")) break; ajStrAppendC(&(*thys)->Superfamily,ajStrGetPtr(line)+3); } ajStrRemoveWhiteExcess(&(*thys)->Superfamily); } else if(ajStrPrefixC(line,"FA")) { ajStrAssignC(&(*thys)->Family,ajStrGetPtr(line)+3); while(ajReadlineTrim(inf,&line)) { if(ajStrPrefixC(line,"XX")) break; ajStrAppendC(&(*thys)->Family,ajStrGetPtr(line)+3); } ajStrRemoveWhiteExcess(&(*thys)->Family); } else if(ajStrPrefixC(line,"TE")) { /* Copy and clean up term. */ temp = ajStrNew(); ajStrAssignC(&temp,ajStrGetPtr(line)+3); ajStrRemoveWhiteExcess(&temp); /* Append a leading and trailing space to search term*/ ajStrAppendK(&temp, ' '); ajStrInsertC(&temp, 0, " "); /* Add the current term to the list. */ ajListstrPush(list_terms,temp); } ok = ajReadlineTrim(inf,&line); } if(!ok) { /* Clean up. */ ajListstrFree(&list_terms); ajStrDel(&line); /* Return. */ return ajFalse; } /* Convert the AjPList of terms to array of AjPSeq's. */ if(!((*thys)->N=ajListstrToarray((AjPList)list_terms,&(*thys)->Keywords))) ajWarn("Zero sized list of terms passed into seqwords_TermsRead"); /* Clean up. Free the list (not the nodes!). */ ajListstrFree(&list_terms); ajStrDel(&line); ajStrDel(&type); return ajTrue; }
int main(int argc, char **argv) { AjPFile infile = NULL; AjPFile outfile = NULL; AjPStr line; AjPGraph graphLB = NULL; AjPGraphdata xygraph = NULL; AjPGraphdata xygraph2 = NULL; AjBool doplot; ajint N=0; float *xdata = NULL; float *ydata = NULL; float *V = NULL; float *S = NULL; float a; float b; float upperXlimit; float upperYlimit; float A; float B; float C; float D; float xmin; float xmax; float ymin; float ymax; float xmin2; float xmax2; float ymin2; float ymax2; float Vmax; float Km; float cutx; float cuty; float amin = 0.; float amax = 0.; float bmin = 0.; float bmax = 0.; embInit("findkm", argc, argv); infile = ajAcdGetInfile("infile"); outfile = ajAcdGetOutfile ("outfile"); doplot = ajAcdGetBoolean("plot"); graphLB = ajAcdGetGraphxy("graphLB"); line = ajStrNew(); /* Determine N by reading infile */ while(ajReadlineTrim(infile, &line)) if(ajStrGetLen(line) >0) N++; /* only allocate memory to the arrays */ AJCNEW(xdata, N); AJCNEW(ydata, N); AJCNEW(S, N); AJCNEW(V, N); ajFileSeek(infile, 0L, 0); N=0; while(ajReadlineTrim(infile, &line)) { if(ajStrGetLen(line) > 0) { sscanf(ajStrGetPtr(line),"%f %f",&S[N],&V[N]); if(S[N] > 0.0 && V[N] > 0.0) { xdata[N] = S[N]; ydata[N] = S[N]/V[N]; N++; } } } /* find the max and min values for the graph parameters*/ xmin = (float)0.5*findkm_findmin(xdata, N); xmax = (float)1.5*findkm_findmax(xdata, N); ymin = (float)0.5*findkm_findmin(ydata, N); ymax = (float)1.5*findkm_findmax(ydata, N); xmin2 = (float)0.5*findkm_findmin(S, N); xmax2 = (float)1.5*findkm_findmax(S, N); ymin2 = (float)0.5*findkm_findmin(V, N); ymax2 = (float)1.5*findkm_findmax(V, N); /* ** In case the casted ints turn out to be same number on the axis, ** make the max number larger than the min so graph can be seen. */ if((ajint)xmax == (ajint)xmin) ++xmax; if((ajint)ymax == (ajint)ymin) ++ymax; if((ajint)xmax2 == (ajint)xmin2) ++xmax2; if((ajint)ymax2 == (ajint)ymin2) ++ymax2; /* ** Gaussian Elimination for Best-fit curve plotting and ** calculating Km and Vmax */ A = findkm_summation(xdata, N); B = findkm_summation(ydata, N); C = findkm_multisum(xdata, ydata, N); D = findkm_multisum(xdata, xdata, N); /* ** To find the best fit line, Least Squares Fit: y =ax +b; ** Two Simultaneous equations, REARRANGE FOR b ** ** findkm_summation(ydata, N) - findkm_summation(xdata,N)*a - N*b =0; ** b = (findkm_summation(ydata,N) - findkm_summation(xdata,N)*a) / N; ** b = (B - A*a)/ N; ** ** C - D*a - A*((B - A*a)/ N) =0; ** C - D*a - A*B/N + A*A*a/N =0; ** C - A*B/N = D*a - A*A*a/N; */ /* REARRANGE FOR a */ a = (N*C - A*B)/ (N*D - A*A); b = (B - A*a)/ N; /* ** Equation of Line - Lineweaver burk eqn ** 1/V = (Km/Vmax)*(1/S) + 1/Vmax; */ Vmax = 1/a; Km = b/a; cutx = -1/Km; cuty = Km/Vmax; /* set limits for last point on graph */ upperXlimit = findkm_findmax(xdata,N)+3; upperYlimit = (upperXlimit)*a + b; ajFmtPrintF(outfile, "---Hanes Woolf Plot Calculations---\n"); ajFmtPrintF(outfile, "Slope of best fit line is a = %.2f\n", a); ajFmtPrintF(outfile,"Coefficient in Eqn of line y = ma +b is b " "= %.2f\n", b); ajFmtPrintF(outfile, "Where line cuts x axis = (%.2f, 0)\n", cutx); ajFmtPrintF(outfile, "Where line cuts y axis = (0, %.2f)\n", cuty); ajFmtPrintF(outfile, "Limit-point of graph for plot = (%.2f, %.2f)\n\n", upperXlimit, upperYlimit); ajFmtPrintF(outfile, "Vmax = %.2f, Km = %f\n",Vmax, Km); /* draw graphs */ if(doplot) { xygraph = ajGraphdataNewI(N); ajGraphdataAddXY(xygraph, S, V); ajGraphDataAdd(graphLB, xygraph); ajGraphdataSetTitleC(xygraph, "Michaelis Menten Plot"); ajGraphdataSetXlabelC(xygraph, "[S]"); ajGraphdataSetYlabelC(xygraph, "V"); ajGraphxySetXstartF(graphLB, 0.0); ajGraphxySetXendF(graphLB, xmax2); ajGraphxySetYstartF(graphLB, 0.0); ajGraphxySetYendF(graphLB, ymax2); ajGraphxySetXrangeII(graphLB, (ajint)0.0, (ajint)xmax2); ajGraphxySetYrangeII(graphLB, (ajint)0.0, (ajint)ymax2); ajGraphdataAddposLine(xygraph, 0.0, 0.0, S[0], V[0], (ajint)BLACK); ajGraphxyShowPointsCircle(graphLB, ajTrue); ajGraphdataSetMinmax(xygraph,0.0,xmax2,0.0,ymax2); ajGraphicsCalcRange(S,N,&amin,&amax); ajGraphicsCalcRange(V,N,&bmin,&bmax); ajGraphdataSetTruescale(xygraph,amin,amax,bmin,bmax); ajGraphdataSetTypeC(xygraph,"2D Plot Float"); xygraph2 = ajGraphdataNewI(N); ajGraphdataAddXY(xygraph2, xdata, ydata); ajGraphDataAdd(graphLB, xygraph2); ajGraphdataSetTitleC(xygraph2, "Hanes Woolf Plot"); ajGraphdataSetXlabelC(xygraph2, "[S]"); ajGraphdataSetYlabelC(xygraph2, "[S]/V"); ajGraphxySetXstartF(graphLB, cutx); ajGraphxySetXendF(graphLB, upperXlimit); ajGraphxySetYstartF(graphLB, 0.0); ajGraphxySetYendF(graphLB, upperYlimit); ajGraphxySetXrangeII(graphLB, (ajint)cutx, (ajint)upperXlimit); ajGraphxySetYrangeII(graphLB, (ajint)0.0, (ajint)upperYlimit); ajGraphxyShowPointsCircle(graphLB, ajTrue); ajGraphdataSetMinmax(xygraph2, cutx,upperXlimit,0.0,upperYlimit); ajGraphicsCalcRange(xdata,N,&amin,&amax); ajGraphicsCalcRange(ydata,N,&bmin,&bmax); ajGraphdataSetTruescale(xygraph2,amin,amax,bmin,bmax); ajGraphdataSetTypeC(xygraph2,"2D Plot"); ajGraphSetTitleC(graphLB,"FindKm"); ajGraphxySetflagOverlay(graphLB,ajFalse); ajGraphxyDisplay(graphLB, ajTrue); } AJFREE(xdata); AJFREE(ydata); AJFREE(S); AJFREE(V); ajFileClose(&infile); ajFileClose(&outfile); ajGraphxyDel(&graphLB); ajStrDel(&line); embExit(); return 0; }
AjBool ajDebugTest(const char* token) { AjPStr filename = NULL; const char* debugtestname = ".debugtest"; char* ctoken = NULL; AjPStr line = NULL; AjPStr strtoken = NULL; AjPStr rest = NULL; static ajint depth = 0; struct { ajuint count; ajuint max; } *stats; if(depth) return ajFalse; depth++; if(!messDebugTestInit) { filename = ajStrNewC(debugtestname); if(ajFilenameExists(filename)) { messDebugTestFile = ajFileNewInNameS(filename); } else { ajFmtPrintS(&filename, "%s%s%s", getenv("HOME"), SLASH_STRING, debugtestname); if(ajFilenameExists(filename)) messDebugTestFile = ajFileNewInNameS(filename); } ajStrDel(&filename); if(messDebugTestFile) { messDebugTestTable = ajTablecharNewLen(256); while(ajReadlineTrim(messDebugTestFile, &line)) { if(ajStrExtractFirst(line, &rest, &strtoken)) { AJNEW0(stats); ctoken = ajCharNewS(strtoken); if(ajStrIsInt(rest)) ajStrToUint(rest, &stats->max); else stats->max = UINT_MAX; ajTablePut(messDebugTestTable, ctoken, stats); ctoken = NULL; stats = NULL; } } ajStrDel(&line); ajStrDel(&strtoken); ajStrDel(&rest); ajFileClose(&messDebugTestFile); } messDebugTestInit = ajTrue; } depth--; if(!messDebugTestTable) return ajFalse; depth++; stats = ajTableFetch(messDebugTestTable, token); depth--; if(!stats) return ajFalse; if(!stats->max) return ajTrue; if(stats->count++ >= stats->max) return ajFalse; return ajTrue; }
int main(int argc, char **argv) { AjPFile inf = NULL; AjPFile inf2 = NULL; AjPFeattable tab = NULL; AjPReport report = NULL; AjPSeq sequence = NULL; AjPStr redatanew = NULL; AjPStr str = NULL; AjPStr regexp = NULL; AjPStr temp = NULL; AjPStr text = NULL; AjPStr docdata = NULL; AjPStr data = NULL; AjPStr accession = NULL; AjPStr name = NULL; EmbPPatMatch match = NULL; AjPStr savereg = NULL; AjPStr fthit = NULL; AjBool full; AjBool prune; ajint i; ajint number; ajint start; ajint end; ajint length; ajint zstart; ajint zend; const char *p; ajint seqlength; AjPStr tmpstr = NULL; AjPStr tailstr = NULL; AjPFeature gf; embInit("patmatmotifs", argc, argv); ajStrAssignC(&fthit, "SO:0001067"); savereg = ajStrNew(); str = ajStrNew(); regexp = ajStrNew(); temp = ajStrNew(); data = ajStrNew(); accession = ajStrNew(); text = ajStrNew(); name = ajStrNew(); sequence = ajAcdGetSeq("sequence"); report = ajAcdGetReport("outfile"); full = ajAcdGetBoolean("full"); prune = ajAcdGetBoolean("prune"); ajSeqFmtUpper(sequence); /* prosite regexs are all upper case */ tab = ajFeattableNewSeq(sequence); ajStrAssignC(&tailstr, ""); seqlength = ajStrGetLen(str); str = ajSeqGetSeqCopyS(sequence); redatanew = ajStrNewC("PROSITE/prosite.lines"); docdata = ajStrNewC("PROSITE/"); inf = ajDatafileNewInNameS(redatanew); if(!inf) ajFatal("Either EMBOSS_DATA undefined or PROSEXTRACT needs running"); ajFmtPrintAppS(&tmpstr, "Full: %B\n", full); ajFmtPrintAppS(&tmpstr, "Prune: %B\n", prune); ajFmtPrintAppS(&tmpstr, "Data_file: %F\n", inf); ajReportSetHeaderS(report, tmpstr); while(ajReadlineTrim(inf, ®exp)) { p=ajStrGetPtr(regexp); if(*p && *p!=' ' && *p!='^') { p=ajSysFuncStrtok(p," "); ajStrAssignC(&name,p); if(prune) if(ajStrMatchCaseC(name,"myristyl") || ajStrMatchCaseC(name,"asn_glycosylation") || ajStrMatchCaseC(name,"camp_phospho_site") || ajStrMatchCaseC(name,"pkc_phospho_site") || ajStrMatchCaseC(name,"ck2_phospho_site") || ajStrMatchCaseC(name,"tyr_phospho_site")) { for(i=0;i<4;++i) ajReadlineTrim(inf, ®exp); continue; } p=ajSysFuncStrtok(NULL," "); ajStrAssignC(&accession,p); } if(ajStrPrefixC(regexp, "^")) { p = ajStrGetPtr(regexp); ajStrAssignC(&temp,p+1); ajStrAssignC(&savereg,p+1); match = embPatMatchFind(temp, str, ajFalse, ajFalse); number = embPatMatchGetNumber(match); for(i=0; i<number; i++) { seqlength = ajStrGetLen(str); start = 1+embPatMatchGetStart(match, i); end = 1+embPatMatchGetEnd(match, i); length = embPatMatchGetLen(match, i); gf = ajFeatNew(tab, NULL, fthit, start, end, (float) length, ' ', 0); ajFmtPrintS(&tmpstr, "*motif %S", name); ajFeatTagAddSS(gf, NULL, tmpstr); if(start-5<0) zstart = 0; else zstart = start-5; if(end+5> seqlength) zend = end; else zend = end+5; ajStrAssignSubS(&temp, str, zstart, zend); } if(full && number) { ajStrAssignC(&redatanew,ajStrGetPtr(docdata)); ajStrAppendC(&redatanew,ajStrGetPtr(accession)); inf2 = ajDatafileNewInNameS(redatanew); if(!inf2) continue; /* ** Insert Prosite documentation from files made by ** prosextract.c */ ajFmtPrintAppS(&tailstr, "Motif: %S\n", name); ajFmtPrintAppS(&tailstr, "Count: %d\n\n", number); while(ajReadlineTrim(inf2, &text)) ajFmtPrintAppS(&tailstr, "%S\n", text); ajFmtPrintAppS(&tailstr, "\n***************\n\n"); ajFileClose(&inf2); } embPatMatchDel(&match); } } ajReportSetTailS(report,tailstr); ajReportWrite(report, tab, sequence); ajReportDel(&report); ajFeattableDel(&tab); ajStrDel(&temp); ajStrDel(®exp); ajStrDel(&savereg); ajStrDel(&str); ajStrDel(&data); ajStrDel(&docdata); ajStrDel(&text); ajStrDel(&redatanew); ajStrDel(&accession); ajSeqDel(&sequence); ajStrDel(&tailstr); ajStrDel(&fthit); ajStrDel(&name); ajStrDel(&tmpstr); ajFeattableDel(&tab); ajFileClose(&inf); embExit(); return 0; }
int main(int argc, char **argv) { AjPSeqall seqall; AjPFile primfile; AjPStr rdline = NULL; Primer primdata; AjPStrTok handle = NULL; AjPList primList = NULL; embInit("stssearch", argc, argv); primfile = ajAcdGetInfile("infile"); out = ajAcdGetOutfile("outfile"); seqall = ajAcdGetSeqall("seqall"); while(ajReadlineTrim(primfile, &rdline)) { if(ajStrGetCharFirst(rdline) == '#') continue; if(ajStrSuffixC(rdline, "..")) continue; AJNEW(primdata); primdata->Name = NULL; primdata->Oligoa = NULL; primdata->Oligob = NULL; handle = ajStrTokenNewC(rdline, " \t"); ajStrTokenNextParse(&handle, &primdata->Name); if(!(nprimers % 1000)) ajDebug("Name [%d]: '%S'\n", nprimers, primdata->Name); ajStrTokenNextParse(&handle, &primdata->Oligoa); ajStrFmtUpper(&primdata->Oligoa); primdata->Prima = ajRegComp(primdata->Oligoa); ajStrTokenNextParse(&handle, &primdata->Oligob); ajStrFmtUpper(&primdata->Oligob); primdata->Primb = ajRegComp(primdata->Oligob); ajStrTokenDel(&handle); if(!nprimers) primList = ajListNew(); ajListPushAppend(primList, primdata); nprimers++; } if(!nprimers) ajFatal("No primers read\n"); ajDebug("%d primers read\n", nprimers); while(ajSeqallNext(seqall, &seq)) { ajSeqFmtUpper(seq); ajStrAssignS(&seqstr, ajSeqGetSeqS(seq)); ajStrAssignS(&revstr, ajSeqGetSeqS(seq)); ajSeqstrReverse(&revstr); ajDebug("Testing: %s\n", ajSeqGetNameC(seq)); ntests = 0; ajListMap(primList, stssearch_primTest, NULL); } ajFileClose(&out); ajSeqallDel(&seqall); ajSeqDel(&seq); ajFileClose(&out); ajStrDel(&revstr); ajStrDel(&seqstr); ajFileClose(&primfile); ajListMap(primList, stssearch_primDel, NULL); ajListFree(&primList); ajStrDel(&rdline); embExit(); return 0; }
int main(int argc, char **argv) { AjPSeqall seqall = NULL; AjPFile dend_outfile = NULL; AjPStr tmp_dendfilename = NULL; AjPFile tmp_dendfile = NULL; AjPStr tmp_aln_outfile = NULL; AjPSeqset seqset = NULL; AjPSeqout seqout = NULL; AjPSeqin seqin = NULL; AjBool only_dend; AjBool are_prot = ajFalse; AjBool do_slow; AjBool use_dend; AjPFile dend_file = NULL; AjPStr dend_filename = NULL; ajint ktup; ajint gapw; ajint topdiags; ajint window; AjBool nopercent; AjPStr pw_matrix = NULL; AjPStr pw_dna_matrix = NULL; AjPFile pairwise_matrix = NULL; float pw_gapc; float pw_gapv; AjPStr pwmstr = NULL; char pwmc = '\0'; AjPStr pwdstr = NULL; char pwdc = '\0'; AjPStr m1str = NULL; AjPStr m2str = NULL; char m1c = '\0'; char m2c = '\0'; AjPStr matrix = NULL; AjPStr dna_matrix = NULL; AjPFile ma_matrix = NULL; float gapc; float gapv; AjBool endgaps; AjBool norgap; AjBool nohgap; ajint gap_dist; ajint maxdiv; AjPStr hgapres = NULL; AjPSeqout fil_file = NULL; AjPSeq seq = NULL; AjPStr cmd = NULL; AjPStr tmp = NULL; AjPStr tmpFilename; AjPStr line = NULL; ajint nb = 0; /* get all the parameters */ embInit("emma", argc, argv); pwmstr = ajStrNew(); pwdstr = ajStrNew(); m1str = ajStrNew(); m2str = ajStrNew(); seqall = ajAcdGetSeqall("sequence"); seqout = ajAcdGetSeqoutset("outseq"); dend_outfile = ajAcdGetOutfile("dendoutfile"); only_dend = ajAcdGetToggle("onlydend"); use_dend = ajAcdGetToggle("dendreuse"); dend_file = ajAcdGetInfile("dendfile"); if (dend_file) ajStrAssignS(&dend_filename, ajFileGetPrintnameS(dend_file)); ajFileClose(&dend_file); do_slow = ajAcdGetToggle("slowalign"); ktup = ajAcdGetInt("ktup"); gapw = ajAcdGetInt("gapw"); topdiags = ajAcdGetInt("topdiags"); window = ajAcdGetInt("window"); nopercent = ajAcdGetBoolean("nopercent"); pw_matrix = ajAcdGetListSingle("pwmatrix"); pwmc = ajStrGetCharFirst(pw_matrix); if(pwmc=='b') ajStrAssignC(&pwmstr,"blosum"); else if(pwmc=='p') ajStrAssignC(&pwmstr,"pam"); else if(pwmc=='g') ajStrAssignC(&pwmstr,"gonnet"); else if(pwmc=='i') ajStrAssignC(&pwmstr,"id"); else if(pwmc=='o') ajStrAssignC(&pwmstr,"own"); pw_dna_matrix = ajAcdGetListSingle("pwdnamatrix"); pwdc = ajStrGetCharFirst(pw_dna_matrix); if(pwdc=='i') ajStrAssignC(&pwdstr,"iub"); else if(pwdc=='c') ajStrAssignC(&pwdstr,"clustalw"); else if(pwdc=='o') ajStrAssignC(&pwdstr,"own"); pairwise_matrix = ajAcdGetInfile("pairwisedatafile"); pw_gapc = ajAcdGetFloat( "pwgapopen"); pw_gapv = ajAcdGetFloat( "pwgapextend"); matrix = ajAcdGetListSingle( "matrix"); m1c = ajStrGetCharFirst(matrix); if(m1c=='b') ajStrAssignC(&m1str,"blosum"); else if(m1c=='p') ajStrAssignC(&m1str,"pam"); else if(m1c=='g') ajStrAssignC(&m1str,"gonnet"); else if(m1c=='i') ajStrAssignC(&m1str,"id"); else if(m1c=='o') ajStrAssignC(&m1str,"own"); dna_matrix = ajAcdGetListSingle( "dnamatrix"); m2c = ajStrGetCharFirst(dna_matrix); if(m2c=='i') ajStrAssignC(&m2str,"iub"); else if(m2c=='c') ajStrAssignC(&m2str,"clustalw"); else if(m2c=='o') ajStrAssignC(&m2str,"own"); ma_matrix = ajAcdGetInfile("mamatrixfile"); gapc = ajAcdGetFloat("gapopen"); gapv = ajAcdGetFloat("gapextend"); endgaps = ajAcdGetBoolean("endgaps"); norgap = ajAcdGetBoolean("norgap"); nohgap = ajAcdGetBoolean("nohgap"); gap_dist = ajAcdGetInt("gapdist"); hgapres = ajAcdGetString("hgapres"); maxdiv = ajAcdGetInt("maxdiv"); tmp = ajStrNewC("fasta"); /* ** Start by writing sequences into a unique temporary file ** get file pointer to unique file */ fil_file = ajSeqoutNew(); tmpFilename = emma_getUniqueFileName(); if(!ajSeqoutOpenFilename( fil_file, tmpFilename)) embExitBad(); /* Set output format to fasta */ ajSeqoutSetFormatS( fil_file, tmp); while(ajSeqallNext(seqall, &seq)) { /* ** Check sequences are all of the same type ** Still to be done ** Write out sequences */ if (!nb) are_prot = ajSeqIsProt(seq); ajSeqoutWriteSeq(fil_file, seq); ++nb; } ajSeqoutClose(fil_file); if(nb < 2) ajFatal("Multiple alignments need at least two sequences"); /* Generate clustalw command line */ cmd = ajStrNewS(ajAcdGetpathC("clustalw")); /* add tmp file containing sequences */ ajStrAppendC(&cmd, " -infile="); ajStrAppendS(&cmd, tmpFilename); /* add out file name */ tmp_aln_outfile = emma_getUniqueFileName(); ajStrAppendC(&cmd, " -outfile="); ajStrAppendS(&cmd, tmp_aln_outfile); /* calculating just the nj tree or doing full alignment */ if(only_dend) ajStrAppendC(&cmd, " -tree"); else if(!use_dend) ajStrAppendC(&cmd, " -align"); /* Set sequence type from information from acd file */ if(are_prot) ajStrAppendC(&cmd, " -type=protein"); else ajStrAppendC(&cmd, " -type=dna"); /* ** set output to MSF format - will read in this file later and output ** user requested format */ ajStrAppendC(&cmd, " -output="); ajStrAppendC(&cmd, "gcg"); /* If going to do pairwise alignment */ if(!use_dend) { /* add fast pairwise alignments*/ if(!do_slow) { ajStrAppendC(&cmd, " -quicktree"); ajStrAppendC(&cmd, " -ktuple="); ajStrFromInt(&tmp, ktup); ajStrAppendS(&cmd, tmp); ajStrAppendC(&cmd, " -window="); ajStrFromInt(&tmp, window); ajStrAppendS(&cmd, tmp); if(nopercent) ajStrAppendC(&cmd, " -score=percent"); else ajStrAppendC(&cmd, " -score=absolute"); ajStrAppendC(&cmd, " -topdiags="); ajStrFromInt(&tmp, topdiags); ajStrAppendS(&cmd, tmp); ajStrAppendC(&cmd, " -pairgap="); ajStrFromInt(&tmp, gapw); ajStrAppendS(&cmd, tmp); } else { if(pairwise_matrix) { if(are_prot) ajStrAppendC(&cmd, " -pwmatrix="); else ajStrAppendC(&cmd, " -pwdnamatrix="); ajStrAppendS(&cmd, ajFileGetPrintnameS(pairwise_matrix)); } else { if(are_prot) { ajStrAppendC(&cmd, " -pwmatrix="); ajStrAppendS(&cmd, pwmstr); } else { ajStrAppendC(&cmd, " -pwdnamatrix="); ajStrAppendS(&cmd, pwdstr); } } ajStrAppendC(&cmd, " -pwgapopen="); ajStrFromFloat(&tmp, pw_gapc, 3); ajStrAppendS(&cmd, tmp); ajStrAppendC(&cmd, " -pwgapext="); ajStrFromFloat(&tmp, pw_gapv, 3); ajStrAppendS(&cmd, tmp); } } /* Multiple alignments */ /* using existing tree or generating new tree? */ if(use_dend) { ajStrAppendC(&cmd, " -usetree="); ajStrAppendS(&cmd, dend_filename); } else { /* use tmp file to hold dend file, will read back in later */ tmp_dendfilename = emma_getUniqueFileName(); ajStrAppendC(&cmd, " -newtree="); ajStrAppendS(&cmd, tmp_dendfilename); } if(ma_matrix) { if(are_prot) ajStrAppendC(&cmd, " -matrix="); else ajStrAppendC(&cmd, " -pwmatrix="); ajStrAppendS(&cmd, ajFileGetPrintnameS(ma_matrix)); } else { if(are_prot) { ajStrAppendC(&cmd, " -matrix="); ajStrAppendS(&cmd, m1str); } else { ajStrAppendC(&cmd, " -dnamatrix="); ajStrAppendS(&cmd, m2str); } } ajStrAppendC(&cmd, " -gapopen="); ajStrFromFloat(&tmp, gapc, 3); ajStrAppendS(&cmd, tmp); ajStrAppendC(&cmd, " -gapext="); ajStrFromFloat(&tmp, gapv, 3); ajStrAppendS(&cmd, tmp); ajStrAppendC(&cmd, " -gapdist="); ajStrFromInt(&tmp, gap_dist); ajStrAppendS(&cmd, tmp); ajStrAppendC(&cmd, " -hgapresidues="); ajStrAppendS(&cmd, hgapres); if(!endgaps) ajStrAppendC(&cmd, " -endgaps"); if(norgap) ajStrAppendC(&cmd, " -nopgap"); if(nohgap) ajStrAppendC(&cmd, " -nohgap"); ajStrAppendC(&cmd, " -maxdiv="); ajStrFromInt(&tmp, maxdiv); ajStrAppendS(&cmd, tmp); /* run clustalw */ /* ajFmtError("..%s..\n\n", ajStrGetPtr( cmd)); */ ajDebug("Executing '%S'\n", cmd); ajSysExecS(cmd); /* produce alignment file only if one was produced */ if(!only_dend) { /* read in tmp alignment output file to output through EMBOSS output */ seqin = ajSeqinNew(); /* ** add the Usa format to the start of the filename to tell EMBOSS ** format of file */ ajStrInsertC(&tmp_aln_outfile, 0, "msf::"); ajSeqinUsa(&seqin, tmp_aln_outfile); seqset = ajSeqsetNew(); if(ajSeqsetRead(seqset, seqin)) { ajSeqoutWriteSet(seqout, seqset); ajSeqoutClose(seqout); ajSeqinDel(&seqin); /* remove the Usa from the start of the string */ ajStrCutStart(&tmp_aln_outfile, 5); } else ajFmtError("Problem writing out EMBOSS alignment file\n"); } /* read in new tmp dend file (if produced) to output through EMBOSS */ if(tmp_dendfilename!=NULL) { tmp_dendfile = ajFileNewInNameS( tmp_dendfilename); if(tmp_dendfile!=NULL){ while(ajReadlineTrim(tmp_dendfile, &line)) ajFmtPrintF(dend_outfile, "%s\n", ajStrGetPtr( line)); ajFileClose(&tmp_dendfile); ajSysFileUnlinkS(tmp_dendfilename); } } ajSysFileUnlinkS(tmpFilename); if(!only_dend) ajSysFileUnlinkS(tmp_aln_outfile); ajStrDel(&pw_matrix); ajStrDel(&matrix); ajStrDel(&pw_dna_matrix); ajStrDel(&dna_matrix); ajStrDel(&tmp_dendfilename); ajStrDel(&dend_filename); ajStrDel(&tmp_aln_outfile); ajStrDel(&pwmstr); ajStrDel(&pwdstr); ajStrDel(&m1str); ajStrDel(&m2str); ajStrDel(&hgapres); ajStrDel(&cmd); ajStrDel(&tmp); ajStrDel(&tmpFilename); ajStrDel(&line); ajFileClose(&dend_outfile); ajFileClose(&tmp_dendfile); ajFileClose(&dend_file); ajFileClose(&pairwise_matrix); ajFileClose(&ma_matrix); ajSeqallDel(&seqall); ajSeqsetDel(&seqset); ajSeqDel(&seq); ajSeqoutDel(&seqout); ajSeqoutDel(&fil_file); ajSeqinDel(&seqin); embExit(); return 0; }
/* @funcstatic domainalign_stamp ********************************************** ** ** Call STAMP and process files. ** ** @param [r] prevdomain [AjPDomain] Previous domain. ** @param [r] domain [AjPDomain] This domain. ** @param [r] daf [AjPDirout] Domain alignment files. ** @param [r] super [AjPDirout] Superimposition files. ** @param [r] singlets [AjPDirout] Singlet files. ** @param [r] align [AjPStr] Align. ** @param [r] alignc [AjPStr] Alignc. ** @param [r] dom [AjPStr] Dom. ** @param [r] name [AjPStr] Name. ** @param [r] set [AjPStr] Name of set file. ** @param [r] scan [AjPStr] Name of scan file. ** @param [r] sort [AjPStr] Name of sort file. ** @param [r] log [AjPStr] Log file name. ** @param [r] out [AjPStr] Out file name. ** @param [r] keepsinglets [AjBool] Keep singlet sequences or not. ** @param [r] moden [ajint] Mode number. ** @param [r] noden [ajint] Node number. ** @param [r] nset [ajint] Number in set. ** @param [r] logf [AjPFile] Lof file. ** ** ** @return [void] True on success ** @@ ****************************************************************************/ static void domainalign_stamp(AjPDomain prevdomain, AjPDomain domain, AjPDirout daf, AjPDirout super, AjPDirout singlets, AjPStr align, AjPStr alignc, AjPStr dom, AjPStr name, AjPStr set, AjPStr scan, AjPStr sort, AjPStr log, AjPStr out, AjBool keepsinglets, ajint moden, ajint noden, ajint nset, AjPFile logf) { AjPStr exec = NULL; /* The UNIX command line to be executed. */ AjPFile clusterf = NULL; /* File pointer for log file. */ ajint ncluster = 0; /* Counter for the number of clusters. */ AjPStr line = NULL; /* Holds a line from the log file. */ AjPRegexp rexp = NULL; /* For parsing no. of clusters in log file */ AjPStr temp = NULL; /* A temporary string. */ ajint x = 0; /* Loop counter. */ exec = ajStrNew(); line = ajStrNew(); temp = ajStrNew(); rexp = ajRegCompC("^(Cluster:)"); ajDebug("domainalign_stamp name: '%S'\n", name); /* Call STAMP. */ ajFmtPrintS(&exec, "%S -l %S -s -n 2 -slide 5 -prefix %S -d %S", ajAcdGetpathC("stamp"), dom, name, set); ajFmtPrint("\n%S\n\n", exec); ajSysExecS(exec); ajFmtPrintS(&exec, "%S -f %S -s Sc 2.5", ajAcdGetpathC("sorttrans"), scan); ajFmtPrint("\n%S > %S\n\n", exec, sort); ajSysExecOutnameS(exec, sort); ajFmtPrintS(&exec, "%S -l %S -prefix %S", ajAcdGetpathC("stamp"), sort, name); ajFmtPrint("\n%S > %S\n\n", exec, log); ajSysExecOutnameS(exec, log); ajFmtPrintS(&exec, "%S -f %S -g -o %S", ajAcdGetpathC("transform"), sort, alignc); ajFmtPrint("\n%S\n\n", exec); ajSysExecS(exec); /* Count the number of clusters in the log file. */ if(!(clusterf=ajFileNewInNameS(log))) ajFatal("Could not open log file '%S'\n", log); ncluster=0; while(ajReadlineTrim(clusterf,&line)) if(ajRegExec(rexp,line)) ncluster++; ajFileClose(&clusterf); ajDebug("ncluster: %d\n", ncluster); /* Call STAMP ... calculate two fields for structural equivalence using threshold Pij value of 0.5, see stamp manual v4.1 pg 27. */ ajFmtPrintS(&exec,"%S -f %S.%d -min 0.5", ajAcdGetpathC("poststamp"), name, ncluster); ajFmtPrint("%S\n\n", exec); ajSysExecS(exec); /* Call STAMP ... convert block format alignment into clustal format. */ ajFmtPrintS(&exec,"%S -f %S.%d.post", ajAcdGetpathC("ver2hor"), name, ncluster); ajFmtPrint("%S > %S\n\n", exec, out); ajSysExecOutnameS(exec, out); /* Process STAMP alignment file and generate alignment file for output. */ domainalign_ProcessStampFile(out, align, prevdomain, noden, logf); /* Remove all temporary files. */ for(x=1;x<ncluster+1;x++) { ajFmtPrintS(&temp, "%S.%d", name, x); ajSysFileUnlinkS(temp); } ajFmtPrintS(&temp, "%S.%d.post", name, ncluster); ajSysFileUnlinkS(temp); ajStrDel(&exec); ajStrDel(&line); ajStrDel(&temp); ajRegFree(&rexp); return; }
static void jaspextract_copyfiles(AjPStr directory) { AjPStr matrixfile = NULL; AjPList flist = NULL; AjPStr wild = NULL; AjPStr entry = NULL; AjPStr bname = NULL; AjPStr line = NULL; AjPStr dest = NULL; const AjPStr datadir = NULL; ajuint preflen = 0; ajuint i = 0; const char *p = NULL; AjPFile inf = NULL; AjPFile outf = NULL; matrixfile = ajStrNew(); flist = ajListNew(); wild = ajStrNewC("*.pfm"); bname = ajStrNew(); line = ajStrNew(); dest = ajStrNew(); datadir = ajDatafileValuePath(); if(!datadir) ajFatal("jaspextract: Cannot determine the EMBOSS data directory"); ajFmtPrintS(&matrixfile,"%S%s",directory,MATRIXFILE); if(!ajFilenameExistsRead(matrixfile)) ajFatal("jaspextract: Directory (%S) doesn't appear to be a JASPAR " "one\nNo matrix_list.txt file found",directory); ajFilelistAddPathWild(flist, directory, wild); while(ajListPop(flist,(void **)&entry)) { ajStrAssignS(&bname,entry); ajFilenameTrimPath(&bname); i = 0; while(Jprefix[i].Prefix) { if(!ajStrPrefixC(bname,Jprefix[i].Prefix)) { ++i; continue; } preflen = strlen(Jprefix[i].Prefix); p = ajStrGetPtr(bname); if(p[preflen]>='0' && p[preflen]<='9') break; ++i; } if(!Jprefix[i].Prefix) { ajStrDel(&entry); continue; } ajFmtPrintS(&dest,"%S%s%c%S",datadir,Jprefix[i].Directory,SLASH_CHAR, bname); outf = ajFileNewOutNameS(dest); if(!outf) ajFatal("Cannot open output file %S",dest); /* Avoid UNIX copy for portability */ inf = ajFileNewInNameS(entry); if(!inf) ajFatal("Cannot open input file: %S",entry); while(ajReadlineTrim(inf,&line)) ajFmtPrintF(outf,"%S\n",line); ajFileClose(&inf); ajFileClose(&outf); ajStrDel(&entry); } ajListFree(&flist); ajStrDel(&wild); ajStrDel(&dest); ajStrDel(&line); ajStrDel(&bname); ajStrDel(&matrixfile); return; }
/* @funcstatic domainalign_ProcessTcoffeeFile ********************************* ** ** Parses tcoffee output. ** ** @param [r] in [AjPStr] Name of TCOFFEE input file ** @param [r] align [AjPStr] Name of sequence alignment file for output ** @param [r] domain [AjPDomain] Domain being aligned ** @param [r] noden [ajint] Node-level of alignment** ** @param [r] logf [AjPFile] Log file ** ** @return [void] True on success ** @@ ****************************************************************************/ static void domainalign_ProcessTcoffeeFile(AjPStr in, AjPStr align, AjPDomain domain, ajint noden, AjPFile logf) { AjPFile outf = NULL; /* Output file pointer. */ AjPFile inf = NULL; /* Input file pointer. */ AjPStr temp1 = NULL; /* Temporary string. */ AjPStr temp2 = NULL; /* Temporary string. */ AjPStr temp3 = NULL; /* Temporary string. */ AjPStr line = NULL; /* Line of text from input file. */ /* Initialise strings. */ line = ajStrNew(); temp1 = ajStrNew(); temp2 = ajStrNew(); temp3 = ajStrNew(); /* Open input and output files. */ if(!(inf=ajFileNewInNameS(in))) ajFatal("Could not open input file in domainalign_ProcessTcoffeeFile"); if(!(outf=ajFileNewOutNameS(align))) ajFatal("Could not open output file in domainalign_ProcessTcoffeeFile"); /*Write DOMAIN classification records to file*/ if((domain->Type == ajSCOP)) { ajFmtPrintF(outf,"# TY SCOP\n# XX\n"); ajFmtPrintF(outf,"# CL %S",domain->Scop->Class); ajFmtPrintSplit(outf,domain->Scop->Fold,"\n# XX\n# FO ",75," \t\n\r"); ajFmtPrintSplit(outf,domain->Scop->Superfamily,"# XX\n# SF ",75," \t\n\r"); ajFmtPrintSplit(outf,domain->Scop->Family,"# XX\n# FA ",75," \t\n\r"); ajFmtPrintF(outf,"# XX\n"); } else { ajFmtPrintF(outf,"# TY CATH\n# XX\n"); ajFmtPrintF(outf,"# CL %S",domain->Cath->Class); ajFmtPrintSplit(outf,domain->Cath->Architecture,"\n# XX\n# AR ",75," \t\n\r"); ajFmtPrintSplit(outf,domain->Cath->Topology,"# XX\n# TP ",75," \t\n\r"); ajFmtPrintSplit(outf,domain->Cath->Superfamily,"# XX\n# SF ",75," \t\n\r"); ajFmtPrintF(outf,"# XX\n"); } if((domain->Type == ajSCOP)) { if(noden==1) ajFmtPrintF(outf,"# SI %d\n# XX\n",domain->Scop->Sunid_Class); else if(noden==2) ajFmtPrintF(outf,"# SI %d\n# XX\n",domain->Scop->Sunid_Fold); else if(noden==3) ajFmtPrintF(outf,"# SI %d\n# XX\n",domain->Scop->Sunid_Superfamily); else if(noden==4) ajFmtPrintF(outf,"# SI %d\n# XX\n", domain->Scop->Sunid_Family); else ajFatal("Node number error in domainalign_ProcessStampFile"); } else { if(noden==5) ajFmtPrintF(outf,"# SI %d\n# XX\n", domain->Cath->Class_Id); else if(noden==6) ajFmtPrintF(outf,"# SI %d\n# XX\n", domain->Cath->Arch_Id); else if(noden==7) ajFmtPrintF(outf,"# SI %d\n# XX\n",domain->Cath->Topology_Id); else if(noden==8) ajFmtPrintF(outf,"# SI %d\n# XX\n",domain->Cath->Superfamily_Id); else if(noden==9) ajFmtPrintF(outf,"# SI %d\n# XX\n",domain->Cath->Family_Id); else ajFatal("Node number error in domainalign_ProcessStampFile"); } /* Start of code for reading input file. */ /*Ignore everything up to first line beginning with 'Number'*/ while((ajReadlineTrim(inf,&line))) /* ajFileReadLine will trim the tailing \n. */ if((ajStrGetCharPos(line, 1)=='\0')) break; /* Read rest of input file. */ while((ajReadlineTrim(inf,&line))) { if((ajStrGetCharPos(line, 1)=='\0')) continue; /* Print the number line out as it is. */ else if(ajStrPrefixC(line,"CLUSTAL")) continue; else if(ajStrPrefixC(line," ")) ajFmtPrintF(outf,"\n"); /* write out a block of protein sequences. */ else { /* Read only the 7 characters of the domain identifier code in. */ ajFmtScanS(line, "%S %S", &temp1,&temp3); ajStrAssignSubS(&temp2, temp1, 0, 6); /* Read the sequence ajStrAssignSubS(&temp3, line, 13, 69); ajStrExchangeSetCC(&temp3, " ", "X"); ajStrFmtUpper(&temp3);*/ /* Write domain id code and sequence out. */ ajFmtPrintF(outf,"%-13S%S\n",temp2, temp3); } } /* Clean up and close input and output files. */ ajFileClose(&outf); ajFileClose(&inf); ajStrDel(&line); ajStrDel(&temp1); ajStrDel(&temp2); ajStrDel(&temp3); /* All done. */ return; }
/* @prog ssematch *********************************************************** ** ** Searches a DCF file (domain classification file) for secondary structure ** matches. ** ****************************************************************************/ int main(int argc, char **argv) { /* Variables declarations */ AjPFile dcfin = NULL; /* Domain classification file */ AjPFile ssin = NULL; /* Secondary structure input file*/ AjPMatrixf matrix = NULL; /* Substitution matrix */ AjPFile out_ss = NULL; /* For ss top matches*/ AjPFile out_se = NULL; /* For se top matches*/ AjPFile outfile = NULL; /* Output file*/ AjPFile logf = NULL; /* Log file */ float gapopen_sss = 0.0; /* Gap insertion penalty */ float gapopen_sse = 0.0; float gapopen = 0.0; float gapextend_sss = 0.0; /* Gap extension penalty */ float gapextend_sse = 0.0; float gapextend = 0.0; ajint max_hits = 0; /* number of top alignments to display*/ ajint mode = 0; ajint x = 0; AjPScop temp_scop = NULL; /* scop object pointer*/ AjPList scop_list = NULL; /* list of scop objects for entire domain classification file */ AjIList iter = NULL; AjPStr msg = NULL; /* Pointer to String used for messages */ AjPStr line = NULL; AjPStr qse = NULL; /* query secondary structure elements*/ AjPStr qss = NULL; /* query secondary structure (by residue)*/ AjPSeq q3se = NULL; /* query secondary structure elements, 3-letter code*/ AjPSeq q3ss = NULL; /* query secondary structure (by residue), 3-letter code*/ AjPSeq query = NULL; /* Read data from acd */ embInitPV("ssematch",argc,argv,"DOMAINATRIX",VERSION); dcfin = ajAcdGetInfile("dcfinfile"); ssin = ajAcdGetInfile("ssinfile"); max_hits = ajAcdGetInt("maxhits"); matrix = ajAcdGetMatrixf("datafile"); gapopen_sss = ajAcdGetFloat("rgapopen"); gapextend_sss = ajAcdGetFloat("rgapextend"); gapopen_sse = ajAcdGetFloat("egapopen"); gapextend_sse = ajAcdGetFloat("egapextend"); out_ss = ajAcdGetOutfile("outssfile"); out_se = ajAcdGetOutfile("outsefile"); logf = ajAcdGetOutfile("logfile"); /* Create list of scop objects for entire input domain classification file. */ scop_list = ajListNew(); while((temp_scop = (ajScopReadCNew(dcfin, "*")))) ajListPushAppend(scop_list,temp_scop); /* Error handing if domain classification file was empty. */ if(!(ajListGetLength(scop_list))) { ajWarn("Empty list from scop input file\n"); ajFileClose(&dcfin); ajFileClose(&ssin); ajMatrixfDel(&matrix); ajFileClose(&out_ss); ajFileClose(&out_se); ajFileClose(&logf); while(ajListPop(scop_list, (void *) &temp_scop)) ajScopDel(&temp_scop); ajListFree(&scop_list); ajListIterDel(&iter); ajExit(); return 1; } /* Error handling in case of empty query file. */ if(ssin == NULL) { ajWarn("Empty secondary structure query file\n"); ajFileClose(&dcfin); ajFileClose(&ssin); ajMatrixfDel(&matrix); ajFileClose(&out_ss); ajFileClose(&out_se); ajFileClose(&logf); while(ajListPop(scop_list, (void *) &temp_scop)) ajScopDel(&temp_scop); ajListFree(&scop_list); ajListIterDel(&iter); ajExit(); return 1; } /* Assign sequences in query file to sequence objects. */ qse = ajStrNew(); qss = ajStrNew(); while(ajReadlineTrim(ssin,&line)) { /* SE string */ if(ajStrPrefixC(line,"SE")) { ajFmtScanS(line, "%*s %S", &qse); /* Convert this string to 3-letter code & then convert to AjPSeq object. */ q3se = ssematch_convertbases(qse); } /* SS string */ else if(ajStrPrefixC(line,"SS")) { while((ajReadlineTrim(ssin,&line)) && !ajStrPrefixC(line,"XX")) ajStrAppendS(&qss,line); ajStrRemoveWhite(&qss); /* Convert this string to 3-letter code & then to AjPSeq object. */ q3ss = ssematch_convertbases(qss); } } /* For se & then for ss, modes 0 & 1. */ for(mode = 0; mode <= 1; mode++) { /* Assign arguments for alignment function. */ if (mode == 0) { query = q3se; gapopen = gapopen_sse; gapextend = gapextend_sse; outfile = out_se; } else if(mode == 1) { query = q3ss; gapopen = gapopen_sss; gapextend = gapextend_sss; outfile = out_ss; } /* Iterate through list of scop objects & calculate alignment scores. */ iter=ajListIterNew(scop_list); while((temp_scop=(AjPScop)ajListIterGet(iter))) { /* The function extracts the se (mode 0) or ss (mode 1) subject sequences from the scop object, performs a Needleman-Wunsch global alignment with the query sequence & allocates the score to the Score element of the scop object*/ if(!(ssematch_NWScore(temp_scop , query, mode, matrix, gapopen, gapextend))) { ajFmtPrintF(logf, "%-15s\n", "ALIGNMENT"); ajFmtPrintF(logf, "Could not align sequence in scop domain %S\n ", temp_scop->Entry); ajFmtPrintS(&msg, "Could not align sequence in scop domain %S\n ", temp_scop->Entry); ajWarn(ajStrGetPtr(msg)); continue; } } ajListIterDel(&iter); temp_scop = NULL; /* Sort list of Scop objects by Score */ ajListSort(scop_list, ssematch_CompScoreInv); iter=ajListIterNew(scop_list); /* Write top-scoring hits to outfile. */ for(x=0; x < max_hits; x++ ) { temp_scop=(AjPScop)ajListIterGet(iter); /* Print score to output file. */ ajFmtPrintF(outfile, "XX ALIGNMENT SCORE %.3f\nXX\n", temp_scop->Score); /* Could also write alignment - later modification. */ if(!ajScopWrite(outfile, temp_scop)) ajFatal("Could not write output file %S\n", outfile); } ajListIterDel(&iter); temp_scop = NULL; } /* Memoryt management. */ ajFileClose(&dcfin); ajFileClose(&ssin); ajMatrixfDel(&matrix); ajFileClose(&out_ss); ajFileClose(&out_se); ajFileClose(&logf); while(ajListPop(scop_list, (void *) &temp_scop)) ajScopDel(&temp_scop); ajListFree(&scop_list); ajStrDel(&msg); ajStrDel(&line); ajStrDel(&qse); ajStrDel(&qss); ajSeqDel(&q3se); ajSeqDel(&q3ss); ajExit(); return 0; }
EmbPMatPrints embMatProtReadInt(AjPFile fp) { EmbPMatPrints ret; AjPStr line; ajint i; ajuint j; ajuint m; const char *p; line = ajStrNewC("#"); p = ajStrGetPtr(line); while(!*p || *p=='#' || *p=='!' || *p=='\n') { if(!ajReadlineTrim(fp,&line)) { ajStrDel(&line); return NULL; } p = ajStrGetPtr(line); } ajDebug("embMatProtReadint starting\n"); ajDebug ("Line: %S\n", line); AJNEW0 (ret); ret->cod = ajStrNew(); ajStrAssignS(&ret->cod,line); ajReadlineTrim(fp,&line); ret->acc = ajStrNew(); ajStrAssignS(&ret->acc,line); ajReadlineTrim(fp,&line); ajStrToUint(line,&ret->n); ajReadlineTrim(fp,&line); ret->tit = ajStrNew(); ajStrAssignS(&ret->tit,line); ajDebug ("Lineb: %S\n", line); AJCNEW(ret->len, ret->n); AJCNEW(ret->max, ret->n); AJCNEW(ret->thresh, ret->n); AJCNEW(ret->matrix, ret->n); for(m=0;m<ret->n;++m) { ajReadlineTrim(fp,&line); ajStrToUint(line,&ret->len[m]); ajReadlineTrim(fp,&line); ajStrToUint(line,&ret->thresh[m]); ajReadlineTrim(fp,&line); ajStrToUint(line,&ret->max[m]); ajDebug ("m: %d/%d len:%d thresh:%d max:%d\n", m, ret->n, ret->len[m], ret->thresh[m], ret->max[m]); for(i=0;i<26;++i) { AJCNEW0(ret->matrix[m][i], ret->len[m]); ajReadlineTrim(fp,&line); ajDebug ("Linec [%d][%d]: %S\n", m, i, line); p = ajStrGetPtr(line); for(j=0;j<ret->len[m];++j) { if(!j) p = ajSysFuncStrtok(p," "); else p = ajSysFuncStrtok(NULL," "); sscanf(p,"%u",&ret->matrix[m][i][j]); } } } ajReadlineTrim(fp,&line); ajDebug ("Linec: %S\n", line); ajStrDel(&line); return ret; }
static AjBool dbxflat_ParseGenbank(EmbPBtreeEntry entry, AjPFile inf) { AjPStr line = NULL; ajlong pos = 0L; AjBool ret = ajTrue; AjPStr sumline = NULL; line = ajStrNewC(""); sumline = ajStrNew(); while(!ajStrPrefixC(line,"//") && ret) { if(ajStrPrefixC(line,"LOCUS")) { entry->fpos = pos; ajFmtScanS(line,"%*S%S",&entry->id); } if(svfield) if(ajStrPrefixC(line,"VERSION")) embBtreeGenBankAC(line,svfield->data); if(accfield) if(ajStrPrefixC(line,"ACCESSION")) embBtreeGenBankAC(line,accfield->data); if(keyfield) if(ajStrPrefixC(line,"KEYWORDS")) { ajStrAssignS(&sumline,line); ret = ajReadlineTrim(inf,&line); while(ret && *MAJSTRGETPTR(line)==' ') { ajStrAppendS(&sumline,line); ret = ajReadlineTrim(inf,&line); } ajStrRemoveWhiteExcess(&sumline); embBtreeGenBankKW(sumline,keyfield->data,keyfield->len); continue; } if(desfield) if(ajStrPrefixC(line,"DEFINITION")) { ajStrAssignS(&sumline,line); ret = ajReadlineTrim(inf,&line); while(ret && *MAJSTRGETPTR(line)==' ') { ajStrAppendS(&sumline,line); ret = ajReadlineTrim(inf,&line); } ajStrRemoveWhiteExcess(&sumline); embBtreeGenBankDE(sumline,desfield->data,desfield->len); continue; } if(orgfield) if(ajStrPrefixC(line,"SOURCE")) { ret = ajReadlineTrim(inf,&line); ajStrAppendC(&line,";"); while(ret && *MAJSTRGETPTR(line)==' ') { ajStrAppendS(&sumline,line); ret = ajReadlineTrim(inf,&line); } ajStrRemoveWhiteExcess(&sumline); embBtreeGenBankTX(sumline,orgfield->data,orgfield->len); continue; } pos = ajFileResetPos(inf); if(!ajReadlineTrim(inf,&line)) ret = ajFalse; } ajStrDel(&line); ajStrDel(&sumline); return ret; }
int main(int argc, char **argv) { AjPSeqall seqall; AjPSeq seq = NULL; AjPReport outf = NULL; AjPFile inf = NULL; ajint begin; ajint end; AjPList l = NULL; AjPStr strand = NULL; AjPStr substr = NULL; AjPStr line = NULL; AjPStr name = NULL; AjPStr acc = NULL; AjPStr bf = NULL; AjPStr menu; AjPStr pattern = NULL; AjPStr opattern = NULL; AjPStr pname = NULL; AjPStr key = NULL; AjPStr value = NULL; AjPTable atable = NULL; AjPTable btable = NULL; ajint mismatch; ajint minlength; ajint sum; ajint v; char cp; const char *p; embInit("tfscan", argc, argv); seqall = ajAcdGetSeqall("sequence"); outf = ajAcdGetReport("outfile"); mismatch = ajAcdGetInt("mismatch"); minlength = ajAcdGetInt("minlength"); menu = ajAcdGetListSingle("menu"); pname = ajStrNew(); cp=ajStrGetCharFirst(menu); if(cp=='F') ajStrAssignC(&pname,"tffungi"); else if(cp=='I') ajStrAssignC(&pname,"tfinsect"); else if(cp=='O') ajStrAssignC(&pname,"tfother"); else if(cp=='P') ajStrAssignC(&pname,"tfplant"); else if(cp=='V') ajStrAssignC(&pname,"tfvertebrate"); else if(cp=='C') inf = ajAcdGetDatafile("custom"); if(cp!='C') { inf = ajDatafileNewInNameS(pname); if(!inf) ajFatal("Either EMBOSS_DATA undefined or TFEXTRACT needs running"); } name = ajStrNew(); acc = ajStrNew(); bf = ajStrNewC(""); substr = ajStrNew(); line = ajStrNew(); pattern = ajStrNewC("AA"); opattern = ajStrNew(); while(ajSeqallNext(seqall, &seq)) { begin=ajSeqallGetseqBegin(seqall); end=ajSeqallGetseqEnd(seqall); ajStrAssignC(&name,ajSeqGetNameC(seq)); strand=ajSeqGetSeqCopyS(seq); ajStrAssignSubC(&substr,ajStrGetPtr(strand),begin-1,end-1); ajStrFmtUpper(&substr); l=ajListNew(); atable = ajTablestrNew(1000); btable = ajTablestrNew(1000); sum=0; while(ajReadlineTrim(inf,&line)) { p = ajStrGetPtr(line); if(!*p || *p=='#' || *p=='\n' || *p=='!') continue; ajFmtScanS(line,"%S%S%S",&pname,&pattern,&acc); p += ajStrGetLen(pname); while(*p && *p==' ') ++p; p += ajStrGetLen(pattern); while(*p && *p==' ') ++p; p += ajStrGetLen(acc); while(*p && *p==' ') ++p; ajStrAssignS(&opattern,pattern); ajStrAssignC(&bf,p); /* rest of line */ v = embPatVariablePattern(pattern,substr,pname,l,0, mismatch,begin); if(v) { key = ajStrNewS(pname); value = ajStrNewS(acc); ajTablePut(atable,(void *)key,(void *)value); key = ajStrNewS(pname); value = ajStrNewS(bf); ajTablePut(btable,(void *)key,(void *)value); } sum += v; } if(sum) tfscan_print_hits(&l,sum,outf,atable,seq,minlength, btable); ajFileSeek(inf,0L,0); ajListFree(&l); ajTablestrFree(&atable); ajTablestrFree(&btable); ajStrDel(&strand); } ajStrDel(&line); ajStrDel(&name); ajStrDel(&acc); ajStrDel(&pname); ajStrDel(&opattern); ajStrDel(&bf); ajStrDel(&pattern); ajStrDel(&substr); ajSeqDel(&seq); ajFileClose(&inf); ajReportClose(outf); ajReportDel(&outf); ajSeqallDel(&seqall); ajSeqDel(&seq); ajStrDel(&menu); embExit(); return 0; }
static void jaspscan_ParseInput(const AjPStr dir, const AjPStr jaspdir, const AjPStr mats, const AjPStr excl, ajuint *recurs, AjPList ret) { ajuint nm = 0; ajuint ne = 0; AjPStr *carr = NULL; AjPStr *earr = NULL; AjPFile inf = NULL; AjPStr line = NULL; AjPStr comm = NULL; AjPStr val = NULL; ajuint i; ajuint j; char c; ajuint rlen = 0; if(*recurs > JASPSCAN_RECURS) ajFatal("Too many recursion levels in matrix list files"); line = ajStrNew(); comm = ajStrNew(); if(mats) { nm = ajArrCommaList(mats,&carr); for(i=0; i < nm; ++i) { if(ajStrGetCharFirst(carr[i]) != '@') ajStrFmtUpper(&carr[i]); if(ajStrMatchC(carr[i],"ALL")) { jaspscan_GetFileList(dir, jaspdir, "*", ret); ajListSortUnique(ret, ajStrVcmp, jaspscan_strdel); } else if(ajStrGetCharFirst(carr[i]) == '@') { ajStrTrimStartC(&carr[i],"@"); inf = ajFileNewInNameS(carr[i]); if(!inf) ajFatal("Cannot open list file %S",carr[i]); while(ajReadlineTrim(inf,&line)) { ajStrRemoveWhite(&line); c = ajStrGetCharFirst(line); if(c == '#' || c== '!') continue; if(ajStrGetLen(comm)) ajStrAppendC(&comm,","); ajStrFmtUpper(&line); ajStrAppendS(&comm,line); } *recurs += 1; jaspscan_ParseInput(dir,jaspdir,comm,NULL,recurs,ret); *recurs -= 1; ajListSortUnique(ret, ajStrVcmp, jaspscan_strdel); ajFileClose(&inf); } else { jaspscan_GetFileList(dir,jaspdir,ajStrGetPtr(carr[i]),ret); ajListSortUnique(ret, ajStrVcmp, jaspscan_strdel); } } for(i=0; i < nm; ++i) ajStrDel(&carr[i]); AJFREE(carr); } if(excl) { ne = ajArrCommaList(excl,&earr); for(i=0; i < ne; ++i) { if(ajStrGetCharFirst(earr[i]) != '@') ajStrFmtUpper(&earr[i]); if(ajStrGetCharFirst(earr[i]) == '@') { ajStrTrimStartC(&earr[i],"@"); inf = ajFileNewInNameS(earr[i]); if(!inf) ajFatal("Cannot open list file %S",earr[i]); while(ajReadlineTrim(inf,&line)) { ajStrRemoveWhite(&line); c = ajStrGetCharFirst(line); if(c == '#' || c== '!') continue; if(ajStrGetLen(comm)) ajStrAppendC(&comm,","); ajStrFmtUpper(&line); ajStrAppendS(&comm,line); } *recurs += 1; jaspscan_ParseInput(dir,jaspdir,NULL,comm,recurs,ret); *recurs -= 1; ajListSortUnique(ret, ajStrVcmp, jaspscan_strdel); ajFileClose(&inf); } else { ajStrAssignS(&line,earr[i]); ajStrAppendC(&line,J_EXT); rlen = ajListGetLength(ret); for(j=0; j < rlen; ++j) { ajListPop(ret,(void **)&val); if(ajStrSuffixS(val,line)) ajStrDel(&val); else ajListPushAppend(ret,(void *)val); } } } for(i=0; i < ne; ++i) ajStrDel(&earr[i]); AJFREE(earr); } ajStrDel(&line); ajStrDel(&comm); return; }
static void domainalign_ProcessStampFile(AjPStr in, AjPStr out, AjPDomain domain, ajint noden, AjPFile logf) { AjPFile outf = NULL; /* Output file pointer. */ AjPFile inf = NULL; /* Input file pointer. */ AjPStr temp1 = NULL; /* Temporary string. */ AjPStr temp2 = NULL; /* Temporary string. */ AjPStr temp3 = NULL; /* Temporary string. */ AjPStr line = NULL; /* Line of text from input file. */ ajint blk = 1; /* Count of the current block in the input file. Block 1 is the numbering and protein sequences, Block 2 is the secondary structure, Block 3 is the Very/Less/Post similar records*/ AjBool ok = ajFalse; /* Initialise strings. */ line = ajStrNew(); temp1 = ajStrNew(); temp2 = ajStrNew(); temp3 = ajStrNew(); /* Open input and output files. */ if(!(inf=ajFileNewInNameS(in))) ajFatal("Could not open input file in domainalign_ProcessStampFile"); /* Start of code for reading input file. Ignore everything up to first line beginning with 'Number'. */ while((ajReadlineTrim(inf,&line))) { /* ajFileReadLine will trim the tailing \n. */ if((ajStrGetCharPos(line, 1)=='\0')) { ok = ajTrue; break; } } /* Read rest of input file. */ if(ok) { /* Write DOMAIN classification records to file. */ if(!(outf=ajFileNewOutNameS(out))) ajFatal("Could not open output file in domainalign_ProcessStampFile"); if((domain->Type == ajSCOP)) { ajFmtPrintF(outf,"# TY SCOP\n# XX\n"); ajFmtPrintF(outf,"# CL %S",domain->Scop->Class); ajFmtPrintSplit(outf,domain->Scop->Fold,"\n# XX\n# FO ", 75," \t\n\r"); ajFmtPrintSplit(outf,domain->Scop->Superfamily,"# XX\n# SF ", 75," \t\n\r"); ajFmtPrintSplit(outf,domain->Scop->Family,"# XX\n# FA ", 75," \t\n\r"); ajFmtPrintF(outf,"# XX\n"); } else { ajFmtPrintF(outf,"# TY CATH\n# XX\n"); ajFmtPrintF(outf,"# CL %S",domain->Cath->Class); ajFmtPrintSplit(outf,domain->Cath->Architecture,"\n# XX\n# AR ", 75," \t\n\r"); ajFmtPrintSplit(outf,domain->Cath->Topology,"# XX\n# TP ",75, " \t\n\r"); ajFmtPrintSplit(outf,domain->Cath->Superfamily,"# XX\n# SF ",75, " \t\n\r"); ajFmtPrintF(outf,"# XX\n"); } if((domain->Type == ajSCOP)) { if(noden==1) ajFmtPrintF(outf,"# SI %d\n# XX",domain->Scop->Sunid_Class); else if(noden==2) ajFmtPrintF(outf,"# SI %d\n# XX",domain->Scop->Sunid_Fold); else if(noden==3) ajFmtPrintF(outf,"# SI %d\n# XX", domain->Scop->Sunid_Superfamily); else if(noden==4) ajFmtPrintF(outf,"# SI %d\n# XX", domain->Scop->Sunid_Family); else ajFatal("Node number error in domainalign_ProcessStampFile"); } else { if(noden==5) ajFmtPrintF(outf,"# SI %d\n# XX", domain->Cath->Class_Id); else if(noden==6) ajFmtPrintF(outf,"# SI %d\n# XX", domain->Cath->Arch_Id); else if(noden==7) ajFmtPrintF(outf,"# SI %d\n# XX",domain->Cath->Topology_Id); else if(noden==8) ajFmtPrintF(outf,"# SI %d\n# XX", domain->Cath->Superfamily_Id); else if(noden==9) ajFmtPrintF(outf,"# SI %d\n# XX",domain->Cath->Family_Id); else ajFatal("Node number error in domainalign_ProcessStampFile"); } while((ajReadlineTrim(inf,&line))) { /* Increment counter for block of file. */ if((ajStrGetCharPos(line, 1)=='\0')) { blk++; if(blk==4) blk=1; continue; } /* Block of numbering line and protein sequences. */ if(blk==1) { /* Print the number line out as it is. */ if(ajStrPrefixC(line,"Number")) ajFmtPrintF(outf,"\n# %7s %S\n"," ", line); else { /* Read only the 7 characters of the domain identifier code in. */ ajFmtScanS(line, "%S", &temp1); ajStrAssignSubS(&temp2, temp1, 0, 6); /* Read the sequence. */ ajStrAssignSubS(&temp3, line, 13, 69); ajStrExchangeSetCC(&temp3, " ", "X"); ajFmtPrintF(logf, "Replaced ' ' in STAMP alignment " "with 'X'\n"); ajStrFmtUpper(&temp3); /* Write domain id code and sequence out. */ ajFmtPrintF(outf,"%-15S%7d %S%7d\n", temp2, 0, temp3, 0); } } /* Secondary structure filled with '????' (unwanted). */ else if(blk==2) { continue; } /* Similarity lines. */ else { if(ajStrPrefixC(line,"Post")) { /* Read the sequence. */ ajStrAssignSubS(&temp3, line, 13, 69); /* Write post similar line out. */ ajFmtPrintF(outf,"%-15s%7s %S\n","# Post_similar", " ", temp3); } /* Ignore Very and Less similar lines. */ else continue; } } } else /* ok == ajFalse. */ { ajWarn("\n***********************************************\n" "* STAMP was called but output file was EMPTY! *\n" "* NO OUTPUT FILE GENERATED FOR THIS NODE. *\n" "***********************************************\n"); ajFmtPrintF(logf, "STAMP called but output file empty. " "No output file for this node!"); } /* Clean up and close input and output files. */ ajFileClose(&outf); ajFileClose(&inf); ajStrDel(&line); ajStrDel(&temp1); ajStrDel(&temp2); ajStrDel(&temp3); /* All done. */ return; }
static AjPTable jaspscan_ReadFamList(const AjPStr jaspdir) { AjPTable ret = NULL; AjPStr lfile = NULL; AjPStr line = NULL; AjPStr key = NULL; AjPStr str = NULL; PJspmat info = NULL; AjPFile inf = NULL; const char *p = NULL; const char *q = NULL; lfile = ajStrNew(); line = ajStrNew(); str = ajStrNew(); ajFmtPrintS(&lfile,"%S%s%s",jaspdir,SLASH_STRING,J_LIST); inf = ajDatafileNewInNameS(lfile); if(!inf) ajFatal("Matrix list file %S not found",lfile); ret = ajTablestrNewLen(JASPTAB_GUESS); while(ajReadlineTrim(inf,&line)) { info = jaspscan_infonew(); ajFmtScanS(line,"%S%S",&info->id,&info->num); p = ajStrGetPtr(line); while(*p !='\t') ++p; ++p; while(*p != '\t') ++p; ++p; q = p; while(*q != '\t') ++q; ajStrAssignSubC(&info->name,p,0,q-p-1); ++q; p = q; while(*q != ';') ++q; ajStrAssignSubC(&info->klass,p,0,q-p-1); ajStrRemoveWhiteExcess(&info->klass); p = q+1; while(*p) { q = p; while(* q && *q != ';') ++q; ajStrAssignSubC(&str,p,0,q-p-1); ajStrRemoveWhiteExcess(&str); jaspscan_coretoken(info, str); if(!*q) p = q; else p = q +1; } key = ajStrNew(); ajStrAssignS(&key,info->id); ajTablePut(ret,(void *)key,(void *) info); } ajFileClose(&inf); ajStrDel(&lfile); ajStrDel(&line); ajStrDel(&str); return ret; }
static void primersearch_read_primers(AjPList *primerList, AjPFile primerFile, ajint mmp) { AjPStr rdline = NULL; AjPStrTok handle = NULL; ajint nprimers = 0; Primer primdata = NULL; while (ajReadlineTrim(primerFile, &rdline)) { primdata = NULL; if (ajStrGetCharFirst(rdline) == '#') continue; if (ajStrSuffixC(rdline, "..")) continue; AJNEW(primdata); primdata->Name = NULL; primersearch_initialise_pguts(&primdata->forward); primersearch_initialise_pguts(&primdata->reverse); primdata->hitlist = ajListNew(); handle = ajStrTokenNewC(rdline, " \t"); ajStrTokenNextParse(&handle, &primdata->Name); ajStrTokenNextParse(&handle, &primdata->forward->patstr); ajStrFmtUpper(&primdata->forward->patstr); ajStrTokenNextParse(&handle, &primdata->reverse->patstr); ajStrFmtUpper(&primdata->reverse->patstr); ajStrTokenDel(&handle); /* copy patterns for Henry Spencer code */ ajStrAssignC(&primdata->forward->origpat, ajStrGetPtr(primdata->forward->patstr)); ajStrAssignC(&primdata->reverse->origpat, ajStrGetPtr(primdata->reverse->patstr)); /* set the mismatch level */ primdata->forward->mm = (ajint) (ajStrGetLen(primdata->forward->patstr)*mmp)/100; primdata->reverse->mm = (ajint) (ajStrGetLen(primdata->reverse->patstr)*mmp)/100; if(primersearch_classify_and_compile(&primdata)) { ajListPushAppend(*primerList, primdata); nprimers++; } else /* there was something funny about the primer sequences */ { ajUser("Cannot use %s\n", ajStrGetPtr(primdata->Name)); primersearch_free_pguts(&primdata->forward); primersearch_free_pguts(&primdata->reverse); ajStrDel(&primdata->Name); ajListFree(&primdata->hitlist); ajListFree(&primdata->hitlist); AJFREE(primdata); } } ajStrDel(&rdline); return; }