graph
navis.graph.classify_nodes #
Classify neuron's nodes into end nodes, branches, slabs or root.
Adds a 'type' column to x.nodes table.
| PARAMETER | DESCRIPTION |
|---|---|
x | TYPE: |
categorical | TYPE: |
inplace | TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
TreeNeuron / List | |
Examples:
>>> import navis
>>> nl = navis.example_neurons(2)
>>> _ = navis.graph.classify_nodes(nl, inplace=True)
Source code in navis/graph/graph_utils.py
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
navis.graph.connected_components_of #
Weakly connected components of the sub-graph induced on keep.
Returns sets of node IDs, mirroring nx.connected_components.
Source code in navis/graph/graph_utils.py
2102 2103 2104 2105 2106 2107 2108 2109 | |
navis.graph.connected_subgraph #
Return set of nodes necessary to connect all nodes in subset ss.
| PARAMETER | DESCRIPTION |
|---|---|
x | TYPE: |
ss | TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
np.ndarray | Node IDs of connected subgraph. |
root ID | ID of the node most proximal to the old root in the connected subgraph. |
Examples:
>>> import navis
>>> n = navis.example_neurons(1)
>>> ends = n.nodes[n.nodes.type.isin(['end', 'root'])].node_id.values
>>> sg, root = navis.graph.graph_utils.connected_subgraph(n, ends)
>>> # Since we asked for a subgraph connecting all terminals + root,
>>> # we expect to see all nodes in the subgraph
>>> sg.shape[0] == n.nodes.shape[0]
True
Source code in navis/graph/graph_utils.py
2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 | |
navis.graph.generate_list_of_childs #
Return list of childs.
| PARAMETER | DESCRIPTION |
|---|---|
x | TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
dict |
|
Source code in navis/graph/graph_utils.py
1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 | |
navis.graph.node_label_sorting #
Return nodes ordered by node label sorting according to Cuntz et al., PLoS Computational Biology (2010).
| PARAMETER | DESCRIPTION |
|---|---|
x | TYPE: |
weighted | TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list |
|
Source code in navis/graph/graph_utils.py
2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 | |
navis.graph.segment_lengths #
Get the length of each of many linear segments.
Same as calling navis.segment_length on each segment but builds the node lookup once instead of once per segment.
| RETURNS | DESCRIPTION |
|---|---|
np.ndarray | Length of each segment. |
Source code in navis/graph/graph_utils.py
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 | |
navis.graph.simplify_graph #
Simplify skeleton graph (networkX or igraph).
This function will simplify the graph by keeping only roots, leafs and branch points. Preserves branch lengths (i.e. weights)!
| PARAMETER | DESCRIPTION |
|---|---|
G | TYPE: |
inplace | TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
G | Simplified graph. TYPE: |
Examples:
>>> import navis
>>> n = navis.example_neurons(1, kind='skeleton')
>>> # Simplify skeleton's NetworkX graph representation
>>> G_simp_nx = navis.graph.simplify_graph(n.graph)
>>> # Check that we have the expected number of nodes
>>> assert len(G_simp_nx.nodes) == (n.n_branches + n.n_root + n.n_leafs)
>>> # Simplify skeleton's iGraph graph representation
>>> G_simp_ig = navis.graph.simplify_graph(n.igraph)
>>> # Check that we have the expected number of nodes
>>> assert len(G_simp_ig.vs) == (n.n_branches + n.n_root + n.n_leafs)
Source code in navis/graph/converters.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
navis.graph.skeleton_adjacency_matrix #
Generate adjacency matrix for a skeleton.
| PARAMETER | DESCRIPTION |
|---|---|
x | TYPE: |
sort | TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
pd.DataFrame | Adjacency matrix where rows are nodes and columns are their parents. |
See Also
navis.geodesic_matrix For distances between all points. navis.distal_to Check if a node A is distal to node B. navis.dist_between Get point-to-point geodesic ("along-the-arbor") distances.
Source code in navis/graph/graph_utils.py
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 | |
navis.graph.subset_igraph #
Induce the sub-graph of a neuron's igraph on a set of node IDs.
The igraph equivalent of x.graph.subgraph(keep), but without paying to build the networkx graph. node_id is carried over onto the new vertices.
Source code in navis/graph/graph_utils.py
2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 | |