From 86253e3712c1e369ce0afb7e5ca664109736a76b Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Thu, 14 Jun 2007 13:34:45 +0000 Subject: [PATCH] git-svn-id: https://www.grenoble.prabi.fr/svn/LECASofts/ecoPCR/branches/refactoring@64 60f365c0-8329-0410-b2a4-ec073aeeaa1d --- src/ecofind.c | 49 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/src/ecofind.c b/src/ecofind.c index eb2e014..9770659 100644 --- a/src/ecofind.c +++ b/src/ecofind.c @@ -9,8 +9,8 @@ /** * display the result in sdtout **/ - -static void printresult(ecotx_t *taxon,ecotaxonomy_t *taxonomy){ +static void printresult(ecotx_t *taxon,ecotaxonomy_t *taxonomy) +{ char* rankname; rankname= taxonomy->ranks->label[taxon->rank]; @@ -21,6 +21,31 @@ static void printresult(ecotx_t *taxon,ecotaxonomy_t *taxonomy){ taxon->name); } + +/* ---------------------------------------- */ +/* get back on given taxid taxonomic parent */ +/* and display it */ +/* ---------------------------------------- */ +void gettaxidparents(int32_t taxid, ecotaxonomy_t *taxonomy) +{ + ecotx_t *next_parent; + int32_t c = 0; + + next_parent = eco_findtaxonbytaxid(taxonomy, taxid); + + printf("# taxonomy id \t|\t taxonomy rank \t|\t scientific name\n#\n"); + + while ( strcmp(next_parent->name, "root") ) + { + printresult(next_parent, taxonomy); + next_parent = next_parent->parent; + c++; + } + + printf("# %d parents found\n#\n",c); +} + + /** * printout usage and exit **/ @@ -85,8 +110,10 @@ int main(int argc, char **argv) int re_error; int re_match; regex_t re_preg; + + int32_t taxid = 0; - while ((carg = getopt(argc, argv, "hd:")) != -1) { + while ((carg = getopt(argc, argv, "hd:t:")) != -1) { switch (carg) { case 'd': /* path to the database */ prefix = optarg; @@ -96,6 +123,10 @@ int main(int argc, char **argv) PrintHelp(); exit(0); break; + + case 't': /* taxid */ + sscanf(optarg,"%d",&taxid); + break; case '?': /* bad option */ errflag++; @@ -112,7 +143,7 @@ int main(int argc, char **argv) errflag++; } - if (errflag) + if (errflag && !taxid) ExitUsage(errflag); /** @@ -125,6 +156,16 @@ int main(int argc, char **argv) printf("# %d taxons\n", tax_count); + /* ---------------------------------------- */ + /* display taxid parent if -t option */ + /* specified in command line */ + /* ---------------------------------------- */ + if (taxid) + { + gettaxidparents(taxid,taxonomy); + return 0; + } + /** * parse taxonomy **/