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

Converting Seurat to Loom #4514

Closed
Jeff87075 opened this issue May 21, 2021 · 4 comments
Closed

Converting Seurat to Loom #4514

Jeff87075 opened this issue May 21, 2021 · 4 comments

Comments

@Jeff87075
Copy link

Hi, I'm trying to convert Seurat objects to loom files but I'm confused as to which functions work now and which functions are deprecated. I first tried the as.loom() function described in this vignette here and it works. However, if I'm understanding things correctly, this function is now deprecated and the preferred approach should be using the functions from SeuratDisk?

Yet when I read the documentation for SeuratDisk and functions related to converting Seurat objects to loom, I see there is also an as.loom() function as well as SaveLoom() function. Yet when I attempt SaveLoom() I get this error message

New count is  Error in cat("New count is ", new_count, "\n") : 
  argument 2 (type 'environment') cannot be handled by 'cat'

On top of all of that, the vignette here for loomR suggests using the Convert() function as such:

pfile <- Convert(from = pbmc_small, to = "loom", filename = "pbmc_small.loom", 
    display.progress = FALSE)

But it seems the Convert() function has been updated and is no longer applicable to operating with anything that is related to loom files (or is loomR completely deprecated)? I've tried to look at the SeuratDisk page articles but it seems there is not a lot of explanation on how to deal with loom file type. I'm currently using Seurat version 3.2.2 (if the version matters) as all of the current analysis was done before the update. I would appreciate any guidance and explanation on the various functions (which still works or which no longer works) and what is the best way to convert Seurat to loom, many thanks!

@denvercal1234GitHub
Copy link

denvercal1234GitHub commented May 21, 2021

Piggybacking on the question. When we convert a Seurat object to loom, it will only change the data type/class to loom data type. But if we want to have spliced/unspliced counts to perform Velocity analysis, we still need go back to the FASTQ/BAM files? If so, what is the main reason why we want to convert the object? Thank you for your help!

@samuel-marsh
Copy link
Collaborator

Hi,

Not member of the dev team but hopefully can be helpful.
@Jeff87075 As the vignette that you reference states the ability to convert and manipulate loom objects is now done via the SeuratDisk package. Older versions of Seurat still have the as.loom function but to make sure your object conversion is done properly I would recommend using SeuratDisk function. Depending on the order in which you loaded packages in given R session you may need to force R to use SeuratDisk's version of the function over that in older version of Seurat i.e.:

loom_obj <- SeuratDisk::as.loom(...)

In regards to the error that you are receiving can you provide a reproducible example where this happens (using object from SeuratData package for instance). I am able to use both as.loom and SaveLoom without any errors using the pbmc3k.final object from SeuratData.

I'm sure that @mojaveazure or another member of the Seurat team can confirm but I believe that loomr is deprecated and now fully replaced by SeuratDisk. As note to @mojaveazure & Seurat team if this is the case then link and text Tutorial vignette should be changed to avoid confusion ("For more details about interacting with loom files in R and Seurat, please see loomR on GitHub.").

@denvercal1234GitHub Yes the format of your object (Seurat, SCE, loom, AnnData, etc) does not have anything to do with RNA velocity measures unless you have run Velocyto or other package on the raw sequencing data and incorporated those into your object first. In terms of why to use the loom object that is going to be package dependent and I would direct you to this link provided in conversion vigentte to Linnarsson lab website explaining loom format: http://linnarssonlab.org/loompy/format/index.html

Best,
Sam

@Jeff87075
Copy link
Author

Thanks for the detailed response! I just have a few follow-up questions:

  1. As I understand it, SeuratDisk depends on SeuratObject to run but since I want to (have to) keep using Seurat v3.0, is there any way I can avoid SeuratDisk from overwriting the functions in v3.0 and replace them with the newer ones?
  2. I get the Error in Graphs(object = x) : could not find function "Graphs" error in the last line and it seems I have to run library(SeuratObject) to avoid this error but then again, does that mean I must be forced to use at least Seurat v4.0 or above?
    The code I ran is as follows:
> library(Seurat)

Seurat v4 will be going to CRAN in the near future;
 for more details, please visit https://satijalab.org/seurat/v4_changes

> library(SeuratDisk)
Registered S3 methods overwritten by 'SeuratObject':
  method                     from  
  $.JackStrawData            Seurat
  $.Seurat                   Seurat
  $.SeuratCommand            Seurat
  $<-.Seurat                 Seurat
  [.Assay                    Seurat
  [.DimReduc                 Seurat
  [.Seurat                   Seurat
  [.SeuratCommand            Seurat
  [.SpatialImage             Seurat
  [[.Assay                   Seurat
  [[.DimReduc                Seurat
  [[.Seurat                  Seurat
  levels<-.Seurat            Seurat
  .DollarNames.JackStrawData Seurat
  .DollarNames.Seurat        Seurat
  .DollarNames.SeuratCommand Seurat
  as.list.SeuratCommand      Seurat
  as.logical.JackStrawData   Seurat
  dim.Assay                  Seurat
  dim.DimReduc               Seurat
  dim.Neighbor               Seurat
  dim.Seurat                 Seurat
  dim.SpatialImage           Seurat
  dimnames.Assay             Seurat
  dimnames.DimReduc          Seurat
  dimnames.Seurat            Seurat
  droplevels.Seurat          Seurat
  length.DimReduc            Seurat
  levels.Seurat              Seurat
  merge.Assay                Seurat
  merge.Seurat               Seurat
  names.DimReduc             Seurat
  names.Seurat               Seurat
  print.DimReduc             Seurat
  subset.Assay               Seurat
  subset.DimReduc            Seurat
  subset.Seurat              Seurat
  subset.SpatialImage        Seurat
Registered S3 methods overwritten by 'SeuratDisk':
  method            from  
  as.Seurat.loom    Seurat
  as.sparse.H5Group Seurat

Attaching package: ‘SeuratDisk’

The following object is masked from ‘package:Seurat’:

    as.loom

> test = pbmc_small
> loom <- as.loom(test, filename = "D:/test.loom")
Saving data from RNA as /matrix
  |=============================================================================| 100%
Adding slot counts for assay RNA
Adding layer counts
  |=============================================================================| 100%
Error in Graphs(object = x) : could not find function "Graphs"

@rsatija
Copy link
Collaborator

rsatija commented Jul 6, 2023

We are closing this issue now as we are no longer prioritizing support for loom conversion.

In Seurat v5, we include support for the v5 assay class, which can flexibly store data in a variety of formats (including disk-backed formats). We include multiple examples for disk-backed analysis using the BPCells package from Ben Parks .

@rsatija rsatija closed this as completed Jul 6, 2023
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

No branches or pull requests

4 participants