Teichlab / cellphonedb

MIT License
340 stars 105 forks source link

API for cellphonedb ? #208

Closed giovp closed 3 years ago

giovp commented 3 years ago

Hi, was wondering: is there any plan to provide an API to use cellphonedb from within python? This would make it super convenient to include cellphonedb in a standard single cell analysis workflow (e.g. with scanpy) and the community could build up other tools on top of it. I'm thinking something like this:

import scanpy as sc
import cellphonedb

adata = sc.datasets.pbmc3k()
results = cellphonedb.method.statistical_analysis(adata)

Thank you!

mief commented 3 years ago

That's a great idea, thanks! We haven't had the time to do this, but hopefully in future. Thanks, Mirjana

stefanpeidli commented 3 years ago

Hi Giovanni @giovp and cellphonedb-people,

I've made a fork where you can use statistical_analysis and anaylsis via python on adata objects. It works like this for example:

import cellphonedb as cphdb
outs=cphdb.statistical_analysis_scanpy(adata, var_names=adata.var_names, obs_names=adata.obs_names, obs_key='cell_type')

obs_key must be something that groups the cells in adata.obs (like 'louvain' or sth like that). Cellphonedb checks for interactions between these groups.

Definetly improvable, but seems to work fine (there is a jupyter notebook in the fork which shows that the results are the same as for conventional API usage). Would be cool to make cellphonedb work with sparse data as well.

Best, Stefan

mief commented 3 years ago

That's really great, many thanks!

giovp commented 3 years ago

Hi @stefanpeidli ! hope you are doing well!

fun fact, since we had no reply, we had the awesome @michalk8 reimplementing with speed up + couple other of improvements. We are testing it and should be released with an upcoming package we are wrapping up. Will keep you posted!

grst commented 3 years ago

Hi @giovp,

is this available already?

giovp commented 3 years ago

hey @grst , my bad missing this. Yes it is! You can find an example here: https://squidpy.readthedocs.io/en/latest/auto_examples/graph/compute_ligrec.html

it's much faster and also uses a larger database (omnipath, whihc contains cellphonedb as well as many others). Looking forward to feedbacks!

grst commented 3 years ago

very cool, thanks!