MEPrep: A robust pipeline for multi-echo fMRI denoising and preprocessing.
The 6 matches
- [1] § Methods › Pre-denoising multi-echo fMRI data with probabilistic ICA ↔ MEPrep_Source/MEPrep_ICA-AROMA/ICA_AROMA_functions_preICA.py, lines 217–287 · score 0.92 · shifted versions, realignment parameter, maximum absolute, maxRPcorr, maximum correlations, motion parameters
- [2] § Methods › Pre-denoising multi-echo fMRI data with probabilistic ICA ↔ MEPrep_Source/MEPrep_ICA-AROMA/ICA_AROMA_functions_pureMotion.py, lines 213–283 · score 0.92 · shifted versions, realignment parameter, maximum absolute, maxRPcorr, maximum correlations, motion parameters
- [3] § Methods › Pre-denoising multi-echo fMRI data with probabilistic ICA ↔ MEPrep_Source/MEPrep_ICA-AROMA/ICA_AROMA_functions_preICA.py, lines 461–535 · score 0.68 · maxRPcorr, CSF fractions, ICA AROMA, HFC, score, edge
- [4] § Methods › Pre-denoising multi-echo fMRI data with probabilistic ICA ↔ MEPrep_Source/MEPrep_ICA-AROMA/ICA_AROMA_functions_pureMotion.py, lines 457–533 · score 0.68 · maxRPcorr, CSF fractions, ICA AROMA, HFC, score, edge
- [5] § Methods › The framework and implementation of MEPrep ↔ MEPrep_Source/fmriprep/workflows/bold/confounds.py, lines 626–769 · score 0.51 · CIFTI formats, alignment, FD, confound, WM, NIfTI
- [6] § Methods › The framework and implementation of MEPrep ↔ MEPrep_Source/meprep/src/workflows/bold/confounds.py, lines 670–745 · score 0.50 · CIFTI formats, pre denoising, alignment, confound, WM, multiecho
Paper
Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC
The paper is loaded when this pane is shown.
The authors' code
Python · 591 lines · 27 KB · no license · 2 matches
- #!/usr/bin/env python
- # Functions for ICA-AROMA v0.3 beta
- from __future__ import division
- from __future__ import print_function
- from future import standard_library
- standard_library.install_aliases()
- from builtins import str
- from builtins import range
- from past.utils import old_div
- import numpy as np
- import shutil
- def runICA(fslDir, inFile, outDir, melDirIn, mask, dim, TR, preICA_scme=False):
- """ This function runs MELODIC and merges the mixture modeled thresholded ICs into a single 4D nifti file
- Parameters
- ---------------------------------------------------------------------------------
- fslDir: Full path of the bin-directory of FSL
- inFile: Full path to the fMRI data file (nii.gz) on which MELODIC should be run
- outDir: Full path of the output directory
- melDirIn: Full path of the MELODIC directory in case it has been run before, otherwise define empty string
- mask: Full path of the mask to be applied during MELODIC
- dim: Dimensionality of ICA
- TR: TR (in seconds) of the fMRI data
- Output (within the requested output directory)
- ---------------------------------------------------------------------------------
- melodic.ica MELODIC directory
- melodic_IC_thr.nii.gz merged file containing the mixture modeling thresholded Z-statistical maps located in melodic.ica/stats/ """
- # Import needed modules
- import os
- import subprocess
- # Define the 'new' MELODIC directory and predefine some associated files
- melDir = os.path.join(outDir, 'melodic.ica')
- melIC = os.path.join(melDir, 'melodic_IC.nii.gz')
- melICmix = os.path.join(melDir, 'melodic_mix')
- melICthr = os.path.join(outDir, 'melodic_IC_thr.nii.gz')
- melICthrIn = os.path.join(melDirIn, 'melodic_IC_thr.nii.gz')
- # When a MELODIC directory is specified,
- # check whether all needed files are present.
- # Otherwise... run MELODIC again
- if len(melDir) != 0 and os.path.isfile(os.path.join(melDirIn, 'melodic_IC.nii.gz')) and os.path.isfile(os.path.join(melDirIn, 'melodic_FTmix')) and os.path.isfile(os.path.join(melDirIn, 'melodic_mix')):
- print(' - The existing/specified MELODIC directory will be used.')
- # If a 'stats' directory is present (contains thresholded spatial maps)
- # create a symbolic link to the MELODIC directory.
- # Otherwise create specific links and
- # run mixture modeling to obtain thresholded maps.
- if os.path.isdir(os.path.join(melDirIn, 'stats')):
- os.symlink(melDirIn, melDir)
- else:
- print(' - The MELODIC directory does not contain the required \'stats\' folder. Mixture modeling on the Z-statistical maps will be run.')
- # Create symbolic links to the items in the specified melodic directory
- os.makedirs(melDir)
- for item in os.listdir(melDirIn):
- os.symlink(os.path.join(melDirIn, item),
- os.path.join(melDir, item))
- # Run mixture modeling
- os.system(' '.join([os.path.join(fslDir, 'melodic'),
- '--in=' + melIC,
- '--ICs=' + melIC,
- '--mix=' + melICmix,
- '--outdir=' + melDir,
- '--Ostats --mmthresh=0.5']))
- else:
- # If a melodic directory was specified, display that it did not contain all files needed for ICA-AROMA (or that the directory does not exist at all)
- if len(melDirIn) != 0:
- if not os.path.isdir(melDirIn):
- print(' - The specified MELODIC directory does not exist. MELODIC will be run seperately.')
- else:
- print(' - The specified MELODIC directory does not contain the required files to run ICA-AROMA. MELODIC will be run seperately.')
- # Run MELODIC
- os.system(' '.join([os.path.join(fslDir, 'melodic'),
- '--in=' + inFile,
- '--outdir=' + melDir,
- '--mask=' + mask,
- '--dim=' + str(dim),
- '--Ostats --nobet --mmthresh=0.5 --report',
- '--tr=' + str(TR)]))
- # Get number of components
- cmd = ' '.join([os.path.join(fslDir, 'fslinfo'),
- melIC,
- '| grep dim4 | head -n1 | awk \'{print $2}\''])
- nrICs = int(float(subprocess.getoutput(cmd)))
- if preICA_scme:
- shutil.copyfile(melICthrIn, melICthr)
- else:
- # Merge mixture modeled thresholded spatial maps. Note! In case that mixture modeling did not converge, the file will contain two spatial maps. The latter being the results from a simple null hypothesis test. In that case, this map will have to be used (first one will be empty).
- for i in range(1, nrICs + 1):
- # Define thresholded zstat-map file
- zTemp = os.path.join(melDir, 'stats', 'thresh_zstat' + str(i) + '.nii.gz')
- cmd = ' '.join([os.path.join(fslDir, 'fslinfo'),
- zTemp,
- '| grep dim4 | head -n1 | awk \'{print $2}\''])
- lenIC = int(float(subprocess.getoutput(cmd)))
- # Define zeropad for this IC-number and new zstat file
- cmd = ' '.join([os.path.join(fslDir, 'zeropad'),
- str(i),
- '4'])
- ICnum = subprocess.getoutput(cmd)
- zstat = os.path.join(outDir, 'thr_zstat' + ICnum)
- # Extract last spatial map within the thresh_zstat file
- os.system(' '.join([os.path.join(fslDir, 'fslroi'),
- zTemp, # input
- zstat, # output
- str(lenIC - 1), # first frame
- '1'])) # number of frames
- # Merge and subsequently remove all mixture modeled Z-maps within the output directory
- os.system(' '.join([os.path.join(fslDir, 'fslmerge'),
- '-t', # concatenate in time
- melICthr, # output
- os.path.join(outDir, 'thr_zstat????.nii.gz')])) # inputs
- os.system('rm ' + os.path.join(outDir, 'thr_zstat????.nii.gz'))
- # Apply the mask to the merged file (in case a melodic-directory was predefined and run with a different mask)
- os.system(' '.join([os.path.join(fslDir, 'fslmaths'),
- melICthr,
- '-mas ' + mask,
- melICthr]))
- def register2MNI(fslDir, inFile, outFile, affmat, warp):
- """ This function registers an image (or time-series of images) to MNI152 T1 2mm. If no affmat is defined, it only warps (i.e. it assumes that the data has been registerd to the structural scan associated with the warp-file already). If no warp is defined either, it only resamples the data to 2mm isotropic if needed (i.e. it assumes that the data has been registered to a MNI152 template). In case only an affmat file is defined, it assumes that the data has to be linearly registered to MNI152 (i.e. the user has a reason not to use non-linear registration on the data).
- Parameters
- ---------------------------------------------------------------------------------
- fslDir: Full path of the bin-directory of FSL
- inFile: Full path to the data file (nii.gz) which has to be registerd to MNI152 T1 2mm
- outFile: Full path of the output file
- affmat: Full path of the mat file describing the linear registration (if data is still in native space)
- warp: Full path of the warp file describing the non-linear registration (if data has not been registered to MNI152 space yet)
- Output (within the requested output directory)
- ---------------------------------------------------------------------------------
- melodic_IC_mm_MNI2mm.nii.gz merged file containing the mixture modeling thresholded Z-statistical maps registered to MNI152 2mm """
- # Import needed modules
- import os
- import subprocess
- # Define the MNI152 T1 2mm template
- fslnobin = fslDir.rsplit('/', 2)[0]
- ref = os.path.join(fslnobin, 'data', 'standard', 'MNI152_T1_2mm_brain.nii.gz')
- # If the no affmat- or warp-file has been specified, assume that the data is already in MNI152 space. In that case only check if resampling to 2mm is needed
- if (len(affmat) == 0) and (len(warp) == 0):
- # Get 3D voxel size
- pixdim1 = float(subprocess.getoutput('%sfslinfo %s | grep pixdim1 | awk \'{print $2}\'' % (fslDir, inFile)))
- pixdim2 = float(subprocess.getoutput('%sfslinfo %s | grep pixdim2 | awk \'{print $2}\'' % (fslDir, inFile)))
- pixdim3 = float(subprocess.getoutput('%sfslinfo %s | grep pixdim3 | awk \'{print $2}\'' % (fslDir, inFile)))
- # If voxel size is not 2mm isotropic, resample the data, otherwise copy the file
- if (pixdim1 != 2) or (pixdim2 != 2) or (pixdim3 != 2):
- os.system(' '.join([os.path.join(fslDir, 'flirt'),
- ' -ref ' + ref,
- ' -in ' + inFile,
- ' -out ' + outFile,
- ' -applyisoxfm 2 -interp trilinear']))
- else:
- os.system('cp ' + inFile + ' ' + outFile)
- # If only a warp-file has been specified, assume that the data has already been registered to the structural scan. In that case apply the warping without a affmat
- elif (len(affmat) == 0) and (len(warp) != 0):
- # Apply warp
- os.system(' '.join([os.path.join(fslDir, 'applywarp'),
- '--ref=' + ref,
- '--in=' + inFile,
- '--out=' + outFile,
- '--warp=' + warp,
- '--interp=trilinear']))
- # If only a affmat-file has been specified perform affine registration to MNI
- elif (len(affmat) != 0) and (len(warp) == 0):
- os.system(' '.join([os.path.join(fslDir, 'flirt'),
- '-ref ' + ref,
- '-in ' + inFile,
- '-out ' + outFile,
- '-applyxfm -init ' + affmat,
- '-interp trilinear']))
- # If both a affmat- and warp-file have been defined, apply the warping accordingly
- else:
- os.system(' '.join([os.path.join(fslDir, 'applywarp'),
- '--ref=' + ref,
- '--in=' + inFile,
- '--out=' + outFile,
- '--warp=' + warp,
- '--premat=' + affmat,
- '--interp=trilinear']))
- def cross_correlation(a, b):
- """Cross Correlations between columns of two matrices"""
- assert a.ndim == b.ndim == 2
- _, ncols_a = a.shape
- # nb variables in columns rather than rows hence transpose
- # extract just the cross terms between cols in a and cols in b
- return np.corrcoef(a.T, b.T)[:ncols_a, ncols_a:]
- def feature_time_series(melmix, mc):
- """ This function extracts the maximum RP correlation feature scores.
- It determines the maximum robust correlation of each component time-series
- with a model of 72 realignment parameters.
- Parameters
- ---------------------------------------------------------------------------------
- melmix: Full path of the melodic_mix text file
- mc: Full path of the text file containing the realignment parameters
- Returns
- ---------------------------------------------------------------------------------
- maxRPcorr: Array of the maximum RP correlation feature scores for the components
- of the melodic_mix file"""
- # Import required modules
- import numpy as np
- import random
- # Read melodic mix file (IC time-series), subsequently define a set of squared time-series
- mix = np.loadtxt(melmix)
- # Read motion parameter file
- rp6 = np.loadtxt(mc)
- _, nparams = rp6.shape
- # Determine the derivatives of the RPs (add zeros at time-point zero)
- rp6_der = np.vstack((np.zeros(nparams),
- np.diff(rp6, axis=0)
- ))
- # Create an RP-model including the RPs and its derivatives
- rp12 = np.hstack((rp6, rp6_der))
- # Add the squared RP-terms to the model
- # add the fw and bw shifted versions
- rp12_1fw = np.vstack((
- np.zeros(2 * nparams),
- rp12[:-1]
- ))
- rp12_1bw = np.vstack((
- rp12[1:],
- np.zeros(2 * nparams)
- ))
- rp_model = np.hstack((rp12, rp12_1fw, rp12_1bw))
- # Determine the maximum correlation between RPs and IC time-series
- nsplits = 1000
- nmixrows, nmixcols = mix.shape
- nrows_to_choose = int(round(0.9 * nmixrows))
- # Max correlations for multiple splits of the dataset (for a robust estimate)
- max_correls = np.empty((nsplits, nmixcols))
- for i in range(nsplits):
- # Select a random subset of 90% of the dataset rows (*without* replacement)
- chosen_rows = random.sample(population=range(nmixrows),
- k=nrows_to_choose)
- # Combined correlations between RP and IC time-series, squared and non squared
- correl_nonsquared = cross_correlation(mix[chosen_rows],
- rp_model[chosen_rows])
- correl_squared = cross_correlation(mix[chosen_rows]**2,
- rp_model[chosen_rows]**2)
- correl_both = np.hstack((correl_squared, correl_nonsquared))
- # Maximum absolute temporal correlation for every IC
- max_correls[i] = np.abs(correl_both).max(axis=1)
- # Feature score is the mean of the maximum correlation over all the random splits
- # Avoid propagating occasional nans that arise in artificial test cases
- return np.nanmean(max_correls, axis=0)
- def feature_frequency(melFTmix, TR):
- """ This function extracts the high-frequency content feature scores.
- It determines the frequency, as fraction of the Nyquist frequency,
- at which the higher and lower frequencies explain half
- of the total power between 0.01Hz and Nyquist.
- Parameters
- ---------------------------------------------------------------------------------
- melFTmix: Full path of the melodic_FTmix text file
- TR: TR (in seconds) of the fMRI data (float)
- Returns
- ---------------------------------------------------------------------------------
- HFC: Array of the HFC ('High-frequency content') feature scores
- for the components of the melodic_FTmix file"""
- # Import required modules
- import numpy as np
- # Determine sample frequency
- Fs = old_div(1, TR)
- # Determine Nyquist-frequency
- Ny = old_div(Fs, 2)
- # Load melodic_FTmix file
- FT = np.loadtxt(melFTmix)
- # Determine which frequencies are associated with every row in the melodic_FTmix file (assuming the rows range from 0Hz to Nyquist)
- f = Ny * (np.array(list(range(1, FT.shape[0] + 1)))) / (FT.shape[0])
- # Only include frequencies higher than 0.01Hz
- fincl = np.squeeze(np.array(np.where(f > 0.01)))
- FT = FT[fincl, :]
- f = f[fincl]
- # Set frequency range to [0-1]
- f_norm = old_div((f - 0.01), (Ny - 0.01))
- # For every IC; get the cumulative sum as a fraction of the total sum
- fcumsum_fract = old_div(np.cumsum(FT, axis=0), np.sum(FT, axis=0))
- # Determine the index of the frequency with the fractional cumulative sum closest to 0.5
- idx_cutoff = np.argmin(np.abs(fcumsum_fract - 0.5), axis=0)
- # Now get the fractions associated with those indices index, these are the final feature scores
- HFC = f_norm[idx_cutoff]
- # Return feature score
- return HFC
- def feature_spatial(fslDir, tempDir, aromaDir, melIC):
- """ This function extracts the spatial feature scores. For each IC it determines the fraction of the mixture modeled thresholded Z-maps respecitvely located within the CSF or at the brain edges, using predefined standardized masks.
- Parameters
- ---------------------------------------------------------------------------------
- fslDir: Full path of the bin-directory of FSL
- tempDir: Full path of a directory where temporary files can be stored (called 'temp_IC.nii.gz')
- aromaDir: Full path of the ICA-AROMA directory, containing the mask-files (mask_edge.nii.gz, mask_csf.nii.gz & mask_out.nii.gz)
- melIC: Full path of the nii.gz file containing mixture-modeled threholded (p>0.5) Z-maps, registered to the MNI152 2mm template
- Returns
- ---------------------------------------------------------------------------------
- edgeFract: Array of the edge fraction feature scores for the components of the melIC file
- csfFract: Array of the CSF fraction feature scores for the components of the melIC file"""
- # Import required modules
- import numpy as np
- import os
- import subprocess
- # Get the number of ICs
- numICs = int(subprocess.getoutput('%sfslinfo %s | grep dim4 | head -n1 | awk \'{print $2}\'' % (fslDir, melIC) ))
- # Loop over ICs
- edgeFract = np.zeros(numICs)
- csfFract = np.zeros(numICs)
- for i in range(0, numICs):
- # Define temporary IC-file
- tempIC = os.path.join(tempDir, 'temp_IC.nii.gz')
- # Extract IC from the merged melodic_IC_thr2MNI2mm file
- os.system(' '.join([os.path.join(fslDir, 'fslroi'),
- melIC,
- tempIC,
- str(i),
- '1']))
- # Change to absolute Z-values
- os.system(' '.join([os.path.join(fslDir, 'fslmaths'),
- tempIC,
- '-abs',
- tempIC]))
- # Get sum of Z-values within the total Z-map (calculate via the mean and number of non-zero voxels)
- totVox = int(subprocess.getoutput(' '.join([os.path.join(fslDir, 'fslstats'),
- tempIC,
- '-V | awk \'{print $1}\''])))
- if not (totVox == 0):
- totMean = float(subprocess.getoutput(' '.join([os.path.join(fslDir, 'fslstats'),
- tempIC,
- '-M'])))
- else:
- print(' - The spatial map of component ' + str(i + 1) + ' is empty. Please check!')
- totMean = 0
- totSum = totMean * totVox
- # Get sum of Z-values of the voxels located within the CSF (calculate via the mean and number of non-zero voxels)
- csfVox = int(subprocess.getoutput(' '.join([os.path.join(fslDir, 'fslstats'),
- tempIC,
- '-k mask_csf.nii.gz',
- '-V | awk \'{print $1}\''])))
- if not (csfVox == 0):
- csfMean = float(subprocess.getoutput(' '.join([os.path.join(fslDir, 'fslstats'),
- tempIC,
- '-k mask_csf.nii.gz',
- '-M'])))
- else:
- csfMean = 0
- csfSum = csfMean * csfVox
- # Get sum of Z-values of the voxels located within the Edge (calculate via the mean and number of non-zero voxels)
- edgeVox = int(subprocess.getoutput(' '.join([os.path.join(fslDir, 'fslstats'),
- tempIC,
- '-k mask_edge.nii.gz',
- '-V | awk \'{print $1}\''])))
- if not (edgeVox == 0):
- edgeMean = float(subprocess.getoutput(' '.join([os.path.join(fslDir, 'fslstats'),
- tempIC,
- '-k mask_edge.nii.gz',
- '-M'])))
- else:
- edgeMean = 0
- edgeSum = edgeMean * edgeVox
- # Get sum of Z-values of the voxels located outside the brain (calculate via the mean and number of non-zero voxels)
- outVox = int(subprocess.getoutput(' '.join([os.path.join(fslDir, 'fslstats'),
- tempIC,
- '-k mask_out.nii.gz',
- '-V | awk \'{print $1}\''])))
- if not (outVox == 0):
- outMean = float(subprocess.getoutput(' '.join([os.path.join(fslDir, 'fslstats'),
- tempIC,
- '-k mask_out.nii.gz',
- '-M'])))
- else:
- outMean = 0
- outSum = outMean * outVox
- # Determine edge and CSF fraction
- if not (totSum == 0):
- edgeFract[i] = old_div((outSum + edgeSum), (totSum - csfSum))
- csfFract[i] = old_div(csfSum, totSum)
- else:
- edgeFract[i] = 0
- csfFract[i] = 0
- # Remove the temporary IC-file
- os.remove(tempIC)
- # Return feature scores
- return edgeFract, csfFract
- def classification(outDir, maxRPcorr, edgeFract, HFC, csfFract):
- """ This function classifies a set of components into motion and
- non-motion components based on four features;
- maximum RP correlation, high-frequency content, edge-fraction and CSF-fraction
- Parameters
- ---------------------------------------------------------------------------------
- outDir: Full path of the output directory
- maxRPcorr: Array of the 'maximum RP correlation' feature scores of the components
- edgeFract: Array of the 'edge fraction' feature scores of the components
- HFC: Array of the 'high-frequency content' feature scores of the components
- csfFract: Array of the 'CSF fraction' feature scores of the components
- Return
- ---------------------------------------------------------------------------------
- motionICs Array containing the indices of the components identified as motion components
- Output (within the requested output directory)
- ---------------------------------------------------------------------------------
- classified_motion_ICs.txt A text file containing the indices of the components identified as motion components """
- # Import required modules
- import numpy as np
- import os
- # Classify the ICs as motion or non-motion
- # Define criteria needed for classification (thresholds and hyperplane-parameters)
- thr_csf = 0.10
- thr_HFC = 0.35
- hyp = np.array([-19.9751070082159, 9.95127547670627, 24.8333160239175])
- # Project edge & maxRPcorr feature scores to new 1D space
- x = np.array([maxRPcorr, edgeFract])
- proj = hyp[0] + np.dot(x.T, hyp[1:])
- # Classify the ICs
- motionICs = np.squeeze(np.array(np.where((proj > 0) + (csfFract > thr_csf) + (HFC > thr_HFC))))
- # Put the feature scores in a text file
- np.savetxt(os.path.join(outDir, 'feature_scores.txt'),
- np.vstack((maxRPcorr, edgeFract, HFC, csfFract)).T)
- # Put the indices of motion-classified ICs in a text file
- txt = open(os.path.join(outDir, 'classified_motion_ICs.txt'), 'w')
- if motionICs.size > 1: # and len(motionICs) != 0: if motionICs is not None and
- txt.write(','.join(['{:.0f}'.format(num) for num in (motionICs + 1)]))
- elif motionICs.size == 1:
- txt.write('{:.0f}'.format(motionICs + 1))
- txt.close()
- # Create a summary overview of the classification
- txt = open(os.path.join(outDir, 'classification_overview.txt'), 'w')
- txt.write('\t'.join(['IC',
- 'Motion/noise',
- 'maximum RP correlation',
- 'Edge-fraction',
- 'High-frequency content',
- 'CSF-fraction']))
- txt.write('\n')
- for i in range(0, len(csfFract)):
- if (proj[i] > 0) or (csfFract[i] > thr_csf) or (HFC[i] > thr_HFC):
- classif = "True"
- else:
- classif = "False"
- txt.write('\t'.join(['{:d}'.format(i + 1),
- classif,
- '{:.2f}'.format(maxRPcorr[i]),
- '{:.2f}'.format(edgeFract[i]),
- '{:.2f}'.format(HFC[i]),
- '{:.2f}'.format(csfFract[i])]))
- txt.write('\n')
- txt.close()
- return motionICs
- def denoising(fslDir, inFile, outDir, melmix, denType, denIdx):
- """ This function classifies the ICs based on the four features;
- maximum RP correlation, high-frequency content, edge-fraction and CSF-fraction
- Parameters
- ---------------------------------------------------------------------------------
- fslDir: Full path of the bin-directory of FSL
- inFile: Full path to the data file (nii.gz) which has to be denoised
- outDir: Full path of the output directory
- melmix: Full path of the melodic_mix text file
- denType: Type of requested denoising ('aggr': aggressive, 'nonaggr': non-aggressive, 'both': both aggressive and non-aggressive
- denIdx: Indices of the components that should be regressed out
- Output (within the requested output directory)
- ---------------------------------------------------------------------------------
- denoised_func_data_<denType>.nii.gz: A nii.gz file of the denoised fMRI data"""
- # Import required modules
- import os
- import numpy as np
- # Check if denoising is needed (i.e. are there components classified as motion)
- check = denIdx.size > 0
- if check == 1:
- # Put IC indices into a char array
- if denIdx.size == 1:
- denIdxStrJoin = "%d"%(denIdx + 1)
- else:
- denIdxStr = np.char.mod('%i', (denIdx + 1))
- denIdxStrJoin = ','.join(denIdxStr)
- # Non-aggressive denoising of the data using fsl_regfilt (partial regression), if requested
- if (denType == 'nonaggr') or (denType == 'both'):
- os.system(' '.join([os.path.join(fslDir, 'fsl_regfilt'),
- '--in=' + inFile,
- '--design=' + melmix,
- '--filter="' + denIdxStrJoin + '"',
- '--out=' + os.path.join(outDir, 'denoised_func_data_nonaggr.nii.gz')]))
- # Aggressive denoising of the data using fsl_regfilt (full regression)
- if (denType == 'aggr') or (denType == 'both'):
- os.system(' '.join([os.path.join(fslDir, 'fsl_regfilt'),
- '--in=' + inFile,
- '--design=' + melmix,
- '--filter="' + denIdxStrJoin + '"',
- '--out=' + os.path.join(outDir, 'denoised_func_data_aggr.nii.gz'),
- '-a']))
- else:
- print(" - None of the components were classified as motion, so no denoising is applied (a symbolic link to the input file will be created).")
- if (denType == 'nonaggr') or (denType == 'both'):
- os.symlink(inFile, os.path.join(outDir, 'denoised_func_data_nonaggr.nii.gz'))
- if (denType == 'aggr') or (denType == 'both'):
- os.symlink(inFile, os.path.join(outDir, 'denoised_func_data_aggr.nii.gz'))
ICA_AROMA_functions_preICA.py at commit c16de31, no license · at the source
Overview
- The Department of Psychiatry, Vagelos College of Physicians and Surgeons, Columbia University, New York, NY, United States
- New York State Psychiatric Institute, New York, NY, United States
Abstract
Multi-echo fMRI has emerged as a powerful strategy to mitigate head motion-related noise and minimize susceptibility-related signal loss in BOLD data. Multi-echo independent component analysis (ME-ICA) effectively distinguishes between BOLD-related (TE-dependent) signals and non-BOLD (TE-independent) noise, yielding substantial enhancements in performance compared to traditional echo-combination methods. We introduce a novel ICA-based denoising step, preICA, applied to raw multi-echo data before optimal T2*-weighted echo combination. This approach, combined with ME-ICA, yields substantial gains in data denoising. Our results show that preICA significantly enhances the efficacy of optimal echo combination and ME-ICA to reduce noise. To facilitate the reliable processing of multi-echo fMRI data, we integrated preICA and ME-ICA into fMRIPrep, resulting in the creation of a robust multi-echo processing pipeline, called MEPrep, offering flexibility in preprocessing options (with or without preICA and/
Reproduced under the paper's license (CC BY), from the paper cited above.
Repository
Its files are read in the Code ↔ Paper reader above, with 6 matches between paragraphs and lines of code.
zswang-brainimaging/MEPrep
c16de3143eff7ed5e475a810adc5ca7a3a541ff5, 6 April 2026Availability: 1 check, the latest on 28 September 2026: the link answers
- 28 September 2026: the link answers
99 files
- MEPrep_Source/
MEPrep_ICA-AROMA/ , Python, 239 linesICA_AROMA.py - MEPrep_Source/
MEPrep_ICA-AROMA/ , Python, 587 linesICA_AROMA_functions.py - MEPrep_Source/
MEPrep_ICA-AROMA/ , Python, 591 lines, 2 matchesICA_AROMA_functions_preI CA.py - MEPrep_Source/
MEPrep_ICA-AROMA/ , Python, 589 lines, 2 matchesICA_AROMA_functions_pure Motion.py - MEPrep_Source/
MEPrep_ICA-AROMA/ , Python, 240 linesICA_AROMA_preICA.py - MEPrep_Source/
MEPrep_ICA-AROMA/ , Python, 247 linesclassification_plots.py - MEPrep_Source/
MEPrep_ICA-AROMA/ , Python, 24 linesica-aroma-via-docker.py - MEPrep_Source/
fmriprep/ , Python, 28 lines__init__.py - MEPrep_Source/
fmriprep/ , Python, 33 lines__main__.py - MEPrep_Source/
fmriprep/ , Python, 46 lines_warnings.py - MEPrep_Source/
fmriprep/ , Python, 1 linecli/ __init__.py - MEPrep_Source/
fmriprep/ , Python, 932 linescli/ parser.py - MEPrep_Source/
fmriprep/ , Python, 250 linescli/ run.py - MEPrep_Source/
fmriprep/ , Python, 1 linecli/ tests/ __init__.py - MEPrep_Source/
fmriprep/ , Python, 272 linescli/ tests/ test_parser.py - MEPrep_Source/
fmriprep/ , Python, 218 linescli/ tests/ test_version.py - MEPrep_Source/
fmriprep/ , Python, 104 linescli/ version.py - MEPrep_Source/
fmriprep/ , Python, 235 linescli/ workflow.py - MEPrep_Source/
fmriprep/ , Python, 825 linesconfig.py - MEPrep_Source/
fmriprep/ , Python, 45 linesconftest.py - MEPrep_Source/
fmriprep/ , Python, 182 linesdata/ __init__.py - MEPrep_Source/
fmriprep/ , Python, 10 linesinterfaces/ __init__.py - MEPrep_Source/
fmriprep/ , Python, 62 linesinterfaces/ bids.py - MEPrep_Source/
fmriprep/ , Python, 447 linesinterfaces/ confounds.py - MEPrep_Source/
fmriprep/ , Python, 40 linesinterfaces/ conftest.py - MEPrep_Source/
fmriprep/ , Python, 68 linesinterfaces/ gifti.py - MEPrep_Source/
fmriprep/ , Python, 84 linesinterfaces/ maths.py - MEPrep_Source/
fmriprep/ , Python, 114 linesinterfaces/ multiecho.py - MEPrep_Source/
fmriprep/ , Python, 117 linesinterfaces/ patches.py - MEPrep_Source/
fmriprep/ , Python, 371 linesinterfaces/ reports.py - MEPrep_Source/
fmriprep/ , Python, 699 linesinterfaces/ resampling.py - MEPrep_Source/
fmriprep/ , Python, 1 lineinterfaces/ tests/ __init__.py - MEPrep_Source/
fmriprep/ , Python, 1 lineinterfaces/ tests/ data/ __init__.py - MEPrep_Source/
fmriprep/ , Python, 72 linesinterfaces/ tests/ test_bids.py - MEPrep_Source/
fmriprep/ , Python, 31 linesinterfaces/ tests/ test_confounds.py - MEPrep_Source/
fmriprep/ , Python, 43 linesinterfaces/ tests/ test_maths.py - MEPrep_Source/
fmriprep/ , Python, 52 linesinterfaces/ tests/ test_reports.py - MEPrep_Source/
fmriprep/ , Python, 807 linesinterfaces/ workbench.py - MEPrep_Source/
fmriprep/ , Python, 1 linereports/ __init__.py - MEPrep_Source/
fmriprep/ , Python, 146 linesreports/ core.py - MEPrep_Source/
fmriprep/ , Python, 1 linereports/ tests/ __init__.py - MEPrep_Source/
fmriprep/ , Python, 111 linesreports/ tests/ test_reports.py - MEPrep_Source/
fmriprep/ , Python, 1 linetests/ __init__.py - MEPrep_Source/
fmriprep/ , Python, 121 linestests/ test_config.py - MEPrep_Source/
fmriprep/ , Python, 40 linestests/ test_fsl6.py - MEPrep_Source/
fmriprep/ , Python, 1 lineutils/ __init__.py - MEPrep_Source/
fmriprep/ , Python, 11 linesutils/ asynctools.py - MEPrep_Source/
fmriprep/ , Python, 416 linesutils/ bids.py - MEPrep_Source/
fmriprep/ , Python, 159 linesutils/ confounds.py - MEPrep_Source/
fmriprep/ , Python, 79 linesutils/ debug.py - MEPrep_Source/
fmriprep/ , Python, 45 linesutils/ meepi.py - MEPrep_Source/
fmriprep/ , Python, 68 linesutils/ misc.py - MEPrep_Source/
fmriprep/ , Python, 216 linesutils/ telemetry.py - MEPrep_Source/
fmriprep/ , Python, 105 linesutils/ transforms.py - MEPrep_Source/
fmriprep/ , Python, 1 lineworkflows/ __init__.py - MEPrep_Source/
fmriprep/ , Python, 846 linesworkflows/ base.py - MEPrep_Source/
fmriprep/ , Python, 33 linesworkflows/ bold/ __init__.py - MEPrep_Source/
fmriprep/ , Python, 219 linesworkflows/ bold/ apply.py - MEPrep_Source/
fmriprep/ , Python, 792 linesworkflows/ bold/ base.py - MEPrep_Source/
fmriprep/ , Python, 819 lines, 1 matchworkflows/ bold/ confounds.py - MEPrep_Source/
fmriprep/ , Python, 940 linesworkflows/ bold/ fit.py - MEPrep_Source/
fmriprep/ , Python, 131 linesworkflows/ bold/ hmc.py - MEPrep_Source/
fmriprep/ , Python, 1,009 linesworkflows/ bold/ outputs.py - MEPrep_Source/
fmriprep/ , Python, 147 linesworkflows/ bold/ reference.py - MEPrep_Source/
fmriprep/ , Python, 772 linesworkflows/ bold/ registration.py - MEPrep_Source/
fmriprep/ , Python, 818 linesworkflows/ bold/ resampling.py - MEPrep_Source/
fmriprep/ , Python, 144 linesworkflows/ bold/ stc.py - MEPrep_Source/
fmriprep/ , Python, 223 linesworkflows/ bold/ t2s.py - MEPrep_Source/
fmriprep/ , Python, 1 lineworkflows/ bold/ tests/ __init__.py - MEPrep_Source/
fmriprep/ , Python, 83 linesworkflows/ bold/ tests/ test_base.py - MEPrep_Source/
fmriprep/ , Python, 176 linesworkflows/ bold/ tests/ test_fit.py - MEPrep_Source/
fmriprep/ , Python, 70 linesworkflows/ tests/ __init__.py - MEPrep_Source/
fmriprep/ , Python, 324 linesworkflows/ tests/ test_base.py - MEPrep_Source/
fsl-6.0.5.1/ , Shell, 54 linesdata/ xtract_data/ standard/ F99/ do_reg_F99.sh - MEPrep_Source/
meprep/ , Python, 1,002 linessrc/ cli/ parser.py - MEPrep_Source/
meprep/ , Python, 256 linessrc/ cli/ run.py - MEPrep_Source/
meprep/ , Python, 837 linessrc/ config.py - MEPrep_Source/
meprep/ , Python, 434 linessrc/ interfaces/ meprep_multiecho.py - MEPrep_Source/
meprep/ , Python, 387 linessrc/ interfaces/ optcomDenoising_multiech o.py - MEPrep_Source/
meprep/ , Python, 119 linessrc/ interfaces/ preICA_apply_mask.py - MEPrep_Source/
meprep/ , Python, 118 linessrc/ interfaces/ preICA_register.py - MEPrep_Source/
meprep/ , Python, 118 linessrc/ interfaces/ preICA_register_direct.p y - MEPrep_Source/
meprep/ , Python, 187 linessrc/ interfaces/ preICA_register_indirect .py - MEPrep_Source/
meprep/ , Python, 203 linessrc/ interfaces/ preICA_register_nonlin.p y - MEPrep_Source/
meprep/ , Python, 393 linessrc/ interfaces/ preICA_scme_interface.py - MEPrep_Source/
meprep/ , Python, 252 linessrc/ interfaces/ preICA_se_interface.py - MEPrep_Source/
meprep/ , Python, 254 linessrc/ interfaces/ preICA_tcme_interface.py - MEPrep_Source/
meprep/ , Python, 417 linessrc/ interfaces/ preICA_tensor_interface. py - MEPrep_Source/
meprep/ , Python, 849 linessrc/ workflows/ base.py - MEPrep_Source/
meprep/ , Python, 33 linessrc/ workflows/ bold/ __init__.py - MEPrep_Source/
meprep/ , Python, 839 linessrc/ workflows/ bold/ base.py - MEPrep_Source/
meprep/ , Python, 871 lines, 1 matchsrc/ workflows/ bold/ confounds.py - MEPrep_Source/
meprep/ , Python, 956 linessrc/ workflows/ bold/ fit.py - MEPrep_Source/
meprep/ , Python, 420 linessrc/ workflows/ bold/ meprep_t2s.py - MEPrep_Source/
meprep/ , Python, 1,068 linessrc/ workflows/ bold/ outputs.py - MEPrep_Source/
meprep/ , Python, 420 linessrc/ workflows/ bold/ preICA_t2s.py - MEPrep_Source/
scripts/ , Python, 136 linesfetch_templates.py - MEPrep_Source/
scripts/ , Python, 42 linesgenerate_reference_mask. py - README.md, Text, 54 lines
The paper's code and data availability statement is in the Data section.
Tracing map
Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.
What the map holds:
- 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
- 98 scripts, each with its path and the digest of its content;
- 6 matches between paragraphs of the paper and lines of the code (method lexical-v1);
- neither the text of the paper nor the code itself.
Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.
Data
Datasets cited
- openfmri.org/
dataset/ , at openfmri.org; found in “Data and Code Availability”ds000258
Data and Code Availability
Our MEPrep pipeline is publicly available on Docker Hub. Users can download and install MEPrep on a Docker-enabled system by running a command under Docker: “docker pull zswang2020/
Reproduced under the paper's license (CC BY), from the paper cited above.
Versions
The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.
Version 1, 28 September 2026: the first record
Recorded: type, language, journal, volume, pages, dates, 5 authors, 6 keywords, 72 references.
Cite
This paper
Wang, Z., Liu, F., Marsh, R., Patel, G. H., & Grinband, J. (2026). MEPrep: A robust pipeline for multi-echo fMRI denoising and preprocessing. Imaging neuroscience (Cambridge, Mass.), 4, IMAG.a.1198. https://
BibTeX
@article{wang2026meprep,
author = {Wang, Zhishun and Liu, Feng and Marsh, Rachel and Patel, Gaurav H. and Grinband, Jack},
title = {{MEPrep: A robust pipeline for multi-echo fMRI denoising and preprocessing}},
journal = {Imaging neuroscience (Cambridge, Mass.)},
year = {2026},
month = apr,
volume = {4},
pages = {IMAG.a.1198},
publisher = {MIT Press},
issn = {2837-6056},
doi = {10.1162/
url = {https://
pmid = {41952841},
pmcid = {PMC13055012}
}
RIS
TY - JOUR
AU - Wang, Zhishun
AU - Liu, Feng
AU - Marsh, Rachel
AU - Patel, Gaurav H.
AU - Grinband, Jack
TI - MEPrep: A robust pipeline for multi-echo fMRI denoising and preprocessing
T2 - Imaging neuroscience (Cambridge, Mass.)
J2 - Imaging Neurosci (Camb)
PY - 2026
DA - 2026/
VL - 4
SP - IMAG.a.1198
SN - 2837-6056
PB - MIT Press
DO - 10.1162/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1162/
"type": "article-journal",
"title": "MEPrep: A robust pipeline for multi-echo fMRI denoising and preprocessing",
"container-title": "Imaging neuroscience (Cambridge, Mass.)",
"author": [
{
"family": "Wang",
"given": "Zhishun"
},
{
"family": "Liu",
"given": "Feng"
},
{
"family": "Marsh",
"given": "Rachel"
},
{
"family": "Patel",
"given": "Gaurav H."
},
{
"family": "Grinband",
"given": "Jack"
}
],
"container-title-short":
"volume": "4",
"page": "IMAG.a.1198",
"DOI": "10.1162/
"PMID": "41952841",
"PMCID": "PMC13055012",
"ISSN": "2837-6056",
"publisher": "MIT Press",
"URL": "https://
"language": "en",
"issued": {
"date-parts": [
[
2026,
4,
6
]
]
}
}
The tracing map gets a citation of its own once an author has validated it and it has a DOI.
Similar papers
The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.
- [1] doi:10.1162/netn.a.547 [code]
- An evaluation of the efficacy of single-echo and multi-echo fMRI denoising strategies.Journal: Network neuroscience (Cambridge, Mass.)In common: tedana, fMRIPrep, Nipype, 9 other tools, fMRI, 21 references
- [2] doi:10.1002/hbm.70621 [code]
- Optimising 7T-fMRI for Imaging Regions of Magnetic Susceptibility.Journal: Human brain mappingIn common: tedana, fMRIPrep, AFNI, 1 other tool, fMRI, 17 references
- [3] doi:10.1162/imag.a.1262 [code]
- Frame-wise multi-echo distortion correction for superior functional MRI.Journal: Imaging neuroscience (Cambridge, Mass.)In common: PyBIDS, FreeSurfer, FSL, 8 other tools, fMRI, 8 references
- [4] doi:10.1038/s41398-026-04157-5 [code]
- Association of glymphatic function with 40-Hz neural oscillations, systemic metabolic markers, and cognitive performance in healthy aging adults: An EEG and MRI study.Journal: Translational psychiatryIn common: TemplateFlow, fMRIPrep, PyBIDS, 11 other tools, fMRI, 1 reference
- [5] doi:10.1162/imag.a.1362 [code]
- Human fMRI at 11.7T: Assessing feasibility, stability, and reliability on the Iseult scanner.Journal: Imaging neuroscience (Cambridge, Mass.)In common: fMRIPrep, Nipype, FreeSurfer, 8 other tools, fMRI, methods / tools, 6 references
- [6] doi:10.1162/imag.a.1347 [code]
- Neural and behavioural correlates of theory of mind reasoning in five-year-old children born preterm.Journal: Imaging neuroscience (Cambridge, Mass.)In common: tedana, fMRIPrep, PyBIDS, 9 other tools, fMRI, 3 references
- [7] doi:10.1162/imag.a.1252 [code]
- Does the brain's E:I balance really shape long-range temporal correlations? Lessons learned from 3T MRI.Journal: Imaging neuroscience (Cambridge, Mass.)In common: tedana, fMRIPrep, AFNI, 8 other tools, fMRI, 6 references
- [8] doi:10.1016/j.neuron.2026.04.011 [code]
- Precision fMRI reveals densely interdigitated network patches with conserved motifs in the lateral prefrontal cortex.Journal: NeuronIn common: tedana, AFNI, FreeSurfer, 6 other tools, fMRI, 8 references
- [9] doi:10.1038/s41467-026-71151-2 [code]
- Common and distinct neural correlates of social interaction processing and theory of mind in narratives.Journal: Nature communicationsIn common: fMRIPrep, Nipype, AFNI, 9 other tools, 5 references
- [10] doi:10.1016/j.dcn.2026.101765 [code]
- Fusiform face area development correlates with development in higher-order social brain regions.Journal: Developmental cognitive neuroscienceIn common: tedana, fMRIPrep, PyBIDS, 9 other tools, fMRI, 2 references
Contribute
The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.
Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 1 repository of the authors' code, each at its verified commit and with its license, 98 scripts, and 6 matches between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:f51ba9de0a968fe5…
Add the badge to its README
The badge links the code to this page. Copy one of these into the README of the paper's code: only you decide where it goes, and nothing is changed for you.
Markdown
[, paste the snippet at the top, then “Commit changes…” and, to review it first, “Create a new branch and start a pull request”. You open the pull request; OSCR asks for no permission.
Request its removal
To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).
Discussion, reproductions, activity
Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.
Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
