RDS file in Rstudio
0
0
Entering edit mode
14 months ago
windsur ▴ 20

Hello, I have downloaded the RDS file here, the "MNP-VERSE".

I am trying to extract all the cells and their value for a specific tissue in a specific gene (e.g. breast tissue and MSR1 gene). So far I get this:

library(tidyverse) 
filename <- file.choose() 
msr1 <-read_rds(filename) 
view(subset(msr1,Tissue == 'Breast'))

I do not have experience with this kind of file, I suppose it is something like this:

view(head(Canteen_clean@assays$integrated@data@Dimnames))

But I do not know how to get it.

Any help is more than welcome! thanks

data R RDS • 1.4k views
ADD COMMENT
0
Entering edit mode

So what exactly is your question? What have you tried? Are you getting an error?

We need more information.

ADD REPLY
0
Entering edit mode

What I want is to get a table with the correlation of cells for a specific gene. I know how to extract the metadata for a tissue (the first view()), but I need to do a selection for a gene, in that case for MSR1

ADD REPLY
0
Entering edit mode

First thing that you need to check is the class of the object that you imported to R. You can do this by running the command:

class(msr1)

This will tell which class the R object msr1 is. Then depending on the class, i.e., matrix, data.frame, tbl, etc, the expression that you need to use to get what you want will vary.

I suspect the msr1 is an object of class Seurat. If so, you can look into the following Seurat vignettes to see how to get what you want: https://satijalab.org/seurat/articles/interaction_vignette.html

Please check the vignettes menu tab in the previous link to look into more vignettes that can help to explore this object.

I hope this helps,

António

ADD REPLY
0
Entering edit mode

Exactly, it is Seurat class object. Thanks for the vignettes. The thing is if I want to use the data attached in the link, I do not know how to filter the gene first and then selecting the correlation with cells

ADD REPLY
3
Entering edit mode

Well there are a couple of things that you need to know first (I'm not sure if you're familiar with them or not).

Currently I can't try to check this object due to its size. Thus everything that I'll say next are just assumptions/speculations based on other Seurat objects that I worked with (which not necessarily hold true for every object).

In principle, in this object you've 2 assays (read more in their wiki): RNA and integrated (you can check this by doing Assays(msr1)).

They will hold slightly different information. Please check the wiki link above to get familiar with the structure of the Seurat object.

Each of these assays may have more than one slot of data. In principle the assay RNA should have the slots: counts (UMI counts), data (normalized data) and scaled.data (scaled data).

In the case of the integrated assay, I think you should have at least the slot data which I think it represents batch-corrected data (please check this out).

Quite often, it is recommended feature selection before performing integration, meaning that the integrated assay may have only a set of genes that are highly variable (quite often 2k), but not all. I don't know if this is the case. This does not seem to be the case based on the Fig.1A from the respective paper (link to the paper).

Thus depending which type of assay and slot that you're interested in, you can use the function GetAssayData(object, slot = "data", assay = NULL, ...) to pick the gene expression data that you want.

Let's say that I want the normalized data from the RNA assay:

norm <- GetAssayData(object = msr1, slot = "data", assay = "RNA") # this gives you a sparse matrix - run the next line to convert it to a matrix
norm <- as.matrix(norm) 

Since you're interested in particular genes, now you can provide that list:

genes <- "CD8A"
head(norm[ genes, ]) # give me just the values for the first 6 cells with the function head() - otherwise prints all the values

You mentioned that you were interested in specific cell subsets. To select cells you can use the same logic as above:

cells <- c("ATGCATGCGAT", "ACGCATGCAT") # I just invented two "cell barcodes" to represent two cells
norm[ genes, cells ] # this will return a matrix in case you provide more than one gene above and more than one cell here

I guess that the @meta.data slot contains the cell metadata where you can check the cells that you might be eventually interested in.

head(msr1@meta.data) # see the first 6 lines of cell metadata
cells <- row.names(msr1@meta.data[ msr1$Tissue == 'Breast', ]) # this assumes that you have a 'Tissue' column in the cell metadata slot and the `Breast` level in that variable

I hope this helps,

António

ADD REPLY
0
Entering edit mode

Thank you so much for your advice and support. I have follow up your steps to understood how it works the Seurat objects. I wrote:

MNP <- read_rds(filename)
dataMSR1 <- subset(MNP, features = c("MSR1","LAG3","HAVCR2","CD274","TNFRSF9","TIGIT","CTLA4","PDCD1","CD40","TNFRSF4"))
PancreasData <- subset(dataMSR1, Tissue == 'Pancreas')
norm <- GetAssayData(object = PancreasData, slot = "data", assay = "RNA")
norm <- as.matrix(norm) 

Indeed, in the metadata shows all the barcodes with its cell. Is there a way you can "change" the cell barcode of the matrix automatically?

ADD REPLY
1
Entering edit mode

You're welcome.

I think you are looking for the function (see function doc).

RenameCells()

This is to rename cell barcodes in the Seurat object, but if you do it before getting the matrix, you'll get a matrix with barcodes renamed.

Otherwise you can use the function colnames to (re)name columns in a matrix, which in this case corresponds to cell barcodes (just be careful because once you do it they will no more correspond to the original barcodes used in the object).

colnames(norm) <- paste0("cell_", 1:ncol(norm)) # this will rename cells as 'cell_1', 'cell_2'....'cell_n', where n is n cols

You can give any character vector above to rename the columns.

I hope this helps,

António

ADD REPLY

Login before adding your answer.

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