Skip to content

Commit 0eb406a

Browse files
committed
Update analysis scripts
1 parent 20a7726 commit 0eb406a

9 files changed

+60
-108
lines changed

src/analyses/03_atrophyAssociation.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,19 @@ def load_multi_tle():
2525
"""
2626
return util.load_data(
2727
"../../data/processed/multi_tle_data.npz",
28-
["age", "sex", "group", "focus", "ct"],
28+
["age", "sex", "focus", "ct"],
2929
)
3030

3131

3232
# Main analysis
3333
def main():
3434
load_dataset = {"local": load_local_tle, "multi": load_multi_tle}
3535
for key in load_dataset:
36+
37+
print("------------------------")
38+
print(f"Dataset: {key}")
39+
print("------------------------")
40+
3641
# Load LTE data
3742
age, sex, focus, ct = load_dataset[key]()
3843

src/analyses/04_epicentreAssociation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def main():
99
"network"
1010
)
1111

12-
for site in ["local", "multi"]:
12+
for site in ["multi"]: #["local", "multi"]:
1313
print("------------------------")
1414
print(f"Dataset: {site}")
1515
print("------------------------")

src/analyses/s01_subcorticalCorrelation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def main():
8383
print(f"{sctx}: r = {r[i]}, r-squared = {r2[i]}, p = {p[i]}")
8484

8585
global_association = pd.DataFrame(
86-
{"subcortical": subcortical, "r": r, "r2": r2, "p": p}
86+
{"subcortical": subcortical.keys(), "r": r, "r2": r2, "p": p}
8787
)
8888

8989
print()

src/analyses/s02_igeSpecificity.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def main():
3737
x = util.zscore_flip(ct, group, "HC", "_")
3838
covar = pd.DataFrame({"age": age, "sex": sex})
3939

40-
slm = util.casecontrol_difference(x, covar, group, "C", "X")
40+
slm = util.casecontrol_difference(x, covar, group, "HC", "IGE")
4141
atrophy["ige"] = slm
4242

4343
print()

src/analyses/s03_psychiatryAtrophySpecificity.py

+8-16
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,12 @@ def load_psychiatry():
1919
the cohen's D effect size from the summary statistics for that condition.
2020
"""
2121
atrophy = {
22-
"adhd": load_summary_stats("adhd")["CortThick_case_vs_controls_adult"]["d_icv"],
23-
"asd": load_summary_stats("asd")["CortThick_case_vs_controls_meta_analysis"][
24-
"d_icv"
25-
],
26-
"bd": load_summary_stats("bipolar")["CortThick_case_vs_controls_adult"][
27-
"d_icv"
28-
],
29-
"mdd": load_summary_stats("depression")["CortThick_case_vs_controls_adult"][
30-
"d_icv"
31-
],
32-
"ocd": load_summary_stats("ocd")["CortThick_case_vs_controls_adult"]["d_icv"],
33-
"scz": load_summary_stats("schizophrenia")["CortThick_case_vs_controls"][
34-
"d_icv"
35-
],
22+
"adhd": load_summary_stats("adhd")["CortThick_case_vs_controls_adult"]["d_icv"].to_numpy(),
23+
"asd": load_summary_stats("asd")["CortThick_case_vs_controls_meta_analysis"]["d_icv"].to_numpy(),
24+
"bd": load_summary_stats("bipolar")["CortThick_case_vs_controls_adult"]["d_icv"].to_numpy(),
25+
"mdd": load_summary_stats("depression")["CortThick_case_vs_controls_adult"]["d_icv"].to_numpy(),
26+
"ocd": load_summary_stats("ocd")["CortThick_case_vs_controls_adult"]["d_icv"].to_numpy(),
27+
"scz": load_summary_stats("schizophrenia")["CortThick_case_vs_controls"]["d_icv"].to_numpy(),
3628
}
3729

3830
return atrophy
@@ -44,7 +36,7 @@ def main():
4436
atrophy = load_psychiatry()
4537

4638
# Load imaging genetic result
47-
imaging_genetics = util.load_imaging_genetic("regional")
39+
imaging_genetics = util.load_imaging_genetic("regional").t
4840

