This commit is contained in:
2007-06-14 13:34:45 +00:00
parent 9f4aa93249
commit 86253e3712

View File

@ -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
**/