Code Monkey home page Code Monkey logo

niches's Introduction

NICHES

Niche Interactions and Cellular Heterogeneity in Extracellular Signaling

Overview

NICHES is a simple but powerful computational toolset to analyze cell-cell signaling at the single-cell level. NICHES creates unique one-to-one pairs of cells and characterizes each cellular interaction across queried ligand-receptor signaling mechanisms. This allows low-dimensional embedding of cellular interactions in signal-space. Existing meta-data is carried over during transformation, allowing easy downstream statistical analysis using existing single-cell software packages including Seurat, Scanpy, Scater, and Monocle3. NICHES allows UMAP, tSNE, and pseudotemporal exploration of cell-cell interactions and sensed cellular microenvironmments across celltypes, between experimental batches and conditions, and over developmental trajectories.

When applied to scRNAseq datasets, a uniform sampling of unique barcode pairings is taken from each celltype cross. When applied to spatial datasets, users may elect to constrain edge construction to cellular nearest-neighbors, or to neighbors within a certain radius, to provide a histologically-grounded portrait of cell-cell signaling and cellular niches. When system-level outputs are requested, NICHES computes all possible connectivity edges between all input cells.

Inputs and outputs to NICHES may be in either tabular or Seurat object format.

For detailed Methods, please see our publication in Bioinformatics: https://doi.org/10.1093/bioinformatics/btac775

Installation

To install NICHES in R, you may run:

library(devtools)
install_github('msraredon/NICHES', ref = 'master')

Vignettes

For use-case vignettes, please visit: https://msraredon.github.io/NICHES/articles/

Reference

If used for publication, please cite: https://doi.org/10.1093/bioinformatics/btac775

niches's People

Contributors

jcyang34 avatar msraredon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

niches's Issues

Setting DefaultAssay to class Function

I'm running the PBMC3k vignette with the sessionInfo pasted below. The RunNICHES() method is throwing the error:

Error in UseMethod(generic = "DefaultAssay<-", object = object) : no applicable method for 'DefaultAssay<-' applied to an object of class "function"

The error appears to be in the prepSeurat function, which is called by RunNICHES() and applies the DefaultAssay function within.

The RunNICHES command from the vignette is:

scc <- RunNICHES(sub,
                 assay = 'RNA',
                 species = 'human',
                 LR.database = 'omnipath',
                 cell_types = 'seurat_annotations',
                 CellToCell = T)

The rest of the vignette can be found here: https://msraredon.github.io/NICHES/articles/02%20NICHES%20Single.html

R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.2 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so.3

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] ggplot2_3.3.6           dplyr_1.0.9             NICHES_1.0.0            SeuratWrappers_0.3.0    pbmc3k.SeuratData_3.1.4 panc8.SeuratData_3.0.2 
 [7] ifnb.SeuratData_3.1.0   SeuratData_0.2.2        sp_1.5-0                SeuratObject_4.1.1      Seurat_4.1.1            biomaRt_2.50.3         

getSeuratAssay function gives an error

Hi,

I am using the latest version of the NICHES and I found that the getSeuratAssay function called from RunNICHES method gives me this error:

Error in .make_numeric_version(x, strict, .standard_regexps()$valid_numeric_version) : 
  invalid non-character version specification 'x' (type: double)

The function uses this code to retrieve assay data depending on the Seurat Version:

getSeuratAssay <- function(object,assay,slot){
  if(SeuratObject::Version(object) >= 5) return(Seurat::GetAssayData(object,assay=assay,layer=slot))
  else return(Seurat::GetAssayData(object,assay=assay,slot=slot))
}

I think the cause of the error is SeuratObject's version function returns a character "4.0.0" which is being compared to 5.0 and it spits out the error pasted above. Can you please fix this?

Thank you.
Madhav

Error: No cell overlap between new meta data and Seurat object

