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
14 changes: 9 additions & 5 deletions R/getSubnetworkFromIndra.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
#' as "namespace:identifier", e.g. "HGNC:1234" or "CHEBI:4911".
#' @param filter_by_curation logical, whether to filter out statements that
#' have been curated as incorrect in INDRA. Default is FALSE.
#' @param api_key string of INDRA API key for accessing curated statements.
#' @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.
#'
#' @return list of 2 data.frames, nodes and edges
#'
Expand All @@ -57,21 +59,23 @@ getSubnetworkFromIndra <- function(input,
sources_filter = NULL,
logfc_cutoff = NULL,
force_include_other = NULL,
filter_by_curation = FALSE,
api_key = "") {
filter_by_curation = FALSE,
filter_by_ptm_site = FALSE) {
Comment thread
tonywu1999 marked this conversation as resolved.
input <- .filterGetSubnetworkFromIndraInput(input, pvalueCutoff, logfc_cutoff, force_include_other)
.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, filter_by_curation, api_key)
res <- .filterIndraResponse(res, statement_types, evidence_count_cutoff, sources_filter)
Comment thread
tonywu1999 marked this conversation as resolved.
edges <- .constructEdgesDataFrame(res, input, protein_level_data)
edges <- .filterEdgesDataFrame(edges, paper_count_cutoff, correlation_cutoff)
nodes <- .constructNodesDataFrame(input, edges)
subnetwork = .filterByPtmSite(nodes, edges, filter_by_ptm_site)
subnetwork = .filterByCuration(subnetwork$nodes, subnetwork$edges, evidence_count_cutoff, filter_by_curation)
warning(
"NOTICE: This function includes third-party software components
that are licensed under the BSD 2-Clause License. Please ensure to
include the third-party licensing agreements if redistributing this
package or utilizing the results based on this package.
See the LICENSE file for more details."
)
return(list(nodes = nodes, edges = edges))
return(subnetwork)
}
52 changes: 32 additions & 20 deletions R/utils_getSubnetworkFromIndra.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@

