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

Load_10XSpatial() Error with CytAssist loading #7608

Closed
ejscience opened this issue Jul 25, 2023 · 10 comments
Closed

Load_10XSpatial() Error with CytAssist loading #7608

ejscience opened this issue Jul 25, 2023 · 10 comments

Comments

@ejscience
Copy link

Hello, I have been trying to load a 10X Visium CytAssist counts matrix into a Spatial Seurat object but I keep running into an issue with having the data load. When I submit the data with

data_dir <- "/mnt/DATA/LairdLab/rojas/SCT_SpTrProject/data/05outs/"
list.files(data_dir)
SCT05 <- Load10X_Spatial(data.dir = data_dir)

It gives me an error of

Error in Load10X_Spatial(data.dir = data_dir) : 
  Image must be an object of class 'VisiumV1'.

Then to fix this I try to add an image file by using the following command which outputs a "LargeVisiumV1"

image_dir <- "/mnt/DATA/LairdLab/rojas/SCT_SpTrProject/data/05outs/spatial/"
image <- Read10X_Image(image.dir = image_dir)

Then when I finally run the Load10X_Spatial again I get

> SCT05 <- Load10X_Spatial(data.dir = data_dir, image = image)
Error in Read10X_h5(filename = file.path(data.dir, filename), ...) : 
  unused argument (image = new("VisiumV1", image = c(0.486274509803922, 0.603921568627451, 0.603921568627451, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.596078431372549, 0.596078431372549, 0.596078431372549, 0.596078431372549, 0.596078431372549, 0.596078431372549, 0.596078431372549, 0.596078431372549, 0.596078431372549, 0.592156862745098, 0.592156862745098, 0.592156862745098, 0.592156862745098, 0.588235294117647, 0.588235294117647, 0.588235294117647, 0.588235294117647, 0.588235294117647, 0.584313725490196, 
0.584313725490196, 0.584313725490196, 0.584313725490196, 0.584313725490196, 0.584313725490196, 0.584313725490196, 0.584313725490196, 0.584313725490196, 0.580392156862745, 0.580392156862745, 0.580392156862745, 0.580392156862745, 0.580392156862745, 0.580392156862745, 0.580392156862745, 0.580392156862745, 0.580392156862745, 0.580392156862745, 0.580392156862745, 0.576470588235294, 0.576470588235294, 0.576470588235294, 0.572549019607843, 0.572549019607843, 0.572549019607843, 0

Can anyone help me figure this out please? I looked it up and only found this link to some people but it did not help this issue.

Here is my sessionInfo for any help

> sessionInfo()
R version 4.3.0 (2023-04-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.2 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0 
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Etc/UTC
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] Seurat_4.9.9.9058       patchwork_1.1.2         ggplot2_3.4.2           SeuratData_0.2.2        SeuratObject_4.9.9.9091
[6] sp_2.0-0               

loaded via a namespace (and not attached):
  [1] deldir_1.0-9           pbapply_1.7-2          gridExtra_2.3          remotes_2.4.2.1        rlang_1.1.1           
  [6] magrittr_2.0.3         RcppAnnoy_0.0.21       matrixStats_1.0.0      ggridges_0.5.4         compiler_4.3.0        
 [11] spatstat.geom_3.2-4    png_0.1-8              vctrs_0.6.3            reshape2_1.4.4         hdf5r_1.3.8           
 [16] stringr_1.5.0          crayon_1.5.2           pkgconfig_2.0.3        fastmap_1.1.1          ellipsis_0.3.2        
 [21] utf8_1.2.3             promises_1.2.0.1       bit_4.0.5              purrr_1.0.1            jsonlite_1.8.7        
 [26] goftest_1.2-3          later_1.3.1            spatstat.utils_3.0-3   irlba_2.3.5.1          parallel_4.3.0        
 [31] cluster_2.1.4          R6_2.5.1               ica_1.0-3              stringi_1.7.12         RColorBrewer_1.1-3    
 [36] spatstat.data_3.0-1    reticulate_1.30        parallelly_1.36.0      lmtest_0.9-40          scattermore_1.2       
 [41] Rcpp_1.0.11            tensor_1.5             future.apply_1.11.0    zoo_1.8-12             sctransform_0.3.5     
 [46] httpuv_1.6.11          Matrix_1.5-1           splines_4.3.0          igraph_1.5.0.1         tidyselect_1.2.0      
 [51] rstudioapi_0.15.0      abind_1.4-5            spatstat.random_3.1-5  codetools_0.2-19       miniUI_0.1.1.1        
 [56] spatstat.explore_3.2-1 curl_5.0.1             listenv_0.9.0          lattice_0.21-8         tibble_3.2.1          
 [61] plyr_1.8.8             withr_2.5.0            shiny_1.7.4.1          ROCR_1.0-11            Rtsne_0.16            
 [66] future_1.33.0          fastDummies_1.7.3      survival_3.5-3         polyclip_1.10-4        fitdistrplus_1.1-11   
 [71] pillar_1.9.0           KernSmooth_2.23-20     plotly_4.10.2          generics_0.1.3         RcppHNSW_0.4.1        
 [76] munsell_0.5.0          scales_1.2.1           globals_0.16.2         xtable_1.8-4           glue_1.6.2            
 [81] lazyeval_0.2.2         tools_4.3.0            data.table_1.14.8      RSpectra_0.16-1        RANN_2.6.1            
 [86] leiden_0.4.3           dotCall64_1.0-2        cowplot_1.1.1          grid_4.3.0             tidyr_1.3.0           
 [91] colorspace_2.1-0       nlme_3.1-162           cli_3.6.1              rappdirs_0.3.3         spatstat.sparse_3.0-2 
 [96] spam_2.9-1             fansi_1.0.4            viridisLite_0.4.2      dplyr_1.1.2            uwot_0.1.16           
[101] gtable_0.3.3           digest_0.6.33          progressr_0.13.0       ggrepel_0.9.3          htmlwidgets_1.6.2     
[106] htmltools_0.5.5        lifecycle_1.0.3        httr_1.4.6             mime_0.12              bit64_4.0.5           
[111] MASS_7.3-59  
@ejscience ejscience changed the title Visium CytAssist Load_10XSpatial() Image must be an object of class 'VisiumV1' not able to load into SeuratObject Load_10XSpatial() Error with CytAssist loading Jul 25, 2023
@alikhuseynov
Copy link
Contributor

could you please list the output of list.files(data_dir) ?
It could be the modifications in SpaceRanger output, see these issues #6338 #6362 and this PR #6208
You might be able to fix it by modifying tissue_positions file, see this comment

@David-J-Byrne
Copy link

David-J-Byrne commented Jul 30, 2023

Hi Team,

I have been using Seurat V5 for a few weeks now with no problems loading Visium datasets via "load10X_Spatial" until today when I updated to version Seurat_4.9.9.9058 from Seurat_4.9.9.9041 and SeuratObject_4.9.9.9091 from SeuratObject_4.9.9.9081. Possible bug?

looks like a problem with Load10X_Spatial because if I use a workaround that I put together to use ENSEMBL IDs the data loads fine (see code below)

# read spatial rnaSeq data with ENSEMBL IDs from features.tsv
data <- Read10X(data_ENSMBL_dir_pri,
                gene.column = 1, # 1= ENSEMBL, 2= GENE SYMBOL
                cell.column = 1,
                unique.features = TRUE,
                strip.suffix = FALSE
                )
# create seurat object from data dgCMatrix
seurat_pri_ENSMBL <- CreateSeuratObject(counts = data,
                                        assay = "Spatial"
                                        )
# read Visium image file
image_pri <- Read10X_Image(data_spatial_pri,
                           image.name = "tissue_lowres_image.png",
                           filter.matrix = TRUE
                           )
image_pri <- image_pri[Cells(x = seurat_pri_ENSMBL)]
# set default assay in image to spatial
DefaultAssay(object = image_pri) <- "Spatial"
# add Visium data to image slot
seurat_pri_ENSMBL[[pri_sample_id]] <- image_pri

Cheers
David

@Polligator
Copy link

I found the root cause of this error
part of the original code for Load10X_Spatial, which look like the below:

function (data.dir, filename = "filtered_feature_bc_matrix.h5",
assay = "Spatial", slice = "slice1", filter.matrix = TRUE,
to.upper = FALSE, ...) {
.......
if (is.null(x = image)) {
image <- Read10X_Image(image.dir = file.path(data.dir,
"spatial"), filter.matrix = filter.matrix)
}
.....
}

as you can see, the "image = NULL," is not present as one of the default parameters, therefore, (is.null(x = image)) will always be FLASE, Read10X_Image function is never going to load the image folder. when checking (!inherits(x = image, what = "VisiumV1")), it will never pass, you will always get the error: "Image must be an object of class 'VisiumV1'."

the fix is to add "image = NULL," before the three dots to
function (data.dir, filename = "filtered_feature_bc_matrix.h5",
assay = "Spatial", slice = "slice1", filter.matrix = TRUE,
to.upper = FALSE, ...){
......

}

@martina-morchio
Copy link

Hi! I have the same issue but the fixes mentioned above aren't working for me...

LN15_A1<-Load10X_Spatial(filedir,filename="filtered_feature_bc_matrix.h5", assay="Spatial",slice="LN15_A1",filter.matrix=TRUE)
Error in Load10X_Spatial(filedir, filename = "filtered_feature_bc_matrix.h5",  : 
  Image must be an object of class 'VisiumV1'.

I have changed the tissue_positions.csv file to tissue_positions_list.csv and it still gives the same error.
If I try and upload the image separately, this is what happens:

> LN15_A1_image <- Read10X_Image(image.dir=paste0(filedir,"/spatial"),image.name="tissue_lowres_image.png",filter.matrix = TRUE)
> LN15_A1_image
Spatial data from the VisiumV1 technology for 960 samples
Associated assay:  
Image key:  
> LN15_A1<-Load10X_Spatial(filedir,filename="filtered_feature_bc_matrix.h5", assay="Spatial",slice="LN15_A1",filter.matrix=TRUE,image=LN15_A1_image)
Error in Read10X_h5(filename = file.path(data.dir, filename), ...) : 
  unused argument (image = new("VisiumV1", image = c(0.52156862745098, 0.52156862745098, 0.52156862745098, 0.52156862745098, 0.52156862745098, 0.52156862745098, 0.52156862745098, 0.52156862745098, 0.52156862745098, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.52156862745098, 0.52156862745098, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 
0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 

I checked the tissue_position_list.csv and it looks fine eg

barcode,in_tissue,array_row,array_col,pxl_row_in_fullres,pxl_col_in_fullres
ACGCCTGACACGCGCT-1,0,0,0,3583,28697
TACCGATCCAACACTT-1,0,1,1,3762,28392
ATTAAAGCGGACGAGC-1,0,0,2,3935,28700
GATAAGGGACGATTAG-1,0,1,3,4114,28396
GTGCAAATCACCAATA-1,0,0,4,4287,28703

Don't know what the issue is, anyone has any idea?

These are the directories my files are in:

> list.files(filedir)
[1] "filtered_feature_bc_matrix"    "filtered_feature_bc_matrix.h5" "spatial" 
> list.files(paste0(filedir,"/spatial"))
[1] "aligned_fiducials.jpg"     "detected_tissue_image.jpg" "scalefactors_json.json"    "spatial_enrichment.csv"    "tissue_hires_image.png"   
[6] "tissue_lowres_image.png"   "tissue_positions_list.csv"

And this is my sessionInfo()

> sessionInfo()
R version 4.2.3 (2023-03-15)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.3.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] dplyr_1.1.2             patchwork_1.1.2         ggplot2_3.4.2           Seurat_4.9.9.9050       SeuratObject_4.9.9.9086
[6] sp_2.0-0               

loaded via a namespace (and not attached):
  [1] spam_2.9-1                  plyr_1.8.8                  igraph_1.5.0                lazyeval_0.2.2             
  [5] splines_4.2.3               RcppHNSW_0.4.1              BiocParallel_1.32.6         listenv_0.9.0              
  [9] scattermore_1.2             GenomeInfoDb_1.34.9         digest_0.6.31               htmltools_0.5.5            
 [13] fansi_1.0.4                 magrittr_2.0.3              memoise_2.0.1               tensor_1.5                 
 [17] cluster_2.1.4               ROCR_1.0-11                 globals_0.16.2              Biostrings_2.66.0          
 [21] annotate_1.76.0             matrixStats_1.0.0           spatstat.sparse_3.0-2       colorspace_2.1-0           
 [25] blob_1.2.4                  ggrepel_0.9.3               crayon_1.5.2                RCurl_1.98-1.12            
 [29] jsonlite_1.8.7              progressr_0.13.0            spatstat.data_3.0-1         survival_3.5-5             
 [33] zoo_1.8-12                  glue_1.6.2                  polyclip_1.10-4             gtable_0.3.3               
 [37] zlibbioc_1.44.0             XVector_0.38.0              leiden_0.4.3                DelayedArray_0.24.0        
 [41] future.apply_1.11.0         BiocGenerics_0.44.0         abind_1.4-5                 scales_1.2.1               
 [45] DBI_1.1.3                   spatstat.random_3.1-5       miniUI_0.1.1.1              Rcpp_1.0.10                
 [49] viridisLite_0.4.2           xtable_1.8-4                reticulate_1.30             bit_4.0.5                  
 [53] dotCall64_1.0-2             stats4_4.2.3                htmlwidgets_1.6.2           httr_1.4.6                 
 [57] RColorBrewer_1.1-3          ellipsis_0.3.2              ica_1.0-3                   pkgconfig_2.0.3            
 [61] XML_3.99-0.14               uwot_0.1.16                 deldir_1.0-9                locfit_1.5-9.7             
 [65] utf8_1.2.3                  tidyselect_1.2.0            rlang_1.1.1                 reshape2_1.4.4             
 [69] later_1.3.1                 AnnotationDbi_1.60.2        munsell_0.5.0               tools_4.2.3                
 [73] cachem_1.0.8                cli_3.6.1                   generics_0.1.3              RSQLite_2.3.1              
 [77] ggridges_0.5.4              stringr_1.5.0               fastmap_1.1.1               goftest_1.2-3              
 [81] bit64_4.0.5                 fitdistrplus_1.1-11         purrr_1.0.1                 RANN_2.6.1                 
 [85] KEGGREST_1.38.0             pbapply_1.7-2               future_1.32.0               nlme_3.1-162               
 [89] mime_0.12                   hdf5r_1.3.8                 compiler_4.2.3              rstudioapi_0.14            
 [93] plotly_4.10.2               png_0.1-8                   spatstat.utils_3.0-3        tibble_3.2.1               
 [97] geneplotter_1.76.0          stringi_1.7.12              RSpectra_0.16-1             lattice_0.21-8             
[101] Matrix_1.5-4.1              vctrs_0.6.3                 pillar_1.9.0                lifecycle_1.0.3            
[105] spatstat.geom_3.2-1         lmtest_0.9-40               RcppAnnoy_0.0.20            data.table_1.14.8          
[109] cowplot_1.1.1               bitops_1.0-7                irlba_2.3.5.1               httpuv_1.6.11              
[113] GenomicRanges_1.50.2        R6_2.5.1                    promises_1.2.0.1            KernSmooth_2.23-21         
[117] gridExtra_2.3               IRanges_2.32.0              parallelly_1.36.0           codetools_0.2-19           
[121] fastDummies_1.6.3           MASS_7.3-60                 SummarizedExperiment_1.28.0 DESeq2_1.38.3              
[125] withr_2.5.0                 sctransform_0.3.5           S4Vectors_0.36.2            GenomeInfoDbData_1.2.9     
[129] parallel_4.2.3              grid_4.2.3                  tidyr_1.3.0                 MatrixGenerics_1.10.0      
[133] Rtsne_0.16                  spatstat.explore_3.2-1      Biobase_2.58.0              shiny_1.7.4 

@Polligator
Copy link

Hi! I have the same issue but the fixes mentioned above aren't working for me...

LN15_A1<-Load10X_Spatial(filedir,filename="filtered_feature_bc_matrix.h5", assay="Spatial",slice="LN15_A1",filter.matrix=TRUE)
Error in Load10X_Spatial(filedir, filename = "filtered_feature_bc_matrix.h5",  : 
  Image must be an object of class 'VisiumV1'.

I have changed the tissue_positions.csv file to tissue_positions_list.csv and it still gives the same error. If I try and upload the image separately, this is what happens:

> LN15_A1_image <- Read10X_Image(image.dir=paste0(filedir,"/spatial"),image.name="tissue_lowres_image.png",filter.matrix = TRUE)
> LN15_A1_image
Spatial data from the VisiumV1 technology for 960 samples
Associated assay:  
Image key:  
> LN15_A1<-Load10X_Spatial(filedir,filename="filtered_feature_bc_matrix.h5", assay="Spatial",slice="LN15_A1",filter.matrix=TRUE,image=LN15_A1_image)
Error in Read10X_h5(filename = file.path(data.dir, filename), ...) : 
  unused argument (image = new("VisiumV1", image = c(0.52156862745098, 0.52156862745098, 0.52156862745098, 0.52156862745098, 0.52156862745098, 0.52156862745098, 0.52156862745098, 0.52156862745098, 0.52156862745098, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.52156862745098, 0.52156862745098, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 
0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 

I checked the tissue_position_list.csv and it looks fine eg

barcode,in_tissue,array_row,array_col,pxl_row_in_fullres,pxl_col_in_fullres
ACGCCTGACACGCGCT-1,0,0,0,3583,28697
TACCGATCCAACACTT-1,0,1,1,3762,28392
ATTAAAGCGGACGAGC-1,0,0,2,3935,28700
GATAAGGGACGATTAG-1,0,1,3,4114,28396
GTGCAAATCACCAATA-1,0,0,4,4287,28703

Don't know what the issue is, anyone has any idea?

These are the directories my files are in:

> list.files(filedir)
[1] "filtered_feature_bc_matrix"    "filtered_feature_bc_matrix.h5" "spatial" 
> list.files(paste0(filedir,"/spatial"))
[1] "aligned_fiducials.jpg"     "detected_tissue_image.jpg" "scalefactors_json.json"    "spatial_enrichment.csv"    "tissue_hires_image.png"   
[6] "tissue_lowres_image.png"   "tissue_positions_list.csv"

And this is my sessionInfo()

> sessionInfo()
R version 4.2.3 (2023-03-15)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.3.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] dplyr_1.1.2             patchwork_1.1.2         ggplot2_3.4.2           Seurat_4.9.9.9050       SeuratObject_4.9.9.9086
[6] sp_2.0-0               

loaded via a namespace (and not attached):
  [1] spam_2.9-1                  plyr_1.8.8                  igraph_1.5.0                lazyeval_0.2.2             
  [5] splines_4.2.3               RcppHNSW_0.4.1              BiocParallel_1.32.6         listenv_0.9.0              
  [9] scattermore_1.2             GenomeInfoDb_1.34.9         digest_0.6.31               htmltools_0.5.5            
 [13] fansi_1.0.4                 magrittr_2.0.3              memoise_2.0.1               tensor_1.5                 
 [17] cluster_2.1.4               ROCR_1.0-11                 globals_0.16.2              Biostrings_2.66.0          
 [21] annotate_1.76.0             matrixStats_1.0.0           spatstat.sparse_3.0-2       colorspace_2.1-0           
 [25] blob_1.2.4                  ggrepel_0.9.3               crayon_1.5.2                RCurl_1.98-1.12            
 [29] jsonlite_1.8.7              progressr_0.13.0            spatstat.data_3.0-1         survival_3.5-5             
 [33] zoo_1.8-12                  glue_1.6.2                  polyclip_1.10-4             gtable_0.3.3               
 [37] zlibbioc_1.44.0             XVector_0.38.0              leiden_0.4.3                DelayedArray_0.24.0        
 [41] future.apply_1.11.0         BiocGenerics_0.44.0         abind_1.4-5                 scales_1.2.1               
 [45] DBI_1.1.3                   spatstat.random_3.1-5       miniUI_0.1.1.1              Rcpp_1.0.10                
 [49] viridisLite_0.4.2           xtable_1.8-4                reticulate_1.30             bit_4.0.5                  
 [53] dotCall64_1.0-2             stats4_4.2.3                htmlwidgets_1.6.2           httr_1.4.6                 
 [57] RColorBrewer_1.1-3          ellipsis_0.3.2              ica_1.0-3                   pkgconfig_2.0.3            
 [61] XML_3.99-0.14               uwot_0.1.16                 deldir_1.0-9                locfit_1.5-9.7             
 [65] utf8_1.2.3                  tidyselect_1.2.0            rlang_1.1.1                 reshape2_1.4.4             
 [69] later_1.3.1                 AnnotationDbi_1.60.2        munsell_0.5.0               tools_4.2.3                
 [73] cachem_1.0.8                cli_3.6.1                   generics_0.1.3              RSQLite_2.3.1              
 [77] ggridges_0.5.4              stringr_1.5.0               fastmap_1.1.1               goftest_1.2-3              
 [81] bit64_4.0.5                 fitdistrplus_1.1-11         purrr_1.0.1                 RANN_2.6.1                 
 [85] KEGGREST_1.38.0             pbapply_1.7-2               future_1.32.0               nlme_3.1-162               
 [89] mime_0.12                   hdf5r_1.3.8                 compiler_4.2.3              rstudioapi_0.14            
 [93] plotly_4.10.2               png_0.1-8                   spatstat.utils_3.0-3        tibble_3.2.1               
 [97] geneplotter_1.76.0          stringi_1.7.12              RSpectra_0.16-1             lattice_0.21-8             
[101] Matrix_1.5-4.1              vctrs_0.6.3                 pillar_1.9.0                lifecycle_1.0.3            
[105] spatstat.geom_3.2-1         lmtest_0.9-40               RcppAnnoy_0.0.20            data.table_1.14.8          
[109] cowplot_1.1.1               bitops_1.0-7                irlba_2.3.5.1               httpuv_1.6.11              
[113] GenomicRanges_1.50.2        R6_2.5.1                    promises_1.2.0.1            KernSmooth_2.23-21         
[117] gridExtra_2.3               IRanges_2.32.0              parallelly_1.36.0           codetools_0.2-19           
[121] fastDummies_1.6.3           MASS_7.3-60                 SummarizedExperiment_1.28.0 DESeq2_1.38.3              
[125] withr_2.5.0                 sctransform_0.3.5           S4Vectors_0.36.2            GenomeInfoDbData_1.2.9     
[129] parallel_4.2.3              grid_4.2.3                  tidyr_1.3.0                 MatrixGenerics_1.10.0      
[133] Rtsne_0.16                  spatstat.explore_3.2-1      Biobase_2.58.0              shiny_1.7.4 

I did not see how you applied the fix in your code.

@martina-morchio
Copy link

Hi! I have the same issue but the fixes mentioned above aren't working for me...

LN15_A1<-Load10X_Spatial(filedir,filename="filtered_feature_bc_matrix.h5", assay="Spatial",slice="LN15_A1",filter.matrix=TRUE)
Error in Load10X_Spatial(filedir, filename = "filtered_feature_bc_matrix.h5",  : 
  Image must be an object of class 'VisiumV1'.

I have changed the tissue_positions.csv file to tissue_positions_list.csv and it still gives the same error. If I try and upload the image separately, this is what happens:

> LN15_A1_image <- Read10X_Image(image.dir=paste0(filedir,"/spatial"),image.name="tissue_lowres_image.png",filter.matrix = TRUE)
> LN15_A1_image
Spatial data from the VisiumV1 technology for 960 samples
Associated assay:  
Image key:  
> LN15_A1<-Load10X_Spatial(filedir,filename="filtered_feature_bc_matrix.h5", assay="Spatial",slice="LN15_A1",filter.matrix=TRUE,image=LN15_A1_image)
Error in Read10X_h5(filename = file.path(data.dir, filename), ...) : 
  unused argument (image = new("VisiumV1", image = c(0.52156862745098, 0.52156862745098, 0.52156862745098, 0.52156862745098, 0.52156862745098, 0.52156862745098, 0.52156862745098, 0.52156862745098, 0.52156862745098, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.52156862745098, 0.52156862745098, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 
0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.525490196078431, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 0.537254901960784, 

I checked the tissue_position_list.csv and it looks fine eg

barcode,in_tissue,array_row,array_col,pxl_row_in_fullres,pxl_col_in_fullres
ACGCCTGACACGCGCT-1,0,0,0,3583,28697
TACCGATCCAACACTT-1,0,1,1,3762,28392
ATTAAAGCGGACGAGC-1,0,0,2,3935,28700
GATAAGGGACGATTAG-1,0,1,3,4114,28396
GTGCAAATCACCAATA-1,0,0,4,4287,28703

Don't know what the issue is, anyone has any idea?
These are the directories my files are in:

> list.files(filedir)
[1] "filtered_feature_bc_matrix"    "filtered_feature_bc_matrix.h5" "spatial" 
> list.files(paste0(filedir,"/spatial"))
[1] "aligned_fiducials.jpg"     "detected_tissue_image.jpg" "scalefactors_json.json"    "spatial_enrichment.csv"    "tissue_hires_image.png"   
[6] "tissue_lowres_image.png"   "tissue_positions_list.csv"

And this is my sessionInfo()

> sessionInfo()
R version 4.2.3 (2023-03-15)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.3.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] dplyr_1.1.2             patchwork_1.1.2         ggplot2_3.4.2           Seurat_4.9.9.9050       SeuratObject_4.9.9.9086
[6] sp_2.0-0               

loaded via a namespace (and not attached):
  [1] spam_2.9-1                  plyr_1.8.8                  igraph_1.5.0                lazyeval_0.2.2             
  [5] splines_4.2.3               RcppHNSW_0.4.1              BiocParallel_1.32.6         listenv_0.9.0              
  [9] scattermore_1.2             GenomeInfoDb_1.34.9         digest_0.6.31               htmltools_0.5.5            
 [13] fansi_1.0.4                 magrittr_2.0.3              memoise_2.0.1               tensor_1.5                 
 [17] cluster_2.1.4               ROCR_1.0-11                 globals_0.16.2              Biostrings_2.66.0          
 [21] annotate_1.76.0             matrixStats_1.0.0           spatstat.sparse_3.0-2       colorspace_2.1-0           
 [25] blob_1.2.4                  ggrepel_0.9.3               crayon_1.5.2                RCurl_1.98-1.12            
 [29] jsonlite_1.8.7              progressr_0.13.0            spatstat.data_3.0-1         survival_3.5-5             
 [33] zoo_1.8-12                  glue_1.6.2                  polyclip_1.10-4             gtable_0.3.3               
 [37] zlibbioc_1.44.0             XVector_0.38.0              leiden_0.4.3                DelayedArray_0.24.0        
 [41] future.apply_1.11.0         BiocGenerics_0.44.0         abind_1.4-5                 scales_1.2.1               
 [45] DBI_1.1.3                   spatstat.random_3.1-5       miniUI_0.1.1.1              Rcpp_1.0.10                
 [49] viridisLite_0.4.2           xtable_1.8-4                reticulate_1.30             bit_4.0.5                  
 [53] dotCall64_1.0-2             stats4_4.2.3                htmlwidgets_1.6.2           httr_1.4.6                 
 [57] RColorBrewer_1.1-3          ellipsis_0.3.2              ica_1.0-3                   pkgconfig_2.0.3            
 [61] XML_3.99-0.14               uwot_0.1.16                 deldir_1.0-9                locfit_1.5-9.7             
 [65] utf8_1.2.3                  tidyselect_1.2.0            rlang_1.1.1                 reshape2_1.4.4             
 [69] later_1.3.1                 AnnotationDbi_1.60.2        munsell_0.5.0               tools_4.2.3                
 [73] cachem_1.0.8                cli_3.6.1                   generics_0.1.3              RSQLite_2.3.1              
 [77] ggridges_0.5.4              stringr_1.5.0               fastmap_1.1.1               goftest_1.2-3              
 [81] bit64_4.0.5                 fitdistrplus_1.1-11         purrr_1.0.1                 RANN_2.6.1                 
 [85] KEGGREST_1.38.0             pbapply_1.7-2               future_1.32.0               nlme_3.1-162               
 [89] mime_0.12                   hdf5r_1.3.8                 compiler_4.2.3              rstudioapi_0.14            
 [93] plotly_4.10.2               png_0.1-8                   spatstat.utils_3.0-3        tibble_3.2.1               
 [97] geneplotter_1.76.0          stringi_1.7.12              RSpectra_0.16-1             lattice_0.21-8             
[101] Matrix_1.5-4.1              vctrs_0.6.3                 pillar_1.9.0                lifecycle_1.0.3            
[105] spatstat.geom_3.2-1         lmtest_0.9-40               RcppAnnoy_0.0.20            data.table_1.14.8          
[109] cowplot_1.1.1               bitops_1.0-7                irlba_2.3.5.1               httpuv_1.6.11              
[113] GenomicRanges_1.50.2        R6_2.5.1                    promises_1.2.0.1            KernSmooth_2.23-21         
[117] gridExtra_2.3               IRanges_2.32.0              parallelly_1.36.0           codetools_0.2-19           
[121] fastDummies_1.6.3           MASS_7.3-60                 SummarizedExperiment_1.28.0 DESeq2_1.38.3              
[125] withr_2.5.0                 sctransform_0.3.5           S4Vectors_0.36.2            GenomeInfoDbData_1.2.9     
[129] parallel_4.2.3              grid_4.2.3                  tidyr_1.3.0                 MatrixGenerics_1.10.0      
[133] Rtsne_0.16                  spatstat.explore_3.2-1      Biobase_2.58.0              shiny_1.7.4 

I did not see how you applied the fix in your code.

Sorry I meant changing the tissue_positions file name... I don't know how to change the original code so I didn't try doing that. If you can show me how to do it I will try it! I just don't know where I need to change the code, can I do it in my script?

@David-J-Byrne
Copy link

David-J-Byrne commented Aug 7, 2023

@martina-boop did you try something like this (see code below) sorry for the formatting

read spatial rnaSeq data with Gene symbol col features.tsv

matrixdir = paste0(filedir,"/filtered_feature_bc_matrix")
LN15_A1_data <- Read10X(matrixdir,
gene.column = 2, # 1= ENSEMBL, 2= GENE SYMBOL
cell.column = 1,
unique.features = TRUE,
strip.suffix = FALSE
)

create seurat object from data dgCMatrix

LN15_A1 <- CreateSeuratObject(counts = LN15_A1_data,
assay = "Spatial"
)

read Visium image file

imagedir = paste0(filedir,"/spatial")
image <- Read10X_Image(imagedir,
image.name = "tissue_lowres_image.png",
filter.matrix = TRUE
)
image <- image[Cells(x = LN15_A1)]

set default assay in image to spatial

DefaultAssay(object = image) <- "Spatial"

add Visium data to image slot

LN15_A1[[LN15_A1]] <- image

@jasonratcliff
Copy link

jasonratcliff commented Aug 8, 2023

Hi all,

This may be a duplicate of #7560, which I wrote about here. Unless there was an intentional design decision to remove the image argument from Load10X_Spatial(), I think there's a quick fix to return the argument. Otherwise, bear with the explanation as this might be an unusual bug with aspects of both git branching and R dot mechanics.

A Missing Argument

It appears the image argument of Load10X_Spatial() was removed in a large merge commit (2eb825c) to the seurat5 branch. That merge commit has two parent commits, 443ab86 and f0c4396, and it looks like image was removed upstream of the latter: R/preprocessing.R (f0c4396). Downstream of the 2eb825c merge commit, image is missing from the function definition in the R/preprocessing.R (f6ec68) source code. Current v.5 installation docs point to that seurat5 remote branch, where git reference ref specifies a non-default branch name:

# Install development version `4.9.9.9058` from the remote `seurat5` branch
remotes::install_github(repo = "satijalab/seurat", ref = "seurat5", quiet = TRUE)
packageVersion("Seurat")
#> [1] ‘4.9.9.9058’

Note the formal argument names of Load10X_Spatial() after installation, with images missing from the list:

names(formals(Load10X_Spatial))
#> [1] "data.dir"      "filename"      "assay"         "slice"        
#> [5] "filter.matrix" "to.upper"      "..."

Also note that the ... dots ellipsis is missing from the Read10X_h5() formal argument list:

names(formals(Read10X_h5))
#> [1] "filename"        "use.names"       "unique.features"

Error: unused argument

I think the unused argument error observed by @ejscience and @martina-boop is raised due to the dot forwarding behavior of Load10X_Spatial(), given that image = NULL is missing as a default argument on the seurat5 branch. Simply providing a temporary directory location and specifying image as the expected default of NULL raises an unused argument error in Read10X_h5():

Load10X_Spatial(data.dir = tempdir(), image = NULL)
#> Error in Read10X_h5(filename = file.path(data.dir, filename), ...): unused argument (image = NULL)

Going deeper, inside the function body of Load10X_Spatial() is a Read10X_h5() function call as follows:

  data <- Read10X_h5(filename = file.path(data.dir, filename), ...)

Above, in the scope of the Load10X_Spatial() function, Read10X_h5() is called with ... but the dots argument is missing in the Read10X_h5() function assignment as below. Instead, Read10X_h5() has a filenameargument shared with Load10X_Spatial() and two other arguments that have default values of TRUE:

Read10X_h5 <- function(filename, use.names = TRUE, unique.features = TRUE) {

Given image is no longer a default argument to Load10X_Spatial(), it is inadvertently dot forwarded to Read10X_h5() which lacks either a ... input argument or a defined image argument, and this in turn raises an unused argument error. I wasn't sure if that is expected dot behavior, but I worked up a minimal example in the details tag below that raises the same unused argument error. Feel free to click the example tag if you made it this far!

Dots Example

Define inner function to paste matched function arguments with expected default values:

# Paste elements 'x', 'y', and 'z' - the latter 2 with default values
g <- function(x, y = TRUE, z = TRUE) {
  m <- match.arg(
    arg = c("x", "y", "z"),
    choices = c("x", "y", "z"),
    several.ok = TRUE
  )
  n <- paste(m, c(x, y, z), sep = ": ")
  return(n)
}

Define outer wrapper function to call g() optionally with non-default y or z values:

# Nested call to `g()` with shared 'x' and additional arguments from '...'
f <- function(x, ...) {
  u <- g(x, ...)
  return(u)
}

Examples of various combinations of positional, default, and forwarded arguments:

f(1, 2, 3)            # Positional matches for all of x, y, z
#> [1] "x: 1" "y: 2" "z: 3"

f("x", z = "n")       # Required arg 'x' with non-default 'z'
#> [1] "x: x"    "y: TRUE" "z: n"

f(x = "x", i = NULL)  # Error raised by unused argument in `g()`
#> Error in g(x, ...): unused argument (i = NULL)

Workarounds

The branch history is complicated, but it looks like it may effect installations going back to v4.9.9.9050 based on provided session info. Until this issue is fixed, I temporarily reverted to the develop branch and was able to read in visium data using Load10X_Spatial():

remotes::install_github(repo = "satijalab/seurat",  ref = "develop")

Another option would be to install stable v4.3.0.1 from CRAN with install.packages("Seurat").

@martina-morchio
Copy link

Hi all, thank you for your replies! I've ended up using the develop branch and Load10X_Spatial works fine!

@dcollins15
Copy link
Contributor

Thanks for using Seurat!

It appears that this issue has gone stale. In an effort to keep our Issues board from getting more unruly than it already is, we’re going to begin closing out issues that haven’t had any activity since the release of v4.4.0.

If this issue is still relevant we strongly encourage you to reopen or repost it, especially if you didn’t initially receive a response from us.

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

7 participants