connectomicslab / connectomemapper3

Connectome Mapper 3 is a BIDS App that implements full anatomical, diffusion, resting/state functional MRI, and recently EEG processing pipelines, from raw T1 / DWI / BOLD , and preprocessed EEG data to multi-resolution brain parcellation with corresponding connection matrices.
https://connectome-mapper-3.readthedocs.io
Other
70 stars 29 forks source link

Extracting connectivity matrix from gpickle #218

Closed milad7093 closed 1 year ago

milad7093 commented 1 year ago

Dear Sebastian

I have just gotten some outputs of cmp3 (connectivity matrices) in the gpickle format and need to extract connectivity matrices base on the following parameters: fa mean adc mean number of fibers

Can you help me?

Please help me

Thanks in advance

Best regards,

-Milad

sebastientourbier commented 1 year ago

Dear Milad,

You can do it using the networkx library as follows:

import networx as nx
conn_mats = {}
connectivity_weights = ['FA_mean', 'ADC_mean', 'number_of_fibers']
G = nx.read_gpickle('path/to/connectome.gpickle')
for weight in connectivity_weights:
    conn_mats[weight] = nx.to_numpy_array(G, weight=weight)

which will store in conn_mats['FA_mean'], conn_mats['ADC_mean'], and conn_mats['number_of_fibers'] each of the connectivity matrices.

You can have an example on how to handle the connectome file here in the documentation.

Hope this helps, Best, Seb