Skip to content

Commit

Permalink
20240706 from cogitate-msp1/fmri@master
Browse files Browse the repository at this point in the history
  • Loading branch information
nbonacchi committed Jul 26, 2024
1 parent af785ea commit 179b917
Show file tree
Hide file tree
Showing 126 changed files with 46,846 additions and 1 deletion.
558 changes: 557 additions & 1 deletion README.md

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# About

General information regarding the fMRI analysis pipeline. A comprehensive description of the pipeline and running instructions can be found in `readme.md`

## Information

| | |
| --- | --- |
author_name | *Yamil Vidal<sup>1</sup>, David Richter<sup>1</sup>, Aya Khalaf<sup>2</sup>*
author_email | *<[email protected]>, <[email protected]>, <[email protected]>*
PI_name | *Floris de Lange<sup>1</sup>, Hal Blumenfeld<sup>2</sup>*
affiliation | *<sup>1</sup>Donders Institute for Brain, Cognition and Behaviour, Radboud University Nijmegen, 6500 HB Nijmegen, The Netherlands. <sup>2</sup>Department of Neurology, Yale University School of Medicine, New Haven, CT*
PI_email | *<[email protected]>, <[email protected]>*
programming_language | *Bash, Python, MATLAB*
Is a readme file included with detailed instructions for running the code? | *Yes. readme.md*
Is the environment file provided? | *Yes*
Is there a config file provided to change runtime parameters? | *No*
Does the code run on the sample dataset? | *Yes*
Binary file added decoding/Helvetica.ttf
Binary file not shown.
103 changes: 103 additions & 0 deletions decoding/MSP1_roi_decoding_plots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
"""
Plots ROI accuracy results on a brain surface
Author: Aya Khalaf
Email: [email protected]
Date created: 03-04-2023
"""

import numpy as np
import matplotlib.pyplot as plt
from plotters import plot_time_series, plot_matrix, plot_rasters, plot_brain
import config
import os
import pandas as pd
# get the parameters dictionary
param = config.param

# =================================================================================
# Select whether to apply plotting to category or orientation decoding problems - options 'category' and 'orientation'
decoding_problem = 'category'
#decoding_problem = 'orientation'
#Select within condition decoding or generalization across conditions - options 'within_condition' and 'generalization'
# For orientation decoding, approach should be set to 'within_condition'
approach = 'generalization'
approach = 'within_condition'
# if approach = 'within_condition', the line below selects relevant or irrelevant condition - options 'relevant' and 'irrelevant'
# if approach = 'generalization', the line below selects generalization direction - options 'relevant-irrelevant' and 'irrelevant-relevant'
condition = 'relevant'
condition = 'relevant-irrelevant'
classifier = 'SVM'
# Stimulus categories - options include 'face', 'object', 'letter' , and 'falseFont'
stimulus_categories = ['face', 'object']
stimulus_categories = ['letter', 'falseFont']
#stimulus_categories = ['letter', 'falsefont']
# Number of voxels per ROI (ROI size)
n_voxels = 300
# Chance level (50% for category decoding (binary) and 33.33% for orientation decoding (3-class) )
chance_level = 0.5
csv_dir = os.path.join('/mnt/beegfs/XNAT/COGITATE/fMRI/phase_2/processed/bids/derivatives/decoding/nibetaseries/roi_decoding/',approach, classifier, decoding_problem, stimulus_categories[0] + '_' + stimulus_categories[1] + '_' + str(n_voxels))
if decoding_problem == 'orientation':
condition = 'relevant+irrelevant'
chance_level = 0.33
stimulus_category = 'face'
#stimulus_category = 'object'
#stimulus_category = 'letter'
#stimulus_category = 'falseFont'
csv_dir = os.path.join('/mnt/beegfs/XNAT/COGITATE/fMRI/phase_2/processed/bids/derivatives/decoding/nibetaseries/roi_decoding/', approach, classifier, decoding_problem, stimulus_category + '_' + str(n_voxels))

