This commit is contained in:
2007-06-21 13:58:06 +00:00
parent 36d536305e
commit 24f958ce1f

View File

@ -48,8 +48,7 @@ static void printheader(void)
/** /**
* 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)
{ {
int32_t i; int32_t i;
ecotx_t *current_taxon; 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) if (taxon->taxid == current_taxon->parent->taxid)
{ {
(*count)++; if (rankname == NULL || !strcmp(rankname,taxonomy->ranks->label[current_taxon->rank]))
{
printresult(current_taxon, NULL, taxonomy); printresult(current_taxon, NULL, taxonomy);
get_son(taxonomy,current_taxon,count); (*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 */ /* get back on given taxid taxonomic parent */
/* and display it */ /* 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; ecotx_t *next_parent;
int32_t c = 0; int32_t c = 0;
@ -102,12 +104,17 @@ void gettaxidparents(int32_t taxid, ecotaxonomy_t *taxonomy)
printheader(); printheader();
printresult(next_parent, NULL,taxonomy);
while ( strcmp(next_parent->name, "root") ) while ( strcmp(next_parent->name, "root") )
{ {
printresult(next_parent, NULL,taxonomy);
next_parent = next_parent->parent; next_parent = next_parent->parent;
if (rankname == NULL || !strcmp(rankname,taxonomy->ranks->label[next_parent->rank]))
{
printresult(next_parent, NULL,taxonomy);
c++; c++;
} }
}
printf("# %d parent(s) found\n#\n",c); printf("# %d parent(s) found\n#\n",c);
} }
@ -139,27 +146,26 @@ static void PrintHelp()
PP "------------------------------------------\n"); PP "------------------------------------------\n");
PP " ecofind Version %s\n", VERSION); PP " ecofind Version %s\n", VERSION);
PP "------------------------------------------\n"); PP "------------------------------------------\n");
PP "synopsis : searching for scientific name, taxonomic\n"); PP "synopsis : searching for taxonomic and rank and\n");
PP " rank and taxonomy id for given regular\n"); PP " taxonomy id for given regular expression patterns\n\n");
PP " expression patterns\n"); PP "usage: ecofind [options] <patterns>\n");
PP "usage: ecofind [options] pattern\n");
PP "------------------------------------------\n"); PP "------------------------------------------\n");
PP "options:\n"); PP "options:\n");
PP "-d : [D]atabase containing the taxonomy\n"); PP "-a : [A]ll enable the search on all alternative names and not only scientific names.\n\n");
PP " to match the expected format, the database\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 " has to be formated first by the ecoPCRFormat.py\n");
PP " program located in the tools directory.\n"); PP " program located in the tools directory.\n");
PP " Write the database radical without any extension.\n\n"); PP " Write the database radical without any extension.\n\n");
PP "-h : [H]elp - print <this> help\n\n"); PP "-h : [H]elp - print <this> help\n\n");
PP "-l : [L]ist all taxonomic rank available for -r option\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 "-p : [P]arents : specifiying this option displays all parental tree's information for the given taxid.\n\n");
PP " all parent'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]on's taxonomic id. Specifiying this option will display "); PP "-s : [S]ons: specifiying this option displays all subtree's information for the given taxid.\n\n");
PP " all son's information for the given taxid.\n\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");
PP " https://www.grenoble.prabi.fr/trac/ecoPCR/wiki\n"); PP " http://www.grenoble.prabi.fr/trac/ecoPCR/\n");
PP "------------------------------------------\n\n"); PP "------------------------------------------\n\n");
} }
@ -245,7 +251,7 @@ int main(int argc, char **argv)
errflag++; errflag++;
} }
if (errflag && !uptree && !rankname && !subtree) if (errflag && !uptree && !rankname && !subtree && !list)
ExitUsage(errflag); ExitUsage(errflag);
/** /**
@ -274,7 +280,7 @@ int main(int argc, char **argv)
/* ---------------------------------------- */ /* ---------------------------------------- */
if (uptree) if (uptree)
{ {
gettaxidparents(uptree,taxonomy); gettaxidparents(uptree,taxonomy,rankname);
return 0; return 0;
} }
@ -286,7 +292,8 @@ int main(int argc, char **argv)
{ {
printheader(); printheader();
subtree_parent = eco_findtaxonbytaxid(taxonomy,subtree); 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); printf("# %d son(s) found\n#\n",count_son);
return 0; return 0;
} }