コード例 #1
0
ファイル: ajhist.c プロジェクト: WenchaoLin/JAMg
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;
}
コード例 #2
0
ファイル: ajhist.c プロジェクト: WenchaoLin/JAMg
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;
}
コード例 #3
0
static void restover_printHits(const AjPSeq seq, const AjPStr seqcmp,
			       AjPFile outf,
			       AjPList l, const AjPStr name, ajint hits,
			       ajint begin, ajint end,
			       ajint mincut, ajint maxcut, AjBool plasmid,
			       ajint sitelen,
			       AjBool limit, const AjPTable table,
			       AjBool alpha, AjBool frags,
			       AjBool html)
{
    EmbPMatMatch m = NULL;
    AjPStr ps = NULL;
    ajint *fa = NULL;
    ajint *fx = NULL;
    ajint fc = 0;
    ajint fn = 0;
    ajint fb = 0;
    ajint last = 0;
    AjPStr overhead = NULL;

    const AjPStr value = NULL;

    ajint i;
    ajint c = 0;

    ajint hang1;
    ajint hang2;


    ps = ajStrNew();
    fn = 0;

    if(html)
	ajFmtPrintF(outf,"<BR>");
    ajFmtPrintF(outf,"# Restrict of %S from %d to %d\n",name,begin,end);

    if(html)
	ajFmtPrintF(outf,"<BR>");
    ajFmtPrintF(outf,"#\n");

    if(html)
	ajFmtPrintF(outf,"<BR>");
    ajFmtPrintF(outf,"# Minimum cuts per enzyme: %d\n",mincut);

    if(html)
	ajFmtPrintF(outf,"<BR>");
    ajFmtPrintF(outf,"# Maximum cuts per enzyme: %d\n",maxcut);

    if(html)
	ajFmtPrintF(outf,"<BR>");
    ajFmtPrintF(outf,"# Minimum length of recognition site: %d\n",
		sitelen);
    if(html)
	ajFmtPrintF(outf,"<BR>");

    hits = embPatRestrictRestrict(l,hits,!limit,alpha);

    if(frags)
    {
	fa = AJALLOC(hits*2*sizeof(ajint));
	fx = AJALLOC(hits*2*sizeof(ajint));
    }


    ajFmtPrintF(outf,"# Number of hits with any overlap: %d\n",hits);

    if(html)
	ajFmtPrintF(outf,"<BR>");

    if(html)
	ajFmtPrintF(outf,"</p><table  border cellpadding=4 "
		    "bgcolor=\"#FFFFF0\">\n");
    if(html)
	ajFmtPrintF(outf,
		    "<th>Base Number</th><th>Enzyme</th><th>Site</th>"
		    "<th>5'</th><th>3'</th><th>[5'</th><th>3']</th>\n");
    else
	ajFmtPrintF(outf,"# Base Number\tEnzyme\t\tSite\t\t5'\t3'\t"
		    "[5'\t3']\n");

    for(i=0;i<hits;++i)
    {
	ajListPop(l,(void **)&m);
	ajDebug("hit %d start:%d cut1:%d cut2:%d\n",
		i, m->start, m->cut1, m->cut2);

	hang1 = (ajint)m->cut1 - (ajint)m->start;
	hang2 = (ajint)m->cut2 - (ajint)m->start;

	if(!plasmid && (hang1>100 || hang2>100))
	{
	    embMatMatchDel(&m);
	    continue;
	}

	if(limit)
	{
	    value=ajTableFetchS(table,m->cod);
	    if(value)
		ajStrAssignS(&m->cod,value);
	}

	if(m->cut2 >= m->cut1)
	    ajStrAssignSubS(&overhead, ajSeqGetSeqS( seq), m->cut1, m->cut2-1);
	else
	{
	    ajStrAssignSubS(&overhead, ajSeqGetSeqS( seq), m->cut2, m->cut1-1);
	    ajStrReverse(&overhead);
	}

	ajDebug("overhead:%S seqcmp:%S\n", overhead, seqcmp);

	/* Print out only those who have the same overhang. */
	if(ajStrMatchCaseS(overhead, seqcmp))
	{
	    if(html)
	    {
		ajFmtPrintF(outf,
			    "<tr><td>%-d</td><td>%-16s</td><td>%-16s"
			    "</td><td>%d</td><td>%d</td></tr>\n",
			    m->start,ajStrGetPtr(m->cod),ajStrGetPtr(m->pat),
			    m->cut1,m->cut2);
	    }
	    else
		ajFmtPrintF(outf,"\t%-d\t%-16s%-16s%d\t%d\t\n",
			    m->start,ajStrGetPtr(m->cod),ajStrGetPtr(m->pat),
			    m->cut1,m->cut2);
	}

	if(frags)
	    fa[fn++] = m->cut1;

	if(m->cut3 || m->cut4)
	{
	    if(m->cut4 >= m->cut3)
		ajStrAssignSubS(&overhead, ajSeqGetSeqS( seq),
				m->cut3, m->cut4-1);
	    else
	    {
		ajStrAssignSubS(&overhead, ajSeqGetSeqS( seq),
				m->cut4, m->cut3-1);
		ajStrReverse(&overhead);
	    }

	    if(ajStrMatchCaseS(overhead, seqcmp))
	    {
		if(html)
		    ajFmtPrintF(outf,
				"<tr><td>%-d</td><td>%-16s</td><td>%-16s"
				"</td><td></td><td></td><td>%d</td><td>%d"
				"</td></tr>\n",
				m->start,ajStrGetPtr(m->cod),
				ajStrGetPtr(m->pat),
				m->cut1,m->cut2);
		else
		    ajFmtPrintF(outf,"\t%-d\t%-16s%-16s\t\t%d\t%d\t\n",
				m->start,ajStrGetPtr(m->cod),
				ajStrGetPtr(m->pat),
				m->cut1,m->cut2);
	    }
	}

	/* I am not sure what fragments are doing so I left it in ...*/
	/* used in the report tail in restrict - restover does much the same */
	if(m->cut3 || m->cut4)
	{
	    if(frags)
		fa[fn++] = m->cut3;
	    /*	       ajFmtPrintF(*outf,"%d\t%d",m->cut3,m->cut4);*/
	}
	ajStrDel(&overhead);

	embMatMatchDel(&m);
    }



    if(frags)
    {
	ajSortIntInc(fa,fn);
	ajFmtPrintF(outf,"\n\nFragment lengths:\n");
	if(!fn || (fn==1 && plasmid))
	    ajFmtPrintF(outf,"    %d\n",end-begin+1);
	else
	{
	    last = -1;
	    fb = 0;
	    for(i=0;i<fn;++i)
	    {
		if((c=fa[i])!=last)
		    fa[fb++]=c;
		last = c;
	    }
	    fn = fb;
	    /* Calc lengths */

	    for(i=0;i<fn-1;++i)
		fx[fc++] = fa[i+1]-fa[i];
	    if(!plasmid)
	    {
		fx[fc++] = fa[0]-begin+1;
		fx[fc++] = end-fa[fn-1];
	    }
	    else
		fx[fc++] = (fa[0]-begin+1)+(end-fa[fn-1]);

	    ajSortIntDec(fx,fc);
	    for(i=0;i<fc;++i)
		ajFmtPrintF(outf,"    %d\n",fx[i]);
	}
	AJFREE(fa);
	AJFREE(fx);
    }


    ajStrDel(&ps);

    if(html)
	ajFmtPrintF(outf,"</table>\n");

    return;
}