Commit 460fe53f authored by Blaise Li's avatar Blaise Li
Browse files

Correct bed sort, moved stuff to libs and wrappers

parents
#!/bin/sh
python3.6 setup.py build_ext
pip3.6 install -e .
from .libhts import do_deseq2
import pandas as pd
from rpy2.robjects import r, pandas2ri, Formula, StrVector
as_df = r("as.data.frame")
from rpy2.robjects.packages import importr
deseq2 = importr("DESeq2")
def do_deseq2(cond_names, conditions, counts_data,
formula=None, contrast=None, deseq2_args=None):
"""Runs a DESeq2 differential expression analysis."""
if formula is None:
formula = Formula("~ lib")
if contrast is None:
contrast = StrVector(["lib", MUT, REF])
if deseq2_args is None:
deseq2_args = {"betaPrior" : True, "addMLE" : True, "independentFiltering" : True}
col_data = pd.DataFrame(conditions).assign(cond_name=pd.Series(cond_names).values)
col_data.set_index("cond_name", inplace=True)
# In case we want contrasts between factor combinations
if ("lib" in col_data.columns) and ("treat" in col_data.columns):
col_data = col_data.assign(
lib_treat = ["%s_%s" % (lib, treat) for (lib, treat) in zip(
col_data["lib"], col_data["treat"])])
# http://stackoverflow.com/a/31206596/1878788
pandas2ri.activate() # makes some conversions automatic
# r_counts_data = pandas2ri.py2ri(counts_data)
# r_col_data = pandas2ri.py2ri(col_data)
# r.DESeqDataSetFromMatrix(countData=r_counts_data, colData=r_col_data, design=Formula("~lib"))
dds = deseq2.DESeqDataSetFromMatrix(
countData=counts_data,
colData=col_data,
design=formula)
dds = deseq2.DESeq(dds, betaPrior=deseq2_args["betaPrior"])
res = pandas2ri.ri2py(as_df(deseq2.results(
dds,
contrast=contrast,
addMLE=deseq2_args["addMLE"],
independentFiltering=deseq2_args["independentFiltering"])))
res.index = counts_data.index
return res
from setuptools import setup, find_packages
#from Cython.Build import cythonize
name = "libhts"
# Adapted from Biopython
__version__ = "Undefined"
for line in open("%s/__init__.py" % name):
if (line.startswith('__version__')):
exec(line.strip())
setup(
name=name,
version=__version__,
description="Miscellaneous things to process high throughput sequencing data.",
author="Blaise Li",
author_email="blaise.li@normalesup.org",
license="MIT",
packages=find_packages())
#ext_modules = cythonize("libsmallrna/libsmallrna.pyx"),
#install_requires=["cytoolz"],
#zip_safe=False
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment