How to add labels to a Seurat object, matching the barcodes?
1
0
Entering edit mode
5 weeks ago

Hi, I'm trying to add a file that contains barcode-label pairs to a Seurat object I have. The file looks like this:

Cells   0
ATGATCGTCTACCACC    Cluster 6
GAAGCCCAGTTACTCG    Cluster 2
CAAGCTACACGGTGTC    Cluster 7
CACAACACACAGTATC    M8
CATCCACGTTCGGTTA    Cluster 2
ATGCATGGTGTGGTCC    Cluster 3
ACCCTTGTCTCGGGAC    Cluster 6

The issue is that the barcodes in this new file do not match the barcodes or the matrix file I originally used to create the Seurat object. It contains fewer rows due to different filtering standards. Is there a way to merge these two files and removing rows that do not appear in the labels file?

Thank you!

R seurat • 237 views
ADD COMMENT
1
Entering edit mode
5 weeks ago
Zhilong Jia ★ 1.8k

Filtering and joining your label file (e.g. naming metasample after reading to R) based on the barcodes that existed in the seurat object (e.g. seu_obj@meta.data).

# the only common colname in the 2 objects should be the barcode column (Cells).
meta_data <- dplyr::left_join(seu_obj@meta.data, metasample, by=Cells)
# check meta_data if correct.
seu_obj@meta.data <- meta_data
ADD COMMENT

Login before adding your answer.

Traffic: 2136 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6