Identifying the sample names from seurat object

Hi, Thanks for the function: ```
demultiplex_convert_to_10x

It seems that it needs two arguments as an input, a seurat object and the sample names. I am struggling to identify the sample names stored in the object. If I follow the tutorial, then I get a list of sample names with 9 elements as all the demultiplexed samples should belong to these 9 samples. But upon running the function with this, I don't get any files demultiplexed but the message NULL is printed on the console. Could you please suggest how can I work around this? 

Thanks in advance.

Hi Rahul,

To help you more effectively, it would be beneficial if you could provide a bit more detail regarding the problem. For example:

  • Can you provide more information about the structure of your Seurat object? Specifically, how the samples are stored within it. You could report here the output of head(data.seurat).

  • Could you share how you are determining the sample names from the Seurat object?

  • You mentioned receiving a message saying NULL. Are there any other warnings or error messages printed to the console when you attempt to run the function?

Please provide these additional details so we can better understand the issue and guide you towards a solution.

Hi Sara,

thanks for your response. The output of the head(seurat.object) looks like this:

The way I’m trying to fetch the sample names is with this command:
sample.names ← unique(singlet$HTO_classification)

The function that I’m trying to run is this one:

demultiplex_convert_to_10x ← function(obj, samples) {
if(class(obj) != “Seurat”) {
message(“WARNING: this rds file does not contain a Seurat object! STOP RUNNING THIS SCRIPT”)
message(“Check the data type by running:”)
message(“class(data.seurat)”)
stop()
}
if(!dir.exists(file.path(getwd(), “demultiplexed”))) {
dir.create(file.path(getwd(), “demultiplexed”))
} else {
print(“WARNING! A demultiplexed directory already exists”)
return()
}
for (i in 1:length(sample.names)) {
print(paste0(“Converting sample “, sample.names[i]))
obj.sub ← obj[[samples[i]]]
DropletUtils::write10xCounts(path = paste0(getwd(),”/demultiplexed/”,sample.names[i]), x = obj.sub[[“RNA”]]@data, type = “sparse”, version=“3”)
}
}

The way I’m running it looks like this:

demultiplex_convert_to_10x(singlet,sample.names), where singlet is a seurat object and sample.names is the vector with sample names.

Interestingly, I used the same function last year in October and it worked perfectly fine for another set of files from the same dataset. But I’m revisiting this now with a second batch of files, it gives me nothing. Please see below what I get upon running this function:

demultiplex_convert_to_10x(singlet,sample.names)
[1] “WARNING! A demultiplexed directory already exists”
NULL

Hi Rahul,

Thanks for sharing the details of your issue. The error message you’re seeing, WARNING! A demultiplexed directory already exists, indicates that the function stops execution because it finds an existing folder named “demultiplexed”. This is a safeguard to prevent overwriting any existing data in that folder.

To resolve this, you can either move or rename the existing “demultiplexed” folder and then run your function again. This should allow the function to create a new “demultiplexed” directory and proceed without interruption.

Let me know if this resolves the issue or if there’s anything else you need help with.