Closed JoyOtten closed 4 years ago
I solved the issue. The issue is when you delete certain spots due to too low coverage these coordinates/spots are still residing in your image data. You need to filter these spots out over there as well.
It would be nice to have a function wherein you can filter and that is automatically adapting the coordinates/spots in your image data.
Hi,
I was wondering if there is a possibility to add filtering steps for the Spatial Transcriptomics dataset. I want to filter my data however, I have some errors and probably that's due to that the metadata or something else does not correspond anymore. Within the ?SeuratObject you have some filtering possibilities is this also a possibility to include something like that for Spatial Transcriptomics?
My code: count_data <- as.data.frame(total_raw@assays[["Spatial"]]@counts)
filtering
Each spot needs at least a gene count of 200
Each gene needs at least a gene count of 10 and detected in more than 2 spots otherwise discarded
dim(count_data) #31053 47062
there are 31052 genes and 47062 spots
keep <- apply(count_data,2,function(x){any(x >=200)}) count_data <- count_data[,keep] dim(count_data) #31053 46837 count_data[c(1:10), c(1:10)]
each gene count needs at least 10 reads
keep <- rowSums(count_data) keep1 <- keep >= 10 count_data <- count_data[keep1, ] dim(count_data) #19427 46837 count_data[c(1:10), c(1:10)] keep <- rowSums(count_data) >= 2 count_data <- count_data[keep,] dim(count_data) #19427 46837 count_data[c(1:10), c(1:10)]
count_data <- as.matrix(count_data) count_data[c(1:10), c(1:10)] count_data <- Matrix(count_data, sparse = TRUE) count_data[c(1:10), c(1:10)] total@assays[["Spatial"]]@counts <- count_data total@assays[["Spatial"]]@data <- count_data count_data <- as.data.frame(count_data) rownames(total_raw@assays[["Spatial"]]@meta.features) #gene names rownames(total@assays[["Spatial"]]@meta.features) <- total@assays[["Spatial"]]@meta.features$
rownames(count_data)
str(total@assays[["Spatial"]]@meta.features) test <- total@assays[["Spatial"]]@meta.features test <- test[,-c(1)] total@assays[["Spatial"]]@meta.features <- testx <- match(colnames(count_data) ,rownames(total@meta.data)) total@meta.data <- total@meta.data[x,]
run normalization to store sctransform residuals for all genes
total <- SCTransform(total, assay = "Spatial", return.only.var.genes = FALSE, verbose = FALSE) total <- GroupCorrelation(total, group.assay = "Spatial", assay = "SCT", slot = "scale.data", do.plot = FALSE) DefaultAssay(total) <- "SCT" total <- RunPCA(total, assay = "SCT", verbose = FALSE) total <- FindNeighbors(total, reduction = "pca", dims = 1:30) total <- FindClusters(total, verbose = FALSE) total <- RunUMAP(total, reduction = "pca", dims = 1:30) p1 <- DimPlot(total, reduction = "umap", label = TRUE) p3 <- SpatialDimPlot(total, label = TRUE, label.size = 3) Error in nn2(data = group.data[, 1:2], query = as.matrix(x = x[c(1, 2)]), : NA/NaN/Inf in foreign function call (arg 1)
If someone could help me out this would be really appreciated! Thank you, Joy