dmcable / spacexr

Spatial-eXpression-R: Cell type identification (including cell type mixtures) and cell type-specific differential expression for spatial transcriptomics
GNU General Public License v3.0
293 stars 72 forks source link

Error while using run.RCTD #22

Closed Roopali24 closed 3 years ago

Roopali24 commented 3 years ago

Hi,

I am using RCTD on a small data with about 500 genes and 1000 spots/locations. When I run: myRCTD <- run.RCTD(myRCTD, doublet_mode = TRUE)

I get the following error:

[1] "fitBulk: decomposing bulk" Error in eigen(H) : infinite or missing values in 'x'

I read issue #12 dealing with the similar problem. So, here's the output for the items you asked for in that issue:

> print(head(myRCTD@spatialRNA@counts)) [1] 14.648361 6.008264 1.104699 6.318929 2.351550 0.000000 > print(head(myRCTD@spatialRNA@nUMI)) V1 V2 V3 V4 V5 V6 5006.512 4022.487 3945.382 5089.467 4635.124 4960.622 > print(head(myRCTD@internal_vars$gene_list_bulk)) [1] "X1700020I14Rik" "X2210016L21Rik" "Ablim1"
[4] "Acin1" "Acsl3" "Acta2"
> print(head(myRCTD@cell_type_info$info[[1]])) Astrocytes Bergmann.Glia Choroid.Plexus X1500015O10Rik 0.03635281 0.038624339 3.826799959 X1700020I14Rik 0.03466931 0.092286325 0.051521164 X2210016L21Rik 0.09262941 0.254168609 0.126459836 Abcb1a 0.00000000 0.004166667 0.002777778 Abcf1 0.04642450 0.258029656 0.110164743 Ablim1 0.03951178 0.047129630 0.110028860 Endothelial.Stalk Granular Microglia Muraland.Tip X1500015O10Rik 0.20555556 0.00000000 0.00000000 NA X1700020I14Rik 0.12438079 0.72294779 0.02333333 Inf X2210016L21Rik 0.08777177 0.32393347 0.02229992 Inf Abcb1a 1.18577494 0.04166667 0.00000000 NA Abcf1 0.15817207 0.32962621 0.06894180 NA Ablim1 0.79753693 0.47035326 0.02103175 Inf Oligo.Poly.dendrocyte Other.Interneurons Purkinje X1500015O10Rik 0.001754386 0.00000000 0.0000000 X1700020I14Rik 0.042232582 0.58493155 1.0744829 X2210016L21Rik 0.137362355 0.38850992 0.4954387 Abcb1a 0.000000000 0.00000000 0.0000000 Abcf1 0.179369232 0.35011960 0.4989859 Ablim1 0.004415954 0.07170912 0.8698186 PV.Interneurons X1500015O10Rik 0.00000000 X1700020I14Rik 0.28598125 X2210016L21Rik 0.15685465 Abcb1a 0.00000000 Abcf1 0.19325718 Ablim1 0.08049062

As you can see one of the cell types is showing NA or Inf values. But I checked and my dge matrix does not have any NA or Inf values. Do you know why this might be happening?

Please help

Roopali

dmcable commented 3 years ago

Hello, please try with the newest version of RCTD, which should fix several of these issues. Please let me know if the issue persists. I will note that RCTD is configured for integer counts -- please round to the nearest count before passing into RCTD. This may be causing the issue. May I ask how you obtained decimal number counts? Are these counts normalized in some form?

Roopali24 commented 3 years ago

Hello, thank you so much for your quick response. I will try with the latest version and let you know if I get similar issue. And yes, I think the counts are normalized so i will put the original counts instead. Thank you pointing that out.

Roopali24 commented 3 years ago

Hi,

So I am running RCTD on this data using this code: refdir <- system.file("extdata",'Reference/mydata',package = 'RCTD') reference <- dgeToSeurat(refdir) datadir <- system.file("extdata",'SpatialRNA/mydata',package = 'RCTD') puck <- read.SpatialRNA(datadir) myRCTD <- create.RCTD(puck, reference, max_cores = 2)

