MOD: Added a [P]ath option displaying for each taxon its full path

git-svn-id: https://www.grenoble.prabi.fr/svn/LECASofts/ecoPCR/trunk@423 60f365c0-8329-0410-b2a4-ec073aeeaa1d
This commit is contained in:
Frédéric Boyer
2012-05-16 11:43:33 +00:00
parent 745d50cfa4
commit 2452df90de

View File

@ -9,7 +9,20 @@
/** /**
* display the result * display the result
**/ **/
static void printresult(ecotx_t *taxon,econame_t* name,ecotaxonomy_t *taxonomy)
void displayPath(ecotx_t *taxon, ecotaxonomy_t *taxonomy){
if (taxon != taxon->parent){
displayPath(taxon->parent,taxonomy);
printf(";");
}
if (rank_index("no rank",taxonomy->ranks) != taxon->rank)
printf("%s:", taxonomy->ranks->label[taxon->rank]);
printf("%s", taxon->name);
}
static void printresult(ecotx_t *taxon,econame_t* name,ecotaxonomy_t *taxonomy, int32_t pathDisplay)
{ {
char* rankname; char* rankname;
char* classname; char* classname;
@ -24,32 +37,38 @@ static void printresult(ecotx_t *taxon,econame_t* name,ecotaxonomy_t *taxonomy)
rankname= taxonomy->ranks->label[taxon->rank]; rankname= taxonomy->ranks->label[taxon->rank];
printf("%10d \t| %15s \t|\t %-50s \t|\t %15s \t|\t %s\n", printf("%10d \t| %15s \t|\t %-50s \t|\t %15s \t|\t %s",
taxon->taxid, taxon->taxid,
rankname, rankname,
matchedname, matchedname,
classname, classname,
taxon->name); taxon->name);
if (pathDisplay) {
printf("\t|\t");
displayPath(taxon, taxonomy);
}
printf("\n");
} }
/** /**
* display header before printing any result * display header before printing any result
**/ **/
static void printheader(void) static void printheader(int32_t pathDisplay)
{ {
printf("# %12s \t| %15s \t|\t %-50s \t|\t %-15s \t|\t %s\n#\n", printf("# %12s \t| %15s \t|\t %-50s \t|\t %-15s \t|\t %s%s\n#\n",
"taxonomy id", "taxonomy id",
"taxonomy rank", "taxonomy rank",
"name", "name",
"class name", "class name",
"scientific name"); "scientific name",
pathDisplay ? "\t|\t path":"");
} }
/** /**
* display son's list for given taxon * display son's list for given taxon
**/ **/
static void get_son(ecotaxonomy_t *taxonomy, ecotx_t *taxon, int32_t *count, char *rankname) static void get_son(ecotaxonomy_t *taxonomy, ecotx_t *taxon, int32_t *count, char *rankname, int32_t pathDisplay)
{ {
int32_t i; int32_t i;
ecotx_t *current_taxon; ecotx_t *current_taxon;
@ -63,10 +82,10 @@ static void get_son(ecotaxonomy_t *taxonomy, ecotx_t *taxon, int32_t *count, cha
{ {
if (rankname == NULL || !strcmp(rankname,taxonomy->ranks->label[current_taxon->rank])) if (rankname == NULL || !strcmp(rankname,taxonomy->ranks->label[current_taxon->rank]))
{ {
printresult(current_taxon, NULL, taxonomy); printresult(current_taxon, NULL, taxonomy, pathDisplay);
(*count)++; (*count)++;
} }
get_son(taxonomy,current_taxon,count,rankname); get_son(taxonomy,current_taxon,count,rankname, pathDisplay);
} }
} }
} }
@ -97,23 +116,23 @@ static void listfilteroptions(ecorankidx_t *ranks)
/* get back on given taxid taxonomic parent */ /* get back on given taxid taxonomic parent */
/* and display it */ /* and display it */
/* ---------------------------------------- */ /* ---------------------------------------- */
void gettaxidparents(int32_t taxid, ecotaxonomy_t *taxonomy, char *rankname) void gettaxidparents(int32_t taxid, ecotaxonomy_t *taxonomy, char *rankname, int32_t pathDisplay)
{ {
ecotx_t *next_parent; ecotx_t *next_parent;
int32_t c = 0; int32_t c = 0;
next_parent = eco_findtaxonbytaxid(taxonomy, taxid); next_parent = eco_findtaxonbytaxid(taxonomy, taxid);
printheader(); printheader(pathDisplay);
printresult(next_parent, NULL,taxonomy); printresult(next_parent, NULL,taxonomy, pathDisplay);
while ( strcmp(next_parent->name, "root") ) while ( strcmp(next_parent->name, "root") )
{ {
next_parent = next_parent->parent; next_parent = next_parent->parent;
if (rankname == NULL || !strcmp(rankname,taxonomy->ranks->label[next_parent->rank])) if (rankname == NULL || !strcmp(rankname,taxonomy->ranks->label[next_parent->rank]))
{ {
printresult(next_parent, NULL,taxonomy); printresult(next_parent, NULL,taxonomy, pathDisplay);
c++; c++;
} }
} }
@ -164,6 +183,7 @@ static void PrintHelp()
PP "-p : [P]arents : specifiying this option displays all parental tree's information for the given taxid.\n\n"); PP "-p : [P]arents : specifiying this option displays all parental tree's information for the given taxid.\n\n");
PP "-r : [R]estrict to given taxonomic rank\n\n"); PP "-r : [R]estrict to given taxonomic rank\n\n");
PP "-s : [S]ons: specifiying this option displays all subtree's information for the given taxid.\n\n"); PP "-s : [S]ons: specifiying this option displays all subtree's information for the given taxid.\n\n");
PP "-P : Display taxonomic [P]ath as suplementary column in output\n\n");
PP "arguments:\n"); PP "arguments:\n");
PP "<taxon> name pattern bearing regular expressions\n\n"); PP "<taxon> name pattern bearing regular expressions\n\n");
PP "------------------------------------------\n"); PP "------------------------------------------\n");
@ -199,12 +219,13 @@ int main(int argc, char **argv)
char *rankname = NULL; char *rankname = NULL;
int32_t rankfilter = 1; int32_t rankfilter = 1;
int32_t list = 0; int32_t list = 0;
int32_t path = 0;
ecotx_t *subtree_parent; ecotx_t *subtree_parent;
int32_t count_son = 0; int32_t count_son = 0;
while ((carg = getopt(argc, argv, "had:p:s:r:l")) != -1) { while ((carg = getopt(argc, argv, "had:p:s:r:lP")) != -1) {
switch (carg) { switch (carg) {
case 's': /* path to the database */ case 's': /* path to the database */
sscanf(optarg,"%d",&subtree); sscanf(optarg,"%d",&subtree);
@ -224,6 +245,10 @@ int main(int argc, char **argv)
case 'l': /* list rank filter options */ case 'l': /* list rank filter options */
list = 1; list = 1;
break; break;
case 'P': /* Path output option */
path=1;
break;
case 'a': /* allow alternative names */ case 'a': /* allow alternative names */
alternative = 1; alternative = 1;
@ -281,7 +306,7 @@ int main(int argc, char **argv)
/* ---------------------------------------- */ /* ---------------------------------------- */
if (uptree) if (uptree)
{ {
gettaxidparents(uptree,taxonomy,rankname); gettaxidparents(uptree,taxonomy,rankname, path);
return 0; return 0;
} }
@ -291,10 +316,10 @@ int main(int argc, char **argv)
/* ---------------------------------------- */ /* ---------------------------------------- */
if (subtree) if (subtree)
{ {
printheader(); printheader(path);
subtree_parent = eco_findtaxonbytaxid(taxonomy,subtree); subtree_parent = eco_findtaxonbytaxid(taxonomy,subtree);
printresult(subtree_parent, NULL,taxonomy); printresult(subtree_parent, NULL,taxonomy, path);
get_son(taxonomy, subtree_parent,&count_son,rankname); get_son(taxonomy, subtree_parent,&count_son,rankname, path);
printf("# %d son(s) found\n#\n",count_son); printf("# %d son(s) found\n#\n",count_son);
return 0; return 0;
} }
@ -317,7 +342,7 @@ int main(int argc, char **argv)
nummatch=0; nummatch=0;
printheader(); printheader(path);
for (j=0,name=taxonomy->names->names; for (j=0,name=taxonomy->names->names;
j < name_count; j < name_count;
@ -331,7 +356,7 @@ int main(int argc, char **argv)
if (!re_match && (alternative || name->is_scientificname) && rankfilter) if (!re_match && (alternative || name->is_scientificname) && rankfilter)
{ {
printresult(name->taxon,name,taxonomy); printresult(name->taxon,name,taxonomy, path);
nummatch++; nummatch++;
} }