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

Updating iSEEnrich & iSEEinit #10

Merged
merged 22 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ccf4e8d
add a couple of param in iSEEnrich to accomodate more plots for visua…
NajlaAbassi Sep 19, 2024
3ae20bf
add tests
NajlaAbassi Sep 19, 2024
7c7f304
update vignette with the new iSEEnrich
NajlaAbassi Sep 19, 2024
c41c3ed
update vignette
NajlaAbassi Sep 20, 2024
9844d1e
less dependencies, just to make the code more uniform
NajlaAbassi Sep 20, 2024
a74ceff
iSEEinit() now accecpts features as a vector, a list or dataframe!
NajlaAbassi Sep 20, 2024
057fe68
check for feature type
NajlaAbassi Sep 20, 2024
2b898fd
updating iSEEinit to accept features as character vector, list or dat…
NajlaAbassi Sep 23, 2024
6b1e87d
updating vignette
NajlaAbassi Sep 23, 2024
a93b387
update the iSEEnrich example
NajlaAbassi Sep 25, 2024
570f6b6
while at it, trying to fix the GHA for the linux system
federicomarini Sep 26, 2024
4dd6bf1
removing the list option in as input
NajlaAbassi Sep 30, 2024
2ba6ac4
new parameter in, it corresponds to the genes column name when featur…
NajlaAbassi Sep 30, 2024
8af497e
adding some tests for the new gene_id param
NajlaAbassi Sep 30, 2024
337519d
add some checks for the reddim_type, clusters and groups
NajlaAbassi Sep 30, 2024
1b7fa29
updating vignette
NajlaAbassi Sep 30, 2024
b5f8cfb
fixing the call position for gene_id
NajlaAbassi Sep 30, 2024
f9942cd
adding a couple of test for iSEEnrich
NajlaAbassi Sep 30, 2024
3aebbc6
adding some additional statements to catch the messages - it is optio…
federicomarini Oct 2, 2024
f85b3c9
Merge branch 'updating_iSEEnrich&iSEEinit' of github.com:NajlaAbassi/…
federicomarini Oct 2, 2024
df61c85
update package version
NajlaAbassi Oct 4, 2024
9b77b50
update news to include main changes in the package
NajlaAbassi Oct 4, 2024
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
9 changes: 4 additions & 5 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@ jobs:
if: runner.os == 'Linux'
env:
RHUB_PLATFORM: linux-x86_64-ubuntu-gcc
run: |
Rscript -e "remotes::install_github('r-hub/sysreqs')"
sysreqs=$(Rscript -e "cat(sysreqs::sysreq_commands('DESCRIPTION'))")
sudo -s eval "$sysreqs"
sudo apt-get update && sudo apt-get -y install libcurl4-openssl-dev libglpk-dev libharfbuzz-dev libfribidi-dev
uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
pak-version: devel

