/* @source cpgplot application ** ** Plots CpG island areas ** ** @author Copyright (C) Alan Bleasby (ableasby@hgmp.mrc.ac.uk) ** @@ ** ** This program is free software; you can redistribute it and/or ** modify it under the terms of the GNU General Public License ** as published by the Free Software Foundation; either version 2 ** of the License, or (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ******************************************************************************/ #include "emboss.h" #include #include static void cpgplot_findbases(const AjPStr substr, ajint len, ajint window, ajint shift, float *obsexp, float *xypc, const AjPStr bases, float *obsexpmax, ajint *plotstart, ajint *plotend); static void cpgplot_countbases(const char *seq, const char *bases, ajint window, float *cx, float *cy, float *cxpy); static void cpgplot_identify(AjPFile outf, const float *obsexp, const float *xypc, AjBool *thresh, ajint begin, ajint len, ajint shift, const char *bases, const char *name, ajint minlen, float minobsexp, float minpc, AjPFeattabOut featout); static void cpgplot_reportislands(AjPFile outf, const AjBool *thresh, const char *bases, const char *name, float minobsexp, float minpc, ajint minlen, ajint begin, ajint len); static void cpgplot_plotit(const char *seq, ajint begin, ajint len, const float *obsexp, const float *xypc, const AjBool *thresh, float obsexpmax, AjBool doobsexp, AjBool docg, AjBool dopc, AjPGraph mult); static void cpgplot_dumpfeatout(AjPFeattabOut featout, const AjBool *thresh, const char *seqname, ajint begin, ajint len); /* @prog cpgplot ************************************************************** ** ** Plot CpG rich areas ** ******************************************************************************/ int main(int argc, char **argv) { AjPSeqall seqall; AjPSeq seq = NULL; AjPFile outf = NULL; AjPStr strand = NULL; AjPStr substr = NULL; AjPStr bases = NULL; AjPGraph mult; AjBool doobsexp; AjBool dopc; AjBool docg; ajint begin; ajint end; ajint len; ajint minlen; float minobsexp; float minpc; AjBool doplot; ajint window; ajint shift; ajint plotstart; ajint plotend; float *xypc = NULL; float *obsexp = NULL; AjBool *thresh = NULL; float obsexpmax; ajint i; ajint maxarr; AjPFeattabOut featout = NULL; embInit("cpgplot",argc,argv); seqall = ajAcdGetSeqall("sequence"); window = ajAcdGetInt("window"); shift = 1; /* other values broken - needs rewrite to fix*/ outf = ajAcdGetOutfile("outfile"); minobsexp = ajAcdGetFloat("minoe"); minlen = ajAcdGetInt("minlen"); minpc = ajAcdGetFloat("minpc"); doplot = ajAcdGetToggle("plot"); mult = ajAcdGetGraphxy ("graph"); doobsexp = ajAcdGetBoolean("obsexp"); docg = ajAcdGetBoolean("cg"); dopc = ajAcdGetBoolean("pc"); featout = ajAcdGetFeatout("outfeat"); substr = ajStrNew(); bases = ajStrNewC("CG"); maxarr = 0; while(ajSeqallNext(seqall, &seq)) { begin = ajSeqallGetseqBegin(seqall); end = ajSeqallGetseqEnd(seqall); strand = ajSeqGetSeqCopyS(seq); ajStrFmtUpper(&strand); ajStrAssignSubC(&substr,ajStrGetPtr(strand),--begin,--end); len = ajStrGetLen(substr); if(len > maxarr) { AJCRESIZE(obsexp,len); AJCRESIZE(thresh,len); AJCRESIZE(xypc,len); } for(i=0;i obsexp[j]) ? *obsexpmax : obsexp[j]; } xypc[j] = (cxf/windowf)*(float)100.0 + (cyf/windowf)*(float)100.0; } *plotend = j; return; } /* @funcstatic cpgplot_countbases ********************************************* ** ** Undocumented. ** ** @param [r] seq [const char*] Undocumented ** @param [r] bases [const char*] Undocumented ** @param [r] window [ajint] Undocumented ** @param [w] cx [float*] Undocumented ** @param [w] cy [float*] Undocumented ** @param [w] cxpy [float*] Undocumented ** @@ ******************************************************************************/ static void cpgplot_countbases(const char *seq, const char *bases, ajint window, float *cx, float *cy, float *cxpy) { ajint i; ajint codex; ajint codey; ajint codea; ajint codeb; *cxpy = *cx = *cy = 0.; codex = ajBaseAlphaToBin(bases[0]); codey = ajBaseAlphaToBin(bases[1]); codeb = ajBaseAlphaToBin(seq[0]); for(i=0; iminobsexp)&&(avpc>minpc)) { if(!sumlen) first = pos; /* start a new island */ sumlen += shift; ajDebug(" ** hit first: %d sumlen: %d\n", first, sumlen); } else { if(sumlen >= minlen) /* island long enough? */ for(i=first; i<=pos-shift;++i) thresh[i] = ajTrue; sumlen=0; } } if(sumlen>=minlen) for(i=first;i %.2f\n",minobsexp); ajFmtPrintF(outf," Percent %c + Percent %c > %.2f\n",bases[0], bases[1],minpc); ajFmtPrintF(outf," Length > %d\n",minlen); island = ajFalse; for(i=0;iobsexp[i]) ? max : obsexp[i]; } ajGraphdataSetMinmax(tmGraph2,(float)begin,(float)begin+len-1, min,max); ajGraphdataSetTruescale(tmGraph2,(float)begin,(float)begin+len-1, 0.0,max); ajGraphdataSetTypeC(tmGraph2,"Multi 2D Plot"); ajGraphxySetXstartF(graphs,(float)begin); ajGraphxySetXendF(graphs,(float)(begin+len-1)); ajGraphxySetYstartF(graphs,0.0); ajGraphxySetYendF(graphs,obsexpmax); ajGraphxySetXrangeII(graphs,begin,begin+len-1); ajGraphxySetYrangeII(graphs,0,(ajint)(obsexpmax+1.0)); ajGraphdataCalcXY(tmGraph2,len,(float)begin,1.0,obsexp); ajGraphDataReplaceI(graphs,tmGraph2,igraph++); tmGraph2 = NULL; } if(dopc) { tmGraph3 = ajGraphdataNew(); ajGraphdataSetTitleC(tmGraph3,"Percentage"); ajGraphdataSetXlabelC(tmGraph3,"Base number"); ajGraphdataSetYlabelC(tmGraph3,"Percentage"); min = 64000.; max = -64000.; for(i=0;ixypc[i]) ? max : xypc[i]; } ajGraphdataSetMinmax(tmGraph3,(float)begin,(float)begin+len-1, min,max); ajGraphdataSetTruescale(tmGraph3,(float)begin,(float)begin+len-1, 0.0,max); ajGraphdataSetTypeC(tmGraph3,"Multi 2D Plot"); ajGraphxySetXstartF(graphs,(float)begin); ajGraphxySetXendF(graphs,(float)(begin+len-1)); ajGraphxySetYstartF(graphs,0); ajGraphxySetYendF(graphs,100); ajGraphxySetXrangeII(graphs,begin,begin+len-1); ajGraphxySetYrangeII(graphs,0,100); ajGraphdataCalcXY(tmGraph3,len,(float)begin,1.0,xypc); ajGraphDataReplaceI(graphs,tmGraph3,igraph++); tmGraph3 = NULL; } if(docg) { AJCNEW (tmp, len); for(i=0;i