if decoding_problem == 'category':
vmin=0.5
vmax=0.85
if ((condition=='relevant') | (condition=='irrelevant-relevant')):
cmaps = 'Oranges'
cmap_start = 0.1
cmap_end = 1
elif ((condition == 'irrelevant') | (condition == 'relevant-irrelevant')):
cmaps = 'Purples'
cmap_start = 0.5
cmap_end = 1
elif decoding_problem == 'orientation':
cmaps = 'Purples'
vmin=0.33
vmax=0.40
cmap_start = 0.5
cmap_end = 1

# Plotting brain surface:
acc_values = {'G_front_middle': 0.9, 'Pole_temporal': 0.7, 'G_occipital_middle': 0.6}
#IIT_roi_list = ['GNW','IIT','IIT_excluded', 'IIT_extended', 'G_and_S_frontomargin', 'G_and_S_transv_frontopol', 'G_front_sup', 'G_rectus', 'G_subcallosal', 'S_orbital_lateral', 'S_orbital_med-olfact', 'S_orbital-H_Shaped', 'S_suborbital']
GNW_roi_list = ['G_and_S_cingul-Ant', 'G_and_S_cingul-Mid-Ant', 'G_and_S_cingul-Mid-Post', 'G_front_inf-Opercular', 'G_front_inf-Orbital', 'G_front_inf-Triangul', 'G_front_middle', 'Lat_Fis-ant-Horizont', 'Lat_Fis-ant-Vertical', 'S_front_inf', 'S_front_middle', 'S_front_sup']
# IIT Basic ROI list
IIT_roi_list_1 = ['G_temporal_inf', 'Pole_temporal', 'G_cuneus', 'G_occipital_sup', 'G_oc-temp_med-Lingual', 'Pole_occipital', 'S_calcarine', 'G_and_S_occipital_inf', 'G_occipital_middle', 'G_oc-temp_lat-fusifor', 'G_oc-temp_med-Parahip', 'S_intrapariet_and_P_trans', 'S_oc_middle_and_Lunatus', 'S_oc_sup_and_transversal', 'S_temporal_sup']
roi_list = GNW_roi_list + IIT_roi_list_1

csv_file = os.path.join(csv_dir, 'accuracy_stats_' + condition + '.csv')
save_file= os.path.join(csv_dir, condition + '.eps')
data_df = pd.read_csv(csv_file)
rois = (data_df['ROI']).tolist()
accuracies= (data_df['Average Accuracy']).array
Significance = (data_df['Significance']).array
#Significance[10]=0
#Significance[36]=0
#G_orbital
#Significance[18]=0
#Significance[16]=0
rois_dict = {}
k=0
for roi in rois:
if roi in roi_list:
if Significance[k]:
rois_dict[roi] =accuracies[k]
k=k+1


plot_brain( roi_map=rois_dict, subject='fsaverage', surface='inflated', hemi='lh', sulc_map='curv', parc='aparc.a2009s',
views=['lateral',(90, -30, 0)],cmap_start=cmap_start, cmap_end=cmap_end,
cmap=cmaps, colorbar=True, colorbar_title='ACC', vmin=vmin, vmax=vmax, outline_overlay=True, overlay_method='overlay',
brain_cmap='Greys', brain_alpha=1, save_file=os.path.join(csv_dir, condition + '_lh_outline_30deg.png'))

#roi_map_edge_color = [0, 0, 0] to add borders around rois



97 changes: 97 additions & 0 deletions decoding/MSP1_searchlight_decoding_plots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
"""
Plots searchlight accuracy maps on a brain surface
Author: Aya Khalaf
Email: [email protected]
Date created: 03-04-2023
"""

from plotters import plot_brain
import matplotlib
import matplotlib.pyplot as plt
import os
import config

