How could I do Glasser parcellation on ABIDE-I dataset

Greetings,

I have have thinking about using Glasser parcellation on ABIDE-I dataset. However, there are few hurdles.

There are few atlases already provided by nilearn but the Glasser 360 atlas, is there any script or .nii Glasser atlas which i could use to achieve the task.

Thank you very much.

Regards

Hi @Saqib_Mamoon,

Does this work for you? GitHub - brainspaces/glasser360: 360-node volumetric atlas derived from the multimodal parcellation from Glasser and colleagues

Best,
Steven

1 Like

Thank you sharing, Yes, I think will work for me.

from nilearn.input_data import NiftiLabelsMasker
from nilearn.datasets import fetch_icbm152_2009

mnitemp = fetch_icbm152_2009()

glassermasker = NiftiLabelsMasker(labels_img='Glasser_masker.nii.gz',mask_img=mnitemp['mask'])
glassermasker.fit()


# In[3]:


import numpy as np 



from nilearn.datasets import fetch_abide_pcp
import pandas
import os
df = pandas.read_csv('Phenotypic_V1_0b_preprocessed1.csv', sep='\t')
site_id=np.unique(df['SITE_ID'])
print(site_id)

for S in (site_id): 
    
    data_dir='test'
    #DX_GROUP: 1 is autism, 2 is control
    abidedata_func_normal=fetch_abide_pcp(data_dir=data_dir, n_subjects= None, pipeline='cpac', band_pass_filtering=True, global_signal_regression=True, derivatives=['func_preproc'], quality_checked=True,DX_GROUP=2,SITE_ID=S)
    abidedata_func_autism=fetch_abide_pcp(data_dir=data_dir, n_subjects= None, pipeline='cpac', band_pass_filtering=True, global_signal_regression=True, derivatives=['func_preproc'], quality_checked=True,DX_GROUP=1,SITE_ID=S)

    

    print(len(abidedata_func_normal['func_preproc']))
    print(len(abidedata_func_autism['func_preproc']))

    ## Extaction of time series for normal
    abide_ts=[]
    abide_ts_normal=[]
    for i in range(len(abidedata_func_normal['func_preproc'])):
        ts_nor = glassermasker.transform(imgs=abidedata_func_normal['func_preproc'][i])
        ts_normal = ts_nor
        abide_ts_normal.append(ts_normal)
        abide_ts.append(ts_normal)
   

    ## Extaction of time series for autism
   
    abide_ts_autism=[]
    for i in range(len(abidedata_func_autism['func_preproc'])):
        ts_aut = glassermasker.transform(imgs=abidedata_func_autism['func_preproc'][i])
        ts_autism = ts_aut
        abide_ts_autism.append(ts_autism)
        abide_ts.append(ts_autism)
        
    print(len(abide_ts))
    
    labels=np.concatenate((np.zeros(len(abide_ts_normal)),np.ones(len(abide_ts_autism))))
    print(labels.shape)

   
    np.savez_compressed("site_"+str(S)+"time_series.npz",
                        labels=labels,
                        abide_ts_normal=abide_ts_normal,
                        abide_ts_autism=abide_ts_autism,
                        abide_ts=abide_ts
                        )
    shutil.rmtree('test/ABIDE_pcp')

I have this section of the code, and I am running it, the results are not out-yet, the atlas is used to parcellate the data after it is downloaded. Do you think this is the right to do this?
Also I kept the band_pass_filtering=True, global_signal_regression=True, is this good in-general?

Thanks!

This isn’t the right solution, it didn’t work. is there any other script which will do the work?

You are welcome to use the MNI 2009c asymmetric volume space version of the Glasser atlas we developed for AFNI. It is distributed by default with AFNI. Some earlier versions had poor alignment with any MNI space.

1 Like

Hi @dglen Thank you for your valuable suggestion. Could you please give an example or how it could be done in python language. Thanks in advance.

from nilearn.maskers import NiftiLabelsMasker
from nilearn.datasets import fetch_icbm152_2009

mnitemp = fetch_icbm152_2009()

glassermasker = NiftiLabelsMasker(labels_img='glasser360MNI.nii.gz',mask_img=mnitemp['mask'])
glassermasker.fit()


# In[3]:


import numpy as np 

count = []
for i in range(0, 360):
    count.append(i)

from nilearn.datasets import fetch_abide_pcp
import pandas
import os
df = pandas.read_csv('Phenotypic_V1_0b_preprocessed1.csv', sep=',')
site_id=np.unique(df['SITE_ID'])
print(site_id)

