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

Tests extended #7

Merged
merged 19 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: iSEEfier
Title: Streamlining the creation of initial states for starting an iSEE instance
Version: 0.2.0
Version: 0.3.0
Authors@R:
c(
person(given = "Najla", family = "Abassi", role = c("aut", "cre"),
Expand Down Expand Up @@ -32,12 +32,14 @@ Imports:
rlang,
stats,
SummarizedExperiment,
SingleCellExperiment,
visNetwork
Suggests:
knitr,
rmarkdown,
scater,
scRNAseq,
org.Mm.eg.db,
scuttle,
BiocStyle,
testthat (>= 3.0.0)
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ importClassesFrom(iSEE,FeatureAssayPlot)
importClassesFrom(iSEE,ReducedDimensionPlot)
importClassesFrom(iSEE,RowDataTable)
importClassesFrom(iSEEu,MarkdownBoard)
importFrom(SingleCellExperiment,reducedDimNames)
importFrom(SummarizedExperiment,colData)
importFrom(ggplot2,aes)
importFrom(ggplot2,geom_tile)
Expand All @@ -27,6 +28,7 @@ importFrom(igraph,"V<-")
importFrom(igraph,V)
importFrom(igraph,graph.empty)
importFrom(igraph,graph_from_data_frame)
importFrom(methods,is)
importFrom(methods,new)
importFrom(rlang,.data)
importFrom(stats,na.omit)
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# iSEEfier 0.3.0

* Main functions are equipped with extra parameters determining their behavior
* Unit test suite is fully in!

# iSEEfier 0.2.0

* Functions renamed to the final version, in a more matching and descriptive manner
Expand Down
227 changes: 153 additions & 74 deletions R/iSEEfier.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' iSEEinit: Create an initial state of an iSEE instance for gene expression visualization
#'
#'
#' `iSEEinit()` defines the initial setup of an iSEE instance, recommending tailored visual elements to effortlessly illustrate the expression of a gene list in a single view.
#'
#' @param sce SingleCellExperiment object
Expand All @@ -14,13 +14,15 @@
#' @export
#' @importFrom methods new
#' @importFrom SummarizedExperiment colData
#' @importFrom SingleCellExperiment reducedDimNames
#' @importFrom methods is
#' @importClassesFrom iSEE ColumnDataPlot
#' @importClassesFrom iSEE ReducedDimensionPlot
#' @importClassesFrom iSEE FeatureAssayPlot
#' @importClassesFrom iSEE RowDataTable
#' @importClassesFrom iSEE ComplexHeatmapPlot
#' @importClassesFrom iSEEu MarkdownBoard
#'
#'
#'
#' @examples
#' sce <- scRNAseq::RichardTCellData()
Expand All @@ -38,92 +40,169 @@ iSEEinit <- function(sce,
groups = colnames(colData(sce))[1],
markdownboard = FALSE,
dynamicMarkerTable = FALSE) {

## Checks on arguments
if (!is(sce, "SingleCellExperiment"))
stop("Please provide a SingleCellExperiment as input!")

stopifnot(is.character(feature.list))
stopifnot(length(feature.list) > 0)

stopifnot(is.character(reddim.type))
stopifnot(length(reddim.type) == 1)

stopifnot(is.character(clusters))
stopifnot(length(clusters) == 1)

stopifnot(is.character(groups))
stopifnot(length(groups) == 1)

stopifnot(is.logical(markdownboard))
stopifnot(length(markdownboard) == 1)
stopifnot(is.logical(dynamicMarkerTable))
stopifnot(length(dynamicMarkerTable) == 1)

if (!(reddim.type %in% reducedDimNames(sce))) {
available_reddims <- reducedDimNames(sce)
stop("The selected reduced dimensionality embedding is not available!\n",
"Please select one of these: ",
paste(available_reddims, collapse = ", "))
}

if (!all(feature.list %in% rownames(sce))) {
not_available_features <- feature.list[!feature.list %in% rownames(sce)]
message("Some of the features specified are not available in the provided sce object!\n",
"Feature(s) not found: ",
paste(not_available_features, collapse = ", "))

feature.list <- feature.list[feature.list %in% rownames(sce)]
if (length(feature.list) == 0)
stop("No features available!")
}

if (!(clusters %in% colnames(colData(sce)))) {
if (ncol(colData(sce)) > 0) {
fallback_clusters <- colnames(colData(sce))[1]
} else {
stop("No colData provided for the `clusters`!")
}

message("colData column not found for the `clusters` parameter, defaulting to ",
fallback_clusters)
}

if (!(groups %in% colnames(colData(sce)))) {
if (ncol(colData(sce)) > 0) {
fallback_groups <- colnames(colData(sce))[1]
} else {
stop("No colData provided for the `groups`!")
}

message("colData column not found for the `groups` parameter, defaulting to ",
fallback_groups)
}




initial <- list()
feature.list <- as.list(feature.list)
clusters <- as.character(clusters)
group <- as.character(groups)


## TODO: do we need this to be enforced as list?
# feature.list <- as.list(feature.list)
# clusters <- as.character(clusters)
# groups <- as.character(groups)


for (j in feature.list) {
initial[[paste0("ReducedDimensionPlot", which(feature.list == j))]] <- new("ReducedDimensionPlot",
Type = reddim.type,
ColorBy = "Feature name",
ColorByFeatureName = j,
ColorByFeatureSource = paste0("RowDataTable", which(feature.list == j)),
ColumnSelectionSource = "ColumnDataPlot1",
SelectionAlpha = 0.05
initial[[paste0("ReducedDimensionPlot", which(feature.list == j))]] <- new(
"ReducedDimensionPlot",
Type = reddim.type,
ColorBy = "Feature name",
ColorByFeatureName = j,
ColorByFeatureSource = paste0("RowDataTable", which(feature.list == j)),
ColumnSelectionSource = "ColumnDataPlot1",
SelectionAlpha = 0.05
)

initial[[paste0("FeatureAssayPlot", which(feature.list == j))]] <- new("FeatureAssayPlot",
XAxis = "Column data",
XAxisColumnData = clusters,
YAxisFeatureName = j,
YAxisFeatureSource = paste0("RowDataTable", which(feature.list == j)),
ColorBy = "Column data",
ColorByColumnData = clusters

initial[[paste0("FeatureAssayPlot", which(feature.list == j))]] <- new(
"FeatureAssayPlot",
XAxis = "Column data",
XAxisColumnData = clusters,
YAxisFeatureName = j,
YAxisFeatureSource = paste0("RowDataTable", which(feature.list == j)),
ColorBy = "Column data",
ColorByColumnData = clusters
)

initial[[paste0("RowDataTable", which(feature.list == j))]] <- new("RowDataTable",
Selected = j,
Search = j

initial[[paste0("RowDataTable", which(feature.list == j))]] <- new(
"RowDataTable",
Selected = j,
Search = j
)
}

if (length(feature.list) > 1) {
initial[[paste0("FeatureAssayPlot", length(feature.list) + 1)]] <- new("FeatureAssayPlot",
XAxis = "Feature name",
XAxisFeatureName = feature.list[[1]],
YAxisFeatureName = feature.list[[2]]
initial[[paste0("FeatureAssayPlot", length(feature.list) + 1)]] <- new(
"FeatureAssayPlot",
XAxis = "Feature name",
XAxisFeatureName = feature.list[[1]],
YAxisFeatureName = feature.list[[2]]
)
}

initial[[paste0("ReducedDimensionPlot", length(feature.list) + 1)]] <- new("ReducedDimensionPlot",
Type = reddim.type,
ColorByColumnData = clusters,
ColorBy = "Column data",
ColumnSelectionSource = paste0("FeatureAssayPlot", length(feature.list) + 1),
FacetColumnBy = "Column data",
FacetColumnByColData = group,
SelectionAlpha = 0.05

initial[[paste0("ReducedDimensionPlot", length(feature.list) + 1)]] <- new(
"ReducedDimensionPlot",
Type = reddim.type,
ColorByColumnData = clusters,
ColorBy = "Column data",
ColumnSelectionSource = paste0("FeatureAssayPlot", length(feature.list) + 1),
FacetColumnBy = "Column data",
FacetColumnByColData = groups,
SelectionAlpha = 0.05
)


initial[["ComplexHeatmapPlot1"]] <- new("ComplexHeatmapPlot",
CustomRowsText = paste(feature.list, collapse = "\n"),
ColumnData = clusters


initial[["ComplexHeatmapPlot1"]] <- new(
"ComplexHeatmapPlot",
CustomRowsText = paste(feature.list, collapse = "\n"),
ColumnData = clusters
)

initial[["ColumnDataPlot1"]] <- new("ColumnDataPlot",
YAxis = clusters,
ColorBy = "Column data",
ColorByColumnData = clusters,
PanelWidth = 6L

initial[["ColumnDataPlot1"]] <- new(
"ColumnDataPlot",
YAxis = clusters,
ColorBy = "Column data",
ColorByColumnData = clusters,
PanelWidth = 6L
)

if (markdownboard == TRUE) {
initial[["MarkdownBoard1"]] <- new("MarkdownBoard",
Content = "# Placeholder\n\nFill me with text!",
PanelWidth = 4L)
initial[["MarkdownBoard1"]] <- new(
"MarkdownBoard",
Content = "# Placeholder\n\nFill me with text!",
PanelWidth = 4L)
}

if(dynamicMarkerTable == TRUE) {
initial[[paste0("ReducedDimensionPlot",length(feature.list)+2)]] <- new("ReducedDimensionPlot",
Type = reddim.type,
ColorByColumnData = clusters,
ColorBy = "Column data",
SelectionAlpha = 0.05,
ColumnSelectionSource = paste0("FeatureAssayPlot",length(feature.list)+2))


initial[["DynamicMarkerTable1"]] <- new("DynamicMarkerTable",
ColumnSelectionSource = paste0("ReducedDimensionPlot",length(feature.list)+2))

initial[[paste0("FeatureAssayPlot",length(feature.list)+2)]] <- new("FeatureAssayPlot",
XAxis = "Column data",
XAxisColumnData = group,
YAxisFeatureSource = "DynamicMarkerTable1")
initial[[paste0("ReducedDimensionPlot",length(feature.list)+2)]] <- new(
"ReducedDimensionPlot",
Type = reddim.type,
ColorByColumnData = clusters,
ColorBy = "Column data",
SelectionAlpha = 0.05,
ColumnSelectionSource = paste0("FeatureAssayPlot",length(feature.list)+2))


initial[["DynamicMarkerTable1"]] <- new(
"DynamicMarkerTable",
ColumnSelectionSource = paste0("ReducedDimensionPlot",length(feature.list)+2))

initial[[paste0("FeatureAssayPlot",length(feature.list)+2)]] <- new(
"FeatureAssayPlot",
XAxis = "Column data",
XAxisColumnData = groups,
YAxisFeatureSource = "DynamicMarkerTable1")
}

return(initial)
}

}
Loading
Loading