[HCP functional connectivity - python library]

Dear Neurostars,

we want to run a functional connectivity analysis on the HCP task data. We were about to use the nilearn python library (https://nilearn.github.io/) to calculate functional connectivity. It appears though, that it works on several, but not on the HCP Glasser atlas (360 parcellation). Could somebody suggest a way to do it (if possible) or alternatively propose a library which works on HCP’s Glasser parcellation?

Thanks a lot in advance!

Best
Jasper

2 Likes

You can try to do it manually (in a for loop or with NumPy vectorization) for each pair of the parcels, which are time-series, in fact. Functional connectivity may be based on correlations/autocorrelations/ mutual information or some other technique to find the connectivity. You can try to find those in scipy.stats or statsmodels or scikit-learn

Hope it will help)

1 Like

bump,
we have the same issue. The HCP per-processed used Glasser360 while is it not an available atlas on nilearn and any other python library. I appreciate if someone can help us to either convert Glasser360 to other atlas or find a library to get coordinates for Glasser360 map and visualize it.

I don’t think you need a neuroimaging-specific library to do analyses on pre-parcellated time seres. The most common functional connectivity measure is simply the Pearson correlation: https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.stats.pearsonr.html

3 Likes

Thanks for your help!

We already checked the functional connectivity and just wanted to visualize the brain networks.
So I was wondering if there is a Python library to do so using the Glasser (2016) atlas with 360 parcells. Please see the attached image:

3 Likes

Can you provide more info/code about how you created these images? Trying to visualize what the order/indices of the 360 parcels refer to location-wise. Thanks!

1 Like

The Glasser atlas is a surface-based parcellation, and reprsenting the parcels with a single point in MNI space does not exactly make sense. But it’s possible to calculate the average coordinate of the surface vertices within each region and make a volumetric visualization that way.

I’ve put up a provisional set of coordinates for the Glasser parcels here.

These seem useable, building on the group_fc example in the data loader notebook:

(plotting is from nilearn import plotting)

I may have time to return to this after the Zone 3 tutorials.

8 Likes

This is how we do it :wink:
Thanks to @michaelwaskom we also have the Glasser atlas!

!pip install nilearn

import numpy as np
from nilearn import datasets
from nilearn import input_data
from nilearn.connectome import ConnectivityMeasure
from nilearn import plotting

url = ("https://gist.githubusercontent.com/mwaskom/cb78082d7eede47bed54866fd8cb06b3/raw/9c39627d84c20e65101fff49fe67adb76d6e4155/glasser_coords.txt")
coords = np.loadtxt(url)
connectivity_measure = ConnectivityMeasure(kind='correlation')
correlation_matrix = connectivity_measure.fit_transform([timeseries.T])[0]

# Plot connectivity matrix (use plot_matrix)
plotting.plot_matrix(correlation_matrix, vmin=-1)
plotting.show()
print(correlation_matrix.shape)

# power = datasets.load_mni152_brain_mask()
# coords = np.vstack((power.rois['x'], power.rois['y'], power.rois['z'])).T

plotting.plot_connectome(correlation_matrix, node_coords=coords,edge_threshold='99%', colorbar=True)
plotting.show()

plotting.view_connectome(correlation_matrix, node_coords=coords,edge_threshold='99%')
7 Likes

Wow, that’s exactly what we needed. Thank you very much.
If anyone else has similar issue and couldn’t resolve it, feel free to message me.

2 Likes

I’ll have a solution for plotting parcel-wise statistics on the surface using nilearn in a bit, too

2 Likes

That said, given that this is a course project where learning is more important than results, I’d encourage you not to rely too much on toolboxes for the analyses. (The plotting, sure, but the statistics, maybe not).

2 Likes

that’d be great. thanks a lot.

In the possible projects slides, it’s mentioned on HCP that we can use dimensionality reduction to generate some patterns in the FC correlations in resting state which we can then regress. Does anyone know the idea from using dimensionality reduction while just comparing timeseries correlations for resting state and task?

FYI: Updates to HCP data loader (including visualization)

1 Like