Skip to content

Commit f491470

Browse files
authored
add logfc filter and filter exempt proteins filter (#49)
1 parent 49da40d commit f491470

3 files changed

Lines changed: 52 additions & 5 deletions

File tree

R/getSubnetworkFromIndra.R

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
#' 0.3
2525
#' @param sources_filter filtering only on specific sources. Default is no filter, i.e. NULL.
2626
#' Otherwise, should be a list, e.g. c('reach', 'medscan').
27+
#' @param logfc_cutoff absolute log fold change cutoff for filtering proteins.
28+
#' Only proteins with |logFC| greater than this value will be retained. Default
29+
#' is NULL, i.e. no logFC filtering.
30+
#' @param force_include_proteins character vector of protein identifiers to exempt
31+
#' from all filtering steps. These proteins will be retained regardless of p-value,
32+
#' logFC, or other filtering criteria. Default is NULL, i.e. no exemptions.
2733
#'
2834
#' @return list of 2 data.frames, nodes and edges
2935
#'
@@ -45,8 +51,10 @@ getSubnetworkFromIndra <- function(input,
4551
paper_count_cutoff = 1,
4652
evidence_count_cutoff = 1,
4753
correlation_cutoff = 0.3,
48-
sources_filter = NULL) {
49-
input <- .filterGetSubnetworkFromIndraInput(input, pvalueCutoff)
54+
sources_filter = NULL,
55+
logfc_cutoff = NULL,
56+
force_include_proteins = NULL) {
57+
input <- .filterGetSubnetworkFromIndraInput(input, pvalueCutoff, logfc_cutoff, force_include_proteins)
5058
.validateGetSubnetworkFromIndraInput(input, protein_level_data, sources_filter)
5159
res <- .callIndraCogexApi(input$HgncId)
5260
res <- .filterIndraResponse(res, statement_types, evidence_count_cutoff, sources_filter)

R/utils_getSubnetworkFromIndra.R

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,48 @@
8686
#' Filter groupComparison result input based on user-defined cutoffs
8787
#' @param input groupComparison result
8888
#' @param pvalueCutoff p-value cutoff
89+
#' @param logfc_cutoff logFC cutoff
90+
#' @param force_include_proteins list of proteins to exempt from filtering
8991
#' @return filtered groupComparison result
9092
#' @keywords internal
9193
#' @noRd
92-
.filterGetSubnetworkFromIndraInput <- function(input, pvalueCutoff) {
94+
.filterGetSubnetworkFromIndraInput <- function(input, pvalueCutoff, logfc_cutoff, force_include_proteins) {
95+
# Extract exempt proteins before any filtering
96+
exempt_proteins <- NULL
97+
if (!is.null(force_include_proteins)) {
98+
if (!is.character(force_include_proteins)) {
99+
stop("force_include_proteins must be a character vector")
100+
}
101+
missing_prots <- setdiff(force_include_proteins, input$Protein)
102+
if (length(missing_prots) > 0) {
103+
warning("force_include_proteins not found: ", paste(missing_prots, collapse = ", "))
104+
}
105+
exempt_proteins <- input[input$Protein %in% force_include_proteins,]
106+
}
107+
108+
# Apply standard filtering
93109
input <- input[!is.na(input$adj.pvalue),]
94110
if (!is.null(pvalueCutoff)) {
95111
input <- input[input$adj.pvalue < pvalueCutoff, ]
96112
}
113+
if (!is.null(logfc_cutoff)) {
114+
if (!is.numeric(logfc_cutoff) || length(logfc_cutoff) != 1 || logfc_cutoff <= 0) {
115+
stop("logfc_cutoff must be a single positive numeric value")
116+
}
117+
input <- input[!is.na(input$log2FC) & abs(input$log2FC) > logfc_cutoff, ]
118+
}
97119
input <- input[is.na(input$issue), ]
120+
121+
# Combine filtered data with exempt proteins and remove duplicates
122+
if (!is.null(exempt_proteins) && nrow(exempt_proteins) > 0) {
123+
combined_input <- rbind(exempt_proteins, input)
124+
# Remove duplicates based on Protein column, keeping first occurrence
125+
input <- combined_input[!duplicated(combined_input$Protein), ]
126+
}
127+
98128
input$Protein <- as.character(input$Protein)
99129
return(input)
100130
}
101-
102131
#' Add additional metadata to an edge
103132
#' @param edge object representation of an INDRA statement
104133
#' @param input filtered groupComparison result

man/getSubnetworkFromIndra.Rd

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)