Exemplo n.º 1
0
static void dotmatcher_pushpoint(AjPList *l, float x1, float y1, float x2,
				 float y2, AjBool stretch)
{
    PPoint p;

    if(!stretch)
    {
	ajGraphicsDrawposLine(x1+1,y1+1,x2+1,y2+1);
	return;
    }

    AJNEW0(p);
    p->x1 = x1+1;
    p->y1 = y1+1;
    p->x2 = x2+1;
    p->y2 = y2+1;
    ajListPush(*l,(void *)p);

    return;
}
Exemplo n.º 2
0
static void pepnet_drawocta(float x, float y, float size)
{
    static float polyx[]=
    {
	(float)-0.05, (float)0.05, (float)0.1, (float)0.1, (float)0.05,
	(float)-0.05, (float)-0.1, (float)-0.1, (float)-0.05
    };
    static float polyy[]=
    {
	(float)0.1, (float)0.1, (float)0.05, (float)-0.05, (float)-0.1,
	(float)-0.1, (float)-0.05, (float)0.05, (float)0.1
    };

    ajint i;

    for(i=0;i<8;++i)
	ajGraphicsDrawposLine(x+polyx[i]*size,y+polyy[i]*size,x+polyx[i+1]*size,
                              y+polyy[i+1]*size);

    return;
}
Exemplo n.º 3
0
static void dottup_drawPlotlines(void *x, void *cl)
{
    EmbPWordMatch p;
    PLFLT x1;
    PLFLT y1;
    PLFLT x2;
    PLFLT y2;

    (void) cl;				/* make it used */

    p  = (EmbPWordMatch)x;

    x1 = x2 = offset1 + (PLFLT)(p->seq1start);
    y1 = y2 = offset2 + (PLFLT)(p->seq2start);

    x2 += (PLFLT)p->length - (PLFLT)1.0;
    y2 += (PLFLT)p->length - (PLFLT)1.0;

    ajGraphicsDrawposLine(x1, y1, x2, y2);

    return;
}
Exemplo n.º 4
0
static void polydot_drawPlotlines(void *x, void *cl)
{
    EmbPWordMatch p;
    PLFLT x1;
    PLFLT y1;
    PLFLT x2;
    PLFLT y2;

    (void) cl;				/*make it used */

    p = (EmbPWordMatch)x;

    lines[which]++;
    pts[which]+= p->length;
    x1 = x2 = (p->seq1start)+xstart;
    y1 = y2 = (PLFLT)(p->seq2start)+ystart;
    x2 += p->length;
    y2 += (PLFLT)p->length;

    ajGraphicsDrawposLine(x1, y1, x2, y2);

    return;
}
Exemplo n.º 5
0
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,&currentheight);
	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,&currentheight);

	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;
}
Exemplo n.º 6
0
int main(int argc, char **argv)
{
    AjPList list = NULL;
    AjPSeq seq;
    AjPSeq seq2;
    AjPStr aa0str = 0;
    AjPStr aa1str = 0;
    const char *s1;
    const char *s2;
    char *strret = NULL;
    ajuint i;
    ajuint j;
    ajuint k;
    ajint l;
    ajint abovethresh;
    ajint total;
    ajint starti = 0;
    ajint startj = 0;
    ajint windowsize;
    float thresh;
    AjPGraph graph   = NULL;
    AjPGraph xygraph = NULL;
    float flen1;
    float flen2;
    ajuint len1;
    ajuint len2;

    AjPTime ajtime = NULL;
    time_t tim;
    AjBool boxit=AJTRUE;
    /* Different ticks as they need to be different for x and y due to
       length of string being important on x */
    ajuint acceptableticksx[]=
    {
	1,10,50,100,500,1000,1500,10000,
	500000,1000000,5000000
    };
    ajuint acceptableticks[]=
    {
	1,10,50,100,200,500,1000,2000,5000,10000,15000,
	500000,1000000,5000000
    };
    ajint numbofticks = 10;
    float xmargin;
    float ymargin;
    float ticklen;
    float tickgap;
    float onefifth;
    float k2;
    float max;
    char ptr[10];
    AjPMatrix matrix = NULL;
    ajint** sub;
    AjPSeqCvt cvt;
    AjPStr  subt = NULL;

    ajint b1;
    ajint b2;
    ajint e1;
    ajint e2;
    AjPStr se1;
    AjPStr se2;
    ajint ithresh;
    AjBool stretch;
    PPoint ppt = NULL;
    float xa[1];
    float ya[1];
    AjPGraphdata gdata=NULL;
    AjPStr tit   = NULL;
    AjIList iter = NULL;
    float x1 = 0.;
    float x2 = 0.;
    float y1 = 0.;
    float y2 = 0.;
    ajuint tui;
    
    se1 = ajStrNew();
    se2 = ajStrNew();

    embInit("dotmatcher", argc, argv);
    
    seq        = ajAcdGetSeq("asequence");
    seq2       = ajAcdGetSeq("bsequence");
    stretch    = ajAcdGetToggle("stretch");
    graph      = ajAcdGetGraph("graph");
    xygraph    = ajAcdGetGraphxy("xygraph");
    windowsize = ajAcdGetInt("windowsize");
    ithresh    = ajAcdGetInt("threshold");
    matrix     = ajAcdGetMatrix("matrixfile");
    
    sub = ajMatrixGetMatrix(matrix);
    cvt = ajMatrixGetCvt(matrix);
    
    thresh = (float)ithresh;

    ajtime = ajTimeNew();

    tim = time(0);
    ajTimeSetLocal(ajtime, tim);
    
    b1 = ajSeqGetBegin(seq);
    b2 = ajSeqGetBegin(seq2);
    e1 = ajSeqGetEnd(seq);
    e2 = ajSeqGetEnd(seq2);
    len1 = ajSeqGetLen(seq);
    len2 = ajSeqGetLen(seq2);
    tui   = ajSeqGetLen(seq);
    flen1 = (float) tui;
    tui   = ajSeqGetLen(seq2);
    flen2 = (float) tui;
    
    ajStrAssignSubC(&se1,ajSeqGetSeqC(seq),b1-1,e1-1);
    ajStrAssignSubC(&se2,ajSeqGetSeqC(seq2),b2-1,e2-1);
    ajSeqAssignSeqS(seq,se1);
    ajSeqAssignSeqS(seq2,se2);
    
    
    s1 = ajStrGetPtr(ajSeqGetSeqS(seq));
    s2 = ajStrGetPtr(ajSeqGetSeqS(seq2));
    
    
    aa0str = ajStrNewRes(1+len1); /* length plus trailing blank */
    aa1str = ajStrNewRes(1+len2);
    
    list = ajListNew();
    
    
    for(i=0;i<len1;i++)
	ajStrAppendK(&aa0str,(char)ajSeqcvtGetCodeK(cvt, *s1++));
    
    for(i=0;i<len2;i++)
	ajStrAppendK(&aa1str,(char)ajSeqcvtGetCodeK(cvt, *s2++));
    
    max = (float)len1;
    if(len2 > max)
	max = (float) len2;
    
    xmargin = ymargin = max *(float)0.15;
    ticklen = xmargin*(float)0.1;
    onefifth  = xmargin*(float)0.2;
    
    subt = ajStrNewC((strret=
		      ajFmtString("(windowsize = %d, threshold = %3.2f  %D)",
				  windowsize,thresh,ajtime)));
    
    

    if(!stretch)
    {
	if( ajStrGetLen(ajGraphGetSubtitleS(graph)) <=1)
	    ajGraphSetSubtitleS(graph,subt);

	ajGraphOpenWin(graph, (float)0.0-ymargin,(max*(float)1.35)+ymargin,
		       (float)0.0-xmargin,(float)max+xmargin);

	ajGraphicsDrawposTextAtmid(flen1*(float)0.5,
                                   (float)0.0-(xmargin/(float)2.0),
		       ajGraphGetXlabelC(graph));
	ajGraphicsDrawposTextAtlineJustify((float)0.0-(xmargin*(float)0.75),
                                           flen2*(float)0.5,
			(float)0.0-(xmargin*(float)0.75),flen1,
			ajGraphGetYlabelC(graph),0.5);

	ajGraphicsSetCharscale(0.5);
    }
    
    
    
    s1= ajStrGetPtr(aa0str);
    s2 = ajStrGetPtr(aa1str);
    
    for(j=0; (ajint)j < (ajint)len2-windowsize;j++)
    {
	i =0;
	total = 0;
	abovethresh =0;

	k = j;
	for(l=0;l<windowsize;l++)
	    total = total + sub[(ajint)s1[i++]][(ajint)s2[k++]];

	if(total >= thresh)
	{
	    abovethresh=1;
	    starti = i-windowsize;
	    startj = k-windowsize;
	}

	while(i < len1 && k < len2)
	{
	    total = total - sub[(ajint)s1[i-windowsize]]
		[(ajint)s2[k-windowsize]];
	    total = total + sub[(ajint)s1[i]][(ajint)s2[k]];

	    if(abovethresh)
	    {
		if(total < thresh)
		{
		    abovethresh = 0;
		    /* draw the line */
		    dotmatcher_pushpoint(&list,(float)starti,(float)startj,
					 (float)i-1,(float)k-1,stretch);
		}
	    }
	    else if(total >= thresh)
	    {
		starti = i-windowsize;
		startj = k-windowsize;
		abovethresh= 1;
	    }
	    i++;
	    k++;
	}

	if(abovethresh)
	    /* draw the line */
	    dotmatcher_pushpoint(&list,(float)starti,(float)startj,
				 (float)i-1,(float)k-1,
				 stretch);
    }
    
    for(i=0; (ajint)i < (ajint)len1-windowsize;i++)
    {
	j = 0;
	total = 0;
	abovethresh =0;

	k = i;
	for(l=0;l<windowsize;l++)
	    total = total + sub[(ajint)s1[k++]][(ajint)s2[j++]];

	if(total >= thresh)
	{
	    abovethresh=1;
	    starti = k-windowsize;
	    startj = j-windowsize;
	}

	while(k < len1 && j < len2)
	{
	    total = total - sub[(ajint)s1[k-windowsize]]
		[(ajint)s2[j-windowsize]];
	    total = total + sub[(ajint)s1[k]][(ajint)s2[j]];

	    if(abovethresh)
	    {
		if(total < thresh)
		{
		    abovethresh = 0;
		    /* draw the line */
		    dotmatcher_pushpoint(&list,(float)starti,(float)startj,
					 (float)k-1,(float)j-1,stretch);
		}
	    }
	    else if(total >= thresh)
	    {
		starti = k-windowsize;
		startj = j-windowsize;
		abovethresh= 1;
	    }
	    j++;
	    k++;
	}

	if(abovethresh)
	    /* draw the line */
	    dotmatcher_pushpoint(&list,(float)starti,(float)startj,
				 (float)k-1,(float)j-1,
				 stretch);
    }
    
    if(boxit && !stretch)
    {
	ajGraphicsDrawposRect(0.0,0.0,flen1, flen2);

	i=0;
	while(acceptableticksx[i]*numbofticks < len1)
	    i++;

	if(i<=13)
	    tickgap = (float)acceptableticksx[i];
	else
	    tickgap = (float)acceptableticksx[10];
	ticklen   = xmargin*(float)0.1;
	onefifth  = xmargin*(float)0.2;

	if(len2/len1 > 10 )
	{
	    /* if a lot smaller then just label start and end */
	    ajGraphicsDrawposLine((float)0.0,(float)0.0,(float)0.0,(float)0.0-ticklen);
	    sprintf(ptr,"%d",b1-1);
	    ajGraphicsDrawposTextAtmid((float)0.0,(float)0.0-(onefifth),ptr);

	    ajGraphicsDrawposLine(flen1,(float)0.0,
			flen1,(float)0.0-ticklen);
	    sprintf(ptr,"%d",len1+b1-1);
	    ajGraphicsDrawposTextAtmid(flen1,(float)0.0-(onefifth),ptr);

	}
	else
	    for(k2=0.0;k2<len1;k2+=tickgap)
	    {
		ajGraphicsDrawposLine(k2,(float)0.0,k2,(float)0.0-ticklen);
		sprintf(ptr,"%d",(ajint)k2+b1-1);
		ajGraphicsDrawposTextAtmid(k2,(float)0.0-(onefifth),ptr);
	    }

	i = 0;
	while(acceptableticks[i]*numbofticks < len2)
	    i++;

	tickgap   = (float)acceptableticks[i];
	ticklen   = ymargin*(float)0.01;
	onefifth  = ymargin*(float)0.02;

	if(len1/len2 > 10 )
	{
	    /* if a lot smaller then just label start and end */
	    ajGraphicsDrawposLine((float)0.0,(float)0.0,(float)0.0-ticklen,(float)0.0);
	    sprintf(ptr,"%d",b2-1);
	    ajGraphicsDrawposTextAtend((float)0.0-(onefifth),(float)0.0,ptr);

	    ajGraphicsDrawposLine((float)0.0,flen2,(float)0.0-ticklen,
			flen2);
	    sprintf(ptr,"%d",len2+b2-1);
	    ajGraphicsDrawposTextAtend((float)0.0-(onefifth),flen2,ptr);
	}
	else
	    for(k2=0.0;k2<len2;k2+=tickgap)
	    {
		ajGraphicsDrawposLine((float)0.0,k2,(float)0.0-ticklen,k2);
		sprintf(ptr,"%d",(ajint)k2+b2-1);
		ajGraphicsDrawposTextAtend((float)0.0-(onefifth),k2,ptr);
	    }
    }
    
    
    if(!stretch)
	ajGraphicsClose();
    else			/* the xy graph for -stretch */
    {
	tit = ajStrNew();
	ajFmtPrintS(&tit,"%S",ajGraphGetTitleS(xygraph));


	gdata = ajGraphdataNewI(1);
	xa[0] = (float)b1;
	ya[0] = (float)b2;

	ajGraphSetTitleC(xygraph,ajStrGetPtr(tit));

	ajGraphSetXlabelC(xygraph,ajSeqGetNameC(seq));
	ajGraphSetYlabelC(xygraph,ajSeqGetNameC(seq2));

	ajGraphdataSetTypeC(gdata,"2D Plot Float");
	ajGraphdataSetTitleS(gdata,subt);
	ajGraphdataSetMinmax(gdata,(float)b1,(float)e1,(float)b2,
			       (float)e2);
	ajGraphdataSetTruescale(gdata,(float)b1,(float)e1,(float)b2,
			       (float)e2);
	ajGraphxySetXstartF(xygraph,(float)b1);
	ajGraphxySetXendF(xygraph,(float)e1);
	ajGraphxySetYstartF(xygraph,(float)b2);
	ajGraphxySetYendF(xygraph,(float)e2);

	ajGraphxySetXrangeII(xygraph,b1,e1);
	ajGraphxySetYrangeII(xygraph,b2,e2);


	if(list)
	{
	    iter = ajListIterNewread(list);
	    while((ppt = ajListIterGet(iter)))
	    {
		x1 = ppt->x1+b1-1;
		y1 = ppt->y1+b2-1;
		x2 = ppt->x2+b1-1;
		y2 = ppt->y2+b2-1;
		ajGraphAddLine(xygraph,x1,y1,x2,y2,0);
		AJFREE(ppt);
	    }
	    ajListIterDel(&iter);
	}

	ajGraphdataAddXY(gdata,xa,ya);
	ajGraphDataReplace(xygraph,gdata);


	ajGraphxyDisplay(xygraph,ajFalse);
	ajGraphicsClose();

	ajStrDel(&tit);
    }
    
    
    
    ajListFree(&list);

    ajSeqDel(&seq);
    ajSeqDel(&seq2);
    ajGraphxyDel(&graph);
    ajGraphxyDel(&xygraph);
    ajMatrixDel(&matrix);
    ajTimeDel(&ajtime);
    
    /* deallocate memory */
    ajStrDel(&aa0str);
    ajStrDel(&aa1str);
    ajStrDel(&se1);
    ajStrDel(&se2);
    ajStrDel(&subt);

    AJFREE(strret);			/* created withing ajFmtString */
    
    embExit();

    return 0;
}
Exemplo n.º 7
0
int main(int argc, char **argv)
{
    AjPSeq seq1;
    AjPSeq seq2;
    ajint wordlen;
    AjPTable seq1MatchTable = 0;
    AjPList matchlist = NULL;
    AjPGraph graph    = NULL;
    AjPGraph xygraph  = NULL;
    AjBool boxit;
    /*
    ** Different ticks as they need to be different for x and y due to
    ** length of string being important on x
    */
    ajuint acceptableticksx[]=
    {
	1,10,50,100,500,1000,1500,10000,
	500000,1000000,5000000
    };
    ajuint acceptableticks[]=
    {
	1,10,50,100,200,500,1000,2000,5000,10000,15000,
	500000,1000000,5000000
    };
    ajint numbofticks = 10;
    float xmargin;
    float ymargin;
    float ticklen;
    float tickgap;
    float onefifth = 0.0;
    ajint i;
    float k;
    float max;
    char ptr[10];
    ajint begin1;
    ajint begin2;
    ajint end1;
    ajint end2;
    ajuint len1;
    ajuint len2;
    float fbegin1;
    float fbegin2;
    float fend1;
    float fend2;
    float flen1;
    float flen2;
    AjBool stretch;
    
    embInit("dottup", argc, argv);

    wordlen = ajAcdGetInt("wordsize");
    seq1    = ajAcdGetSeq("asequence");
    seq2    = ajAcdGetSeq("bsequence");
    graph   = ajAcdGetGraph("graph");
    boxit   = ajAcdGetBoolean("boxit");
    stretch = ajAcdGetToggle("stretch");
    xygraph = ajAcdGetGraphxy("xygraph");

    begin1 = ajSeqGetBegin(seq1);
    begin2 = ajSeqGetBegin(seq2);
    end1   = ajSeqGetEnd(seq1);
    end2   = ajSeqGetEnd(seq2);
    len1   = end1 - begin1 + 1;
    len2   = end2 - begin2 + 1;

    flen1  = (float) len1;
    flen2  = (float) len2;
    fbegin1 = (float) begin1;
    fbegin2 = (float) begin2;
    fend1   = (float) end1;
    fend2   = (float) end2;

    offset1 = fbegin1;
    offset2 = fbegin2;

    ajSeqTrim(seq1);
    ajSeqTrim(seq2);

    embWordLength(wordlen);
    if(embWordGetTable(&seq1MatchTable, seq1))
	matchlist = embWordBuildMatchTable(seq1MatchTable, seq2, ajTrue);


    if(stretch)
    {
	dottup_stretchplot(xygraph,matchlist,seq1,seq2,begin1,begin2,end1,
			   end2);
	if(matchlist)
	    embWordMatchListDelete(&matchlist); /* free the match structures */
    }

    else
    {
	/* only here if stretch is false */

	max= flen1;
	if(flen2 > max)
	    max = flen2;

	xmargin = ymargin = max * (float)0.15;

	ajGraphOpenWin(graph, fbegin1-ymargin,fend1+ymargin,
		       fbegin2-xmargin,(float)fend2+xmargin);

	ajGraphicsSetCharscale(0.5);

	if(matchlist)
	    dottup_plotMatches(matchlist);

	if(boxit)
	{
	    ajGraphicsDrawposRect(fbegin1, fbegin2, fend1, fend2);
	    i = 0;
	    while(acceptableticksx[i]*numbofticks < len1)
		i++;

	    if(i<=13)
		tickgap = (float) acceptableticksx[i];
	    else
		tickgap = (float) acceptableticksx[10];

	    ticklen = xmargin * (float) 0.1;
	    onefifth  = xmargin * (float)0.2;
	    ajGraphicsDrawposTextAtmid(fbegin1+flen1*(float)0.5,
                                       fbegin1-(onefifth*(float)3.0),
                                       ajGraphGetYlabelC(graph));

	    if(len2/len1 > 10 )
	    {
		/* a lot smaller then just label start and end */
		ajGraphicsDrawposLine(fbegin1,fbegin2,fbegin1,
			    fbegin2-ticklen);
		sprintf(ptr,"%u",ajSeqGetOffset(seq1));
		ajGraphicsDrawposTextAtmid(fbegin1,fbegin2-(onefifth),ptr);
		
		ajGraphicsDrawposLine(fend1,fbegin2,
			    fend1,fbegin2-ticklen);
		sprintf(ptr,"%d",end1);
		ajGraphicsDrawposTextAtmid(fend1,fbegin2-(onefifth),ptr);
	    }
	    else
		for(k=fbegin1;k<fend1;k+=tickgap)
		{
		    ajGraphicsDrawposLine(k,fbegin2,k,fbegin2-ticklen);
		    sprintf(ptr,"%d",(ajint)k);
		    ajGraphicsDrawposTextAtmid( k,fbegin2-(onefifth),ptr);
		}

	    i = 0;
	    while(acceptableticks[i]*numbofticks < len2)
		i++;

	    tickgap   = (float) acceptableticks[i];
	    ticklen   = ymargin*(float)0.1;
	    onefifth  = ymargin*(float)0.2;
	    ajGraphicsDrawposTextAtlineJustify(fbegin1-(onefifth*(float)4.),
                                               fbegin2+flen2*(float)0.5,
                                               fbegin2-(onefifth*(float)4.),
                                               fbegin2+flen2,
                                               ajGraphGetXlabelC(graph),
                                               0.5);

	    if(len1/len2 > 10 )
	    {
		/* a lot smaller then just label start and end */
		ajGraphicsDrawposLine(fbegin1,fbegin2,fbegin1-ticklen,
			    fbegin2);
		sprintf(ptr,"%u",ajSeqGetOffset(seq2));
		ajGraphicsDrawposTextAtend(fbegin1-(onefifth),fbegin2,ptr);

		ajGraphicsDrawposLine(fbegin1,fend2,fbegin1-ticklen,
			    fend2);
		sprintf(ptr,"%d",end2);
		ajGraphicsDrawposTextAtend(fbegin2-(onefifth),fend2,ptr);
	    }
	    else
		for(k=fbegin2;k<fend2;k+=tickgap)
		{
		    ajGraphicsDrawposLine(fbegin1,k,fbegin1-ticklen,k);
		    sprintf(ptr,"%d",(ajint)k);
		    ajGraphicsDrawposTextAtend(fbegin1-(onefifth),k,ptr);
		}
	}
    }

    ajGraphicsClose();
    ajSeqDel(&seq1);
    ajSeqDel(&seq2);
    ajGraphxyDel(&graph);
    ajGraphxyDel(&xygraph);

    embWordFreeTable(&seq1MatchTable);

    if(matchlist)
	embWordMatchListDelete(&matchlist); /* free the match structures */

    embExit();

    return 0;
}
Exemplo n.º 8
0
static void prettyplot_fillinboxes(ajint numseq, ajint length, 
				   ajint seqstart, ajint seqend,
				   ajint start, ajint end,
				   ajint numres, ajint resbreak,
				   AjBool boxit, AjBool boxcol, 
				   AjBool consensus,
				   float ystart, float yincr,
				   const AjPSeqCvt cvt)
{
    ajint count = 1;
    ajint gapcount = 0;
    ajint countforgap = 0;
    ajint table[16];
    ajint i;
    ajint j;
    ajint k;
    ajint w;
    ajint oldfg = 0;
    ajint oldcol = 0;
    ajint l;
    float y;
    char res[2]=" ";
    AjPStr strcon = NULL;
    char numberstring[10];
    float defcs = 0.;
    float curcs = 0.;

/*
    ajDebug("fillinboxes numseq: %d length: %d\n",
	    numseq, length);
    ajDebug("fillinboxes start: %d end: %d seqstart: %d seqend; %d\n",
	    start, end, seqstart, seqend);
    ajDebug("fillinboxes numres: %d resbreak: %d\n",
	    numres, resbreak);
    ajDebug("fillinboxes boxit: %B boxcol: %B consensus: %B \n",
	    boxit, boxcol, consensus);
    ajDebug("fillinboxes xmid: %.3f ystart:%.3f yincr: %.3f\n",
	    xmid, ystart, yincr);
*/
    ajStrAppendC(&strcon,"Consensus");
    ajStrTruncateLen(&strcon,charlen);

    if(boxit && boxcol)
    {
	y = ystart-(float)6.0;
	for(k=start; k< end; k++)
	{
	    if(countforgap >= resbreak)
	    {
		gapcount++;
		countforgap = 0;
	    }
	    if(count >= numres+1 )
	    {
		y = y-(yincr*((float)numseq+(float)2.0+((float)consensus*
							(float)2)));
		if(y<yincr*((float)numseq+(float)2.0+((float)consensus*
						      (float)2)))
		{
		    y = ystart-(float)6.0;
		}
		count = 1;
		gapcount = 0;
	    }
	    count++;
	    countforgap++;
	    /* thiscol = ajGraphicsGetColourFore(); Unused */

	    for(j=seqstart,l=0;j<seqend;j++,l++)
		if(seqboxptr[j][k] & BOXCOLOURED)
		{
		    ajGraphicsDrawposRectFill((float)(count+gapcount-(float)1)+
                                              (float)1.0,
                                              y-(yincr*((float)l+(float)0.5)),
                                              (float)(count+gapcount-(float)1),
                                              y-(yincr*((float)l-(float)0.5)));
		}
	}
    }

    oldcol = ajGraphicsSetFgcolour(BLACK);

    /* DO THE BACKGROUND OF THE BOXES FIRST */

    count = 0;
    gapcount = countforgap = 0;
    y = ystart-(float)6.0;

    ajGraphicsGetCharsize(&defcs,&curcs);

    if(shownames)
    {
	for(i=seqstart,l=0;i<seqend;i++,l++)
	    ajGraphicsDrawposTextAtstart((float)-charlen,y-(yincr*l),
                                         ajStrGetPtr(seqnames[i]));

	if(consensus && (numseq==seqend))
	    ajGraphicsDrawposTextAtstart(
                (float)-charlen,
                y-(yincr*((seqend-seqstart)+(float)1)),ajStrGetPtr(strcon));

    }

    for(k=start; k< end; k++)
    {
	if(countforgap >= resbreak)
	{
	    gapcount++;
	    countforgap = 0;
	}

	if(count >= numres )
	{
	    if(shownumbers)
	    {
		for(j=seqstart,l=0;j<seqend;j++,l++)
		{
		    sprintf(numberstring,"%d",seqcount[j]);
		    ajGraphicsDrawposTextAtstart(
                        (float)(count+numgaps)+(float)5.0,
                        y-(yincr*(float)l),numberstring);
		}

		if(consensus && (numseq==seqend))
		{
		    sprintf(numberstring,"%d",k);
		    ajGraphicsDrawposTextAtstart(
                        (float)(count+numgaps)+(float)5.0,
                        y-(yincr*((float)l+(float)1)),
                        numberstring);
		}
	    }

	    y = y-(yincr*((float)numseq+(float)2.0+((float)consensus*
						    (float)2)));
	    if(y<yincr*((float)numseq+(float)2.0+((float)consensus*(float)2)))
	    {
		y = ystart-(float)6.0;
	    }

	    count = 0;
	    gapcount = 0;
	    if(shownames)
	    {
		for(i=seqstart,l=0;i<seqend;i++,l++)
		    ajGraphicsDrawposTextAtstart((float)-charlen,y-(yincr*l),
                                                 ajStrGetPtr(seqnames[i]));

		if(consensus &&(numseq==seqend))
		    ajGraphicsDrawposTextAtstart(
                        (float)-charlen,
                        y-(yincr*((seqend-seqstart)+1)),
                        ajStrGetPtr(strcon));
	    }
	}
	count++;
	countforgap++;

	if(boxit)
	{
	    for(j=seqstart,l=0; j< seqend; j++,l++)
	    {
		if(ajSeqcvtGetCodeK(cvt, seqcharptr[j][k]))
		    seqcount[j]++;
		if(seqboxptr[j][k] & BOXLEF)
		    ajGraphicsDrawposLine((float)(count+gapcount),y-
                                          (yincr*((float)l+(float)0.5)),
                                          (float)(count+gapcount),
                                          y-(yincr*((float)l-(float)0.5)));

		if(seqboxptr[j][k] & BOXTOP)
		    ajGraphicsDrawposLine((float)(count+gapcount),y-
                                          (yincr*((float)l-(float)0.5)),
                                          (float)(count+gapcount)+(float)1.0,
                                          y-(yincr*((float)l-(float)0.5)));

		if(seqboxptr[j][k] & BOXBOT)
		    ajGraphicsDrawposLine((float)(count+gapcount),y-
                                          (yincr*((float)l+(float)0.5)),
                                          (float)(count+gapcount)+(float)1.0,
                                          y-(yincr*((float)l+(float)0.5)));

		if(seqboxptr[j][k] & BOXRIG)
		    ajGraphicsDrawposLine((float)(count+gapcount)+(float)1.0,y-
                                          (yincr*((float)l+(float)0.5)),
                                          (float)(count+gapcount)+(float)1.0,
                                          y-(yincr*((float)l-(float)0.5)));
	    }
	}
	else if(shownumbers)	/* usually set in the boxit block */
	{
	  for(j=seqstart,l=0; j< seqend; j++,l++)
	  {
	    if(ajSeqcvtGetCodeK(cvt, seqcharptr[j][k]))
	      seqcount[j]++;
	  }
	}
	if(consensus && (numseq==seqend))
	{
	    res[0] = constr[k];

	    /* start -> mid */
            ajGraphicsDrawposTextAtmid((float) 0.5 + (float)(count+gapcount),
                                       y-(yincr*((seqend-seqstart)+1)),res);
	}
    }

    if(shownumbers)
    {
	for(j=seqstart,l=0;j<seqend;j++,l++)
	{
	    sprintf(numberstring,"%d",seqcount[j]);
	    ajGraphicsDrawposTextAtstart((float)(count+numgaps)+
                                         (float)5.0,y-(yincr*l),
                                         numberstring);
	}

	if(consensus && (numseq==seqend))
	{
	    sprintf(numberstring,"%d",k);
	    ajGraphicsDrawposTextAtstart((float)(count+numgaps)+(float)5.0,
                                         y-(yincr*(l+(float)1)),
                                         numberstring);
	}
    }


    ajStrDel(&strcon);

    for(i=0;i<16;i++)
	table[i] = -1;
    for(i=0;i<numseq;i++)
	for(k=0; k< length; k++)
	    table[seqcolptr[i][k]] = 1;

    /* now display again but once for each colour */

    /*    for(w=0;w<15;w++)*/
    for(w=0;w<16;w++)
    {
	/* not 16 as we can ignore white on plotters*/
	if(table[w] > 0)
	{
	    oldfg = ajGraphicsSetFgcolour(w);
	    count = 0;
	    gapcount = countforgap = 0;

	    y = ystart-(float)6.0;

	    for(k=start; k< end; k++)
	    {
		if(countforgap >= resbreak)
		{
		    gapcount++;
		    countforgap=0;
		}

		if(count >= numres )
		{
		    y=y-(yincr*((float)(seqend-seqstart)+(float)2.0+
				((float)consensus*(float)2)));
		    count = 0;
		    gapcount = 0;
		}
		count++;
		countforgap++;

		for(j=seqstart,l=0; j< seqend; j++,l++){
		    if(seqcolptr[j][k] == w)
		    {
			if(ajSeqcvtGetCodeK(cvt, seqcharptr[j][k]))
			    res[0] = seqcharptr[j][k];
			else
			    res[0] = '-';
	    /* start -> mid */
			ajGraphicsDrawposTextAtmid((float) 0.5 +
                                                   (float) (count+gapcount),
                                                   y-(yincr*l),res);
		    }
		}
	    }
	}
	oldfg = ajGraphicsSetFgcolour(oldfg);
    }

    oldfg = ajGraphicsSetFgcolour(oldcol);
    start = end;

    return;
}
Exemplo n.º 9
0
int main(int argc, char **argv)
{

    AjPSeqset seqset;
    const AjPSeq seq1;
    const AjPSeq seq2;
    ajint wordlen;
    AjPTable seq1MatchTable = NULL;
    AjPList matchlist ;
    AjPGraph graph = 0;
    ajuint i;
    ajuint j;
    float total=0;
    ajuint acceptableticks[]=
    {
	1,10,50,100,200,500,1000,1500,10000,50000,
	100000,500000,1000000,5000000
    };
    ajint numbofticks = 10;
    ajint gap,tickgap;
    AjBool boxit    = AJTRUE;
    AjBool dumpfeat = AJFALSE;
    float xmargin;
    float ymargin;
    float k;
    char ptr[10];
    float ticklen;
    float onefifth;
    AjPFeattable *tabptr = NULL;
    AjPFeattabOut seq1out = NULL;
    AjPStr sajb = NULL;
    float flen1;
    float flen2;
    ajuint tui;
    
    embInit("polydot", argc, argv);

    wordlen  = ajAcdGetInt("wordsize");
    seqset   = ajAcdGetSeqset("sequences");
    graph    = ajAcdGetGraph("graph");
    gap      = ajAcdGetInt("gap");
    boxit    = ajAcdGetBoolean("boxit");
    seq1out  = ajAcdGetFeatout("outfeat");
    dumpfeat = ajAcdGetToggle("dumpfeat");

    sajb = ajStrNew();
    embWordLength(wordlen);

    AJCNEW(lines,ajSeqsetGetSize(seqset));
    AJCNEW(pts,ajSeqsetGetSize(seqset));
    AJCNEW(tabptr,ajSeqsetGetSize(seqset));

    for(i=0;i<ajSeqsetGetSize(seqset);i++)
    {
	seq1 = ajSeqsetGetseqSeq(seqset, i);
	total += ajSeqGetLen(seq1);

    }
    
    total +=(float)(gap*(ajSeqsetGetSize(seqset)-1));
    
    xmargin = total*(float)0.15;
    ymargin = total*(float)0.15;
    
    ticklen = xmargin*(float)0.1;
    onefifth  = xmargin*(float)0.2;
    
    i = 0;
    while(acceptableticks[i]*numbofticks < ajSeqsetGetLen(seqset))
	i++;
    
    if(i<=13)
	tickgap = acceptableticks[i];
    else
	tickgap = acceptableticks[13];
    
    ajGraphAppendTitleS(graph, ajSeqsetGetUsa(seqset));

    ajGraphOpenWin(graph, (float)0.0-xmargin,(total+xmargin)*(float)1.35,
		   (float)0.0-ymargin,
		   total+ymargin);
    ajGraphicsSetCharscale((float)0.3);
    
    
    for(i=0;i<ajSeqsetGetSize(seqset);i++)
    {
	which = i;
	seq1 = ajSeqsetGetseqSeq(seqset, i);
	tui = ajSeqGetLen(seq1);
	flen1 = (float) tui;

	if(embWordGetTable(&seq1MatchTable, seq1)){ /* get table of words */
	    for(j=0;j<ajSeqsetGetSize(seqset);j++)
	    {
		seq2 = ajSeqsetGetseqSeq(seqset, j);
		tui  = ajSeqGetLen(seq2);
		flen2 = (float) tui;

		if(boxit)
		    ajGraphicsDrawposRect(xstart,ystart,
                                          xstart+flen1,
                                          ystart+flen2);

		matchlist = embWordBuildMatchTable(seq1MatchTable, seq2,
						   ajTrue);
		if(matchlist)
		    polydot_plotMatches(matchlist);

		if(i<j && dumpfeat)
		    embWordMatchListConvToFeat(matchlist,&tabptr[i],
					       &tabptr[j],seq1,
					       seq2);

		if(matchlist)	       /* free the match structures */
		    embWordMatchListDelete(&matchlist);

		if(j==0)
		{
		    for(k=0.0;k<ajSeqGetLen(seq1);k+=tickgap)
		    {
			ajGraphicsDrawposLine(xstart+k,ystart,xstart+k,
				    ystart-ticklen);

			sprintf(ptr,"%d",(ajint)k);
			ajGraphicsDrawposTextAtmid(xstart+k,
                                                   ystart-(onefifth),
                                                   ptr);
		    }
		    ajGraphicsDrawposTextAtmid(
                        xstart+(flen1/(float)2.0),
                        ystart-(3*onefifth),
                        ajStrGetPtr(ajSeqsetGetseqNameS(seqset, i)));
		}

		if(i==0)
		{
		    for(k=0.0;k<ajSeqGetLen(seq2);k+=tickgap)
		    {
			ajGraphicsDrawposLine(xstart,ystart+k,xstart-ticklen,
				    ystart+k);

			sprintf(ptr,"%d",(ajint)k);
			ajGraphicsDrawposTextAtend(xstart-(onefifth),
                                                   ystart+k,
                                                   ptr);
		    }
		    ajGraphicsDrawposTextAtlineJustify(
                        xstart-(3*onefifth),
                        ystart+(flen2/(float)2.0),
                        xstart-(3*onefifth),ystart+flen2,
                        ajStrGetPtr(ajSeqsetGetseqNameS(seqset, j)),0.5);
		}
		ystart += flen2+(float)gap;
	    }
	}
	embWordFreeTable(&seq1MatchTable);
	seq1MatchTable = NULL;
	xstart += flen1+(float)gap;
	ystart = 0.0;
    }
    
    ajGraphicsDrawposTextAtstart(total+onefifth,total-(onefifth),
		     "No. Length  Lines  Points Sequence");
    
    for(i=0;i<ajSeqsetGetSize(seqset);i++)
    {
	seq1 = ajSeqsetGetseqSeq(seqset, i);
	ajFmtPrintS(&sajb,"%3u %6d %5d %6d %s",i+1,
		    ajSeqGetLen(seq1),lines[i],
		    pts[i],ajSeqGetNameC(seq1));

	ajGraphicsDrawposTextAtstart(total+onefifth,total-(onefifth*(i+2)),
                                     ajStrGetPtr(sajb));
    }
    
    if(dumpfeat && seq1out)
    {
	for(i=0;i<ajSeqsetGetSize(seqset);i++)
	{
	    ajFeattableWrite(seq1out, tabptr[i]);
	    ajFeattableDel(&tabptr[i]);
	}
    }
    
    ajGraphicsClose();
    ajGraphxyDel(&graph);

    ajStrDel(&sajb);
    AJFREE(lines);
    AJFREE(pts);
    AJFREE(tabptr);

    ajSeqsetDel(&seqset);
    ajFeattabOutDel(&seq1out);;

    embExit();

    return 0;
}
Exemplo n.º 10
0
int main(int argc, char **argv)
{
    AjPSeq seq      = NULL;
    AjPStr strand   = NULL;
    AjPStr substr   = NULL;
    AjPStr squares  = NULL;
    AjPStr diamonds = NULL;
    AjPStr octags   = NULL;
    AjBool wheel;
    AjBool amphipathic;
    AjPGraph  graph=0;
    AjBool first;
    AjBool startloop;

    ajint begin;
    ajint end;
    ajint len;

    ajint steps;
    ajint turns;
    ajint lc;

    ajint i;
    ajint j;
    ajint k;

    float xmin = (float) -1.0;
    float xmax = (float)  1.0;
    float ymin = (float) -0.75;
    float ymax = (float)  0.75;

    float minresplot = (float) 36.0;
    float resgap =     (float) 0.0533;
    float wheelgap =   (float) 0.00;
    float nresgap =    (float) 0.08;




    float angle;
    float oldangle;
    float ang;
    float radius;
    float wradius;
    float xx1;
    float xx2;
    float yy1;
    float yy2;


    embInit("pepwheel", argc, argv);


    seq         = ajAcdGetSeq("sequence");
    steps       = ajAcdGetInt("steps");
    turns       = ajAcdGetInt("turns");
    graph       = ajAcdGetGraph("graph");
    octags      = ajAcdGetString("octags");
    squares     = ajAcdGetString("squares");
    diamonds    = ajAcdGetString("diamonds");
    wheel       = ajAcdGetBoolean("wheel");
    amphipathic = ajAcdGetToggle("amphipathic");

    ajStrFmtUpper(&octags);
    ajStrFmtUpper(&squares);
    ajStrFmtUpper(&diamonds);

    if(amphipathic)
    {
	ajStrAssignC(&squares,"ACFGILMVWY");
	ajStrAssignC(&diamonds,"");
	ajStrAssignC(&octags,"");
    }


    substr = ajStrNew();

    begin = ajSeqGetBegin(seq);
    end   = ajSeqGetEnd(seq);
    ajDebug("begin: %d end: %d\n", begin, end);
    strand = ajSeqGetSeqCopyS(seq);

    ajStrFmtUpper(&strand);
    ajStrAssignSubC(&substr,ajStrGetPtr(strand),begin-1,end-1);
    len = ajStrGetLen(substr);

    ajGraphAppendTitleS(graph, ajSeqGetUsaS(seq));

    ajGraphOpenWin(graph,xmin,xmax,ymin,ymax);

    ajGraphicsSetFgcolour(AJB_BLACK);

    ang = ((float)360.0 / (float)steps) * (float)turns;

    first = ajTrue;
    angle = (float) 90.0 + ang;
    if(end-begin > (ajint)minresplot)
	wradius = (float) 0.2;
    else
	wradius = (float) 0.40;

    for(i=0,lc=0,radius=wradius+wheelgap;i<len;i+=steps)
    {
	wradius += wheelgap;
	startloop = ajTrue;
	k = AJMIN(i+steps, end);
	for(j=i;j<k;++j)
	{
	    oldangle = angle;
	    angle    = oldangle-ang;
	    if(first)
		startloop = first = ajFalse;
	    else
	    {
		if(startloop)
		{
		    if(wheel)
		    {
			ajCvtPolToRec(wradius-wheelgap,oldangle,&xx1,&yy1);
			ajCvtPolToRec(wradius,angle,&xx2,&yy2);
			ajGraphicsDrawposLine(xx1,yy1,xx2,yy2);
		    }
		    startloop=ajFalse;
		}
		else
		    if(wheel)
		    {
			ajCvtPolToRec(wradius,oldangle,&xx1,&yy1);
			ajCvtPolToRec(wradius,angle,&xx2,&yy2);
			ajGraphicsDrawposLine(xx1,yy1,xx2,yy2);
		    }
	    }
	    pepwheel_plotresidue(*(ajStrGetPtr(substr)+lc),radius+resgap,angle,
				 ajStrGetPtr(squares),ajStrGetPtr(octags),
				 ajStrGetPtr(diamonds),
				 xmin,xmax,ymin,ymax);
	    ++lc;
	    if(lc==len)
		break;
	}
	radius += nresgap;

    }

    ajGraphicsClose();
    ajGraphxyDel(&graph);

    ajStrDel(&strand);
    ajStrDel(&substr);

    ajSeqDel(&seq);

    ajStrDel(&squares);
    ajStrDel(&diamonds);
    ajStrDel(&octags);

    embExit();

    return 0;
}