# Select whether to apply plotting to category or orientation decoding problems - options 'category' and 'orientation'
decoding_problem = 'category'
decoding_problem = 'orientation'
# Select within condition decoding or generalization across conditions - options 'within_condition' and 'generalization'
# For orientation decoding, approach should be set to 'within_condition'
approach = 'generalization'
approach = 'within_condition'
# if approach = 'within_condition', the line below selects relevant or irrelevant condition - options 'relevant' and 'irrelevant'
# if approach = 'generalization', the line below selects generalization direction - options 'relevant-irrelevant' and 'irrelevant-relevant'
# For orientation decoding, no need to change 'condition' as it will be specified at line 40.
condition = 'irrelevant-relevant'
#condition ='relevant'

classifier = 'SVM'

# Stimulus categories - options include 'face', 'object', 'letter' , and 'falseFont'
# For orientation decoding, do not change 'stimulus_categories' here and change line 42 instead.
stimulus_categories = ['face', 'object']
#stimulus_categories = ['letter', 'falseFont']
#stimulus_categories = ['face', 'baseline']
#stimulus_categories = ['object', 'baseline']
#stimulus_categories = ['letter', 'baseline']
#stimulus_categories = ['falseFont', 'baseline']
#stimulus_categories = ['falseFonts', 'baseline']
# Radius of searchlight sphere
searchlight_radius = 4
# Chance level (50% for category decoding (binary) and 33.33% for orientation decoding (3-class) )
chance_level = 0.5

data_dir = os.path.join('/mnt/beegfs/XNAT/COGITATE/fMRI/phase_2/processed/bids/derivatives/decoding/nibetaseries/searchlight_decoding',approach, condition, classifier, str(searchlight_radius) + 'mm', 'category/' + stimulus_categories[0] + '_' + stimulus_categories[1])

if decoding_problem == 'orientation':
condition = 'relevant+irrelevant'
chance_level = 0.33
stimulus_category = 'face'
#stimulus_category = 'object'
#stimulus_category = 'letter'
#stimulus_category = 'falseFont'
data_dir = os.path.join( '/mnt/beegfs/XNAT/COGITATE/fMRI/phase_2/processed/bids/derivatives/decoding/nibetaseries/searchlight_decoding',approach, condition, classifier, str(searchlight_radius) + 'mm', 'Orientation/' + stimulus_category)


if decoding_problem == 'category':
if ((condition == 'relevant') | (condition == 'irrelevant-relevant')):
cmaps = 'Oranges'
cmap_start = 0.1
cmap_end = 1
elif ((condition == 'irrelevant') | (condition == 'relevant-irrelevant')):
cmaps = 'Purples'
cmap_start = 0.5
cmap_end = 1
#plot_brain( surface='inflated', cmap=cmaps, cmap_start=0.5, cmap_end=1, overlays=[os.path.join(data_dir, 'searchlight_group_accuracy_map_nonparametric.nii')], overlay_threshold=0, vmin=chance_level, vmax=0.75, outline_overlay=True, save_file=os.path.join(data_dir, condition + '_' + 'lh_outline.png'))
## for the right side
#plot_brain( surface='inflated', cmap=cmaps, cmap_start=0.5, cmap_end=1, hemi='rh', overlays=[os.path.join(data_dir, 'searchlight_group_accuracy_map_nonparametric.nii')], overlay_threshold=0, vmin=chance_level, vmax=0.75, outline_overlay=True, views=['medial', 'lateral'], save_file=os.path.join(data_dir, condition + '_' + 'rh_outline.png'))
plot_brain( surface='inflated', cmap=cmaps, overlays=[os.path.join(data_dir, 'searchlight_group_accuracy_map_nonparametric.nii')], overlay_threshold=0, vmin=chance_level, vmax=0.75, cmap_start=cmap_start, cmap_end=cmap_end, outline_overlay=True, views=['lateral',(90, -30, 0)], save_file=os.path.join(data_dir, condition + '_' + 'lh_outline_30deg.png'))
## for the right side
plot_brain( surface='inflated', cmap=cmaps, hemi='rh', overlays=[os.path.join(data_dir, 'searchlight_group_accuracy_map_nonparametric.nii')], overlay_threshold=0, vmin=chance_level, vmax=0.75, cmap_start=cmap_start, cmap_end=cmap_end, outline_overlay=True, views=[(-90, 30, 0), 'lateral'], save_file=os.path.join(data_dir, condition + '_' + 'rh_outline_30deg.png'))