Hi NICHES Team. Thank you for the nice package you developed.
I am having trouble running NICHES on my dataset and even when using the brain data in the tutorial.
For the tutorial, by just running exactly the same lines of code as provided in the vignette, I get this same error as when i use my own dataset: the error message is what is indicated in the subject above: Below is a backtrace tree construction of the error:

  1. ├─seurat_merged_impute_list %>% ...
  2. └─purrr::map(...)
  3. └─purrr:::map_("list", .x, .f, ..., .progress = .progress)
  4. ├─purrr:::with_indexed_errors(...)
    
  5. │ └─base::withCallingHandlers(...)
    
  6. ├─purrr:::call_with_cleanup(...)
    
  7. └─.f(.x[[i]], ...)
    
  8.   ├─NICHES::RunNICHES(...)
    
  9.   └─NICHES:::RunNICHES.Seurat(...)
    
  10.     └─NICHES:::RunNICHES.default(...)
    
  11.       └─NICHES::RunNeighborhoodToCell(...)
    
  12.         ├─Seurat::AddMetaData(...)
    
  13.         └─SeuratObject:::AddMetaData.Seurat(...)
    
  14.           ├─methods (local) `[[<-`(`*tmp*`, col.name, value = `<fct>`)
    
  15.           └─SeuratObject (local) `[[<-`(`*tmp*`, col.name, value = `<fct>`)
    
  16.             └─base::stop(...)
    

Error: No cell overlap between new meta data and Seurat object

Could this be a bug, and is there a way to solve this?

Thank you

Default map all metadata

Not critical, but would be better for new users if default in RunNICHES was to map all metadata from the input object

How to draw the heatmap blow using code in Vignette '01 NICHES Spatial.Rmd'

Hi, I am very appreciated by your excellent work ! I have a question that how to draw the heatmap below using code in Vignette '01 NICHES Spatial.Rmd'? From the vignette, drawing the heatmap of principal components of cell-cell matrix is available but how to directly draw the celltype-celltype matrix heatmap? Thanks a lot !
image

Function RunNICHES does not work for one-cell case

I am trying to run NICHES analysis on a splitted, un-imputed data set. The data set has 6 samples (annotated by 'Condition'), and 13 cell types (annotated by 'Global_CellType_V2'). Some cell types contain few cells, and that caused the problem -- when a cell type has only 1 single cell, RunNICHES reports an error: https://github.com/satijalab/seurat/issues/8362

