Mouse Connectivity

This notebook demonstrates how to access and manipulate data in the Allen Mouse Brain Connectivity Atlas. The MouseConnectivityCache AllenSDK class provides methods for downloading metadata about experiments, including their viral injection site and the mouse's transgenic line. You can request information either as a Pandas DataFrame or a simple list of dictionaries.

An important feature of the MouseConnectivityCache is how it stores and retrieves data for you. By default, it will create (or read) a manifest file that keeps track of where various connectivity atlas data are stored. If you request something that has not already been downloaded, it will download it and store it in a well known location.


In [41]:
from allensdk.core.mouse_connectivity_cache import MouseConnectivityCache

# The manifest file is a simple JSON file that keeps track of all of
# the data that has already been downloaded onto the hard drives.
# If you supply a relative path, it is assumed to be relative to your
# current working directory.
mcc = MouseConnectivityCache(manifest_file='connectivity/manifest.json')

# open up a list of all of the experiments
all_experiments = mcc.get_experiments(dataframe=True)
print "%d total experiments" % len(all_experiments)

# take a look at what we know about an experiment with a primary motor injection
all_experiments.loc[122642490]


2173 total experiments
Out[41]:
gender                                                                   M
id                                                               122642490
injection-coordinates                                   [4020, 2160, 6870]
injection-structures     [{u'abbreviation': u'MOp', u'color': u'1F9D5A'...
strain                                                               B6.Cg
structure-abbrev                                                       MOp
structure-color                                                     1F9D5A
structure-id                                                           985
structure-name                                          Primary motor area
transgenic-line                                             Syt6-Cre_KI148
Name: 122642490, dtype: object

MouseConnectivityCache has a method for retrieving the adult mouse structure ontology as an Ontology class instance. This is a light wrapper around a Pandas DataFrame of structures that provides some helper methods for figuring out which structures are parents/children of each other. It's also handy for finding the ID of a structure by its acronym.


In [42]:
# grab the Ontology instance
ontology = mcc.get_ontology()

# get some info on the isocortex
isocortex = ontology['Isocortex']
isocortex


Out[42]:
acronym atlas_id color_hex_triplet depth failed failed_facet graph_id graph_order hemisphere_id id ... neuro_name_structure_id neuro_name_structure_id_path ontology_id parent_structure_id safe_name sphinx_id st_level structure_id_path structure_name_facet weight
id
315 Isocortex 746 70FF71 5 False 734881840 1 5 3 315 ... NaN NaN 1 695 Isocortex 6 NaN /997/8/567/688/695/315/ 2323732626 8690

1 rows × 21 columns

On the connectivity atlas web site, you'll see that we show most of our data at a fairly coarse structure level. We did this by creating a "structure set" of ~300 structures. If you want to filter your ontology structures down to that list, you can do this:


In [43]:
from allensdk.api.queries.ontologies_api import OntologiesApi

# get the adult mouse structures summary structures
summary_structures = OntologiesApi().get_structures(structure_set_names='Mouse Connectivity - Summary')

summary_structure_ids = [ s['id'] for s in summary_structures ]

ontology[summary_structure_ids]


Out[43]:
acronym atlas_id color_hex_triplet depth failed failed_facet graph_id graph_order hemisphere_id id ... neuro_name_structure_id neuro_name_structure_id_path ontology_id parent_structure_id safe_name sphinx_id st_level structure_id_path structure_name_facet weight
id
1 TMv 424 FF4C3E 8 False 734881840 1 710 3 1 ... NaN NaN 1 557 Tuberomammillary nucleus ventral part 711 NaN /997/8/343/1129/1097/467/331/557/1/ 3678649713 8690
1027 AUDpo 835 019399 7 False 734881840 1 126 3 1027 ... NaN NaN 1 247 Posterior auditory area 127 NaN /997/8/567/688/695/315/247/1027/ 57661303 8690
4 IC 141 FF7AFF 5 False 734881840 1 746 3 4 ... NaN NaN 1 339 Inferior colliculus 747 NaN /997/8/343/313/339/4/ 3456805092 8690
1029 POL 269 FF909F 7 False 734881840 1 615 3 1029 ... NaN NaN 1 138 Posterior limiting nucleus of the thalamus 616 NaN /997/8/343/1129/549/856/138/1029/ 3921343755 8690
1031 GPi 128 8599CC 6 False 734881840 1 560 3 1031 ... NaN NaN 1 818 Globus pallidus internal segment 561 NaN /997/8/567/623/803/818/1031/ 2033111499 8690
1033 COPY 411 FFFC91 5 False 734881840 1 994 3 1033 ... NaN NaN 1 1073 Copula pyramidis 995 NaN /997/8/512/528/1073/1033/ 2916242466 8690
523 MPO 206 FF5547 6 False 734881840 1 684 3 523 ... NaN NaN 1 141 Medial preoptic area 685 NaN /997/8/343/1129/1097/141/523/ 1992330649 8690
12 IF 142 FFA6FF 6 False 734881840 1 796 3 12 ... NaN NaN 1 165 Interfascicular nucleus raphe 797 NaN /997/8/343/313/348/165/12/ 1057138099 8690
1037 POST 270 48C83C 7 False 734881840 1 488 3 1037 ... NaN NaN 1 822 Postsubiculum 489 NaN /997/8/567/688/695/1089/822/1037/ 2028146433 8690
15 PT 284 FF909F 7 False 734881840 1 636 3 15 ... NaN NaN 1 571 Parataenial nucleus 637 NaN /997/8/343/1129/549/856/571/15/ 1224128658 8690
1041 PFL 412 FFFC91 5 False 734881840 1 998 3 1041 ... NaN NaN 1 1073 Paraflocculus 999 NaN /997/8/512/528/1073/1041/ 775625608 8690
19 IG 143 7ED04B 7 False 734881840 1 452 3 19 ... NaN NaN 1 1080 Induseum griseum 453 NaN /997/8/567/688/695/1089/1080/19/ 2117099319 8690
1044 PP 271 FF8084 6 False 734881840 1 604 3 1044 ... NaN NaN 1 864 Peripeduncular nucleus 605 NaN /997/8/343/1129/549/864/1044/ 4073956777 8690
533 VISpm 915 08858C 7 False 734881840 1 182 3 533 ... NaN NaN 1 669 posteromedial visual area 183 NaN /997/8/567/688/695/315/669/533/ 558797901 8690
534 SUT 349 FFBA86 6 False 734881840 1 835 3 534 ... NaN NaN 1 987 Supratrigeminal nucleus 836 NaN /997/8/343/1065/771/987/534/ 252744374 8690
23 AAA 2 80C0E2 6 False 734881840 1 542 3 23 ... NaN NaN 1 278 Anterior amygdalar area 543 NaN /997/8/567/623/477/278/23/ 4252873038 8690
536 CEA 66 80C0E2 6 False 734881840 1 544 3 536 ... NaN NaN 1 278 Central amygdalar nucleus 545 NaN /997/8/567/623/477/278/536/ 3284898075 8690
1049 FL 413 FFFC91 5 False 734881840 1 1002 3 1049 ... NaN NaN 1 1073 Flocculus 1003 NaN /997/8/512/528/1073/1049/ 1738627181 8690
27 IGL 144 FF909F 7 False 734881840 1 646 3 27 ... NaN NaN 1 1014 Intergeniculate leaflet of the lateral genicul... 647 NaN /997/8/343/1129/549/856/1014/27/ 1900856090 8690
1052 PPN 272 FFA6FF 5 False 734881840 1 794 3 1052 ... NaN NaN 1 348 Pedunculopontine nucleus 795 NaN /997/8/343/313/348/1052/ 2704258246 8690
541 TEa 350 15B0B3 6 False 734881840 1 321 3 541 ... NaN NaN 1 315 Temporal association areas 322 NaN /997/8/567/688/695/315/541/ 2291994334 8690
30 PVa 286 FF5D50 6 False 734881840 1 671 3 30 ... NaN NaN 1 157 Periventricular hypothalamic nucleus anterior ... 672 NaN /997/8/343/1129/1097/157/30/ 4028794868 8690
773 XII 379 FFB3D9 6 False 734881840 1 920 3 773 ... NaN NaN 1 370 Hypoglossal nucleus 921 NaN /997/8/343/1065/354/370/773/ 2567805299 8690
1057 GU 131 009C75 6 False 734881840 1 97 3 1057 ... NaN NaN 1 315 Gustatory areas 98 NaN /997/8/567/688/695/315/1057/ 722362724 8690
35 III 145 FF90FF 5 False 734881840 1 783 3 35 ... NaN NaN 1 323 Oculomotor nucleus 784 NaN /997/8/343/313/323/35/ 3545914074 8690
1061 PPT 273 FF90FF 6 False 734881840 1 780 3 1061 ... NaN NaN 1 1100 Posterior pretectal nucleus 781 NaN /997/8/343/313/323/1100/1061/ 834486063 8690
38 PVH 287 FF5D50 6 False 734881840 1 660 3 38 ... NaN NaN 1 157 Paraventricular hypothalamic nucleus 661 NaN /997/8/343/1129/1097/157/38/ 3443963014 8690
39 ACAd 4 40A666 7 False 734881840 1 209 3 39 ... NaN NaN 1 31 Anterior cingulate area dorsal part 210 NaN /997/8/567/688/695/315/31/39/ 1697985147 8690
7 PSV 283 FFAE6F 6 False 734881840 1 808 3 7 ... NaN NaN 1 1132 Principal sensory nucleus of the trigeminal 809 NaN /997/8/343/1065/771/1132/7/ 977401861 8690
44 ILA 146 59B363 6 False 734881840 1 228 3 44 ... NaN NaN 1 315 Infralimbic area 229 NaN /997/8/567/688/695/315/44/ 1110609938 8690
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
970 PGRNd 828 FFB3D9 7 False 734881840 1 904 3 970 ... NaN NaN 1 938 Paragigantocellular reticular nucleus dorsal part 905 NaN /997/8/343/1065/354/370/938/970/ 33977280 8690
972 PL 262 2FA850 6 False 734881840 1 221 3 972 ... NaN NaN 1 315 Prelimbic area 222 NaN /997/8/567/688/695/315/972/ 1936208719 8690
463 CA3 57 7ED04B 8 False 734881840 1 428 3 463 ... NaN NaN 1 375 Field CA3 429 NaN /997/8/567/688/695/1089/1080/375/463/ 3396545448 8690
612 NLL 217 FFAE6F 6 False 734881840 1 804 3 612 ... NaN NaN 1 1132 Nucleus of the lateral lemniscus 805 NaN /997/8/343/1065/771/1132/612/ 3619563008 8690
978 PGRNl 829 FFB3D9 7 False 734881840 1 905 3 978 ... NaN NaN 1 938 Paragigantocellular reticular nucleus lateral ... 906 NaN /997/8/343/1065/354/370/938/978/ 3947319470 8690
980 PMd 263 FF4C3E 6 False 734881840 1 715 3 980 ... NaN NaN 1 467 Dorsal premammillary nucleus 716 NaN /997/8/343/1129/1097/467/980/ 282623527 8690
982 FC 122 7ED04B 7 False 734881840 1 451 3 982 ... NaN NaN 1 1080 Fasciola cinerea 452 8 /997/8/567/688/695/1089/1080/982/ 2329016707 8690
985 MOp 830 1F9D5A 7 False 734881840 1 15 3 985 ... NaN NaN 1 500 Primary motor area 16 NaN /997/8/567/688/695/315/500/985/ 1852742012 8690
475 MG 200 FF8084 7 False 734881840 1 606 3 475 ... NaN NaN 1 1008 Medial geniculate complex 607 NaN /997/8/343/1129/549/864/1008/475/ 3303425611 8690
135 AMB 16 FFB3D9 6 False 734881840 1 883 3 135 ... NaN NaN 1 370 Nucleus ambiguus 884 NaN /997/8/343/1065/354/370/135/ 1540571580 8690
989 FN 123 FFFDBC 4 False 734881840 1 1010 3 989 ... NaN NaN 1 519 Fastigial nucleus 1011 NaN /997/8/512/519/989/ 960199658 8690
993 MOs 831 1F9D5A 7 False 734881840 1 21 3 993 ... NaN NaN 1 500 Secondary motor area 22 NaN /997/8/567/688/695/315/500/993/ 1043755260 8690
1107 MDRNv 845 FFB3D9 7 False 734881840 1 900 3 1107 ... NaN NaN 1 395 Medullary reticular nucleus ventral part 901 NaN /997/8/343/1065/354/370/395/1107/ 4055979044 8690
483 MH 201 FF909F 7 False 734881840 1 652 3 483 ... NaN NaN 1 958 Medial habenula 653 NaN /997/8/343/1129/549/856/958/483/ 176609275 8690
422 SPFp 335 FF8084 7 False 734881840 1 602 3 422 ... NaN NaN 1 406 Subparafascicular nucleus parvicellular part 603 NaN /997/8/343/1129/549/864/406/422/ 1800790730 8690
998 FS 124 80CDF8 6 False 734881840 1 526 3 998 ... NaN NaN 1 493 Fundus of striatum 527 NaN /997/8/567/623/477/493/998/ 663741194 8690
1002 AUDp 832 019399 7 False 734881840 1 119 3 1002 ... NaN NaN 1 247 Primary auditory area 120 NaN /997/8/567/688/695/315/247/1002/ 760301534 8690
491 MM 202 FF4C3E 7 False 734881840 1 703 3 491 ... NaN NaN 1 331 Medial mammillary nucleus 704 NaN /997/8/343/1129/1097/467/331/491/ 338961468 8690
1004 PMv 266 FF4C3E 6 False 734881840 1 716 3 1004 ... NaN NaN 1 467 Ventral premammillary nucleus 717 NaN /997/8/343/1129/1097/467/1004/ 959948768 8690
177 NR 446 FFB3D9 7 False 734881840 1 908 3 177 ... NaN NaN 1 154 Nucleus of Roller 909 NaN /997/8/343/1065/354/370/154/177/ 2483747197 8690
173 RCH 304 F2483B 6 False 734881840 1 733 3 173 ... NaN NaN 1 290 Retrochiasmatic area 734 NaN /997/8/343/1129/1097/290/173/ 3507634346 8690
1009 fiber tracts 691 CCCCCC 1 False 734881840 1 1013 3 1009 ... NaN NaN 1 997 fiber tracts 1014 NaN /997/1009/ 771268094 8690
1011 AUDd 833 019399 7 False 734881840 1 112 3 1011 ... NaN NaN 1 247 Dorsal auditory area 113 NaN /997/8/567/688/695/315/247/1011/ 2633724239 8690
502 SUB 345 4FC244 7 False 734881840 1 496 3 502 ... NaN NaN 1 822 Subiculum 497 NaN /997/8/567/688/695/1089/822/502/ 3628141206 8690
1017 AN 409 FFFC91 5 False 734881840 1 981 3 1017 ... NaN NaN 1 1073 Ansiform lobule 982 NaN /997/8/512/528/1073/1017/ 3221901529 8690
1018 AUDv 834 019399 7 False 734881840 1 133 3 1018 ... NaN NaN 1 247 Ventral auditory area 134 NaN /997/8/567/688/695/315/247/1018/ 3132221761 8690
507 MOB 204 9AD2BD 6 False 734881840 1 341 3 507 ... NaN NaN 1 698 Main olfactory bulb 342 NaN /997/8/567/688/695/698/507/ 2457606556 8690
1020 PO 268 FF909F 7 False 734881840 1 614 3 1020 ... NaN NaN 1 138 Posterior complex of the thalamus 615 NaN /997/8/343/1129/549/856/138/1020/ 2102251263 8690
1022 GPe 127 8599CC 6 False 734881840 1 559 3 1022 ... NaN NaN 1 818 Globus pallidus external segment 560 NaN /997/8/567/623/803/818/1022/ 3096725950 8690
975 EW 121 FF90FF 5 False 734881840 1 784 3 975 ... NaN NaN 1 323 Edinger-Westphal nucleus 785 NaN /997/8/343/313/323/975/ 3165212518 8690

293 rows × 21 columns

This is how you can filter experiments by transgenic line:


In [44]:
# fetch the experiments that have injections in the isocortex of cre-positive mice
cre_cortical_experiments = mcc.get_experiments(cre=True, 
                                                injection_structure_ids=isocortex['id'])

print "%d Rbp4 cortical experiments" % len(cre_cortical_experiments)

# same as before, but restrict the cre line
rbp4_cortical_experiments = mcc.get_experiments(cre=[ 'Rbp4-Cre_KL100' ], 
                                                injection_structure_ids=isocortex['id'])


print "%d Rbp4 cortical experiments" % len(rbp4_cortical_experiments)


612 Rbp4 cortical experiments
55 Rbp4 cortical experiments

Structure Signal Unionization

The ProjectionStructureUnionizes API data tells you how much signal there was in a given structure and experiment. It contains the density of projecting signal, volume of projecting signal, and other information. MouseConnectivityCache provides methods for querying and storing this data.


In [45]:
# find wild-type injections into primary visual area
visp = ontology['VISp']
visp_experiments = mcc.get_experiments(cre=False, 
                                       injection_structure_ids=visp['id'])

print "%d VISp experiments" % len(visp_experiments)

structure_unionizes = mcc.get_structure_unionizes([ e['id'] for e in visp_experiments ], 
                                                  is_injection=False,
                                                  structure_ids=isocortex['id'])

print "%d VISp non-injection, cortical structure unionizes" % len(structure_unionizes)


32 VISp experiments
27840 VISp non-injection, cortical structure unionizes

In [46]:
structure_unionizes


Out[46]:
hemisphere_id id is_injection max_voxel_density max_voxel_x max_voxel_y max_voxel_z normalized_projection_volume projection_density projection_energy projection_intensity projection_volume experiment_id structure_id sum_pixel_intensity sum_pixels sum_projection_pixel_intensity sum_projection_pixels volume
0 3 466802104 False 1.000000 10140 1490 7680 0.045834 0.067916 120.268000 1770.830 3.666620e-02 180296424 442 1.353400e+11 440712000 5.300370e+10 2.993160e+07 0.539872
1 3 466802595 False 0.361521 4800 2840 8160 0.000149 0.000087 0.031525 361.665 1.192570e-04 180296424 1102 2.371280e+11 1116870000 3.520900e+07 9.735250e+04 1.368160
2 3 466802641 False 0.998660 8120 1830 8920 0.008150 0.138228 157.277000 1137.810 6.519820e-03 180296424 312782624 1.556250e+10 38503800 6.055750e+09 5.322300e+06 0.047167
3 2 466801549 False 0.517563 6530 4610 9600 0.000213 0.007225 3.065770 424.333 1.703020e-04 180296424 849 2.487860e+09 19242000 5.899160e+07 1.390220e+05 0.023571
4 3 466802487 False 0.178821 4740 2960 9310 0.000006 0.000005 0.002624 498.282 5.168790e-06 180296424 950 2.640480e+11 801248000 2.102460e+06 4.219420e+03 0.981529
5 1 466800731 False 0.714281 8310 820 4380 0.004481 0.016841 9.103330 540.531 3.585070e-03 180296424 774 3.999920e+10 173773000 1.581910e+09 2.926590e+06 0.212872
6 1 466800580 False 0.635501 8120 690 4100 0.009341 0.051480 33.828600 657.116 7.472350e-03 180296424 565 3.452200e+10 118490000 4.008330e+09 6.099880e+06 0.145150
7 1 466800912 False 0.700408 4340 2120 5200 0.000733 0.001560 0.734970 471.269 5.865830e-04 180296424 1015 7.725300e+10 307039000 2.256640e+08 4.788430e+05 0.376122
8 1 466800945 False 0.417395 7870 1950 2390 0.000714 0.004476 1.719120 384.104 5.713050e-04 180296424 1062 1.379890e+10 104202000 1.791350e+08 4.663720e+05 0.127647
9 2 466801357 False 1.000000 9830 1760 9280 0.209088 0.106538 135.337000 1270.320 1.672660e-01 180296424 541 4.517480e+11 1281640000 1.734540e+11 1.365440e+08 1.570010
10 2 466801525 False 0.785237 8520 2910 10440 0.006212 0.034698 23.092000 665.518 4.969230e-03 180296424 816 3.698490e+10 116910000 2.699680e+09 4.056520e+06 0.143215
11 3 466802568 False 0.352882 6290 4150 10030 0.000148 0.000221 0.115465 523.065 1.181360e-04 180296424 1058 1.030480e+11 436867000 5.044300e+07 9.643740e+04 0.535162
12 1 466801006 False 0.999915 9700 2100 1680 0.003824 0.082374 91.951400 1116.270 3.058820e-03 180296424 312782578 7.417700e+09 30312900 2.787310e+09 2.496990e+06 0.037133
13 2 466801459 False 0.255427 5860 3090 9440 0.000039 0.000065 0.039638 606.151 3.151540e-05 180296424 702 1.172000e+11 393419000 1.559440e+07 2.572680e+04 0.481938
14 1 466800936 False 0.545816 7720 1510 2050 0.000626 0.001123 0.620849 553.064 5.005410e-04 180296424 1047 1.030480e+11 363993000 2.259850e+08 4.086050e+05 0.445892
15 1 466800462 False 0.412181 3840 2750 2130 0.000165 0.000036 0.008584 238.208 1.317400e-04 180296424 345 8.391130e+11 2984430000 2.561750e+07 1.075430e+05 3.655920
16 2 466801389 False 1.000000 8130 1770 8950 0.054765 0.651217 1497.320000 2299.260 4.381110e-02 180296424 601 9.689360e+10 54918900 8.223110e+10 3.576410e+07 0.067276
17 3 466802355 False 1.000000 9120 430 7000 0.060444 0.251688 588.038000 2336.380 4.835420e-02 180296424 805 1.296370e+11 156832000 9.222330e+10 3.947280e+07 0.192119
18 3 466802448 False 1.000000 9740 2110 2220 0.111439 0.475599 1431.370000 3009.620 8.914880e-02 180296424 902 2.617320e+11 153016000 2.190240e+11 7.277450e+07 0.187445
19 2 466801696 False 0.589572 5050 4670 9120 0.002646 0.001296 0.576712 445.088 2.116400e-03 180296424 1057 2.628800e+11 1333360000 7.689670e+08 1.727670e+06 1.633370
20 2 466801527 False 0.495069 4650 2440 6530 0.001171 0.025503 10.014300 392.675 9.371090e-04 180296424 819 5.166290e+09 29996100 3.003910e+08 7.649870e+05 0.036745
21 2 466801200 False 0.636549 5330 1840 5950 0.025154 0.050278 30.936100 615.299 2.012240e-02 180296424 296 9.273840e+10 326711000 1.010720e+10 1.642640e+07 0.400221
22 1 466800973 False 0.000000 0 0 0 0.000000 0.000000 0.000000 0.000 0.000000e+00 180296424 1106 4.292520e+10 190055000 0.000000e+00 0.000000e+00 0.232817
23 2 466801547 False 0.846486 8400 2500 10000 0.027546 0.054915 38.221200 696.010 2.203590e-02 180296424 847 1.085070e+11 327571000 1.252020e+10 1.798850e+07 0.401275
24 3 466802012 False 0.595259 5520 4980 9230 0.003496 0.011546 6.246480 541.022 2.796390e-03 180296424 314 3.662030e+10 197716000 1.235030e+09 2.282760e+06 0.242202
25 1 466800648 False 0.575121 6330 830 4920 0.000099 0.000027 0.020303 757.162 7.941070e-05 180296424 648 6.836670e+11 2417570000 4.908310e+07 6.482510e+04 2.961530
26 2 466801446 False 0.864219 8670 920 6570 0.081020 0.064046 57.951900 904.844 6.481380e-02 180296424 687 2.660670e+11 826108000 4.787460e+10 5.290920e+07 1.011980
27 2 466801773 False 1.000000 9670 2200 9450 0.191289 0.745494 3466.000000 4649.270 1.530270e-01 180296424 312782636 6.103670e+11 167566000 5.807850e+11 1.249200e+08 0.205269
28 1 466800778 False 0.178543 5680 2530 1320 0.000001 0.000001 0.000282 227.492 6.779390e-07 180296424 838 1.141290e+11 446302000 1.258980e+05 5.534190e+02 0.546720
29 3 466802094 False 1.000000 10030 1850 2190 0.043933 0.051044 57.830300 1132.950 3.514510e-02 180296424 427 1.260440e+11 562062000 3.250420e+10 2.868990e+07 0.688526
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
27810 1 469438008 False 0.000000 0 0 0 0.000000 0.000000 0.000000 0.000 0.000000e+00 304762965 816 1.653280e+10 116910000 0.000000e+00 0.000000e+00 0.143215
27811 2 469439076 False 0.459489 8600 1240 9220 0.025146 0.003110 0.883070 283.950 1.989060e-03 304762965 409 7.073120e+10 522106000 4.610560e+08 1.623720e+06 0.639580
27812 2 469440003 False 0.000000 0 0 0 0.000000 0.000000 0.000000 0.000 0.000000e+00 304762965 312782550 5.150820e+09 38745000 0.000000e+00 0.000000e+00 0.047463
27813 2 469440079 False 0.202515 9380 2660 9460 0.000736 0.000815 0.224985 275.993 5.821670e-05 304762965 312782648 7.267470e+09 58298400 1.311630e+07 4.752380e+04 0.071415
27814 2 469439208 False 0.000000 0 0 0 0.000000 0.000000 0.000000 0.000 0.000000e+00 304762965 540 1.641650e+10 205690000 0.000000e+00 0.000000e+00 0.251970
27815 3 469441870 False 0.020616 5500 1480 9090 0.000013 0.000007 0.001025 145.365 1.050820e-06 304762965 182305693 1.264440e+10 121613000 1.246950e+05 8.578110e+02 0.148976
27816 1 469437808 False 0.000000 0 0 0 0.000000 0.000000 0.000000 0.000 0.000000e+00 304762965 598 3.507420e+09 36933300 0.000000e+00 0.000000e+00 0.045243
27817 2 469439225 False 0.146811 8340 930 7540 0.000234 0.000127 0.032278 253.262 1.849910e-05 304762965 565 1.620310e+10 118490000 3.824590e+06 1.510130e+04 0.145150
27818 1 469438021 False 0.000000 0 0 0 0.000000 0.000000 0.000000 0.000 0.000000e+00 304762965 827 2.813640e+10 210684000 0.000000e+00 0.000000e+00 0.258088
27819 2 469439787 False 0.000000 0 0 0 0.000000 0.000000 0.000000 0.000 0.000000e+00 304762965 1023 5.153460e+10 335030000 0.000000e+00 0.000000e+00 0.410411
27820 2 469439876 False 0.015097 4840 2320 6750 0.000001 0.000002 0.000134 80.000 8.554880e-08 304762965 1085 1.017130e+09 41661900 5.586860e+03 6.983570e+01 0.051036
27821 1 469437507 False 0.089657 9590 2100 2950 0.000043 0.000038 0.006940 181.393 3.420330e-06 304762965 305 6.528450e+09 72981900 5.064700e+05 2.792110e+03 0.089403
27822 1 469437761 False 0.000000 0 0 0 0.000000 0.000000 0.000000 0.000 0.000000e+00 304762965 545 5.032990e+08 6943500 0.000000e+00 0.000000e+00 0.008506
27823 3 469440248 False 0.170834 4470 4760 1650 0.001285 0.000015 0.002798 180.851 1.016150e-04 304762965 95 6.540200e+11 5362290000 1.500180e+07 8.295100e+04 6.568800
27824 2 469439524 False 0.000000 0 0 0 0.000000 0.000000 0.000000 0.000 0.000000e+00 304762965 810 1.591090e+10 129384000 0.000000e+00 0.000000e+00 0.158495
27825 3 469441059 False 0.157981 8880 2050 10110 0.000381 0.000060 0.019188 318.441 3.010690e-05 304762965 527 4.089860e+10 407880000 7.826360e+06 2.457710e+04 0.499653
27826 1 469437178 False 0.000000 0 0 0 0.000000 0.000000 0.000000 0.000 0.000000e+00 304762965 44 9.173870e+10 770998000 0.000000e+00 0.000000e+00 0.944472
27827 2 469439414 False 0.102676 4410 5090 9590 0.000208 0.000062 0.009947 160.151 1.642980e-05 304762965 704 2.258010e+10 215940000 2.147960e+06 1.341210e+04 0.264526
27828 3 469441884 False 0.000000 0 0 0 0.000000 0.000000 0.000000 0.000 0.000000e+00 304762965 312782554 1.753940e+10 142772000 0.000000e+00 0.000000e+00 0.174896
27829 1 469437765 False 0.000000 0 0 0 0.000000 0.000000 0.000000 0.000 0.000000e+00 304762965 556 3.212740e+10 232503000 0.000000e+00 0.000000e+00 0.284817
27830 2 469439195 False 0.157981 8880 2050 10110 0.000379 0.000120 0.038315 319.015 3.000480e-05 304762965 527 2.488420e+10 203940000 7.813870e+06 2.449370e+04 0.249827
27831 2 469439304 False 0.058628 8040 1260 6500 0.000038 0.000065 0.012544 191.803 3.013540e-06 304762965 622 2.285570e+09 37614600 4.718400e+05 2.460030e+03 0.046078
27832 3 469441524 False 0.000000 0 0 0 0.000000 0.000000 0.000000 0.000 0.000000e+00 304762965 893 7.170690e+09 120206000 0.000000e+00 0.000000e+00 0.147252
27833 3 469441572 False 0.710235 7240 5090 10030 0.002244 0.000073 0.027705 377.139 1.774660e-04 304762965 922 1.861460e+11 1972080000 5.463620e+07 1.448700e+05 2.415800
27834 3 469441361 False 0.697775 8390 3010 10560 0.000212 0.000029 0.013508 459.254 1.676350e-05 304762965 755 5.417440e+10 465255000 6.284680e+06 1.368450e+04 0.569937
27835 3 469441142 False 0.000000 0 0 0 0.000000 0.000000 0.000000 0.000 0.000000e+00 304762965 582 4.146330e+10 328088000 0.000000e+00 0.000000e+00 0.401908
27836 1 469437580 False 0.000000 0 0 0 0.000000 0.000000 0.000000 0.000 0.000000e+00 304762965 363 2.919100e+10 203117000 0.000000e+00 0.000000e+00 0.248819
27837 2 469439511 False 0.000000 0 0 0 0.000000 0.000000 0.000000 0.000 0.000000e+00 304762965 800 2.306240e+10 182028000 0.000000e+00 0.000000e+00 0.222984
27838 1 469438137 False 0.000000 0 0 0 0.000000 0.000000 0.000000 0.000 0.000000e+00 304762965 869 2.206210e+09 20761200 0.000000e+00 0.000000e+00 0.025433
27839 2 469439450 False 0.930085 2710 4330 6030 0.003920 0.000419 3.089020 7372.700 3.100840e-04 304762965 746 7.987390e+10 604155000 1.866250e+09 2.531300e+05 0.740090

27840 rows × 19 columns

This is a rather large table, even for a relatively small number of experiments. You can filter it down to a smaller list of structures like this.


In [47]:
dense_unionizes = structure_unionizes[ structure_unionizes.projection_density > .5 ]
large_unionizes = dense_unionizes[ dense_unionizes.volume > .5 ]
large_structures = ontology[large_unionizes.structure_id]

print "%d large, dense, cortical, non-injection unionizes, %d structures" % ( len(large_unionizes), len(large_structures) )

print large_structures.name

large_unionizes


23 large, dense, cortical, non-injection unionizes, 8 structures
id
33                  Primary visual area, layer 6a
312782628                         Postrhinal area
417                     Rostrolateral visual area
425                    Posterolateral visual area
312782574                 Laterointermediate area
22           Posterior parietal association areas
409                           Lateral visual area
669                                  Visual areas
Name: name, dtype: object
Out[47]:
hemisphere_id id is_injection max_voxel_density max_voxel_x max_voxel_y max_voxel_z normalized_projection_volume projection_density projection_energy projection_intensity projection_volume experiment_id structure_id sum_pixel_intensity sum_pixels sum_projection_pixel_intensity sum_projection_pixels volume
39 3 466802085 False 1 9710 2040 1740 0.687285 0.529886 2256.86 4259.15 0.549813 180296424 409 2.068930e+12 847026000 1.911620e+12 448827000 1.037610
219 2 466801771 False 1 9410 2500 9080 0.597458 0.835835 4615.01 5521.43 0.477953 180296424 312782628 2.205160e+12 466797000 2.154270e+12 390166000 0.571827
616 3 466802642 False 1 9790 2150 1700 0.761375 0.523711 2418.87 4618.72 0.609083 180296424 312782628 2.469310e+12 949400000 2.296480e+12 497211000 1.163010
640 3 466802093 False 1 9840 2070 1760 0.385286 0.507268 1933.31 3811.22 0.308221 180296424 425 1.067280e+12 496007000 9.589370e+11 251609000 0.607608
778 2 466801045 False 1 9560 1360 7700 0.493331 0.619365 2160.03 3487.49 0.394654 180296424 33 1.253770e+12 520156000 1.123550e+12 322166000 0.637191
781 2 466801434 False 1 9120 430 7000 4.282840 0.522578 2109.36 4036.45 3.426180 180296424 669 1.258740e+13 5352090000 1.128950e+13 2796880000 6.556300
1385 2 468716555 False 1 9410 2500 9080 0.384089 0.703545 4746.31 6746.28 0.415927 309004492 312782628 2.462820e+12 482602000 2.290580e+12 339533000 0.591188
1672 3 468717338 False 1 9310 2520 9140 0.247361 0.500414 3419.28 6832.92 0.267866 309004492 312782574 1.597700e+12 436971000 1.494130e+12 218666000 0.535289
2282 2 464590260 False 1 7890 1480 8340 0.309360 0.511926 1307.37 2553.82 0.280996 309372716 417 6.881910e+11 448082000 5.858080e+11 229385000 0.548900
2387 2 464589276 False 1 8350 1210 7550 0.341720 0.592527 1758.98 2968.60 0.310390 309372716 33 8.231460e+11 427625000 7.521820e+11 253379000 0.523841
3136 2 464673011 False 1 8410 1810 8790 0.346579 0.576891 2265.98 3927.91 0.366763 307558646 409 1.339100e+12 518986000 1.176010e+12 299399000 0.635758
3874 2 469049369 False 1 7740 1390 8080 0.835746 0.632798 1974.78 3120.72 0.340669 113887162 417 9.587200e+11 439472000 8.678630e+11 278097000 0.538353
4290 2 469048301 False 1 7750 1220 7790 1.092520 0.514036 1456.22 2832.91 0.445337 113887162 22 1.193390e+12 707227000 1.029880e+12 363540000 0.866353
4529 2 464693465 False 1 9410 2500 9080 0.588003 0.525714 1001.53 1905.09 0.310796 307295727 312782628 5.514320e+11 482602000 4.833410e+11 253711000 0.591188
5706 2 464641326 False 1 8600 1320 7920 0.579938 0.562626 2394.80 4256.47 0.329715 307743253 33 1.300680e+12 478391000 1.145650e+12 269155000 0.586029
5870 2 464641791 False 1 8410 1810 8790 0.850793 0.963606 5404.93 5609.06 0.483706 307743253 409 2.229140e+12 409775000 2.214800e+12 394862000 0.501974
6163 2 464612333 False 1 8290 1220 7560 0.364743 0.522912 1668.58 3190.93 0.285784 309113907 33 8.438810e+11 446142000 7.444220e+11 233293000 0.546523
7317 2 468394758 False 1 8420 1780 8810 0.842245 0.643162 1580.56 2457.49 0.411354 307137980 409 9.416340e+11 522107000 8.252220e+11 335799000 0.639581
7332 2 468394191 False 1 8850 1390 7770 0.744679 0.623297 2194.76 3521.20 0.363703 307137980 33 1.143760e+12 476338000 1.045450e+12 296900000 0.583515
8207 2 464668468 False 1 9180 2180 8830 0.606213 0.809194 4200.65 5191.16 0.488059 307321674 409 2.181880e+12 492361000 2.068240e+12 398415000 0.603142
9425 2 464692615 False 1 8620 1880 8830 0.544465 0.575531 1674.43 2909.37 0.361219 307297141 409 1.035320e+12 512349000 8.578950e+11 294873000 0.627627
10145 2 464663987 False 1 9180 2180 8830 0.571475 0.720363 4720.18 6552.50 0.452388 307296433 409 2.571680e+12 512653000 2.419820e+12 369296000 0.628000
12237 2 464626025 False 1 9000 1150 7450 0.700531 0.683128 2361.48 3456.87 0.363209 307593747 33 1.113930e+12 434029000 1.024950e+12 296497000 0.531686

Generating a Projection Matrix

The MouseConnectivityCache class provides a helper method for converting ProjectionStructureUnionize records for a set of experiments and structures into a matrix. This code snippet demonstrates how to make a matrix of projection density values in auditory sub-structures for cre-negative VISp experiments.


In [48]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

visp_experiment_ids = [ e['id'] for e in visp_experiments ]
ctx_children = ontology.get_child_ids( ontology['Isocortex'].id )

pm = mcc.get_projection_matrix(experiment_ids = visp_experiment_ids, 
                               projection_structure_ids = ctx_children,
                               hemisphere_ids= [2], # right hemisphere, ipsilateral
                               parameter = 'projection_density')

row_labels = pm['rows'] # these are just experiment ids
column_labels = [ c['label'] for c in pm['columns'] ] 
matrix = pm['matrix']

fig, ax = plt.subplots(figsize=(15,15))
heatmap = ax.pcolor(matrix, cmap=plt.cm.afmhot)

# put the major ticks at the middle of each cell
ax.set_xticks(np.arange(matrix.shape[1])+0.5, minor=False)
ax.set_yticks(np.arange(matrix.shape[0])+0.5, minor=False)

ax.set_xlim([0, matrix.shape[1]])
ax.set_ylim([0, matrix.shape[0]])          

# want a more natural, table-like display
ax.invert_yaxis()
ax.xaxis.tick_top()

ax.set_xticklabels(column_labels, minor=False)
ax.set_yticklabels(row_labels, minor=False)
plt.show()


Manipulating Grid Data

The MouseConnectivityCache class also helps you download and open every experiment's projection grid data volume. By default it will download 25um volumes, but uou could also download data at other resolutions if you prefer (10um, 50um, 100um).

This demonstrates how you can load the projection density for a particular experiment. It also shows how to download the template volume to which all grid data is registered. Voxels in that template have been structurally annotated by neuroanatomists and stored in a separate annotation volume image.


In [49]:
experiment_id = 181599674

# projection density: number of projecting pixels / voxel volume
pd, pd_info = mcc.get_projection_density(experiment_id)

# injection density: number of projecting pixels in injection site / voxel volume
ind, ind_info = mcc.get_injection_density(experiment_id)

# injection fraction: number of pixels in injection site / voxel volume
inf, inf_info = mcc.get_injection_fraction(experiment_id)

# data mask:
# binary mask indicating which voxels contain valid data
dm, dm_info = mcc.get_data_mask(experiment_id)

template, template_info = mcc.get_template_volume()
annot, annot_info = mcc.get_annotation_volume()

print pd_info
print pd.shape, template.shape, annot.shape






{'space origin': [0.0, 0.0, 0.0], 'space directions': [[25.0, 0.0, 0.0], [0.0, 25.0, 0.0], [0.0, 0.0, 25.0]], 'sizes': [528, 320, 456], 'space': 'left-posterior-superior', 'encoding': 'gzip', 'keyvaluepairs': {}, 'endian': 'little', 'kinds': ['domain', 'domain', 'domain'], 'type': 'float', 'dimension': 3}
(528, 320, 456) (528, 320, 456) (528, 320, 456)

Once you have these loaded, you can use matplotlib see what they look like.


In [50]:
# compute the maximum intensity projection of the projection density
pd_mip = pd.max(axis=0)
ind_mip = ind.max(axis=0)
inf_mip = inf.max(axis=0)
dm_mip = dm.min(axis=0)

# show that slice of all volumes side-by-side
f, ((ax1, ax2, ax3), (ax4, ax5, ax6)) = plt.subplots(2, 3, figsize=(15, 6))

ax1.imshow(pd_mip, cmap='hot', aspect='equal')
ax1.set_title("projection density MaxIP")

ax2.imshow(ind_mip, cmap='hot', aspect='equal')
ax2.set_title("injection density MaxIP")

ax3.imshow(inf_mip, cmap='hot', aspect='equal')
ax3.set_title("injection fraction MaxIP")

# pick a slice to show
slice_idx = 264

ax4.imshow(template[slice_idx,:,:], cmap='gray', aspect='equal', vmin=template.min(), vmax=template.max())
ax4.set_title("registration template")

ax5.imshow(annot[slice_idx,:,:], cmap='gray', aspect='equal', vmin=0, vmax=2000)
ax5.set_title("annotation volume")

ax6.imshow(dm_mip, cmap='hot', aspect='equal', vmin=0, vmax=1)
ax6.set_title('data mask MinIP')


Out[50]:
<matplotlib.text.Text at 0x10da779d0>

The MouseConnectivityCache also provides you with a way to compute and store structure masks. A structure mask is a numpy array that tells you if a voxel belongs to a particular structure.

How is this different from the annotation volume? The annotation volume assigns each voxel a single label, usually one that is at the bottom of the structure ontology. You won't find a single voxel labeled 'Isocortex' in the annotation volume, but there are many voxels that are labeled as descendants of the Isocortex. MouseConnectivityCache can compute for you a mask of voxels that are labeled as any of the descendants of a structure.

Careful. Computing masks is a time-consuming task!


In [51]:
isocortex_mask, _ = mcc.get_structure_mask(isocortex['id'])

# pull out the values of all voxels in the isocortex mask
isocortex_pd = pd[isocortex_mask > 0]

# print out the average projection density of voxels in the isocortex
print isocortex_pd.mean()


0.0194974