kstreet13 / slingshot

Functions for identifying and characterizing continuous developmental trajectories in single-cell data.
259 stars 42 forks source link

Average curve weights and Pseudotime #233

Closed ayyildizd closed 6 months ago

ayyildizd commented 8 months ago

I am trying to calculate DE with Tradeseq based on slingshot lineages. I am able to run it for multiple lineages, but there are 3 lineages out of 5 that I want to combine by taking the average. I am trying to make pseudotime and cellWeights objects to feed fitGAM function. So I modified the slingAvgPseudotime function to get averages of the lineages I want like so:

slingAvgPseudotime_custom <- function(x, lineages=NULL){ if (is.null(lineages)) { wts <- slingCurveWeights(x) wts <- wts / rowSums(wts) pst <- slingPseudotime(x) pst[is.na(pst)] <- 0 return(rowSums(pst wts)) } else { wts <- as.data.frame(slingCurveWeights(x)) %>% dplyr::select(all_of(lineages)) wts <- wts / rowSums(wts) pst <- as.data.frame(slingPseudotime(x)) %>% dplyr::select(all_of(lineages)) pst[is.na(pst)] <- 0 return(rowSums(pst wts)) }
}

But how shall I prepare cellWeights data? Can I simply get the mean of the lineages I want from the original cellWeights dataframe or there is a more accurate way to do it?

Thanks a lot!

kstreet13 commented 8 months ago

Hi @ayyildizd,

That's an interesting question! I think the most correct way to do that would be to represent the weights as probabilities (as.probs = TRUE) and then take the sum of the probabilities for those 3 lineages as the probability for the 1 average lineage. You can then convert these probabilities back into weights by scaling such that the maximum weight is 1 (which is the same as dividing each row by its maximum). And that should give you the weights matrix you need.

Let me know if that doesn't work or if anything is unclear!

Best, Kelly