Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
BioSeqDataLib
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
domainWorld
BioSeqDataLib
Commits
3bf1fd52
Commit
3bf1fd52
authored
Feb 27, 2019
by
Elias Dohmen
🎓
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added TreeTest (bifurcation)
parent
fe3e6dd1
Pipeline
#702
passed with stages
in 1 minute and 55 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
1 deletion
+69
-1
src/phylogeny/Tree.hpp
src/phylogeny/Tree.hpp
+40
-0
tests/phylogeny/TreeTest.hpp
tests/phylogeny/TreeTest.hpp
+29
-1
No files found.
src/phylogeny/Tree.hpp
View file @
3bf1fd52
...
...
@@ -692,6 +692,46 @@ Tree<TreeNodeType>::~Tree()
// TODO Auto-generated destructor stub
}
/**
* \brief Checks if a tree is strictly bifurcating.
* \details For a strictly bifurcating tree every inner node can just have exactly two child nodes;
* based on the throwError parameter the function either returns boolean (true = tree is strictly bifurcating)
* or throws at first non-bifurcating node a runtime error and quits.
*
* \param tree tree to be checked for bifurcation
* \param throwError if set to true a runtime error is thrown at first non-bifurcating node instead of a false return value
*
* \relates Tree
*/
template
<
typename
DataType
>
bool
isBifurcatingTree
(
const
Tree
<
DataType
>
&
tree
,
bool
throwError
=
false
)
{
bool
bifur
=
true
;
for
(
auto
cNode
=
tree
.
postorderBegin
();
cNode
!=
tree
.
postorderEnd
();
++
cNode
)
{
if
(
!
cNode
->
isLeaf
())
{
unsigned
int
cnum
=
cNode
->
nChildren
();
if
(
cnum
==
1
)
{
if
(
throwError
)
{
throw
std
::
runtime_error
(
"Error: Not a bifurcating tree. Node with just one child detected - Node-ID "
+
cNode
->
id
);
}
else
{
bifur
=
false
;
}
}
if
(
cnum
>
2
)
{
if
(
throwError
)
{
throw
std
::
runtime_error
(
"Error: Not a bifurcating tree. Node with more than two childs detected - Node-ID "
+
cNode
->
id
);
}
else
{
bifur
=
false
;
}
}
}
}
return
bifur
;
}
/** @} */
// PhyloGroup
}
/* namespace BioSeqDataLib */
...
...
tests/phylogeny/TreeTest.hpp
View file @
3bf1fd52
...
...
@@ -33,10 +33,38 @@
#include "../../src/utility/Matrix.hpp"
#include "../../src/phylogeny/Tree.hpp"
#include "../../src/phylogeny/PhylogeneticTree.hpp"
BOOST_AUTO_TEST_SUITE
(
Tree_Test
)
BOOST_AUTO_TEST_CASE
(
Bifurcation_Test
)
{
// bifurcating tree
BioSeqDataLib
::
PhylogeneticTree
<
int
>
bifurTree
;
bifurTree
.
str2tree
(
"(((C:2.000000,(A:1.000000,B:3.000000)),(D:1.000000,E:1.500000)),OG);"
);
// bifurcation
bool
bifurTreeBifur
=
BioSeqDataLib
::
isBifurcatingTree
(
bifurTree
);
BOOST_CHECK_EQUAL
(
bifurTreeBifur
,
true
);
// monofurcating tree
BioSeqDataLib
::
PhylogeneticTree
<
int
>
monofurTree
;
monofurTree
.
str2tree
(
"((((C),(A,B)),(D,E)),OG);"
);
// monofurcation
bool
monoTreeBifur
=
BioSeqDataLib
::
isBifurcatingTree
(
monofurTree
);
BOOST_CHECK_EQUAL
(
monoTreeBifur
,
false
);
BOOST_CHECK_THROW
(
BioSeqDataLib
::
isBifurcatingTree
(
monofurTree
,
true
),
std
::
runtime_error
);
// multifurcating tree
BioSeqDataLib
::
PhylogeneticTree
<
int
>
multifurTree
;
multifurTree
.
str2tree
(
"(((C,B,A),(D,E)),OG);"
);
// multifurcation
bool
multiTreeBifur
=
BioSeqDataLib
::
isBifurcatingTree
(
multifurTree
);
BOOST_CHECK_EQUAL
(
multiTreeBifur
,
false
);
BOOST_CHECK_THROW
(
BioSeqDataLib
::
isBifurcatingTree
(
multifurTree
,
true
),
std
::
runtime_error
);
}
BOOST_AUTO_TEST_SUITE_END
()
#endif
/* TREETEST_HPP_ */
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