Skip to content

Commit

Permalink
more fixes for check and bioccheck
Browse files Browse the repository at this point in the history
  • Loading branch information
shazanfar committed Sep 19, 2024
1 parent 8418e36 commit 1b17fd0
Show file tree
Hide file tree
Showing 34 changed files with 939 additions and 568 deletions.
25 changes: 18 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ Title: Weighted Sliced Inverse Regression (wSIR) for supervised
gene expression data
Version: 0.1.3
Authors@R: c(
person("Max", "Woollard", , "[email protected]", role = c("aut", "cre", "ctb")),
person("Pratibha", "Panwar", role = c("ctb")),
person("Linh", "Nghiem", role = c("aut","ctb")),
person("Shila", "Ghazanfar", , "[email protected]", role = c("aut", "ctb"))
person("Max", "Woollard", email = "[email protected]",
role = c("aut", "cre", "ctb"),
comment=c(ORCID="0009-0000-6319-6926")),
person("Pratibha", "Panwar", role = c("ctb"),
comment = c(ORCID = "0000-0002-7437-7084")),
person("Linh", "Nghiem", role = c("aut","ctb"),
comment=c(ORCID = "0000-0003-2874-9067")),
person("Shila", "Ghazanfar", email = "[email protected]",
role = c("aut", "ctb"), comment=c(ORCID="0000-0001-7861-6997"))
)
Description: Weighted Sliced Inverse Regression (wSIR) is a supervised dimension
reduction algorithm for spatial transcriptomics gene expression data. For a
Expand All @@ -23,10 +28,16 @@ License: GPL-2
Encoding: UTF-8
URL: https://sydneybiox.github.io/wSIR
BugReports: https://github.com/sydneybiox/wSIR/issues
biocViews: DimensionReduction, Software
LazyData: true
biocViews: DimensionReduction,
Software,
GeneExpression,
SingleCell,
Spatial,
Transcriptomics,
Regression
LazyData: false
Roxygen: list(markdown = TRUE)
Depends: R (>= 4.3.0),
Depends: R (>= 4.4.0),
Imports: Rfast,
magrittr,
ggplot2,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export(wSIR)
importFrom(BiocParallel,MulticoreParam)
importFrom(BiocParallel,bplapply)
importFrom(Rcpp,evalCpp)
importFrom(Rfast,dcor)
importFrom(distances,distances)
importFrom(doBy,which.maxn)
importFrom(ggplot2,aes)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# wSIR v0.1.4 (2024-09-19)
+ Submitted to Bioconductor.
26 changes: 18 additions & 8 deletions R/createWeightMatrix.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
#' createWeightMatrix
#'
#' @description
#' A function to create the weight matrix given the location of the cells, tile allocations and desired spatial weighting strength. Weight matrix entries represent level of spatial correlation between all pairs of tiles.
#' A function to create the weight matrix given the location of the cells,
#' tile allocations and desired spatial weighting strength. Weight matrix
#' entries represent level of spatial correlation between all pairs of tiles.
#'
#' @param coords dataframe of dimension n * 2. Column names c("x", "y"). Spatial position of each cell.
#' @param labels dataframe of dimension n * 1, column name c("coordinate"). Tile allocation of each cell. This is automatically created in the wSIR function.
#' @param alpha numeric value giving strength of spatial weighting matrix. alpha = 0 returns identity matrix and equals SIR. Large alpha values tend all entries towards 1. Default is 4.
#' @param coords dataframe of dimension n * 2. Column names c("x", "y").
#' Spatial position of each cell.
#' @param labels dataframe of dimension n * 1, column name c("coordinate").
#' Tile allocation of each cell. This is automatically created in the wSIR
#' function.
#' @param alpha numeric value giving strength of spatial weighting matrix.
#' alpha = 0 returns identity matrix and equals SIR. Large alpha values tend
#' all entries towards 1. Default is 4.
#'
#' @return matrix containing the weight value for all pairs of tiles. Each value is between 0 and 1, with 1 always on the diagonal.
#' @return matrix containing the weight value for all pairs of tiles. Each
#' value is between 0 and 1, with 1 always on the diagonal.
#'
#'
#'
#' @keywords internal

