From 2ad365322efe158bda79f7ad3781b23d31b1fd39 Mon Sep 17 00:00:00 2001 From: Tony Wu Date: Tue, 22 Oct 2024 16:29:32 +0200 Subject: [PATCH] refactor(collapse-edges): Refactor how edges are collapsed to remove clutter --- R/utils_getSubnetworkFromIndra.R | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/R/utils_getSubnetworkFromIndra.R b/R/utils_getSubnetworkFromIndra.R index 36c8985..ad8198b 100644 --- a/R/utils_getSubnetworkFromIndra.R +++ b/R/utils_getSubnetworkFromIndra.R @@ -48,8 +48,7 @@ edge$evidence_list <- paste( "https://db.indra.bio/statements/from_agents?subject=", edge$source_id, "@HGNC&object=", - edge$target_id, "@HGNC&type=", - edge$data$stmt_type, "&format=html", + edge$target_id, "&format=html", sep = "" ) edge$source_uniprot_id <- input[input$HgncId == edge$source_id, ]$Protein @@ -69,18 +68,26 @@ edgeToMetadataMapping <- hashmap() for (edge in res) { - key <- paste(edge$source_id, edge$target_id, edge$data$stmt_type, - sep = "_" - ) + key <- paste(edge$source_id, edge$target_id, sep = "_") if (key %in% keys(edgeToMetadataMapping)) { edgeToMetadataMapping[[key]]$data$evidence_count <- edgeToMetadataMapping[[key]]$data$evidence_count + edge$data$evidence_count + edgeToMetadataMapping[[key]]$data$stmt_type <- c( + edgeToMetadataMapping[[key]]$data$stmt_type, + edge$data$stmt_type) } else { edge <- .addAdditionalMetadataToIndraEdge(edge, input) edgeToMetadataMapping[[key]] <- edge } } + + for (key in keys(edgeToMetadataMapping)) { + edgeToMetadataMapping[[key]]$data$stmt_type <- + unique(edgeToMetadataMapping[[key]]$data$stmt_type) + edgeToMetadataMapping[[key]]$data$stmt_type <- + paste(edgeToMetadataMapping[[key]]$data$stmt_type, collapse = ", ") + } return(edgeToMetadataMapping) }