Note
Click here to download the full example code
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-03-31 13:29:47,546 - JUNIFER - INFO - ===== Lib Versions =====
2023-03-31 13:29:47,547 - JUNIFER - INFO - numpy: 1.23.5
2023-03-31 13:29:47,547 - JUNIFER - INFO - scipy: 1.10.1
2023-03-31 13:29:47,547 - JUNIFER - INFO - pandas: 1.5.3
2023-03-31 13:29:47,547 - JUNIFER - INFO - nilearn: 0.10.0
2023-03-31 13:29:47,547 - JUNIFER - INFO - nibabel: 4.0.2
2023-03-31 13:29:47,547 - JUNIFER - INFO - junifer: 0.0.2
2023-03-31 13:29:47,547 - 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-03-31 13:29:47,548 - JUNIFER - INFO - Getting element sub001
2023-03-31 13:29:50,838 - JUNIFER - INFO - Fitting pipeline
2023-03-31 13:29:50,838 - JUNIFER - INFO - Reading BOLD from /tmp/tmps3v5evu8/sub001_bold.nii.gz
2023-03-31 13:29:50,839 - JUNIFER - INFO - BOLD is type NIFTI
2023-03-31 13:29:50,840 - JUNIFER - INFO - Reading T1w from /tmp/tmps3v5evu8/sub001_T1w.nii.gz
2023-03-31 13:29:50,840 - JUNIFER - INFO - T1w is type NIFTI
2023-03-31 13:29:50,840 - JUNIFER - INFO - Fitting marker Schaefer100x17_RSSETS
2023-03-31 13:29:50,840 - JUNIFER - INFO - Computing BOLD
2023-03-31 13:29:50,841 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2023-03-31 13:29:50,841 - JUNIFER - INFO - Parcellation parameters:
2023-03-31 13:29:50,841 - JUNIFER - INFO - n_rois: 100
2023-03-31 13:29:50,841 - JUNIFER - INFO - yeo_networks: 17
2023-03-31 13:29:50,841 - JUNIFER - INFO - resolution: 3.0
2023-03-31 13:29:50,841 - 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-03-31 13:29:51,253 - JUNIFER - INFO - Loading parcellation /home/runner/junifer/data/parcellations/schaefer_2018/Schaefer2018_100Parcels_17Networks_order_FSLMNI152_2mm.nii.gz
2023-03-31 13:29:53,958 - JUNIFER - INFO - Storing in <SQLiteFeatureStorage @ /tmp/tmp6r7xyl66/test.sqlite (multiple output)>
2023-03-31 13:29:53,981 - JUNIFER - INFO - Fitting marker Schaefer200x17_RSSETS
2023-03-31 13:29:53,981 - JUNIFER - INFO - Computing BOLD
2023-03-31 13:29:53,981 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2023-03-31 13:29:53,981 - JUNIFER - INFO - Parcellation parameters:
2023-03-31 13:29:53,981 - JUNIFER - INFO - n_rois: 200
2023-03-31 13:29:53,981 - JUNIFER - INFO - yeo_networks: 17
2023-03-31 13:29:53,981 - JUNIFER - INFO - resolution: 3.0
2023-03-31 13:29:53,981 - 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-03-31 13:29:54,565 - JUNIFER - INFO - Loading parcellation /home/runner/junifer/data/parcellations/schaefer_2018/Schaefer2018_200Parcels_17Networks_order_FSLMNI152_2mm.nii.gz
2023-03-31 13:29:56,179 - JUNIFER - INFO - Storing in <SQLiteFeatureStorage @ /tmp/tmp6r7xyl66/test.sqlite (multiple output)>
2023-03-31 13:29:56,205 - JUNIFER - INFO - Marker collection fitting done
2023-03-31 13:29:56,206 - JUNIFER - INFO - Collecting data using SQLiteFeatureStorage
2023-03-31 13:29:56,207 - JUNIFER - INFO - Collecting data from /tmp/tmp6r7xyl66/*test.sqlite
file: 0it [00:00, ?it/s]
feature: 0%| | 0/2 [00:00<?, ?it/s]
feature: 100%|##########| 2/2 [00:00<00:00, 51.93it/s]
file: 1it [00:00, 17.77it/s]
2023-03-31 13:29:56,264 - JUNIFER - INFO - Collect done
{'f33cd023de6ea00f108a80090a79f26c': {'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'}, 'e6475c5aad7a219209b39654badbd781': {'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
Total running time of the script: ( 0 minutes 8.746 seconds)