Seurat: CreateSeuratObject error, please help
1
0
Entering edit mode
7 weeks ago
mnx0723 • 0

I want to make Seurat Object because I need gene expression matrix. My data form is cell.tsv, feature.tsv and .mtx

This is my code and error.

barcodes <- read.table("4861STDY7387182_cells.tsv", header = TRUE, sep = "\t")[,1]
feature <- read.table("4861STDY7387182_features.tsv",header = FALSE)
matrix <- Matrix::readMM("4861STDY7387182.mtx")

seurat_obj <- CreateSeuratObject(counts = matrix, meta.data = data.frame(Barcode = barcodes), features = feature)
Error: Not enough features for the counts matrices provided

And this is my data structure

> head(barcodes)
[1] "4861STDY7387182_AAACCTGAGCCAGTAG" "4861STDY7387182_AAACCTGAGCGATAGC" "4861STDY7387182_AAACCTGAGGGTGTTG" "4861STDY7387182_AAACCTGCACACTGCG" "4861STDY7387182_AAACCTGCAGGTCCAC" "4861STDY7387182_AAACCTGCATACAGCT"

> head(feature)
        V1
1 RP11-34P13.3
2      FAM138A
3 RP11-34P13.7
4 RP11-34P13.8
5 RP11-34P13.9
6   FO538757.2

> str(feature)
'data.frame':   28614 obs. of  1 variable:
 $ V1: chr  "RP11-34P13.3" "FAM138A" "RP11-34P13.7" "RP11-34P13.8" ...
> str(matrix)
Formal class 'dgTMatrix' [package "Matrix"] with 6 slots
..@ i       : int [1:18607530] 22 27 28 33 40 41 49 55 56 72 ...
..@ j       : int [1:18607530] 0 0 0 0 0 0 0 0 0 0 ...
..@ Dim     : int [1:2] 28614 6356
..@ Dimnames:List of 2
.. ..$ : NULL
.. ..$ : NULL
..@ x       : num [1:18607530] 1 1 3 1 5 1 1 1 1 1 ...
..@ factors : list()

I think each data have same row, how can I solve this matter? I tried it for a few days.

Seruat • 284 views
ADD COMMENT
1
Entering edit mode
6 weeks ago
bk11 ★ 2.4k

A quick and dirty way to create a Seurat object from this data will be as follows:-

In a directory do the followings-

awk '{print $1}' 4861STDY7387182_cells.tsv |sed '1d' >barcodes.tsv
cp 4861STDY7387182_features.tsv features.tsv
cp 4861STDY7387182.mtx matrix.mtx

#gzip the files
gzip barcodes.tsv
gzip features.tsv
gzip matrix.mtx

Now in R do the following-

library(Seurat)
data_dir <- "/path_to_above_gzip_files/"
data <- Read10X(data.dir = data_dir, gene.column = 1)
seurat_obj <- CreateSeuratObject(counts = data)

# Add metadata to Seurat object
barcodes <- read.table("4861STDY7387182_cells.tsv", header = TRUE, sep = "\t")
seurat_obj <- AddMetaData(object = seurat_obj, metadata = barcodes)
head(seurat_obj@meta.data)
                                      orig.ident nCount_RNA nFeature_RNA DonorID log2p1_count n_genes percent_mito  BiopsyType
4861STDY7387182_AAACCTGAGCCAGTAG 4861STDY7387182       6364         2046     A13     12.63594    2046   0.03048397 Organ_Donor
4861STDY7387182_AAACCTGAGCGATAGC 4861STDY7387182      15358         3644     A13     13.90680    3644   0.04688111 Organ_Donor
4861STDY7387182_AAACCTGAGGGTGTTG 4861STDY7387182       7457         2367     A13     12.86457    2367   0.07241518 Organ_Donor
4861STDY7387182_AAACCTGCACACTGCG 4861STDY7387182      11614         3293     A13     13.50370    3293   0.04640951 Organ_Donor
4861STDY7387182_AAACCTGCAGGTCCAC 4861STDY7387182      14388         4034     A13     13.81268    4034   0.03697526 Organ_Donor
4861STDY7387182_AAACCTGCATACAGCT 4861STDY7387182       5634         1748     A13     12.46020    1748   0.03461129 Organ_Donor
                                             Location  Binary.Stage phase broad_celltypes general_celltypes fine_celltypes
4861STDY7387182_AAACCTGAGCCAGTAG endometrium_enriched Proliferative    G1         Stromal                eS             eS
4861STDY7387182_AAACCTGAGCGATAGC endometrium_enriched Proliferative    G1         Stromal                eS             eS
4861STDY7387182_AAACCTGAGGGTGTTG endometrium_enriched Proliferative    G1          Immune          Lymphoid       Lymphoid
4861STDY7387182_AAACCTGCACACTGCG endometrium_enriched Proliferative    G1         Stromal                eS             eS
4861STDY7387182_AAACCTGCAGGTCCAC endometrium_enriched Proliferative   G2M         Stromal                eS             eS
4861STDY7387182_AAACCTGCATACAGCT endometrium_enriched Proliferative    G1         Stromal                eS             eS
ADD COMMENT
0
Entering edit mode

Oh, Thank you!! It helps me

ADD REPLY

Login before adding your answer.

Traffic: 2745 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