Cell Type Prediction

导出 h5ad,供下一篇 CellTypist 使用。

pacman::p_load(Seurat, tidyverse, qs2, SingleCellExperiment, zellkonverter)
knitr::opts_knit$set(root.dir = "/home/han/Desktop/guoqiang/stroke_bm/stroke_bm_Rproj")
setwd("/home/han/Desktop/guoqiang/stroke_bm/stroke_bm_Rproj")
source("codes/functions.R")
file_path <- "celltypist"
if (!dir.exists(file_path)) {
  dir.create(file_path, recursive = TRUE)
}
seurat_object <-
  qs_read(
    "data/rdata/dim_reduction/seurat_object_clustered.qs2",
    nthreads = 10
  )

DefaultAssay(seurat_object)
[1] "RNA"
Layers(seurat_object)
[1] "counts"     "data"       "scale.data"
# seurat_object <-
#   seurat_object |>
#   JoinLayers()
seurat_object[["RNA"]]$counts <-
  as(seurat_object[["RNA"]]$counts, Class = "dgCMatrix")
seurat_object[["RNA"]]$data <- NULL
seurat_object[["RNA"]]$scale.data <- NULL
seurat_object <- as.SingleCellExperiment(seurat_object, assay = c("RNA"))
writeH5AD(
  seurat_object,
  "celltypist/seurat_object.h5ad",
  X_name = "counts"
)
sessionInfo()
R version 4.4.3 (2025-02-28)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 24.04.3 LTS

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

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] 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   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Asia/Shanghai
tzcode source: system (glibc)

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

other attached packages:
 [1] zellkonverter_1.16.0        SingleCellExperiment_1.28.1
 [3] SummarizedExperiment_1.36.0 Biobase_2.66.0             
 [5] GenomicRanges_1.58.0        GenomeInfoDb_1.42.0        
 [7] IRanges_2.40.0              S4Vectors_0.44.0           
 [9] BiocGenerics_0.52.0         MatrixGenerics_1.18.0      
[11] matrixStats_1.4.1           qs2_0.1.7                  
[13] lubridate_1.9.3             forcats_1.0.0              
[15] stringr_1.5.1               dplyr_1.1.4                
[17] purrr_1.0.2                 readr_2.1.5                
[19] tidyr_1.3.1                 tibble_3.2.1               
[21] ggplot2_3.5.1               tidyverse_2.0.0            
[23] Seurat_5.2.1                SeuratObject_5.0.2         
[25] sp_2.1-4                   

loaded via a namespace (and not attached):
  [1] RColorBrewer_1.1-3      jsonlite_1.8.9          magrittr_2.0.3         
  [4] spatstat.utils_3.1-1    farver_2.1.2            rmarkdown_2.29         
  [7] zlibbioc_1.52.0         vctrs_0.6.5             ROCR_1.0-11            
 [10] spatstat.explore_3.3-3  S4Arrays_1.6.0          htmltools_0.5.8.1      
 [13] SparseArray_1.6.0       sctransform_0.4.1       parallelly_1.39.0      
 [16] KernSmooth_2.23-26      basilisk_1.18.0         htmlwidgets_1.6.4      
 [19] ica_1.0-3               plyr_1.8.9              plotly_4.10.4          
 [22] zoo_1.8-12              igraph_2.1.2            mime_0.12              
 [25] lifecycle_1.0.4         pkgconfig_2.0.3         Matrix_1.7-3           
 [28] R6_2.5.1                fastmap_1.2.0           GenomeInfoDbData_1.2.13
 [31] fitdistrplus_1.2-1      future_1.34.0           shiny_1.9.1            
 [34] digest_0.6.37           colorspace_2.1-1        patchwork_1.3.0        
 [37] tensor_1.5              RSpectra_0.16-2         irlba_2.3.5.1          
 [40] filelock_1.0.3          progressr_0.15.1        fansi_1.0.6            
 [43] spatstat.sparse_3.1-0   timechange_0.3.0        httr_1.4.7             
 [46] polyclip_1.10-7         abind_1.4-8             compiler_4.4.3         
 [49] withr_3.0.2             fastDummies_1.7.4       MASS_7.3-65            
 [52] DelayedArray_0.32.0     tools_4.4.3             lmtest_0.9-40          
 [55] httpuv_1.6.15           future.apply_1.11.3     goftest_1.2-3          
 [58] glue_1.8.0              nlme_3.1-166            promises_1.3.2         
 [61] grid_4.4.3              Rtsne_0.17              cluster_2.1.8.1        
 [64] reshape2_1.4.4          generics_0.1.3          gtable_0.3.6           
 [67] spatstat.data_3.1-4     tzdb_0.4.0              data.table_1.16.2      
 [70] hms_1.1.3               XVector_0.46.0          stringfish_0.18.0      
 [73] utf8_1.2.4              spatstat.geom_3.3-4     RcppAnnoy_0.0.22       
 [76] ggrepel_0.9.6           RANN_2.6.2              pillar_1.9.0           
 [79] spam_2.11-0             RcppHNSW_0.6.0          later_1.4.1            
 [82] splines_4.4.3           lattice_0.22-6          survival_3.8-3         
 [85] deldir_2.0-4            tidyselect_1.2.1        miniUI_0.1.1.1         
 [88] pbapply_1.7-2           knitr_1.49              gridExtra_2.3          
 [91] scattermore_1.2         xfun_0.49               UCSC.utils_1.2.0       
 [94] stringi_1.8.4           lazyeval_0.2.2          yaml_2.3.10            
 [97] pacman_0.5.1            evaluate_1.0.1          codetools_0.2-20       
[100] cli_3.6.3               uwot_0.2.2              RcppParallel_5.1.9     
[103] xtable_1.8-4            reticulate_1.42.0       munsell_0.5.1          
[106] Rcpp_1.0.13-1           dir.expiry_1.14.0       globals_0.16.3         
[109] spatstat.random_3.3-2   png_0.1-8               spatstat.univar_3.1-1  
[112] parallel_4.4.3          basilisk.utils_1.18.0   dotCall64_1.2          
[115] listenv_0.9.1           viridisLite_0.4.2       scales_1.3.0           
[118] ggridges_0.5.6          crayon_1.5.3            rlang_1.1.4            
[121] cowplot_1.1.3