BaseTree¶
Dataclass for the tree toplogy of a B cell lineage tree.
Attributes:
Name | Type | Description |
---|---|---|
T |
Digraph
|
a rooted tree |
root |
str
|
the unique identifier of the root |
id |
(int, optional)
|
the identifier of the tree |
name |
(str, optional)
|
the name of the tree |
Source code in tribal/base_tree.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
|
children(n)
¶
Return the set of children of a specified node n
.
Source code in tribal/base_tree.py
96 97 98 |
|
edges()
¶
Return the list of edges of the tree.
Source code in tribal/base_tree.py
60 61 62 |
|
find_leaf_descendants(node, graph)
staticmethod
¶
Obtain all descendants of a node in a graph that is a leaf.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node |
(str, int)
|
|
required |
graph |
DiGraph
|
|
required |
Returns:
Type | Description |
---|---|
the set of leaf descendants
|
|
Source code in tribal/base_tree.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
|
get_clade_set(tree)
¶
Get the clades of the tree.
Source code in tribal/base_tree.py
203 204 205 206 207 208 209 |
|
get_edge_df()
¶
Get the edge list as a pandas.DataFrame.
Source code in tribal/base_tree.py
224 225 226 227 228 |
|
get_leafs()
¶
Return the leafset of the lineage tree.
Source code in tribal/base_tree.py
115 116 117 |
|
get_parents()
¶
Obtain the parent of each node.
Returns:
Type | Description |
---|---|
dict
|
node as key and parent node as child. "" indicates no parent, i.e., the root. |
Source code in tribal/base_tree.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
|
is_leaf(node)
¶
Check if node is a leaf of the tree.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node |
str | int
|
a node in the lineage tree |
required |
Returns:
Type | Description |
---|---|
bool
|
leaf status of the specified node |
Source code in tribal/base_tree.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
is_root(node)
¶
Check if node is the root.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node |
str | int
|
a node in the lineage tree |
required |
Returns:
Type | Description |
---|---|
bool
|
indicator if the node is the root |
Source code in tribal/base_tree.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
nodes()
¶
Return the list of nodes of the tree.
Source code in tribal/base_tree.py
56 57 58 |
|
parent(n)
¶
Get the parent node of the given node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
node
|
The node for which to find the parent. |
required |
Returns:
Type | Description |
---|---|
str | None
|
The parent node if it exists, otherwise None. |
Source code in tribal/base_tree.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
postorder_traversal()
¶
Perform a postorder traversal of the tree.
Postorder traversal means visiting the children nodes first, and then the parent node.
Returns:
Type | Description |
---|---|
list
|
List of nodes in postorder. |
Source code in tribal/base_tree.py
30 31 32 33 34 35 36 37 38 39 40 41 |
|
preorder_traversal()
¶
Perform a preorder traversal of the tree.
Preorder traversal means visiting the parent node first, and then the children nodes.
Returns:
Type | Description |
---|---|
list
|
List of nodes in preorder. |
Source code in tribal/base_tree.py
43 44 45 46 47 48 49 50 51 52 53 54 |
|
relabel(labels)
¶
Relabels a tree in place.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
labels |
dict
|
a dictionary with current nodes as keys and new labels as values. May include only a subset of nodes. |
required |
Source code in tribal/base_tree.py
83 84 85 86 87 88 89 90 91 92 93 94 |
|
save_edges(fname)
¶
Write the edge list to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fname |
str
|
the file where the edge list should be saved. |
required |
Source code in tribal/base_tree.py
212 213 214 215 216 217 218 219 220 221 222 |
|
set_id(id)
¶
Update the id of the tree.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id |
(str, int)
|
the new id of the tree |
required |
Source code in tribal/base_tree.py
152 153 154 155 156 157 158 159 160 |
|
set_name(name)
¶
Update the name of the tree.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
the new id of the tree |
required |
Source code in tribal/base_tree.py
162 163 164 165 166 167 168 169 170 |
|