AjPStr embPropProt1to3(AjPSeq seq, ajint pad) { const char *p; const char *p3; AjPStr temp; ajint i; temp = ajStrNewRes(ajSeqGetLen(seq)*3 + pad+1); /* put any required padding spaces at the start */ for(i=0; i<pad; i++) ajStrAppendC(&temp, " "); for(p=ajSeqGetSeqC(seq); *p; p++) { if(*p == '*') ajStrAppendC(&temp, "***"); else if(*p == '.') ajStrAppendC(&temp, "..."); else if(*p == '-') ajStrAppendC(&temp, "---"); else if(!isalpha((ajint)*p)) ajStrAppendC(&temp, "???"); else { p3 = embPropCharToThree(*p); ajStrAppendK(&temp, *p3); ajStrAppendK(&temp, *(p3+1)); ajStrAppendK(&temp, *(p3+2)); } } return temp; }
static const AjPStr eprimer3_tableget(const char *key1, ajint number, const char *key2, const AjPTable table) { AjPStr fullkey = NULL; AjPStr keynum = NULL; const AjPStr value = NULL; ajStrAssignC(&fullkey, key1); if(number > 0) { ajStrAppendC(&fullkey, "_"); ajStrFromInt(&keynum, number); ajStrAppendS(&fullkey, keynum); } if(strcmp(key2, "")) ajStrAppendC(&fullkey, "_"); ajStrAppendC(&fullkey, key2); ajDebug("Constructed key=%S\n", fullkey); value = ajTableFetchS(table, fullkey); ajStrDel(&fullkey); ajStrDel(&keynum); return value; }
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; }
AjBool embMiscMatchPatternDelimC (const AjPStr str, const AjPStr pattern, const char* delim) { char whiteSpace[] = " \t\n\r"; /* skip whitespace */ AjPStrTok tokens; AjPStr delimstr = NULL; AjPStr key = NULL; AjBool val = ajFalse; delimstr = ajStrNewC(whiteSpace); ajStrAppendC(&delimstr, delim); tokens = ajStrTokenNewS(pattern, delimstr); while (ajStrTokenNextParse( &tokens, &key)) if (ajStrMatchWildCaseS(str, key)) { val = ajTrue; break; } ajStrTokenDel( &tokens); ajStrDel(&key); ajStrDel(&delimstr); return val; }
static void tranalign_AddGaps(AjPSeq newseq, const AjPSeq nseq, const AjPSeq pseq, ajlong npos) { AjPStr newstr = NULL; ajuint ppos = 0; newstr = ajStrNew(); for(; ppos<ajSeqGetLen(pseq); ppos++) if(ajSeqGetSeqC(pseq)[ppos] == '-') ajStrAppendC(&newstr, "---"); else { ajStrAppendSubS(&newstr, ajSeqGetSeqS(nseq), npos, npos+2); npos+=3; } ajDebug("aligned seq=%S\n", newstr); ajSeqAssignSeqS(newseq, newstr); ajStrDel(&newstr); return; }
int main(int argc, char **argv) { // initialize EMBASSY info embInitPV("kclique", argc, argv, "KBWS", "1.0.9"); struct soap soap; char* jobid; char* result; AjPFile infile; AjPFile outf; AjPStr substr; AjPStr indata = NULL; AjPStr line = NULL; infile = ajAcdGetInfile("infile"); outf = ajAcdGetOutfile("outfile"); while (ajReadline(infile, &line)) { ajStrAppendS(&indata, line); ajStrAppendC(&indata, "\n"); } soap_init(&soap); char* in0; in0 = ajCharNewS(indata); if ( soap_call_ns1__runClique( &soap, NULL, NULL, in0, &jobid ) == SOAP_OK ) { } else { soap_print_fault(&soap, stderr); } int check = 0; while ( check == 0 ) { if ( soap_call_ns1__checkStatus( &soap, NULL, NULL, jobid, &check ) == SOAP_OK ) { } else { soap_print_fault(&soap, stderr); } sleep(3); } if ( soap_call_ns1__getResult( &soap, NULL, NULL, jobid, &result ) == SOAP_OK ) { substr = ajStrNewC(result); ajFmtPrintF(outf,"%S\n",substr); } else { soap_print_fault(&soap, stderr); } soap_destroy(&soap); soap_end(&soap); soap_done(&soap); ajFileClose(&infile); ajFileClose(&outf); ajStrDel(&substr); embExit(); return 0; }
static void splitter_MakeSubSeqName (AjPStr * name_ptr, const AjPSeq seq, ajuint start, ajuint end) { AjPStr value = ajStrNew(); /* create a nice name for the subsequence */ ajStrAssignS(name_ptr, ajSeqGetNameS(seq)); ajStrAppendC(name_ptr, "_"); ajStrFromUint(&value, ajSeqGetBegin(seq)+start); ajStrAppendS(name_ptr, value); ajStrAppendC(name_ptr, "-"); ajStrFromUint(&value, ajSeqGetBegin(seq)+end); ajStrAppendS(name_ptr, value); ajStrDel(&value); }
static const AjPStr assemSAMGetReadgroupHeaderlines(const AjPAssem assem) { AjPStr* rgids = NULL; const AjPAssemReadgroup rg = NULL; ajint i =0; ajTableToarrayKeys(assem->Readgroups, (void***)&rgids); ajStrAssignC(&assemoutSamLinetxt, ""); while (rgids[i]) /* read groups */ { rg = ajTableFetchS(assem->Readgroups, rgids[i++]); ajFmtPrintAppS(&assemoutSamLinetxt, "@RG\tID:%S", rg->ID); if(rg->CN) ajFmtPrintAppS(&assemoutSamLinetxt, "\tCN:%S", rg->CN); if(rg->Desc) ajFmtPrintAppS(&assemoutSamLinetxt, "\tDS:%S", rg->Desc); if(rg->Date) ajFmtPrintAppS(&assemoutSamLinetxt, "\tDT:%S", rg->Date); if(rg->FlowOrder) ajFmtPrintAppS(&assemoutSamLinetxt, "\tFO:%S", rg->FlowOrder); if(rg->KeySeq) ajFmtPrintAppS(&assemoutSamLinetxt, "\tKS:%S", rg->KeySeq); if(rg->Library) ajFmtPrintAppS(&assemoutSamLinetxt, "\tLB:%S", rg->Library); if(rg->Programs) ajFmtPrintAppS(&assemoutSamLinetxt, "\tPG:%S", rg->Programs); if(rg->Isize) ajFmtPrintAppS(&assemoutSamLinetxt, "\tPI:%d", rg->Isize); if(rg->Platform) ajFmtPrintAppS(&assemoutSamLinetxt, "\tPL:%s", ajAssemreadgroupGetPlatformname(rg)); if(rg->Unit) ajFmtPrintAppS(&assemoutSamLinetxt, "\tPU:%S", rg->Unit); if(rg->Sample) ajFmtPrintAppS(&assemoutSamLinetxt, "\tSM:%S", rg->Sample); ajStrAppendC(&assemoutSamLinetxt, "\n"); } AJFREE(rgids); return assemoutSamLinetxt; }
/* @funcstatic domainalign_writeid ******************************************** ** ** House-keeping function. ** ** @param [r] domain [AjPDomain] Domain. ** @param [r] noden [ajint] Node number. ** @param [r] daf [AjPDirout] Domain alignment files. ** @param [r] super [AjPDirout] Structural superimposition files. ** @param [r] align [AjPStr *] Align. ** @param [r] alignc [AjPStr *] Alignc. ** ** @return [void] ** ** @@ ****************************************************************************/ static void domainalign_writeid(AjPDomain domain, ajint noden, AjPDirout daf, AjPDirout super, AjPStr *align, AjPStr *alignc) { AjPStr temp=NULL; temp=ajStrNew(); if(noden==1) ajStrFromInt(&temp, domain->Scop->Sunid_Class); else if (noden==2) ajStrFromInt(&temp, domain->Scop->Sunid_Fold); else if (noden==3) ajStrFromInt(&temp, domain->Scop->Sunid_Superfamily); else if (noden==4) ajStrFromInt(&temp, domain->Scop->Sunid_Family); else if (noden==5) ajStrFromInt(&temp, domain->Cath->Class_Id ); else if (noden==6) ajStrFromInt(&temp, domain->Cath->Arch_Id); else if (noden==7) ajStrFromInt(&temp, domain->Cath->Topology_Id); else if (noden==8) ajStrFromInt(&temp, domain->Cath->Superfamily_Id); else if (noden==9) ajStrFromInt(&temp, domain->Cath->Family_Id); ajStrAssignS(align, temp); ajStrInsertS(align, 0, ajDiroutGetPath(daf)); ajStrAppendC(align, "."); ajStrAppendS(align, ajDiroutGetExt(daf)); ajStrAssignS(alignc, temp); ajStrInsertS(alignc, 0, ajDiroutGetPath(super)); ajStrAppendC(alignc, "."); ajStrAppendS(alignc, ajDiroutGetExt(super)); ajDebug("daf file '%S' super file '%S'\n", *align, *alignc); ajStrDel(&temp); return; }
AjPStr embPropProt1to3Rev(AjPSeq seq, ajint pad) { const char *p; const char *p3; AjPStr temp; ajint i=0; temp = ajStrNewRes(ajSeqGetLen(seq)*3 + pad+1); for(p=ajSeqGetSeqC(seq); *p; p++) { if(*p == '*') ajStrAppendC(&temp, "***"); else if(*p == '.') ajStrAppendC(&temp, "..."); else if(*p == '-') ajStrAppendC(&temp, "---"); else if(!isalpha((ajint)*p)) ajStrAppendC(&temp, "???"); else { p3 = embPropCharToThree(*p); if(i++) { ajStrAppendK(&temp, *(p3+2)); ajStrAppendK(&temp, *(p3+1)); ajStrAppendK(&temp, *p3); } else { if(pad >= 2) ajStrAppendK(&temp, *(p3+2)); if(pad >= 1) ajStrAppendK(&temp, *(p3+1)); ajStrAppendK(&temp, *p3); } } } return temp; }
static AjBool extractfeat_MatchPatternDescribe(const AjPFeature feat, const AjPStr describe, AjPStr *strout) { AjIList titer; /* iterator for feat */ AjPStr tagnam = NULL; /* tag structure */ AjPStr tagval = NULL; /* tag structure */ AjBool val = ajFalse; /* returned value */ /* iterate through the tags and test for match to patterns */ titer = ajFeatTagIter(feat); while(ajFeatTagval(titer, &tagnam, &tagval)) { if(embMiscMatchPatternDelimC(tagnam, describe, ",;|")) { /* There's a match, so write to strout in a pretty format */ if(!val) ajStrAssignC(strout, "("); else ajStrAppendC(strout, ", "); val = ajTrue; ajStrAppendS(strout, tagnam); if(ajStrGetLen(tagval)) { ajStrAppendC(strout, "=\""); ajStrAppendS(strout, tagval); ajStrAppendC(strout, "\""); } } } ajListIterDel(&titer); if(val) ajStrAppendC(strout, ") "); ajStrDel(&tagnam); ajStrDel(&tagval); return val; }
int main(int argc, char **argv) { /* ACD data item variables */ AjPFile database = NULL; /* Housekeeping variables */ AjPStr cmd = NULL; AjPStr tmp = NULL; /* ACD file processing */ embInitPV("ehmmindex",argc,argv,"HMMERNEW",VERSION); database = ajAcdGetInfile("database"); /* MAIN APPLICATION CODE */ /* 1. Housekeeping */ cmd = ajStrNew(); tmp = ajStrNew(); /* 2. Build hmmindex command line */ /* Command line is built in this order: i. Application name. ii. HMMER 'options' (in order they appear in ACD file) iii.HMMER 'options' (that don't appear in ACD file) iv. HMMER & new parameters. */ ajFmtPrintS(&cmd, "%S ", ajAcdGetpathC("hmmindex")); ajStrAppendC(&cmd, ajFileGetNameC(database)); /* 3. Close ACD files. */ ajFileClose(&database); /* 4. Call hmmindex */ ajFmtPrint("\n%S\n\n", cmd); system(ajStrGetPtr(cmd)); /* 5. Exit cleanly */ ajStrDel(&cmd); ajStrDel(&tmp); embExit(); return 0; }
AjPStr embPropProtGaps(AjPSeq seq, ajint pad) { const char *p; AjPStr temp; ajint i; temp = ajStrNewRes(ajSeqGetLen(seq)*3 + pad+1); /* put any required padding spaces at the start */ for(i=0; i<pad; i++) ajStrAppendC(&temp, " "); for(p=ajSeqGetSeqC(seq); *p; p++) { ajStrAppendK(&temp, *p); ajStrAppendC(&temp, " "); } return temp; }
static void dbiblast_newname(AjPStr* nname, const AjPStr oname, const char *suff) { ajStrAssignS(nname, oname); if(ajStrGetCharFirst(oname)=='@') ajStrCutStart(nname, 1); ajStrAppendK(nname, '.'); ajStrAppendC(nname, suff); return; }
AjBool embPropGetProperties(const EmbPPropAmino prop, AjPStr* Pstr) { ajStrAssignC(Pstr, ""); if(prop->tiny) ajStrAppendC(Pstr, "tiny,"); if(prop->sm_all) ajStrAppendC(Pstr, "small,"); if(prop->aliphatic) ajStrAppendC(Pstr, "aliphatic,"); if(prop->aromatic) ajStrAppendC(Pstr, "aromatic,"); if(prop->polar) ajStrAppendC(Pstr, "polar,"); if(prop->nonpolar) ajStrAppendC(Pstr, "nonpolar,"); ajStrTrimEndC(Pstr, ","); if(!ajStrGetLen(*Pstr)) return ajFalse; return ajTrue; }
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; }
AjBool ensGvdatabaseadaptorFailedvariationsconstraint( EnsPGvdatabaseadaptor gvdba, const AjPStr tablename, AjPStr *Pconstraint) { char *txttablename = NULL; if (!gvdba) return ajFalse; if (!Pconstraint) return ajFalse; if (!*Pconstraint) *Pconstraint = ajStrNew(); if (gvdba->Failedvariations) { if ((tablename != NULL) && (ajStrGetLen(tablename))) { ensDatabaseadaptorEscapeC( ensGvdatabaseadaptorGetDatabaseadaptor(gvdba), &txttablename, tablename); ajStrAssignC(Pconstraint, txttablename); ajCharDel(&txttablename); } else ajStrAssignC(Pconstraint, "failed_variation"); ajStrAppendC(Pconstraint, ".variation_id IS NULL"); } else ajStrAssignC(Pconstraint, "1"); return ajTrue; }
int main(int argc, char *argv[]) { embInitPV("gseqinfo", argc, argv, "GEMBASSY", "1.0.1"); struct soap soap; AjPSeqall seqall; AjPSeq seq; AjPStr inseq = NULL; AjPStr seqid = NULL; AjPStr tmp = NULL; AjPStr parse = NULL; AjPStr numA = NULL; AjPStr numT = NULL; AjPStr numG = NULL; AjPStr numC = NULL; AjPStrTok handle = NULL; ajint n; char *in0; char *result; AjBool show = 0; AjPFile outf = NULL; seqall = ajAcdGetSeqall("sequence"); outf = ajAcdGetOutfile("outfile"); while(ajSeqallNext(seqall, &seq)) { soap_init(&soap); inseq = NULL; ajStrAppendC(&inseq, ">"); ajStrAppendS(&inseq, ajSeqGetNameS(seq)); ajStrAppendC(&inseq, "\n"); ajStrAppendS(&inseq, ajSeqGetSeqS(seq)); ajStrAssignS(&seqid, ajSeqGetAccS(seq)); in0 = ajCharNewS(inseq); if(soap_call_ns1__seqinfo( &soap, NULL, NULL, in0, &result ) == SOAP_OK) { tmp = ajStrNewC(result); ajStrExchangeCC(&tmp, "<", "\n"); ajStrExchangeCC(&tmp, ">", "\n"); handle = ajStrTokenNewC(tmp, "\n"); while(ajStrTokenNextParse(handle, &parse)) { if(ajStrIsInt(parse)) if(!numA) numA = ajStrNewS(parse); else if(!numT) numT = ajStrNewS(parse); else if(!numG) numG = ajStrNewS(parse); else if(!numC) numC = ajStrNewS(parse); } if(show) ajFmtPrint("Sequence: %S A: %S T: %S G: %S C: %S\n", seqid, numA, numT, numG, numC); else ajFmtPrintF(outf, "Sequence: %S A: %S T: %S G: %S C: %S\n", seqid, numA, numT, numG, numC); } else { soap_print_fault(&soap, stderr); } soap_destroy(&soap); soap_end(&soap); soap_done(&soap); AJFREE(in0); ajStrDel(&inseq); } ajSeqallDel(&seqall); ajSeqDel(&seq); ajStrDel(&seqid); embExit(); return 0; }
/* @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[]) { embInitPV("gbaseinformationcontent", argc, argv, "GEMBASSY", "1.0.1"); AjPSeqall seqall; AjPSeq seq; AjPStr inseq = NULL; AjPStr position = 0; ajint PatLen = 0; ajint upstream = 0; ajint downstream = 0; AjBool accid = ajFalse; AjPStr restid = NULL; AjPStr seqid = NULL; AjPStr base = NULL; AjPStr url = NULL; AjPFile tmpfile = NULL; AjPStr tmpname = NULL; AjBool plot = 0; AjPFile outf = NULL; AjPFilebuff buff = NULL; AjPGraph mult = NULL; gPlotParams gpp; AjPStr title = NULL; seqall = ajAcdGetSeqall("sequence"); position = ajAcdGetSelectSingle("position"); PatLen = ajAcdGetInt("patlen"); upstream = ajAcdGetInt("upstream"); downstream = ajAcdGetInt("downstream"); accid = ajAcdGetBoolean("accid"); plot = ajAcdGetToggle("plot"); outf = ajAcdGetOutfile("outfile"); mult = ajAcdGetGraphxy("graph"); base = ajStrNewC("rest.g-language.org"); gAssignUniqueName(&tmpname); while(ajSeqallNext(seqall, &seq)) { inseq = NULL; if(!accid) { if(gFormatGenbank(seq, &inseq)) { gAssignUniqueName(&tmpname); tmpfile = ajFileNewOutNameS(tmpname); if(!tmpfile) { ajFmtError("Output file (%S) open error\n", tmpname); embExitBad(); } ajFmtPrintF(tmpfile, "%S", inseq); ajFileClose(&tmpfile); ajFmtPrintS(&url, "http://%S/upload/upl.pl", base); gFilePostSS(url, tmpname, &restid); ajStrDel(&url); ajSysFileUnlinkS(tmpname); } else { ajFmtError("Sequence does not have features\n" "Proceeding with sequence accession ID\n"); accid = ajTrue; } } if(accid) { ajStrAssignS(&seqid, ajSeqGetAccS(seq)); if(!ajStrGetLen(seqid)) { ajStrAssignS(&seqid, ajSeqGetNameS(seq)); } if(!ajStrGetLen(seqid)) { ajFmtError("No valid header information\n"); embExitBad(); } ajStrAssignS(&restid, seqid); } ajStrAssignS(&seqid, ajSeqGetAccS(seq)); url = ajStrNew(); ajFmtPrintS(&url, "http://%S/%S/base_information_content/position=%S/" "PatLen=%d/upstream=%d/downstream=%d/output=f/tag=gene", base, restid, position, PatLen, upstream, downstream); if(plot) { title = ajStrNew(); ajStrAppendC(&title, argv[0]); ajStrAppendC(&title, " of "); ajStrAppendS(&title, seqid); gpp.title = ajStrNewS(title); gpp.xlab = ajStrNewC("position"); gpp.ylab = ajStrNewC("information content"); if(!gFilebuffURLS(url, &buff)) { ajDie("File downloading error from:\n%S\n", url); } if(!gPlotFilebuff(buff, mult, &gpp)) { ajDie("Error in plotting\n"); } AJFREE(gpp.title); AJFREE(gpp.xlab); AJFREE(gpp.ylab); ajStrDel(&title); ajFilebuffDel(&buff); } else { ajFmtPrintF(outf, "Sequence: %S\n", seqid); if(!gFileOutURLS(url, &outf)) { ajDie("File downloading error from:\n%S\n", url); } } } ajFileClose(&outf); ajSeqallDel(&seqall); ajSeqDel(&seq); ajStrDel(&seqid); ajStrDel(&position); embExit(); return 0; }
int main(int argc, char **argv) { embInitPV("kdnapenny", argc, argv, "KBWS", "1.0.8"); struct soap soap; char* jobid; char* result; AjPSeqall seqall; AjPSeq seq; AjPFile outf; AjPStr substr; AjPStr inseq = NULL; seqall = ajAcdGetSeqall("seqall"); outf = ajAcdGetOutfile("outfile"); AjPStr tmp = NULL; AjPStr tmpFileName = NULL; AjPSeqout fil_file; AjPStr line = NULL; AjPStr sizestr = NULL; ajint thissize = 0; ajint nb = 0; AjBool are_prot = ajFalse; ajint size = 0; AjPFile infile; tmp = ajStrNewC("fasta"); fil_file = ajSeqoutNew(); tmpFileName = getUniqueFileName(); if( !ajSeqoutOpenFilename(fil_file, tmpFileName) ) { embExitBad(); } ajSeqoutSetFormatS(fil_file, tmp); while (ajSeqallNext(seqall, &seq)) { if (!nb) { are_prot = ajSeqIsProt(seq); } ajSeqoutWriteSeq(fil_file, seq); ++nb; } ajSeqoutClose(fil_file); ajSeqoutDel(&fil_file); if (nb < 2) { ajFatal("Multiple alignments need at least two sequences"); } infile = ajFileNewInNameS(tmpFileName); while (ajReadline(infile, &line)) { ajStrAppendS(&inseq,line); ajStrAppendC(&inseq,"\n"); } soap_init(&soap); char* in0; in0 = ajCharNewS(inseq); if ( soap_call_ns1__runDnapenny( &soap, NULL, NULL, in0, &jobid ) == SOAP_OK ) { fprintf(stderr,"Jobid: %s\n",jobid); } else { soap_print_fault(&soap, stderr); } int check = 0; while ( check == 0 ) { if ( soap_call_ns1__checkStatus( &soap, NULL, NULL, jobid, &check ) == SOAP_OK ) { fprintf(stderr,"*"); } else { soap_print_fault(&soap, stderr); } sleep(3); } fprintf(stderr, "\n"); if ( soap_call_ns1__getResult( &soap, NULL, NULL, jobid, &result ) == SOAP_OK ) { substr = ajStrNewC(result); ajFmtPrintF(outf,"%S\n",substr); } else { soap_print_fault(&soap, stderr); } ajSysFileUnlinkS(tmpFileName); soap_destroy(&soap); soap_end(&soap); soap_done(&soap); ajFileClose(&outf); ajSeqallDel(&seqall); ajSeqDel(&seq); ajStrDel(&substr); embExit(); return 0; }
int main(int argc, char *argv[]) { embInitPV("ggcskew", argc, argv, "GEMBASSY", "1.0.3"); AjPSeqall seqall; AjPSeq seq; AjPStr inseq = NULL; AjBool accid = ajFalse; AjPStr restid = NULL; AjPStr seqid = NULL; AjPStr base = NULL; AjPStr url = NULL; AjPStr tmpname = NULL; AjPSeqout tmpout = NULL; ajint window = 0; ajint slide = 0; AjBool cumulative = 0; AjBool at = 0; AjBool purine = 0; AjBool keto = 0; AjBool plot = 0; AjPFile outf = NULL; AjPFilebuff buff = NULL; AjPGraph mult = NULL; gPlotParams gpp; AjPStr title = NULL; seqall = ajAcdGetSeqall("sequence"); window = ajAcdGetInt("window"); slide = ajAcdGetInt("slide"); cumulative = ajAcdGetBoolean("cumulative"); at = ajAcdGetBoolean("at"); purine = ajAcdGetBoolean("purine"); keto = ajAcdGetBoolean("keto"); plot = ajAcdGetToggle("plot"); outf = ajAcdGetOutfile("outfile"); mult = ajAcdGetGraphxy("graph"); base = ajStrNewC("rest.g-language.org"); gAssignUniqueName(&tmpname); ajStrAppendC(&tmpname, ".fasta"); while(ajSeqallNext(seqall, &seq)) { tmpout = ajSeqoutNew(); if(!ajSeqoutOpenFilename(tmpout, tmpname)) { embExitBad(); } ajSeqoutSetFormatS(tmpout,ajStrNewC("fasta")); ajSeqoutWriteSeq(tmpout, seq); ajSeqoutClose(tmpout); ajSeqoutDel(&tmpout); ajFmtPrintS(&url, "http://%S/upload/upl.pl", base); gFilePostSS(url, tmpname, &restid); ajStrDel(&url); ajSysFileUnlinkS(tmpname); ajStrAssignS(&seqid, ajSeqGetAccS(seq)); if(ajStrGetLen(seqid) == 0) { ajStrAssignS(&seqid, ajSeqGetNameS(seq)); } if(ajStrGetLen(seqid) == 0) { ajWarn("No valid header information\n"); } url = ajStrNew(); ajFmtPrintS(&url, "http://%S/%S/gcskew/window=%d/slide=%d/cumulative=%d/" "at=%d/purine=%d/keto=%d/output=f/", base, restid, window, slide, cumulative, at, purine, keto); if(plot) { title = ajStrNew(); ajStrAppendC(&title, argv[0]); ajStrAppendC(&title, " of "); ajStrAppendS(&title, seqid); gpp.title = ajStrNewS(title); gpp.xlab = ajStrNewC("location"); gpp.ylab = ajStrNewC("GC skew"); if(!gFilebuffURLS(url, &buff)) { ajDie("File downloading error from:\n%S\n", url); } if(!gPlotFilebuff(buff, mult, &gpp)) { ajDie("Error in plotting\n"); } AJFREE(gpp.title); AJFREE(gpp.xlab); AJFREE(gpp.ylab); ajStrDel(&title); ajFilebuffDel(&buff); } else { ajFmtPrintF(outf, "Sequence: %S\n", seqid); if(!gFileOutURLS(url, &outf)) { ajDie("File downloading error from:\n%S\n", url); } } ajStrDel(&url); ajStrDel(&restid); ajStrDel(&seqid); } ajFileClose(&outf); ajSeqallDel(&seqall); ajSeqDel(&seq); ajStrDel(&base); embExit(); return 0; }
int main(int argc, char **argv) { embInitPV("kmafft", argc, argv, "KBWS", "1.0.8"); struct soap soap; struct ns1__mafftInputParams params; char* jobid; char* result; AjPSeqall seqall; AjPSeq seq; AjPFile outf; AjPStr substr; AjPStr inseq = NULL; AjPStr strategy; AjPStr outorder; float op; float ep; AjPStr scorematrix; AjBool homologs; AjBool showhomologs; float threshold; AjPStr referenceseq; AjPStr harrplot; strategy = ajAcdGetString("strategy"); outorder = ajAcdGetString("outorder"); op = ajAcdGetFloat("op"); ep = ajAcdGetFloat("ep"); scorematrix = ajAcdGetString("scorematrix"); homologs = ajAcdGetBoolean("homologs"); showhomologs = ajAcdGetBoolean("showhomologs"); threshold = ajAcdGetFloat("threshold"); referenceseq = ajAcdGetString("referenceseq"); harrplot = ajAcdGetString("harrplot"); seqall = ajAcdGetSeqall("seqall"); outf = ajAcdGetOutfile("outfile"); params.strategy = ajCharNewS(strategy); params.outorder = ajCharNewS(outorder); params.op = op; params.ep = ep; params.scorematrix = ajCharNewS(scorematrix); if (homologs) { params.homologs = xsd__boolean__true_; } else { params.homologs = xsd__boolean__false_; } if (showhomologs) { params.showhomologs = xsd__boolean__true_; } else { params.showhomologs = xsd__boolean__false_; } params.threshold = threshold; params.referenceseq = ajCharNewS(referenceseq); params.harrplot = ajCharNewS(harrplot); AjPStr tmp = NULL; AjPStr tmpFileName = NULL; AjPSeqout fil_file; AjPStr line = NULL; /* if "AjPStr line; -> ajReadline is not success!" */ AjPStr sizestr = NULL; ajint thissize; ajint nb = 0; AjBool are_prot = ajFalse; ajint size = 0; AjPFile infile; tmp = ajStrNewC("fasta"); fil_file = ajSeqoutNew(); tmpFileName = getUniqueFileName(); if( !ajSeqoutOpenFilename(fil_file, tmpFileName) ) { embExitBad(); } ajSeqoutSetFormatS(fil_file, tmp); while (ajSeqallNext(seqall, &seq)) { if (!nb) { are_prot = ajSeqIsProt(seq); } ajSeqoutWriteSeq(fil_file, seq); ++nb; } ajSeqoutClose(fil_file); ajSeqoutDel(&fil_file); if (nb < 2) { ajFatal("Multiple alignments need at least two sequences"); } infile = ajFileNewInNameS(tmpFileName); while (ajReadline(infile, &line)) { ajStrAppendS(&inseq,line); ajStrAppendC(&inseq,"\n"); } soap_init(&soap); char* in0; in0 = ajCharNewS(inseq); if ( soap_call_ns1__runMafft( &soap, NULL, NULL, in0, ¶ms, &jobid ) == SOAP_OK ) { fprintf(stderr,"Jobid: %s\n",jobid); } else { soap_print_fault(&soap, stderr); } int check = 0; while ( check == 0 ) { if ( soap_call_ns1__checkStatus( &soap, NULL, NULL, jobid, &check ) == SOAP_OK ) { fprintf(stderr,"*"); } else { soap_print_fault(&soap, stderr); } sleep(3); } fprintf(stderr,"\n"); if ( soap_call_ns1__getResult( &soap, NULL, NULL, jobid, &result ) == SOAP_OK ) { substr = ajStrNewC(result); ajFmtPrintF(outf,"%S\n",substr); } else { soap_print_fault(&soap, stderr); } ajSysFileUnlinkS(tmpFileName); soap_destroy(&soap); soap_end(&soap); soap_done(&soap); ajFileClose(&outf); ajSeqallDel(&seqall); ajSeqDel(&seq); ajStrDel(&substr); embExit(); return 0; }
int main(int argc, char **argv) { /* ACD data item variables */ AjPSeqset alignfile = NULL; AjPFile prior = NULL; AjPFile null = NULL; AjPFile pam = NULL; float pamwgt = 0.0; AjPStr nhmm = NULL; AjPStr strategy = NULL; ajint pbswitch = 0; float archpri = 0.0; AjBool binary = ajFalse; AjBool fast = ajFalse; float gapmax = 0.0; AjBool hand = ajFalse; float idlevel = 0.0; AjBool noeff = ajFalse; float swentry = 0.0; float swexit = 0.0; AjBool verbosity = ajFalse; AjPStr weighting = NULL; AjPFile hmmfile = NULL; AjPFile o = NULL; AjPFile cfile = NULL; /* Housekeeping variables */ AjPStr cmd = NULL; AjPStr rnd1 = NULL; AjPStr rnd2 = NULL; AjPStr tmp = NULL; AjPStr fmt = NULL; char option; AjBool fmtok = ajFalse; AjPStr hmmfilename = NULL; /* ACD file processing */ embInitPV("ehmmbuild",argc,argv,"HMMERNEW",VERSION); alignfile = ajAcdGetSeqset("alignfile"); prior = ajAcdGetInfile("prior"); null = ajAcdGetInfile("null"); pam = ajAcdGetInfile("pam"); pamwgt = ajAcdGetFloat("pamwgt"); nhmm = ajAcdGetString("nhmm"); strategy = ajAcdGetListSingle("strategy"); pbswitch = ajAcdGetInt("pbswitch"); archpri = ajAcdGetFloat("archpri"); binary = ajAcdGetBoolean("binary"); fast = ajAcdGetBoolean("fast"); gapmax = ajAcdGetFloat("gapmax"); hand = ajAcdGetBoolean("hand"); idlevel = ajAcdGetFloat("sidlevel"); noeff = ajAcdGetBoolean("noeff"); swentry = ajAcdGetFloat("swentry"); swexit = ajAcdGetFloat("swexit"); verbosity = ajAcdGetBoolean("verbosity"); weighting = ajAcdGetListSingle("weighting"); hmmfile = ajAcdGetOutfile("hmmfile"); o = ajAcdGetOutfile("o"); cfile = ajAcdGetOutfile("cfile"); /* MAIN APPLICATION CODE */ /* 1. Housekeeping */ cmd = ajStrNew(); rnd1 = ajStrNew(); rnd2 = ajStrNew(); tmp = ajStrNew(); fmt = ajStrNew(); hmmfilename = ajStrNew(); ajStrAssignC(&hmmfilename, ajFileGetNameC(hmmfile)); /* 2. Ensure alignfile is in format HMMER can understand. These include FASTA, GENBANK,EMBL, GCG, PIR, STOCKHOLM, SELEX, MSF,CLUSTAL and PHYLIP. EMBOSS name definitions are taken from seqInFormatDef in ajseqread.c and seqOutFormat in ajseqwrite.c */ fmtok=ajFalse; ajStrAssignS(&fmt, ajSeqsetGetFormat(alignfile)); if(ajStrMatchC(fmt, "fasta") || ajStrMatchC(fmt, "genbank") || ajStrMatchC(fmt, "embl") || ajStrMatchC(fmt, "gcg") || ajStrMatchC(fmt, "pir") || ajStrMatchC(fmt, "stockholm")|| ajStrMatchC(fmt, "selex") || ajStrMatchC(fmt, "msf") || ajStrMatchC(fmt, "clustal") || ajStrMatchC(fmt, "phylip")) fmtok = ajTrue; /* This could be replaced with code to reformat the file. */ if(!fmtok) ajFatal("Input alignment ('alignfile' ACD option) is not in format " "HMMER understands. Please use a a file in FASTA, GENBANK, " "EMBL, GCG, PIR, STOCKHOLM, SELEX, MSF,CLUSTAL or PHYLIP format."); /* 3. Build hmmbuild command line */ /* Command line is built in this order: i. Application name. ii. HMMER 'options' (in order they appear in ACD file) iii.HMMER 'options' (that don't appear in ACD file) iv. HMMER & new parameters. */ ajStrAssignS(&cmd, ajAcdGetpathC("hmmbuild")); if(prior) ajFmtPrintAppS(&cmd, " --prior %s ", ajFileGetNameC(prior)); if(null) ajFmtPrintS(&cmd, " --null %s ", ajFileGetNameC(null)); if(pam) ajFmtPrintAppS(&cmd, " --pam %s --pamwgt %f ", ajFileGetNameC(pam), pamwgt); ajFmtPrintAppS(&cmd, " -n %S ", nhmm); /* ACD option only allows one selection */ option = ajStrGetCharFirst(strategy); if(option == 'F') ajStrAppendC(&cmd, " -f "); else if(option == 'G') ajStrAppendC(&cmd, " -g "); else if(option == 'S') ajStrAppendC(&cmd, " -s "); /* else go with default ('D' option in ACD file) */ ajFmtPrintAppS(&cmd, " --pbswitch %d ", pbswitch); ajFmtPrintAppS(&cmd, " --archpri %f ", archpri); if(binary) ajStrAppendC(&cmd, " --binary "); if(fast) ajFmtPrintAppS(&cmd, " --fast --gapmax %f ", gapmax); if(hand) ajStrAppendC(&cmd, " --hand "); ajFmtPrintAppS(&cmd, " --idlevel %f ", idlevel); if(noeff) ajStrAppendC(&cmd, " --noeff "); ajFmtPrintAppS(&cmd, " --swentry %f ", swentry); ajFmtPrintAppS(&cmd, " --swexit %f ", swexit); if(verbosity) ajStrAppendC(&cmd, " --verbose "); /* ACD option only allows one selection */ option = ajStrGetCharFirst(weighting); if(option == 'B') ajStrAppendC(&cmd, " --wblosum "); else if(option == 'G') ajStrAppendC(&cmd, " --wgsc "); else if(option == 'K') ajStrAppendC(&cmd, " --wme "); else if(option == 'W') ajStrAppendC(&cmd, " --wpb "); else if(option == 'V') ajStrAppendC(&cmd, " --wvoronoi "); else if(option == 'N') ajStrAppendC(&cmd, " --wnone "); if(o) ajFmtPrintAppS(&cmd, " -o %s ", ajFileGetNameC(o)); if(cfile) ajFmtPrintAppS(&cmd, " --cfile %s ", ajFileGetNameC(cfile)); /* -A (append) always set but file will be wiped by EMBOSS first unless append: "Y" is set for "hmmfile" in the ACD file. */ ajStrAppendC(&cmd, " -A -F "); ajFmtPrintAppS(&cmd, " %S %S", hmmfilename, ajSeqsetGetFilename(alignfile)); /* 4. Close ACD files */ ajSeqsetDel(&alignfile); ajFileClose(&prior); ajFileClose(&null); ajFileClose(&pam); ajFileClose(&hmmfile); ajFileClose(&o); ajFileClose(&cfile); /* 5. Call hmmbuild */ ajFmtPrint("\n%S\n", cmd); system(ajStrGetPtr(cmd)); /* 6. Exit cleanly */ ajStrDel(&nhmm); ajStrDel(&cmd); ajStrDel(&rnd1); ajStrDel(&rnd2); ajStrDel(&tmp); ajStrDel(&fmt); ajStrDel(&hmmfilename); ajStrDel(&strategy); ajStrDel(&weighting); embExit(); return 0; }
int main(int argc, char **argv) { AjPSeqset seqset = NULL; AjPStr cl = NULL; AjPSeqout seqout = NULL; AjBool full = ajFalse; AjPStr fn = NULL; AjPStr stmp = NULL; AjPStr outfname = NULL; embInitPV("echlorop", argc, argv, "CBSTOOLS", VERSION); seqset = ajAcdGetSeqset("sequence"); outfname= ajAcdGetOutfileName("outfile"); full = ajAcdGetBoolean("full"); cl = ajStrNewS(ajAcdGetpathC("chlorop")); fn = ajStrNew(); stmp = ajStrNew(); ajFilenameSetTempname(&fn); seqout = ajSeqoutNew(); if(!ajSeqoutOpenFilename(seqout, fn)) ajFatal("Cannot open temporary file %S",fn); ajSeqoutSetFormatC(seqout, "fasta"); ajSeqoutWriteSet(seqout,seqset); ajSeqoutClose(seqout); if(full) ajStrAppendC(&cl," -F"); ajFmtPrintS(&stmp," %S",fn); ajStrAppendS(&cl,stmp); #if 0 ajFmtPrint("%S\n",cl); #endif #if 1 ajSysExecOutnameAppendS(cl, outfname); #endif ajSysFileUnlinkS(fn); ajStrDel(&cl); ajStrDel(&fn); ajStrDel(&stmp); ajSeqoutDel(&seqout); ajSeqsetDel(&seqset); ajStrDel(&outfname); embExit(); return 0; }
static void remap_RestrictPreferred(const AjPList l, const AjPTable t) { AjIList iter = NULL; EmbPMatMatch m = NULL; const AjPStr value = NULL; AjPStr newiso = NULL; AjBool found; /* name found in isoschizomer list */ /* for parsing value->iso string */ AjPStrTok tok = NULL; char tokens[] = " ,"; AjPStr code = NULL; iter = ajListIterNewread(l); while((m = (EmbPMatMatch)ajListIterGet(iter))) { found = ajFalse; /* get prototype name */ value = ajTableFetchS(t, m->cod); if(value) { ajStrAssignC(&newiso, ""); /* parse isoschizomer names from m->iso */ ajStrTokenDel(&tok); tok = ajStrTokenNewC(m->iso, tokens); while(ajStrTokenNextParseC(&tok, tokens, &code)) { if(ajStrGetLen(newiso) > 0) ajStrAppendC(&newiso, ","); /* found the prototype name? */ if(!ajStrCmpCaseS(code, value)) { ajStrAppendS(&newiso, m->cod); found = ajTrue; } else ajStrAppendS(&newiso, code); } ajStrTokenDel(&tok); /* if the name was not replaced, then add it in now */ if(!found) { if(ajStrGetLen(newiso) > 0) ajStrAppendC(&newiso, ","); ajStrAppendS(&newiso, m->cod); } ajDebug("RE: %S -> %S iso=%S newiso=%S\n", m->cod, value, m->iso, newiso); /* replace the old iso string with the new one */ ajStrAssignS(&m->iso, newiso); /* rename the enzyme to the prototype name */ ajStrAssignS(&m->cod, value); } } ajListIterDel(&iter); ajStrDel(&newiso); ajStrDel(&code); ajStrTokenDel(&tok); return; }
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; }
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; }
int main(int argc, char **argv) { AjPDasServer server = NULL; AjPDasSource source = NULL; AjPDasSegment segment = NULL; AjPStr host = NULL; AjPStr path = NULL; AjPFile outf = NULL; ajint port = 80; AjBool sequencesourcesonly; AjBool entrypoints; AjBool showtestqueries; AjBool runtestqueries = ajTrue; AjBool quickexit = ajFalse; ajint itest=0; ajint j=0; ajint maxtests=0; ajint maxfeatures=0; ajint maxsegments=0; AjIList iter = NULL; AjIList coordsi = NULL; AjIList itereps = NULL; AjPFilebuff buff = NULL; AjPUrlref uo = NULL; AjPList segments = NULL; AjPStr ffname = NULL; AjPStr url = NULL; AjPStr dbhttpver = ajStrNew(); AjPStr dbname = ajStrNew(); AjPStr dbproxy = ajStrNew(); AjPStr servername = NULL; AjPTable titlecount = NULL; const ajuint* count; int k=0; embInit("dastest", argc, argv); host = ajAcdGetString("host"); path = ajAcdGetString("path"); port = ajAcdGetInt("port"); sequencesourcesonly = ajAcdGetBoolean("sequencesourcesonly"); entrypoints = ajAcdGetBoolean("entrypoints"); showtestqueries = ajAcdGetBoolean("showtestqueries"); runtestqueries = ajAcdGetBoolean("runtestqueries"); servername = ajAcdGetString("servername"); outf = ajAcdGetOutfile("outfile"); maxtests = ajAcdGetInt("maxtests"); maxfeatures = ajAcdGetInt("maxfeatures"); maxsegments = ajAcdGetInt("maxsegments"); server = ajDasServerNew(); if(runtestqueries) { url = ajStrNew(); if(!ajNamServer(servername)) { ajWarn("following das server is required to be defined " "for test queries..."); ajWarn("\nSERVER %S [\n" " type: \"sequence\"\n" " method: \"das\"\n" " url: \"http://%S%S\"\n" "]\n",servername, host,path); ajWarn("ignoring -runtestqueries option..."); runtestqueries = ajFalse; } else { ajNamSvrGetUrl(servername, &url); ajHttpUrlDeconstruct(url, &port, &host, &path); ajStrDel(&url); } } ajDasServerSethostS(server,host); ajDasServerSetport(server,port); if(ajStrGetCharLast(path)!='/') ajStrAppendK(&path,'/'); ajStrAppendC(&path,"sources"); ajDasServerSetpathS(server,path); ajFmtPrintF(outf,"host = %S\npath = %S\nport = %d\n", server->host, server->path, server->port); /* * TODO: stop using http-read but instead use * ajNamSvrListListDatabases(svrname, dbnames); */ buff = ajHttpRead(dbhttpver, dbname, dbproxy, host, port, path); if(!buff) ajExitAbort(); ajFilebuffHtmlNoheader(buff); ajDasParseRegistry(buff, server->sources); ajFmtPrintF(outf,"DAS sources and descriptions\n\n"); titlecount = dastestGetTitleCount(server); iter = ajListIterNew(server->sources); while(!ajListIterDone(iter) && !quickexit) { source = ajListIterGet(iter); if ((sequencesourcesonly && !source->sequence) || ajStrMatchC(source->title,"cath") || k++ <50) continue; ajFmtPrintF(outf,"%-30S %-50S\n%S\n",source->uri,source->title, source->description); if(entrypoints && source->entry_points) { uo = ajHttpUrlrefNew(); ajHttpUrlrefParseC(&uo, ajStrGetPtr(source->entry_points_uri)); if(ajStrGetLen(uo->Port)) ajStrToInt(uo->Port, &port); else port = 80; ajFilebuffDel(&buff); buff = ajHttpRead(dbhttpver, dbname, dbproxy, uo->Host, port, uo->Absolute); ajHttpUrlrefDel(&uo); if(!buff) continue; ajFilebuffHtmlNoheader(buff); segments = ajListNew(); ajDasParseEntrypoints(buff, segments); itereps = ajListIterNew(segments); ajFmtPrintF(outf, "Number of entry points %d\n", ajListGetLength(segments)); j=0; while(!ajListIterDone(itereps)) { segment = ajListIterGet(itereps); if (j++ < maxsegments) ajFmtPrintF(outf, "segment id:%S orientation:%S start:%d stop:%d\n", segment->id, segment->orientation, segment->start, segment->stop); ajDasSegmentDel(&segment); } ajListIterDel(&itereps); ajListFree(&segments); } if(showtestqueries || runtestqueries) { AjPDasCoordinate coord; coordsi = ajListIterNew(source->coordinates); while(!ajListIterDone(coordsi) && !quickexit) { coord = ajListIterGet(coordsi); ajDebug("coordinate uri:%S taxid:%S source:%S test_range:%S\n", coord->uri, coord->taxid, coord->source, coord->test_range); if(showtestqueries) { if(source->sequence) ajFmtPrintF(outf, "example/test entry = '%S?segment=%S'\n", source->sequence_query_uri,coord->test_range); if(source->features) ajFmtPrintF(outf, "example/test entry = '%S?segment=%S'\n", source->features_query_uri,coord->test_range); } if(runtestqueries) { AjPStr idqry = ajStrNew(); AjPStr entry = NULL; AjPSeq seq = NULL; ajint ibegin = 0; ajint iend = 0; AjPStr example = NULL; example = ajDasTestrangeParse(coord->test_range, &entry, &ibegin, &iend); if(ajStrGetLen(entry)) { count = ajTableFetchS(titlecount, source->title); dbname = ajDasSourceGetDBname(source, *count>1); if (source->features) { AjPStr qpath=NULL; uo = ajHttpUrlrefNew(); ajFmtPrintS(&idqry,"dasgff::%S:%S:%S", servername, dbname, entry); ajFmtPrintF(outf, "feature query: %S start:%d end:%d\n", idqry, ibegin, iend); ajHttpUrlrefParseC(&uo, ajStrGetPtr(source->features_query_uri)); ajHttpUrlrefSplitPort(uo); ajFmtPrintS(&qpath,"%S?segment=%S", uo->Absolute,entry); if(iend>0) ajFmtPrintAppS(&qpath,":%d,%d",ibegin, iend); if(ajStrGetLen(uo->Port)) ajStrToInt(uo->Port, &port); else port = 80; ajDebug("calling ajHttpRead to get the raw" " output; host:%S port:%d path:%S\n", uo->Host, port, qpath); ajFilebuffDel(&buff); buff = ajHttpRead(dbhttpver, dbname, dbproxy, uo->Host, port, qpath); if(buff) { AjPFeattable ft; ajFmtPrintS(&ffname, "%S.%S", source->uri, entry); ajFilebuffHtmlNoheader(buff); dastestSaveRawFeatures(buff, ffname); ajDebug("now using EMBOSS feature queries\n"); ft = dastestFeatureQuery(idqry, ibegin, iend); dastestSaveMappedFeatures(ft, ffname, outf, maxfeatures); ajStrDel(&ffname); ajFeattableDel(&ft); } ajHttpUrlrefDel(&uo); ajStrDel(&qpath); if(++itest>=maxtests) quickexit = ajTrue; } else if(source->sequence) { seq = ajSeqNewRes(iend-ibegin+1); ajFmtPrintS(&idqry,"%S:%S:%S", servername, dbname, entry); ajFmtPrintF(outf, "sequence query: %S start:%d end:%d\n", idqry, ibegin, iend); ajSeqGetFromUsaRange(idqry, ajFalse, ibegin, iend, seq); ajFmtPrintF(outf, "length of sequence returned: %d\n", ajSeqGetLen(seq)); if(ajSeqGetLen(seq)>0) ajFmtPrintF(outf, "sequence returned (first 100 bases):" " %-100.100s\n", ajSeqGetSeqC(seq)); ajSeqDel(&seq); } ajStrDel(&dbname); } ajStrDel(&entry); ajStrDel(&idqry); ajStrDel(&example); } } ajListIterDel(&coordsi); } } ajListIterDel(&iter); ajDasServerDel(&server); ajFilebuffDel(&buff); ajStrDel(&host); ajStrDel(&path); ajStrDel(&servername); ajStrDel(&dbhttpver); ajStrDel(&dbname); ajStrDel(&dbproxy); ajFileClose(&outf); ajTableDelValdel(&titlecount, ajMemFree); embExit(); return 0; }