Skip to content

Connectivity preprocessing

Natalia Rozengard edited this page Aug 29, 2018 · 22 revisions

Currently, this tool supports functional connectivity between cortical labels (fMRI/MEG) or invasive electrodes. There are two preprocessing steps that are needed for creating the connectivity files for display: First, you need to preprocess the given modality (fMRI/MEG/electrodes) input files.

Second, process the output of the first step for creating the connectivity files necessary for display:

fMRI connectivity processing

The fMRI preprocessing creates two files, one for each hemisphere: labels_data_(atlas_name}{labels_extract_mode}{hemi}.npz. The files are located in the links/mmvt_blend/subject-name/fmri folder. These npz files include two variables: data (labels_num x T), and names, the labels names. To load them and run a functional connectivity analysis, you should call the connectivity preprocessing module as the following:

python -m src.preproc.connectivity -s subject-name -a atlas-name -f calc_lables_connectivity --connectivity_modality fmri --connectivity_method connectivity-method --windows_length windows-length --windows_shift windows-shift

Where the connectivity-method is the method you want to use to calculate the functional connectivity. The methods that are supported are Pearson correlation (corr) and Phase Lag Index (pli).The calculation will be done using sliding windows, according to the window-length (the length of the windows) and window-shift (the shift in each slide). You can also calculate the coefficient variation of the values by concatenating 'cv' (using a comma) to the connectivity-method. The unit of the length and shift of the windows is the fMRI TR. For example, if your fMRI TR is 3s, windows-length=20 and windows-shift=3, then the length of the windows will be 60s, and the windows shift 9s.

The end result is the following files in the links/mmvt_blend/subject-name/connectivity:

  • fmri_connectivity-method.npy: The numpy matrix, NxNxW, where N is the number of the cortical labels and W is the number of windows.
  • fmri_connectivity-method.npz: The connectivity properties for visualization.
  • fmri_vertices.pkl: The vertices information for visualization.

In case you added cv to the connectivity-method, these files will also be created:

  • fmri_connectivity-method_cv.npy: The coefficient variation of the fmri_connectivity-method matrix.
  • fmri_connectivity-method_cv.npz: The coefficient variation connectivity properties for visualization.
  • fmri_connectivity-method_cv_mean.npy: The mean of the fmri_connectivity-method_cv matrix
  • fmri_connectivity-method_cv_mean.csv: A cortical labels coloring file, which is saved in the ../coloring folder.

For example, if you wish to:

  • Calculate the correlation between the fMRI BOLD signal of the cortical labels time course
  • Where the labels are parcellated according to the Lausanne125 atlas
  • Calculate also the coefficient of variation for each label
  • Use windows length of one minute and shift of 9s, where the TR is 3s

python -m src.preproc.fMRI -s subject-name -a laus125 -f calc_lables_connectivity --connectivity_modality fmri connectivity_method=corr,cv --windows_length 20 --windows_shift 3

If you wish to call this script from code, take a look at the example in src.preproc.examples.connectivity.calc_fmri_connectivity:

from src.preproc import connectivity as con
args = con.read_cmd_args(dict(
    subject=args.subject,
    atlas='laus125',
    function='calc_lables_connectivity',
    connectivity_modality='fmri',
    connectivity_method='corr,cv',
    windows_length=20,
    windows_shift=3
))
con.call_main(args)

MEG connectivity processing

For calculating MEG restings state connectivity, you should call the script like in the fMRI, and set the connectivity_modality to 'meg'. The only difference is the windows_length and windows_shift units, which are ms for MEG. For example, if you wish to:

  • Calculate the phase lag index (PLI) of the cortical labels
  • Parcellated according to the Lausanne125 atlas
  • Calculate, like in the fMRI, the coefficient of variation
  • Find much faster dynamics, 0.5s windows length, and 0.1s windows shift

python -m src.preproc.fMRI -s subject-name -a laus125 -f calc_lables_connectivity --connectivity_modality meg connectivity_method=pli,cv --windows_length 500 --windows_shift 100

To call this function in code you should:

from src.preproc import connectivity as con
args = con.read_cmd_args(dict(
    subject=args.subject,
    atlas='laus125',
    function='calc_lables_connectivity',
    connectivity_modality='meg',
    connectivity_method='pli,cv',
    windows_length=500,
    windows_shift=100
))
con.call_main(args)
You can’t perform that action at this time.