Closed changostraw closed 3 years ago
So I changed all the factors in the broad metadata to characters and recreated the object and all the metadata cells became NA. I also tried renaming all the factors and copying to another column as characters and the same thing occurs. The same thing happens when I use as.character within a command. Does anyone have any suggestions of what I might be doing wrong?
Update for anyone else having this issue with metadata characters becoming NAs when creating a Seurat object and preventing any kind of Seurat object manipulation.
I found that this issue could be re-created in two ways.
When the metadata file has more rows than the matrix. In this case the metadata was for multiple matrix files and needed to be subset. You can't create a seurat object and then subset. You have to subset the metadata file first.
When the rownames in the metadata file are not set. You need to set the rownames before creating the Seurat object: rownames(metadata) <- metadata$V1. It doesn't matter how the metadata file is imported or with what class as long as you set the rownames you can then use as.character to switch from a factor to a character without creating NAs in your object.
Thanks for following up. Yes, the metadata needs to have the cell names as the rownames in order to know which cell to associate with what piece of metadata.
Hello, I am new to Seurat. I am trying to split a class 4 seurat object created from a publicly available 10X cellranger 2 processed dataset that was downloaded from the broad single cell portal:
https://singlecell.broadinstitute.org/single_cell/study/SCP1038/the-human-and-mouse-enteric-nervous-system-at-single-cell-resolution: gene_sorted-hli.matrix.mtx, hli.barcodes.tsv, hli.genes.tsv, all.meta.txt.
I need to split the object by the column in the all.meta file named "Dataset".
I get this error: Error in CellsByIdentities(object = object, cells = cells) : Cannot find cells provided
I tried this with the pancreas data from Seurat (https://www.dropbox.com/s/1zxbn92y5du9pu0/pancreas_v3_files.tar.gz?dl=1), splitting it by "tech" and "celltype" and it worked fine.
The only difference I can find between my object and the pancreas object is that in my object the Dataset columns are listed as factors and in the pancreas object the metadata columns are listed as characters. However, I am not sure how to change this in my object. Is this the issue? I tried to use the as.character function to see if this would make a difference, but it didn't.
I am using R 4.0.3 Bunny-Wunnies Freak Out and Seurat 4.0.0
Thanks!