From 24f958ce1f25ba63f7019afa44cc6a2fd86109ae Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Thu, 21 Jun 2007 13:58:06 +0000 Subject: [PATCH] git-svn-id: https://www.grenoble.prabi.fr/svn/LECASofts/ecoPCR/branches/refactoring@79 60f365c0-8329-0410-b2a4-ec073aeeaa1d --- src/ecofind.c | 61 ++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/src/ecofind.c b/src/ecofind.c index edadf78..f59594d 100644 --- a/src/ecofind.c +++ b/src/ecofind.c @@ -48,8 +48,7 @@ static void printheader(void) /** * display son's list for given taxon **/ - -static void get_son(ecotaxonomy_t *taxonomy, ecotx_t *taxon, int32_t *count) +static void get_son(ecotaxonomy_t *taxonomy, ecotx_t *taxon, int32_t *count, char *rankname) { int32_t i; ecotx_t *current_taxon; @@ -60,9 +59,12 @@ static void get_son(ecotaxonomy_t *taxonomy, ecotx_t *taxon, int32_t *count) { if (taxon->taxid == current_taxon->parent->taxid) { - (*count)++; - printresult(current_taxon, NULL, taxonomy); - get_son(taxonomy,current_taxon,count); + if (rankname == NULL || !strcmp(rankname,taxonomy->ranks->label[current_taxon->rank])) + { + printresult(current_taxon, NULL, taxonomy); + (*count)++; + } + get_son(taxonomy,current_taxon,count,rankname); } } } @@ -93,7 +95,7 @@ static void listfilteroptions(ecorankidx_t *ranks) /* get back on given taxid taxonomic parent */ /* and display it */ /* ---------------------------------------- */ -void gettaxidparents(int32_t taxid, ecotaxonomy_t *taxonomy) +void gettaxidparents(int32_t taxid, ecotaxonomy_t *taxonomy, char *rankname) { ecotx_t *next_parent; int32_t c = 0; @@ -101,12 +103,17 @@ void gettaxidparents(int32_t taxid, ecotaxonomy_t *taxonomy) next_parent = eco_findtaxonbytaxid(taxonomy, taxid); printheader(); + + printresult(next_parent, NULL,taxonomy); while ( strcmp(next_parent->name, "root") ) { - printresult(next_parent, NULL,taxonomy); next_parent = next_parent->parent; - c++; + if (rankname == NULL || !strcmp(rankname,taxonomy->ranks->label[next_parent->rank])) + { + printresult(next_parent, NULL,taxonomy); + c++; + } } printf("# %d parent(s) found\n#\n",c); @@ -139,27 +146,26 @@ static void PrintHelp() PP "------------------------------------------\n"); PP " ecofind Version %s\n", VERSION); PP "------------------------------------------\n"); - PP "synopsis : searching for scientific name, taxonomic\n"); - PP " rank and taxonomy id for given regular\n"); - PP " expression patterns\n"); - PP "usage: ecofind [options] pattern\n"); + PP "synopsis : searching for taxonomic and rank and\n"); + PP " taxonomy id for given regular expression patterns\n\n"); + PP "usage: ecofind [options] \n"); PP "------------------------------------------\n"); PP "options:\n"); - PP "-d : [D]atabase containing the taxonomy\n"); - PP " to match the expected format, the database\n"); - PP " has to be formated first by the ecoPCRFormat.py\n"); - PP " program located in the tools directory.\n"); - PP " Write the database radical without any extension.\n\n"); - PP "-h : [H]elp - print help\n\n"); - PP "-l : [L]ist all taxonomic rank available for -r option\n\n"); - PP "-p : [P]arent's taxonomic id. Specifiying this option will display "); - PP " all parent's information for the given taxid.\n\n"); + PP "-a : [A]ll enable the search on all alternative names and not only scientific names.\n\n"); + PP "-d : [D]atabase containing the taxonomy.\n"); + PP " To match the expected format, the database\n"); + PP " has to be formated first by the ecoPCRFormat.py\n"); + PP " program located in the tools directory.\n"); + PP " Write the database radical without any extension.\n\n"); + PP "-h : [H]elp - print help\n\n"); + PP "-l : [L]ist all taxonomic rank available for -r option\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 "-s : [S]on's taxonomic id. Specifiying this option will display "); - PP " all son'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 "arguments:\n"); PP " name pattern bearing regular expressions\n\n"); PP "------------------------------------------\n"); - PP " https://www.grenoble.prabi.fr/trac/ecoPCR/wiki\n"); + PP " http://www.grenoble.prabi.fr/trac/ecoPCR/\n"); PP "------------------------------------------\n\n"); } @@ -245,7 +251,7 @@ int main(int argc, char **argv) errflag++; } - if (errflag && !uptree && !rankname && !subtree) + if (errflag && !uptree && !rankname && !subtree && !list) ExitUsage(errflag); /** @@ -274,7 +280,7 @@ int main(int argc, char **argv) /* ---------------------------------------- */ if (uptree) { - gettaxidparents(uptree,taxonomy); + gettaxidparents(uptree,taxonomy,rankname); return 0; } @@ -286,7 +292,8 @@ int main(int argc, char **argv) { printheader(); subtree_parent = eco_findtaxonbytaxid(taxonomy,subtree); - get_son(taxonomy, subtree_parent,&count_son); + printresult(subtree_parent, NULL,taxonomy); + get_son(taxonomy, subtree_parent,&count_son,rankname); printf("# %d son(s) found\n#\n",count_son); return 0; }