Giter Site home page Giter Site logo

combat.py's Introduction

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):

Rscript R-combat.R

Then, from the same directory, run

python combat.py

you can then run this python code to see the differences:

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:

   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.

combat.py's People

Contributors

brentp avatar mgalardini avatar olgabot avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.