theislab / single-cell-tutorial

Single cell current best practices tutorial case study for the paper:Luecken and Theis, "Current best practices in single-cell RNA-seq analysis: a tutorial"
1.39k stars 458 forks source link

Running in pure python env: in a .py file #83

Open DUAN-GAO opened 2 years ago

DUAN-GAO commented 2 years ago

Hello Malte,I m running in a .py file, when I tried to use scran function computeSumFactors, that I need to convert anndata to SingleCellExperiment object,I tried following but not worked: a = robjects.r'list' b = robjects.r'SingleCellExperiment' size_factors = computeSumFactors(b, clusters=input_groups)

could you help, many thanks.

LuckyMD commented 2 years ago

Hi @Iweirdo,

You can take the command for how to run the calculateSumFactors function (as it's now called) from #77. This function is from scran, which is an R package. So you'd need to run it in r. Try something like:

import rpy2.robjects as ro

ro.r('data') = data
adata.obs['size_factors'] = ro.r('calculateSumFactors(...)')

I haven't tested the above. This is just to give you an idea of what needs to be run in R and what in python.