for S in (site_id): 
    
    data_dir='test'
    #DX_GROUP: 1 is autism, 2 is control
    abidedata_func_normal=fetch_abide_pcp(data_dir=data_dir, n_subjects= None, pipeline='cpac', band_pass_filtering=True, global_signal_regression=True, derivatives=['func_preproc'], quality_checked=True,DX_GROUP=2,SITE_ID=S)
    abidedata_func_autism=fetch_abide_pcp(data_dir=data_dir, n_subjects= None, pipeline='cpac', band_pass_filtering=True, global_signal_regression=True, derivatives=['func_preproc'], quality_checked=True,DX_GROUP=1,SITE_ID=S)

##########################################Normal#########################################################################

    ## Extaction of time series for normal
    abide_ts=[]
    print(abide_ts)
    abide_ts_normal=[]
    filename_normal=[]
    for i in range(len(abidedata_func_normal['func_preproc'])):
        ts_nor = glassermasker.transform(abidedata_func_normal['func_preproc'][i])
        print(abidedata_func_normal['func_preproc'][i])
        filename = os.path.basename(abidedata_func_normal['func_preproc'][i])
        file_name_without_extension = filename[:-7]
        print(file_name_without_extension)
        ts_normal = ts_nor[:,count]
        abide_ts_normal.append(ts_normal)
        abide_ts.append(ts_normal)
        filename_normal.append(file_name_without_extension)
    # Create a directory to store the text files
    text_file_dir = 'Normal'
    if not os.path.exists(os.path.join(S, text_file_dir)):
        os.makedirs(os.path.join(S, text_file_dir))
    # Iterate over the file paths in the list
    for file, name in zip(abide_ts, filename_normal):
        #Convert to dataframe
        df = pd.DataFrame(file)
        # Create a text file for the DataFrame
        text_file_path = os.path.join(S, text_file_dir, '{}.txt'.format(name))
        # Save the DataFrame to the text file
        df.to_csv(text_file_path, index=False, header=False)
   
   
############################################# Autism ########################################################################
   
    ## Extaction of time series for normal
    abide_ts=[]
    print(abide_ts)
    abide_ts_autism=[]
    filename_autism=[]
    for i in range(len(abidedata_func_autism['func_preproc'])):
        ts_nor = glassermasker.transform(abidedata_func_autism['func_preproc'][i])
        print(abidedata_func_autism['func_preproc'][i])
        filename = os.path.basename(abidedata_func_autism['func_preproc'][i])
        file_name_without_extension = filename[:-7]
        print(file_name_without_extension)
        ts_autism = ts_nor[:,count]
        abide_ts_autism.append(ts_autism)
        abide_ts.append(ts_autism)
        filename_autism.append(file_name_without_extension)
    # Create a directory to store the text files
    text_file_dir = 'Autism'
    if not os.path.exists(os.path.join(S, text_file_dir)):
        os.makedirs(os.path.join(S, text_file_dir))
    # Iterate over the file paths in the list
    for file, name in zip(abide_ts, filename_autism):
        #Convert to dataframe
        df = pd.DataFrame(file)
        # Create a text file for the DataFrame
        text_file_path = os.path.join(S, text_file_dir, '{}.txt'.format(name))
        # Save the DataFrame to the text file
        df.to_csv(text_file_path, index=False, header=False)

Could you please guide where to make changes to use “MNI 2009c asymmetric volume space version of the Glasser atlas”, I have this code running.

bundle of thanks!

I expect you would change the NIFTI file that you have been using to MNI_Glasser_HCP_v1.0.nii.gz instead.

1 Like

Hi @dglen Thank you for your guidance. So far what I understand is, The “MNI_Glasser_HCP_v1.0.nii.gz” is already in MNI space, so don’t have to use “mask_img”, so just have to directly apply the “MNI_Glasser_HCP_v1.0.nii.gz” to the data.

Like:

glassermasker = NiftiLabelsMasker(labels_img='MNI_Glasser_HCP_v1.0.nii.gz',mask_img=None)
glassermasker.fit()

and later in my case:

ts_nor = glassermasker.transform(abidedata_func_normal['func_preproc'][i])

Have i got your point right?

Thanks in advance.

I don’t know anything about the calling code here, but there doesn’t seem anything specific to any particular values, so it seems reasonable to try it with our Glasser parcellation in MNI space. I can’t tell what the glassermasker.transform does. It might be useful to find out what you intend to do with the Glasser atlas.