7.5. Extracting root sum of squares from edge-wise timeseries.#

This example uses a RSSETSMarker to compute root sum of squares of the edge-wise timeseries using the Schaefer parcellation (100 rois and 200 rois, 17 Yeo networks) for a 4D nifti BOLD file.

Authors: Leonard Sasse, Sami Hamdan, Nicolas Nieto, Synchon Mandal

License: BSD 3 clause

import tempfile

import junifer.testing.registry  # noqa: F401
from junifer.api import collect, run
from junifer.storage import SQLiteFeatureStorage
from junifer.utils import configure_logging

Set the logging level to info to see extra information:

configure_logging(level="INFO")
2022-12-20 14:34:24,518 - JUNIFER - INFO - ===== Lib Versions =====
2022-12-20 14:34:24,518 - JUNIFER - INFO - numpy: 1.23.5
2022-12-20 14:34:24,518 - JUNIFER - INFO - scipy: 1.9.3
2022-12-20 14:34:24,518 - JUNIFER - INFO - pandas: 1.5.2
2022-12-20 14:34:24,518 - JUNIFER - INFO - nilearn: 0.9.2
2022-12-20 14:34:24,518 - JUNIFER - INFO - nibabel: 4.0.2
2022-12-20 14:34:24,518 - JUNIFER - INFO - junifer: 0.0.1
2022-12-20 14:34:24,518 - JUNIFER - INFO - ========================

Define the datagrabber interface

datagrabber = {
    "kind": "SPMAuditoryTestingDatagrabber",
}

Define the markers interface

markers = [
    {
        "name": "Schaefer100x17_RSSETS",
        "kind": "RSSETSMarker",
        "parcellation": "Schaefer100x17",
    },
    {
        "name": "Schaefer200x17_RSSETS",
        "kind": "RSSETSMarker",
        "parcellation": "Schaefer200x17",
    },
]

Create a temporary directory for junifer feature extraction: At the end you can read the extracted data into a pandas.DataFrame.

with tempfile.TemporaryDirectory() as tmpdir:
    # Define the storage interface
    storage = {
        "kind": "SQLiteFeatureStorage",
        "uri": f"{tmpdir}/test.sqlite",
    }
    # Run the defined junifer feature extraction pipeline
    run(
        workdir=tmpdir,
        datagrabber=datagrabber,
        markers=markers,
        storage=storage,
        elements=["sub001"],  # we calculate for one subject only
    )
    # Collect extracted features data
    collect(storage=storage)
    # Create storage object to read in extracted features
    db = SQLiteFeatureStorage(uri=storage["uri"])

    # List all the features
    print(db.list_features())
    # Read extracted features
    df_vbm = db.read_df(feature_name="BOLD_Schaefer100x17_RSSETS")
2022-12-20 14:34:24,519 - JUNIFER - INFO - Getting element sub001
2022-12-20 14:34:27,685 - JUNIFER - INFO - Fitting pipeline
2022-12-20 14:34:27,685 - JUNIFER - INFO - Reading BOLD from /tmp/tmp8gd0w1t5/sub001_bold.nii.gz
2022-12-20 14:34:27,686 - JUNIFER - INFO - BOLD is type NIFTI
2022-12-20 14:34:27,687 - JUNIFER - INFO - Reading T1w from /tmp/tmp8gd0w1t5/sub001_T1w.nii.gz
2022-12-20 14:34:27,687 - JUNIFER - INFO - T1w is type NIFTI
2022-12-20 14:34:27,688 - JUNIFER - INFO - Fitting marker Schaefer100x17_RSSETS
2022-12-20 14:34:27,688 - JUNIFER - INFO - Computing BOLD
2022-12-20 14:34:27,688 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2022-12-20 14:34:27,688 - JUNIFER - INFO - Parcellatikon parameters:
2022-12-20 14:34:27,688 - JUNIFER - INFO -      n_rois: 100
2022-12-20 14:34:27,688 - JUNIFER - INFO -      yeo_networks: 17
2022-12-20 14:34:27,688 - JUNIFER - INFO -      resolution: 3.0
2022-12-20 14:34:27,688 - JUNIFER - INFO - At least one of the parcellation files are missing. Fetching using nilearn.
Downloading data from https://raw.githubusercontent.com/ThomasYeoLab/CBIG/v0.14.3-Update_Yeo2011_Schaefer2018_labelname/stable_projects/brain_parcellation/Schaefer2018_LocalGlobal/Parcellations/MNI/Schaefer2018_100Parcels_17Networks_order.txt ...
 ...done. (0 seconds, 0 min)
Downloading data from https://raw.githubusercontent.com/ThomasYeoLab/CBIG/v0.14.3-Update_Yeo2011_Schaefer2018_labelname/stable_projects/brain_parcellation/Schaefer2018_LocalGlobal/Parcellations/MNI/Schaefer2018_100Parcels_17Networks_order_FSLMNI152_2mm.nii.gz ...
 ...done. (0 seconds, 0 min)