createWeightMatrix <- function(coords, labels, alpha = 4) {
alpha = 4/alpha # alpha_old = 0 (function argument = 0) gives alpha_new = Inf (rather than undefined) which equals SIR
alpha <- 4/alpha
# alpha_old = 0 (function argument = 0) gives
# alpha_new = Inf (rather than undefined) which equals SIR

avg_coords <- slicerCategorical(coords, labels)

Expand All @@ -23,10 +33,10 @@ createWeightMatrix <- function(coords, labels, alpha = 4) {
dist_mat <- as.matrix(stats::dist(avg_coords, diag = TRUE, upper = TRUE))

# mask out the slices that are far away from each other
D2 = as.matrix(stats::dist(avg_coords_groups, method = "manhattan"))
D2 <- as.matrix(stats::dist(avg_coords_groups, method = "manhattan"))
D2[D2 > 0] <- Inf

dist_mat_new = dist_mat + D2
dist_mat_new <- dist_mat + D2

dist_norm <- (1 - dist_mat_new / max(dist_mat, na.rm = TRUE))^alpha
weight_mat <- dist_norm
Expand Down
39 changes: 26 additions & 13 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#' MouseGastrulationData
#'
#' Data set consists of spatial transcriptomics data from a mouse embryo.
#' There are three samples, for each we have gene expression data (351 genes), spatial
#' There are three samples, for each we have gene expression data (351 genes),
#' spatial
#' coordinates on the two-dimensional spatial plane, and cell type labels.
#' Sample 1 contains 19451 cells, sample 2 contains 14891 cells and sample 3
#' contains 23194 cells. We have randomly sampled 20% of the cells from
Expand All @@ -15,19 +16,31 @@
#' sample2_exprs sample2_coords sample2_cell_types
#' sample3_exprs sample3_coords sample3_cell_types
#' @docType data
#' @format \code{sample1_exprs} has a row for each cell in sample 1 and a column for the
#' expression level of each gene. \code{sample1_coords} has a row for each cell in sample 1
#' and a column for its position in each of the two spatial axes. \code{sample1_cell_types}
#' a vector whose i'th entry contains the cell type of the i'th cell of sample 1.
#' \code{sample2_exprs} has a row for each cell in sample 2 and a column for the expression
#' level of each gene. \code{sample2_coords} has a row for each cell in sample 2 and a column
#' for its position in each of the two spatial axes. \code{sample2_cell_types} a vector whose
#' i'th entry contains the cell type of the i'th cell of sample 2. \code{sample3_exprs} has
#' a row for each cell in sample 3 and a column for the expression level of each gene.
#' \code{sample3_coords} has a row for each cell in sample 3 and a column for its position
#' in each of the two spatial axes. \code{sample3_cell_types} a vector, whose i'th entry
#' @format \code{sample1_exprs} has a row for each cell in sample 1 and a
#' column for the
#' expression level of each gene. \code{sample1_coords} has a row for each
#' cell in sample 1
#' and a column for its position in each of the two spatial axes.
#' \code{sample1_cell_types}
#' a vector whose i'th entry contains the cell type of the i'th cell of sample
#' 1.
#' \code{sample2_exprs} has a row for each cell in sample 2 and a column
#' for the expression
#' level of each gene. \code{sample2_coords} has a row for each cell in
#' sample 2 and a column
#' for its position in each of the two spatial axes. \code{sample2_cell_types}
#' a vector whose
#' i'th entry contains the cell type of the i'th cell of sample 2.
#' \code{sample3_exprs} has
#' a row for each cell in sample 3 and a column for the expression level of
#' each gene.
#' \code{sample3_coords} has a row for each cell in sample 3 and a column
#' for its position
#' in each of the two spatial axes. \code{sample3_cell_types} a vector,
#' whose i'th entry
#' contains the cell type of the i'th cell of sample 3.
#' @source Integration of spatial and single-cell transcriptomic data elucidates mouse
#' @source Integration of spatial and single-cell transcriptomic data
#' elucidates mouse
#' organogenesis, \emph{Nature Biotechnology}, 2022. Webpage:
#' \url{https://www.nature.com/articles/s41587-021-01006-2}
#' @keywords datasets
Expand Down
Loading

0 comments on commit 1b17fd0

Please sign in to comment.