4941
association = {}
5042
print("----------------------")
@@ -54,7 +46,7 @@ def main():
5446
print()
5547
print(f"{psy}")
5648
print("----------------------")
57-
r, p, null = util.spatial_correlation(atrophy[psy], imaging_genetics.t)
49+
r, p, null = util.spatial_correlation(atrophy[psy], imaging_genetics)
5850

5951
association[psy] = {"r": r, "p": p, "null": null}
6052

src/analyses/s04_psychiatryEpicentreSpecificity.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ def main():
8282
print("Save results")
8383
print("------------")
8484
util.save_to_pickle(
85-
"../../data/results/s04_psychiatricEpicentreSpecificity/psychiatric_epicentre.pkl",
85+
"../../data/results/s04_psychiatryEpicentreSpecificity/psychiatric_epicentre.pkl",
8686
{"epicentre": epicentre},
8787
)
8888

8989
util.save_to_pickle(
90-
"../../data/results/s04_psychiatricsEpicentreSpecificity/psychiatric_association.pkl",
90+
"../../data/results/s04_psychiatryEpicentreSpecificity/psychiatric_association.pkl",
9191
{"association": association},
9292
)
9393

src/analyses/s05_thresholdConsistency.py

+38-69
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,33 @@ def load_abcd():
2121
)
2222

2323

24-
def load_local_tle():
24+
def load_multi_tle():
2525
"""
26-
Load local TLE (EpiC x MICs x NKG) data
26+
Load multisite TLE (ENIGMA) data
2727
2828
Returns:
29-
numpy.ndarray: The loaded data containing age, sex, dataset, focus, and ct information.
29+
numpy.ndarray: The loaded data containing age, sex, dataset, group, focus, and ct information.
3030
"""
3131
return util.load_data(
32-
"../../data/processed/local_tle_data.npz",
33-
["age", "sex", "dataset", "focus", "ct"],
32+
"../../data/processed/multi_tle_data.npz",
33+
["age", "sex", "focus", "ct"],
34+
)
35+
36+
37+
def load_multi_ige():
38+
"""
39+
Load multisite IGE (ENIGMA) data
40+
41+
Returns:
42+
numpy.ndarray: The loaded data containing age, sex, dataset, group, focus, and ct information.
43+
"""
44+
return util.load_data(
45+
"../../data/processed/multi_ige_data.npz",
46+
["age", "sex", "group", "ct"],
3447
)
3548

3649

50+
3751
# Main analysis
3852
def main():
3953
# Load data
@@ -72,30 +86,7 @@ def main():
7286

