This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Manually logging TPM count matrix in Seurat

Hello everyone,

I have some TPM data for single cell RNA sequencing but I am unsure of how to manually log transform the count matrix in the SeuratObject created. So far, this is what I have:

df <- read.table(file="...",nrows=2000, sep = "\t", row.names=1, header=T)

proj <- CreateSeuratObject(counts = df, project = "proj", min.cells = 3, min.features = 200) 

proj <- subset(proj, subset = nFeature_RNA > 200 & nFeature_RNA < 2500 )

GetAssayData(object = proj) = log(GetAssayData(object = proj)@x)

I am trying to log the tpm counts in the last step but I get an error so I am assuming that I am accessing the data incorrectly. Any help would be greatly appreciated!

seurat

2 answers

This will work.

proj[["RNA"]] <- CreateAssayObject(counts = log(proj[["RNA"]]@counts))

You might want to log+1 transform though, since there are going to be a ton of 0 values that will evaluate to -Infinity in R.

As a suggestion, if you can get a hold of the raw counts, you should use Seurat's SCTransform normalization, which is their preferred normalization scheme. Relevant paper, and the accompanying vignette.

Thank you for your reply, when I try this, I get this error:

Error in (function (cl, name, valueClass)  : 
  assignment of an object of class “dgeMatrix” is not valid for @‘counts’ in an object of class “Assay”; is(value, "AnyMatrix") is not TRUE

I edited the answer to fix the error. I confirmed it is now working.

Thank you, that worked! Is there any resource that can better help me understand how to access the different components of the Seurat object?

When they updated from version 2 to 3, they created a cheat sheet that is a nice overview of how to access different parts of the data.

Yes, I was referring to this: https://satijalab.org/seurat/essential_commands.html from which I gathered that I could access the count data by using GetAssayData(object = object) but I was wondering how I could have derived at CreateAssayObject(counts = ...) or if there is some other documentation I might have missed.

If you type help(package = Seurat) and scroll down a bit, it lists each function in the package with a short description of it. You can then open up the help documentation for any of those functions for more information.

Seurat has a built in log-transform function Seurat::LogNormalize() you can use on your count matrix. Use this prior to creating your Seurat object.

Thank you for your reply, will this function not normalize the matrix as well? My understanding was that since I had TPM data, I have to log transform it but skip the normalization step?

Log in to answer this question.