Entering edit mode
4.2 years ago
roberts
▴
60
Hello, I have successfully add my VDJ data to my GEX data by adding it as meta data. I would now like to distinguish between CD8 and CD4 TCR. I know by using WhichCell, I can pull out cells that express CD8 (T8 <- WhichCells(object, expression= CD8A >1)). I would then like to take that T8 data and make a .csv file with the clonotypes, aa sequence, nt sequence, etc. How would I go about doing that. Would I have to add it as metadata again? If so how would I go about that? Thank you!
Thank you for your help it is greatly appreciated. I still have some questions though. It seems that the command T8 <- WhichCells(object, expression= CD8A >1) only saves barcodes. Is there a way to also get it to save TCR data (mostly clonotypes, aa sequence, and nt sequence). Also what is the function T8[[]] doing? Thank you again for your help!
T8 <- subset(object, subset = CD8A > 1)
will subset your Seurat object as you want.T8[[]]
just returns the metadata as a dataframe.Thank you! I ran your code and the error messages went away. The only thing is that in the new CSV file under clonotype_id it says none for every barcode. Also is there a way to add in the aa sequence and nt sequence that I got from the cellranger output from the VDJ library prep. Thank you for taking your time to help me greatly appreciated!
It sounds like you haven't actually added the clonotype data to your metadata then.
If you have already added it to your metadata, you can run the commands in my original answer to save the full metadata dataframe. It will have everything you added to metadata. Or you can select multiple columns in your
T8[[]]
call, e.g.T8.meta <- [[c("clonotype_id", "clonotype_aa", "clonotype_nt"]]
if you don't want the extra columns.Hello I have seemed to include the clonotype_id, aa sequence, and nt sequence. My isse now is that when I go to create a .csv I get this error "Error in as.data.frame.default(x[[i]], optional = TRUE) : cannot coerce class ‘structure("Seurat", package = "Seurat")’ to a data.frame". I cant seem to figure out a way to make a .csv?
It seems you are somehow trying to write the Seurat object to file rather than the metadata dateframe. Need the code used to have any shot of helping you.
Yes of course. Here is the full script-
--
I also just realized that the aa sequence and the nt sequence is not at all in my data opps! Thank you again for taking time to help me!
Please use the code formatting button (the one with 1's and 0's) in the future. I have done it for you this time.
Why did you think your last few lines would work? You never define the
T8.meta
object, and you were not meant to just useobject
in yoursubset
call, but your Seurat object, the name of which I had no way of knowing. You also no longer need theWhichCells
call since you're using subset instead.So your last 3 lines should be:
In the future, please place all relevant code in your opening post so folks don't have to continually ask for more information.
Hello, Thank you very much for all your help, you got it to work! Also sorry for all the confusion/hassle if you couldn't tell I am new to this and you've been a great help!
Glad to hear it. If this answers your question, consider accepting the answer by clicking the checkmark by the answer.
Hello again, when I plug in say T8.meta <- T8[["clonotype_id"]] i get this error message "subscript out of bounds" and that seems to be the same for everything I plug into the brackets
This occurs because
T8
is just a vector of cell barcodes rather than a subset of your Seurat object. Running the code in my previous comment before doing this will fix it.