Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 11 additions & 2 deletions R/getSubnetworkFromIndra.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
#' @param filter_by_ptm_site logical, whether to filter edges based on whether the
#' site information from INDRA matches with the PTM site in the input. Default is FALSE.
#' Only applicable for differential PTM abundance results.
#' @param include_infinite_fc logical, whether to include proteins with
#' infinite log fold change (i.e. proteins that are only detected in one condition).
#' Default is FALSE.
#' @param direction Character string specifying the direction of regulation to
#' include. One of \code{"both"} (default), \code{"up"} (upregulated only),
#' or \code{"down"} (downregulated only).
#'
#' @return list of 2 data.frames, nodes and edges
#'
Expand All @@ -60,8 +66,11 @@ getSubnetworkFromIndra <- function(input,
logfc_cutoff = NULL,
force_include_other = NULL,
filter_by_curation = FALSE,
filter_by_ptm_site = FALSE) {
input <- .filterGetSubnetworkFromIndraInput(input, pvalueCutoff, logfc_cutoff, force_include_other)
filter_by_ptm_site = FALSE,
include_infinite_fc = FALSE,
direction = c("both", "up", "down")) {
direction = match.arg(direction)
input <- .filterGetSubnetworkFromIndraInput(input, pvalueCutoff, logfc_cutoff, force_include_other, include_infinite_fc, direction)
.validateGetSubnetworkFromIndraInput(input, protein_level_data, sources_filter, force_include_other)
res <- .callIndraCogexApi(input$HgncId, force_include_other)
res <- .filterIndraResponse(res, statement_types, evidence_count_cutoff, sources_filter)
Expand Down
10 changes: 9 additions & 1 deletion R/utils_cytoscapeNetwork.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@
return(rep("#D3D3D3", length(logFC_values)))
}

is_pos_inf <- is.infinite(logFC_values) & logFC_values > 0
is_neg_inf <- is.infinite(logFC_values) & logFC_values < 0

finite_values <- logFC_values[is.finite(logFC_values)]
default_max <- 2
max_logFC <- max(c(abs(logFC_values), default_max), na.rm = TRUE)
max_logFC <- max(c(abs(finite_values), default_max), na.rm = TRUE)
min_logFC <- -max_logFC

logFC_values[is_pos_inf] <- max_logFC
logFC_values[is_neg_inf] <- min_logFC

color_map <- grDevices::colorRamp(colors)
normalized <- (logFC_values - min_logFC) / (max_logFC - min_logFC)
normalized[is.na(normalized)] <- 0.5
Expand Down
32 changes: 28 additions & 4 deletions R/utils_getSubnetworkFromIndra.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,21 @@
#' @param pvalueCutoff p-value cutoff
#' @param logfc_cutoff logFC cutoff
#' @param force_include_other list of identifiers to exempt from filtering
#' @param include_infinite_fc logical, whether to include proteins with
#' infinite log fold change (i.e. proteins that are only detected in one condition).
#' Default is FALSE.
#' @param direction Character string specifying the direction of regulation to
#' include. One of \code{"both"} (default), \code{"up"} (upregulated only),
#' or \code{"down"} (downregulated only).
#' @return filtered groupComparison result
#' @keywords internal
#' @noRd
.filterGetSubnetworkFromIndraInput <- function(input, pvalueCutoff, logfc_cutoff, force_include_other) {
.filterGetSubnetworkFromIndraInput <- function(input,
pvalueCutoff,
logfc_cutoff,
force_include_other,
include_infinite_fc,
direction) {
input$Protein <- as.character(input$Protein)

# Extract exempt proteins before any filtering
Expand All @@ -152,7 +163,11 @@
}
}

# Apply standard filtering
infinite_fc_proteins <- NULL
if (include_infinite_fc) {
infinite_fc_proteins <- input[is.infinite(input$log2FC), ]
}

input <- input[!is.na(input$adj.pvalue),]
if (!is.null(pvalueCutoff)) {
input <- input[input$adj.pvalue < pvalueCutoff, ]
Expand All @@ -163,8 +178,16 @@
}
input <- input[!is.na(input$log2FC) & abs(input$log2FC) > logfc_cutoff, ]
}
if ("issue" %in% colnames(input)) {
input <- input[is.na(input$issue), ]

if (!is.null(infinite_fc_proteins) && nrow(infinite_fc_proteins) > 0) {
combined_input <- rbind(infinite_fc_proteins, input)
input <- combined_input[!duplicated(combined_input$Protein), ]
}

if (direction == "up") {
input <- input[!is.na(input$log2FC) & input$log2FC > 0, ]
} else if (direction == "down") {
input <- input[!is.na(input$log2FC) & input$log2FC < 0, ]
}

# Combine filtered data with exempt proteins and remove duplicates
Expand All @@ -186,6 +209,7 @@
}
return(input)
}

#' Add additional metadata to an edge
#' @param edge object representation of an INDRA statement
#' @param input filtered groupComparison result
Expand Down
12 changes: 11 additions & 1 deletion man/getSubnetworkFromIndra.Rd

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

6 changes: 6 additions & 0 deletions tests/testthat/test-utils_cytoscapeNetwork.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ test_that(".mapLogFCToColor handles empty input", {
expect_length(colors, 0)
})

test_that(".mapLogFCToColor handles Inf and -Inf values", {
colors <- MSstatsBioNet:::.mapLogFCToColor(c(-Inf, 0, Inf))
expect_length(colors, 3)
expect_true(all(grepl("^#[0-9A-Fa-f]{6}$", colors)))
})

# =============================================================================
# .relProps
# =============================================================================
Expand Down
Loading