theislab / moscot

Multi-omic single-cell optimal transport tools
https://moscot-tools.org
BSD 3-Clause "New" or "Revised" License
101 stars 9 forks source link

Pull distributions #676

Closed L-traveling closed 3 months ago

L-traveling commented 3 months ago

I read the article "Mapping cells through time and space with moscot", The superiority of moscot can be verified by the Spearman correlation between gene expression levels of known driver genes and the ancestor probability of cells at a certain time. But when I tried to output the ancestor probability of the cell after tp.pull(source=4, target=7) in Pull/push distributions https://moscot.readthedocs.io/en/latest/notebooks/examples/plotting/100_push_pull.html I ran into a bit of trouble. I went to see the code mentioned in the paper at https://github.com/theislab/moscot-framework_reproducibility, but it seems to be very complicated, could you tell me what is the convenient way to output it? Thank you very much.

MUCDK commented 3 months ago

Hi @L-traveling ,

In order for us to be able to help you, please be more concise with your question, and provide a reproducible example of what you would like to do.

L-traveling commented 3 months ago

Ok @MUCDK ,when I try the following code:

import moscot.plotting as mtp
from moscot import datasets
from moscot.problems.time import TemporalProblem

adata = datasets.hspc()
tp = TemporalProblem(adata).prepare(time_key="day").solve(epsilon=1e-2, threshold=1e-2)

new_key = "subset_push"
tp.pull(
    source=4,
    target=7,
    data="cell_type",
    subset="HSC",
    key_added=new_key,
)
mtp.pull(tp, time_points=[4], key=new_key, basis="umap_GEX")
# mtp.pull(tp, time_points=[7], key=new_key, basis="umap_GEX")

I want to output the ancestor probability of "HSC" at time_points==4. I want to output this data, not just plot it. Thanks.

ArinaDanilina commented 3 months ago

Hi @L-traveling , the output of tp.pull() is saved in the key_added obs column. With this code it would be adata.obs["subset_push"] (you might want to use new_key="subset_pull" for clarity?) and you can subset it to the chosen time point adata[adata.obs["day"] == 4].obs[new_key]. Is this the output you were looking for?

L-traveling commented 3 months ago

Thanks @ArinaDanilina , I get it.