MCPcopy Create free account
hub / github.com/rambaut/figtree / createNodes

Method createNodes

src/figtree/treeviewer/ReRootedTree.java:85–127  ·  view source on GitHub ↗

Clones the entire tree structure from the given (unrooted) Tree. @param tree the unrooted tree @param parent the parent node @param child the child node

(RootedTree tree, Node parent, Node child)

Source from the content-addressed store, hash-verified

83 * @param child the child node
84 */
85 public Node createNodes(RootedTree tree, Node parent, Node child) throws NoEdgeException {
86
87 Node newNode = null;
88 double length;
89
90 if (tree.isExternal(child)) {
91 newNode = createExternalNode(child, tree.getTaxon(child));
92 length = tree.getEdgeLength(parent, child);
93 } else {
94 List<Node> adjacencies = tree.getAdjacencies(child);
95
96 if (adjacencies.size() == 2) {
97 // this is the root node so skip over it...
98 if (adjacencies.get(0) == parent) {
99 newNode = createNodes(tree, child, adjacencies.get(1));
100 } else {
101 newNode = createNodes(tree, child, adjacencies.get(0));
102 }
103 length = tree.getEdgeLength(adjacencies.get(0), child) +
104 tree.getEdgeLength(adjacencies.get(1), child);
105
106 } else {
107 List<Node> children = new ArrayList<Node>();
108
109 for (Node child2 : adjacencies) {
110 if (child2 != parent) {
111 children.add(createNodes(tree, child, child2));
112 }
113 }
114
115 if (tree.getParent(parent) == child) {
116 newNode = createInternalNode(parent, children);
117 } else {
118 newNode = createInternalNode(child, children);
119 }
120 length = tree.getEdgeLength(parent, child);
121 }
122 }
123
124 setLength(newNode, length);
125
126 return newNode;
127 }
128
129 /**
130 * Creates a new external node with the given taxon. See createInternalNode

Callers 1

ReRootedTreeMethod · 0.95

Calls 10

createExternalNodeMethod · 0.95
createInternalNodeMethod · 0.95
setLengthMethod · 0.95
getEdgeLengthMethod · 0.80
getMethod · 0.65
isExternalMethod · 0.45
getTaxonMethod · 0.45
getAdjacenciesMethod · 0.45
addMethod · 0.45
getParentMethod · 0.45

Tested by

no test coverage detected