Hi all,
I’m trying to make functional matrix with nilearn modules of Python.
I want to do frame censoring (high motion data removal) automatically.
I have tsv file of confound data since I performed preprocessing via fmriprep.
Do you have any idea to implement framewise displacement with nilearn module?
Thanks in advance.
Hi @rikaatgithub
You might want to check load_confounds: GitHub - SIMEXP/load_confounds: Load fMRIprep confounds in python
We are planning to have some integration within Nilearn at some point, but this is still ongoing work (see this issue: Integration of `load_confounds` to `nilearn` · Issue #2777 · nilearn/nilearn · GitHub ).
Note that, in the mean time, it shouldn’t be too hard to integrate it in your workflow.
Let me know if this is helping or not!
Nicolas
@NicolasGensollen
Thank you so much for your quick reply.
So we can not implement framewise displacement without nilearn’s module for now…
I’ll try it!
You might be interested in:
opened 05:07PM - 04 Dec 24 UTC
closed 04:52PM - 10 Dec 24 UTC
### Is there an existing issue for this?
- [x] I have searched the existing iss… ues
### Describe your proposed enhancement in detail.
Are there plans to offer a function that calculates framewise-displacement (and possibly other measures?)
I am aware that `nilearn.interfaces.fmriprep.load_confounds` exists but this relies on a previous fmriprep run. There is an R-package "fMRIscrub" that can do this, but I would love to see a python-implementation preferably in nilearn.
Example:
```python
import requests
import numpy as np
from io import StringIO
from rpy2.robjects.packages import importr
from rpy2.robjects import numpy2ri
numpy2ri.activate()
fmriscrub = importr('fMRIscrub')
# download this file:
# https://openneuro.org/datasets/ds000113/versions/1.3.0/file-display/derivatives:motion:sub-01:ses-forrestgump:func:sub-01_ses-forrestgump_acq-dico_run-01_bold_moco.txt
url = ("https://s3.amazonaws.com/openneuro.org/ds000113/derivatives/motion/sub-01/"
"ses-forrestgump/func/sub-01_ses-forrestgump_acq-dico_run-01_bold_moco.txt"
"?versionId=oCUziRWPCbZh5XCF3R283ojCdw8BQRRJ"
)
# Fetch the file content
response = requests.get(url)
content = response.text
motion = np.loadtxt(StringIO(content))
# compute mean frame wise displacement
# make sure R and rpy2 is installed and install.packages('fMRIscrub)
fd = fmriscrub.FD(X=motion)[0]
mean_fd = np.mean(fd)
```
### Benefits to the change
I haven't found any package besides fMRIScrub and this one that can calculate Mean FD:
https://gist.github.com/JulianKlug/68ca5379935e0eedb9bdeed5ab03cf3a
Especially for old in-house datasets it's complicated and/or not possible to bring the dataset into BIDS-format, run fmriprep and then load them using `nilearn.interfaces.fmriprep.load_confounds`
### Pseudocode for the new behavior, if applicable
```python
# insert your code below
```