#' @importFrom httr GET status_code content
#' @importFrom jsonlite fromJSON
.get_incorrect_curation_count <- function(stmt_hash, api_key) {
.get_incorrect_curation_count <- function(stmt_hash) {
stmt_hash_char <- as.character(stmt_hash)
url <- paste0("https://db.indra.bio/curation/list/", stmt_hash_char, "?api_key=", api_key)
url <- paste0("https://db.indra.bio/curation/list/", stmt_hash_char)

tryCatch({
response <- GET(url)
Expand All @@ -96,21 +96,18 @@

#' Call INDRA Cogex API and return response
#' @param res response from INDRA
#' @param interaction_types interaction types to filter by
#' @param statement_types interaction types to filter by
#' @param evidence_count_cutoff number of evidence to filter on for each paper
#' @param sources_filter list of sources to filter by. Default is NULL, i.e. no filter
#' @param filter_by_curation logical, whether to filter out statements that
#' have been curated as incorrect in INDRA. Default is FALSE.
#' @param api_key string of INDRA API key for accessing curated statements.
#' @return filtered list of INDRA statements
#' @importFrom jsonlite fromJSON
#' @keywords internal
#' @noRd
.filterIndraResponse <- function(res, interaction_types, evidence_count_cutoff,
sources_filter = NULL, filter_by_curation = FALSE, api_key = "") {
if (!is.null(interaction_types)) {
.filterIndraResponse <- function(res, statement_types, evidence_count_cutoff,
sources_filter = NULL) {
if (!is.null(statement_types)) {
res = Filter(
function(statement) statement$data$stmt_type %in% interaction_types,
function(statement) statement$data$stmt_type %in% statement_types,
res)
}
if (!is.null(sources_filter)) {
Expand All @@ -123,16 +120,6 @@
res
)
}
if (filter_by_curation) {
for (i in seq_along(res)) {
stmt_json <- fromJSON(res[[i]]$data$stmt_json)
stmt_hash <- stmt_json$matches_hash
incorrect_count <- .get_incorrect_curation_count(stmt_hash, api_key)
res[[i]]$data$evidence_count <- res[[i]]$data$evidence_count - incorrect_count
# Todo: Also subtract source_counts accordingly if requested
Sys.sleep(0.1)
}
}
res = Filter(
function(statement) statement$data$evidence_count >= evidence_count_cutoff,
res
Expand Down Expand Up @@ -373,6 +360,31 @@
return(edges)
}

.filterByCuration = function(nodes, edges, evidence_count_cutoff, filter_by_curation) {
if (filter_by_curation) {
incorrect_counts <- numeric(nrow(edges))
for (i in seq_len(nrow(edges))) {
incorrect_counts[i] <- .get_incorrect_curation_count(edges$stmt_hash[i])
Sys.sleep(0.1)
}
edges$evidenceCount <- edges$evidenceCount - incorrect_counts
edges <- edges[edges$evidenceCount >= evidence_count_cutoff, ]
nodes <- nodes[nodes$id %in% c(edges$source, edges$target), ]
}
return(list(nodes = nodes, edges = edges))
}

.filterByPtmSite = function(nodes, edges, filter_by_ptm_site) {
if (filter_by_ptm_site && nrow(nodes[!is.na(nodes$Site), ]) > 0) {
ptm_overlap <- .calculatePTMOverlapAggregated(edges, nodes)
keep <- ptm_overlap[paste(edges$source, edges$target, edges$interaction, sep = "-")]
edges <- edges[!is.na(keep) & keep != "", ]
edges <- edges[!is.na(edges$site),]
nodes <- nodes[nodes$id %in% c(edges$source, edges$target), ]
}
return(list(nodes = nodes, edges = edges))
}
Comment thread
tonywu1999 marked this conversation as resolved.

#' Construct correlation matrix from MSstats
#' @param protein_level_data output of dataProcess
#' @importFrom tidyr pivot_wider
Expand Down
6 changes: 4 additions & 2 deletions R/visualizeNetworksWithHTML.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ getRelationshipProperties <- function() {
#' @param edges Data frame with edge information including 'target' and 'site' columns
#' @param nodes Data frame with node information including 'id' and 'Site' columns
#' @return Vector of overlap descriptions for each unique edge (after consolidation)
#' @keywords internal
#' @noRd
calculatePTMOverlapAggregated <- function(edges, nodes) {
.calculatePTMOverlapAggregated <- function(edges, nodes) {
if (nrow(edges) == 0) return(character(0))

# Group edges by source-target-interaction to match consolidation logic
Expand Down Expand Up @@ -153,7 +154,7 @@ consolidateEdges <- function(edges, nodes = NULL) {

# Calculate aggregated PTM overlap information if nodes are provided
ptm_overlap_map <- if (!is.null(nodes)) {
calculatePTMOverlapAggregated(edges, nodes)
.calculatePTMOverlapAggregated(edges, nodes)
} else {
NULL
}
Expand Down Expand Up @@ -1141,6 +1142,7 @@ createEdgeClickHandler <- function() {
#' @param edges Data frame with edge information
#' @param filename Output HTML filename
#' @param displayLabelType Type of label to display ("id" or "hgncName")
#' @param nodeFontSize Font size for node labels (default: 12)
#' @param ... Additional arguments passed to exportCytoscapeToHTML()
#' @export
#' @return Invisibly returns the file path of the created HTML file
Expand Down
3 changes: 3 additions & 0 deletions man/exportNetworkToHTML.Rd

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

3 changes: 2 additions & 1 deletion man/generateCytoscapeConfig.Rd

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

6 changes: 4 additions & 2 deletions man/getSubnetworkFromIndra.Rd

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

8 changes: 7 additions & 1 deletion man/previewNetworkInBrowser.Rd

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

Loading