Hi,
Sorry if I am asking a million questions, I find Seurat rather confusing.
I have created the following function:
move_counts_to_new_assay <- function(patient_data, assay_name, new_assay_name, pattern) {
assay_to_subset <- patient_data[[assay_name]]
features_to_extract <- row.names(assay_to_subset) %>%
grep(pattern, ., value = TRUE)
# Extract the data from the specified assay
extracted_data <- subset(
assay_to_subset,
features = features_to_extract)
# Change the key of the newly created assay
extracted_data@key <- paste0(new_assay_name, "_")
# Save the extracted data into a new assay
patient_data[[new_assay_name]] <- extracted_data
# Remove data from the original assay
patient_data[[assay_name]] <- subset(
assay_to_subset,
features = setdiff(row.names(assay_to_subset), features_to_extract))
return(patient_data)
}
The idea is to take a Seurat object and split one of its assays into two assays according to a pattern matched by grep. For example, I have an assay called "Nanostring" which contains RNA features ("AATK", "ABL1", "ABL2", "ACACB", "ACE", "ACKR1") and negative probes features ("Negative1", "Negative10", "Negative2", "Negative3"). I want to move the negative probes features to a different assay inside the same Seurat object so that the object has two assay, "Nanostring" with the RNA features and "negative" with the negative probes features.
The function above works but it throws a couple of warnings I do not fully understand:
extracted_data <- subset(
assay_to_subset,
features = features_to_extract)
Warning: Different features in new layer data than already exists for counts
The original "Nanostring" assay does not have a "data" layer, what is this error about? Can I subset the "counts" layer and remove the corresponding features from the "data" and "scale.data" features?
patient_data[[assay_name]] <- subset(
assay_to_subset,
features = setdiff(row.names(assay_to_subset), features_to_extract))
Warning: Different features in new layer data than already exists for counts
Warning message:
Different cells and/or features from existing assay Nanostring
Is this just saying that the new assay is different from the original one? Can I safely ignore this error? Or better, is there a way to do the same operation without triggering the error? Maybe I should just create two new assays and delete the original one.
Any insights on how to better accomplish this is highly appreciated, thanks!