Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 20, 2024
1 parent 8e24e18 commit 7562bb4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 34 deletions.
39 changes: 21 additions & 18 deletions R/DeconvExplorer.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ DeconvExplorer <- function(deconvexp_bulk = NULL,
width = 12,
fileInput("userSignatureUpload", "Upload Signature"),
div(style = "margin-top: -25px"),

p("You can upload a previsouly generated signature matrix of a deconvolution method and analyse it with DeconvExplorer. Multiple uploads are possible."),
fluidRow(
column(4, shinyWidgets::actionBttn("selectSigExploration", "Explore the signature", icon = icon("arrow-right"), color = "success", style = "simple")),
Expand Down Expand Up @@ -202,7 +201,7 @@ DeconvExplorer <- function(deconvexp_bulk = NULL,
column(
width = 4,
selectInput("deconvMethod", "Deconvolution Method",
choices = c('MuSiC'='music', omnideconv::deconvolution_methods[-10])
choices = c("MuSiC" = "music", omnideconv::deconvolution_methods[-10])
)
),
column(
Expand All @@ -221,8 +220,10 @@ DeconvExplorer <- function(deconvexp_bulk = NULL,
column(
width = 3,
div(
shinyBS::popify(shinyWidgets::actionBttn("deconvolute", "Deconvolute", style = 'simple', icon = icon('triangle-exclamation'), color = 'warning'),
"Attention", "Some methods are considerably slower than others; please keep this in mind when using DeconvExplorer for deconvolution."),
shinyBS::popify(
shinyWidgets::actionBttn("deconvolute", "Deconvolute", style = "simple", icon = icon("triangle-exclamation"), color = "warning"),
"Attention", "Some methods are considerably slower than others; please keep this in mind when using DeconvExplorer for deconvolution."
),
style = "margin-top:1.7em"
)
),
Expand All @@ -235,7 +236,7 @@ DeconvExplorer <- function(deconvexp_bulk = NULL,
title = "",
content = "Select a deconvolution method to run. If required and supported by the deconvolution method you can additionally select a custom signature to be used in computation. Please note this is an advanced feature and should be used with caution. "
)


deconv_plot_box <- shinydashboard::box(
id = "tour_deconvPlot",
Expand Down Expand Up @@ -512,43 +513,45 @@ DeconvExplorer <- function(deconvexp_bulk = NULL,
title = span("Clustered Signature", icon("question-circle", id = "sigHeatmapQ")),
status = "info", solidHeader = TRUE,
width = 12,
fluidRow(
fluidRow(
column(
width = 4,
selectInput("signatureToHeatmap", "Select a Signature", choices = NULL)
),
column(
width = 2,
selectInput("signatureAnnotationScore", "Select an annotation score",
choices = c("Entropy" = "entropy", "Gini Index" = "gini")
choices = c("Entropy" = "entropy", "Gini Index" = "gini")
)
),
column(
width = 2,
selectInput("signatureAnnotationPlotType", "Annotation Type",
choices = c("Bars" = "bar", "Lines" = "line")
choices = c("Bars" = "bar", "Lines" = "line")
)
),
column(
width = 2,
selectInput("clusterCelltypes", "Order rows (cell types)",
choices = c(".. by cell-type similarity" = "cluster", ".. alphabetically" = "no_cluster")
choices = c(".. by cell-type similarity" = "cluster", ".. alphabetically" = "no_cluster")
)
),
column(
width = 2,
selectInput("clusterGenes", "Order columns (genes)",
choices = c(".. by maximal z-score per cell type" = "z-score cutoff",
".. hierarchically based on euclidean distance" = "hierarchical clustering",
".. alphabetically" = "alphabetical")
choices = c(
".. by maximal z-score per cell type" = "z-score cutoff",
".. hierarchically based on euclidean distance" = "hierarchical clustering",
".. alphabetically" = "alphabetical"
)
)
)
),
fluidRow(
column(
width = 12,
InteractiveComplexHeatmap::originalHeatmapOutput("clusteredHeatmapOneSignature",
width = "1250px", height = "450px", containment = TRUE
width = "1250px", height = "450px", containment = TRUE
)
)
),
Expand Down Expand Up @@ -726,7 +729,7 @@ DeconvExplorer <- function(deconvexp_bulk = NULL,
column(
width = 7,
sliderInput("refinePercentZero", "Maximum percentage of zeroes allowed for each gene",
min = 0, max = 100, value = 90, step = 1, post = "%"
min = 0, max = 100, value = 90, step = 1, post = "%"
)
),
column(
Expand Down Expand Up @@ -760,7 +763,7 @@ DeconvExplorer <- function(deconvexp_bulk = NULL,
)
)

refUnspecificPopover <-
refUnspecificPopover <-
shinyBS::bsPopover(
id = "refUnspecificQ",
title = "",
Expand Down Expand Up @@ -818,8 +821,8 @@ refUnspecificPopover <-
shinyBS::bsPopover(
id = "refManuallyQ",
title = "",
content =
)
content =
)

# Info Boxes --------------------------------------------------------------
info_overview <- shinydashboard::box(
Expand Down Expand Up @@ -1662,7 +1665,7 @@ refUnspecificPopover <-
scoring_method = input$signatureAnnotationScore,
annotation_type = input$signatureAnnotationPlotType,
color_palette = input$globalColor,
order_rows = input$clusterCelltypes,
order_rows = input$clusterCelltypes,
order_columns = input$clusterGenes
),
"clusteredHeatmapOneSignature",
Expand Down
15 changes: 6 additions & 9 deletions R/SignatureExplorationPlots.R
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ plot_meanEntropyPerMethod <- function(signature_list,
#' @param scoring_method The score used to annotate the genes (entropy, gini)
#' @param annotation_type How the score is rendered (line, bar)
#' @param order_rows Either 'cluster' to order cell types by similarity or 'no_cluster' to order alphabetically
#' @param order_columns Character, either 'z-score cutoff', 'hierarchical clustering' or 'alphabetical'
#' @param order_columns Character, either 'z-score cutoff', 'hierarchical clustering' or 'alphabetical'
#' @param threshold the threshold for the z-scored expression in the signature matrix to consider
#' a gene as being differentially expressed. Default: 1.5
#'
Expand Down Expand Up @@ -254,22 +254,19 @@ plot_signatureClustered <- function(signature_mat,
cell.types.ordered <- order(colnames(mat))
}

if(order_columns == 'z-score cutoff'){
if (order_columns == "z-score cutoff") {
genes <- c()
for (c in cell.types.ordered) {
highly.expr.genes <- names(which(mat[, c] > threshold))
genes <- union(genes, highly.expr.genes)
}

genes <- union(genes, rownames(mat))
}else if(order_columns == 'hierarchical clustering'){

} else if (order_columns == "hierarchical clustering") {
# use hierarchical ward D2 clustering based on euclidean distance
clustering <- hclust(dist(mat), method = 'ward.D2')
clustering <- hclust(dist(mat), method = "ward.D2")
genes <- rownames(mat)[clustering$order]

}else if(order_columns == 'alphabetical'){

} else if (order_columns == "alphabetical") {
genes <- sort(rownames(mat))
}

Expand Down
14 changes: 7 additions & 7 deletions R/SignatureRefinements.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,26 @@ removeUnspecificGenes <- function(signature_mat,

signature_mat <- as.matrix(signature_mat)

to_keep <- sapply(1:nrow(signature_mat), function(i){
to_keep <- sapply(1:nrow(signature_mat), function(i) {
row <- signature_mat[i, ] # has colnames! drop FALSE is mandatory !!!!!

# calculate bins to prevent error
breaks <- seq(floor(min(row)), ceiling(max(row)), length.out = number_of_bins + 1)

# cut into bins, seperate for each gene
bins <- cut(row, breaks = breaks, labels = labels, include.lowest = TRUE)

nHighBins <- sum(bins == "high") # not working when labels is something else

# this value needs to be greater than one, depending of the step in the pipeline there arent
# any rows producing zeros left but that is not the case for all signatures
if (nHighBins <= max_count & nHighBins > 0) {
return(TRUE)
}else{
} else {
return(FALSE)
}
})


refinedSignature <- signature_mat[to_keep, ]

Expand Down

0 comments on commit 7562bb4

Please sign in to comment.