7387
# Lobe indices
7488
lobe_names = ["whole", "frontal", "limbic", "occipital", "parietal", "temporal"]
75-
frontal = [
76-
17,
77-
18,
78-
25,
79-
16,
80-
22,
81-
2,
82-
26,
83-
10,
84-
12,
85-
30,
86-
15,
87-
46,
88-
64,
89-
60,
90-
49,
91-
44,
92-
59,
93-
52,
94-
50,
95-
56,
96-
36,
97-
51,
98-
]
89+
frontal = [17, 18, 25, 16, 22, 2, 26, 10, 12, 30, 15, 46, 64, 60, 49, 44, 59, 52, 50, 56, 36, 51,]
9990
limbic = [8, 21, 1, 24, 33, 58, 35, 55, 42, 67]
10091
occipital = [11, 19, 9, 3, 45, 53, 37, 43]
10192
parietal = [20, 27, 29, 6, 23, 54, 61, 40, 63, 57]
@@ -182,49 +173,27 @@ def main():
182173
print("Comparison to case-control atrophy")
183174
print("----------------------------------")
184175
# Generate atrophy for each site:
185-
age, sex, dataset, focus, ct = load_local_tle()
186-
local_tle_atrophy = util.load_result(
187-
"../../data/results/03_atrophyAssociation/local_atrophy.pkl", ["atrophy"]
176+
epilepsy_atrophy = {}
177+
178+
multi_tle_atrophy = util.load_result(
179+
"../../data/results/03_atrophyAssociation/multi_atrophy.pkl", ["atrophy"]
188180
)[0]
189-
# Combined
190-
tle_atrophy = {}
191-
tle_atrophy["lh_all"] = local_tle_atrophy["ltle"]
192-
tle_atrophy["rh_all"] = local_tle_atrophy["rtle"]
193-
194-
# Across different datasets
195-
for d in ["EpiC", "MICs"]:
196-
dataset_idx = dataset == d
197-
dataset_ct = ct[dataset_idx, :]
198-
dataset_age = age[dataset_idx]
199-
dataset_sex = sex[dataset_idx]
200-
dataset_focus = focus[dataset_idx]
201-
202-
x = util.zscore_flip(dataset_ct, dataset_focus, "C", "R")
203-
for hemi in ["L", "R"]:
204-
covar = pd.DataFrame({"age": dataset_age, "sex": dataset_sex})
205-
tle_atrophy[f"{hemi.lower()}h_{d.lower()}"] = util.casecontrol_difference(
206-
x, covar, dataset_focus, "C", hemi
207-
)
208-
209-
print(f"{d} atrophy done")
210-
211-
site_labels = [
212-
"lh_all",
213-
"lh_epic",
214-
"lh_mics",
215-
"rh_all",
216-
"rh_epic",
217-
"rh_mics",
218-
]
219-
atrophy_similarity_r = np.zeros((len(thresholds), len(site_labels)))
220-
atrophy_similarity_p = np.zeros((len(thresholds), len(site_labels)))
181+
epilepsy_atrophy["ltle"] = multi_tle_atrophy["ltle"]
182+
epilepsy_atrophy["rtle"] = multi_tle_atrophy["rtle"]
183+
184+
multi_ige_atrophy = util.load_result(
185+
"../../data/results/s02_igeSpecificity/ige_atrophy.pkl", ["atrophy"]
186+
)[0]
187+
epilepsy_atrophy["ige"] = multi_ige_atrophy["ige"]
188+
189+
atrophy_similarity_r = np.zeros((len(thresholds), len(epilepsy_atrophy)))
190+
atrophy_similarity_p = np.zeros((len(thresholds), len(epilepsy_atrophy)))
221191
for i in range(len(thresholds)):
222192
map1 = regional_association[thresholds[i]]
223-
for site in site_labels:
224-
map2 = tle_atrophy[site]
225-
atrophy_similarity_r[i, j], atrophy_similarity_p[i, j], _ = (
226-
util.spatial_correlation(map1.t, map2.t, n_rot=5000)
227-
)
193+
for j, subtype in enumerate(epilepsy_atrophy):
194+
map2 = epilepsy_atrophy[subtype]
195+
atrophy_similarity_r[i, j], atrophy_similarity_p[i, j], _ = util.spatial_correlation(map1.t, map2.t, n_rot=5000)
196+
228197

229198
print()
230199
print("Save results")

src/analyses/s06_epicentreConsistency.py

+2-16
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,6 @@
22
import utilities as util
33

44

5-
# Helper functions
6-
def load_abcd():
7-
"""
8-
Load abcd data
9-
10-
Returns:
11-
numpy.ndarray: The loaded data containing age, sex, dataset, focus, and ct information.
12-
"""
13-
return util.load_data(
14-
"../../data/processed/abcd_data.npz",
15-
["age", "sex", "site", "pc10", "thresh", "prs_all", "ct_vertex", "ct_aparc"],
16-
)
17-
18-
195
# Main analysis
206
def main():
217
print("------------------------------------------")
@@ -33,9 +19,9 @@ def main():
3319
]
3420

3521
regional_association = util.load_result(
36-
"../../data/results/s01_thresholdConsistency/threshold_regional_association.pkl",
22+
"../../data/results/s05_thresholdConsistency/threshold_regional_association.pkl",
3723
["regional_association"],
38-
)
24+
)[0]
3925

4026
fc_ctx, fc_sctx, sc_ctx, sc_sctx = util.load_connectomes()
4127

src/datasets.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def main():
254254
print("Thickness data")
255255
print("-------------------------")
256256
multi_ige_ct = pd.read_csv("../data/raw/multi_ige_ct.csv", index_col="participant")
257-
ct = np.transpose(multi_ige_ct.to_numpy())
257+
ct = multi_ige_ct.to_numpy()
258258

259259
print()
260260
print("Save data")

0 commit comments

Comments
 (0)