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

rooting and pseudotime calculation need some work #130

Open
zouter opened this issue Apr 11, 2019 · 2 comments
Open

rooting and pseudotime calculation need some work #130

zouter opened this issue Apr 11, 2019 · 2 comments

Comments

@zouter
Copy link
Member

zouter commented Apr 11, 2019

  • Pseudotime for cycles doesn't make any sense, because the non-directed geodesic distances are used

  • calculate_pseudotime shouldn't just root the trajectory as it sees fit. The rooting should be done before pseudotime calculation/plotting.

Otherwise, you get things like this:

image

@rcannood
Copy link
Member

rcannood commented Oct 12, 2019

Adding a small reproducible example ;) In both rootings, things are going wrong.

plot

Example code
library(tidyverse)
library(dyno)

milestone_ids <- c("W", "X", "Y", "Z", "A", "B", "C")

milestone_network <- tribble(
  ~from, ~to, ~length, ~directed,
  "W", "X", 2, TRUE,
  "X", "Y", 4, TRUE,
  "Y", "W", 3, TRUE,
  "Y", "Z", 2, TRUE,
  "A", "B", 1, TRUE,
  "C", "A", 1, TRUE
)

progressions <- 
  milestone_network %>% 
  rowwise() %>% 
  do({
    df <- .
    tibble(
      cell_id = paste0(df$from, df$to, seq_len(20)),
      from = df$from,
      to = df$to,
      percentage = seq(0, 1, length.out = length(cell_id))
    )
  }) %>% 
  ungroup()

trajectory <- wrap_data(
  id = "test",
  cell_ids = unique(progressions$cell_id)
) %>% add_trajectory(
  milestone_ids = milestone_ids,
  milestone_network = milestone_network,
  progressions = progressions
)
g1 <- plot_graph(trajectory, label_milestones = TRUE)
t2 <- trajectory %>% add_root(root_milestone_id = "W")
g2 <- 
  plot_graph(
    t2, "pseudotime",
    pseudotime = calculate_pseudotime(t2), 
    label_milestones = TRUE
  ) + labs(title = "Root W")
t3 <- trajectory %>% add_root(root_milestone_id = "Z")
g3 <- 
  plot_graph(
    t3, "pseudotime",
    pseudotime = calculate_pseudotime(t3), 
    label_milestones = TRUE
  ) + labs(title = "Root Z")

patchwork::wrap_plots(g1, g2, g3)
ggsave("~/plot.png", width = 12, height = 4)

@zouter
Copy link
Member Author

zouter commented Nov 28, 2019

Okay, I understand. So if you root at Y (or W, X), you only want to Z-Y if necessary, but not the other edges. So only the edges that are not accessible should be swapped

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

2 participants