Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OBITools3
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
21
Issues
21
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
OBITools
OBITools3
Commits
ef8dc85f
Commit
ef8dc85f
authored
Nov 27, 2018
by
Celine Mercier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
C, taxonomy: new function to get the lowest common ancestor of two taxa
parent
f942dd85
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
0 deletions
+69
-0
src/obidms_taxonomy.c
src/obidms_taxonomy.c
+57
-0
src/obidms_taxonomy.h
src/obidms_taxonomy.h
+12
-0
No files found.
src/obidms_taxonomy.c
View file @
ef8dc85f
...
...
@@ -3528,6 +3528,63 @@ int obi_taxo_add_preferred_name_with_taxon(OBIDMS_taxonomy_p tax, ecotx_t* taxon
}
ecotx_t
*
obi_taxo_get_lca
(
ecotx_t
*
taxon1
,
ecotx_t
*
taxon2
)
// TODO could be more efficient maybe
{
ecotx_t
*
current_taxon
;
ecotx_t
*
next_taxon
;
ecotx_t
*
lca
;
ecotx_t
*
path1
[
1000
];
ecotx_t
*
path2
[
1000
];
int
i
,
j
;
if
((
taxon1
==
NULL
)
||
(
taxon2
==
NULL
))
{
obi_set_errno
(
OBI_TAXONOMY_ERROR
);
obidebug
(
1
,
"
\n
Error getting the LCA of two taxons: at least one of the taxon pointers is NULL"
);
return
NULL
;
}
// Get path of first taxon // TODO function to get path?
current_taxon
=
taxon1
;
next_taxon
=
current_taxon
->
parent
;
path1
[
0
]
=
current_taxon
;
i
=
0
;
while
(
current_taxon
!=
next_taxon
)
// root node
{
current_taxon
=
next_taxon
;
next_taxon
=
current_taxon
->
parent
;
i
++
;
path1
[
i
]
=
current_taxon
;
}
i
--
;
// Get path of second taxon // TODO function to get path?
current_taxon
=
taxon2
;
next_taxon
=
current_taxon
->
parent
;
path2
[
0
]
=
current_taxon
;
j
=
0
;
while
(
current_taxon
!=
next_taxon
)
// root node
{
current_taxon
=
next_taxon
;
next_taxon
=
current_taxon
->
parent
;
j
++
;
path2
[
j
]
=
current_taxon
;
}
j
--
;
while
((
i
>=
0
)
&&
(
j
>=
0
)
&&
(
path1
[
i
]
==
path2
[
j
]))
{
i
--
;
j
--
;
}
i
++
;
lca
=
path1
[
i
];
return
lca
;
}
ecotx_t
*
obi_taxo_get_parent_at_rank
(
ecotx_t
*
taxon
,
int32_t
rankidx
)
{
ecotx_t
*
current_taxon
;
...
...
src/obidms_taxonomy.h
View file @
ef8dc85f
...
...
@@ -320,6 +320,18 @@ int obi_taxo_add_preferred_name_with_taxid(OBIDMS_taxonomy_p tax, int32_t taxid,
int
obi_taxo_add_preferred_name_with_taxon
(
OBIDMS_taxonomy_p
tax
,
ecotx_t
*
taxon
,
const
char
*
preferred_name
);
/**
* @brief Function returning the last common ancestor of two taxa.
*
* @param taxon1 A pointer on the first taxon.
* @param taxon2 A pointer on the second taxon.
*
* @returns A pointer on the last common ancestor of the two taxa.
* @retval NULL if an error occurred.
*/
ecotx_t
*
obi_taxo_get_lca
(
ecotx_t
*
taxon1
,
ecotx_t
*
taxon2
);
/**
* @brief Function returning the parent of a taxon at a given rank.
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment