with full coverage statistic
git-svn-id: https://www.grenoble.prabi.fr/svn/LECASofts/ecoPrimers/branches/eric-test@187 60f365c0-8329-0410-b2a4-ec073aeeaa1d
This commit is contained in:
@ -6,41 +6,118 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <search.h>
|
#include <search.h>
|
||||||
|
#include "ecoprimer.h"
|
||||||
|
|
||||||
static int cmptaxon(void *t1, void* t2);
|
static int cmptaxon(const void *t1, const void* t2);
|
||||||
|
|
||||||
|
static int cmptaxon(const void *t1, const void* t2)
|
||||||
static int cmptaxon(void *t1, void* t2)
|
|
||||||
{
|
{
|
||||||
if (*t1 < *t2)
|
const size_t taxid1=(size_t)t1;
|
||||||
|
const size_t taxid2=(size_t)t2;
|
||||||
|
|
||||||
|
// fprintf(stderr,"==> counted taxid1 : %d\n",taxid1);
|
||||||
|
// fprintf(stderr,"==> counted taxid2 : %d\n",taxid2);
|
||||||
|
|
||||||
|
if (taxid1 < taxid2)
|
||||||
return -1;
|
return -1;
|
||||||
if (*t1 > *t2)
|
if (taxid1 > taxid2)
|
||||||
return +1;
|
return +1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t counttaxon(int32_t taxid)
|
||||||
|
{
|
||||||
|
static void* taxontree=NULL;
|
||||||
|
static int32_t taxoncount=0;
|
||||||
|
|
||||||
|
// fprintf(stderr,"counted taxid : %d taxontree %p\n",taxid,taxontree);
|
||||||
|
|
||||||
|
if (taxid==-1)
|
||||||
|
{
|
||||||
|
if (taxontree)
|
||||||
|
ECOFREE(taxontree,"Free taxon tree");
|
||||||
|
taxontree=NULL;
|
||||||
|
taxoncount=0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((!taxontree) || (!tfind((void*)((size_t)taxid),&taxontree,cmptaxon)))
|
||||||
|
{
|
||||||
|
tsearch((void*)((size_t)taxid),&taxontree,cmptaxon);
|
||||||
|
taxoncount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return taxoncount;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t getrankdbstats(pecodnadb_t seqdb, uint32_t seqdbsize, ecotaxonomy_t *taxonomy,
|
||||||
|
poptions_t options)
|
||||||
|
{
|
||||||
|
|
||||||
|
uint32_t i;
|
||||||
|
uint32_t j;
|
||||||
|
ecotx_t *taxon;
|
||||||
|
ecotx_t *tmptaxon;
|
||||||
|
|
||||||
|
counttaxon(-1);
|
||||||
|
|
||||||
|
for (i=0;i<seqdbsize;i++)
|
||||||
|
{
|
||||||
|
taxon = &(taxonomy->taxons->taxon[seqdb[i]->taxid]);
|
||||||
|
seqdb[i]->isexample=isGoodTaxon(taxonomy,seqdb[i]->taxid,options);
|
||||||
|
|
||||||
|
tmptaxon = eco_findtaxonatrank(taxon,
|
||||||
|
options->taxonrankidx);
|
||||||
|
|
||||||
|
// fprintf(stderr,"Taxid : %d %p\n",taxon->taxid,tmptaxon);
|
||||||
|
|
||||||
|
if (tmptaxon)
|
||||||
|
{
|
||||||
|
// fprintf(stderr,"orig : %d trans : %d\n",taxon->taxid,
|
||||||
|
// tmptaxon->taxid);
|
||||||
|
|
||||||
|
seqdb[i]->ranktaxonid=tmptaxon->taxid;
|
||||||
|
if (seqdb[i]->isexample)
|
||||||
|
options->intaxa = counttaxon(tmptaxon->taxid);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
seqdb[i]->ranktaxonid=-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
counttaxon(-1);
|
||||||
|
|
||||||
|
for (i=0;i<seqdbsize;i++)
|
||||||
|
{
|
||||||
|
if (seqdb[i]->ranktaxonid>=0 && !seqdb[i]->isexample)
|
||||||
|
options->outtaxa = counttaxon(seqdb[i]->ranktaxonid);
|
||||||
|
}
|
||||||
|
|
||||||
|
return options->outtaxa + options->intaxa;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
float taxonomycoverage(ppair_t pair, poptions_t options)
|
float taxonomycoverage(ppair_t pair, poptions_t options)
|
||||||
{
|
{
|
||||||
int32_t seqcount;
|
int32_t seqcount;
|
||||||
int32_t *taxon;
|
|
||||||
int32_t i;
|
int32_t i;
|
||||||
void **taxontree;
|
int32_t incount=0;
|
||||||
ppair_t *inserted;
|
int32_t outcount=0;
|
||||||
int32_t taxoncount;
|
|
||||||
|
|
||||||
|
|
||||||
seqcount=pair->pcr.ampcount;
|
seqcount=pair->pcr.ampcount;
|
||||||
taxon = ECOMALLOC(seqcount * sizeof(int32_t));
|
|
||||||
|
|
||||||
taxoncount=0;
|
|
||||||
taxontree=NULL;
|
|
||||||
|
|
||||||
|
counttaxon(-1);
|
||||||
for (i=0; i < seqcount; i++)
|
for (i=0; i < seqcount; i++)
|
||||||
if (pair->pcr.amplifias[i].sequence->isexample)
|
if (pair->pcr.amplifias[i].sequence->isexample)
|
||||||
{
|
incount = counttaxon(pair->pcr.amplifias[i].sequence->ranktaxonid);
|
||||||
inserted = tsearch(pair->pcr.amplifias[i].sequence->ranktaxonid,
|
|
||||||
taxontree,
|
|
||||||
cmptaxon);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
counttaxon(-1);
|
||||||
|
for (i=0; i < seqcount; i++)
|
||||||
|
if (!pair->pcr.amplifias[i].sequence->isexample)
|
||||||
|
outcount = counttaxon(pair->pcr.amplifias[i].sequence->ranktaxonid);
|
||||||
|
|
||||||
|
|
||||||
|
pair->intaxa=incount;
|
||||||
|
pair->outtaxa=outcount;
|
||||||
|
return (float)incount/options->intaxa;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user