Taxonomy: new functions and improvements
This commit is contained in:
@ -148,7 +148,7 @@ static char* get_taxonomy_path(OBIDMS_p dms, const char* tax_name);
|
||||
* @returns The index of a rank in the ecorankidx_t structure.
|
||||
* @retval -1 if the rank was not found.
|
||||
*/
|
||||
static int32_t rank_index(const char* label, ecorankidx_t* ranks);
|
||||
static int32_t rank_label_to_index(const char* label, ecorankidx_t* ranks);
|
||||
|
||||
|
||||
/**
|
||||
@ -543,7 +543,7 @@ static char* get_taxonomy_path(OBIDMS_p dms, const char* tax_name)
|
||||
}
|
||||
|
||||
|
||||
static int32_t rank_index(const char* label, ecorankidx_t* ranks)
|
||||
static int32_t rank_label_to_index(const char* label, ecorankidx_t* ranks)
|
||||
{
|
||||
char **rep;
|
||||
|
||||
@ -3501,6 +3501,13 @@ ecotx_t* obi_taxo_get_parent_at_rank(ecotx_t* taxon, int32_t rankidx)
|
||||
ecotx_t* current_taxon;
|
||||
ecotx_t* next_taxon;
|
||||
|
||||
if (taxon == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_TAXONOMY_ERROR);
|
||||
obidebug(1, "\nError getting the parent of a taxon at a given rank: taxon pointer is NULL");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
current_taxon = taxon;
|
||||
next_taxon = current_taxon->parent;
|
||||
|
||||
@ -3524,6 +3531,13 @@ ecotx_t* obi_taxo_get_taxon_with_taxid(OBIDMS_taxonomy_p taxonomy, int32_t taxid
|
||||
ecomerged_t *indexed_taxon;
|
||||
int32_t count;
|
||||
|
||||
if (taxonomy == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_TAXONOMY_ERROR);
|
||||
obidebug(1, "\nError trying to get a taxon with its taxid: taxonomy pointer is NULL");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
count = (taxonomy->merged_idx)->count;
|
||||
|
||||
indexed_taxon = (ecomerged_t*) bsearch((const void *) ((size_t) taxid),
|
||||
@ -3543,12 +3557,19 @@ ecotx_t* obi_taxo_get_taxon_with_taxid(OBIDMS_taxonomy_p taxonomy, int32_t taxid
|
||||
}
|
||||
|
||||
|
||||
bool obi_taxo_is_taxon_under_taxid(ecotx_t* taxon, int32_t other_taxid) // TODO discuss that this doesn't work with deprecated taxids
|
||||
int obi_taxo_is_taxon_under_taxid(ecotx_t* taxon, int32_t other_taxid) // TODO discuss that this doesn't work with deprecated taxids
|
||||
{
|
||||
ecotx_t* next_parent;
|
||||
|
||||
next_parent = taxon->parent;
|
||||
|
||||
if (taxon == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_TAXONOMY_ERROR);
|
||||
obidebug(1, "\nError checking if a taxon is under another: taxon pointer is NULL");
|
||||
return -1;
|
||||
}
|
||||
|
||||
while ((other_taxid != next_parent->taxid) && (strcmp(next_parent->name, "root")))
|
||||
next_parent = next_parent->parent;
|
||||
|
||||
@ -3561,19 +3582,27 @@ bool obi_taxo_is_taxon_under_taxid(ecotx_t* taxon, int32_t other_taxid) // TODO
|
||||
|
||||
ecotx_t* obi_taxo_get_species(ecotx_t* taxon, OBIDMS_taxonomy_p taxonomy)
|
||||
{
|
||||
static OBIDMS_taxonomy_p tax = NULL;
|
||||
static int32_t rankindex = -1;
|
||||
static int32_t rankindex = -1;
|
||||
|
||||
if (taxonomy && (tax != taxonomy))
|
||||
{
|
||||
rankindex = rank_index("species", taxonomy->ranks);
|
||||
tax = taxonomy;
|
||||
}
|
||||
|
||||
if (!tax || (rankindex < 0))
|
||||
if (taxonomy == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_TAXONOMY_ERROR);
|
||||
obidebug(1, "\nError trying to get the species associated with a taxon: No taxonomy defined");
|
||||
obidebug(1, "\nError trying to get the species associated with a taxon: taxonomy pointer is NULL");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (taxon == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_TAXONOMY_ERROR);
|
||||
obidebug(1, "\nError trying to get the species associated with a taxon: taxon pointer is NULL");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rankindex = rank_label_to_index("species", taxonomy->ranks);
|
||||
if (rankindex < 0)
|
||||
{
|
||||
obi_set_errno(OBI_TAXONOMY_ERROR);
|
||||
obidebug(1, "\nError trying to get the species associated with a taxon: error getting rank index");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -3583,19 +3612,27 @@ ecotx_t* obi_taxo_get_species(ecotx_t* taxon, OBIDMS_taxonomy_p taxonomy)
|
||||
|
||||
ecotx_t* obi_taxo_get_genus(ecotx_t* taxon, OBIDMS_taxonomy_p taxonomy)
|
||||
{
|
||||
static OBIDMS_taxonomy_p tax = NULL;
|
||||
static int32_t rankindex = -1;
|
||||
static int32_t rankindex = -1;
|
||||
|
||||
if (taxonomy && (tax != taxonomy))
|
||||
{
|
||||
rankindex = rank_index("genus", taxonomy->ranks);
|
||||
tax = taxonomy;
|
||||
}
|
||||
|
||||
if (!tax || (rankindex < 0))
|
||||
if (taxonomy == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_TAXONOMY_ERROR);
|
||||
obidebug(1, "\nError trying to get the genus associated with a taxon: No taxonomy defined");
|
||||
obidebug(1, "\nError trying to get the genus associated with a taxon: taxonomy pointer is NULL");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (taxon == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_TAXONOMY_ERROR);
|
||||
obidebug(1, "\nError trying to get the genus associated with a taxon: taxon pointer is NULL");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rankindex = rank_label_to_index("genus", taxonomy->ranks);
|
||||
if (rankindex < 0)
|
||||
{
|
||||
obi_set_errno(OBI_TAXONOMY_ERROR);
|
||||
obidebug(1, "\nError trying to get the genus associated with a taxon: error getting rank index");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -3605,19 +3642,27 @@ ecotx_t* obi_taxo_get_genus(ecotx_t* taxon, OBIDMS_taxonomy_p taxonomy)
|
||||
|
||||
ecotx_t* obi_taxo_get_family(ecotx_t* taxon, OBIDMS_taxonomy_p taxonomy)
|
||||
{
|
||||
static OBIDMS_taxonomy_p tax = NULL;
|
||||
static int32_t rankindex = -1;
|
||||
static int32_t rankindex = -1;
|
||||
|
||||
if (taxonomy && (tax != taxonomy))
|
||||
{
|
||||
rankindex = rank_index("family", taxonomy->ranks);
|
||||
tax = taxonomy;
|
||||
}
|
||||
|
||||
if (!tax || (rankindex < 0))
|
||||
if (taxonomy == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_TAXONOMY_ERROR);
|
||||
obidebug(1, "\nError trying to get the family associated with a taxon: No taxonomy defined");
|
||||
obidebug(1, "\nError trying to get the family associated with a taxon: taxonomy pointer is NULL");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (taxon == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_TAXONOMY_ERROR);
|
||||
obidebug(1, "\nError trying to get the family associated with a taxon: taxon pointer is NULL");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rankindex = rank_label_to_index("family", taxonomy->ranks);
|
||||
if (rankindex < 0)
|
||||
{
|
||||
obi_set_errno(OBI_TAXONOMY_ERROR);
|
||||
obidebug(1, "\nError trying to get the family associated with a taxon: error getting rank index");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -3627,19 +3672,27 @@ ecotx_t* obi_taxo_get_family(ecotx_t* taxon, OBIDMS_taxonomy_p taxonomy)
|
||||
|
||||
ecotx_t* obi_taxo_get_kingdom(ecotx_t* taxon, OBIDMS_taxonomy_p taxonomy)
|
||||
{
|
||||
static OBIDMS_taxonomy_p tax = NULL;
|
||||
static int32_t rankindex = -1;
|
||||
static int32_t rankindex = -1;
|
||||
|
||||
if (taxonomy && (tax != taxonomy))
|
||||
{
|
||||
rankindex = rank_index("kingdom", taxonomy->ranks);
|
||||
tax = taxonomy;
|
||||
}
|
||||
|
||||
if (!tax || (rankindex < 0))
|
||||
if (taxonomy == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_TAXONOMY_ERROR);
|
||||
obidebug(1, "\nError trying to get the kingdom associated with a taxon: No taxonomy defined");
|
||||
obidebug(1, "\nError trying to get the kingdom associated with a taxon: taxonomy pointer is NULL");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (taxon == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_TAXONOMY_ERROR);
|
||||
obidebug(1, "\nError trying to get the kingdom associated with a taxon: taxon pointer is NULL");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rankindex = rank_label_to_index("kingdom", taxonomy->ranks);
|
||||
if (rankindex < 0)
|
||||
{
|
||||
obi_set_errno(OBI_TAXONOMY_ERROR);
|
||||
obidebug(1, "\nError trying to get the kingdom associated with a taxon: error getting rank index");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -3649,22 +3702,36 @@ ecotx_t* obi_taxo_get_kingdom(ecotx_t* taxon, OBIDMS_taxonomy_p taxonomy)
|
||||
|
||||
ecotx_t* obi_taxo_get_superkingdom(ecotx_t* taxon, OBIDMS_taxonomy_p taxonomy)
|
||||
{
|
||||
static OBIDMS_taxonomy_p tax = NULL;
|
||||
static int32_t rankindex = -1;
|
||||
|
||||
if (taxonomy && (tax != taxonomy))
|
||||
{
|
||||
rankindex = rank_index("superkingdom", taxonomy->ranks);
|
||||
tax = taxonomy;
|
||||
}
|
||||
|
||||
if (!tax || (rankindex < 0))
|
||||
if (taxonomy == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_TAXONOMY_ERROR);
|
||||
obidebug(1, "\nError trying to get the superkingdom associated with a taxon: No taxonomy defined");
|
||||
obidebug(1, "\nError trying to get the superkingdom associated with a taxon: taxonomy pointer is NULL");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (taxon == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_TAXONOMY_ERROR);
|
||||
obidebug(1, "\nError trying to get the superkingdom associated with a taxon: taxon pointer is NULL");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rankindex = rank_label_to_index("superkingdom", taxonomy->ranks);
|
||||
if (rankindex < 0)
|
||||
{
|
||||
obi_set_errno(OBI_TAXONOMY_ERROR);
|
||||
obidebug(1, "\nError trying to get the superkingdom associated with a taxon: error getting rank index");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return obi_taxo_get_parent_at_rank(taxon, rankindex);
|
||||
}
|
||||
|
||||
|
||||
const char* obi_taxo_rank_index_to_label(int32_t rank_idx, ecorankidx_t* ranks)
|
||||
{
|
||||
return (ranks->label)[rank_idx];
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user