Coder Social home page Coder Social logo

Comments (4)

chiblyaa avatar chiblyaa commented on August 23, 2024 11

Hi Stephen,

I updated Jeffrey's SeuratToURD function to import the Seurat (v3) object into URD. I'm just testing it now and haven't encountered any issues so far. You'll have to create a custom function - in this case I named it seuratToURD2 - and then use that one to import your seurat object. Here's the code:

seuratToURD2 <- function(seurat.object) {
  if (requireNamespace("Seurat", quietly = TRUE)) {
    # Create an empty URD object
    ds <- new("URD")
    
    # Copy over data
    [email protected] <- as(as.matrix(seurat.object@assays$RNA@data), "dgCMatrix")
    if(!any(dim(seurat.object@assays$RNA@counts) == 0)) [email protected] <- as(as.matrix(seurat.object@assays$RNA@counts[rownames(seurat.object@assays$RNA@data), colnames(seurat.object@assays$RNA@data)]), "dgCMatrix")
    
    # Copy over metadata
    ## TO DO - grab kmeans clustering info
    get.data <- NULL
    if (.hasSlot(seurat.object, "data.info")) { 
      get.data <- as.data.frame(seurat.object@[email protected])
    } else if (.hasSlot(seurat.object, "meta.data")) { 
      get.data <- as.data.frame([email protected]) 
    }
    if(!is.null(get.data)) {
      di <- colnames(get.data)
      m <- grep("res|cluster|Res|Cluster", di, value=T, invert = T) # Put as metadata if it's not the result of a clustering.
      discrete <- apply(get.data, 2, function(x) length(unique(x)) / length(x))
      gi <- di[which(discrete <= 0.015)]
      ds@meta <- get.data[,m,drop=F]
      [email protected] <- get.data[,gi,drop=F]
    }
    
    # Copy over var.genes
    if(length(seurat.object@[email protected] > 0)) [email protected] <- seurat.object@[email protected]
    
    # Move over tSNE projection
    if (.hasSlot(seurat.object, "tsne.rot")) {
      if(!any(dim([email protected]) == 0)) {
        [email protected] <- as.data.frame([email protected])
        colnames([email protected]) <- c("tSNE1", "tSNE2")
      }
    } else if (.hasSlot(seurat.object, "reductions")) {
      if(("tsne" %in% names(seurat.object@reductions)) && !any(dim(seurat.object@reductions$tsne) == 0)) {
        [email protected] <- as.data.frame(seurat.object@[email protected])
        colnames([email protected]) <- c("tSNE1", "tSNE2")
      }
    }
    
    # Move over PCA results
    if (.hasSlot(seurat.object, "pca.x")) {
      if(!any(dim([email protected]) == 0)) {
        [email protected] <- [email protected]
        [email protected] <- [email protected]
        warning("Need to set which PCs are significant in @pca.sig")
      }
      ## TO DO: Convert SVD to sdev
    } else if (.hasSlot(seurat.object, "reductions")) {
      if(("pca" %in% names(seurat.object@reductions)) && !any(dim(Loadings(seurat.object, reduction = "pca")) == 0)) {
        [email protected] <- as.data.frame(Loadings(seurat.object, reduction = "pca"))
        [email protected] <- as.data.frame(seurat.object@[email protected])
        [email protected] <- seurat.object@reductions$pca@stdev
        [email protected] <- pcaMarchenkoPastur(M=dim([email protected])[1], N=dim([email protected])[1], [email protected])
      }
    }
    return(ds)
  } else {
    stop("Package Seurat is required for this function. To install: install.packages('Seurat')\n")
  }
}

from urd.

farrellja avatar farrellja commented on August 23, 2024

There is a function seuratToURD that should work with Seurat v2. I have not yet updated it for Seurat v3, and I believe the structure of the object changed there. You would then need to do all steps beginning with Calculate Diffusion Map in the QuickStart tutorial. The method that URD uses to calculate variable genes is different from Seurat, so you may also want to explore URD's variable gene results and compare them to those from Seurat. Additionally, if you didn't calculate a tSNE representation in Seurat, you may want to calculate one in URD just for visualization and exploration. Clustering wise, I generally cluster at each stage individually, though you could try exploring both methods.

from urd.

farrellja avatar farrellja commented on August 23, 2024

Thanks, Augustin! I will incorporate this into the code base soon & add an acknowledgment to you in the documentation & homepage.

from urd.

CLambert7 avatar CLambert7 commented on August 23, 2024

Thanks Stephen - really helpful!

from urd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.