8.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")
2023-07-24 05:10:04,460 - JUNIFER - INFO - ===== Lib Versions =====
2023-07-24 05:10:04,461 - JUNIFER - INFO - numpy: 1.25.1
2023-07-24 05:10:04,461 - JUNIFER - INFO - scipy: 1.11.1
2023-07-24 05:10:04,461 - JUNIFER - INFO - pandas: 1.5.3
2023-07-24 05:10:04,461 - JUNIFER - INFO - nilearn: 0.10.0
2023-07-24 05:10:04,461 - JUNIFER - INFO - nibabel: 4.0.2
2023-07-24 05:10:04,461 - JUNIFER - INFO - junifer: 0.0.3
2023-07-24 05:10:04,461 - 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")
2023-07-24 05:10:04,463 - JUNIFER - INFO - Getting element sub001
2023-07-24 05:10:08,142 - JUNIFER - INFO - Fitting pipeline
2023-07-24 05:10:08,143 - JUNIFER - INFO - Reading BOLD from /tmp/tmpmsyhxuvs/sub001_bold.nii.gz
2023-07-24 05:10:08,143 - JUNIFER - INFO - BOLD is type NIFTI
2023-07-24 05:10:08,144 - JUNIFER - INFO - Reading T1w from /tmp/tmpmsyhxuvs/sub001_T1w.nii.gz
2023-07-24 05:10:08,144 - JUNIFER - INFO - T1w is type NIFTI
2023-07-24 05:10:08,145 - JUNIFER - INFO - Fitting marker Schaefer100x17_RSSETS
2023-07-24 05:10:08,145 - JUNIFER - INFO - Computing BOLD
2023-07-24 05:10:08,145 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2023-07-24 05:10:08,145 - JUNIFER - INFO - Parcellation parameters:
2023-07-24 05:10:08,145 - JUNIFER - INFO -      resolution: 3.0
2023-07-24 05:10:08,145 - JUNIFER - INFO -      n_rois: 100
2023-07-24 05:10:08,146 - JUNIFER - INFO -      yeo_networks: 17
2023-07-24 05:10:08,146 - 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)
2023-07-24 05:10:08,291 - JUNIFER - INFO - Loading parcellation /home/runner/junifer/data/parcellations/schaefer_2018/Schaefer2018_100Parcels_17Networks_order_FSLMNI152_2mm.nii.gz
2023-07-24 05:10:11,446 - JUNIFER - INFO - Storing in <SQLiteFeatureStorage @ /tmp/tmphbgauh9d/test.sqlite (multiple output)>
2023-07-24 05:10:11,490 - JUNIFER - INFO - Fitting marker Schaefer200x17_RSSETS
2023-07-24 05:10:11,491 - JUNIFER - INFO - Computing BOLD
2023-07-24 05:10:11,491 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2023-07-24 05:10:11,491 - JUNIFER - INFO - Parcellation parameters:
2023-07-24 05:10:11,491 - JUNIFER - INFO -      resolution: 3.0
2023-07-24 05:10:11,491 - JUNIFER - INFO -      n_rois: 200
2023-07-24 05:10:11,491 - JUNIFER - INFO -      yeo_networks: 17
2023-07-24 05:10:11,491 - 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)
2023-07-24 05:10:11,648 - JUNIFER - INFO - Loading parcellation /home/runner/junifer/data/parcellations/schaefer_2018/Schaefer2018_200Parcels_17Networks_order_FSLMNI152_2mm.nii.gz
2023-07-24 05:10:13,755 - JUNIFER - INFO - Storing in <SQLiteFeatureStorage @ /tmp/tmphbgauh9d/test.sqlite (multiple output)>
2023-07-24 05:10:13,789 - JUNIFER - INFO - Marker collection fitting done
2023-07-24 05:10:13,790 - JUNIFER - INFO - Collecting data using SQLiteFeatureStorage
2023-07-24 05:10:13,790 - JUNIFER - INFO - Collecting data from /tmp/tmphbgauh9d/*test.sqlite

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

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

file: 1it [00:00, 14.98it/s]
2023-07-24 05:10:13,858 - JUNIFER - INFO - Collect done
{'61d3902439427985464dd546dcdf2b67': {'datagrabber': {'class': 'SPMAuditoryTestingDataGrabber', 'types': ['BOLD', 'T1w']}, 'dependencies': {'nilearn': '0.10.0'}, 'datareader': {'class': 'DefaultDataReader'}, 'type': 'BOLD', 'marker': {'agg_method': 'mean', 'agg_method_params': None, 'class': 'RSSETSMarker', 'masks': None, 'name': 'Schaefer100x17_RSSETS', 'parcellation': 'Schaefer100x17'}, '_element_keys': ['subject'], 'name': 'BOLD_Schaefer100x17_RSSETS'}, '42e63896925a3d28cca0d97a6ba11c07': {'datagrabber': {'class': 'SPMAuditoryTestingDataGrabber', 'types': ['BOLD', 'T1w']}, 'dependencies': {'nilearn': '0.10.0'}, 'datareader': {'class': 'DefaultDataReader'}, 'type': 'BOLD', 'marker': {'agg_method': 'mean', 'agg_method_params': None, 'class': 'RSSETSMarker', 'masks': 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.436 seconds)

Gallery generated by Sphinx-Gallery