Nifti surface seed-based FC analyses


Importage

# KF Tools and related imports
from kftools.data import fetch_file
from kftools.nifti import run_surf_seedbasedfc_ana

from nilearn.datasets import fetch_surf_nki_enhanced
from nilearn.surface import load_surf_data
import nibabel as nib

from matplotlib import pyplot as plt
from nilearn.plotting import plot_surf_stat_map

Grab the data

data_dir='.'

fetch_file(data_dir=data_dir, filetype='kp-nii-hbo',
            site='snic', task='rec', subid='sub008', sesid='ses02')
nii_hbo_f = 'snic_sub008_rec_ses02_0920-1711_kp-nii-hbo.nii.gz'

nki_dataset = fetch_surf_nki_enhanced(n_subjects=1)
nki_rsfmri_lh = load_surf_data(nki_dataset['func_left'][0])
nki_rsfmri_rh = load_surf_data(nki_dataset['func_right'][0])

Out:

Dataset created in /home/runner/nilearn_data/nki_enhanced_surface

Downloading data from https://www.nitrc.org/frs/download.php/8470/pheno_nki_nilearn.csv ...
 ...done. (0 seconds, 0 min)
Downloading data from https://www.nitrc.org/frs/download.php/8261/A00028185_rh_preprocessed_fsaverage5_fwhm6.gii ...

Downloaded 19963904 of 42412120 bytes (47.1%,    1.1s remaining) ...done. (2 seconds, 0 min)
Downloading data from https://www.nitrc.org/frs/download.php/8260/A00028185_lh_preprocessed_fsaverage5_fwhm6.gii ...

Downloaded 19333120 of 42402060 bytes (45.6%,    1.2s remaining) ...done. (2 seconds, 0 min)

Plotting function

def do_plot(surf_lh,surf_rh,stat_map_lh,stat_map_rh,sulc_lh,sulc_rh,title='',
            thrs=[.1,.1,.1,.1],vmaxs = [1,1,1,1]):

    fig, ax = plt.subplots(ncols=4, figsize=(18,3),subplot_kw={'projection': '3d'})

    a = ax[0]
    disp = plot_surf_stat_map([vtx_lh,tri_lh], stat_map=stat_map_lh,hemi='left',
                              view='medial', colorbar=True,bg_map=sulc_lh,bg_on_data=True,
                              cmap='cold_hot', threshold=thrs[0],vmax=vmaxs[0],axes=a)
    a = ax[1]
    disp = plot_surf_stat_map([vtx_lh,tri_lh], stat_map=stat_map_lh,hemi='left',
                              view='lateral', colorbar=True,bg_map=sulc_lh,bg_on_data=True,
                              cmap='cold_hot', threshold=thrs[1],vmax=vmaxs[1],axes=a)

    a = ax[2]
    disp = plot_surf_stat_map([vtx_rh,tri_rh], stat_map=stat_map_rh,hemi='right',
                              view='lateral', colorbar=True,bg_map=sulc_rh,bg_on_data=True,
                              cmap='cold_hot', threshold=thrs[2],vmax=vmaxs[2],axes=a)

    a = ax[3]
    disp = plot_surf_stat_map([vtx_rh,tri_rh], stat_map=stat_map_rh,hemi='right',
                              view='medial', colorbar=True,bg_map=sulc_rh,bg_on_data=True,
                              cmap='cold_hot', threshold=thrs[3],vmax=vmaxs[3],axes=a)

    fig.suptitle(title)

Analysis and viz

Run FC analysis

seed_name = b'G_cingul-Post-dorsal';
seed_hemi = 'left'

img = nib.load(nii_hbo_f)
res_hbo = run_surf_seedbasedfc_ana(seed_name,seed_hemi,vol_dat_img=img,radius=12.0)

res_fmri = run_surf_seedbasedfc_ana(seed_name,seed_hemi,
                                    surf_dat_lh=nki_rsfmri_lh,surf_dat_rh=nki_rsfmri_rh)

Out:

Dataset created in /home/runner/nilearn_data/destrieux_surface

Downloading data from https://www.nitrc.org/frs/download.php/9343/lh.aparc.a2009s.annot ...
 ...done. (1 seconds, 0 min)
Downloading data from https://www.nitrc.org/frs/download.php/9342/rh.aparc.a2009s.annot ...
 ...done. (0 seconds, 0 min)
/opt/hostedtoolcache/Python/3.8.13/x64/lib/python3.8/site-packages/nilearn/surface/surface.py:684: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
  return np.asarray([arr.data for arr in gifti_img.darrays]).T.squeeze()
/opt/hostedtoolcache/Python/3.8.13/x64/lib/python3.8/site-packages/scipy/stats/_stats_py.py:4424: ConstantInputWarning: An input array is constant; the correlation coefficient is not defined.
  warnings.warn(stats.ConstantInputWarning(msg))


/opt/hostedtoolcache/Python/3.8.13/x64/lib/python3.8/site-packages/nilearn/surface/surface.py:684: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
  return np.asarray([arr.data for arr in gifti_img.darrays]).T.squeeze()



Plot

(stat_map_lh,stat_map_rh,surf_dat_lh,surf_dat_rh,_,
 vtx_lh,tri_lh,sulc_lh,vtx_rh,tri_rh,sulc_rh,_) = res_hbo
do_plot([vtx_lh,tri_lh],[vtx_rh,tri_rh],stat_map_lh,stat_map_rh,sulc_lh,sulc_rh,title='',
        thrs=[.1,.1,.1,.1],vmaxs=[.4,.4,.4,4])

(stat_map_lh,stat_map_rh,surf_dat_lh,surf_dat_rh,_,
 vtx_lh,tri_lh,sulc_lh,vtx_rh,tri_rh,sulc_rh,_) = res_fmri
do_plot([vtx_lh,tri_lh],[vtx_rh,tri_rh],stat_map_lh,stat_map_rh,sulc_lh,sulc_rh,title='',
        thrs=[.2,.2,.2,.2],vmaxs=[.8,.8,.8,8])
  • eg010r  nifti surf seedfc
  • eg010r  nifti surf seedfc

Total running time of the script: ( 0 minutes 35.462 seconds)

Gallery generated by Sphinx-Gallery