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

enhancement for RCTD function gather_results to increase speed. #196

Open
szimmerman92 opened this issue Mar 22, 2024 · 1 comment
Open

Comments

@szimmerman92
Copy link

Hello,

Thank you for creating this amazing tool. I noticed that the gather_results function can be quite slow for my Xenium data. It has taken several days for samples that have hundreds of thousands of cells. So I decided to rewrite the gather_results function and it appears to be much faster. Do you think this approach could be helpful to speed up RCTD? Thank you. Below please find the code.

library(dplyr)
gather_results <- function(RCTD, results) {
  weights_doublet = bind_rows(lapply(results, function(x) {
    double_weigths_temp = x$doublet_weights
    names(double_weigths_temp) = c("first_type","second_type")
    return(double_weigths_temp)
  }))
  weights_doublet = as.data.frame(weights_doublet)
  rownames(weights_doublet) = barcodes


  weights = bind_rows(lapply(results, function(x) x$all_weights))
  weights = as.data.frame(weights)
  rownames(weights) = barcodes
  colnames(weights) = cell_type_names

  results_df = bind_rows(lapply(results, function(x) {
    spot_class = x["spot_class"]
    first_type = x["first_type"]
    second_type = x["second_type"]
    first_class = x["first_class"]
    second_class = x["second_class"]
    min_score = x["min_score"]
    singlet_score = x["singlet_score"]
    conv_all = x["conv_all"]
    conv_doublet = x["conv_doublet"]
    return(c(spot_class,first_type,second_type,first_class,second_class,min_score,singlet_score,conv_all,conv_doublet))
  }))
  results_df = as.data.frame(results_df)
  rownames(results_df) = barcodes


  score_mat = lapply(results, function(x) x$score_mat)
  singlet_scores = lapply(results, function(x) x$singlet_scores)
  RCTD@results <- list(results_df = results_df, weights = weights, weights_doublet = weights_doublet,
                       score_mat = score_mat, singlet_scores = singlet_scores)
  return(RCTD)
}

@orrzor
Copy link

orrzor commented Apr 9, 2024

Hi Dylan @dmcable , any thoughts on this above? Would be great to speed this up. Thanks! -Orr

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