Error in methods::slot(object = object, name = "layers")[[layer]][features, :
incorrect number of [dimensions]

Below is the code, and the cell type distribution when i=2 (where the problem occurs).

split <- SplitObject(All_Annotated_V2.imputed,split.by='Condition')
names(split)

# Cell To Cell (CTC)
scc.list <- list()
for(i in 1:length(split)){
  print(i)
  scc.list[[i]] <- RunNICHES(split[[i]],
                             LR.database="fantom5",
                             species="mouse",
                             assay="RNA",
                             cell_types = "Global_CellType_V2",
                             meta.data.to.map = names(split[[i]]@meta.data), 
                             SystemToCell = F,
                             CellToCell = T,
                             CellToSystem=F) 
}
names(scc.list) <- names(split)
table(Idents(split[[i]]))

Adipogenic_Precursor_Cells           Dcn+_Fibroblasts          Dkk2+_Fibroblasts                Endothelial 
                        16                       1686                        468                         22 
                Epithelial        Fibroblasts_Cycling IFN_Stimulated_Fibroblasts                     Immune 
                         2                        345                         41                        202 
        Myh11+_Fibroblasts   Rspo3+_Frzb+_Fibroblasts              Schwann_Cells            Schwann_Cycling 
                         1                        583                       1390                        137 
        Taco1+_Fibroblasts 
                        34 

omnipath_download() failed

Hi, thank you for your hard work on this package.

I am currently trying to run the function RunNICHES(), and I am getting an error related to retrieving data from Omnipath.

niches_results <- RunNICHES(seurat,
                 assay = 'RNA',
                 species = 'mouse',
                 LR.database = 'omnipath',
                 CellToCell = T)


Error in (function (URL, FUN, ..., N.TRIES = 1L)  :
  omnipath_download() failed:
  URL: https://omnipathdb.org/interactions?genesymbols=yes&datasets=ligrecextra&organisms=10090&fields=sources,references,curation_effort&license=academic
  error: cannot open the connection to 'https://omnipathdb.org/interactions?genesymbols=yes&datasets=ligrecextra&organisms=10090&fields=sources,references,curation_effort&license=academic'

Calls: <Anonymous> ... <Anonymous> -> import_omnipath -> do.call -> <Anonymous>
Execution halted

I found a discussion on this error message on the OmnipathR Github page (link) and they stated there that it could be due to a temporary disruption in the Omnipath service. However, I have been trying to run this command for the past three days and it has not resolved yet. Please let me know if you have any advice for me.

Normalization, rad.set, scripts

Hi,
Thank you for the new cool tool! As Im using NICHES, I have several questions (as follow) and hope to get clarification on:

  1. Normalization:
    I notice that in vignettes/01 NICHES Spatial.Rmd, the UMAP was created with SCTransformed data, yet RunNICHES uses log normalized + imputed (Seurat Normalize +ALRA function) for the analysis. I also notice that tests/test_2.R uses SCT for RunNICHES.
    So just curious in what scenarios would you recommend using SCT or log normalization for RunNICHES?

  2. rad.set:
    I also hope to get clarification on RunNICHES rad.set.
    To be specific, let's say rad.set = 2. Then what's the exact distance Im setting?
    My guess, is that radius r = Euclidean distance to the nearest (1st) neighbor.
    And rad.set = 2 means the search distance is 2r = 2 times the time distance to the 1st neighbor. (like in the picture attached)
    Is that NICHES definition of rad.set, or is it something else?

  3. scripts:
    I'm also curious if you plan to post the scripts used to generate the figures in the manuscripts?
    (I looked at the 3 scripts in vignettes and 2 scripts in test, but I dont think I encounter such scripts).

Thank you in advance for your time and help!

Screen Shot 2022-02-15 at 12 57 28 PM

Error: No cell overlap between new meta data and Seurat object

Hi,

Thanks for this great tool.

NICHES has worked well for me in the past. However, now I am running into "Error: No cell overlap between new meta data and Seurat object".

I am trying to find ligand receptor networks upregulated in Visium spots with a certain annotation in meta.data column "hotspots".

Here is my code:
[email protected]$x <- s12_niche@images$caudal_6.5_r_V13Y22.328_D1@coordinates$row
[email protected]$y <- s12_niche@images$caudal_6.5_r_V13Y22.328_D1@coordinates$col
DefaultAssay(s12_niche) <- "Spatial"
s12_niche <- SeuratWrappers::RunALRA(s12_niche)
s12_niche_output <- RunNICHES(object = s12_niche,
LR.database = "fantom5",
species = "human",
assay = "alra",
position.x = 'x',
position.y = 'y',
k = 4,
cell_types = "hotspots",
min.cells.per.ident = 0,
min.cells.per.gene = NULL,
meta.data.to.map = c('orig.ident', 'hotspots'),
CellToCell = F,CellToSystem = F,SystemToCell = F,
CellToCellSpatial = F,CellToNeighborhood = F,NeighborhoodToCell = T).

Output:

Set cell types as Identity of object internally

Subsetting to populations with greater than 0 cells

3987 distinct cells from 2 celltypes to be analyzed

Limiting ground truth to genes within dataset

Mapping against 2470 ground truth signaling mechanisms
Compute edgelist based on mutual nearest neighbors.
Error: No cell overlap between new meta data and Seurat object

I would appreciate any help regarding potential issues.
Thank you!

Number of space transcriptome samples

Hi,
msraredon, I have learned your Spatio-Temporal NICHES tutorial, and now I have a question to consult you. Your tutorial contains an E10 sample and an E11 sample, but I have three biological duplicates for each sample. Can I analyze six samples through one analytical process? Or do I have to choose one to one for analysis?

Running NICHES on large spatial datasets

I have encountered an interesting bug, I think related to how we are calculating edgelists in spatial data.

If I RunNICHES on imputed spatial data of reasonable size, I get the following:
image and the loop quits after i=1

If I RunNICHES on the non-imputed but same spatial data, the loop gets through i=3 and then quits, and gives the following:
image

Thoughts?

I think that

  1. we probably need to update how we compute edgelists
  2. something about more vs. less sparse data is having an effect here... why?
    S

memory leak for single-cell resolution spatial edgelist construction

Hi, Thank you for writing such a wonderful & useful tool!

I am currently using this for my MERFISH data; and I noticed that with even one sample of 30,000 cells; the function for constructing the edgelist causes a memory leak since it seems to first calculate all possible distances between all cells for the spatial edgelist before filtering for the k closest neighbors. For single-cell resolution spatial data, this can quickly get out of hand; in my case, my 64G RAM was no match.

I have made a slower, but more RAM-friendly work-around by hacking together a version of the edgelist construction function that finds the neighboring cells iteratively and only retains the k closest neighbor cells as it goes.

I'm including a snippet of it here (with added option for parallelization with future), since I hope it may be a useful addition to helping to solve this leak for others using your software.

# example for 10 neighbors
# meta is a data.frame with your cell metadata information
# spatial_1 and spatial_2 are column names inside the meta data frame for the x and y coordinates
get_niche_neighbors <- function(meta, spatial_1='spatial_1', spatial_2='spatial_2', k = 10) {
  library(pblapply)
  library(future)

  df <- data.frame(x = meta[,spatial_1], y = meta[, spatial_2])
  rownames(df) <- rownames(meta)

  edgelist <- pblapply(X = rownames(df),
                       cl = "future",
                       FUN = function(cell) {
    # only keep the k closest cells for each iteration; don't let it save the rest
    data.frame(
      from = cell,
      to = names(sort(setNames(sqrt(abs(df[cell, "x"] - df$x)^2 + abs(df[cell, "y"] - df$y)^2), rownames(df)))[1:(k + 1)])
      )
  })
  edgelist <- do.call(rbind, edgelist)

  return(edgelist)
}

Sorry if this would be better placed as a pull request; I am honestly not much of a developer!

Compatibility with Seurat V5

Seurat v5 introduces several structural changes to Seurat object that are incompatible to NICHES:

  • Removal of slot

  • Accessor change regarding the retrieval of the count and data matrix: obj[[assay_name]]@data changed to obj[[assay_name]]$data

Suggestions:

  • Check versions of Seurat objects
  • Update accessors if it's v5

NICHES for spatial transcriptomic data

Thank you for developing such a wonderful tool.

I am attempting to use NICHES on spatial transcriptomic data on Visium.

I saw the vignette pasted here: (https://msraredon.github.io/NICHES/articles/01%20NICHES%20Spatial.html)

I have a few questions:

**1. I am currently analyzing my spatial dataset through Giotto but it seems like NICHES utilizes Seurat. The vignette was not specific regarding where NICHES is utilized- is it after the deconvolution step after seurat?

  1. NICHES can be run on imputed or non-imputed data. - is this deconvoluted vs. non-deconvolved data? Do you have vignette on non-imputed data?

  2. it seems like niches output into an object and I have to scale/visualize and create UMAP again ?**

Appreciate the assistance.

Analyzing scRNA-seq data with multiple treatment groups

Hi,
I have a scRNA-seq Seurat object with cells from six different treatment groups depending on age and time interval (meaning six different options for orig.ident). I am following the vignette 'Converting Single-Cell Atlases to Single-Cell Signaling Atlases' and I want to run NICHES on each treatment type subset so I can compare the results, but I am unsure whether to subset my Seurat object by orig.ident and run NICHES on each separately, or to run NICHES on the entire dataset together, and then subset the NICHES object by orig.ident.

I have tried both methods and they yield very different results, so I was wondering which you would recommend?

Trying to install `NICHE` in a fresh `renv 0.15.4` within `R/4.1.0` fails:

`* Project '/lustre06/project/6004736/modules/software/R-spatial-tools' loaded. [renv 0.15.4]

R
Error: object 'R' not found
renv::install("msraredon/NICHES")
Retrieving 'https://api.github.com/repos/msraredon/NICHES/tarball/8d378d53dc2d06cda7a83072846122151c5a5cff' ...
OK [downloaded 10.1 Mb in 1.8 secs]
Error in state$requirements[[record$Package]] :
wrong arguments for subsetting an environment
Traceback (most recent calls last):
11: renv::install("msraredon/NICHES")
10: retrieve(names(remotes))
9: handler(package, renv_retrieve_impl(package))
8: renv_retrieve_impl(package)
7: renv_retrieve_github(record)
6: renv_retrieve_package(record, url, path)
5: renv_retrieve_successful(record, path)
4: retrieve(package)
3: handler(package, renv_retrieve_impl(package))
2: renv_retrieve_impl(package)
1: renv_retrieve_incompatible(record)`

On the same system NICHE can be installed outside of an renv without any problem.
$ hostnamectl Operating System: Rocky Linux 8.4 (Green Obsidian) Architecture: x86-64

Any suggestions on what it is going on?

Thank you in advance!

reference for installation path wrong

Path for installation is incorrect

To install NICHES in R, you may run:

library(devtools)
install_github('msraredon/Connectome', ref = 'master')

should be refering to NICHES as path
To install NICHES in R, you may run:

library(devtools)
install_github('msraredon/NICHES', ref = 'master')

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.