Пример #1
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;
}
Пример #2
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;
}