Note
Go to the end 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")
2024-04-05 15:56:54,827 - JUNIFER - INFO - ===== Lib Versions =====
2024-04-05 15:56:54,827 - JUNIFER - INFO - numpy: 1.26.4
2024-04-05 15:56:54,827 - JUNIFER - INFO - scipy: 1.11.4
2024-04-05 15:56:54,827 - JUNIFER - INFO - pandas: 2.1.4
2024-04-05 15:56:54,827 - JUNIFER - INFO - nilearn: 0.10.2
2024-04-05 15:56:54,827 - JUNIFER - INFO - nibabel: 5.2.1
2024-04-05 15:56:54,827 - JUNIFER - INFO - junifer: 0.0.4
2024-04-05 15:56:54,827 - 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")
2024-04-05 15:56:54,828 - JUNIFER - INFO - Validating Marker Collection
2024-04-05 15:56:54,828 - JUNIFER - INFO - DataGrabber output type: ['BOLD', 'T1w']
2024-04-05 15:56:54,828 - JUNIFER - INFO - Validating Data Reader:
2024-04-05 15:56:54,828 - JUNIFER - INFO - Data Reader output type: ['BOLD', 'T1w']
2024-04-05 15:56:54,828 - JUNIFER - INFO - Validating Marker: Schaefer100x17_RSSETS
2024-04-05 15:56:54,828 - JUNIFER - INFO - Marker output type: ['timeseries']
2024-04-05 15:56:54,828 - JUNIFER - INFO - Validating storage for Schaefer100x17_RSSETS
2024-04-05 15:56:54,828 - JUNIFER - INFO - Validating Marker: Schaefer200x17_RSSETS
2024-04-05 15:56:54,828 - JUNIFER - INFO - Marker output type: ['timeseries']
2024-04-05 15:56:54,828 - JUNIFER - INFO - Validating storage for Schaefer200x17_RSSETS
2024-04-05 15:56:54,829 - JUNIFER - INFO - Getting element sub001
2024-04-05 15:56:57,258 - JUNIFER - INFO - Fitting pipeline
2024-04-05 15:56:57,258 - JUNIFER - INFO - Reading BOLD from /tmp/tmp_uiu6qqa/sub001_bold.nii.gz
2024-04-05 15:56:57,258 - JUNIFER - INFO - BOLD is type NIFTI
2024-04-05 15:56:57,259 - JUNIFER - INFO - Reading T1w from /tmp/tmp_uiu6qqa/sub001_T1w.nii.gz
2024-04-05 15:56:57,259 - JUNIFER - INFO - T1w is type NIFTI
2024-04-05 15:56:57,260 - JUNIFER - INFO - Fitting marker Schaefer100x17_RSSETS
2024-04-05 15:56:57,260 - JUNIFER - INFO - Computing BOLD
2024-04-05 15:56:57,260 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2024-04-05 15:56:57,260 - JUNIFER - INFO - Parcellation parameters:
2024-04-05 15:56:57,260 - JUNIFER - INFO - resolution: 3.0
2024-04-05 15:56:57,260 - JUNIFER - INFO - n_rois: 100
2024-04-05 15:56:57,260 - JUNIFER - INFO - yeo_networks: 17
2024-04-05 15:56:57,260 - 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)
2024-04-05 15:56:57,313 - JUNIFER - INFO - Loading parcellation /home/runner/junifer/data/parcellations/schaefer_2018/Schaefer2018_100Parcels_17Networks_order_FSLMNI152_2mm.nii.gz
2024-04-05 15:56:57,342 - JUNIFER - INFO - Found existing xfm file for MNI152NLin6Asym to MNI152Lin at /home/runner/junifer/data/xfms/MNI152NLin6Asym_to_MNI152Lin/MNI152NLin6Asym_to_MNI152Lin_Composite.h5
2024-04-05 15:56:58,367 - JUNIFER - INFO - Downloading template MNI152Lin in resolution 2
2024-04-05 15:56:58,464 - JUNIFER - INFO - antsApplyTransforms command to be executed:
antsApplyTransforms -d 3 -e 3 -n 'GenericLabel[NearestNeighbor]' -i /tmp/tmpp56odh8d/parcellations2cd8f5w0/Schaefer100x17.nii.gz -r /tmp/tmpp56odh8d/parcellations2cd8f5w0/MNI152Lin_T1w_3.0.nii.gz -t /home/runner/junifer/data/xfms/MNI152NLin6Asym_to_MNI152Lin/MNI152NLin6Asym_to_MNI152Lin_Composite.h5 -o /tmp/tmp2sfzmhci/parcellationsw0umveg8/Schaefer100x17_warped_from_MNI152NLin6Asym_to_MNI152Lin.nii.gz
2024-04-05 15:56:59,859 - JUNIFER - INFO - antsApplyTransforms command succeeded with the following output:
b''
2024-04-05 15:57:02,552 - JUNIFER - INFO - Storing in <SQLiteFeatureStorage @ /tmp/tmpxccxf5rd/test.sqlite (multiple output)>
2024-04-05 15:57:02,569 - JUNIFER - INFO - Fitting marker Schaefer200x17_RSSETS
2024-04-05 15:57:02,569 - JUNIFER - INFO - Computing BOLD
2024-04-05 15:57:02,570 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2024-04-05 15:57:02,570 - JUNIFER - INFO - Parcellation parameters:
2024-04-05 15:57:02,570 - JUNIFER - INFO - resolution: 3.0
2024-04-05 15:57:02,570 - JUNIFER - INFO - n_rois: 200
2024-04-05 15:57:02,570 - JUNIFER - INFO - yeo_networks: 17
2024-04-05 15:57:02,570 - 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)
2024-04-05 15:57:02,632 - JUNIFER - INFO - Loading parcellation /home/runner/junifer/data/parcellations/schaefer_2018/Schaefer2018_200Parcels_17Networks_order_FSLMNI152_2mm.nii.gz
2024-04-05 15:57:02,664 - JUNIFER - INFO - Found existing xfm file for MNI152NLin6Asym to MNI152Lin at /home/runner/junifer/data/xfms/MNI152NLin6Asym_to_MNI152Lin/MNI152NLin6Asym_to_MNI152Lin_Composite.h5
2024-04-05 15:57:03,686 - JUNIFER - INFO - Downloading template MNI152Lin in resolution 2
2024-04-05 15:57:03,783 - JUNIFER - INFO - antsApplyTransforms command to be executed:
antsApplyTransforms -d 3 -e 3 -n 'GenericLabel[NearestNeighbor]' -i /tmp/tmpp56odh8d/parcellationsxplfejmj/Schaefer200x17.nii.gz -r /tmp/tmpp56odh8d/parcellationsxplfejmj/MNI152Lin_T1w_3.0.nii.gz -t /home/runner/junifer/data/xfms/MNI152NLin6Asym_to_MNI152Lin/MNI152NLin6Asym_to_MNI152Lin_Composite.h5 -o /tmp/tmp2sfzmhci/parcellationsr6lxts4p/Schaefer200x17_warped_from_MNI152NLin6Asym_to_MNI152Lin.nii.gz
2024-04-05 15:57:05,793 - JUNIFER - INFO - antsApplyTransforms command succeeded with the following output:
b''
2024-04-05 15:57:07,934 - JUNIFER - INFO - Storing in <SQLiteFeatureStorage @ /tmp/tmpxccxf5rd/test.sqlite (multiple output)>
2024-04-05 15:57:07,953 - JUNIFER - INFO - Marker collection fitting done
2024-04-05 15:57:07,955 - JUNIFER - INFO - Collecting data using SQLiteFeatureStorage
2024-04-05 15:57:07,955 - JUNIFER - INFO - Collecting data from /tmp/tmpxccxf5rd/*test.sqlite
file: 0it [00:00, ?it/s]
feature: 0%| | 0/2 [00:00<?, ?it/s]
feature: 100%|██████████| 2/2 [00:00<00:00, 80.92it/s]
file: 1it [00:00, 28.10it/s]
2024-04-05 15:57:07,991 - JUNIFER - INFO - Collect done
{'1d81ad1f44011f6c4d7e180b2e69045a': {'datagrabber': {'class': 'SPMAuditoryTestingDataGrabber', 'types': ['BOLD', 'T1w']}, 'dependencies': {'nilearn': '0.10.2'}, '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'}, '24fef87855ff678fc17e53f2c2ab5e6e': {'datagrabber': {'class': 'SPMAuditoryTestingDataGrabber', 'types': ['BOLD', 'T1w']}, 'dependencies': {'nilearn': '0.10.2'}, '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 13.184 seconds)