Prune a network by upstream and downstream nodes
prune_network(network, upstream_nodes, downstream_nodes)
A dataframe with three columns: source, target, and sign.
A character vector of upstream node names.
A character vector of downstream node names.
A dataframe of the pruned network with three columns: source, target, and sign.
This function takes a network in dataframe format with three columns (source, target, and interaction), a set of upstream nodes, and a set of downstream nodes. It returns a pruned network containing only nodes that can be reached downstream of the upstream set of nodes and upstream of the downstream set of nodes.
# Sample network data
network_data <- data.frame(
source = c("A", "A", "B", "B", "C", "D", "E"),
target = c("B", "C", "C", "D", "E", "F", "F"),
interaction = c(1, -1, 1, -1, 1, 1, -1)
)
# Upstream and downstream node sets
upstream_nodes <- c("A", "B")
downstream_nodes <- c("E", "F")
# Prune the network
pruned_network <- prune_network(network_data, upstream_nodes, downstream_nodes)
print(pruned_network)
#> source target interaction
#> 1 A B 1
#> 2 A C -1
#> 3 B C 1
#> 4 B D -1
#> 5 C E 1
#> 6 D F 1
#> 7 E F -1