But it only gives me estimates for 962 spots instead of 1000 spots and so I checked the dimension of my puck and rctd object, this is what I get:

dim(myRCTD@spatialRNA@coords) [1] 962 2 dim(puck@coords) [1] 1000 2

I do not understand why this is happening.

Thank you in advance.

dmcable commented 3 years ago

Hello,

Please see the updated vignette https://raw.githack.com/dmcable/RCTD/dev/vignettes/spatial-transcriptomics.html for instructions on how to create the Reference and SpatialRNA objects.

dgeToSeurat and read.SpatialRNA are not used in the current version of RCTD.

Dylan

Roopali24 commented 3 years ago

Hi Cable,

Thank you for the vignette. So now I am using the new method but when I run:

reference <- Reference(counts, cell_types, nUMI I get the following error: Error in Reference(counts, cell_types, nUMI) : could not find function "Reference"

Not sure why. I have RCTD, Matrix and seurat library loaded. Any other package I need for this?

Thank you, Roopali

dmcable commented 3 years ago

Roopali,

Looks good on your end -- I made a mistake where I forgot to add the file for the documentation of RCTD Reference function. Please re-update the package and try again. Sorry for the inconvenience.

Dylan

Roopali24 commented 3 years ago

Hello Dylan,

When I re-install the package using devtools::install_github("dmcable/RCTD", build_vignettes = TRUE)

I get this error:

Error: Failed to install 'RCTD' from GitHub: System command 'R' failed, exit status: 1, stdout + stderr (last 10 lines): E> Quitting from lines 119-121 (spatial-transcriptomics.Rmd) E> Error: processing vignette 'spatial-transcriptomics.Rmd' failed with diagnostics: E> argument "cell_type_names" is missing, with no default E> --- failed re-building ‘spatial-transcriptomics.Rmd’ E> E> SUMMARY: processing the following file failed: E> ‘spatial-transcriptomics.Rmd’ E> E> Error: Vignette re-building failed. E> Execution halted

So, instead I install it as devtools::install_github("dmcable/RCTD", build_vignettes = FALSE) When I run reference <- Reference(counts, cell_types, nUMI)

I still get the following error: Error in Reference(counts, cell_types, nUMI) : could not find function "Reference"

Is it due to to the installation process?

Thanks, Roopali

dmcable commented 3 years ago

Yes, we had an issue with cell_type_names mixing that was fixed in a recent PR. Please try again, and thank you for your patience.

Roopali24 commented 3 years ago

Thank you for your response. I was able to install RCTD using devtools::install_github("dmcable/RCTD", build_vignettes = TRUE)

But I still get the error: Error in Reference(counts, cell_types, nUMI) : could not find function "Reference"

Thanks, Roopali

dmcable commented 3 years ago

Can you try clearing your R session and then doing library(RCTD)? Thank you.

Roopali24 commented 3 years ago

Thank you for your help. I started a new session and everything worked fine but the original problem still occurs i.e.

dim(myRCTD@spatialRNA@coords) [1] 962 2 dim(puck@coords) [1] 1000 2

dmcable commented 3 years ago

Dear Roopali,

Glad to hear. This is most likely because RCTD filters out pixels with fewer than UMI_MIN UMIs. You may change the UMI_MIN parameter in create.RCTD (which was 100 by default), or you may directly edit the RCTD parameters by doing myRCTD@config$UMI_MIN = YOUR_NEW_VALUE.

Roopali24 commented 3 years ago

Hi Dylan,

I checked the UMI counts for the locations and this is the summary:

summary(nUMI) Min. 1st Qu. Median Mean 3rd Qu. Max. 11256 38648 56458 64350 69484 206376

However, I still tried setting the UMI_min to 1 by using myRCTD <- create.RCTD(puck, reference, max_cores = 1, UMI_min = 1)

and this didn't fix the problem either. I still get 962 locations instead of 1000.

dmcable commented 3 years ago

Ah, likewise, I believe there is a UMI_max parameter set to 200,000 or so.

Dylan

Roopali24 commented 3 years ago

Yes that was the issue. Thank you so much for all your help. Means a lot.

Roopali