library(Seurat)
## Attaching SeuratObject
library(SpaTrio)
library(ggsci)
library(ggplot2)
library(readr)
Before using SpaTrio, we collected DBIT-seq data of mouse embryos (Sample: GSM4189614), and based on this, we built a set of single-cell multi-omics data and a set of spatial transcriptome data.
multi_object <- readRDS("data/Mouse_embryo/multi_object.rds")
spatial_object <- readRDS("data/Mouse_embryo/spatial_object.rds")
dim(multi_object)
## [1] 18787 1789
dim(spatial_object)
## [1] 18787 472
sdplot(multi_object,pt.size.factor=1.6,image.alpha = 0,stroke = NA,shape=22)+scale_fill_startrek()
## Scale for fill is already present.
## Adding another scale for fill, which will replace the existing scale.
sdplot(spatial_object,pt.size.factor=12,image.alpha = 0,stroke = NA,shape=22)+scale_fill_manual(values = pal_startrek()(7)[c(1,4,2,3,7,5,6)])
## Scale for fill is already present.
## Adding another scale for fill, which will replace the existing scale.
We enter the following data into SpaTrio, which will build spatial maps of single cells
- Gene expression count matrix of cells and spots (multi_rna.csv & spatial_rna.csv)
- Cluster/Cell-type information of cells and spots (multi_meta.csv & spatial_meta.csv)
- Low-dimensional representation of protein assay (emb.csv)
- Spatial position coordinates of spots (pos.csv)
spatrio(spatrio_path="/home/yph/SpaTrio-main",
py_path="/home/yph/anaconda3/envs/spatrio/bin/python",
input_path="data/Mouse_embryo",
output_path="data/Mouse_embryo",
top_num =4)
# We provide the number of cell types in each spot in ref_counts.csv. This dataframe can be converted to the number of cells in each spot.
# ref_counts <- read.csv(file = "path_to_ref/ref_counts.csv", header = TRUE, row.names = 1)
# expected_num <- data.frame(cell_num = rowSums(ref_counts), row.names = rownames(ref_counts))
# write.csv(expected_num,file = "path/expected_num.csv")
# spatrio(spatrio_path="/home/yph/SpaTrio-main",
# py_path="/home/yph/anaconda3/envs/spatrio/bin/python",
# input_path="data/Mouse_embryo",
# output_path="data/Mouse_embryo",
# expected_num_path = "path/expected_num.csv")
## [1] "Using the Python interpreter with a path of /home/yph/anaconda3/envs/spatrio/bin/python"
output <- read_csv("data/Mouse_embryo/output.csv")
## New names:
## Rows: 1789 Columns: 10
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (4): spot, cell, spot_type, cell_type dbl (6): ...1, value, x, y, Cell_xcoord,
## Cell_ycoord
## ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
## Specify the column types or set `show_col_types = FALSE` to quiet this message.
## • `` -> `...1`
pred<-subset(multi_object,cell=output$cell)
coordinate = output[,c("Cell_xcoord","Cell_ycoord")]
coordinate<-as.data.frame(coordinate)
colnames(coordinate)<-c("x","y")
rownames(coordinate)<-output$cell
pred@images[["slice1"]]=NULL
pred@images$image = new(
Class = 'SlideSeq',
assay = "RNA",
key = "image_",
coordinates = coordinate)
output<-as.data.frame(output)
rownames(output)<-output$cell
pred<-AddMetaData(pred, output[,2:10])
sdplot(pred,pt.size.factor=7,image.alpha = 0,stroke = NA,shape=22)+scale_fill_startrek()
## Scale for fill is already present.
## Adding another scale for fill, which will replace the existing scale.