PMBio/MuDataSeurat

invalid class “DimReduc” object

gjhuizing opened this issue · 7 comments

Hi,

ReadH5MU was giving me the following error:

Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
Warning: No columnames present in cell embeddings, setting to 'atacpca_1:50'
Error in validObject(.Object) : 
  invalid class “DimReduc” object: invalid object for slot "feature.loadings" in class "DimReduc": got class "NULL", should be or extend class "matrix"
In addition: Warning messages:
1: In missing_on_read("/var", "global variables metadata") :
  Missing on read: /var. Seurat does not support global variables metadata.
2: In missing_on_read("/varp", "pairwise annotation of variables") :
  Missing on read: /varp. Seurat does not support pairwise annotation of variables.

I managed to fix it by computing the PCA embeddings explicitly. Before that I was plotting UMAPs without explicitly computing PCA before.

Putting it here in case someone encounters the same error. Does the conversion to Seurat require PCA embeddings ? Or maybe it does when UMAP is present ?

Anyway thanks for this compatibility tool!

Best,

GJ

Can you test this patch?

diff --git a/R/ReadH5MU.R b/R/ReadH5MU.R
index f93d33e..98b232d 100644
--- a/R/ReadH5MU.R
+++ b/R/ReadH5MU.R
@@ -224,7 +224,8 @@ ReadH5MU <- function(file) {
     maybe_loadings <- matrix()
     if (emb %in% names(OBSM2VARM)) {
       varm_key = OBSM2VARM[[emb]]
-      maybe_loadings <- loadings[[varm_key]]
+      if (hasName(loadings, varm_key))
+        maybe_loadings <- loadings[[varm_key]]
     }
 
     emb_stdev <- numeric()
@@ -254,7 +255,8 @@ ReadH5MU <- function(file) {
       maybe_loadings <- matrix()
       if (emb %in% names(OBSM2VARM)) {
         varm_key = OBSM2VARM[[emb]]
-        maybe_loadings <- mod_varm[[mod]][[varm_key]]
+        if (hasName(mod_varm[[mod]], varm_key))
+            maybe_loadings <- mod_varm[[mod]][[varm_key]]
       }
 
       emb_stdev <- numeric()

Hum that doesn't seem to work, I get the same error! But I'm not very familiar with R so maybe I installed the patch in the wrong way? I forked the repo, applied the patch and did remotes::install_github("gjhuizing/MuDataSeurat").

No, you seem to have done everything correctly. In that case, it would be really helpful if you could provide a sample .h5mu file.

Sure, I can provide the h5mu that works (pca done) and the one that doesn't (no pca done). Do you mind if I send it to you privately though ?

Sure, just use the email address in the package description.

I can read both files with my patch (but not without it). Did you install the patched version in a session that you already worked in? If so, did you restart R afterwards?

I can read both files with my patch (but not without it). Did you install the patched version in a session that you already worked in? If so, did you restart R afterwards?

Oh I didn't, that might be the reason! I'll give it a look this afternoon but we can probably consider it fixed then! Thanks :)