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

Report renv causes jupyterlab kernel die #2097

Open
dfc-1931475 opened this issue Feb 23, 2025 · 0 comments
Open

Report renv causes jupyterlab kernel die #2097

dfc-1931475 opened this issue Feb 23, 2025 · 0 comments

Comments

@dfc-1931475
Copy link

Hello, thanks for developing this useful tool.

I got some problem when I use renv in jupyterlab:

When I ran a single cell project practice here, More specifically, the **find_de_MAST_RE**function in Chapter16.5.1. It is to use MAST package to fit model. However, once the code is coming to summaryCond <- summary(zlmCond, doLRT='groupstim.CD14_Monocytes')(within the find_de_MAST_RE function), my jupyterlab will report kernel died immediately, without any traceback information. The code will work well if I run renv::deactivate command, may you know why could this happen? Is there any method to make jupyterlab and renv work well with each other?

the find_de_MAST_RE function is like below:

  %%R
  find_de_MAST_RE <- function(adata_){
      # create a MAST object
      sca <- SceToSingleCellAssay(adata_, class = "SingleCellAssay")
      print("Dimensions before subsetting:")
      print(dim(sca))
      print("")
      # keep genes that are expressed in more than 10% of all cells
      sca <- sca[freq(sca)>0.1,]
      print("Dimensions after subsetting:")
      print(dim(sca))
      print("")
      # add a column to the data which contains scaled number of genes that are expressed in each cell
      cdr2 <- colSums(assay(sca)>0)
      colData(sca)$ngeneson <- scale(cdr2)
      # store the columns that we are interested in as factors
      label <- factor(colData(sca)$label)
      # set the reference level
      label <- relevel(label,"ctrl")
      colData(sca)$label <- label
      celltype <- factor(colData(sca)$cell_type)
      colData(sca)$celltype <- celltype
      # same for donors (which we need to model random effects)
      replicate <- factor(colData(sca)$replicate)
      colData(sca)$replicate <- replicate
      # create a group per condition-celltype combination
      colData(sca)$group <- paste0(colData(adata_)$label, ".", colData(adata_)$cell_type)
      colData(sca)$group <- factor(colData(sca)$group)
      # define and fit the model
      zlmCond <- zlm(formula = ~ngeneson + group + (1 | replicate), 
                     sca=sca, 
                     method='glmer', 
                     ebayes=F, 
                     strictConvergence=F,
                     fitArgsD=list(nAGQ = 0)) # to speed up calculations
      
      # perform likelihood-ratio test for the condition that we are interested in    
      summaryCond <- summary(zlmCond, doLRT='groupstim.CD14_Monocytes')
      # get the table with log-fold changes and p-values
      summaryDt <- summaryCond$datatable
      result <- merge(summaryDt[contrast=='groupstim.CD14_Monocytes' & component=='H',.(primerid, `Pr(>Chisq)`)], # p-values
                       summaryDt[contrast=='groupstim.CD14_Monocytes' & component=='logFC', .(primerid, coef)],
                       by='primerid') # logFC coefficients
      # MAST uses natural logarithm so we convert the coefficients to log2 base to be comparable to edgeR
      result[,coef:=result[,coef]/log(2)]
      # do multiple testing correction
      result[,FDR:=p.adjust(`Pr(>Chisq)`, 'fdr')]
      result = result[result$FDR<0.01,, drop=F]
  
      result <- stats::na.omit(as.data.frame(result))
      return(result)
  }
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

1 participant