Skip to content

Commit

Permalink
fix plots for compound feature names
Browse files Browse the repository at this point in the history
  • Loading branch information
ivokwee committed Aug 9, 2024
1 parent 16e7fdb commit 6f801a7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
5 changes: 3 additions & 2 deletions components/board.dataview/R/dataview_plot_averagerank.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ dataview_plot_averagerank_server <- function(id,
nsamples <- length(samples)

if (data_type %in% c("counts", "abundance")) {
mean.fc <- sort(rowMeans(pgx$counts[, samples, drop = FALSE], na.rm = TRUE), decreasing = TRUE)
mean.fc <- sort(rowMeans(pgx$counts[, samples, drop = FALSE], na.rm = TRUE),
decreasing = TRUE)
ylab <- tspan("Counts", js = FALSE)
}
if (data_type %in% c("logCPM", "log2")) {
Expand Down Expand Up @@ -155,7 +156,7 @@ dataview_plot_averagerank_server <- function(id,
plotly::add_annotations(
x = sel,
y = mean.fc[sel],
ax = 20,
ax = ifelse(sel < length(mean.fc)/2, 40, -40),
ay = -40,
text = gene
)
Expand Down
19 changes: 9 additions & 10 deletions components/board.dataview/R/dataview_plot_correlation.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ dataview_plot_correlation_server <- function(id,
r.samples = reactive(NULL),
watermark = FALSE) {
moduleServer(id, function(input, output, session) {
getTopCorrelatedGenes <- function(pgx, gene, n = 30, samples = NULL) {
samples <- r.samples()
gene <- r.gene()

getTopCorrelatedGenes <- function(pgx, gene, n, samples) {

## precompute
if (is.null(samples)) samples <- colnames(pgx$X)
Expand All @@ -53,15 +52,15 @@ dataview_plot_correlation_server <- function(id,
}

samples <- intersect(samples, colnames(pgx$X))
pp <- rownames(pgx$genes)[match(gene, pgx$genes$gene_name)]

probe <- gene
## corr always in log.scale and restricted to selected samples subset
## should match exactly the rawtable!!
if (pp %in% rownames(pgx$X)) {
rho <- cor(t(pgx$X[, samples]), pgx$X[pp, samples], use = "pairwise")[, 1]
} else if (pp %in% rownames(pgx$counts)) {
if (probe %in% rownames(pgx$X)) {
rho <- cor(t(pgx$X[, samples]), pgx$X[probe, samples], use = "pairwise")[, 1]
} else if (probe %in% rownames(pgx$counts)) {
x0 <- playbase::logCPM(pgx$counts[, samples])
x1 <- x0[pp, ]
x1 <- x0[probe, ]
rho <- cor(t(x0), x1, use = "pairwise")[, 1]
} else {
rho <- rep(0, nrow(pgx$genes))
Expand Down Expand Up @@ -175,7 +174,7 @@ dataview_plot_correlation_server <- function(id,
df <- pd[[1]]
df$genes <- factor(df$genes, levels = df$genes)
df$gene_title <- stringr::str_extract(df$annot, "(?<=gene_title: <b>)[^<]+")
df$gene_name <- stringr::str_extract(df$annot, "(?<=gene_name: <b>)[^<]+")
df$gene_name <- stringr::str_extract(df$annot, "(?<=gene_name: <b>)[^<]+")
df$color <- NULL
df$annot <- NULL
return(df)
Expand Down
15 changes: 7 additions & 8 deletions components/board.dataview/R/dataview_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,9 @@ DataViewBoard <- function(id, pgx) {
## ========================= FUNCTIONS ============================================
## ================================================================================

getCountStatistics <- reactiveVal()

observeEvent(
## getCountStatistics <- reactiveVal()
## observeEvent(
getCountStatistics <- eventReactive(
{
list(
pgx$X,
Expand Down Expand Up @@ -327,7 +327,7 @@ DataViewBoard <- function(id, pgx) {
colnames(counts) <- substring(colnames(counts), 1, 24)

gset <- list()
gg <- pgx$genes[rownames(counts), ]$gene_name
gg <- pgx$genes[rownames(counts), ]$symbol
tt <- pgx$genes[rownames(counts), ]$gene_title
g1 <- gg[grep("^rpl|^rps", gg, ignore.case = TRUE)]
g2 <- gg[grep("^mrpl|^mrps", gg, ignore.case = TRUE)]
Expand Down Expand Up @@ -389,10 +389,9 @@ DataViewBoard <- function(id, pgx) {
prop.counts = prop.counts,
gset.genes = gset.genes
)
getCountStatistics(res)
},
ignoreNULL = TRUE
)
##getCountStatistics(res)
return(res)
}, ignoreNULL = TRUE)

## ================================================================================
## ================================= END ====================================
Expand Down

0 comments on commit 6f801a7

Please sign in to comment.