2323# %%
2424import matplotlib .pyplot as plt
2525from nilearn import plotting
26- import pandas as pd
27- import re
2826import seaborn as sns
2927import siibra
3028
3836
3937jubrain = siibra .parcellations .JULICH_BRAIN_CYTOARCHITECTONIC_ATLAS_V3_0_3
4038pmaps = jubrain .get_map (space = "mni152" , maptype = "statistical" )
39+ print (jubrain .publications [0 ]['citation' ])
4140
4241# %%
4342# Obtain definitions and probabilistic maps in MNI asymmetric space of area IFG 44
5352 colorbar = False ,
5453 annotate = False ,
5554 symmetric_cbar = True ,
55+ title = r .name ,
5656 )
57- plt .savefig (f"{ r .key } .png" )
5857
5958# %%
60- # For each of the two brain areas, retrieve average densities of a selection of monogenetic
61- # neurotransmitter receptors, layer-specific distributions of cell bodies, as well as expressions
62- # of a selection of genes coding for these receptors.
59+ # For each of the two brain areas, query for layer-specific distributions of cell bodies.
60+ fig , axs = plt .subplots (1 , len (regions ), sharey = True , figsize = (8 , 2.7 ))
61+ for i , region in enumerate (regions ):
62+ layerwise_cellbody_densities = siibra .features .get (region , "layerwise cell density" )
63+ layerwise_cellbody_densities [0 ].plot (ax = axs [i ], textwrap = 25 )
64+ print (layerwise_cellbody_densities [0 ].urls )
65+ axs [i ].set_ylim (25 , 115 )
6366
64- receptors = ["M1" , "M2" , "M3" , "D1" , "5-HT1A" , "5-HT2" ]
65- genes = ["CHRM1" , "CHRM2" , "CHRM3" , "HTR1A" , "HTR2A" , "DRD1" ]
66- modalities = [
67- ("receptor density fingerprint" , {}, {"receptors" : receptors , "rot" : 90 }),
68- ("layerwise cell density" , {}, {"rot" : 0 }),
69- ("gene expressions" , {"gene" : genes }, {"rot" : 90 }),
70- ]
71- fig , axs = plt .subplots (
72- len (modalities ) + 1 , len (regions ), figsize = (4 * len (regions ), 11 ), sharey = "row"
73- )
74- ymax = [1000 , 150 , None ]
67+ # %%
68+ # Next, retrieve average densities of a selection of monogenetic
69+ # neurotransmitter receptors.
70+ receptors = ["M1" , "M2" , "M3" , "5-HT1A" , "5-HT2" , "D1" ]
71+ fig , axs = plt .subplots (1 , len (regions ), sharey = True , figsize = (8 , 3.5 ))
72+ for i , region in enumerate (regions ):
73+ receptor_fingerprints = siibra .features .get (region , "receptor density fingerprint" )
74+ receptor_fingerprints [0 ].plot (receptors = receptors , ax = axs [i ])
75+ print (receptor_fingerprints [0 ].urls )
76+ axs [i ].set_ylim (0 , 1000 )
77+ axs [i ].title .set_size (12 )
78+ transmitters = [
79+ siibra .vocabularies .RECEPTOR_SYMBOLS [r ]['neurotransmitter' ]['name' ]
80+ for r in receptors
81+ ]
82+ axs [i ].set_xticklabels ([f"{ r } \n ({ n } )" for r , n in zip (receptors , transmitters )])
7583
84+ # %%
85+ # Now, for further insight, query for expressions of a selection of genes coding
86+ # for these receptors.
87+ genes = ["CHRM1" , "CHRM2" , "CHRM3" , "HTR1A" , "HTR2A" , "DRD1" ]
88+ fig , axs = plt .subplots (1 , len (regions ), sharey = True , figsize = (7 , 3 ))
7689for i , region in enumerate (regions ):
77- axs [0 , i ].imshow (plt .imread (f"{ region .key } .png" ))
78- axs [0 , i ].set_title (f'{ region .name .replace ("Area " , "" )} ' )
79- axs [0 , i ].axis ("off" )
80- for j , (modality , kwargs , plotargs ) in enumerate (modalities ):
81- fts = siibra .features .get (region , modality , ** kwargs )
82- assert len (fts ) > 0
83- if len (fts ) > 1 :
84- print (f"More than one feature found for { modality } , { region .name } " )
85- f = fts [0 ]
86- f .plot (ax = axs [j + 1 , i ], ** plotargs )
87- if modality == "receptor density fingerprint" :
88- # add neurotransmitter names to receptor names in xtick labels
89- transmitters = [re .sub (r"(^.*\()|(\))" , "" , n ) for n in f .neurotransmitters ]
90- axs [j + 1 , i ].set_xticklabels (
91- [f"{ r } \n ({ n } )" for r , n in zip (receptors , transmitters )]
92- )
93- if ymax [j ] is not None :
94- axs [j + 1 , i ].set_ylim (0 , ymax [j ])
95- if "std" in axs [j + 1 , i ].yaxis .get_label_text ():
96- axs [j + 1 , i ].set_ylabel (
97- axs [j + 1 , i ].yaxis .get_label_text ().replace ("std" , "std\n " )
98- )
99- axs [j + 1 , i ].set_title (f"{ fts [0 ].modality } " )
100- fig .suptitle ("" )
101- fig .tight_layout ()
90+ gene_expressions = siibra .features .get (region , "gene expressions" , gene = genes )
91+ assert len (gene_expressions ) == 1
92+ gene_expressions [0 ].plot (ax = axs [i ])
93+ axs [i ].title .set_size (11 )
94+ print (gene_expressions [0 ].urls )
10295
10396# %%
10497# For each of the two brain areas, collect functional connectivity profiles referring to
10598# temporal correlation of fMRI timeseries of several hundred subjects from the Human Connectome
10699# Project. We show the strongest connections per brain area for the average connectivity patterns
107- fts = siibra .features .get (regions [0 ], "functional connectivity" )
108- conn = fts [1 ]
109-
110- # aggregate connectivity profiles for first region across subjects
111- D1 = (
112- pd .concat ([c .get_profile (regions [0 ]).data for c in conn ], axis = 1 )
113- .agg (["mean" , "std" ], axis = 1 )
114- .sort_values (by = "mean" , ascending = False )
115- )
116-
117- # aggregate connectivity profiles for second region across subjects
118- D2 = (
119- pd .concat ([c .get_profile (regions [1 ]).data for c in conn ], axis = 1 )
120- .agg (["mean" , "std" ], axis = 1 )
121- .sort_values (by = "mean" , ascending = False )
122- )
100+ fts = siibra .features .get (jubrain , "functional connectivity" )
101+ for cf in fts :
102+ if cf .cohort != "HCP" :
103+ continue
104+ if cf .paradigm == "Resting state (EmpCorrFC concatenated)" :
105+ conn = cf
106+ break
107+ print (conn .urls )
123108
124109
125110# plot both average connectivity profiles to target regions
@@ -132,35 +117,32 @@ def shorten_name(n):
132117 )
133118
134119
135- fig , (a1 , a2 ) = plt .subplots (1 , 2 , sharey = True , figsize = (3.6 * len (regions ), 4.1 ))
136- kwargs = {"kind" : "bar" , "width" : 0.85 , "logy" : True }
137- D1 .iloc [:17 ]["mean" ].plot (
138- ** kwargs , yerr = D1 .iloc [:17 ]["std" ], ax = a1 , ylabel = shorten_name (regions [0 ].name )
139- )
140- D2 .iloc [:17 ]["mean" ].plot (
141- ** kwargs , yerr = D2 .iloc [:17 ]["std" ], ax = a2 , ylabel = shorten_name (regions [1 ].name )
142- )
143- a1 .set_ylabel ("temporal correlation" )
144- a1 .xaxis .set_ticklabels (
145- [shorten_name (t .get_text ()) for t in a1 .xaxis .get_majorticklabels ()]
146- )
147- a2 .xaxis .set_ticklabels (
148- [shorten_name (t .get_text ()) for t in a2 .xaxis .get_majorticklabels ()]
149- )
150- a1 .grid (True )
151- a2 .grid (True )
152- a1 .set_title (regions [0 ].name .replace ("Area " , "" ))
153- a2 .set_title (regions [1 ].name .replace ("Area " , "" ))
120+ plotkwargs = {
121+ "kind" : "bar" ,
122+ "width" : 0.85 ,
123+ "logscale" : True ,
124+ "xlabel" : "" ,
125+ "ylabel" : "temporal correlation" ,
126+ "rot" : 90 ,
127+ "ylim" : (0.3 , 1.1 ),
128+ "capsize" : 2 ,
129+ }
130+ fig , axs = plt .subplots (1 , len (regions ), sharey = True , figsize = (7 , 4.5 ))
131+ for i , region in enumerate (regions ):
132+ plotkwargs ["ax" ] = axs [i ]
133+ conn .plot (region , max_rows = 17 , ** plotkwargs )
134+ axs [i ].xaxis .set_ticklabels ([shorten_name (t .get_text ()) for t in axs [i ].xaxis .get_majorticklabels ()])
135+ axs [i ].set_title (region .name .replace ("Area " , "" ), fontsize = 8 )
136+ axs [i ].grid (True , 'minor' )
154137plt .suptitle ("Functional Connectivity" )
155- plt .tight_layout ()
156138
157139# %%
158140# For both brain areas, sample representative cortical image patches at 1µm
159141# resolution that were automatically extracted from scans of BigBrain sections.
160142# The image patches display clearly the differences in laminar structure of the two regions
161143
162144selected_sections = [4950 , 1345 ]
163- fig , axs = plt .subplots (1 , len (regions ))
145+ fig , axs = plt .subplots (1 , len (regions ), sharey = True )
164146for r , sn , ax in zip (regions , selected_sections , axs ):
165147 # find 1 micron sections intersecting the region
166148 pmap = pmaps .get_volume (r )
@@ -176,6 +158,4 @@ def shorten_name(n):
176158 ax .axis ("off" )
177159 ax .set_title (r .name )
178160
179- plt .tight_layout ()
180-
181161# sphinx_gallery_thumbnail_number = 2
0 commit comments