elif decoding_problem == 'orientation':
param = config.param
colors = [(1, 1, 1), param['colors']['face']]
cmaps = matplotlib.colors.LinearSegmentedColormap.from_list('Custom', colors, N=128)

"""
plot_brain(surface='inflated', cmap=cmaps, cmap_start=0.5, cmap_end=1,
overlays=[os.path.join(data_dir, 'searchlight_group_accuracy_map_nonparametric.nii')],
overlay_threshold=0, vmin=chance_level, vmax=0.45, outline_overlay=True, views=['lateral', (180, 20, -10)],
save_file=os.path.join(data_dir, 'orientation_lh_inf_outline_posterior.png'))
# for the right side
plot_brain(surface='inflated', cmap=cmaps, cmap_start=0.5, cmap_end=1, hemi='rh',
overlays=[os.path.join(data_dir, 'searchlight_group_accuracy_map_nonparametric.nii')],
overlay_threshold=0, vmin=chance_level, vmax=0.45, outline_overlay=True, views=[(180, 20, -10), 'lateral'],
save_file=os.path.join(data_dir, 'orientation_rh_inf_outline_posterior.png'))
"""
plot_brain(surface='inflated', cmap=cmaps, cmap_start=0.5, cmap_end=1,
overlays=[os.path.join(data_dir, 'searchlight_group_accuracy_map_nonparametric.nii')],
overlay_threshold=0, vmin=chance_level, vmax=0.45, outline_overlay=True, views=['lateral', 'medial'],
save_file=os.path.join(data_dir, 'orientation_lh_inf_outline.png'))
# for the right side
plot_brain(surface='inflated', cmap=cmaps, cmap_start=0.5, cmap_end=1, hemi='rh',
overlays=[os.path.join(data_dir, 'searchlight_group_accuracy_map_nonparametric.nii')],
overlay_threshold=0, vmin=chance_level, vmax=0.45, outline_overlay=True, views=['medial', 'lateral'],
save_file=os.path.join(data_dir, 'orientation_rh_inf_outline.png'))

63 changes: 63 additions & 0 deletions decoding/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
param = {
"font": "helvetica",
"font_size": 22,
"figure_size_mm": [183, 108],
"fig_res_dpi": 300,
"colors": {
"iit": [
0.00392156862745098,
0.45098039215686275,
0.6980392156862745],
"gnw": [
0.00784313725490196,
0.6196078431372549,
0.45098039215686275
],
"task relevant": [
0.8352941176470589,
0.3686274509803922,
0.0
],
"Irrelevant": [
0.5450980392156862,
0.16862745098039217,
0.8862745098039215
],
"face": [
0/255,
53/255,
68/255
],
"object": [
173/255,
80/255,
29/255
],
"letter": [
57/255,
115/255,
132/255
],
"false": [
97/255,
15/255,
0/255
],
"500ms": [
1.0,
0.48627450980392156,
0.0
],
"1000ms": [
0.6235294117647059,
0.2823529411764706,
0.0
],
"1500ms": [
1.0,
0.7686274509803922,
0.0
],
"cmap": "RdYlBu_r"
}
}
Binary file added decoding/mni_icbm152_t1_tal_nlin_asym_09c.nii
Binary file not shown.
Loading

0 comments on commit 179b917

Please sign in to comment.