Skip to content

Commit

Permalink
Updates for compiling parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiyu committed Dec 12, 2023
1 parent 68594f8 commit 46ccaab
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 23 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Description: A novel spatial topic model to integrate both cell type and spatial
information for every single cell.
License: GPL (>= 3)
Depends: R (>= 3.5.0),
Rcpp (>= 0.12.0),
Imports: RANN (>= 2.6.0),
Imports: Rcpp (>= 0.12.0),
RANN (>= 2.6.0),
sf (>= 1.0-12),
methods (>= 3.4),
foreach (>= 1.5.0),
Expand Down
4 changes: 3 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ export(Seurat5obj_to_SpaTopic)
export(SpaTopic_inference)
export(stratified_sampling_sf)
import(foreach)
import(iterators)
import(methods)
importFrom(RANN,nn2)
importFrom(Rcpp,evalCpp)
importFrom(Rcpp,sourceCpp)
importFrom(sf,st_as_sf)
importFrom(sf,st_cast)
importFrom(sf,st_crs)
Expand Down
5 changes: 5 additions & 0 deletions R/Gibbs_sampler.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,13 @@ gibbs_spatial_LDA_multiple<-function(...){
#' @seealso \code{\link{gibbs.res-class}}
#'
#' @importFrom RANN nn2
#'
#' @import foreach
#'
#' @import methods
#'
#' @import iterators
#'
#' @examples
#'
#' ## tissue is a data frame containing cellular information from one image or
Expand Down
2 changes: 1 addition & 1 deletion R/SpaTopic-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#'
#' @keywords package
#'
#' @importFrom Rcpp evalCpp
#' @importFrom Rcpp sourceCpp
#'
#' @useDynLib SpaTopic
NA
Expand Down
10 changes: 5 additions & 5 deletions docs/articles/SpaTopic.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ articles:
Model_Selection: Model_Selection.html
SpaTopic: SpaTopic.html
Intro_SpaTopic: Intro_SpaTopic.html
last_built: 2023-12-12T19:28Z
last_built: 2023-12-12T20:53Z

2 changes: 1 addition & 1 deletion docs/search.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/Makevars
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
## set the appropriate value, possibly CXX17.
#CXX_STD = CXX11

PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
CXXFLAGS=-O3
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) -Ilibsrc $(SHLIB_OPENMP_CXXFLAGS) ‘$(R_HOME)/bin/Rscript -e "RcppProgress:::CxxFlags()"‘
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) ‘$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"‘ $(SHLIB_OPENMP_CXXFLAGS) ‘$(R_HOME)/bin/Rscript -e "RcppProgress:::CxxFlags()"‘
#CXXFLAGS=-O3
CC=ccache clang -Qunused-arguments
CXX=ccache clang++ -Qunused-arguments
CCACHE_CPP2=yes
2 changes: 1 addition & 1 deletion src/Makevars.win
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
CXXFLAGS=-O3
#CXXFLAGS=-O3
CC=ccache clang -Qunused-arguments
CXX=ccache clang++ -Qunused-arguments
CCACHE_CPP2=yes
16 changes: 8 additions & 8 deletions vignettes/articles/SpaTopic.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The Lung5-1 sample contains 38 annotated cell types.
Since we used healthy lung tissue as the reference, tumor cells were labeled as ’basal’ cells.
More informaion can be found [here](https://satijalab.org/seurat/articles/seurat5_spatial_vignette_2.html#human-lung-nanostring-cosmx-spatial-molecular-imager).

```{r,message=FALSE,warning=FALSE}
```{r seurat,message=FALSE,warning=FALSE}
## We use Seurat v5 package to visualze the results
library(Seurat, quietly = TRUE);packageVersion("Seurat")
## Load the Seurat object for the image
Expand All @@ -51,7 +51,7 @@ options(future.globals.maxSize = 1e9)

We can use the Seurat function `ImageDimPlot` to visualize the distribution of cell types on the image.

```{r,fig.width=7, fig.height=13,message=FALSE,warning=FALSE}
```{r celltype,fig.width=7, fig.height=13,message=FALSE,warning=FALSE}
library(ggplot2)
celltype.plot <-ImageDimPlot(nano.obj, fov = "lung5.rep1", axes = TRUE, cols = "glasbey",dark.background = T)
celltype.plot+theme(legend.position = "bottom",legend.direction = "vertical")
Expand All @@ -69,7 +69,7 @@ The required input of SpaTopic is a data frame containing cells within on a sing
You may use the function `Seurat5obj_to_SpaTopic()` to extract input data from a typical Seurat v5 object.
The column name for cell type information need to be provided via option `group.by`.

```{r,message=FALSE,warning=FALSE}
```{r reformat, message=FALSE,warning=FALSE}
library(SpaTopic);packageVersion("SpaTopic")
## Prepare input from Seurat Object
dataset<-Seurat5obj_to_SpaTopic(object = nano.obj, group.by = "predicted.annotation.l1",image = "image1")
Expand All @@ -80,7 +80,7 @@ head(dataset)

This step takes around 90 seconds on a regular laptop

```{r}
```{r inference}
## Gibbs sampling for SpaTopic
system.time(gibbs.res<-SpaTopic_inference(dataset, ntopics = 7, sigma = 50, region_radius = 400))
```
Expand All @@ -91,7 +91,7 @@ system.time(gibbs.res<-SpaTopic_inference(dataset, ntopics = 7, sigma = 50, regi
SpaTopic identify seven topics from the image.
Below we use the heatmap to show the cell type composition within each topic.

```{r,fig.width=7,fig.height=4}
```{r heatmap,fig.width=7,fig.height=4}
library(pheatmap)
m <- as.data.frame(gibbs.res$Beta)
colnames(m)<-paste0("topic",1:7)
Expand All @@ -102,7 +102,7 @@ pheatmap::pheatmap(t(m))
We assign each cell to a topic with the highest posterior probability
and visualize the distribution of cell topics over the image.

```{r,fig.width=7, fig.height=8}
```{r topics,fig.width=7, fig.height=8}
prob<-as.matrix(gibbs.res$Z.trace)
nano.obj$Topic<-as.factor(apply(prob,1,which.max))
library(ggplot2)
Expand All @@ -115,15 +115,15 @@ ImageDimPlot(nano.obj, fov = "lung5.rep1", group.by = "Topic", axes = TRUE,
We compare `SpaTopic` to the function `BuildNicheAssay()` in Seurat v5.
It took around 5 min on the same laptop.

```{r,eval=FALSE}
```{r niches,eval=FALSE}
### NOT RUN!! We use the pre-computed result
system.time(nano.obj <- BuildNicheAssay(object = nano.obj, "lung5.rep1", group.by = "predicted.annotation.l1",
niches.k = 7, neighbors.k = 100))
```

We also visualize the distribution of seven niches over the same image.

```{r,fig.width=7, fig.height=8}
```{r niches_vis,fig.width=7, fig.height=8}
ImageDimPlot(nano.obj, fov = "lung5.rep1", group.by = "niches", axes = TRUE, dark.background = T,cols = "glasbey") + ggtitle("Niches")
```

Expand Down

0 comments on commit 46ccaab

Please sign in to comment.