-
Notifications
You must be signed in to change notification settings - Fork 1
/
S-3_data_showcase_cammoun.py
174 lines (133 loc) · 7.38 KB
/
S-3_data_showcase_cammoun.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# %%
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from pyls import behavioral_pls
from scipy.stats import zscore, spearmanr
from plot_utils import divergent_green_orange
savefig = False
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# LOAD DATA
###############################################################################
# load genes and gene list
receptor_genes = pd.read_csv('data/receptor_gene_expression_Cammoun2012_250_7N_Freesurfer_Subcortex.csv', index_col=0)
receptor_names = receptor_genes.columns
receptor_list = pd.read_csv('data/receptor_list.csv')
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# RAW DATA PLOT
###############################################################################
# load region names
atlas_regions = pd.read_csv('./data/parcellations/Cammoun2012_7N_Freesurfer_Subcortex_LUT.csv')
# only select scale250 in column scale
atlas_regions = atlas_regions[atlas_regions['scale'] == 'scale250'].iloc[:-1]
# rename label in atlas_info to name and yeo_7 to network
atlas_regions = atlas_regions.rename(columns={'label': 'name', 'yeo_7': 'network'})
atlas_regions = atlas_regions.groupby(['structure', 'network', 'name']).apply(lambda x: x).reset_index(drop=True)
atlas_regions['name_alt'] = atlas_regions['hemisphere'] + '_' + atlas_regions['name']
atlas_regions['network_alt'] = atlas_regions.apply(lambda x: x['name'] if x['structure'] == 'subcortex' else x['network'], axis=1)
atlas_regions['network_alt'] = atlas_regions['hemisphere'] + '_' + atlas_regions['network_alt']
# reorder receptor_genes according to atlas_regions
receptor_genes = receptor_genes.loc[atlas_regions['name_alt']]
# average by network
networks = atlas_regions['network_alt'].unique()
network_genes = {network: receptor_genes.loc[(atlas_regions['network_alt'] == network).values].mean(axis=0) \
for network in networks}
# define network order
network_order = [f'L_{ctx_net}' for ctx_net in ['visual', 'somatomotor',
'dorsal attention', 'ventral attention',
'frontoparietal', 'default mode', 'limbic']] + \
[f'L_{sbctx_net}' for sbctx_net in ['accumbensarea', 'amygdala', 'caudate', 'hippocampus',
'pallidum', 'putamen', 'thalamusproper']]
network_genes = pd.DataFrame(network_genes).T
network_genes = network_genes.loc[network_order]
# load schaefer gene expression order
order = np.load('results/gene_expression_cluster_order.npy')
# swap columns in network_genes to match order
network_genes = network_genes.iloc[:, order]
# plot heatmap
plt.figure(figsize=(5, 11), dpi=200)
sns.heatmap(network_genes.T, cmap=divergent_green_orange(), cbar_kws={'label': 'gene expression', 'shrink': 0.5},
xticklabels=True, yticklabels=True, square=True, linewidths=0.01, linecolor='white', vmin=0, vmax=1)
if savefig:
plt.savefig('./figs/genes_heatmap_cammoun.pdf')
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# SUPPLEMENTARY: COMPARE PCA LOADINGS TO SCHAEFER 400 ATLAS
###############################################################################
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler
from scipy.stats import spearmanr
# load all abagen genes
schaefer = pd.read_csv('data/abagen_gene_expression_Schaefer2018_400_7N_Tian_Subcortex_S4.csv', index_col=0)
cammoun = pd.read_csv('data/abagen_gene_expression_Cammoun2012_250_7N_Freesurfer_Subcortex.csv', index_col=0)
# standardize data columnwise
scaler = StandardScaler()
schaefer_scaled = scaler.fit_transform(schaefer.values)
cammoun_scaled = scaler.fit_transform(cammoun.values)
# fit PCA
schaefer_pca = PCA(n_components=2)
schaefer_pca.fit(schaefer_scaled)
cammoun_pca = PCA(n_components=2)
cammoun_pca.fit(cammoun_scaled)
# compare loadings of gene PCs
schaefer_loadings = schaefer_pca.components_
cammoun_loadings = cammoun_pca.components_
# do four subplots showing a scatterplot of the first two PCs of schaefer and cammoun
fig, axs = plt.subplots(2, 2, figsize=(10, 10), dpi=200)
for i in range(2):
for j in range(2):
# use regplot to show correlation
sns.regplot(x=schaefer_loadings[j], y=cammoun_loadings[i], ax=axs[i, j], color='gray', scatter_kws={'s': 1})
r, p = spearmanr(schaefer_loadings[j], cammoun_loadings[i])
print(f'PC{i+1} vs PC{j+1} r={r:.2f}, p={p:.5e}')
axs[i, j].set_title(f'Loading correlation r={r:.2f}')
axs[i, j].set_xlabel(f'Schaefer PC{j+1} loadings')
axs[i, j].set_ylabel(f'Cammoun PC{i+1} loadings')
# set tight layout
plt.tight_layout()
sns.despine(trim=True)
if savefig:
plt.savefig('./figs/cammoun_schaefer_genes_pca_loadings_correlation.pdf')
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# SUPPLEMENTARY: COMPARE PLS WEIGHTS
###############################################################################
# Load receptor gene expression
cammoun = pd.read_csv('data/receptor_gene_expression_Cammoun2012_250_7N_Freesurfer_Subcortex.csv', index_col=0)
# Load neurosynth
cammoun_ns = pd.read_csv('data/neurosynth/derivatives/Cammoun2012_7N_Freesurfer_Subcortex_neurosynth.csv', index_col=0)
cammoun_ns = cammoun_ns.iloc[:-1] # no brainstem
atlas_regions = pd.read_csv('data/parcellations/Cammoun2012_7N_Freesurfer_Subcortex_LUT.csv')
atlas_regions = atlas_regions[atlas_regions['scale'] == 'scale250']
atlas_regions.set_index('label', inplace=True)
# join hemisphere and label to create label_alt
atlas_regions['label_alt'] = atlas_regions['hemisphere'] + '_' + atlas_regions.index
# rename cammoun_ns index to label_alt
cammoun_ns.index = atlas_regions['label_alt'].iloc[:-1]
# order cammoun_ns according to cammoun index
cammoun_ns = cammoun_ns.loc[cammoun.index]
X = zscore(cammoun_ns.values, axis=0)
Y = zscore(cammoun.values, axis=0)
pls_results = behavioral_pls(X, Y, n_boot=0, n_perm=0, rotate=True, permsamples=None,
permindices=False, test_split=0, seed=0)
schaefer_pls_result = np.load('results/pls_result_Schaefer400_TianS4_HTH.npy', allow_pickle=True).item()
# compare PLS1 weights
r, p = spearmanr(pls_results['x_weights'][:, 0], schaefer_pls_result['x_weights'][:, 0])
print(f'Term map weight correlation r={r:.2f}, p={p:.5e}')
plt.figure(figsize=(5,5),dpi=200)
sns.regplot(x=pls_results['x_weights'][:, 0], y=schaefer_pls_result['x_weights'][:, 0], color='gray', scatter_kws={'s': 10})
plt.title(f'Term maps\nSpearman r={r:.2f}')
plt.xlabel('Weights using anatomical Cammoun atlas')
plt.ylabel('Weights using functional Schaefer atlas')
sns.despine()
if savefig:
plt.savefig('./figs/cammoun_schaefer_pls_weights_terms.pdf')
r, p = spearmanr(pls_results['y_weights'][:, 0], schaefer_pls_result['y_weights'][:, 0])
print(f'Receptor map weight correlation r={r:.2f}, p={p:.5e}')
plt.figure(figsize=(5,5),dpi=200)
sns.regplot(x=pls_results['y_weights'][:, 0], y=schaefer_pls_result['y_weights'][:, 0], color='gray', scatter_kws={'s': 10})
plt.xlabel('Weights using anatomical Cammoun atlas')
plt.ylabel('Weights using functional Schaefer atlas')
plt.title(f'Receptor maps\nSpearman r={r:.2f}')
sns.despine()
if savefig:
plt.savefig('./figs/cammoun_schaefer_pls_weights_receptor.pdf')