kharchenkolab / pagoda2

R package for analyzing and interactively exploring large-scale single-cell RNA-seq datasets
210 stars 47 forks source link

cannot change value of locked binding for 'counts' #115

Closed xiongyichun closed 3 years ago

xiongyichun commented 3 years ago

Thanks for your excellent work. I have been utilizing pagoda2 for scRNA-seq analysis for a long time. But today while I was running it with newly installed pagoda2, an error ocurred:

library(pagoda2)
>print(class(n_counts))
[1] "matrix"
>print(dim(n_counts))
[1] 4892  500
>print(n_counts[1:5,1:5])
         TTCAGACTTGAGAAb GAACTGTGTCAGGTb AATTACGAACCTTTb GCTACGCTGGACGAb
MADD                0.00            0.00            0.00            0.00
ZNF32               0.00            0.00            0.00            0.01
HIST1H1E            0.03            0.01            0.02            2.00
PXK                 0.00            0.00            0.00            0.01
PDHB                0.00            0.00            1.00            0.00
         ACCGAAACCTATTCb
MADD                0.00
ZNF32               0.01
HIST1H1E            0.02
PXK                 0.00
PDHB                0.00

> p2 = Pagoda2$new(n_counts, n.cores = n_cores,log.scale=F)

<simpleError in self$setCountMatrix(x, min.cells.per.gene = min.cells.per.gene,     trim = trim, min.transcripts.per.cell = 
min.transcripts.per.cell,     lib.sizes = lib.sizes, log.scale = log.scale, keep.genes = keep.genes,     verbose = verbose): 
cannot change value of locked binding for 'counts'>

According to the R Error - cannot change value of locked binding for 'df', I think the problem might ocurred within the function:

setCountMatrix=function(countMatrix, depthScale=1e3, min.cells.per.gene=0, 
                            trim=round(min.cells.per.gene/2), min.transcripts.per.cell=10, 
                            lib.sizes=NULL, log.scale=FALSE, keep.genes=NULL, verbose=TRUE) 

But I'm not sure which line of script. Could you figure out what's the problem and solve it? Many thanks in advance.

evanbiederstedt commented 3 years ago

Hi @xiongyichun

Thanks for using pagoda2.

Yes, this was a scoping error due to how we used to use reference classes. It should be fixed now---please give it a try.

Please let me know if it works now.

Thanks, Evan

xiongyichun commented 3 years ago

Happy new year! Evan. Best wishes to you. (Sorry for forgeting blessing you at the beginning of this issue. I was just too busy and absorbed in my work. Sorry!)

Thank you very much, that problem was solved but another error ocurred: <simpleError in misc[["rawCounts"]] <- counts: object 'misc' not found> I think you are likely to know what it is.

Thank you, YiChun

evanbiederstedt commented 3 years ago

Hi @xiongyichun

That's also my fault---apologies. Please re-install and try again.

Let me know if everything works now. Best, Evan

xiongyichun commented 3 years ago

Hi @evanbiederstedt ,

I tried reinstall it serval times, and the error still exists. I downloaded pagoda2 and installed it as follows:

>remove.packages("pagoda2")
>devtools::install_local("/data/pagoda2-master.zip")

And I have nerver successfully installed new pagoda2 by devtools::install_github('kharchenkolab/pagoda2', build_vignettes = TRUE). At this time the error is:

> devtools::install_github('kharchenkolab/pagoda2', build_vignettes = TRUE)
Downloading GitHub repo kharchenkolab/pagoda2@HEAD

✔  checking for file ‘/tmp/RtmpVF6rYd/remotes3dd579b1f858/kharchenkolab-pagoda2-1cc7c19/DESCRIPTION’ ...
─  preparing ‘pagoda2’:
✔  checking DESCRIPTION meta-information ...
─  cleaning src
─  installing the package to build vignettes
E  creating vignettes (1m 0.8s)
   --- re-building ‘pagoda2.walkthrough.Rmd’ using rmarkdown
   Warning in engine$weave(file, quiet = quiet, encoding = enc) :
     The vignette engine knitr::rmarkdown is not available because the rmarkdown package is not available. Did you forget to add it to Suggests in DESCRIPTION? Please see https://github.com/yihui/knitr/issues/1864 for more information.

   Attaching package: 'igraph'

   The following objects are masked from 'package:stats':

       decompose, spectrum

   The following object is masked from 'package:base':

       union

   Attaching package: 'dplyr'

   The following objects are masked from 'package:igraph':

       as_data_frame, groups, union

   The following objects are masked from 'package:stats':

       filter, lag

   The following objects are masked from 'package:base':

       intersect, setdiff, setequal, union

   Quitting from lines 45-47 (pagoda2.walkthrough.Rmd) 
   Error: processing vignette 'pagoda2.walkthrough.Rmd' failed with diagnostics:
   object 'misc' not found
   --- failed re-building ‘pagoda2.walkthrough.Rmd’

   SUMMARY: processing the following file failed:
     ‘pagoda2.walkthrough.Rmd’

   Error: Vignette re-building failed.
   Execution halted
