Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple root cells possible? #146

Open
TdzBAS opened this issue Jul 16, 2024 · 2 comments
Open

Multiple root cells possible? #146

TdzBAS opened this issue Jul 16, 2024 · 2 comments

Comments

@TdzBAS
Copy link

TdzBAS commented Jul 16, 2024

Hi @flying-sheep ,

Is it possible to set multiple root cells before running pseudotime calculation with palantir?
I have multiple root stem cells in my tissue/data.

Best,
T

@flying-sheep
Copy link
Contributor

I’m not a member of @dpeerlab, so what’s the case

  1. the original API allows it while scanpy’s external wrapper doesn’t allow it and needs to be updated (then this should be a scanpy issue instead of here)
  2. the palantir library itself doesn’t allow it (then it should be here, but I shouldn’t be tagged)

@katosh
Copy link
Collaborator

katosh commented Jul 22, 2024

Hi all! I was confused about the tag too but am happy to clarify.

Pseudotime is defined from one specific start cell and approximates the time a cell would need to differentiate into any other state.

So, for the typical workflow we recommend using a single stem cell that appears to be the most stem-like. For that we often take the cell that is at the extreme for a diffusion component that coincides with the stemness. E.g., in this dataset the stem cells are at the bottom and component 0 reaches a maximum there:
image
To, automatically select the extreme cell you could use

early_cell = palantir.utils.early_cell(ad, celltype="stem_cell", celltype_column="celltype")

Note that this assumes you annotated some cells as "stem_cell" in ad.obs["celltype"]. The subsequent Palantir call could be

palantir.core.run_palantir(ad, early_cell=early_cell)

However, if you really want to compute a psuedotime for multiple root cells, then you can do that too. To compute a separate pseudotime for each root cell you could run

root_cells = [...]
for cell in root_cells:
    palantir.core.run_palantir(
        ad,
        early_cell=cell,
        pseudo_time_key=f"cell_{cell}_psuedotime", 
        entropy_key=f"cell_{cell}_entropy",
        fate_prob_key=f"cell_{cell}_fate_probabilities",
    )

After that, you would have to decide how to define a pseudotime for multiple root cells. Is it the minimal pseudotemporal distance to a root cell? Then you could set it as

ad.obs["multi_root_pseudotime"] = ad.obs[[f"cell_{cell}_psuedotime" for cell in root_cells]].min(axis=1)

Or, if it is the average pseudotemporal distance to a root cell, then you could run

ad.obs["multi_root_pseudotime"] = ad.obs[[f"cell_{cell}_psuedotime" for cell in root_cells]].mean(axis=1)

Please let me know if I got this right or if you have any further questions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants