dynverse / dyneval

Metrics to compare two or more trajectories ⚖
2 stars 2 forks source link

problems with ti_slingshot.R #57

Open QidiFeng opened 5 years ago

QidiFeng commented 5 years ago

Hi Wouter,

Sorry to trouble again~ I met another problem when I tried to use the code in ti_slingshot.R to wrap the slingshot results into model required by dyneval: model <- dynwrap::wrap_data( cell_ids = rownames(expression) ) %>% dynwrap::add_trajectory( milestone_network = cluster_network, progressions = progressions ) %>% dynwrap::add_dimred( dimred = dimred )

Error: assert_that: missing values present in assertion

I checked it into detail and found 'progressions' may cause the error. When the inferred trajectory contains more than one lineages, then the produced progression contain multiple 'NA' in 'percentage' column. If the inferred trajectory contains only one lineage. Then the progressions does not contain NA and the error would not appear. I am wondering how to fix the problem? I attached the slingshot results below slingshot.data5.method1.RData.zip And the code for getting 'progressions' is below:

progressions <- map_df(seq_along(lineages), function(l) { ind <- lin_assign == l lin <- lineages[[l]] pst.full <- slingPseudotime(slingout, na = FALSE)[,l] pst <- pst.full[ind] means <- sapply(lin, function(clID){ stats::weighted.mean(pst.full, cluster[,clID]) }) non_ends <- means[-c(1,length(means))] edgeID.l <- as.numeric(cut(pst, breaks = c(-Inf, non_ends, Inf))) from.l <- lineages[[l]][edgeID.l] to.l <- lineages[[l]][edgeID.l + 1] m.from <- means[from.l] m.to <- means[to.l]

pct <- (pst - m.from) / (m.to - m.from)
pct[pct < 0] <- 0
pct[pct > 1] <- 1

tibble(cell_id = names(which(ind)), from = from.l, to = to.l, percentage = pct)

})

Thank you very much!

Best, Qidi