Skip to content

Commit

Permalink
fix preprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
YingxinLin committed Oct 15, 2024
1 parent f54cc84 commit e446fcb
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 104 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

S3method(aggregate,Matrix)
export(CellSPA)
export(calAggExpressionCorrelation)
export(calBaselineAllMetrics)
Expand Down
3 changes: 2 additions & 1 deletion R/processing.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ processingSPE <- function(spe,
spe <- scater::runUMAP(spe,
dimred = "PCA",
min_dist = 0.3,
verbose = verbose)
verbose = verbose,
n_neighbors = min(ncol(spe), 15))
return(spe)
}

Expand Down
11 changes: 6 additions & 5 deletions R/readMethods.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ readXenium <- function(data_dir,
#' corresponding to the meta data in the output files.
#' @param tiff_path a character specifying the path of a tiff file output from BIDCell.
#' @param method_name a character specifying the name of the method.
#' @param spatialCoordsNames a vector of two characters indicate the name of the spatial coordinates for each cell.
#'
#' @import SpatialExperiment
#' @importFrom methods as
Expand All @@ -109,9 +110,11 @@ readXenium <- function(data_dir,
readBIDCell <- function(data_dir,
meta_idx = NULL,
tiff_path = NULL,
method_name = NULL) {
method_name = NULL,
spatialCoordsNames = c("cell_centroid_x",
"cell_centroid_y")) {

all_files <- list.files(data_dir)
all_files <- list.files(data_dir, pattern = "csv")

cell_outputs <- lapply(1:length(all_files), function(i) {
res <- read.csv(file.path(data_dir, all_files[i]))
Expand Down Expand Up @@ -155,11 +158,9 @@ readBIDCell <- function(data_dir,
data <- as(as.matrix(data), "CsparseMatrix")



spe <- SpatialExperiment(assay = list(counts = Matrix::t(data)),
colData = data.frame(meta),
spatialCoordsNames = c("cell_centroid_x",
"cell_centroid_y"))
spatialCoordsNames = spatialCoordsNames)

spe <- .initialise_CellSPA_list(spe)
spe <- .add_dataset_metrics(spe)
Expand Down
1 change: 1 addition & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ subset <- function(spe, col_idx) {

# From Matrix.utils::aggregate.Matrix() function, which has been archived on CRAN

#' @export
aggregate.Matrix <- function(x, groupings = NULL, form = NULL, fun = 'sum', ...) {
if (!methods::is(x,'Matrix')) {
x <- Matrix::Matrix(as.matrix(x), sparse = TRUE)
Expand Down
159 changes: 82 additions & 77 deletions docs/articles/CellSPA.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ pkgdown: 2.1.0
pkgdown_sha: ~
articles:
CellSPA: CellSPA.html
last_built: 2024-09-13T03:13Z
last_built: 2024-10-15T03:57Z
12 changes: 11 additions & 1 deletion docs/reference/readBIDCell.html

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

10 changes: 9 additions & 1 deletion man/readBIDCell.Rd

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

42 changes: 24 additions & 18 deletions vignettes/CellSPA.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,28 @@ output:
toc_float: true
package: BiocStyle
vignette: >
%\VignetteIndexEntry{CellSPA}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
%\VignetteIndexEntry{CellSPA}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---



```{r global-options, include=FALSE}
knitr::opts_chunk$set(
message=FALSE,
warning=FALSE,
collapse=TRUE,
comment="#>"
)
library(BiocStyle)
knitr::opts_chunk$set(
message=FALSE,
warning=FALSE,
collapse=TRUE,
comment="#>"
)
library(BiocStyle)
```




```{r, include=FALSE}
library(CellSPA)
library(ggplot2)
library(ggthemes)
Expand All @@ -41,14 +42,19 @@ theme_set(theme_bw())

# Read BIDCell output

```{r, cache=TRUE}
```{r cache = TRUE}
data_dir <- system.file("extdata/BIDCell_csv_output", package = "CellSPA")
data_dir
tiff_path <- system.file("extdata/BIDCell_output_subset.tif", package = "CellSPA")
spe <- readBIDCell(data_dir,
tiff_path = tiff_path,
method_name = "BIDCell",
spatialCoordsNames = c("cell_centroid_x",
"cell_centroid_y"))
```


```{r, cache=TRUE}
```{r cache = TRUE}
spe <- processingSPE(spe,
qc_range = list(total_transciprts = c(20, 2000),
total_genes = c(20, Inf)))
Expand Down Expand Up @@ -82,7 +88,7 @@ head(colData(spe))

```{r}
sce_ref_full <- readRDS(system.file("extdata/sce_FFPE_full.rds",
package = "CellSPA"))
package = "CellSPA"))
sce_ref <- processingRef(sce_ref_full,
celltype = sce_ref_full$graph_cluster_anno,
subset_row = rownames(spe))
Expand Down

0 comments on commit e446fcb

Please sign in to comment.