Vesalius
Vesalius copied to clipboard
Inserting my own log normed PCA data
Hello,
How can I replace this step
...
bead <- new(Class = 'SlideSeq', assay = 'Spatial', coordinates = coords[,c("x","y")])
rownames(bead@coordinates) <- rownames(coords)
exp <- CreateSeuratObject(counts, assay ="Spatial")
bead <- bead[Cells(x = exp)]
DefaultAssay(object = bead) <- "Spatial"
exp[["slice1"]] <- bead
#reducedDims(exp, withDimnames=TRUE) <- list(logPCA=t(data.matrix(lpc, rownames.force=TRUE)))
exp <- NormalizeData(exp)
exp <- FindVariableFeatures(exp, nfeatures = 100)
exp <- ScaleData(exp)
#message(paste0("Seurat Pre-Processed Data: maynard_noNA_",slideTag[i]))
rgbu <- rgbUMAP(exp, pcs=30, conserveSparse = FALSE)
...
when I have a preprocessed matrix of log normalized PCs for my spots?
Hi,
Replacing the PCA embedding with your own data is not possible in vesalius as this a core feature of the package.
You will have to use the normalization offered by Seurat and vesalius will use that count data to run PCA ( followed by UMAP) internally.
Would there be a workaround? The lack of this may be prohibitive for our group.
In the current version there is no work around. The embedding and the way we use them is a core functionality of the package. Could you explain why this is a prohibitive issue?
This is a low priority feature and I will consider adding it if there is a high number of user requests for it. I might look into it for the next release but for the current version I don't think it is worth the time.
I will leave this issue open and tag it as a feature request.
As I said above, I will have a look into it for the next version.
If anyone else is interested in seeing this feature, you can upvote this comment.
It is prohibitive because we would like to preprocess a given data set in the same way and compare it across multiple methods. Is it such a core feature that user preprocessed data would change the way the method works?
Understood.
It will not change how the method works but it would require some changes to the core code that would need to be thoroughly tested to ensure that everything works as it should. At least on the new version.
In the version you are currently using, I am not sure of how much it would require but as I said, at the moment making these changes to the release version is not a high work priority for me.
As this is an open source project, you are free to change the source code to suit your needs and make a pull request with your changes.
Yes I would be willing to do that. Can you guide me?
The code you will need to modify is in https://github.com/patrickCNMartin/Vesalius/blob/main/R/PCA_to_RGB.R
I suspect you would be better off modifying the rgbUMAP
function.
Please note that once the new version is fully functional, I will overwrite the entire main branch with the new code. I am not sure of a timeline for this to happen. Just in case you can always fork the main version now.
Thank you! Seems all I may need to do is replace the following line in rgbUMAP
reduc <- RunPCA(SO,npcs = pcs,verbose =FALSE)
with
reduc <- SO
Given, I send a Seurat Object to rgbUMAP
with the reduction slot filled, as if by RunPCA
exp[["pca"]] <- CreateDimReducObject(embeddings = <mylogPCAdata>, key = "PC", assay = DefaultAssay(exp))
This should work, as long as the following slots for the DimReduceObject don't matter for RunUMAP
and subsequent processing in rgbUMAP
.
feature.loadings, feature.loadings.projected, stdev
I wonder if I need the following code anymore, if the log normalized scaled data and variable features are only used to run PCA and UMAP in rgbUMAP
? Or is the original data with variable features important to Vesalius after this point?
exp <- NormalizeData(exp)
exp <- FindVariableFeatures(exp, nfeatures = 100)
exp <- ScaleData(exp)
Good to know. I assume that this should do what you expect it to do as long as the RunUMAP
function gets the correct reduction argument (reduction.use = "pca"
. ) As for the other internal aspects of Seurat objects, that is beyond my knowledge.
This section won't be required if you are doing all of these steps yourself. NormalizeData
is a log transform by default, FindVariableFeatures uses a Loess regression (if I am not mistaken) to get the the top n
features. ScaleData
will scale your data.
exp <- NormalizeData(exp)
exp <- FindVariableFeatures(exp, nfeatures = 100)
exp <- ScaleData(exp)
Something to keep in mind, is that Seurat runs PCA only on the top variable features.
If you goal is to make sure that everything is exactly the same between each tool, it would be wise to also check the output of your variable features if you use any.
Thank you.
I am not familiar with install_github and am having trouble actually locating the file in my local install. I looked in the R library where I installed packages for the environment under vesalius
but couldnt find it.
In this case, I would advise you to build and install from source. You should have a local copy of the source code where you make your changes.
To do so, you can use the following from your R console:
library(devtools)
devtools::build("vesalius", vignettes = FALSE) # vesalius = directory containing source code
install.packages("vesalius_1.0.1.tar.gz", repos = NULL) # vesalius...tar.gz = the output of R CMD build as done by devtools
library(vesalius)
Note that the version of vesalius is shown in the DESCRIPTION file.
If you have already loaded vesalius into R, you can add the following to ensure that the package is being removed before the new install:
detach(package:vesalius, unload=TRUE)
remove.packages("vesalius")