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

Sample codes #1

Open
whelena opened this issue Jun 3, 2019 · 1 comment
Open

Sample codes #1

whelena opened this issue Jun 3, 2019 · 1 comment

Comments

@whelena
Copy link

whelena commented Jun 3, 2019

Hi I am attempting to use the novoSpaRc package in R 3.5.0 using a matrix.mtx file from 10x genomics. However, I am having difficulty setting up the inputs and parameters for gw_assign. i am wondering if there are any sample codes out there (python/R) that could help me out a bit

@lambdamoses
Copy link
Owner

Sorry for the late reply. I'm no longer working on predicting gene expression in spatial data. First you should normalize the data whichever way you like. Here allen_use is a dgCMatrix for scRNA-seq data with genes in rows and cells in columns. starmap_use is a dgCMatrix for spatial data with genes in rows and cells in columns. locations is a data frame with columns x, y, and if you wish, z, for locations of cells. Calculate graph-based distance:

D_cell <- calc_graph_dist(allen_use, k = 20)
D_loc <- calc_graph_dist(locations, k = 20, transposed = TRUE)

If a reference spatial gene expression atlas is provided, then you should also provide Euclidean distances between each cell in the scRNA-seq dataset and each location in gene expression space. For this example, a randomly selected panel of 50 genes present in both the scRNA-seq and the spatial dataset is used.

set.seed(50)
genes_use <- sample(rownames(allen_use), 50)
allen_sub <- as.matrix(allen_use[genes_use,])
starmap_sub <- as.matrix(starmap_use[genes_use,])
D_cell_loc <- Rfast::dista(t(allen_sub), t(starmap_sub))

Then probabilistically assign cells to locations: This step will be very time consuming if you are not using an optimized BLAS.

p <- rep(1, ncol(allen_sub)) / ncol(allen_sub)
q <- rep(1, nrow(locations)) / nrow(locations)
cell_loc <- gw_assign(D_cell, D_loc, D_cell_loc, alpha = 0.5, p = p, q = q, check_every = 1)

Predict gene expressions at the locations:

gene_pred <- predict_expr_loc(allen_use, cell_loc)

Use the function plot_spatial_expression to plot the predictions and group truth.

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

2 participants