forked from muhikp/pourmajidian_metabolism-genes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths16_prepare_connectivity_measures.py
More file actions
94 lines (73 loc) · 3.19 KB
/
Copy paths16_prepare_connectivity_measures.py
File metadata and controls
94 lines (73 loc) · 3.19 KB
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
'''
Calculate the SC and FC connectivity measures
using the bctpy package
Author: Moohebat
Date: 28/06/2024
'''
import pickle
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from nilearn.datasets import fetch_atlas_schaefer_2018
from bct import degree, centrality, distance, clustering
from scipy.spatial.distance import squareform, pdist
plt.rcParams['svg.fonttype'] = 'none'
plt.rcParams.update({'font.size': 8})
# path to directories
path_data = './data/'
path_result = './results/'
path_fig = './figures/'
# functional networks for participation coeff
schaefer400 = fetch_atlas_schaefer_2018()
rsn_mapping = []
for row in range(len(schaefer400['labels'])):
rsn_mapping.append(schaefer400['labels'][row].decode('utf-8').split('_')[2])
rsn_mapping = np.array(rsn_mapping)
#############
# sc measures
# binary sc
sc = np.load(path_data+'consensusSC.npy')
# distance
path = path_data+'schaefer_coords/'
coords = np.genfromtxt(path+'Schaefer_400_centres.txt')[:, 1:]
eu_distance = squareform(pdist(coords, metric='euclidean'))
eu = np.mean(eu_distance, axis=1).reshape(-1, 1)
sc_deg = degree.degrees_und(sc).reshape(-1, 1)
sc_between = centrality.betweenness_bin(sc).reshape(-1, 1)
sc_cluster = clustering.clustering_coef_bu(sc).reshape(-1, 1)
sc_dist = distance.distance_bin(sc)
sc_spath = np.mean(sc_dist, axis=1).reshape(-1, 1)
sc_effic = distance.efficiency_bin(sc, local=True,).reshape(-1, 1)
sc_partic = centrality.participation_coef(sc, rsn_mapping,
'undirected').reshape(-1, 1)
# sc measure dataframe
sc_attr = np.concatenate((eu, sc_deg, sc_between, sc_cluster,
sc_spath, sc_effic, sc_partic), axis=1)
sc_df = pd.DataFrame(sc_attr, columns=['euc_dist', 'sc_degree',
'sc_betweenness', 'sc_clustering',
'sc_spath', 'sc_efficiency',
'sc_participation'])
#####################
# fc network measure
fc = np.load(path_data+'haemodynamic_connectivity.npy')
fc_strength = degree.strengths_und(abs(fc)).reshape(-1, 1)
fc_between = centrality.betweenness_wei(abs(1/fc)).reshape(-1, 1)
fc_cluster = clustering.clustering_coef_wu(abs(fc)).reshape(-1, 1)
fc_partic = centrality.participation_coef(abs(fc), rsn_mapping).reshape(-1, 1)
fc_dist, _ = distance.distance_wei(abs(1/fc))
fc_spath = np.mean(fc_dist, axis=1).reshape(-1, 1)
fc_strength_pos, _, _, _ = degree.strengths_und_sign(fc)
fc_partic_pos, _ = centrality.participation_coef_sign(fc, rsn_mapping)
# fc dataframe
fc_attr = np.concatenate((fc_strength, fc_between,
fc_cluster, fc_partic, fc_spath,
fc_strength_pos.reshape(-1,1),
fc_partic_pos.reshape(-1,1)), axis=1)
fc_df = pd.DataFrame(fc_attr, columns=['fc_strength', 'fc_betweenness',
'fc_clustering', 'fc_participation',
'fc_spath', 'fc_strength_pos',
'fc_partic_pos'])
# save
conn_df = pd.concat([sc_df, fc_df], axis=1)
with open(path_data + 'conn_df.pickle', 'wb') as f:
pickle.dump(conn_df, f)