|
86 | 86 | #' Filter groupComparison result input based on user-defined cutoffs |
87 | 87 | #' @param input groupComparison result |
88 | 88 | #' @param pvalueCutoff p-value cutoff |
| 89 | +#' @param logfc_cutoff logFC cutoff |
| 90 | +#' @param force_include_proteins list of proteins to exempt from filtering |
89 | 91 | #' @return filtered groupComparison result |
90 | 92 | #' @keywords internal |
91 | 93 | #' @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 |
93 | 109 | input <- input[!is.na(input$adj.pvalue),] |
94 | 110 | if (!is.null(pvalueCutoff)) { |
95 | 111 | input <- input[input$adj.pvalue < pvalueCutoff, ] |
96 | 112 | } |
| 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 | + } |
97 | 119 | 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 | + |
98 | 128 | input$Protein <- as.character(input$Protein) |
99 | 129 | return(input) |
100 | 130 | } |
101 | | - |
102 | 131 | #' Add additional metadata to an edge |
103 | 132 | #' @param edge object representation of an INDRA statement |
104 | 133 | #' @param input filtered groupComparison result |
|
0 commit comments