seurat
seurat copied to clipboard
TransferData() function gives error
Hi!
I was wondering if you could please advise on how to rectify the error below? Many thanks!
library(Seurat)
library(SeuratData)
InstallData("panc8")
data("panc8")
pancreas.list <- SplitObject(panc8, split.by = "tech")
pancreas.list <- pancreas.list[c("celseq", "celseq2", "fluidigmc1", "smartseq2")]
for (i in 1:length(pancreas.list)) {
pancreas.list[[i]] <- NormalizeData(pancreas.list[[i]], verbose = FALSE)
pancreas.list[[i]] <- FindVariableFeatures(pancreas.list[[i]], selection.method = "vst", nfeatures = 2000,
verbose = FALSE)
}
reference.list <- pancreas.list[c("celseq", "celseq2", "smartseq2")]
pancreas.anchors <- FindIntegrationAnchors(object.list = reference.list, dims = 1:30)
pancreas.integrated <- IntegrateData(anchorset = pancreas.anchors, dims = 1:30)
library(ggplot2)
library(cowplot)
library(patchwork)
# switch to integrated assay. The variable features of this assay are automatically set during
# IntegrateData
DefaultAssay(pancreas.integrated) <- "integrated"
# Run the standard workflow for visualization and clustering
pancreas.integrated <- ScaleData(pancreas.integrated, verbose = FALSE)
pancreas.integrated <- RunPCA(pancreas.integrated, npcs = 30, verbose = FALSE)
pancreas.integrated <- RunUMAP(pancreas.integrated, reduction = "pca", dims = 1:30, verbose = FALSE)
p1 <- DimPlot(pancreas.integrated, reduction = "umap", group.by = "tech")
p2 <- DimPlot(pancreas.integrated, reduction = "umap", group.by = "celltype", label = TRUE, repel = TRUE) +
NoLegend()
p1 + p2
#Query dataset
expression_matrix <- ReadMtx(
mtx = paste0("Z:/H5, TSV and MTX files/E15.5 ctrl filtered", "/matrix.mtx"),
features = paste0("Z:/H5, TSV and MTX files/E15.5 ctrl filtered", "/features.tsv"),
cells = paste0("Z:/H5, TSV and MTX files/E15.5 ctrl filtered", "/barcodes.tsv")
)
pancreas.query <- CreateSeuratObject(counts = expression_matrix)
pancreas.query <- NormalizeData(pancreas.query)
pancreas.query <- FindVariableFeatures(pancreas.query, selection.method = "vst", nfeatures = 2000)
pancreas.query <- ScaleData(pancreas.query, verbose = FALSE)
pancreas.query <- RunPCA(pancreas.query, npcs = 30, verbose = FALSE)
pancreas.query <- RunUMAP(pancreas.query, reduction = "pca", dims = 1:30, verbose = FALSE)
p1 <- DimPlot(pancreas.query, reduction = "umap", group.by = "tech")
p2 <- DimPlot(pancreas.query, reduction = "umap", group.by = "celltype", label = TRUE, repel = TRUE) +
NoLegend()
p1 + p2
pancreas.anchors <- FindTransferAnchors(reference = pancreas.integrated, query = pancreas.query,
dims = 1:30, reference.reduction = "pca")
predictions <- TransferData(anchorset = pancreas.anchors, refdata = pancreas.integrated$celltype,
dims = 1:30)
When I run the above line the following message appears:
Warning: Please provide a vector that is the same length as the number of reference cells used in anchor finding.
Length of vector provided: 5683
Length of vector required: 0
Skipping element 1.
Error: None of the provided refdata elements are valid.
Hello,
Are you able to run these functions using the data in the vignette? If so, there is something likely going on when you are finding anchors between your query and the integrated reference. How many anchors do you get in the pancreas.anchors
object, after running FindTransferAnchors
?
Since we haven’t heard from you, we will close this issue first. If you still have this issue, we can reopen it.