Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update scVIIntegration to take StdAssay/SCTAssay as input #180

Merged
merged 8 commits into from
Jan 29, 2024

Conversation

dcollins15
Copy link
Contributor

@dcollins15 dcollins15 commented Jan 25, 2024

Follow up to #179 - unfortunately, the complimentary fix to #179 (https://github.com/satijalab/seurat-private/pull/894) caused IntegrateLayers to break if SeuratWrappers was not installed.

This PR resolves the problem by bringing scVIIntegration into better sync with the methods provided natively in Seurat and operating on Assays as opposed to Seurat instances.

Since I was in the neighborhood I've done a bit of tidying up but in the process reformatted the code in a kinda opinionated way (I'm running styler) - keen to hear what folks think!

Once https://github.com/satijalab/seurat-private/pull/895 is merged SeuratWrappers will be compatible with prod and develop versions of Seurat and the following script should run as before:

library(rlang)
library(Seurat)
library(SeuratData)
library(SeuratWrappers)

InstallData("ifnb")
ifnb <- LoadData("ifnb")

# split the RNA assay into layers for control and stimulated cells, respectively
ifnb[["RNA"]] <- split(ifnb[["RNA"]], f = ifnb$stim)

# run standard anlaysis workflow
ifnb <- NormalizeData(ifnb)
ifnb <- FindVariableFeatures(ifnb)
ifnb <- ScaleData(ifnb)
ifnb <- RunPCA(ifnb)

# integrate using scVI
ifnb <- IntegrateLayers(
  object = ifnb,
  method = scVIIntegration,
  orig.reduction = "pca",
  new.reduction = "integrated.scvi",
  conda_env = "path/to/conda/env",
  verbose = TRUE,
  # set low to speed things up
  max_epochs = 10,
)

Closes:

# get a named vector mapping each cell to its respective layer
layer.map <- labels(
layer.masks,
values = Cells(object, layer = layers)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mhkowalski would you mind giving this function a sanity check for me?

Since CreateIntegrationGroups isn't exported by Seurat it seemed simpler to just re-implement the logic here. I've dropped the scale.layer param since.

As far as I can tell this was just being used get the cell IDs for all of the layers since there's only ever one scale layer present. Unless the order is important here, or there's a possibility that the data is subset during normalization/scaling than I think this should be safe (especially since scVIIntegration itself forces the use of the "counts" layers).

I might be missing something though...

@Gesmira
Copy link
Contributor

Gesmira commented Jan 26, 2024

Thank you for doing this! I really appreciate the efforts to make the code clean!
I ran this on a pbmc3k example and didn't have any issues. One problem that we should maybe think about addressing is working with BPCells. If i convert the counts and data to IterableMatrix types, I do get this error

> pbmc3k <- IntegrateLayers(
+ object = pbmc3k, method = scVIIntegration,
+ orig.reduction = "pca", new.reduction = "integrated.rpca.tissue",
+ verbose = FALSE, conda_env = "/home/mollag/anaconda3/envs/py39/"
+ )
Error: Matrix type cannot be converted to python (only integer, numeric, complex, logical, and character matrixes can be converted

@dcollins15
Copy link
Contributor Author

One problem that we should maybe think about addressing is working with BPCells.

That is a very good point - was this working before?

@Gesmira
Copy link
Contributor

Gesmira commented Jan 26, 2024

No, BPCells w scvi did not work on the previous branch either!

@dcollins15
Copy link
Contributor Author

No, BPCells w scvi did not work on the previous branch either!

Alright, in that case, I'd say this is OOS for now - let's spin up a card and tackle it in a subsequent iteration 👌

@dcollins15 dcollins15 merged commit d9594f6 into master Jan 29, 2024
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants