How to read a dataframe into Seurat for AddMetaData properly?
2
1
Entering edit mode
3.6 years ago
Pratik ★ 1.0k

Before I report this as a bug can someone show me the proper way to add metadata using the AddMetaData function.

I first read a file that is new line delimited with the meta data labels I want using read table. The ftimecell_columns.txt file looks like this:

"12wks"
"12wks"
"12wks"
"12wks"
"12wks"
...

So I do this command to make the dataframe:

timecell_col <- read.table("~/Projects/FetalPancreas/timecell_columns.txt", header=FALSE, sep="\n")

and then this to AddMetaData:

AddMetaData(object = scfp, metadata = timecell_col, col.name = 'time.cell')

However, when I do:

head(x = scfp@meta.data)

All I see is the original meta data values:

           orig.ident nCount_RNA nFeature_RNA
GSM2978830   scfetpan     382565         5080
GSM2978831   scfetpan     634726         4932
GSM2978832   scfetpan     565912         4501
GSM2978833   scfetpan     717152         5117
GSM2978834   scfetpan     207659         3508
GSM2978835   scfetpan     869148         5055

Am I reading the data in correctly?

Any help would be appreciated!

Very Respectfully, Pratik

seurat rna-seq RNA-Seq R • 12k views
ADD COMMENT
6
Entering edit mode
2.9 years ago
Pratik ★ 1.0k

So figured it out. Months later, but nonetheless got it.

For reference: My column names were the GSM sample names because I downloaded the data from GEO, where each GSM####### corresponds to a cell (see image below:

enter image description here

Your gene expression matrix/data frame should be cells as column names, and genes as row names.

It may be obvious to some, but it was not obvious to me then. In order to add meta data. Your meta data, data frame should have your row names as cells and the corresponding meta data information should be the row values, so it should look something like this, and lastly your column names should be what you want that meta data to be named see below:

enter image description here

If your meta data, data frame is arranged in the way. You could simply do a modification of the default Seurat command like this by adding the meta.data = yourmetadata like so:

scfp <- CreateSeuratObject(counts = df, project = 'scfp', meta.data = SCFPmetadata, min.cells = 3, min.features = 200)

or the following after your make your Seurat object:

scfp <- AddMetaData(object = scfp, metadata = SCFPmetadata)

Hope this helps!

ADD COMMENT
2
Entering edit mode
3.6 years ago

Is that your exact command line?

Not

scfp <- AddMetaData(object = scfp, metadata = timecell_col, col.name = 'time.cell')
ADD COMMENT
0
Entering edit mode

That worked with scfp <- AddMetaData, Gosh, silly mistake... but now problem is the MetaData displays as NA NA NA NA NA... I think it could be a problem with how my dataframe is formatted, and the way Seurat wants it. swbarnes2, if you don't mind me asking when you're loading a data frame what does it look like? Do you have the data frame you're reading as column 1, and all the metadata as rows like I showed above with:

"12wks"
"12wks"
"12wks"
"12wks"
"12wks"
...

Or do you have them as the actual column names? What is the data frame format supposed to be? When I use the cbind as you remember from this post C: How to embed known cell information into Seurat object? AddMetaData? the data frame is fine and the meta data loads into it perfectly, but I'm assuming Seurat wants the dataframe a certain way?

Any help would be appreciated!

Very Respectfully, Pratik

ADD REPLY
0
Entering edit mode

So your metadata is by project, and not cell barcode? I don't understand what you are doing at all.

ADD REPLY
0
Entering edit mode

Instead of cell barcode, the cells are labeled by the unique cell sample name, that's all.

I was wondering what format a data frame should be in, in order to use it to add meta data using the AddMetaData function.

ADD REPLY

Login before adding your answer.

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