Fmriprep: acompcor 5 CSF and 5 WM

Hi everyone,

this a questin regarding fmriprep and denoising.

I have previously used the confounds_regressors.tsv file to regress out either motion parameters or AROMA+ GSR. Now I would like to try to use motion and acompcor instead, with the top 5 regressors from WM mask and CSF mask, like in Muschelli et al 2014 and Ciric et al 2017 for example.

However, in the tsv file the acompcors are not sorted by mask. Instead this information can only be found in the regressors.json file, but is different for every participant.

Does anyone know how to write a skript (maybe in python), that uses the json file to find out what the top 5 regressors from WM and CSF masks are and then extracts them from the tsv file?
So maybe sort json by mask first, then by sort by variance explained (or cumulative variance explained?), and then take the top 5 from WM and CSF mask and extract those columns from the tsv file.

Unfortunately I am very new to mfri research and programming, so programming this is well beyond my skills…

Can someone help me out, please?

Hi, here is a script i use to automatically extract the name of the corresponding columns of the first 5 components of WM and CSF masks:

import json
import sys, argparse

parser = argparse.ArgumentParser(description='Process some integers.')
                help='an integer for the accumulator')

args = parser.parse_args()

with open(args.path, 'r') as json_file:
    js = json.load(json_file)
a_comp_cor_csf, a_comp_cor_wm = ([] for _ in range(2))
for i in js.keys():
if i.startswith('a_comp_cor'):
    if js[i]['Mask'] == 'CSF' and js[i]['Retained']:
    if js[i]['Mask'] == 'WM' and js[i]['Retained']:

a_comp_cor_csf.sort(key=lambda x: '{0:0>18}'.format(x).lower())

a_comp_cor_wm.sort(key=lambda x: '{0:0>18}'.format(x).lower())

a_comp_cor = a_comp_cor_csf[:5] + a_comp_cor_wm[:5]


The way I use it is like this:

python <my_regressor_json>

Opened an issue: aCompCor components with different masks are inter-mixed · Issue #2384 · nipreps/fmriprep · GitHub

Not sure why things are like this.

Hi everyone, thank you very much for your responses!
@jsein Thanks heaps for the skript! I managed to merge it with my previous skript to extract those columns that your skript provides. (My skript now looks a bit cobbled together, but does the job :wink: )

@effigies I just wanted to add that our data has been processed using fmriprep version 20.0.6 - not sure if anything would be different with the current version.

Great, I am glad the script could help!
For information the naming of the acompcor components is the same in the latest fmriprep version as well: version 20.2.1