Question: Removing some character from Seurat metadata
0
gravatar for Za
7 months ago by
Za120
Za120 wrote:

Hi,

My Seurat metadata looks so

> head(immune.combined@meta.data)
      nGene    nUMI    orig.ident res.0.7 CELL STAGE GENO dataset stage.nice celltype var.ratio.pca res.0.6
_s1.1  4331  373762 SeuratProject       0 s1.1   H16   WT       1        H16        0     1.8560791       1
_s1.2  5603 1074639 SeuratProject       0 s1.2   H16   WT       1        H16        0     1.1616687       0
_s1.3  2064   49544 SeuratProject       0 s1.3   H16   WT       1        H16        0     1.1566137       1
_s1.4  4680  772399 SeuratProject       1 s1.4   H16   WT       1        H16        1     0.5947263       0
_s1.5  3876  272356 SeuratProject       1 s1.5   H16   WT       1        H16        1     1.4148602       0
_s1.6  2557  122314 SeuratProject       0 s1.6   H16   WT       1        H16        0     1.2174034       1
>

I tried to feed my Seurat to CellRouter R package but CellRouter return

Error in rep(colors, times = replicate_row) : invalid 'times' argument

I think because of _ in row names of my metadata

I tried to edit my metadata manually but after adding edited version to Seurat that looks so :(

> cc <- AddMetaData(object = immune.combined, metadata = rrrrr) 
> cc <- SetAllIdent(object = cc, id = "rownames(rrrrr")
> head(cc@meta.data)
      nGene nUMI orig.ident res.0.7 CELL STAGE GENO dataset stage.nice celltype var.ratio.pca res.0.6
_s1.1    NA   NA       <NA>      NA <NA>  <NA> <NA>      NA       <NA>       NA            NA      NA
_s1.2    NA   NA       <NA>      NA <NA>  <NA> <NA>      NA       <NA>       NA            NA      NA
_s1.3    NA   NA       <NA>      NA <NA>  <NA> <NA>      NA       <NA>       NA            NA      NA
_s1.4    NA   NA       <NA>      NA <NA>  <NA> <NA>      NA       <NA>       NA            NA      NA
_s1.5    NA   NA       <NA>      NA <NA>  <NA> <NA>      NA       <NA>       NA            NA      NA
_s1.6    NA   NA       <NA>      NA <NA>  <NA> <NA>      NA       <NA>       NA            NA      NA

Who knows how I can edit metadata in seurat?

ADD COMMENTlink modified 7 months ago by Santosh Anand4.7k • written 7 months ago by Za120
1
gravatar for Santosh Anand
7 months ago by
Santosh Anand4.7k
Santosh Anand4.7k wrote:
## first, let's get the meta data
md = cc@meta.data

## change its rownames according to your wish
rownames(md) = gsub("^_", "", rownames(md)) 

## check that md has the desired format of rownames
head(md)

## insert it back
cc@meta.data = md

WARNING: The metadata slot gets its rownames from the original data (these are cell identifiers). If you only change it here, the Seurat object is no longer consistent. It is better to change this in the input data itself if you will use Seurat object later.

ADD COMMENTlink modified 7 months ago • written 7 months ago by Santosh Anand4.7k

I did as you kindly suggested as below

> md = immune.combined@meta.data
> 
> rownames(md) = gsub("^_", "", rownames(md)) 
> head(md)
     nGene    nUMI    orig.ident res.0.7 CELL STAGE GENO dataset stage.nice celltype var.ratio.pca res.0.6
s1.1  4331  373762 SeuratProject       0 s1.1   H16   WT       1        H16        0     1.0109592       2
s1.2  5603 1074639 SeuratProject       0 s1.2   H16   WT       1        H16        0     0.9927172       2
s1.3  2064   49544 SeuratProject       0 s1.3   H16   WT       1        H16        0     1.1282714       0
s1.4  4680  772399 SeuratProject       1 s1.4   H16   WT       1        H16        1     1.2222062       1
s1.5  3876  272356 SeuratProject       1 s1.5   H16   WT       1        H16        1     2.3811263       1
s1.6  2557  122314 SeuratProject       0 s1.6   H16   WT       1        H16        0     0.7024815       2
> 
> immune.combined@meta.data=md
> 
> head(immune.combined@meta.data)
     nGene    nUMI    orig.ident res.0.7 CELL STAGE GENO dataset stage.nice celltype var.ratio.pca res.0.6
s1.1  4331  373762 SeuratProject       0 s1.1   H16   WT       1        H16        0     1.0109592       2
s1.2  5603 1074639 SeuratProject       0 s1.2   H16   WT       1        H16        0     0.9927172       2
s1.3  2064   49544 SeuratProject       0 s1.3   H16   WT       1        H16        0     1.1282714       0
s1.4  4680  772399 SeuratProject       1 s1.4   H16   WT       1        H16        1     1.2222062       1
s1.5  3876  272356 SeuratProject       1 s1.5   H16   WT       1        H16        1     2.3811263       1
s1.6  2557  122314 SeuratProject       0 s1.6   H16   WT       1        H16        0     0.7024815       2
> 
> metadata <- immune.combined@meta.data
> head(data[,1:4])
             _s1.1 _s1.2 _s1.3 _s1.4
DDB_G0267178     0     1     0     1
DDB_G0267180     0     0     0     0
DDB_G0267182     0     0     0     3
DDB_G0267184     0     0     0     0
DDB_G0267188     1     0     0     1
DDB_G0267202     0     0     0     0
> colnames(data) = gsub("^_", "", colnames(data)) 
> head(data[,1:4])
             s1.1 s1.2 s1.3 s1.4
DDB_G0267178    0    1    0    1
DDB_G0267180    0    0    0    0
DDB_G0267182    0    0    0    3
DDB_G0267184    0    0    0    0
DDB_G0267188    1    0    0    1
DDB_G0267202    0    0    0    0
> library('cccd')
> library('proxy')
> cellrouter <- CellRouter(rawdata=as.data.frame(data), min.cells=3,min.genes=0)
[1] "Initializing CellRouter object"
> cellrouter <- addInfo(cellrouter, metadata=metadata, colname = 'res.0.6', metadata.column = 'res.0.6')
Error in rep(colors, times = replicate_row) : invalid 'times' argument
> head(metadata)
     nGene    nUMI    orig.ident res.0.7 CELL STAGE GENO dataset stage.nice celltype var.ratio.pca res.0.6
s1.1  4331  373762 SeuratProject       0 s1.1   H16   WT       1        H16        0     1.0109592       2
s1.2  5603 1074639 SeuratProject       0 s1.2   H16   WT       1        H16        0     0.9927172       2
s1.3  2064   49544 SeuratProject       0 s1.3   H16   WT       1        H16        0     1.1282714       0
s1.4  4680  772399 SeuratProject       1 s1.4   H16   WT       1        H16        1     1.2222062       1
s1.5  3876  272356 SeuratProject       1 s1.5   H16   WT       1        H16        1     2.3811263       1
s1.6  2557  122314 SeuratProject       0 s1.6   H16   WT       1        H16        0     0.7024815       2
>

But as you are considering CellRouter returns the same error

> cellrouter <- CellRouter(rawdata=as.data.frame(data), min.cells=3,min.genes=0)
[1] "Initializing CellRouter object"
> cellrouter <- addInfo(cellrouter, metadata=metadata, colname = 'res.0.6', metadata.column = 'res.0.6')
Error in rep(colors, times = replicate_row) : invalid 'times' argument
ADD REPLYlink written 7 months ago by Za120
1

I don't use Cellrouter, but can confidently say that this is not an issue due to row.names. The code from https://github.com/edroaldo/cellrouter/blob/master/CellRouter_Class.R

  replicate_row <- as.vector(unlist(lapply(split(sampTab, sampTab[[colname]]), nrow)))
  colors_row <- rep(colors, times=replicate_row)

The replicate_row is coming from sampTab and probably you need to explicitly pass a sampleTable somewhere.

ADD REPLYlink written 7 months ago by Santosh Anand4.7k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1644 users visited in the last hour