void ajMessErrorCode(const char *code) { char *mess = 0; if(messErrorTable) { mess = ajTableFetch(messErrorTable, code); if(mess) ajErr(mess); else ajErr("could not find error code %s",code); } else { if(ajMessReadErrorFile()) { mess = ajTableFetch(messErrorTable, code); if(mess) ajErr(mess); else ajErr("could not find error code %s",code); } else ajErr("Could not read the error file, " "hence no reference to %s", code); } return; }
ajint ajRegOffsetI(const AjPRegexp rp, ajint isub) { if(isub < 0) ajErr("Invalid substring number %d", isub); if(isub >= (rp->ovecsize)) ajErr("Invalid substring number %d", isub); return (rp->ovector[isub*2]); }
AjPRegexp ajRegCompC(const char* rexp) { AjPRegexp ret; int options = 0; int errpos = 0; const char *errptr = NULL; const unsigned char *tableptr = NULL; AJNEW0(ret); AJCNEW0(ret->ovector, AJREG_OVECSIZE); ret->ovecsize = AJREG_OVECSIZE/3; ret->pcre = pcre_compile(rexp, options, &errptr, &errpos, tableptr); if(!ret->pcre) { ajErr("Failed to compile regular expression '%s' at position %d: %s", rexp, errpos, errptr); AJFREE(ret); return NULL; } regAlloc += sizeof(ret); regCount ++; regTotal ++; /*ajDebug("ajRegCompC %x size %d regexp '%s'\n", ret, (int) sizeof(ret), rexp);*/ return ret; }
AjBool ajAssemoutformatFind(const AjPStr format, ajint* iformat) { AjPStr tmpformat = NULL; ajuint i = 0; /* ajDebug("ajAssemoutformatFind '%S'\n", format); */ if(!ajStrGetLen(format)) return ajFalse; ajStrAssignS(&tmpformat, format); ajStrFmtLower(&tmpformat); for(i=0; assemoutFormatDef[i].Name; i++) { /* ajDebug("test %d '%s' \n", i, assemoutFormatDef[i].Name); */ if(ajStrMatchCaseC(tmpformat, assemoutFormatDef[i].Name)) { *iformat = i; ajStrDel(&tmpformat); /* ajDebug("found '%s' at %d\n", assemoutFormatDef[i].Name, i); */ return ajTrue; } } ajErr("Unknown output format '%S'", format); ajStrDel(&tmpformat); *iformat = 0; return ajFalse; }
static size_t dbiblast_memfseek(PMemFile mf, ajlong offset, ajint whence) { if(mf->IsMem) { /* memory mapped */ switch(whence) { case 0: mf->Pos = offset; break; case 1: mf->Pos += offset; break; case 2: mf->Pos = mf->Size + offset; break; default: ajErr("invalid memfseek code %d", whence); embExitBad(); } if(mf->Pos > mf->Size) mf->Pos = mf->Size; if(mf->Pos < 0) mf->Pos = 0; return 0; } return ajFileSeek( mf->File, offset, whence); }
AjBool ajSoapAxis2Error(axiom_node_t *fault, const axutil_env_t *env) { axis2_char_t* faultcode = NULL; axis2_char_t* faultmsg = NULL; axis2_char_t* exception = NULL; axiom_element_t* parent = NULL; axiom_element_t* child = NULL; axiom_node_t* node = NULL; axutil_qname_t* qname = NULL; parent = axiom_node_get_data_element(fault, env); if (!parent) return ajFalse; /* fault->faultcode */ qname = axutil_qname_create(env, "faultcode", NULL, ""); child = axiom_element_get_first_child_with_qname(parent, env, qname, fault, &node); if (child) faultcode = axiom_element_get_text(child, env, node); axutil_qname_free(qname, env); /* fault->faultstring */ qname = axutil_qname_create(env, "faultstring", NULL, ""); child = axiom_element_get_first_child_with_qname(parent, env, qname, fault, &node); if (child) faultmsg = axiom_element_get_text(child, env, node); axutil_qname_free(qname, env); /* fault->detail */ qname = axutil_qname_create(env, "detail", NULL, ""); parent = axiom_element_get_first_child_with_qname(parent, env, qname, fault, &node); axutil_qname_free(qname, env); if(!parent) return ajFalse; /* fault->detail->exceptionName */ qname = axutil_qname_create(env, "exceptionName", AXIS_NS , ""); child = axiom_element_get_first_child_with_qname(parent, env, qname, node, &node); if(child) exception = axiom_element_get_text(child, env, node); if(!strstr(exception, "DbfNoEntryFoundException")) ajErr("webservices error: %s, %s %s", faultcode, faultmsg, exception); axutil_qname_free(qname, env); return ajTrue; }
static AjBool ajMessReadErrorFile(void) { char line[512]; char name[12]; char message[200]; FILE *fp=0; char *mess; char *cp; char *namestore; char *messstore; if(messErrorFile) fp = fopen(messErrorFile,"r"); if(!fp) { messErrorFile = ajFmtString("%s/messages/messages.english", getenv("EMBOSS_ROOT")); fp = fopen(messErrorFile,"r"); } if(!fp) return ajFalse; messErrorTable = ajTablecharNew(); while(fgets(line, 512, fp)) { if(sscanf(line,"%s %s",name,message)!=2) ajFatal("Library sscanf1"); cp = strchr(line,'"'); cp++; mess = &message[0]; while(*cp != '"') { *mess = *cp; cp++; mess++; } *mess = '\0'; namestore = ajFmtString("%s",name); messstore = ajFmtString("%s",message); mess = (char *) ajTableFetch(messErrorTable, namestore); if(mess) ajErr("%s is listed more than once in file %s", name,messErrorFile); else ajTablePut(messErrorTable, namestore, messstore); } return ajTrue; }
int main(int argc, char **argv) { AjPSeqall seqall; AjPSeq seq = NULL; AjPFile primerFile; /* read the primer pairs from a file */ AjPFile outf; AjPList primerList; ajint mmp = 0; embInit("primersearch", argc, argv); seqall = ajAcdGetSeqall("seqall"); outf = ajAcdGetOutfile("outfile"); primerFile = ajAcdGetInfile("infile"); mmp = ajAcdGetInt("mismatchpercent"); /* build list of forward/reverse primer pairs as read from primerfile */ primerList = ajListNew(); /* read in primers from primerfile, classify and compile them */ primersearch_read_primers(&primerList,primerFile, mmp); /* check there are primers to be searched */ if(!ajListGetLength(primerList)) { ajErr("No suitable primers found - exiting"); embExitBad(); return 0; } /* query sequences one by one */ while(ajSeqallNext(seqall,&seq)) primersearch_primer_search(primerList, seq); /* output the results */ primersearch_print_hits(primerList, outf); /* delete all nodes of list, then the list itself */ ajListMap(primerList, primersearch_free_primer, NULL); ajListFree(&primerList); ajListFree(&primerList); ajFileClose(&outf); ajSeqallDel(&seqall); ajSeqDel(&seq); ajFileClose(&primerFile); embExit(); return 0; }
void ajHistSetmultiYlabelC(AjPHist thys, ajuint indexnum, const char *txt) { if(indexnum >= thys->numofdatapoints) { ajErr("Histograms can only be allocated from 0 to %d. NOT %u", thys->numofdatapoints-1,indexnum); return; } ajStrAssignC(&thys->hists[indexnum]->yaxis,txt); return; }
void ajHistSetmultiXlabelS(AjPHist thys, ajuint indexnum, const AjPStr str) { if(indexnum >= thys->numofdatapoints) { ajErr("Histograms can only be allocated from 0 to %d. NOT %u", thys->numofdatapoints-1,indexnum); return; } ajStrAssignS(&thys->hists[indexnum]->xaxis, str); return; }
static void remap_GetFrames(AjPStr const *framelist, AjBool *frames) { int i; /* reset the vector */ for(i=0; i<6; i++) frames[i] = ajFalse; for(i=0; framelist[i]; i++) { if(ajStrMatchC(framelist[i], "1")) frames[0] = ajTrue; else if(ajStrMatchC(framelist[i], "2")) frames[1] = ajTrue; else if(ajStrMatchC(framelist[i], "3")) frames[2] = ajTrue; else if(ajStrMatchC(framelist[i], "-1")) frames[3] = ajTrue; else if(ajStrMatchC(framelist[i], "-2")) frames[4] = ajTrue; else if(ajStrMatchC(framelist[i], "-3")) frames[5] = ajTrue; else if(ajStrMatchC(framelist[i], "F")) { frames[0] = ajTrue; frames[1] = ajTrue; frames[2] = ajTrue; } else if(ajStrMatchC(framelist[i], "R")) { frames[3] = ajTrue; frames[4] = ajTrue; frames[5] = ajTrue; } else if(ajStrMatchC(framelist[i], "6")) { frames[0] = ajTrue; frames[1] = ajTrue; frames[2] = ajTrue; frames[3] = ajTrue; frames[4] = ajTrue; frames[5] = ajTrue; } else ajErr("Unknown frame: '%S'", framelist[i]); } return; }
void ajHistSetmultiColour(AjPHist thys, ajuint indexnum, ajint colour) { if(indexnum >= thys->numofdatapoints) { ajErr("Histograms can only be allocated from 0 to %d. NOT %u", thys->numofdatapoints-1,indexnum); return; } thys->hists[indexnum]->colour = colour; return; }
void ajHistSetmultiPattern(AjPHist thys, ajuint indexnum, ajint style) { if(indexnum >= thys->numofdatapoints) { ajErr("Histograms can only be allocated from 0 to %d. NOT %u", thys->numofdatapoints-1,indexnum); return; } thys->hists[indexnum]->pattern = style; return; }
axis2_svc_client_t* ajSoapAxis2GetClient(const axutil_env_t *env, const axis2_char_t *address) { AjPStr home = NULL; axis2_endpoint_ref_t* endpoint_ref = NULL; axis2_options_t* options = NULL; axis2_svc_client_t* svc_client = NULL; options = axis2_options_create(env); endpoint_ref = axis2_endpoint_ref_create(env, address); axis2_options_set_soap_version(options, env, AXIOM_SOAP11); axis2_options_set_to(options, env, endpoint_ref); /* Set up axis2c location. ** This is either from: ** EMBOSS_AXIS2C_HOME: Used by mEMBOSS as axis2c files are ** provided by the setup and there could ** be confusion with an existing axis2c ** installation otherwise. ** axis2C_HOME: The location specified during the ** EMBOSS configuration. ** ** The client uses this information to pick up the ** libraries, modules and axis2.xml file */ if(!ajNamGetValueC("AXIS2C_HOME",&home)) home = ajStrNewC(axis2C_HOME); /* Create service client */ svc_client = axis2_svc_client_create(env, ajStrGetPtr(home)); if (!svc_client) { ajErr("Error creating webservice client: %s", AXIS2_ERROR_GET_MESSAGE(env->error)); return NULL; } axis2_svc_client_set_options(svc_client, env, options); axis2_svc_client_engage_module(svc_client, env, AXIS2_MODULE_ADDRESSING); ajStrDel(&home); return svc_client; }
static ajuint patternRegexFormat(const AjPStr fmt) { ajuint i = 0; if(!ajStrGetLen(fmt)) return 0; while (patRegInformat[i].Name) { if(ajStrMatchCaseC(fmt, patRegInformat[i].Name)) return i; i++; } ajErr("Unrecognized regular expression file format '%S'",fmt); return 0; }
void ajHistDataAdd(AjPHist thys, ajuint indexnum, PLFLT *data) { if(indexnum >= thys->numofdatapoints) { ajErr("Histograms can only be allocated from 0 to %d. NOT %u", thys->numofdatapoints-1,indexnum); return; } if(!thys->hists[indexnum]->data) thys->numofsets++; thys->hists[indexnum]->data = data; return; }
axiom_node_t* ajSoapAxis2Call(axis2_svc_client_t *client, const axutil_env_t *env, axiom_node_t *payload) { axiom_node_t *ret_node = NULL; axis2_char_t * om_str = NULL; if (ajDebugOn()) { om_str = axiom_node_to_string(payload, env); if (om_str) { ajDebug("\nSending OM : %s\n", om_str); AXIS2_FREE(env->allocator, om_str); om_str = NULL; } } /* Send request */ ret_node = axis2_svc_client_send_receive(client, env, payload); if (ret_node) { if(ajDebugOn()) { om_str = axiom_node_to_string(ret_node, env); if (om_str) ajDebug("\nReceived OM : %s\n", om_str); AXIS2_FREE(env->allocator, om_str); om_str = NULL; } } else { ajDebug("seqAxis2wsCall: webservice call failed: %s\n", AXIS2_ERROR_GET_MESSAGE(env->error)); ajErr("webservice call FAILED: %s\n", AXIS2_ERROR_GET_MESSAGE(env->error)); } return ret_node; }
static ajuint patternSeqFormat(const AjPStr fmt) { ajuint i = 0; if(!ajStrGetLen(fmt)) return 0; while (patSeqInformat[i].Name) { if(ajStrMatchCaseC(fmt, patSeqInformat[i].Name)) return i; i++; } ajErr("Unrecognized pattern file format '%S'",fmt); return 0; }
void ajHistDataCopy(AjPHist thys, ajuint indexnum, PLFLT const *srcdata) { ajuint i; if(indexnum >= thys->numofdatapoints) { ajErr("Histograms can only be allocated from 0 to %d. NOT %u", thys->numofdatapoints-1,indexnum); return; } thys->hists[indexnum]->data = AJALLOC(thys->numofdatapoints*sizeof(PLFLT)); for(i=0; i < thys->numofdatapoints; i++) thys->hists[indexnum]->data[i] = srcdata[i]; thys->hists[indexnum]->deletedata = AJTRUE; thys->numofsets++; return; }
int main(int argc, char **argv) { /* Variable declarations */ AjPOutfile outfile = NULL; AjPTaxall taxall = NULL; AjPTax tax = NULL; AjPTax taxtest = NULL; AjPList taxlist = ajListNew(); AjPTable foundtable = NULL; ajuint ifound = 0; ajuint ikeep = 0; /* ACD processing */ embInit("taxgetspecies", argc, argv); taxall = ajAcdGetTaxonall("taxons"); outfile = ajAcdGetOuttaxon("outfile"); foundtable = ajTablestrNew(600); while(ajTaxallNext(taxall, &tax)) { ajListPushAppend(taxlist, ajTaxNewTax(tax)); ajTaxGetTree(tax, taxlist); while(ajListGetLength(taxlist)) { ajListPop(taxlist, (void**) &taxtest); if(!ajStrMatchC(ajTaxGetRank(taxtest), "species")) { ajTaxDel(&taxtest); continue; } ifound++; if(!ajTableMatchS(foundtable, taxtest->Id)) { ajTaxoutWrite(outfile, taxtest); ajTablePut(foundtable, ajStrNewS(taxtest->Id), (void *) 1); ikeep++; } ajTaxDel(&taxtest); } } if(!ifound) ajErr("No matching terms"); /* Memory clean-up and exit */ ajListFree(&taxlist); ajTaxallDel(&taxall); ajTaxDel(&tax); ajOutfileClose(&outfile); ajTablestrFreeKey(&foundtable); embExit(); return 0; }
static AjBool assemoutWriteNextMaf(AjPOutfile outfile, const AjPAssem assem) { AjPFile outf = ajOutfileGetFile(outfile); AjPAssemContig c = NULL; AjPAssemRead r = NULL; AjPAssemTag t = NULL; ajint i = 0; ajint nreads = 0; AjIList j = NULL; AjIList k = NULL; AjIList reads = NULL; AjPAssemContig* contigs = NULL; if(!outf) return ajFalse; if(!assem) return ajFalse; if(!assem->Hasdata) { ajTableToarrayValues(assem->Contigs, (void***)&contigs); for (;contigs[i];i++) { c = contigs[i]; ajFmtPrintF(outf, "CO\t%S\n", c->Name); ajFmtPrintF(outf, "NR\t%d\n", c->Nreads); ajFmtPrintF(outf, "LC\t%d\n", c->Length); j = ajListIterNewread(c->Tags); while (!ajListIterDone(j)) { t = ajListIterGet(j); ajFmtPrintF(outf, "CT\t%S %u %u %S\n", t->Name, t->x1, t->y1, t->Comment); } ajListIterDel(&j); ajFmtPrintF(outf, "CS\t%S\n", c->Consensus); ajFmtPrintF(outf, "CQ\t%S\n", c->ConsensusQ); ajFmtPrintF(outf, "\\\\\n"); } AJFREE(contigs); return ajTrue; } /* data */ reads = ajListIterNewread(assem->Reads); while (!ajListIterDone(reads)) { nreads++; r = ajListIterGet(reads); if(r->Reference !=i) ajErr("different reference/contig number(%d) than expected(%d)" "\nreads were expected to be sorted by contigs"); ajFmtPrintF(outf, "RD\t%S\n", r->Name); ajFmtPrintF(outf, "RS\t%S\n", r->Seq); ajFmtPrintF(outf, "RQ\t%S\n", r->SeqQ); ajFmtPrintF(outf, "TN\t%S\n", r->Template); if(r->Direction) ajFmtPrintF(outf, "DI\t%c\n", r->Direction); if(r->TemplateSizeMin) ajFmtPrintF(outf, "TF\t%d\n", r->TemplateSizeMin); if(r->TemplateSizeMax) ajFmtPrintF(outf, "TT\t%d\n", r->TemplateSizeMax); if(r->File) ajFmtPrintF(outf, "SF\t%S\n", r->File); if(r->VectorLeft) ajFmtPrintF(outf, "SL\t%d\n", r->VectorLeft); if(r->VectorRight) ajFmtPrintF(outf, "SR\t%d\n", r->VectorRight); if(r->QualLeft) ajFmtPrintF(outf, "QL\t%d\n", r->QualLeft); if(r->QualRight) ajFmtPrintF(outf, "QR\t%d\n", r->QualRight); if(r->ClipLeft) ajFmtPrintF(outf, "SL\t%d\n", r->ClipLeft); if(r->ClipRight) ajFmtPrintF(outf, "SR\t%d\n", r->ClipRight); k = ajListIterNewread(r->Tags); while (!ajListIterDone(k)) { t = ajListIterGet(k); ajFmtPrintF(outf, "RT\t%S %u %u\n", t->Name, t->x1, t->y1); } ajListIterDel(&k); ajFmtPrintF(outf, "ST\t%S\n", r->Technology); ajFmtPrintF(outf, "ER\n"); ajFmtPrintF(outf, "AT\t%u %u %u %u\n", r->x1, r->y1, r->x2, r->y2); } ajListIterDel(&j); ajListIterDel(&reads); if(!nreads) { ajFmtPrintF(outf, "//\n"); ajFmtPrintF(outf, "EC\n"); } return ajTrue; }
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; }
ajint ajUserGet(AjPStr* pthis, const char* fmt, ...) { AjPStr thys; const char *cp; char *buff; va_list args; ajint ipos; ajint isize; ajint ilen; ajint jlen; ajint fileBuffSize = ajFileValueBuffsize(); va_start(args, fmt); ajFmtVError(fmt, args); va_end(args); if(ajFileValueRedirectStdin()) { ajUser("(Standard input in use: using default)"); ajStrAssignC(pthis, ""); return ajStrGetLen(*pthis); } ajStrSetRes(pthis, fileBuffSize); buff = ajStrGetuniquePtr(pthis); thys = *pthis; isize = ajStrGetRes(thys); ilen = 0; ipos = 0; /*ajDebug("ajUserGet buffer len: %d res: %d ptr: %x\n", ajStrGetLen(thys), ajStrGetRes(thys), thys->Ptr);*/ while(buff) { #ifndef __ppc__ cp = fgets(&buff[ipos], isize, stdin); #else cp = ajSysFuncFgets(&buff[ipos], isize, stdin); #endif if(!cp && !ipos) { if(feof(stdin)) { ajErr("Unable to get reply from user - end of standard input"); ajExitBad(); } else ajFatal("Error reading from user: '******'\n", strerror(errno)); } jlen = strlen(&buff[ipos]); ilen += jlen; /* ** We need to read again if: ** We have read the entire buffer ** and we don't have a newline at the end ** (must be careful about that - we may just have read enough) */ ajStrSetValidLen(pthis, ilen); thys = *pthis; if((jlen == (isize-1)) && (ajStrGetCharLast(thys) != '\n')) { ajStrSetRes(pthis, ajStrGetRes(thys)+fileBuffSize); thys = *pthis; /*ajDebug("more to do: jlen: %d ipos: %d isize: %d ilen: %d " "Size: %d\n", jlen, ipos, isize, ilen, ajStrGetRes(thys));*/ ipos += jlen; buff = ajStrGetuniquePtr(pthis); isize = ajStrGetRes(thys) - ipos; /* ajDebug("expand to: ipos: %d isize: %d Size: %d\n", ipos, isize, ajStrGetRes(thys)); */ } else buff = NULL; } ajStrSetValidLen(pthis, ilen); if(ajStrGetCharLast(*pthis) == '\n') ajStrCutEnd(pthis, 1); /* PC files have \r\n Macintosh files have just \r : this fixes both */ if(ajStrGetCharLast(*pthis) == '\r') { /*ajDebug("Remove carriage-return characters from PC-style files\n");*/ ajStrCutEnd(pthis, 1); } ajStrTrimWhite(pthis); return ajStrGetLen(*pthis); }
int main(int argc, char **argv) { /* Variable declarations */ AjPOutfile outfile = NULL; AjPOboall oboall = NULL; AjBool subclasses = ajFalse; AjBool obsolete = ajFalse; AjPObo obo = NULL; AjPObo obotest = NULL; AjPList obolist = ajListNew(); AjPTable foundtable = NULL; ajuint ifound = 0; ajuint ikeep = 0; /* ACD processing */ embInit("ontoget", argc, argv); oboall = ajAcdGetOboall("oboterms"); outfile = ajAcdGetOutobo("outfile"); subclasses = ajAcdGetBoolean("subclasses"); obsolete = ajAcdGetBoolean("obsolete"); foundtable = ajTablestrNew(600); while(ajOboallNext(oboall, &obo)) { ajListPushAppend(obolist, ajOboNewObo(obo)); if(subclasses) ajOboGetTree(obo, obolist); while(ajListGetLength(obolist)) { ajListPop(obolist, (void**) &obotest); if(!obsolete && ajOboIsObsolete(obotest)) { ajOboDel(&obotest); continue; } ifound++; if(!ajTableMatchS(foundtable, obotest->Id)) { ajObooutWrite(outfile, obotest); ajTablePut(foundtable, ajStrNewS(obotest->Id), (void *) 1); ikeep++; } ajOboDel(&obotest); } } if(!ifound) ajErr("No matching terms"); /* Memory clean-up and exit */ ajListFree(&obolist); ajOboallDel(&oboall); ajOboDel(&obo); ajOutfileClose(&outfile); ajTablestrFreeKey(&foundtable); embExit(); return 0; }
AjPPatlistRegex ajPatlistRegexRead (const AjPStr patspec, const AjPStr patname, const AjPStr fmt, ajuint type, AjBool upper, AjBool lower) { AjPPatlistRegex patlist = NULL; AjPStr line = NULL; AjPStr pat = NULL; AjPStr name = NULL; AjPFilebuff infile = NULL; AjPStr patstr = NULL; ajuint ifmt; ajuint npat = 0; AjPStr namestr = NULL; ajStrAssignS(&namestr, patname); ajStrAssignEmptyC(&namestr, "regex"); ajStrAssignS(&patstr, patspec); patlist = ajPatlistRegexNewType(type); ifmt = patternRegexFormat(fmt); if(ajStrGetCharFirst(patspec) == '@') { ajStrCutStart(&patstr, 1); infile = ajFilebuffNewNameS(patstr); if(!infile) { ajErr("Unable to open regular expression file '%S'", patstr); return NULL; } line = ajStrNew(); pat = ajStrNew(); name = ajStrNew(); if(!ifmt) { ajBuffreadLineTrim(infile,&line); if(ajStrPrefixC(line, ">")) ifmt = 2; else ifmt = 1; ajFilebuffReset(infile); } switch(ifmt) { case 1: while (ajBuffreadLineTrim(infile,&line)) { npat++; ajStrAppendS (&pat,line); if(lower) ajStrFmtLower(&pat); if(upper) ajStrFmtUpper(&pat); ajFmtPrintS(&name, "%S%u", namestr, npat); ajPatternRegexNewList(patlist,name,pat); ajStrSetClear(&pat); } break; default: while (ajBuffreadLineTrim(infile,&line)) { if (ajStrFindC(line,">")>-1) { npat++; if (ajStrGetLen(name)) { if(lower) ajStrFmtLower(&pat); if(upper) ajStrFmtUpper(&pat); ajPatternRegexNewList(patlist,name,pat); ajStrSetClear(&name); ajStrSetClear(&pat); } ajStrCutStart(&line,1); ajStrAssignS (&name,line); if(!ajStrGetLen(name)) ajFmtPrintS(&name, "%S%u", namestr, npat); } else ajStrAppendS (&pat,line); } ajStrAssignEmptyS(&name, patname); ajPatternRegexNewList(patlist,name,pat); ajStrSetClear(&pat); break; } ajFilebuffDel(&infile); } else { ajStrAssignS(&pat, patspec); if(lower) ajStrFmtLower(&pat); if(upper) ajStrFmtUpper(&pat); ajStrAssignS(&name, namestr); ajPatternRegexNewList(patlist,name,pat); } ajStrDel(&name); ajStrDel(&namestr); ajStrDel(&patstr); ajStrDel(&line); ajStrDel(&pat); return patlist; }
void ajHistDisplay(const AjPHist thys) { PLFLT *data = NULL; /* points to data in hist */ PLFLT *totals = NULL; PLFLT *totals2 = NULL; float ptsperbin; float max = FLT_MIN; float min = 0.0; ajuint i; ajuint j; ajint ratioint; ajint num; ajint old; float bin_range; float bar_width; float offset; float start; float tot; float percent5; /* Sanity check */ if(thys->numofdatapoints < 1 || thys->numofsets < 1 || thys->bins < 1) { ajErr("points =%d, sets = %d, bins = %d !!! " "Must all be Greater than 1 ", thys->numofdatapoints,thys->numofsets,thys->bins); return; } /* what multiple is the bins to numofdatasets */ /* as i may have to take an average if not identical */ ptsperbin = (float)thys->numofdatapoints/(float)thys->bins; if(ptsperbin < 1.0) { ajErr("You cannot more have bins than datapoints!!"); return; } /* is the ratio a whole number? */ ratioint = (ajint)ptsperbin; if((ptsperbin - (float)ratioint) != 0.0) { ajErr("number of data points needs to be a multiple of bins"); return; } /* end Sanity check */ /* Add spacing either side */ percent5 = (thys->xmax - thys->xmin)*(float)0.025; /* calculate max and min for each set */ if(thys->numofsets != 1) { /* if NOT side by side max and min as the sets added together */ if(thys->displaytype == HIST_SIDEBYSIDE) { /* find the max value */ max = INT_MIN; min = 0; for(j=0; j < thys->numofsets; j++) { data = thys->hists[j]->data; for(i=0;i<thys->numofdatapoints;i++) { if(data[i] > max) max = data[i]; if(data[i] < min) min = data[i]; } } } else if(thys->displaytype == HIST_ONTOP) { totals = AJALLOC(thys->numofdatapoints*(sizeof(PLFLT))); /* set all memory to 0.0 */ for(i=0;i<thys->numofdatapoints;i++) { totals[i] = 0.0; } min = 0; max = 0; for(j=0; j < thys->numofsets; j++) { data = thys->hists[j]->data; for(i=0;i<thys->numofdatapoints;i++) { totals[i] += data[i]; if(totals[i] > max) max = totals[i]; if(totals[i] < min) min = totals[i]; /* ajDebug("%d %d\t%f",j,i,totals[i]);*/ } } } else if(thys->displaytype == HIST_SEPARATE) { totals = AJALLOC(thys->numofsets*(sizeof(PLFLT))); totals2 = AJALLOC(thys->numofsets*(sizeof(PLFLT))); for(j=0; j < thys->numofsets; j++) { data = thys->hists[j]->data; totals[j] = 0; totals2[j] = 0; for(i=0;i<thys->numofdatapoints;i++) { if(totals[j] < data[i]) totals[j] = data[i]; if(totals2[j] > data[i]) totals2[j] = data[i]; } } } } else { data = thys->hists[0]->data; max = data[0]; min = 0; for(i=1; i < thys->numofdatapoints; i++) { if(data[i] > max) max = data[i]; if(data[i] < min) min = data[i]; } if(thys->displaytype == HIST_ONTOP /*!thys->sidebyside*/) { totals = AJALLOC(thys->numofdatapoints*(sizeof(PLFLT))); /* set all memory to 0.0 */ for(i=0; i < thys->numofdatapoints; i++) totals[i] = 0.0; } else if(thys->displaytype == HIST_SEPARATE) { totals = AJALLOC((sizeof(PLFLT))); totals[0]= max; totals2 = AJALLOC((sizeof(PLFLT))); totals2[0]= min; } } bin_range = (thys->xmax - thys->xmin)/(float)thys->bins; if(thys->displaytype != HIST_SEPARATE) { if(max <= 0.01) { if(max < 0.0) max = 0.0; else max = 1.0; } ajGraphOpenPlotset(thys->graph, 1); ajGraphicsPlenv(thys->xmin-percent5, thys->xmax+percent5, min, max*((float)1.025), aj_hist_mark); ajGraphicsSetLabelsS(thys->xaxis , thys->yaxisleft , thys->title, thys->subtitle); ajGraphicsSetRlabelS(thys->yaxisright); } else ajGraphOpenPlotset(thys->graph, thys->numofsets); if(thys->displaytype == HIST_SIDEBYSIDE) { bar_width = bin_range/thys->numofsets; for(i=0; i < thys->numofsets; i++) { offset = i*bar_width; start = thys->xmin; num = 0; tot=0.0; data = thys->hists[i]->data; for(j=0; j < thys->numofdatapoints; j++) { tot += data[j]; num++; if(num >= ptsperbin) { tot = tot / (float)num; if(thys->BaW) old = ajGraphicsSetFillpat(thys->hists[i]->pattern); else old = ajGraphicsSetFgcolour(thys->hists[i]->colour); ajGraphicsDrawposRectFill(start+offset,0.0, start+offset+bar_width,tot); if(thys->BaW) ajGraphicsSetFillpat(old); else ajGraphicsSetFgcolour(old); ajGraphicsDrawposRect(start+offset,0.0, start+offset+bar_width,tot); num = 0; tot = 0; start +=bin_range; } } } } else if(thys->displaytype == HIST_SEPARATE) { bar_width = bin_range; for(i=0; i < thys->numofsets; i++) { if(totals[i] <= 0.01) { /* apparently the ymin value */ if(totals[i] < 0.0) totals[i] = 0.0; else totals[i] = 1.0; } ajGraphicsPlenv(thys->xmin - percent5, thys->xmax + percent5, totals2[i]*((float)1.025), totals[i]*((float)1.025), aj_hist_mark); offset = /*bar_width*/0.0; start = thys->xmin; num = 0; tot=0.0; data = thys->hists[i]->data; ajGraphicsSetLabelsS(thys->hists[i]->xaxis, thys->hists[i]->yaxis, thys->hists[i]->title, thys->hists[i]->subtitle); for(j=0; j < thys->numofdatapoints; j++) { tot += data[j]; num++; if(num >= ptsperbin) { tot = tot / (float)num; if(thys->BaW) old = ajGraphicsSetFillpat(thys->hists[i]->pattern); else old = ajGraphicsSetFgcolour(thys->hists[i]->colour); ajGraphicsDrawposRectFill(start+offset,0.0, start+offset+bar_width,tot); if(thys->BaW) ajGraphicsSetFillpat(old); else ajGraphicsSetFgcolour(old); ajGraphicsDrawposRect(start+offset,0.0, start+offset+bar_width,tot); num = 0; tot = 0; start +=bin_range; } } } } else if(thys->displaytype == HIST_ONTOP) { for(i=0; i < thys->numofdatapoints; i++) totals[i] = 0.0; for(i=0; i < thys->numofsets; i++) { data = thys->hists[i]->data; start = thys->xmin; num = 0; tot=0.0; for(j=0; j < thys->numofdatapoints; j++) { tot += data[j]; num++; if(num >= ptsperbin) { tot = tot / (float)num; if(thys->BaW) old = ajGraphicsSetFillpat(thys->hists[i]->pattern); else old = ajGraphicsSetFgcolour(thys->hists[i]->colour); ajGraphicsDrawposRectFill(start,totals[j], start+bin_range,tot+totals[j]); if(thys->BaW) ajGraphicsSetFillpat(old); else ajGraphicsSetFgcolour(old); ajGraphicsDrawposRect(start,totals[j], start+bin_range,tot+totals[j]); totals[j] += tot; tot = 0; /* ajDebug("num = %d",num);*/ num = 0; start +=bin_range; } } } } AJFREE(totals); AJFREE(totals2); return; }
int main(int argc, char **argv) { AjPSeqall nucseq; /* input nucleic sequences */ AjPSeqset protseq; /* input aligned protein sequences */ AjPSeqout seqout; AjPSeq nseq; /* next nucleic sequence to align */ const AjPSeq pseq; /* next protein sequence use in alignment */ AjPTrn trnTable; AjPSeq pep; /* translation of nseq */ AjPStr tablelist; ajint table; AjPSeqset outseqset; /* set of aligned nucleic sequences */ ajint proteinseqcount = 0; AjPStr degapstr = NULL; /* used to check if it matches with START removed */ AjPStr degapstr2 = NULL; AjPStr codon = NULL; /* holds temporary codon to check if is START */ char aa; /* translated putative START codon */ ajint type; /* returned type of the putative START codon */ /* start position of guide protein in translation */ ajlong pos = 0; AjPSeq newseq = NULL; /* output aligned nucleic sequence */ ajint frame; embInit("tranalign", argc, argv); nucseq = ajAcdGetSeqall("asequence"); protseq = ajAcdGetSeqset("bsequence"); tablelist = ajAcdGetListSingle("table"); seqout = ajAcdGetSeqoutset("outseq"); outseqset = ajSeqsetNew(); degapstr = ajStrNew(); /* initialise the translation table */ ajStrToInt(tablelist, &table); trnTable = ajTrnNewI(table); ajSeqsetFill(protseq); while(ajSeqallNext(nucseq, &nseq)) { if((pseq = ajSeqsetGetseqSeq(protseq, proteinseqcount++)) == NULL) ajErr("No guide protein sequence available for " "nucleic sequence %S", ajSeqGetNameS(nseq)); ajDebug("Aligning %S and %S\n", ajSeqGetNameS(nseq), ajSeqGetNameS(pseq)); /* get copy of pseq string with no gaps */ ajStrAssignS(°apstr, ajSeqGetSeqS(pseq)); ajStrRemoveGap(°apstr); /* ** for each translation frame look for subset of pep that ** matches pseq */ for(frame = 1; frame <4; frame++) { ajDebug("trying frame %d\n", frame); pep = ajTrnSeqOrig(trnTable, nseq, frame); degapstr2 = ajStrNew(); ajStrAssignRef(°apstr2, degapstr); pos = ajStrFindCaseS(ajSeqGetSeqS(pep), degapstr); /* ** we might have a START codon that should be translated as 'M' ** we need to check if there is a match after a possible START ** codon */ if(pos == -1 && ajStrGetLen(degapstr) > 1 && (ajStrGetPtr(degapstr)[0] == 'M' || ajStrGetPtr(degapstr)[0] == 'm')) { /* see if pep minus the first character is a match */ ajStrCutStart(°apstr2, 1); pos = ajStrFindCaseS(ajSeqGetSeqS(pep), degapstr2); /* ** pos is >= 1 if we have a match that is after the first ** residue */ if(pos >= 1) { /* point back at the putative START Methionine */ pos--; /* test if first codon is a START */ codon = ajStrNew(); ajStrAssignSubS(&codon, ajSeqGetSeqS(nseq), (pos*3)+frame-1, (pos*3)+frame+2); type = ajTrnCodonstrTypeS(trnTable, codon, &aa); if(type != 1) { /* first codon is not a valid START, force a mismatch */ pos = -1; } ajStrDel(&codon); } else { /* force 'pos == 0' to be treated as a mismatch */ pos = -1; } } ajStrDel(°apstr2); ajSeqDel(&pep); if(pos != -1) break; } if(pos == -1) ajErr("Guide protein sequence %S not found in nucleic sequence %S", ajSeqGetNameS(pseq), ajSeqGetNameS(nseq)); else { ajDebug("got a match with frame=%d\n", frame); /* extract the coding region of nseq with gaps */ newseq = ajSeqNew(); ajSeqSetNuc(newseq); ajSeqAssignNameS(newseq, ajSeqGetNameS(nseq)); ajSeqAssignDescS(newseq, ajSeqGetDescS(nseq)); tranalign_AddGaps(newseq, nseq, pseq, (pos*3)+frame-1); /* output the gapped nucleic sequence */ ajSeqsetApp(outseqset, newseq); ajSeqDel(&newseq); } ajStrRemoveWhiteExcess(°apstr); } ajSeqoutWriteSet(seqout, outseqset); ajSeqoutClose(seqout); ajTrnDel(&trnTable); ajSeqsetDel(&outseqset); ajStrDel(°apstr); ajStrDel(°apstr2); ajSeqallDel(&nucseq); ajSeqDel(&nseq); ajSeqoutDel(&seqout); ajSeqsetDel(&protseq); ajStrDel(&tablelist); embExit(); return 0; }
int main(int argc, char **argv) { AjPSeqall seq1; AjPSeqset seq2; AjPSeq a; const AjPSeq b; AjPStr m = 0; AjPStr n = 0; AjPFile errorf; AjBool show = ajFalse; ajint lena = 0; ajint lenb = 0; const char *p; const char *q; AjPMatrixf matrix; AjPSeqCvt cvt = 0; float **sub; ajint *compass = NULL; float *path = NULL; float gapopen; float gapextend; float score; ajint begina; ajint i; ajuint k; ajint beginb; ajint start1 = 0; ajint start2 = 0; ajint end1 = 0; ajint end2 = 0; ajint width = 0; AjPTable seq1MatchTable = 0; ajint wordlen = 6; ajint oldmax = 0; AjPAlign align = NULL; embInit("supermatcher", argc, argv); matrix = ajAcdGetMatrixf("datafile"); seq1 = ajAcdGetSeqall("asequence"); seq2 = ajAcdGetSeqset("bsequence"); gapopen = ajAcdGetFloat("gapopen"); gapextend = ajAcdGetFloat("gapextend"); wordlen = ajAcdGetInt("wordlen"); align = ajAcdGetAlign("outfile"); errorf = ajAcdGetOutfile("errorfile"); width = ajAcdGetInt("width"); /* not the same as awidth */ gapopen = ajRoundFloat(gapopen, 8); gapextend = ajRoundFloat(gapextend, 8); sub = ajMatrixfGetMatrix(matrix); cvt = ajMatrixfGetCvt(matrix); embWordLength(wordlen); ajSeqsetTrim(seq2); while(ajSeqallNext(seq1,&a)) { ajSeqTrim(a); begina = 1 + ajSeqGetOffset(a); m = ajStrNewRes(1+ajSeqGetLen(a)); lena = ajSeqGetLen(a); ajDebug("Read '%S'\n", ajSeqGetNameS(a)); if(!embWordGetTable(&seq1MatchTable, a)) /* get table of words */ ajErr("Could not generate table for %s\n", ajSeqGetNameC(a)); for(k=0;k<ajSeqsetGetSize(seq2);k++) { b = ajSeqsetGetseqSeq(seq2, k); lenb = ajSeqGetLen(b); beginb = 1 + ajSeqGetOffset(b); ajDebug("Processing '%S'\n", ajSeqGetNameS(b)); p = ajSeqGetSeqC(a); q = ajSeqGetSeqC(b); if(!supermatcher_findstartpoints(seq1MatchTable,b,a, &start1, &start2, &end1, &end2)) { ajFmtPrintF(errorf, "No wordmatch start points for " "%s vs %s. No alignment\n", ajSeqGetNameC(a),ajSeqGetNameC(b)); continue; } n=ajStrNewRes(1+ajSeqGetLen(b)); ajStrAssignC(&m,""); ajStrAssignC(&n,""); ajDebug("++ %S v %S start:%d %d end:%d %d\n", ajSeqGetNameS(a), ajSeqGetNameS(b), start1, start2, end1, end2); if(end1-start1+1 > oldmax) { oldmax = ((end1-start1)+1); AJRESIZE(path,oldmax*width*sizeof(float)); AJRESIZE(compass,oldmax*width*sizeof(ajint)); ajDebug("++ resize to oldmax: %d\n", oldmax); } for(i=0;i<((end1-start1)+1)*width;i++) path[i] = 0.0; ajDebug("Calling embAlignPathCalcFast " "%d..%d [%d/%d] %d..%d [%d/%d]\n", start1, end1, (end1 - start1 + 1), lena, start2, end2, (end2 - start2 + 1), lenb); score = embAlignPathCalcSWFast(&p[start1],&q[start2], end1-start1+1,end2-start2+1, 0,width, gapopen,gapextend, path,sub,cvt, compass,show); embAlignWalkSWMatrixFast(path,compass,gapopen,gapextend,a,b, &m,&n,end1-start1+1,end2-start2+1, 0,width, &start1,&start2); if(!ajAlignFormatShowsSequences(align)) { ajAlignDefineCC(align, ajStrGetPtr(m), ajStrGetPtr(n), ajSeqGetNameC(a), ajSeqGetNameC(b)); ajAlignSetScoreR(align, score); } else { embAlignReportLocal(align, a, b, m,n,start1,start2, gapopen, gapextend, score,matrix, begina, beginb); } ajAlignWrite(align); ajAlignReset(align); ajStrDel(&n); } embWordFreeTable(&seq1MatchTable); /* free table of words */ seq1MatchTable=0; ajStrDel(&m); } if(!ajAlignFormatShowsSequences(align)) { ajMatrixfDel(&matrix); } AJFREE(path); AJFREE(compass); ajAlignClose(align); ajAlignDel(&align); ajSeqallDel(&seq1); ajSeqDel(&a); ajSeqsetDel(&seq2); ajFileClose(&errorf); embExit(); return 0; }
AjPPatlistSeq ajPatlistSeqRead (const AjPStr patspec, const AjPStr patname, const AjPStr fmt, AjBool protein, ajuint mismatches) { AjPPatlistSeq patlist = NULL; AjPStr line = NULL; AjPStr name = NULL; AjPFilebuff infile = NULL; AjPRegexp mismreg = NULL; AjPStr patstr = NULL; AjPStr pat = NULL; ajuint mismatch = 0; ajint ifmt = 0; ajuint npat = 0; AjPStr namestr = NULL; ajStrAssignS(&namestr, patname); ajStrAssignEmptyC(&namestr, "pattern"); ajStrAssignS(&patstr, patspec); patlist = ajPatlistSeqNewType(protein); ifmt = patternSeqFormat(fmt); ajDebug("ajPatlistSeqRead patspec: '%S' patname: '%S' " "protein: %B mismatches: %d\n", patspec, patname, protein, mismatches); if(ajStrGetCharFirst(patstr) == '@') { ajStrCutStart(&patstr, 1); infile = ajFilebuffNewNameS(patstr); if(!infile) { ajErr("Unable to open pattern file '%S'", patstr); return NULL; } line = ajStrNew(); name = ajStrNew(); if(!ifmt) { ajBuffreadLineTrim(infile,&line); if(ajStrPrefixC(line, ">")) ifmt = 2; else ifmt = 1; ajFilebuffReset(infile); } switch(ifmt) { case 1: while (ajBuffreadLineTrim(infile,&line)) { npat++; ajStrAppendS (&pat,line); ajFmtPrintS(&name, "%S%u", namestr, npat); ajPatternSeqNewList(patlist,name,pat,mismatches); ajStrSetClear(&pat); } break; default: mismreg = ajRegCompC("<mismatch=(\\d+)>"); while (ajBuffreadLineTrim(infile,&line)) { if (ajStrGetCharFirst(line) == '>') { if (ajStrGetLen(name)) { ajPatternSeqNewList(patlist,name,pat, mismatch); ajStrSetClear(&name); ajStrSetClear(&pat); mismatch=mismatches; } ajStrCutStart(&line,1); if (ajRegExec(mismreg,line)) { ajRegSubI(mismreg,1,&name); ajStrToUint(name,&mismatch); ajStrTruncateLen(&line,ajRegOffset(mismreg)); ajStrTrimWhiteEnd(&line); } ajStrAssignS (&name,line); ajStrAssignEmptyS(&name, patname); } else ajStrAppendS (&pat,line); } ajStrAssignEmptyS(&name, patname); ajPatternSeqNewList(patlist,name,pat,mismatch); ajRegFree(&mismreg); break; } ajFilebuffDel(&infile); } else { ajStrAssignS(&name, namestr); ajPatternSeqNewList(patlist,name,patstr,mismatches); } ajStrDel(&name); ajStrDel(&line); ajStrDel(&pat); ajStrDel(&namestr); ajStrDel(&patstr); return patlist; }
static AjBool assemoutWriteSamAlignment(AjPFile outf, const AjPAssemRead r, AjPAssemContig const * contigs, ajint ncontigs) { AjPAssemTag t = NULL; AjIList l = NULL; AjPStr qualstr = NULL; AjPStr tmp = NULL; ajint POS = 0; AjPStr CIGAR = NULL; const char* RNEXT = NULL; AjPStr SEQ = NULL; AjPStr QUAL = NULL; AjPStr SEQunpadded = NULL; AjPStr QUALunpadded = NULL; AjPStr consensus = NULL; AjBool rc= ajFalse; AjBool ret = ajTrue; const char* refseq = NULL; const AjPAssemContig contig = NULL; ajuint k = 0; if(r->Reference>=ncontigs) ajDie("assemoutWriteSamAlignment: reference sequence number" " '%d' is larger than or equal to known number of reference" " sequences '%d'. Problem while processing read '%S'.", r->Reference, ncontigs, r->Name); contig = (r->Reference==-1 ? NULL : contigs[r->Reference]); ajStrAssignRef(&SEQ, r->Seq); consensus = contig==NULL? NULL : contig->Consensus; if (r->Rnext==-1) RNEXT= "*"; else if(r->Rnext==r->Reference) RNEXT = "="; else RNEXT = ajStrGetPtr(contigs[r->Rnext]->Name); if (r->Flag & BAM_FREVERSE) { rc = ajTrue; qualstr = ajStrNewS(r->SeqQ); if(!r->Reversed) { ajStrReverse(&qualstr); ajSeqstrReverse(&SEQ); } QUAL = qualstr; POS = r->y1; ajStrAssignSubS(&tmp, SEQ, ajStrGetLen(r->Seq) - r->y2, ajStrGetLen(r->Seq) - r->x2 ); } else { rc= ajFalse; POS = r->x1; QUAL = r->SeqQ; ajStrAssignSubS(&tmp, SEQ, r->x2-1, r->y2-1 ); } if(r->Cigar==NULL && consensus) { refseq = ajStrGetPtr(consensus) + (rc ? r->y1-1 : r->x1-1); CIGAR = assemoutMakeCigar(refseq, ajStrGetPtr(tmp)); SEQunpadded = ajStrNewRes(ajStrGetLen(SEQ)); QUALunpadded = ajStrNewRes(ajStrGetLen(SEQ)); for(k=0; k< ajStrGetLen(SEQ); k++) { if (ajStrGetCharPos(SEQ, k) == '*') continue; ajStrAppendK(&SEQunpadded, ajStrGetCharPos(SEQ, k)); ajStrAppendK(&QUALunpadded, ajStrGetCharPos(QUAL, k)); } ajDebug("cigar: %S\n", CIGAR); ajStrAssignS(&tmp, CIGAR); if(rc) { if(r->y2 < (ajint)ajStrGetLen(SEQ)) ajFmtPrintS(&CIGAR, "%dS%S", ajStrGetLen(SEQ) - r->y2, tmp); if(r->x2 > 1) ajFmtPrintAppS(&CIGAR, "%dS", r->x2 - 1); } else { if(r->x2 > 1) ajFmtPrintS(&CIGAR, "%dS%S", r->x2 - 1, tmp); if(r->y2 < (ajint)ajStrGetLen(SEQ)) ajFmtPrintAppS(&CIGAR, "%dS", ajStrGetLen(SEQ) - r->y2); } ajStrDel(&tmp); } else if(r->Cigar==NULL) { ajErr("both CIGAR string and consensus sequence not available"); ret = ajFalse; ajStrAssignK(&CIGAR, '*'); } else if(!ajStrGetLen(r->Cigar)) ajStrAssignK(&CIGAR, '*'); else if(ajStrGetLen(r->Cigar)) { if(!ajStrGetLen(SEQ)) ajStrAssignK(&SEQ, '*'); if(!ajStrGetLen(QUAL)) ajStrAssignK(&QUAL, '*'); } ajStrDel(&tmp); ajFmtPrintF(outf, "%S\t%d\t%s\t%d\t%d\t%S\t%s\t%Ld\t%d\t%S\t%S", r->Name, r->Flag, (contig==NULL ? "*" : ajStrGetPtr(contig->Name)), POS, r->MapQ, (CIGAR ? CIGAR : r->Cigar), RNEXT, r->Pnext, r->Tlen, (r->Cigar ? SEQ : SEQunpadded), (r->Cigar ? QUAL : QUALunpadded)); l = ajListIterNewread(r->Tags); while (!ajListIterDone(l)) { t = ajListIterGet(l); /* TODO: array type, 'B' */ /* In SAM, all single integer types are mapped to int32_t [SAM spec] */ ajFmtPrintF(outf, "\t%S:%c:", t->Name, (t->type == 'c' || t->type == 'C' || t->type == 's' || t->type == 'S' || t->type == 'I') ? 'i' : t->type ); if(t->x1 || t->y1) ajFmtPrintF(outf, " %u %u", t->x1, t->y1); if(t->Comment && ajStrGetLen(t->Comment)>0) ajFmtPrintF(outf, "%S", t->Comment); } ajListIterDel(&l); ajFmtPrintF(outf, "\n"); if(qualstr) ajStrDel(&qualstr); ajStrDel(&SEQ); ajStrDel(&CIGAR); ajStrDel(&SEQunpadded); ajStrDel(&QUALunpadded); return ret; }