2022-12-20 14:34:27,850 - JUNIFER - INFO - Loading parcellation /home/runner/junifer/data/parcellations/schaefer_2018/Schaefer2018_100Parcels_17Networks_order_FSLMNI152_2mm.nii.gz
2022-12-20 14:34:31,276 - JUNIFER - INFO - Storing in <SQLiteFeatureStorage @ /tmp/tmp07ywouc7/test.sqlite (multiple output)>
2022-12-20 14:34:31,306 - JUNIFER - INFO - Fitting marker Schaefer200x17_RSSETS
2022-12-20 14:34:31,306 - JUNIFER - INFO - Computing BOLD
2022-12-20 14:34:31,307 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2022-12-20 14:34:31,307 - JUNIFER - INFO - Parcellatikon parameters:
2022-12-20 14:34:31,307 - JUNIFER - INFO -      n_rois: 200
2022-12-20 14:34:31,307 - JUNIFER - INFO -      yeo_networks: 17
2022-12-20 14:34:31,307 - JUNIFER - INFO -      resolution: 3.0
2022-12-20 14:34:31,307 - JUNIFER - INFO - At least one of the parcellation files are missing. Fetching using nilearn.
Downloading data from https://raw.githubusercontent.com/ThomasYeoLab/CBIG/v0.14.3-Update_Yeo2011_Schaefer2018_labelname/stable_projects/brain_parcellation/Schaefer2018_LocalGlobal/Parcellations/MNI/Schaefer2018_200Parcels_17Networks_order.txt ...
 ...done. (0 seconds, 0 min)
Downloading data from https://raw.githubusercontent.com/ThomasYeoLab/CBIG/v0.14.3-Update_Yeo2011_Schaefer2018_labelname/stable_projects/brain_parcellation/Schaefer2018_LocalGlobal/Parcellations/MNI/Schaefer2018_200Parcels_17Networks_order_FSLMNI152_2mm.nii.gz ...
 ...done. (0 seconds, 0 min)
2022-12-20 14:34:31,469 - JUNIFER - INFO - Loading parcellation /home/runner/junifer/data/parcellations/schaefer_2018/Schaefer2018_200Parcels_17Networks_order_FSLMNI152_2mm.nii.gz
2022-12-20 14:34:33,968 - JUNIFER - INFO - Storing in <SQLiteFeatureStorage @ /tmp/tmp07ywouc7/test.sqlite (multiple output)>
2022-12-20 14:34:34,003 - JUNIFER - INFO - Marker collection fitting done
2022-12-20 14:34:34,004 - JUNIFER - INFO - Collecting data using SQLiteFeatureStorage
2022-12-20 14:34:34,004 - JUNIFER - INFO - Collecting data from /tmp/tmp07ywouc7/*test.sqlite

file: 0it [00:00, ?it/s]

feature:   0%|          | 0/2 [00:00<?, ?it/s]
feature: 100%|##########| 2/2 [00:00<00:00, 46.29it/s]

file: 1it [00:00, 15.97it/s]
2022-12-20 14:34:34,068 - JUNIFER - INFO - Collect done
{'76d87c5c1e936aeb2df95400767134ef': {'datagrabber': {'class': 'SPMAuditoryTestingDatagrabber', 'types': ['BOLD', 'T1w']}, 'dependencies': {'nilearn': '0.9.2'}, 'datareader': {'class': 'DefaultDataReader'}, 'type': 'BOLD', 'marker': {'agg_method': 'mean', 'agg_method_params': None, 'class': 'RSSETSMarker', 'mask': None, 'name': 'Schaefer100x17_RSSETS', 'parcellation': 'Schaefer100x17'}, '_element_keys': ['subject'], 'name': 'BOLD_Schaefer100x17_RSSETS'}, 'ba261e032ab21eda639cf47af4ed4b9f': {'datagrabber': {'class': 'SPMAuditoryTestingDatagrabber', 'types': ['BOLD', 'T1w']}, 'dependencies': {'nilearn': '0.9.2'}, 'datareader': {'class': 'DefaultDataReader'}, 'type': 'BOLD', 'marker': {'agg_method': 'mean', 'agg_method_params': None, 'class': 'RSSETSMarker', 'mask': None, 'name': 'Schaefer200x17_RSSETS', 'parcellation': 'Schaefer200x17'}, '_element_keys': ['subject'], 'name': 'BOLD_Schaefer200x17_RSSETS'}}

Now we take a look at the dataframe

root_sum_of_squares_ets
subject timepoint
sub001 0 1439.862751
1 79.140510
2 46.187470
3 72.499142
4 49.109437


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

Gallery generated by Sphinx-Gallery