- name: Install system dependencies (macOS)
if: runner.os == 'macOS'
Expand Down
2 changes: 1 addition & 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: 1.1.1
Version: 1.1.2
Authors@R:
c(
person(given = "Najla", family = "Abassi", role = c("aut", "cre"),
Expand Down
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ importFrom(ggplot2,scale_fill_manual)
importFrom(ggplot2,scale_y_discrete)
importFrom(ggplot2,theme)
importFrom(ggplot2,theme_void)
importFrom(iSEE,RowDataTable)
importFrom(iSEEu,FeatureSetTable)
importFrom(iSEEu,createGeneSetCommands)
importFrom(iSEEu,registerFeatureSetCommands)
importFrom(igraph,"V<-")
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

* Adding in a new function `iSEEmarker()`, more focused on finding marker genes
* A new `iSEEinit()` version without the `DynamicMarkerTable` panel
* Expanding the input of `iSEEinit()` to accept features as `data.frame` in addition to `vector`
* Adding visualization plots to `iSEEnrich()`

# iSEEfier 1.0.0

Expand Down
76 changes: 51 additions & 25 deletions R/iSEEinit.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
#' list in a single view.
#'
#' @param sce SingleCellExperiment object
#' @param features A character vector containing a list of genes
#' @param features A character vector or a data.frame containing a list of genes.
#' If `features` is a data.frame, the column containing the gene names must be named "id"
#' @param reddim_type A string vector containing the dimensionality reduction
#' type
#' @param clusters A character string containing the name of the
#' clusters/cell-type/state...(as listed in the colData of the sce)
#' @param groups A character string of the groups/conditions...(as it appears in
#' the colData of the sce)
#' @param gene_id A character string containing the name of the column name containing
#' gene names/ids, when 'features' is a data.frame
#' @param add_markdown_panel A logical indicating whether or not to include the
#' MarkdownBoard panel in the initial configuration

#'
#' @return A list of "Panel" objects specifying the initial state of iSEE
#' instance
Expand Down Expand Up @@ -48,21 +52,22 @@ iSEEinit <- function(sce,
reddim_type = "TSNE",
clusters = colnames(colData(sce))[1],
groups = colnames(colData(sce))[1],
gene_id="id",
add_markdown_panel = FALSE) {

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

stopifnot(is.character(features), length(features) > 0)

stopifnot(isScalarCharacter(reddim_type))

stopifnot(isScalarCharacter(clusters))

stopifnot(isScalarCharacter(groups))

stopifnot(isTRUEorFALSE(add_markdown_panel))

stopifnot(isScalarCharacter(gene_id))


if (!(reddim_type %in% reducedDimNames(sce))) {
Expand All @@ -71,6 +76,23 @@ iSEEinit <- function(sce,
"Please select one of these: ",
paste(available_reddims, collapse = ", "))
}

if (is.data.frame(features)) {
if ((gene_id %in% colnames(features))) {

features <- as.character(features[[gene_id]])
} else {
stop("The column name '", gene_id,"' does not exist in the 'features' data.frame!")
}
}

else if (is.vector(features)) {
features <- as.character(features)
} else {
stop("Unsupported feature type. Must be a character vector, or data.frame!")
}

stopifnot(is.character(features), NROW(features) > 0)

if (!all(features %in% rownames(sce))) {
not_available_features <- features[!features %in% rownames(sce)]
Expand All @@ -79,7 +101,7 @@ iSEEinit <- function(sce,
paste(not_available_features, collapse = ", "))

features <- features[features %in% rownames(sce)]
if (length(features) == 0)
if (NROW(features) == 0)
federicomarini marked this conversation as resolved.
Show resolved Hide resolved
stop("No features available!")
}

Expand All @@ -104,57 +126,60 @@ iSEEinit <- function(sce,
message("colData column not found for the `groups` parameter, defaulting to ",
fallback_groups)
}





initial <- list()


for (j in features) {
initial[[paste0("ReducedDimensionPlot", which(features == j))]] <- new(
for (j in 1:NROW(features)) {
feature_name <- if (is.data.frame(features)) features[j, ] else features[[j]]
initial[[paste0("ReducedDimensionPlot", j)]] <- new(
"ReducedDimensionPlot",
Type = reddim_type,
ColorBy = "Feature name",
ColorByFeatureName = j,
ColorByFeatureSource = paste0("RowDataTable", which(features == j)),
ColorByFeatureName = feature_name,
ColorByFeatureSource = paste0("RowDataTable", j),
ColumnSelectionSource = "ColumnDataPlot1",
SelectionAlpha = 0.05
)
initial[[paste0("FeatureAssayPlot", which(features == j))]] <- new(

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

initial[[paste0("RowDataTable", which(features == j))]] <- new(
initial[[paste0("RowDataTable", j)]] <- new(
"RowDataTable",
Selected = j,
Search = j
Selected = feature_name,
Search = feature_name
)
}

if (length(features) > 1) {
initial[[paste0("FeatureAssayPlot", length(features) + 1)]] <- new(
if (NROW(features) > 1) {
feature1 <- if (is.data.frame(features)) features[1, ] else features[[1]]
feature2 <- if (is.data.frame(features)) features[2, ] else features[[2]]

initial[[paste0("FeatureAssayPlot", NROW(features) + 1)]] <- new(
"FeatureAssayPlot",
XAxis = "Feature name",
XAxisFeatureName = features[[1]],
YAxisFeatureName = features[[2]]
XAxisFeatureName = feature1,
YAxisFeatureName = feature2
)
}

if (add_markdown_panel == TRUE) {
initial[[paste0("ReducedDimensionPlot", length(features) + 1)]] <- new(
initial[[paste0("ReducedDimensionPlot", NROW(features) + 1)]] <- new(
"ReducedDimensionPlot",
Type = reddim_type,
ColorByColumnData = clusters,
ColorBy = "Column data",
ColumnSelectionSource = paste0("FeatureAssayPlot", length(features) + 1),
ColumnSelectionSource = paste0("FeatureAssayPlot", NROW(features) + 1),
FacetColumnBy = "Column data",
FacetColumnByColData = groups,
SelectionAlpha = 0.05
Expand All @@ -165,12 +190,12 @@ iSEEinit <- function(sce,
Content = "# Placeholder\n\nFill me with text!",
PanelWidth = 4L)
} else {
initial[[paste0("ReducedDimensionPlot", length(features) + 1)]] <- new(
initial[[paste0("ReducedDimensionPlot", NROW(features) + 1)]] <- new(
"ReducedDimensionPlot",
Type = reddim_type,
ColorByColumnData = clusters,
ColorBy = "Column data",
ColumnSelectionSource = paste0("FeatureAssayPlot", length(features) + 1),
ColumnSelectionSource = paste0("FeatureAssayPlot", NROW(features) + 1),
FacetColumnBy = "Column data",
FacetColumnByColData = groups,
SelectionAlpha = 0.05,
Expand All @@ -196,5 +221,6 @@ iSEEinit <- function(sce,


return(initial)


}
107 changes: 96 additions & 11 deletions R/iSEEnrich.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,22 @@
#' extract mappings of gene sets to gene IDs.
#' @param gene_identifier A character string specifying the identifier to use to
#' extract gene IDs for the organism package
#'
#'
#' @param clusters A character string containing the name of the
#' clusters/cell-type/state...(as listed in the colData of the sce)
#'
#' @param groups A character string of the groups/conditions...(as it appears in
#' the colData of the sce)
federicomarini marked this conversation as resolved.
Show resolved Hide resolved
#'
#' @param reddim_type A string vector containing the dimensionality reduction
#' type
#'
#'
#' @return A list of "Panel" objects specifying the initial state of iSEE
#' instance
#' @export iSEEnrich
#' @importFrom iSEE RowDataTable
#' @importFrom iSEEu createGeneSetCommands
#' @importFrom iSEEu registerFeatureSetCommands
#' @importFrom iSEEu FeatureSetTable
#' @importFrom BiocBaseUtils isScalarCharacter
#'
#'
Expand All @@ -29,15 +37,24 @@
#' GO_collection <- "GO"
#' Mm_organism <- "org.Mm.eg.db"
#' gene_id <- "SYMBOL"
#' clusters <- "stimulus"
#' groups <- "single cell quality"
#' reddim_type <- "PCA"
#' results <- iSEEnrich(sce = sce,
#' collection = GO_collection,
#' organism = Mm_organism,
#' gene_identifier = gene_id)
#' gene_identifier = gene_id,
#' clusters = clusters,
#' groups = groups,
#' reddim_type = reddim_type)
#'
iSEEnrich <- function(sce,
collection = c("GO", "KEGG"),
organism = "org.Hs.eg.db",
gene_identifier = "ENTREZID") {
gene_identifier = "ENTREZID",
clusters = colnames(colData(sce))[1],
groups = colnames(colData(sce))[1],
reddim_type = "PCA") {

## Checks on arguments
if (!is(sce, "SingleCellExperiment"))
Expand All @@ -50,7 +67,40 @@ iSEEnrich <- function(sce,
stopifnot(isScalarCharacter(organism))

stopifnot(isScalarCharacter(gene_identifier))


stopifnot(isScalarCharacter(clusters))

stopifnot(isScalarCharacter(groups))
federicomarini marked this conversation as resolved.
Show resolved Hide resolved

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)
}

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 (!requireNamespace(organism, quietly = TRUE))
stop("Please check the value of the provided orgDb package ",
"(the package needs to be installed)...",
Expand All @@ -64,11 +114,46 @@ iSEEnrich <- function(sce,
organism = organism,
identifier = gene_identifier)
sce1 <- registerFeatureSetCommands(sce, cmds)

initial[["FeatureSetTable1"]] <- FeatureSetTable()

initial[["RowDataTable1"]] <- RowDataTable(
RowSelectionSource = "FeatureSetTable1")

initial[["FeatureSetTable1"]] <- new(
"FeatureSetTable", Collection = collection)

initial[["RowDataTable1"]] <- new(
"RowDataTable", RowSelectionSource = "FeatureSetTable1")

initial[["FeatureAssayPlot1"]] <- new(
"FeatureAssayPlot",
XAxis = "Column data",
XAxisColumnData = groups,
YAxisFeatureSource = "RowDataTable1",
ColorBy = "Column data",
ColorByColumnData = groups,
ColumnSelectionSource = "ColumnDataPlot1")

initial[["ColumnDataPlot1"]] <- new(
"ColumnDataPlot",
XAxis = "Column data",
YAxis = clusters,
XAxisColumnData = groups,
ColorByColumnData = clusters,
ColorBy = "Column data"

)

initial[["ReducedDimensionPlot1"]] <- new(
"ReducedDimensionPlot",
Type = reddim_type,
FacetColumnByColData = groups,
FacetColumnBy = "Column data",
ColorBy = "Feature name",
ColorByFeatureSource = "RowDataTable1",
ColumnSelectionSource = "ColumnDataPlot1"
)

initial[["MarkdownBoard1"]] <- new(
"MarkdownBoard",
Content = "# Placeholder\n\nFill me with genes, or anything!")


return(
list(
Expand Down
7 changes: 6 additions & 1 deletion man/iSEEinit.Rd

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

Loading
Loading