AjBool gFormatGenbank(AjPSeq seq, AjPStr *inseq){ AjPSeqout seqout = NULL; AjPFeattabOut featout = NULL; AjPFeattable feat = NULL; AjPStr seqline = NULL; AjPStr featline = NULL; AjPFile seqfile = NULL; AjPFile featfile = NULL; AjPStr filename = NULL; gAssignUniqueName(&filename); feat = ajSeqGetFeatCopy(seq); if(!feat) return ajFalse; seqout = ajSeqoutNew(); if(!ajSeqoutOpenFilename(seqout,filename)) embExitBad(); ajSeqoutSetFormatS(seqout,ajStrNewC("genbank")); ajSeqoutWriteSeq(seqout,seq); ajSeqoutClose(seqout); ajSeqoutDel(&seqout); seqfile = ajFileNewInNameS(filename); ajSysFileUnlinkS(filename); featout = ajFeattabOutNew(); if(!ajFeattabOutOpen(featout,filename)) return ajFalse; ajFeattableWriteGenbank(featout,feat); ajFeattableDel(&feat); //ajFeattabOutDel(&featout); ajFileClose(&(featout->Handle)); featfile = ajFileNewInNameS(filename); ajSysFileUnlinkS(filename); while(ajReadline(seqfile,&seqline)){ if(ajStrMatchC(seqline,"ORIGIN\n")){ while(ajReadline(featfile,&featline)){ ajStrAppendS(inseq, featline); } } ajStrAppendS(inseq, seqline); } ajStrDel(&seqline); ajStrDel(&featline); ajStrDel(&filename); ajFileClose(&seqfile); ajFileClose(&featfile); return ajTrue; }
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; }
void embIepPkRead(double *pK) { AjPFile inf = NULL; AjPStr line; const char *p; double amino = 8.6; double carboxyl = 3.6; char ch; ajint i; inf = ajDatafileNewInNameC(PKFILE); if(!inf) ajFatal("%s file not found",PKFILE); for(i=0;i<EMBIEPSIZE;++i) pK[i]=0.0; line = ajStrNew(); while(ajReadline(inf,&line)) { p = ajStrGetPtr(line); if(*p=='#' || *p=='!' || *p=='\n' || *p=='\r') continue; if(ajStrPrefixCaseC(line,"Amino")) { p = ajSysFuncStrtok(p," \t\n\r"); p = ajSysFuncStrtok(NULL," \t\n\r"); sscanf(p,"%lf",&amino); continue; } if(ajStrPrefixCaseC(line,"Carboxyl")) { p = ajSysFuncStrtok(p," \t\n\r"); p = ajSysFuncStrtok(NULL," \t\n\r"); sscanf(p,"%lf",&carboxyl); continue; } p = ajSysFuncStrtok(p," \t\n\r"); ch = ajSysCastItoc(toupper((ajint)*p)); p = ajSysFuncStrtok(NULL," \t\n\r"); sscanf(p,"%lf",&pK[ajBasecodeToInt(ch)]); } pK[EMBIEPAMINO] = amino; pK[EMBIEPCARBOXYL] = carboxyl; ajStrDel(&line); ajFileClose(&inf); return; }
AjBool gHttpGetBinS(AjPStr url, AjPFile* outf) { AjPFile file = NULL; AjPStr line = NULL; AjPStr host = NULL; AjPStr path = NULL; AjPStr get = NULL; ajint port = 80; ajuint http = 0; FILE *fp; AjPRegexp crlf = NULL; char buf[8]; AjOSysSocket sock; get = ajStrNew(); ajHttpUrlDeconstruct(url, &port, &host, &path); while(file==NULL || gHttpRedirect(file, &host, &port, &path)) { if(ajStrGetCharFirst(path) != '/') ajStrInsertK(&path, 0, '/'); ajFmtPrintS(&get, "GET http://%S:%d%S HTTP/1.1\r\n", host, port, path); fp = ajHttpOpen(NULL, host, port, get, &sock); file = ajFileNewFromCfile(fp); if(!file) return ajFalse; } ajStrDel(&get); crlf = ajRegCompC("^\r?\n$"); while(ajReadline(file, &line)) { if(ajRegExec(crlf, line)) break; } while(ajReadbinBinary(file, 1, 1, buf)) { ajWritebinBinary(*outf, 1, 1, buf); } ajFileClose(outf); ajFileClose(&file); return ajTrue; }
static void acdrelations_readtypefile (AjPFile inf, PKtype *T) { AjPStr line = NULL; PKtypedat dattmp = NULL; AjPList datlist = NULL; if(!T) ajFatal("Null arg error 1 in acdrelations_readtypefile"); if(!inf) ajFatal("Null arg error 3 in acdrelations_readtypefile"); /* Allocate memory */ line = ajStrNew(); datlist = ajListNew(); /* Read data from file */ while(ajReadline(inf,&line)) { /* Discard comment lines */ if(ajStrPrefixC(line,"#")) continue; /* Create object for holding line */ dattmp = ajKtypedatNew(); /* Tokenise line delimited by '|' Parse first token (value of knowntype: attribute) */ ajStrAssignS(&dattmp->ktype, ajStrParseC(line, "|")); ajStrRemoveSetC(&dattmp->ktype, "_"); ajStrRemoveWhite(&dattmp->ktype); /* Parse second token (ACD datatype) */ ajStrAssignS(&dattmp->acdtype, ajStrParseC(NULL, "|")); /* Parse third token (EDAM relations: value ) */ ajStrAssignS(&dattmp->edam, ajStrParseC(NULL, "|")); /* Push line onto list */ ajListPushAppend(datlist, dattmp); } /* Write PKtype structure */ ((*T)->n) = ajListToarray(datlist, (void***) &((*T)->dat)); /* Free memory */ ajStrDel(&line); ajListFree(&datlist); return; }
static void jaspextract_readmatrixlist(AjPTable mtable, const AjPStr directory) { const AjPStr datadir = NULL; AjPStr matrixfile = NULL; AjPFile inf = NULL; AjPStr line = NULL; AjPStr key = NULL; AjPStr value = NULL; matrixfile = 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); inf = ajFileNewInNameS(matrixfile); if(!inf) ajFatal("Cannot open input file: %S",matrixfile); while(ajReadline(inf,&line)) { key = ajStrNew(); if(ajFmtScanS(line,"%S",&key) != 1) { ajStrDel(&key); continue; } value = ajStrNew(); ajStrAssignS(&value,line); ajTablePut(mtable,(void *)key, (void *)value); } ajFileClose(&inf); ajStrDel(&matrixfile); ajStrDel(&line); return; }
int main(int argc, char **argv) { /* Variable Declarations */ AjPFile inf = NULL; AjPFile outf = NULL; AjPStr line = NULL; /* Line from inf */ AjPStr option = NULL; AjBool doall = AJFALSE; AjBool doend = AJFALSE; AjBool doexcess = AJFALSE; /* ACD File Processing */ embInit("nospace", argc, argv); inf = ajAcdGetInfile("infile"); outf = ajAcdGetOutfile("outfile"); option = ajAcdGetListSingle("menu"); if(ajStrMatchC(option, "all")) doall = ajTrue; else if(ajStrMatchC(option, "end")) doend = ajTrue; else if(ajStrMatchC(option, "excess")) doexcess = ajTrue; /* Application logic */ line = ajStrNew(); while(ajReadline(inf,&line)) { if(doall) ajStrRemoveWhite(&line); else if(doend) ajStrTrimWhiteEnd(&line); else if(doexcess) ajStrRemoveWhiteExcess(&line); ajFmtPrintF(outf, "%S\n", line); } /* Memory management and exit */ ajFileClose(&inf); ajFileClose(&outf); ajStrDel(&line); ajStrDel(&option); embExit(); return 0; }
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; }
AjBool ajReadlineAppend(AjPFile file, AjPStr* Pdest) { static AjPStr locbuff = 0; AjBool ok; if(!locbuff) locbuff = ajStrNewRes(512); ok = ajReadline(file, &locbuff); if(ok) ajStrAppendS(Pdest, locbuff); ajStrDel(&locbuff); return ok; }
AjBool gGetFileContent(AjPStr* content, AjPStr filename){ AjPFile file = NULL; AjPStr line = NULL; if((file = ajFileNewInNameS(filename)) == NULL) return ajFalse; while(ajReadline(file, &line)) ajStrAppendS(content, line); if(file) ajFileClose(&file); ajSysFileUnlinkS(filename); return ajTrue; }
int main(int argc, char *argv[]) { embInitPV("genret", argc, argv, "GEMBASSY", "1.0.3"); AjPSeqall seqall; AjPSeq seq = NULL; AjPStr inseq = NULL; AjPStr gene = NULL; AjPStr access = NULL; AjBool accid = ajTrue; AjPStr argument = NULL; AjPFile outfile = NULL; AjPStr seqid = NULL; AjPStr restid = NULL; AjBool valid = ajFalse; AjBool isseq = ajFalse; AjBool isgbk = ajFalse; AjPFilebuff buff = NULL; AjPFile tmpfile = NULL; AjPStr tmpname = NULL; AjPStr regexstr = NULL; AjPStrTok token = NULL; AjPRegexp regex = NULL; AjPStr url = NULL; AjPStr base = NULL; AjPStr head = NULL; AjPStr line = NULL; seqall = ajAcdGetSeqall("sequence"); access = ajAcdGetString("access"); gene = ajAcdGetString("gene"); argument = ajAcdGetString("argument"); accid = ajAcdGetBoolean("accid"); outfile = ajAcdGetOutfile("outfile"); if( ajStrMatchC(access, "translation") || ajStrMatchC(access, "get_exon") || ajStrMatchC(access, "get_exons") || ajStrMatchC(access, "get_cdsseq") || ajStrMatchC(access, "get_gbkseq") || ajStrMatchC(access, "get_geneseq") || ajStrMatchC(access, "get_intron") || ajStrMatchC(access, "getseq") || ajStrMatchC(access, "seq") || ajStrMatchC(access, "around_startcodon") || ajStrMatchC(access, "around_stopcodon") || ajStrMatchC(access, "before_startcodon") || ajStrMatchC(access, "before_stopcodon") || ajStrMatchC(access, "after_startcodon") || ajStrMatchC(access, "after_stopcodon") ) { isseq = ajTrue; } else if(ajStrMatchC(access, "annotate") || ajStrMatchC(access, "output")) { isgbk = ajTrue; } else { ajFmtPrintF(outfile, "gene,%S\n", access); } base = ajStrNewC("rest.g-language.org"); ajStrExchangeCC(&argument, " ", "/"); ajStrExchangeCC(&argument, ",", "/"); ajStrExchangeCC(&argument, "\t", "/"); ajStrExchangeCC(&argument, "\r", "/"); ajStrExchangeCC(&argument, "\n", "/"); if(ajStrMatchC(gene, "*")) { ajStrInsertK(&gene, 0, '.'); } if(ajStrPrefixC(gene, "@") || ajStrPrefixC(gene, "list::")) { ajStrExchangeCC(&gene, "@", ""); ajStrExchangeCC(&gene, "list::", ""); ajStrAssignS(&tmpname, gene); tmpfile = ajFileNewInNameS(tmpname); if(!tmpfile) { ajDie("List file (%S) open error\n", tmpname); } gene = ajStrNew(); while(ajReadline(tmpfile, &line)) { ajStrAppendS(&gene, line); } ajFileClose(&tmpfile); ajStrDel(&tmpname); ajStrDel(&line); } tmpname = ajStrNew(); gAssignUniqueName(&tmpname); while(ajSeqallNext(seqall, &seq)) { inseq = ajStrNew(); if(!accid) { if(gFormatGenbank(seq, &inseq)) { tmpfile = ajFileNewOutNameS(tmpname); if(!tmpfile) { ajDie("Output file (%S) open error\n", tmpname); } ajFmtPrintF(tmpfile, "%S", inseq); ajFileClose(&tmpfile); ajFmtPrintS(&url, "http://%S/upload/upl.pl", base); gFilePostSS(url, tmpname, &restid); ajStrDel(&url); ajSysFileUnlinkS(tmpname); } else { ajWarn("Sequence does not have features\n" "Proceeding with sequence accession ID\n"); accid = ajTrue; } } ajStrAssignS(&seqid, ajSeqGetAccS(seq)); if(ajStrGetLen(seqid) == 0) { ajStrAssignS(&seqid, ajSeqGetNameS(seq)); } if(ajStrGetLen(seqid) == 0) { ajWarn("No valid header information\n"); } if(accid) { ajStrAssignS(&restid, seqid); if(ajStrGetLen(seqid) == 0) { ajDie("Cannot proceed without header with -accid\n"); } if(!gValID(seqid)) { ajDie("Invalid accession ID:%S, exiting\n", seqid); } } url = ajStrNew(); if(isgbk) { ajFmtPrintS(&url, "http://%S/%S/%S", base, restid, access); } else { ajFmtPrintS(&url, "http://%S/%S/*/%S/%S", base, restid, access, argument); } if(!gFilebuffURLS(url, &buff)) { ajDie("GET error from %S\n", url); } while(ajBuffreadLine(buff, &line)) { if(isgbk){ ajFmtPrintF(outfile, "%S", line); continue; } ajStrRemoveLastNewline(&line); regex = ajRegCompC("^>"); if(ajRegExec(regex, line)) { head = ajStrNew(); ajStrAssignS(&head, line); ajStrTrimStartC(&head, ">"); valid = ajFalse; token = ajStrTokenNewC(ajStrNewS(gene), " ,\t\r\n"); while(ajStrTokenNextParse(token, ®exstr)) { if(ajStrGetLen(regexstr)) { regex = ajRegComp(regexstr); if(ajRegExec(regex, line)) { valid = ajTrue; if(ajStrIsAlnum(regexstr)) { ajStrExchangeSC(&gene, regexstr, ""); } } ajRegFree(®ex); } } } else { if(valid) { if(isseq) { ajStrFmtWrap(&line, 60); ajFmtPrintF(outfile, ">%S\n%S\n", head, line); } else { ajFmtPrintF(outfile, "%S,%S\n", head, line); } valid = ajFalse; } } } ajFileClose(&outfile); ajStrDel(&restid); ajStrDel(&seqid); ajStrDel(&inseq); } ajSeqallDel(&seqall); ajSeqDel(&seq); ajStrDel(&access); ajStrDel(&gene); embExit(); }
int main(int argc, char **argv) { // initialize EMBASSY info embInitPV("kweblogo", argc, argv, "KBWS", "1.0.9"); // soap driver and parameter object struct soap soap; struct ns1__weblogoInputParams params; char* jobid; AjPSeqall seqall; AjPSeq seq; AjPStr substr; AjPStr inseq = NULL; // get input sequence seqall= ajAcdGetSeqall("seqall"); // get/set parameters params.format = ajCharNewS(ajAcdGetString("format")); 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; AjPFile goutf; AjPStr goutfile; goutfile= ajAcdGetString("goutfile"); 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__runWeblogo( &soap, NULL, NULL, in0, ¶ms, &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); } char* image_url; if (soap_call_ns1__getResult(&soap, NULL, NULL, jobid, &image_url) == SOAP_OK) { goutf= ajFileNewOutNameS(goutfile); if (!goutf) { // can not open image output file ajFmtError("Problem writing out image file"); embExitBad(); } if (!gHttpGetBinC(image_url, &goutf)) { // can not download image file ajFmtError("Problem downloading image file"); embExitBad(); } } else { soap_print_fault(&soap, stderr); } // delete temporary multi-fasta sequence file ajSysFileUnlinkS(tmpFileName); // destruct SOAP driver soap_destroy(&soap); soap_end(&soap); soap_done(&soap); // destruct EMBOSS object ajSeqallDel(&seqall); ajSeqDel(&seq); ajStrDel(&substr); // exit embExit(); return 0; }
/* @funcstatic acdrelations_procacdfile *************************************** ** ** Process ACD file and write new ACD file with new relations: attributes ** added (replaced if necessary). ** ** @param [r] inf [AjPFile] ACD input file ** @param [r] outf [AjPFile] ACD output file ** @param [r] P [PEdam] edam object ** @param [r] T [PKtype] ktype object ** @return [void] ** @@ ******************************************************************************/ static void acdrelations_procacdfile (AjPFile inf, AjPFile outf, PEdam P, PKtype T) { AjPStr line = NULL; AjPStr tok = NULL; AjPStr acdtype = NULL; AjPStr strtmp = NULL; AjPList strlist = NULL; AjPStr *strarr = NULL; ajint nstr = 0; /* Allocate memory */ line = ajStrNew(); tok = ajStrNew(); acdtype = ajStrNew(); strlist = ajListstrNew(); /* Read next line */ while(ajReadline(inf,&line)) { ajFmtScanS(line, "%S", &tok); /* Write application definition or section definition out as-is */ if(ajStrMatchC(tok, "application:") || ajStrMatchC(tok, "section:")) { ajFmtPrintF(outf, "%S", line); while(ajReadline(inf,&line)) { ajFmtPrintF(outf, "%S", line); ajFmtScanS(line, "%S", &tok); if(ajStrMatchC(tok, "]")) break; } } /* Write variables, endsection definitions and comments out as-is */ else if(ajStrMatchC(tok, "variable:") || ajStrMatchC(tok, "endsection:") || ajStrMatchC(tok, "#")) ajFmtPrintF(outf, "%S", line); /* Write out blank lines as-is */ else if (!ajFmtScanS(line, "%S", &tok)) ajFmtPrintF(outf, "%S", line); /* Process data definition */ else /* First line of data definition */ { /* Process and write datatype line */ ajFmtPrintF(outf, "%S", line); ajFmtScanS(line, "%S", &acdtype); ajStrRemoveSetC(&acdtype, ":"); /* Process subsequent (attribute) lines */ while(ajReadline(inf,&line)) { strtmp = ajStrNew(); ajStrAssignS(&strtmp, line); ajStrRemoveWhite(&strtmp); ajListstrPushAppend(strlist, strtmp); ajFmtScanS(line, "%S", &tok); /* Reached end of data definition */ if(ajStrMatchC(tok, "]")) { nstr = ajListstrToarray(strlist, &strarr); /* Write relations: line */ acdrelations_writerelations(outf, acdtype, strarr, nstr, P, T); AJFREE(strarr); ajListstrFreeData(&strlist); strlist = ajListstrNew(); ajFmtPrintF(outf, "%S", line); break; } /* Ignore existing relations: lines */ else if(ajStrMatchC(tok, "relations:")) continue; ajFmtPrintF(outf, "%S", line); } } } /* Free memory */ ajStrDel(&line); ajStrDel(&tok); ajStrDel(&acdtype); ajListstrFreeData(&strlist); return; }
EmbPPropMolwt* embPropEmolwtRead(AjPFile mfptr) { AjPStr line = NULL; AjPStr token = NULL; AjBool firstline; const char *p; ajuint i; ajint n; EmbPPropMolwt *ret; line = ajStrNew(); token = ajStrNew(); firstline = ajTrue; AJCNEW0(ret,EMBPROPSIZE+2); for(i=0; i < EMBPROPSIZE+2; ++i) AJNEW0(ret[i]); while(ajReadline(mfptr, &line)) { ajStrRemoveWhiteExcess(&line); p = ajStrGetPtr(line); if(*p=='#' || *p=='!' || !*p) continue; if(firstline) { if(!ajStrPrefixC(line,"Mol")) ajFatal("Incorrect format molwt file: '%S'", line); firstline = ajFalse; continue; } ajFmtScanS(line,"%S",&token); ajStrFmtUpper(&token); if(ajStrGetLen(token) != 1) { if(ajStrPrefixC(token,"HYDROGEN")) { if(ajFmtScanS(line,"%*s%lf%lf", &ret[EMBPROPHINDEX]->average, &ret[EMBPROPHINDEX]->mono) != 2) ajFatal("Bad format hydrogen data line"); } else if(ajStrPrefixC(token,"OXYGEN")) { if(ajFmtScanS(line,"%*s%lf%lf", &ret[EMBPROPOINDEX]->average, &ret[EMBPROPOINDEX]->mono) != 2) ajFatal("Bad format oxygen data line"); } else if(ajStrPrefixC(token,"WATER")) { if(ajFmtScanS(line,"%*s%lf%lf", &ret[EMBPROPWINDEX]->average, &ret[EMBPROPWINDEX]->mono) != 2) ajFatal("Bad format water data line"); } else ajFatal("Unknown molwt token %S",token); continue; } i = ajBasecodeToInt((ajint) *ajStrGetPtr(token)); if(i == 27) ajFatal("Molwt file line doesn't begin with a single A->Z (%S)", line); n = ajFmtScanS(line,"%*s%lf%lf", &ret[i]->average, &ret[i]->mono); if(n != 2) ajFatal("Only %d columns in amino file - expected %d",n,3); } ajStrDel(&line); ajStrDel(&token); return ret; }
AjBool gHttpRedirect(AjPFile file, AjPStr* host, ajint* port, AjPStr* path) { AjPFilebuff buff = NULL; AjPRegexp httpexp = NULL; AjPRegexp nullexp = NULL; AjPRegexp redirexp = NULL; AjPStr codestr = NULL; AjPStr newurl = NULL; AjPStr newhost = NULL; AjPStr currline = NULL; ajuint httpcode = 0; AjBool isheader = ajFalse; AjBool ret = ajFalse; httpexp = ajRegCompC("^HTTP/\\S+\\s+(\\d+)"); ajReadline(file, &currline); ajDebug("gHttpRedirect: First line: '%S'\n", currline); if(ajRegExec(httpexp, currline)) { isheader = ajTrue; ajRegSubI(httpexp, 1, &codestr); ajStrToUint(codestr, &httpcode); ajDebug("Header: codestr '%S' code '%u'\n", codestr, httpcode); ajStrDel(&codestr); } if(isheader) { if(httpcode == 301 || httpcode == 302 || httpcode==307) { redirexp = ajRegCompC("^Location: (\\S+)"); nullexp = ajRegCompC("^\r?\n?$"); while( ajReadline(file, &currline) && !ajRegExec(nullexp, currline)) { ajDebug("gHttpRedirect: header line: '%S'\n", currline); if(ajRegExec(redirexp, currline)) { ajRegSubI(redirexp, 1, &newurl); ajHttpUrlDeconstruct(newurl, port, &newhost, path); if(ajStrGetLen(newhost)) ajStrAssignS(host, newhost); ajStrDel(&newurl); ajStrDel(&newhost); ret = ajTrue; break; } } ajRegFree(&redirexp); ajRegFree(&nullexp); } } ajRegFree(&httpexp); ajStrDel(&currline); return ret; }
AjPFilebuff gHttpPostFileSS(AjPStr url, AjPStr filename) { AjPFilebuff buff = NULL; AjPFile file = NULL; AjPStr line = NULL; AjPStr cont = NULL; AjPStr host = NULL; AjPStr path = NULL; AjPStr post = NULL; AjPStr body = NULL; ajint port = 80; ajuint http = 0; FILE *fp; char crlf[] = "\015\021"; AjOSysSocket sock; AjOSysTimeout timo; post = ajStrNew(); body = ajStrNew(); cont = ajStrNew(); file = ajFileNewInNameS(filename); while(ajReadline(file, &line)) { ajStrAppendS(&cont, line); } ajHttpUrlDeconstruct(url, &port, &host, &path); while(buff==NULL || ajHttpRedirect(buff, &host, &port, &path, &http)) { if(ajStrGetCharFirst(path) != '/') ajStrInsertK(&path, 0, '/'); ajFmtPrintS( &body, "--xYzZY\015\012" "Content-Disposition: form-data; name=\"file\";" " filename=\"%S\"\015\012" "Content-Type: text/plain\015\012" "%S\015\012" "\015\012--xYzZY--\015\012", filename, cont ); ajFmtPrintS( &post, "POST http://%S%S\n" "Content-Length: %d\n" "Content-Type: multipart/form-data; boundary=xYzZY\n\n" "%S", host, path, ajStrGetLen(body), body ); ajFmtPrint("%S", post); fp = ajHttpOpen(NULL, host, port, post, &sock); buff = ajFilebuffNewFromCfile(fp); if(!buff) return NULL; } ajStrDel(&post); timo.seconds = 180; ajSysTimeoutSet(&timo); ajFilebuffLoadAll(buff); ajSysTimeoutUnset(&timo); return buff; }
int main(int argc, char **argv) { embInitPV("kclustalw", argc, argv, "KBWS", "1.0.8"); struct soap soap; struct ns1__clustalwInputParams params; char* jobid; char* result; AjPSeqall seqall; AjPSeq seq; AjPFile outf; AjPFile outf_dnd; AjPStr substr; AjPStr inseq = NULL; AjPStr alignment; AjPStr output; AjPStr matrix; AjPStr outorder; ajint ktup; ajint window; ajint gapopen; float gapext; ajint gapdist; AjBool endgaps; ajint pairgap; ajint topdiags; AjPStr score; AjBool tossgaps; AjBool kimura; AjPStr outputtree; AjBool tree; AjBool quicktree; AjBool align; AjPStr clustering; ajint numiter; AjPStr iteration; alignment = ajAcdGetString("alignment"); output = ajAcdGetString("output"); matrix = ajAcdGetString("matrix"); outorder = ajAcdGetString("outorder"); ktup = ajAcdGetInt("ktup"); window = ajAcdGetInt("window"); gapopen = ajAcdGetInt("gapopen"); gapext = ajAcdGetFloat("gapext"); gapdist = ajAcdGetInt("gapdist"); endgaps = ajAcdGetBoolean("endgaps"); pairgap = ajAcdGetInt("pairgap"); topdiags = ajAcdGetInt("topdiags"); score = ajAcdGetString("score"); tossgaps = ajAcdGetBoolean("tossgaps"); kimura = ajAcdGetBoolean("kimura"); outputtree = ajAcdGetString("outputtree"); tree = ajAcdGetBoolean("tree"); quicktree = ajAcdGetBoolean("quicktree"); align = ajAcdGetBoolean("align"); clustering = ajAcdGetString("clustering"); numiter = ajAcdGetInt("numiter"); iteration = ajAcdGetString("iteration"); seqall = ajAcdGetSeqall("seqall"); outf = ajAcdGetOutfile("outfile"); outf_dnd = ajAcdGetOutfile("dndoutfile"); params.alignment = ajCharNewS(alignment); params.output = ajCharNewS(output); params.matrix = ajCharNewS(matrix); params.outorder = ajCharNewS(outorder); params.ktup = ktup; params.window = window; params.gapopen = gapopen; params.gapext = gapext; params.gapdist = gapdist; if (endgaps) { params.endgaps = xsd__boolean__true_; } else { params.endgaps = xsd__boolean__false_; } params.pairgap = pairgap; params.topdiags = topdiags; params.score = ajCharNewS(score); if (tossgaps) { params.tossgaps = xsd__boolean__true_; } else { params.tossgaps = xsd__boolean__false_; } if (kimura) { params.kimura = xsd__boolean__true_; } else { params.kimura = xsd__boolean__false_; } params.outputtree = ajCharNewS(outputtree); if (tree) { params.tree = xsd__boolean__true_; } else { params.tree = xsd__boolean__false_; } if (quicktree) { params.quicktree = xsd__boolean__true_; } else { params.quicktree = xsd__boolean__false_; } if (align) { params.align = xsd__boolean__true_; } else { params.align = xsd__boolean__false_; } params.clustering = ajCharNewS(clustering); params.numiter = numiter; params.iteration = ajCharNewS(iteration); 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__runClustalw( &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"); char* type; type = "out"; if(soap_call_ns1__getMultiResult( &soap, NULL, NULL, jobid, type, &result )== SOAP_OK) { substr = ajStrNewC(result); fprintf(stdout, "%s\n", ajStrGetPtr(substr)); } else { soap_print_fault(&soap, stderr); } type = "aln"; if(soap_call_ns1__getMultiResult( &soap, NULL, NULL, jobid, type, &result )== SOAP_OK) { substr = ajStrNewC(result); ajFmtPrintF(outf,"%S\n",substr); } else { soap_print_fault(&soap, stderr); } type = "dnd"; if(soap_call_ns1__getMultiResult( &soap, NULL, NULL, jobid, type, &result )== SOAP_OK) { substr = ajStrNewC(result); ajFmtPrintF(outf_dnd,"%S\n",substr); } else { soap_print_fault(&soap, stderr); } ajSysFileUnlinkS(tmpFileName); soap_destroy(&soap); soap_end(&soap); soap_done(&soap); ajFileClose(&outf_dnd); ajFileClose(&outf); ajSeqallDel(&seqall); ajSeqDel(&seq); ajStrDel(&substr); 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; }
static void acdrelations_readdatfile (AjPFile inf, PEdam *P) { AjPStr line = NULL; const AjPStr tok = NULL; const AjPStr subtok = NULL; AjPStr strtmp = NULL; AjPList strlist = NULL; AjPStr acdtype = NULL; AjPStr relations = NULL; PEdamdat dattmp = NULL; AjPList datlist = NULL; if(!P) ajFatal("Null arg error 1 in acdrelations_readdatfile"); if(!inf) ajFatal("Null arg error 3 in acdrelations_readdatfile"); /* Allocate memory */ line = ajStrNew(); acdtype = ajStrNew(); relations = ajStrNew(); datlist = ajListNew(); /* Read data from file */ while(ajReadline(inf,&line)) { /* Discard comment lines */ if(ajStrPrefixC(line,"#")) continue; /* Tokenise line, delimited by '|'. Parse first token (ACD datatype ) */ ajStrAssignS(&acdtype, ajStrParseC(line, "|")); /* Parse second token (EDAM relations: value ) */ ajStrAssignS(&relations, ajStrParseC(NULL, "|")); /* Parse third token (attribute:value strings block) */ tok = ajStrParseC(NULL, "|"); /* Create new string list */ strlist = ajListstrNew(); /* Tokenise third token itself into tokens delimited by ' ' (space) Parse tokens (individual attribute:value strings)*/ if((subtok=ajStrParseC(tok, ";"))) { strtmp = ajStrNew(); ajStrAssignS(&strtmp, subtok); ajStrRemoveWhite(&strtmp); ajListstrPushAppend(strlist, strtmp); while((subtok=ajStrParseC(NULL, ";"))) { strtmp = ajStrNew(); ajStrAssignS(&strtmp, subtok); ajStrRemoveWhite(&strtmp); ajListstrPushAppend(strlist, strtmp); } } /* Write PEdamdat structure & push onto list */ dattmp = ajEdamdatNew(); ajStrRemoveWhite(&acdtype); ajStrAssignS(&dattmp->acdtype, acdtype); ajStrAssignS(&dattmp->edam, relations); dattmp->n = ajListstrToarray(strlist, &dattmp->acdattr); ajListPushAppend(datlist, dattmp); /* Clear nodes (but not strings) from string list */ ajListstrFree(&strlist); } /* Write PEdam structure */ ((*P)->n) = ajListToarray(datlist, (void***) &((*P)->dat)); /* Free memory */ ajStrDel(&line); ajStrDel(&acdtype); ajStrDel(&relations); ajListFree(&datlist); return; }
EmbPPropAmino* embPropEaminoRead(AjPFile mfptr) { AjPStr line = NULL; AjPStr token = NULL; AjBool firstline; const char *p; ajuint i; ajint n; EmbPPropAmino *ret; line = ajStrNew(); token = ajStrNew(); firstline = ajTrue; AJCNEW0(ret,EMBPROPSIZE); for(i=0; i < EMBPROPSIZE; ++i) AJNEW0(ret[i]); while(ajReadline(mfptr, &line)) { ajStrRemoveWhiteExcess(&line); p = ajStrGetPtr(line); if(*p=='#' || *p=='!' || !*p) continue; if(firstline) { if(!ajStrPrefixC(line,"aa")) ajFatal("Incorrect (old?) format amino data file"); firstline = ajFalse; continue; } ajFmtScanS(line,"%S",&token); ajStrFmtUpper(&token); if(ajStrGetLen(token) != 1) ajFatal("Amino file line doesn't begin with a single character"); i = ajBasecodeToInt((ajint) *ajStrGetPtr(token)); if(i == 27) ajFatal("Amino file line doesn't begin with a single A->Z (%S)", line); n = ajFmtScanS(line,"%*s%d%d%d%d%d%d%f%d%d%d", &ret[i]->tiny, &ret[i]->sm_all, &ret[i]->aliphatic, &ret[i]->aromatic, &ret[i]->nonpolar, &ret[i]->polar, &ret[i]->charge, &ret[i]->pve, &ret[i]->nve, &ret[i]->extcoeff); if(n!= 10) ajFatal("Only %d columns in amino file - expected %d",n+1,11); } ajStrDel(&line); ajStrDel(&token); return ret; }
int main(int argc, char **argv) { AjPSeq seq; AjPGraph graph = 0; AjPFile outf = NULL; AjPFile file = NULL; AjPStr buffer = NULL; float twist[4][4][4]; float roll[4][4][4]; float tilt[4][4][4]; float rbend; float rcurve; float bendscale; float curvescale; float twistsum = (float) 0.0; float pi = (float) 3.14159; float pifac = (pi/(float) 180.0); float pi2 = pi/(float) 2.0; ajint *iseq = NULL; float *x; float *y; float *xave; float *yave; float *curve; float *bend; const char *ptr; ajint i; ajint ii; ajint k; ajint j; char residue[2]; float maxbend; float minbend; float bendfactor; float maxcurve; float mincurve; float curvefactor; float fxp; float fyp; float yincr; float yy1; ajint ixlen; ajint iylen; ajint ixoff; ajint iyoff; float ystart; float defheight; float currentheight; ajint count; ajint portrait = 0; ajint title = 0; ajint numres; ajint ibeg; ajint iend; ajint ilen; AjPStr sstr = NULL; ajint ipos; float dx; float dy; float rxsum; float rysum; float yp1; float yp2; double td; embInit("banana", argc, argv); seq = ajAcdGetSeq("sequence"); file = ajAcdGetDatafile("anglesfile"); outf = ajAcdGetOutfile("outfile"); graph = ajAcdGetGraph("graph"); numres = ajAcdGetInt("residuesperline"); ibeg = ajSeqGetBegin(seq); iend = ajSeqGetEnd(seq); ajStrAssignSubS(&sstr, ajSeqGetSeqS(seq), ibeg-1, iend-1); ilen = ajStrGetLen(sstr); AJCNEW0(iseq,ilen+1); AJCNEW0(x,ilen+1); AJCNEW0(y,ilen+1); AJCNEW0(xave,ilen+1); AJCNEW0(yave,ilen+1); AJCNEW0(curve,ilen+1); AJCNEW0(bend,ilen+1); ptr= ajStrGetPtr(sstr); for(ii=0;ii<ilen;ii++) { if(*ptr=='A' || *ptr=='a') iseq[ii+1] = 0; else if(*ptr=='T' || *ptr=='t') iseq[ii+1] = 1; else if(*ptr=='G' || *ptr=='g') iseq[ii+1] = 2; else if(*ptr=='C' || *ptr=='c') iseq[ii+1] = 3; else ajErr("%c is not an ATCG hence not valid",*ptr); ptr++; } if(!file) ajErr("Banana failed to open angle file"); ajReadline(file,&buffer); /* 3 junk lines */ ajReadline(file,&buffer); ajReadline(file,&buffer); for(k=0;k<4;k++) for(ii=0;ii<4;ii++) { if(ajReadline(file,&buffer)) { sscanf(ajStrGetPtr(buffer),"%f,%f,%f,%f", &twist[ii][0][k],&twist[ii][1][k],&twist[ii][2][k], &twist[ii][3][k]); } else ajErr("Error reading angle file"); for(j=0;j<4;j++) twist[ii][j][k] *= pifac; } for(k=0;k<4;k++) for(ii=0;ii<4;ii++) if(ajReadline(file,&buffer)) { sscanf(ajStrGetPtr(buffer),"%f,%f,%f,%f",&roll[ii][0][k], &roll[ii][1][k],&roll[ii][2][k],&roll[ii][3][k]); } else ajErr("Error reading angle file"); for(k=0;k<4;k++) for(ii=0;ii<4;ii++) if(ajReadline(file,&buffer)) sscanf(ajStrGetPtr(buffer),"%f,%f,%f,%f",&tilt[ii][0][k], &tilt[ii][1][k],&tilt[ii][2][k],&tilt[ii][3][k]); else ajErr("Error reading angle file"); if(ajReadline(file,&buffer)) sscanf(ajStrGetPtr(buffer),"%f,%f,%f,%f",&rbend,&rcurve, &bendscale,&curvescale); else ajErr("Error reading angle file"); ajFileClose(&file); ajStrDel(&buffer); for(ii=1;ii<ilen-1;ii++) { twistsum += twist[iseq[ii]][iseq[ii+1]][iseq[ii+2]]; dx = (roll[iseq[ii]][iseq[ii+1]][iseq[ii+2]]*sinfban(twistsum)) + (tilt[iseq[ii]][iseq[ii+1]][iseq[ii+2]]*sinfban(twistsum-pi2)); dy = roll[iseq[ii]][iseq[ii+1]][iseq[ii+2]]*cosfban(twistsum) + tilt[iseq[ii]][iseq[ii+1]][iseq[ii+2]]*cosfban(twistsum-pi2); x[ii+1] = x[ii]+dx; y[ii+1] = y[ii]+dy; } for(ii=6;ii<ilen-6;ii++) { rxsum = 0.0; rysum = 0.0; for(k=-4;k<=4;k++) { rxsum+=x[ii+k]; rysum+=y[ii+k]; } rxsum+=(x[ii+5]*(float)0.5); rysum+=(y[ii+5]*(float)0.5); rxsum+=(x[ii-5]*(float)0.5); rysum+=(y[ii-5]*(float)0.5); xave[ii] = rxsum*(float)0.1; yave[ii] = rysum*(float)0.1; } for(i=(ajint)rbend+1;i<=ilen-(ajint)rbend-1;i++) { td = sqrt(((x[i+(ajint)rbend]-x[i-(ajint)rbend])* (x[i+(ajint)rbend]-x[i-(ajint)rbend])) + ((y[i+(ajint)rbend]-y[i-(ajint)rbend])* (y[i+(ajint)rbend]-y[i-(ajint)rbend]))); bend[i] = (float) td; bend[i]*=bendscale; } for(i=(ajint)rcurve+6;i<=ilen-(ajint)rcurve-6;i++) { td = sqrt(((xave[i+(ajint)rcurve]- xave[i-(ajint)rcurve])*(xave[i+(ajint)rcurve]- xave[i-(ajint)rcurve]))+ ((yave[i+(ajint)rcurve]-yave[i-(ajint)rcurve])* (yave[i+(ajint)rcurve]-yave[i-(ajint)rcurve]))); curve[i] = (float) td; } if(outf) { ajFmtPrintF(outf,"Base Bend Curve\n"); ptr = ajStrGetPtr(sstr); for(ii=1;ii<=ilen;ii++) { ajFmtPrintF(outf,"%c %6.1f %6.1f\n", *ptr, bend[ii], curve[ii]); ptr++; } ajFileClose(&outf); } if(graph) { maxbend = minbend = 0.0; maxcurve = mincurve = 0.0; for(ii=1;ii<=ilen;ii++) { if(bend[ii] > maxbend) maxbend = bend[ii]; if(bend[ii] < minbend) minbend = bend[ii]; if(curve[ii] > maxcurve) maxcurve = curve[ii]; if(curve[ii] < mincurve) mincurve = curve[ii]; } ystart = 75.0; ajGraphAppendTitleS(graph, ajSeqGetUsaS(seq)); ajGraphicsSetPagesize(960, 768); ajGraphOpenWin(graph,(float)-1.0, (float)numres+(float)10.0, (float)0.0, ystart+(float)5.0); ajGraphicsGetParamsPage(&fxp,&fyp,&ixlen,&iylen,&ixoff,&iyoff); if(portrait) { ixlen = 768; iylen = 960; } else { ixlen = 960; iylen = 768; } ajGraphicsGetCharsize(&defheight,¤theight); if(!currentheight) { defheight = currentheight = (float) 4.440072; currentheight = defheight * ((float)ixlen/ ((float)(numres)*(currentheight+(float)1.0))) /currentheight; } ajGraphicsSetCharscale(((float)ixlen/((float)(numres)* (currentheight+(float)1.0)))/ currentheight); ajGraphicsGetCharsize(&defheight,¤theight); yincr = (currentheight + (float)3.0)*(float)0.3; if(!title) yy1 = ystart; else yy1 = ystart-(float)5.0; count = 1; residue[1]='\0'; bendfactor = (3*yincr)/maxbend; curvefactor = (3*yincr)/maxcurve; ptr = ajStrGetPtr(sstr); yy1 = yy1-(yincr*((float)5.0)); for(ii=1;ii<=ilen;ii++) { if(count > numres) { yy1 = yy1-(yincr*((float)5.0)); if(yy1<1.0) { if(!title) yy1=ystart; else yy1 = ystart-(float)5.0; yy1 = yy1-(yincr*((float)5.0)); ajGraphNewpage(graph,AJFALSE); } count = 1; } residue[0] = *ptr; ajGraphicsDrawposTextAtend((float)(count)+(float)2.0,yy1,residue); if(ii>1 && ii < ilen) { yp1 = yy1+yincr + (bend[ii]*bendfactor); yp2 = yy1+yincr + (bend[ii+1]*bendfactor); ajGraphicsDrawposLine((float)count+(float)1.5,yp1, (float)(count)+(float)2.5,yp2); } ipos = ilen-(ajint)rcurve-7; if(ipos < 0) ipos = 0; if(ii>rcurve+5 && ii<ipos) { yp1 = yy1+yincr + (curve[ii]*curvefactor); yp2 = yy1+yincr + (curve[ii+1]*curvefactor); ajGraphicsDrawposLine((float)count+(float)1.7,yp1, (float)(count)+(float)2.3,yp2); } ajGraphicsDrawposLine((float)count+(float)1.5,yy1+yincr, (float)(count)+(float)2.5,yy1+yincr); count++; ptr++; } ajGraphicsClose(); } AJFREE(iseq); AJFREE(x); AJFREE(y); AJFREE(xave); AJFREE(yave); AJFREE(curve); AJFREE(bend); ajStrDel(&sstr); ajSeqDel(&seq); ajFileClose(&file); ajFileClose(&outf); ajGraphxyDel(&graph); embExit(); return 0; }
static AjBool dbifasta_ParseFasta(AjPFile libr, ajint* dpos, ajint* maxFieldLen, ajuint* countfield, AjPRegexp idexp, ajuint usertype, AjPFile* alistfile, AjBool systemsort, AjPStr const * fields) { char* fd; ajlong ipos; static AjPStr tstr = NULL; static ajint numFields; static ajint accfield = -1; static ajint desfield = -1; static ajint svnfield = -1; static AjBool reset = AJTRUE; ajuint type = usertype; if(!fields) { reset = ajTrue; accfield = svnfield = desfield = -1; return ajFalse; } if(reset) { numFields = 0; while(fields[numFields]) { if(ajStrMatchCaseC(fields[numFields], "acc")) accfield=numFields; else if(ajStrMatchCaseC(fields[numFields], "sv")) svnfield=numFields; else if(ajStrMatchCaseC(fields[numFields], "des")) desfield=numFields; else ajWarn("EMBL parsing unknown field '%S' ignored", fields[numFields]); numFields++; } reset = ajFalse; } if(!dbifastaGWrdexp) dbifastaGWrdexp = ajRegCompC("([A-Za-z0-9]+)"); if(!tstr) tstr = ajStrNew(); *dpos = (ajint) ajFileResetPos(libr); /* Lossy cast */ ajReadline(libr, &dbifastaGRline); if(!ajStrGetLen(dbifastaGRline)) return ajFalse; if(!ajRegExec(idexp,dbifastaGRline)) { ajStrDelStatic(&dbifastaGTmpAc); type = FASTATYPE_SIMPLE; idexp = dbifastaGIdexp; if(!ajRegExec(idexp, dbifastaGRline)) { ajFatal("Unrecognised ID line format: %S", dbifastaGRline); return ajFalse; } ajWarn("Invalid ID line for selected format: %S", dbifastaGRline); } /* ** each case needs to set id, tmpac, tmpsv, tmpdes ** using empty values if they are not found */ ajStrAssignC(&dbifastaGTmpSv, ""); ajStrAssignC(&dbifastaGTmpGi, ""); ajStrAssignC(&dbifastaGTmpDb, ""); ajStrAssignC(&dbifastaGTmpDes, ""); ajStrAssignC(&dbifastaGTmpAc, ""); ajStrAssignC(&dbifastaGTmpId, ""); switch(type) { case FASTATYPE_SIMPLE: ajRegSubI(idexp,2,&dbifastaGTmpId); ajStrAssignS(&dbifastaGTmpAc,dbifastaGTmpId); ajRegPost(idexp, &dbifastaGTmpDes); break; case FASTATYPE_DBID: ajRegSubI(idexp,1,&dbifastaGTmpId); ajStrAssignS(&dbifastaGTmpAc,dbifastaGTmpId); ajRegPost(idexp, &dbifastaGTmpDes); break; case FASTATYPE_GCGID: ajRegSubI(idexp,1,&dbifastaGTmpId); ajStrAssignS(&dbifastaGTmpAc,dbifastaGTmpId); ajRegPost(idexp, &dbifastaGTmpDes); break; case FASTATYPE_NCBI: if(!ajSeqParseNcbi(dbifastaGRline, &dbifastaGTmpId, &dbifastaGTmpAc, &dbifastaGTmpSv, &dbifastaGTmpGi, &dbifastaGTmpDb, &dbifastaGTmpDes)) { ajStrDelStatic(&dbifastaGTmpAc); return ajFalse; } break; case FASTATYPE_GCGIDACC: ajRegSubI(idexp,1,&dbifastaGTmpId); ajRegSubI(idexp,2,&dbifastaGTmpAc); ajRegPost(idexp, &dbifastaGTmpDes); break; case FASTATYPE_GCGACCID: ajRegSubI(idexp,1,&dbifastaGTmpAc); ajRegSubI(idexp,2,&dbifastaGTmpId); ajRegPost(idexp, &dbifastaGTmpDes); break; case FASTATYPE_IDACC: ajRegSubI(idexp,1,&dbifastaGTmpId); ajRegSubI(idexp,2,&dbifastaGTmpAc); ajRegPost(idexp, &dbifastaGTmpDes); break; case FASTATYPE_ACCID: ajRegSubI(idexp,1,&dbifastaGTmpAc); ajRegSubI(idexp,2,&dbifastaGTmpId); ajRegPost(idexp, &dbifastaGTmpDes); break; default: ajStrDelStatic(&dbifastaGTmpAc); return ajFalse; } ajStrFmtUpper(&dbifastaGTmpId); ajStrFmtUpper(&dbifastaGTmpAc); if(accfield >= 0) embDbiMaxlen(&dbifastaGTmpAc, &maxFieldLen[accfield]); if(svnfield >= 0) { embDbiMaxlen(&dbifastaGTmpSv, &maxFieldLen[svnfield]); embDbiMaxlen(&dbifastaGTmpGi, &maxFieldLen[svnfield]); } if(systemsort) { if(accfield >= 0 && ajStrGetLen(dbifastaGTmpAc)) { countfield[accfield]++; ajFmtPrintF(alistfile[accfield], "%S %S\n", dbifastaGTmpId, dbifastaGTmpAc); } if(svnfield >= 0 && ajStrGetLen(dbifastaGTmpSv)) { countfield[svnfield]++; ajFmtPrintF(alistfile[svnfield], "%S %S\n", dbifastaGTmpId, dbifastaGTmpSv); } if(svnfield >= 0 && ajStrGetLen(dbifastaGTmpGi)) { countfield[svnfield]++; ajFmtPrintF(alistfile[svnfield], "%S %S\n", dbifastaGTmpId, dbifastaGTmpGi); } if(desfield >= 0 && ajStrGetLen(dbifastaGTmpDes)) while(ajRegExec(dbifastaGWrdexp, dbifastaGTmpDes)) { ajRegSubI(dbifastaGWrdexp, 1, &dbifastaGTmpFd); embDbiMaxlen(&dbifastaGTmpFd, &maxFieldLen[desfield]); ajStrFmtUpper(&dbifastaGTmpFd); ajDebug("++des '%S' tmpdes '%S\n", dbifastaGTmpFd, dbifastaGTmpDes); countfield[desfield]++; ajFmtPrintF(alistfile[desfield], "%S %S\n", dbifastaGTmpId, dbifastaGTmpFd); ajRegPost(dbifastaGWrdexp, &dbifastaGTmpDes); } } else { if(accfield >= 0 && ajStrGetLen(dbifastaGTmpAc)) { fd = ajCharNewS(dbifastaGTmpAc); ajListPushAppend(dbifastaGFdl[accfield],fd); countfield[accfield]++; } if(svnfield >= 0 && ajStrGetLen(dbifastaGTmpSv)) { fd = ajCharNewS(dbifastaGTmpSv); ajListPushAppend(dbifastaGFdl[svnfield], fd); countfield[svnfield]++; } if(svnfield >= 0 && ajStrGetLen(dbifastaGTmpGi)) { fd = ajCharNewS(dbifastaGTmpGi); ajListPushAppend(dbifastaGFdl[svnfield], fd); countfield[svnfield]++; } if(desfield >= 0 && ajStrGetLen(dbifastaGTmpDes)) while(ajRegExec(dbifastaGWrdexp, dbifastaGTmpDes)) { ajRegSubI(dbifastaGWrdexp, 1, &dbifastaGTmpFd); embDbiMaxlen(&dbifastaGTmpFd, &maxFieldLen[desfield]); ajStrFmtUpper(&dbifastaGTmpFd); ajDebug("++des '%S' tmpdes: '%S'\n", dbifastaGTmpFd, dbifastaGTmpDes); fd = ajCharNewS(dbifastaGTmpFd); ajListPushAppend(dbifastaGFdl[desfield], fd); countfield[desfield]++; ajRegPost(dbifastaGWrdexp, &dbifastaGTmpDes); } } ipos = ajFileResetPos(libr); while(ajReadline(libr, &dbifastaGRline)) { if(ajStrGetCharFirst(dbifastaGRline) == '>') { ajFileSeek(libr, ipos, 0); return ajTrue; } ipos = ajFileResetPos(libr); } ajFileSeek(libr, ipos, 0); /* end of file reached */ return ajTrue; }
/* @obsolete ajFileGets ** @rename ajReadline */ __deprecated AjBool ajFileGets(AjPFile thys, AjPStr* pdest) { return ajReadline(thys, pdest); }
AjPMatrix ajMatrixNewFile(const AjPStr filename) { AjPMatrix ret = NULL; AjPStr buffer = NULL; const AjPStr tok = NULL; AjPStr firststring = NULL; AjPStr *orderstring = NULL; AjPFile file = NULL; AjBool first = ajTrue; const char *ptr = NULL; ajint **matrix = NULL; ajint minval = -1; ajint i = 0; ajint l = 0; ajint k = 0; ajint cols = 0; ajint rows = 0; ajint *templine = NULL; AjPList rlabel_list = NULL; AjPStr *rlabel_arr = NULL; #ifndef WIN32 static const char *delimstr = " :\t\n"; #else static const char *delimstr = " :\t\n\r"; #endif rlabel_list = ajListNew(); firststring = ajStrNew(); file = ajDatafileNewInNameS(filename); if(!file) { ajStrDel(&firststring); ajListFree(&rlabel_list); return NULL; } /* Read row labels */ while(ajReadline(file,&buffer)) { ptr = ajStrGetPtr(buffer); #ifndef WIN32 if(*ptr != '#' && *ptr != '\n') #else if(*ptr != '#' && *ptr != '\n' && *ptr != '\r') #endif { if(first) first = ajFalse; else { ajFmtScanC(ptr, "%S", &firststring); ajListPushAppend(rlabel_list, firststring); firststring = ajStrNew(); } } } first = ajTrue; ajStrDel(&firststring); rows = ajListToarray(rlabel_list, (void ***) &rlabel_arr); ajFileSeek(file, 0, 0); while(ajReadline(file,&buffer)) { ajStrRemoveWhiteExcess(&buffer); ptr = ajStrGetPtr(buffer); if(*ptr && *ptr != '#') { if(first) { cols = ajStrParseCountC(buffer,delimstr); AJCNEW0(orderstring, cols); for(i=0; i<cols; i++) orderstring[i] = ajStrNew(); tok = ajStrParseC(buffer, " :\t\n"); ajStrAssignS(&orderstring[l++], tok); while((tok = ajStrParseC(NULL, " :\t\n"))) ajStrAssignS(&orderstring[l++], tok); first = ajFalse; ret = ajMatrixNewAsym(orderstring, cols, rlabel_arr, rows, filename); matrix = ret->Matrix; } else { ajFmtScanC(ptr, "%S", &firststring); /* JISON 19/7/4 k = ajSeqcvtGetCodeK(ret->Cvt, ajStrGetCharFirst(firststring)); */ k = ajSeqcvtGetCodeS(ret->Cvt, firststring); /* ** cols+1 is used below because 2nd and subsequent lines have ** one more string in them (the residue label) */ templine = ajArrIntLine(buffer,delimstr,2,cols+1); for(i=0; i<cols; i++) { if(templine[i] < minval) minval = templine[i]; /* JISON 19/7/4 matrix[k][ajSeqcvtGetCodeK(ret->Cvt, ajStrGetCharFirst(orderstring[i]))] = templine[i]; */ matrix[k][ajSeqcvtGetCodeAsymS(ret->Cvt, orderstring[i])] = templine[i]; } AJFREE(templine); } } } ajDebug("fill rest with minimum value %d\n", minval); ajFileClose(&file); ajStrDel(&buffer); for(i=0; i<cols; i++) ajStrDel(&orderstring[i]); AJFREE(orderstring); ajDebug("read matrix file %S\n", filename); ajStrDel(&firststring); for(i=0; i<rows; i++) ajStrDel(&rlabel_arr[i]); AJFREE(rlabel_arr); ajListFree(&rlabel_list); return ret; }
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; }
AjPMatrixf ajMatrixfNewFile(const AjPStr filename) { AjPMatrixf ret = NULL; AjPStr *orderstring = NULL; AjPStr buffer = NULL; AjPStr firststring = NULL; AjPStr reststring = NULL; const AjPStr tok = NULL; ajint len = 0; ajint i = 0; ajint l = 0; ajint k = 0; ajint cols = 0; ajint rows = 0; const char *ptr = NULL; AjPFile file = NULL; AjBool first = ajTrue; float **matrix = NULL; float *templine = NULL; float minval = -1.0; AjPList rlabel_list = NULL; AjPStr *rlabel_arr = NULL; #ifndef WIN32 static const char *delimstr = " :\t\n"; #else static const char *delimstr = " :\t\n\r"; #endif rlabel_list = ajListNew(); firststring = ajStrNew(); reststring = ajStrNew(); file = ajDatafileNewInNameS(filename); if(!file) { ajStrDel(&firststring); ajStrDel(&reststring); return NULL; } /* Read row labels */ while(ajReadline(file,&buffer)) { ptr = ajStrGetPtr(buffer); #ifndef WIN32 if(*ptr != '#' && *ptr != '\n') #else if(*ptr != '#' && *ptr != '\n' && *ptr != '\r') #endif { if(first) first = ajFalse; else { ajFmtScanC(ptr, "%S", &firststring); ajListPushAppend(rlabel_list, firststring); firststring = ajStrNew(); } } } first = ajTrue; ajStrDel(&firststring); rows = ajListToarray(rlabel_list, (void ***) &rlabel_arr); ajFileSeek(file, 0, 0); while(ajReadline(file,&buffer)) { ajStrRemoveWhiteExcess(&buffer); ptr = ajStrGetPtr(buffer); if(*ptr && *ptr != '#') { if(first) { cols = ajStrParseCountC(buffer,delimstr); AJCNEW0(orderstring, cols); for(i=0; i<cols; i++) orderstring[i] = ajStrNew(); tok = ajStrParseC(buffer, " :\t\n"); ajStrAssignS(&orderstring[l++], tok); while((tok = ajStrParseC(NULL, " :\t\n"))) ajStrAssignS(&orderstring[l++], tok); first = ajFalse; ret = ajMatrixfNewAsym(orderstring, cols, rlabel_arr, rows, filename); matrix = ret->Matrixf; } else { ajFmtScanC(ptr, "%S", &firststring); /* JISON 19/7/4 k = ajSeqcvtGetCodeK(ret->Cvt, ajStrGetCharFirst(firststring)); */ k = ajSeqcvtGetCodeS(ret->Cvt, firststring); len = MAJSTRGETLEN(firststring); ajStrAssignSubC(&reststring, ptr, len, -1); /* ** Must discard the first string (label) and use ** reststring otherwise ajArrFloatLine would fail (it ** cannot convert a string to a float) ** ** Use cols,1,cols in below because although 2nd and ** subsequent lines have one more string in them (the ** residue label in the 1st column) we've discarded that ** from the string that's passed */ templine = ajArrFloatLine(reststring,delimstr,1,cols); for(i=0; i<cols; i++) { if(templine[i] < minval) minval = templine[i]; /* JISON 19/7/4 matrix[k][ajSeqcvtGetCodeK(ret->Cvt, ajStrGetCharFirst(orderstring[i]))] = templine[i]; */ matrix[k][ajSeqcvtGetCodeAsymS(ret->Cvt, orderstring[i])] = templine[i]; } AJFREE(templine); } } } ajDebug("fill rest with minimum value %d\n", minval); ajFileClose(&file); ajStrDel(&buffer); for(i=0; i<cols; i++) ajStrDel(&orderstring[i]); AJFREE(orderstring); ajDebug("read matrix file %S\n", filename); ajStrDel(&firststring); ajStrDel(&reststring); for(i=0; i<rows; i++) ajStrDel(&rlabel_arr[i]); AJFREE(rlabel_arr); ajListFree(&rlabel_list); return ret; }