Open petermr opened 9 years ago
Current progress:
@Test
public void testBuildTree() {
NexmlNEXML nexml1 = makeTree1();
Assert.assertEquals("xml", "<nexml xmlns=\"http://www.nexml.org/2009\" xmlns:nex=\"http://www.nexml.org/2009\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><otus><otu id=\"id4\" /><otu id=\"id5\" /><otu id=\"id6\" /><otu id=\"id7\" /></otus><trees><tree><node id=\"node1\" /><node id=\"node2\" /><node id=\"node3\" /><node id=\"node4\" otu=\"id4\" /><node id=\"node5\" otu=\"id5\" /><node id=\"node6\" otu=\"id6\" /><node id=\"node7\" otu=\"id7\" /><edge source=\"node1\" target=\"node2\" id=\"edge12\" /><edge source=\"node1\" target=\"node3\" id=\"edge13\" /><edge source=\"node2\" target=\"node4\" id=\"edge24\" /><edge source=\"node2\" target=\"node5\" id=\"edge25\" /><edge source=\"node3\" target=\"node6\" id=\"edge36\" /><edge source=\"node3\" target=\"node7\" id=\"edge37\" /></tree></trees></nexml>", nexml1.toXML());
Assert.assertEquals("newick", "((node4,node5)node2,(node6,node7)node3)node1;", nexml1.createNewick());
}
@Test
public void testDeleteTip() {
NexmlNEXML nexml1 = makeTree1();
NexmlNode node7 = nexml1.getNodeById("node7");
Assert.assertNotNull(node7);
nexml1.deleteTip(node7);
Assert.assertEquals("xml", "<nexml xmlns=\"http://www.nexml.org/2009\" xmlns:nex=\"http://www.nexml.org/2009\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><otus><otu id=\"id4\" /><otu id=\"id5\" /><otu id=\"id6\" /><otu id=\"id7\" /></otus><trees><tree><node id=\"node1\" /><node id=\"node2\" /><node id=\"node3\" /><node id=\"node4\" otu=\"id4\" /><node id=\"node5\" otu=\"id5\" /><node id=\"node6\" otu=\"id6\" /><edge source=\"node1\" target=\"node2\" id=\"edge12\" /><edge source=\"node1\" target=\"node3\" id=\"edge13\" /><edge source=\"node2\" target=\"node4\" id=\"edge24\" /><edge source=\"node2\" target=\"node5\" id=\"edge25\" /><edge source=\"node3\" target=\"node6\" id=\"edge36\" /></tree></trees></nexml>", nexml1.toXML());
Assert.assertEquals("newick", "((node4,node5)node2,(node6)node3)node1;", nexml1.createNewick());
}
The Newick has a node with singleton child, but this displays OK in Trex http://www.trex.uqam.ca/index.php?action=newick&project=trex PMR action to remove the singleton.
Deleting tips on different branches works, but on same one fails:
/**
* Nodes on different branches
*/
@Test
public void testDelete2TipAndElideNodesWithSingletonChildren() {
NexmlNEXML nexml1 = makeTree1();
NexmlNode node7 = nexml1.getNodeById("node7");
nexml1.deleteTipAndElideIfParentHasSingletonChild(node7);
NexmlNode node5 = nexml1.getNodeById("node5");
nexml1.deleteTipAndElideIfParentHasSingletonChild(node5);
Assert.assertEquals("xml", ""
+ "<nexml xmlns=\"http://www.nexml.org/2009\" xmlns:nex=\"http://www.nexml.org/2009\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><otus><otu id=\"id4\" /><otu id=\"id5\" /><otu id=\"id6\" /><otu id=\"id7\" /></otus><trees><tree><node id=\"node1\" /><node id=\"node2\" /><node id=\"node3\" /><node id=\"node4\" otu=\"id4\" /><node id=\"node6\" otu=\"id6\" /><edge target=\"node4\" id=\"edge24\" source=\"node1\" /><edge target=\"node6\" id=\"edge36\" source=\"node1\" /></tree></trees></nexml>",
nexml1.toXML());
Assert.assertEquals("newick", "(node6,node4)node1;", nexml1.createNewick());
}
/**
* Nodes on same branch
*/
@Test
public void testDelete2TipSameBranch() {
NexmlNEXML nexml1 = makeTree1();
NexmlNode node7 = nexml1.getNodeById("node7");
nexml1.deleteTipAndElideIfParentHasSingletonChild(node7);
NexmlNode node6 = nexml1.getNodeById("node6");
nexml1.deleteTipAndElideIfParentHasSingletonChild(node6);
Assert.assertEquals("xml", ""
+ "<nexml xmlns=\"http://www.nexml.org/2009\" xmlns:nex=\"http://www.nexml.org/2009\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><otus><otu id=\"id4\" /><otu id=\"id5\" /><otu id=\"id6\" /><otu id=\"id7\" /></otus><trees><tree><node id=\"node1\" /><node id=\"node2\" /><node id=\"node3\" /><node id=\"node4\" otu=\"id4\" /><node id=\"node6\" otu=\"id6\" /><edge target=\"node4\" id=\"edge24\" source=\"node1\" /><edge target=\"node6\" id=\"edge36\" source=\"node1\" /></tree></trees></nexml>",
nexml1.toXML());
Assert.assertEquals("newick", "(node6,node4)node1;", nexml1.createNewick());
}
results in:
java.lang.NullPointerException
at org.xmlcml.ami2.plugins.phylotree.nexml.NexmlNEXML.getEdge(NexmlNEXML.java:156)
at org.xmlcml.ami2.plugins.phylotree.nexml.NexmlNEXML.elideIfHasSingletonChild(NexmlNEXML.java:125)
at org.xmlcml.ami2.plugins.phylotree.nexml.NexmlNEXML.deleteTipAndElideIfParentHasSingletonChild(NexmlNEXML.java:116)
at org.xmlcml.ami2.plugins.phylotree.nexml.NexmlTest.testDelete2TipSameBranch(NexmlTest.java:88)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
... snipped ...
Fixed. Can delete all nodes except the root. Leaving issue open until more tests.
To create a tool which removes tip nodes (primarily because they have no labels). This should be done on
nexml
. Any resultant poorly formed nodes (e.g. with 1 or 0 children) should be deleted/tidied