https://github.com/brentp/combat.py
python / numpy / pandas / patsy version of ComBat for removing batch effects.
https://github.com/brentp/combat.py
Last synced: 3 months ago
JSON representation
python / numpy / pandas / patsy version of ComBat for removing batch effects.
- Host: GitHub
- URL: https://github.com/brentp/combat.py
- Owner: brentp
- License: mit
- Created: 2012-10-10T23:12:39.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2018-12-31T06:03:39.000Z (over 6 years ago)
- Last Synced: 2024-10-13T02:21:12.336Z (8 months ago)
- Language: Python
- Size: 18.9 MB
- Stars: 101
- Watchers: 6
- Forks: 43
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
ComBat is an R package for removing batch effects from data.
This is a python version that matches the output from the ComBat function
in SVA (http://www.bioconductor.org/packages/release/bioc/html/sva.html).
This code is completely copied from the ComBat function in that package.Compare
=======To test, run this R code (requires sva and bladderbatch from bioconductor):
```Shell
Rscript R-combat.R
```
Then, from the same directory, run
```Shell
python combat.py
```
you can then run this python code to see the differences:
```Python
import pandas as pa
p = pa.read_table('py-batch.txt', index_col=0)
r = pa.read_table('r-batch.txt', index_col=0)print (p - r).max().max()
```
This outputs 3.9423421307e-05 on my machine. Indicating that
that is the largest difference between the 22,283*57 values generated by the
R version and those generated in this version.Performance
===========
In the example above, the combat function runs in < 1 second in python
and about 15 seconds in R.On an identical dataset, of 30K rows * 190 samples, this python version finishes in 10.008s
as measured by unix `time`.
The R version takes 4m0.681s with output identical to 3 decimal places. This is a speed-up
of about *24x.*The speed improvement seems to be larger for larger datasets.
Function
========The python version is usable as a module, the function has the signature:
```Python
combat(dat, batch, mod, numCovs=None)
```
which is the same as the R function except the non-parametric version is not supported.
+ dat is the expression/methylation data.
+ batch is a list containing the batch variable
+ mod is the model matrix (can use patsy for this from python)
+ numCovs is a list like ["age", "height"], that gives the column name or number
of numeric variables in batch (otherwise they will be converted to factors).Read
====Johnson WE, Rabinovic A, Li C (2007). Adjusting batch effects in microarray
expression data using Empirical Bayes methods. Biostatistics 8:118-127.Jeffrey T. Leek, W. Evan Johnson, Hilary S. Parker, Andrew E. Jaffe
and John D. Storey (). sva: Surrogate Variable Analysis. R package
version 3.4.0.