.. _index_neuronlists: Indexing CatmaidNeuronLists **************************** A :class:`pymaid.CatmaidNeuronList` is a subclass of :class:`navis:navis.NeuronList` and as such behaves similar to pandas DataFrames in that it allow some fancing indexing: To illustrate, let's first get a bunch of neurons .. code:: ipython3 skids = pymaid.get_neurons_in_volume('AL_L') nl = pymaid.get_neurons(skids) nl.head() .. raw:: html
neuron_name skeleton_id n_nodes n_connectors n_branch_nodes n_end_nodes open_ends cable_length review_status soma
0 neuron 4562948 4562947 2 0 0 1 1 3.945403 NA False
1 neuron 7094282 MWP Hogeweg 7094281 4267 64 56 57 42 1537.999647 NA True
2 neuron 8216644 NS 8216643 5934 140 163 166 141 2330.199132 NA False
3 Multiglomerular PN mALT 57431 IJA ECM 57430 5436 205 101 106 87 1389.803214 NA True
4 aSP-g tract 6725720 KMS 6725719 2251 29 79 84 38 842.488107 NA True
Index by attributes +++++++++++++++++++ You can index by all :class:`pymaid.CatmaidNeuronList`/:class:`navis:navis.NeuronList` attributes that return a ``numpy.array``. For example ``n_nodes``, ``cable_length``, ``soma``, etc. Index using node count .. code:: ipython3 subset = nl[nl.n_nodes > 6000] subset.head() .. raw:: html
neuron_name skeleton_id n_nodes n_connectors n_branch_nodes n_end_nodes open_ends cable_length review_status soma
0 Multiglomerular bilateral PN mALT 57435 LK 57434 8582 155 161 168 82 1415.474701 NA True
1 PBG5-EBw-gall (right) neuron 341414 EWN AW 4210786 29397 3107 1886 1955 0 4875.387524 NA True
2 Multiglomerular PN mALT bilateral 57476 IJA 57475 6737 174 192 196 63 1236.637869 NA True
3 putative OA mALT 57480 GA FML 57479 8558 226 202 207 116 1965.510890 NA True
4 PN glomerulus VL1 57500 ML 57499 6551 530 303 322 111 1854.932978 NA True
Subset to neurons that have a soma .. code:: ipython3 subset = nl[nl.soma != None] subset.head() .. raw:: html
neuron_name skeleton_id n_nodes n_connectors n_branch_nodes n_end_nodes open_ends cable_length review_status soma
0 neuron 7094282 MWP Hogeweg 7094281 4267 64 56 57 42 1537.999647 NA True
1 Multiglomerular PN mALT 57431 IJA ECM 57430 5436 205 101 106 87 1389.803214 NA True
2 aSP-g tract 6725720 KMS 6725719 2251 29 79 84 38 842.488107 NA True
3 Multiglomerular bilateral PN mALT 57435 LK 57434 8582 155 161 168 82 1415.474701 NA True
4 PBG5-EBw-gall (right) neuron 341414 EWN AW 4210786 29397 3107 1886 1955 0 4875.387524 NA True
Index by skeleton ID ++++++++++++++++++++ Indexing by skeleton ID(s) uses the ``.skid`` indexer: Index by single skeleton ID .. code:: ipython3 subset = nl.skid['57499'] subset .. raw:: html
type <class 'pymaid.core.CatmaidNeuron'>
neuron_name PN glomerulus VL1 57500 ML
skeleton_id 57499
n_nodes 6551
n_connectors 530
n_branch_nodes 303
n_end_nodes 322
n_open_ends 111
cable_length 1854.93
review_status NA
soma 3247378
Index by list of skeleton IDs .. code:: ipython3 subset = nl.skid [[57499, 57479]] subset .. raw:: html
neuron_name skeleton_id n_nodes n_connectors n_branch_nodes n_end_nodes open_ends cable_length review_status soma
0 putative OA mALT 57480 GA FML 57479 8558 226 202 207 116 1965.510890 NA True
1 PN glomerulus VL1 57500 ML 57499 6551 530 303 322 111 1854.932978 NA True
Index by neuron name ++++++++++++++++++++ If you index a :class:`pymaid.CatmaidNeuronList` by a name (i.e. something that can't be converted into an integer), it will assumed to be a neuron name: .. code:: ipython3 subset = nl['PN glomerulus VL1 57500 ML'] subset .. raw:: html
neuron_name skeleton_id n_nodes n_connectors n_branch_nodes n_end_nodes open_ends cable_length review_status soma
0 PN glomerulus VL1 57500 ML 57499 6551 530 303 322 111 1854.932978 NA True
Index by annotation +++++++++++++++++++ Indexing by annotation(s) uses the :func:`~pymaid.CatmaidNeuronList.has_annotation` function. This is something unique to :class:`~pymaid.CatmaidNeuronList` and won't work with :class:`navis:navis.NeuronList`. .. code:: ipython3 subset = nl.has_annotation('LH_DONE', intersect=False) subset.head() .. raw:: html
neuron_name skeleton_id n_nodes n_connectors n_branch_nodes n_end_nodes open_ends cable_length review_status soma
0 PN glomerulus VL1 57500 ML 57499 6551 530 303 322 111 1854.932978 NA True
1 Multiglomerular PN mALT 57537 LK-NM 57536 14654 1233 850 906 278 3193.380472 NA True
2 PN glomerulus VL1 73938 LK 73937 5273 452 259 274 119 1610.767540 NA True
3 AL.L(DA1) -{mALT}-> CAL.L-LH.L 2319458 PN036 D... 2319457 10209 964 431 458 90 1747.511710 NA True
4 PN glomerulus DA2 2467660 RJVR 2467659 2855 266 54 56 8 726.656270 NA True
:func:`pymaid.CatmaidNeuronList.has_annotation` allows for some more sophisticated intersections and criteria. For example, leading a string with "~" (tilde), works as a *negative* indicator: .. code:: ipython3 subset = nl.has_annotation('~LH_DONE', intersect=False) subset.head() .. raw:: html
neuron_name skeleton_id n_nodes n_connectors n_branch_nodes n_end_nodes open_ends cable_length review_status soma
0 neuron 4562948 4562947 2 0 0 1 1 3.945403 NA False
1 neuron 7094282 MWP Hogeweg 7094281 4267 64 56 57 42 1537.999647 NA True
2 neuron 8216644 NS 8216643 5934 140 163 166 141 2330.199132 NA False
3 Multiglomerular PN mALT 57431 IJA ECM 57430 5436 205 101 106 87 1389.803214 NA True
4 aSP-g tract 6725720 KMS 6725719 2251 29 79 84 38 842.488107 NA True
Index XOR (either or) by multiple annotations .. code:: ipython3 subset = nl.has_annotation(['LH_DONE', 'glomerulus DL1'], intersect=False) subset.head() .. raw:: html
neuron_name skeleton_id n_nodes n_connectors n_branch_nodes n_end_nodes open_ends cable_length review_status soma
0 PN glomerulus VL1 57500 ML 57499 6551 530 303 322 111 1854.932978 NA True
1 Multiglomerular PN mALT 57537 LK-NM 57536 14654 1233 850 906 278 3193.380472 NA True
2 PN glomerulus VL1 73938 LK 73937 5273 452 259 274 119 1610.767540 NA True
3 AL.L(DA1) -{mALT}-> CAL.L-LH.L 2319458 PN036 D... 2319457 10209 964 431 458 90 1747.511710 NA True
4 PN glomerulus DA2 2467660 RJVR 2467659 2855 266 54 56 8 726.656270 NA True
Index XAND (all required) by multiple annotations .. code:: ipython3 subset = nl.has_annotation(['LH_DONE', 'glomerulus DL1'], intersect=True) subset.head() .. raw:: html
neuron_name skeleton_id n_nodes n_connectors n_branch_nodes n_end_nodes open_ends cable_length review_status soma
0 PN glomerulus DL1 5269365 GSXEJ 5269364 3477 893 167 181 58 1228.339971 NA True
1 PN glomerulus DL1 5305038 ARJ 5305037 2818 898 128 138 15 1050.094319 NA True