Rodent fMRI ‐ Generating Seeds for Seed Based Connectivity - CoBrALab/documentation GitHub Wiki
Seed Based Connectivity
Disclaimer: This wiki was created my Marina Broomfield. Please cite this page and give credit when using or copying the following code.
Seed based connectivity (SBC) can be used in fMRI studies to examine the activity across specific regions of interest. Before running SBC the experimenter must have a solid hypothesis for examining predefined regions of interests, otherwise, a whole-brain data driven approach such as group independent component analysis and dual regression are a better approach.
Creating Seeds
First downsmaple the 100 DSURQUE template to 200 microns to match that of the EPI scans with a voxel size of 0.25 0.5 0.25
# 100 DSURQUE template path:
preprocess_outputs/bold_datasink/commonspace_resampled_template/resampled_template.nii.gz
To down sample the template the following code can be run in bash:
module load ANTs
ResampleImage 3 /data/scratch2/marina/experiment1_oct_2023/scanning/functional/run2/preprocess_outputs/bold_datasink/commonspace_resampled_template/resampled_template.nii.gz /data/scratch2/marina/experiment1_oct_2023/make_mask/BOLD_downsampled_200.nii.gz 0.25x0.5x0.25 0 0 6
Next, locate voxel coordinates for each seed by overlaying the BOLD_downsampled_200 template with DSUQUE lables:
Display /data/scratch2/marina/experiment1_oct_2023/make_mask/BOLD_downsampled_200.nii.gz -label /data/scratch2/marina/experiment1_oct_2023/scanning/functional/run2/preprocess_outputs/bold_datasink/commonspace_labels/_scan_info_subject_idC01S015.session1_split_name_sub-C01S015_ses-1_acq-FLASH_T1w/_run_None/sub-C01S015_ses-1_task-rest_acq-EPI_bold_RAS_EPI_anat_labels.nii.gz
After obtaining the desired coordinates for the anatomical region of interest, a spherical seed with a diameter of 0.5mm can be generated. All anatomical areas will have the same seed size to avoid any biases.
module load FSL
fslmaths /data/scratch2/marina/FINALexp/masks/functional/BOLD_downsampled_200.nii.gz -mul 0 -add 1 -roi 12 1 15 1 15 1 0 1 vHIP_point.nii.gz -odt float
fslmaths vHIP_point -kernel sphere .5 -fmean vHIP_sphere -odt float
fslmaths vHIP_sphere.nii.gz -bin vHIP_sphere_mask.nii.gz
Check the seed is around the right anatomical area :
Display seedX /data/scratch2/marina/experiment1_oct_2023/scanning/functional/run2/confound_correction_outputs/confound_correction_datasink/cleaned_timeseries/_split_name_sub-C01S015_ses-1_task-rest_acq-EPI_bold/sub-C01S015_ses-1_task-rest_acq-EPI_bold_RAS_combined_cleaned.nii.gz
To run SBC in RABIES, you will require a single .mnc file containing all the desired seeds. To merge all the seed masks previously generated for each seed, you can run the following code:
fslmerge -a /data/scratch2/marina/FINALexp/scanning/functional/seed_based/merged_seed_masks.nii.gz \
/data/scratch2/marina/FINALexp/scanning/functional/seed_based/seed_masks/dSTR_sphere_mask.nii.gz \
/data/scratch2/marina/FINALexp/scanning/functional/seed_based/seed_masks/FAC_sphere_mask.nii.gz \
/data/scratch2/marina/FINALexp/scanning/functional/seed_based/seed_masks/ICC_sphere_mask.nii.gz \
/data/scratch2/marina/FINALexp/scanning/functional/seed_based/seed_masks/INSU_sphere_mask.nii.gz \
/data/scratch2/marina/FINALexp/scanning/functional/seed_based/seed_masks/MC1_sphere_mask.nii.gz \
/data/scratch2/marina/FINALexp/scanning/functional/seed_based/seed_masks/MC2_sphere_mask.nii.gz \
/data/scratch2/marina/FINALexp/scanning/functional/seed_based/seed_masks/NACC_sphere_mask.nii.gz \
/data/scratch2/marina/FINALexp/scanning/functional/seed_based/seed_masks/RPC_sphere_mask.nii.gz \
/data/scratch2/marina/FINALexp/scanning/functional/seed_based/seed_masks/SMS1_sphere_mask.nii.gz \
/data/scratch2/marina/FINALexp/scanning/functional/seed_based/seed_masks/SMS2_sphere_mask.nii.gz \
/data/scratch2/marina/FINALexp/scanning/functional/seed_based/seed_masks/THAL_sphere_mask.nii.gz \
/data/scratch2/marina/FINALexp/scanning/functional/seed_based/seed_masks/vHIP_sphere_mask.nii.gz
To create a spatial map depicting the anatomical area of interest along with the generated seed you can run the following code in R: Disclaimer: This code was generated by Dr. Yohan Yee and Marina Broomfield please cite appropriately when using it.
library(tidyverse)
library(ggnewscale)
library(scales)
library(png)
library(ggfx)
source("/data/chamal/projects/yohan/projects/2022-11-gene-interpolation/code/functions/plotting_functions.R")
source("/data/chamal/projects/yohan/projects/2022-11-gene-interpolation/code/functions/plotting_functions_labels.R")
#in world coordinates
slices = seq(from=-2, to=1.5, length.out= 4) #-3.4 -1.8 5.5
mask_file= ("/data/scratch2/marina/experiment1_oct_2023/scanning/functional/stats/spatialmaps_sex/spatialMaps_masksub-C01S015_ses-1_task-rest_acq-EPI_bold_RAS_EPI_brain_mask.mnc")
plt_background = prepare_anatomy("/data/scratch2/marina/experiment1_oct_2023/scanning/functional/run2/preprocess_outputs/unbiased_template_datasink/warped_unbiased_template/template_sharpen_shapeupdate_output_warped_image.mnc", 'y', slices)
#anatomical contounrs
# MC1 = 269
#FAC = 264
#MC2= 270
#SMS1 =280
#SMS2 =289
#THAL= 4
#VSTR =17
#DSTAR =17
# VHIP =323
#INSU =266
#RPC =184
#ICC =178
plt_labels = prepare_label_contours("/data/scratch2/marina/FINALexp/scanning/functional/preprocess_outputs/bold_datasink/commonspace_labels/_scan_info_subject_idC01S015.session1_split_name_sub-C01S015_ses-1_acq-FLASH_T1w/_run_None/sub-C01S015_ses-1_task-rest_acq-EPI_bold_RAS_EPI_anat_labels.mnc",slice_axis='y',
slice_axis_coordinates = slices, labels = 323) #c(81,82,269,270,24,26,27,28,29,30,35,37,39,41,169,171,172,173,178,178,182,184,186,188)
#seed contours
# /data/scratch2/marina/experiment1_oct_2023/scanning/functional/run2/seed_based_analysis/seed_masks/dSTR_sphere_mask.mnc
# /data/scratch2/marina/experiment1_oct_2023/scanning/functional/run2/seed_based_analysis/seed_masks/FAC_sphere_mask.mnc
# /data/scratch2/marina/experiment1_oct_2023/scanning/functional/run2/seed_based_analysis/seed_masks/ICC_sphere_mask.mnc
# /data/scratch2/marina/experiment1_oct_2023/scanning/functional/run2/seed_based_analysis/seed_masks/INSU_sphere_mask.mnc
# /data/scratch2/marina/experiment1_oct_2023/scanning/functional/run2/seed_based_analysis/seed_masks/MC1_sphere_mask.mnc
# /data/scratch2/marina/experiment1_oct_2023/scanning/functional/run2/seed_based_analysis/seed_masks/MC2_sphere_mask.mnc
# /data/scratch2/marina/experiment1_oct_2023/scanning/functional/run2/seed_based_analysis/seed_masks/RPC_sphere_mask.mnc
# /data/scratch2/marina/experiment1_oct_2023/scanning/functional/run2/seed_based_analysis/seed_masks/SMS1_sphere_mask.mnc
# /data/scratch2/marina/experiment1_oct_2023/scanning/functional/run2/seed_based_analysis/seed_masks/SMS2_sphere_mask.mnc
# /data/scratch2/marina/experiment1_oct_2023/scanning/functional/run2/seed_based_analysis/seed_masks/THAL_sphere_mask.mnc
# /data/scratch2/marina/FINALexp/scanning/functional/seed_based/seed_masks/NACC_sphere_mask.mnc
#/data/scratch2/marina/FINALexp/scanning/functional/seed_based/seed_masks/vHIP_sphere_mask.mnc
plt_seed_labels <- prepare_label_contours(file= "/data/scratch2/marina/FINALexp/scanning/functional/seed_based/seed_masks/vHIP_sphere_mask.mnc",
slice_axis='y', slice_axis_coordinates = slices,
labels = 1)
plt_bgcontours <- prepare_contours(file="/data/scratch2/marina/FINALexp/scanning/functional/preprocess_outputs/unbiased_template_datasink/warped_unbiased_template/template_sharpen_shapeupdate_output_warped_image.mnc",
slice_axis='y', slice_axis_coordinates = slices,
contour_levels = c(5000, 10000, 15000, 17000, 20000), filter_size = 100)
plt_stats <- ggplot(plt_background$anatomy_df, aes(x =x, y = z)) +
geom_raster(aes(fill=intensity), interpolate = T) +
scale_fill_gradient(low="black", high = "white", guide=FALSE) +
new_scale_fill() +
geom_path(aes(group=interaction(label, obj)), data=plt_labels$contours_df, colour = 'red', linewidth=0.9) + #to plot anatomical outline
geom_path(aes(group=interaction(label, obj)), data=plt_seed_labels$contours_df, colour = 'green', linewidth =0.7) + #for seed analysis
coord_fixed(ratio = 1) +
theme_void() +
theme(plot.background = element_rect(fill = "black"))+
facet_wrap(~ slice_index,ncol = 2) +
labs(title = "Ventral Hippocampus Seed ") +
theme(plot.title = element_text(color= "white", hjust = 0.5,vjust = -5, size = 20, face = "bold", margin = margin(b = 20)),
legend.title = element_text(color='white'),
legend.text = element_text(color='white'),
plot.background = element_rect(colour = "white", size=2.5))
png('/data/scratch2/marina/FINALexp/scanning/functional/seed_based/seed_masks/vHIP.png', width=3180, height = 1347, res=300, bg="transparent") #width=3180, height = 1347
print(plt_stats)
dev.off()
#ggsave('/data/scratch2/marina/experiment1_oct_2023/scanning/functional/run2/FSL_stats/DR/DR_all_MvsF_plot/THAL_all_corrpTest.png', width=3180, height = 1347, units = "px" ,dpi =300, bg="transparent")
plt_background_sagittal = prepare_anatomy("/data/scratch2/marina/experiment1_oct_2023/scanning/functional/run2/preprocess_outputs/unbiased_template_datasink/warped_unbiased_template/template_sharpen_shapeupdate_output_warped_image.mnc", 'x', 0.1)
plt_bgcontours_sagittal <- prepare_contours(file="/data/scratch2/marina/experiment1_oct_2023/scanning/functional/run2/preprocess_outputs/unbiased_template_datasink/warped_unbiased_template/template_sharpen_shapeupdate_output_warped_image.mnc",
mask_file = "/data/scratch2/marina/experiment1_oct_2023/make_mask/exp1_mask.mnc" ,
slice_axis='x', slice_axis_coordinates = 0.1,
contour_levels = c(5000, 10000, 15000, 17000, 20000), filter_size = 100)
brain_slices<- plt_bgcontours_sagittal$contours_df %>%
ggplot(aes(x=y, y=z)) +
geom_path(aes(group=interaction(obj, level)), colour= 'white') + #this will do the outline of the brain anatomy
geom_vline(aes(xintercept=slice),
data=tibble(slice=slices), color='red', lty=1, linewidth=1) +
scale_fill_gradient(low="black", high="white", guide="none") +
scale_x_continuous(expand = c(0,0)) +
scale_y_continuous(expand = c(0,0)) +
coord_fixed() +
theme_void() +
theme(plot.background = element_rect(fill = 'black'),
legend.position="none")
png('/data/scratch2/marina/experiment1_oct_2023/scanning/functional/run2/FSL_stats/DR/DR_all_MvsF_plot/brain_slices.png', width=1632, height = 762, res=300, bg="transparent")
print(brain_slices)
dev.off()
plt_slicekey <- plt_background_sagittal$anatomy_df %>%
ggplot(aes(x=y, y=z)) +
geom_raster(aes(fill=intensity)) +
geom_vline(aes(xintercept=slice),
data=tibble(slice=slices), color='red', lty=1, linewidth=1) +
scale_fill_gradient(low="black", high="white", guide="none") +
scale_x_continuous(expand = c(0,0)) +
scale_y_continuous(expand = c(0,0)) +
coord_fixed() +
theme_void() +
theme(plot.background = element_rect(fill = 'black'))
#png("/tmp/slicekey.png", width=1581, height = 798, res=300)
print(plt_slicekey)
#dev.off()