Jfortin1 / neuroCombat

Harmonization of multi-site imaging data with ComBat (Python)
MIT License
124 stars 37 forks source link
combat harmonization mri-images multi-site-imaging neuroimaging normalization python

Multi-site harmonization in Python with neuroCombat

License: MIT Version [PythonVersion]()

This is the maintained and official version of neuroCombat (previously hosted here) introduced in our our recent paper.

Installation

neuroCombat is hosted on PyPI, and the easiest way to install neuroCombat is to use the pip command:

pip install neuroCombat

Usage

The neuroCombat function performs harmonization

from neuroCombat import neuroCombat
import pandas as pd
import numpy as np

# Getting example data
# 200 rows (features) and 10 columns (scans)
data = np.genfromtxt('testdata/testdata.csv', delimiter=",", skip_header=1)

# Specifying the batch (scanner variable) as well as a biological covariate to preserve:
covars = {'batch':[1,1,1,1,1,2,2,2,2,2],
          'gender':[1,2,1,2,1,2,1,2,1,2]} 
covars = pd.DataFrame(covars)  

# To specify names of the variables that are categorical:
categorical_cols = ['gender']

# To specify the name of the variable that encodes for the scanner/batch covariate:
batch_col = 'batch'

#Harmonization step:
data_combat = neuroCombat(dat=data,
    covars=covars,
    batch_col=batch_col,
    categorical_cols=categorical_cols)["data"]

Optional arguments

Output

Since version 0.2.10, the neuroCombat function outputs a dictionary with 3 elements:

To simply return the harmonized data, one can use the following:

data_combat = neuroCombat(dat=dat, ...)["data"]

where ... are the user-specified arguments needed for harmonization.