Indexing CatmaidNeuronLists

A pymaid.CatmaidNeuronList is a subclass of 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

[1]:
skids = pymaid.get_neurons_in_volume('AL_L')
nl = pymaid.get_neurons(skids)
nl.head()
[1]:
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 pymaid.CatmaidNeuronList/navis.NeuronList attributes that return a numpy.array. For example n_nodes, cable_length, soma, etc.

Index using node count

[2]:
subset = nl[nl.n_nodes > 6000]
subset.head()
[2]:
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

[3]:
subset = nl[nl.soma != None]
subset.head()
[3]:
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

[4]:
subset = nl.skid['57499']
subset
[4]:
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

[5]:
subset = nl.skid [[57499, 57479]]
subset
[5]:
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 pymaid.CatmaidNeuronList by a name (i.e. something that can’t be converted into an integer), it will assumed to be a neuron name:

[6]:
subset = nl['PN glomerulus VL1 57500 ML']
subset
[6]:
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 has_annotation() function. This is something unique to CatmaidNeuronList and won’t work with navis.NeuronList.

[7]:
subset = nl.has_annotation('LH_DONE', intersect=False)
subset.head()
[7]:
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

pymaid.CatmaidNeuronList.has_annotation() allows for some more sophisticated intersections and criteria. For example, leading a string with “~” (tilde), works as a negative indicator:

[8]:
subset = nl.has_annotation('~LH_DONE', intersect=False)
subset.head()
[8]:
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

[9]:
subset = nl.has_annotation(['LH_DONE', 'glomerulus DL1'], intersect=False)
subset.head()
[9]:
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

[10]:
subset = nl.has_annotation(['LH_DONE', 'glomerulus DL1'], intersect=True)
subset.head()
[10]:
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