Error: Failed to install 'pagoda2' from GitHub:
  System command 'R' failed, exit status: 1, stdout + stderr (last 10 lines):
E> Quitting from lines 45-47 (pagoda2.walkthrough.Rmd) 
E> Error: processing vignette 'pagoda2.walkthrough.Rmd' failed with diagnostics:
E> object 'misc' not found
E> --- failed re-building ‘pagoda2.walkthrough.Rmd’
E> 
E> SUMMARY: processing the following file failed:
E>   ‘pagoda2.walkthrough.Rmd’
E> 
E> Error: Vignette re-building failed.
E> Execution halted

I think this is the same error with that one I got while I installed it by devtools::install_local("/data/pagoda2-master.zip") and executed.

Thanks, YiChun

evanbiederstedt commented 3 years ago

Hi @xiongyichun

Please try it again. I've been updating since you last wrote this message, as I've taken time to test it. The vignettes work for me.

Thanks for the patience. Let me know if everything works now.

xiongyichun commented 3 years ago

Thank you very much, @evanbiederstedt . I can install it and execute p2 = Pagoda2$new(n_counts, n.cores = n_cores,log.scale=F) successfully. But another problem started at executing p2$testPathwayOverdispersion :

library(pagoda2)
>print(class(n_counts))
[1] "matrix"
>print(dim(n_counts))
[1] 4892  500
>print(n_counts[1:5,1:5])
         TTCAGACTTGAGAAb GAACTGTGTCAGGTb AATTACGAACCTTTb GCTACGCTGGACGAb
MADD                0.00            0.00            0.00            0.00
ZNF32               0.00            0.00            0.00            0.01
HIST1H1E            0.03            0.01            0.02            2.00
PXK                 0.00            0.00            0.00            0.01
PDHB                0.00            0.00            1.00            0.00
         ACCGAAACCTATTCb
MADD                0.00
ZNF32               0.01
HIST1H1E            0.02
PXK                 0.00
PDHB                0.00
> p2 = Pagoda2$new(n_counts, n.cores = n_cores,log.scale=F)
> p2$adjustVariance(plot=F)
> p2$calculatePcaReduction(nPcs = nPcs,use.odgenes=F,fastpath=F)
> path_names = c()
> env = new.env(parent=globalenv())
> invisible(lapply(1:length(gSets),function(i) {
      genes = intersect(gSets[[i]],rownames(n_counts))
      name = names(gSets[i])
      if(length(genes)>3){
        assign(name, genes, envir = env)
        path_names = c(path_names, name)
      }
    }))

>print(class(env)) 
[1] "environment"
>p2$testPathwayOverdispersion(setenv = env, verbose = T,
                                 recalculate.pca = T,
                                 min.pathway.size = 1)
<simpleError in gzfile(file, mode): cannot open the connection>

I'm not sure whether it came from pagoda2, because I didn't find the code within R script of pagoda2. But I think there is no problem with my rest code. Do you have any idea about this? Many thanks for any suggestion.

Best, YiChun

evanbiederstedt commented 3 years ago

Hi YiChun

I'm guessing it's possibly a permissions issue, cf: https://stackoverflow.com/questions/15363076/error-in-gzfilefile-wb-cannot-open-the-connection-or-compressed-file

However, I cannot really debug the situation from here.

FWIW, I would stay away from assign() if I were you. Refer to, e.g. https://stackoverflow.com/questions/17559390/why-is-using-assign-bad https://stackoverflow.com/questions/54064394/when-is-rs-assign-function-appropriate

Glad it is working! Apologies about the issues

Best, Evan

xiongyichun commented 3 years ago

Hi Evan,

Many thanks for your help. Your suggestion is very valuable. Now that this issue doesn't come from pagoda2, I believe it's my problem and I will debug it.

Thanks again for your patient help and debuging.

Happy new year! Best, YiChun