forked from dagush/WholeBrain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DecoEtAl2020_Fig2DEF.py
91 lines (76 loc) · 3.47 KB
/
DecoEtAl2020_Fig2DEF.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
# ==========================================================================
# ==========================================================================
# Plots Figure 2.D-E-F in the paper
#
# --------------------------------------------------------------------------
#
# Taken from the code (read_gain.m) from:
# [DecoEtAl_2021] Gustavo Deco, Kevin Aquino, Aurina Arnatkeviciute, Stuart Oldham, Kristina Sabaroedin,
# Nigel Rogasch, Morten L. Kringelbach, and Alex Fornito, "Dynamical consequences of regional heterogeneity
# in the brain’s transcriptional landscape", 2020, biorXiv
# https://doi.org/10.1101/2020.10.28.359943
#
# Code by Gustavo Deco and Kevin Aquino
# Translated to Python & refactoring by Gustavo Patow
# ==========================================================================
# ==========================================================================
import numpy as np
import scipy.io as sio
import matplotlib.pyplot as plt
from pathlib import Path
def plotData(fig, DataFitt, title, pos, optim):
Values = DataFitt.reshape(grid[0].shape)
ax = fig.add_subplot(spec[pos*2])
plot = ax.pcolormesh(Betas, Alphas, Values.T)
ax.invert_yaxis()
plt.colorbar(plot, ax=ax, cmap=plt.get_cmap(name)) # label="Number of regions"
ax.set_ylabel("Bias (B)")
ax.set_title(title)
ax = fig.add_subplot(spec[pos*2+1])
AOptim = np.where(np.isclose(Alphas, optim[0]))
plot = ax.plot(Betas, (Values[:,AOptim]).flatten())
ax.set_ylabel("Level")
ax.set_xlabel("Heterogeneity Scaling (Z)")
# return ax
# baseInPath = 'Data_Raw/DecoEtAl2020'
baseOutPath = 'Data_Produced/DecoEtAl2020'
filePath = baseOutPath + '/DecoEtAl2020_fittingBZ.mat'
if not Path(filePath).is_file():
import DecoEtAl2020_Fitting_genes_balanced_gain as fitting
fitting.Fitting()
print('Loading {}'.format(filePath))
fNeuro = sio.loadmat(filePath)
Alphas = fNeuro['Alphas'].flatten()
Betas = fNeuro['Betas'].flatten()
swFCDfitt = fNeuro['swFCDfitt'].flatten()
FCfitt = fNeuro['FCfitt'].flatten()
GBCfitt = fNeuro['GBCfitt'].flatten()
grid = np.meshgrid(Alphas,Betas)
grid = np.round(grid[0],3), np.round(grid[1],3)
flatGrid = [a for a in np.nditer(grid)]
maxFC = flatGrid[np.argmax(FCfitt)]
minFCD = flatGrid[np.argmin(swFCDfitt)]
maxGBC = flatGrid[np.argmax(GBCfitt)]
print("\n\n#####################################################################################################")
print(f"# Max FC({maxFC}) = {np.max(FCfitt)}")
print(f"# Max swGBC({maxGBC}) = {np.max(GBCfitt)}")
print(f"# Min swFCD({minFCD}) = {np.min(swFCDfitt)}")
print("#####################################################################################################\n\n")
plt.rcParams.update({'font.size': 12})
# fig, axs = plt.subplots(3, 1)
fig = plt.figure(constrained_layout=True)
# widths = [2, 3, 1.5]
heights = [3, 1, 3, 1, 3, 1]
spec = fig.add_gridspec(ncols=1, nrows=6, # width_ratios=widths,
height_ratios=heights,
hspace=1)
name = 'YlGnBu'
plotData(fig, GBCfitt, "GBC", 0, maxGBC)
plotData(fig, FCfitt, "FC", 1, maxFC)
plotData(fig, swFCDfitt, "swFCD", 2, minFCD)
# axs[0].title("swFCD")
# plt.legend()
plt.show()
# ================================================================================================================
# ================================================================================================================
# ================================================================================================================EOF