Skip to content
Snippets Groups Projects
Commit 0e0e8059 authored by Christian Hohenfeld's avatar Christian Hohenfeld
Browse files

Merge branch 'to_subgraph' into 'master'

Add function for creating subgraphs.

See merge request choh/rsanalysis!8
parents b6e5a682 67206617
No related branches found
No related tags found
No related merge requests found
Package: rsAnalysis Package: rsAnalysis
Title: High-Level Tools for rsfMRI analysis Title: High-Level Tools for rsfMRI analysis
Version: 0.4.1 Version: 0.4.2
Authors@R: Authors@R:
person(given = "Christian", person(given = "Christian",
family = "Hohenfeld", family = "Hohenfeld",
......
...@@ -25,6 +25,7 @@ export(remove_loops) ...@@ -25,6 +25,7 @@ export(remove_loops)
export(rs_pipeline) export(rs_pipeline)
export(single_component_threshold) export(single_component_threshold)
export(split_graph_list) export(split_graph_list)
export(to_subgraph)
importFrom(magrittr,"%>%") importFrom(magrittr,"%>%")
importFrom(rlang,":=") importFrom(rlang,":=")
importFrom(rlang,.data) importFrom(rlang,.data)
#' Take a list of graphs and return subgraphs.
#'
#' `to_subgraph` makes the assumption that all graphs share a common set of
#' nodes like it is common with graph analysis of the brain.
#'
#' @param graph_list A list of tbl_graphs
#' @param to_keep The names of the nodes to keep.
#'
#' @return A list of the graphs in `graph_list` reduced to the respective
#' subgraphs.
#' @export
to_subgraph <- function(graph_list, to_keep) {
all_nodes <- graph_list[[1]] %>%
tidygraph::activate("nodes") %>%
tibble::as_tibble() %>%
tibble::deframe()
to_remove_net <- all_nodes[!all_nodes %in% to_keep]
graph_list <- lapply(graph_list,
function(x) igraph::delete.vertices(x, to_remove_net))
graph_list <- lapply(graph_list, tidygraph::as_tbl_graph)
graph_list
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/to_subgraph.R
\name{to_subgraph}
\alias{to_subgraph}
\title{Take a list of graphs and return subgraphs.}
\usage{
to_subgraph(graph_list, to_keep)
}
\arguments{
\item{graph_list}{A list of tbl_graphs}
\item{to_keep}{The names of the nodes to keep.}
}
\value{
A list of the graphs in `graph_list` reduced to the respective
subgraphs.
}
\description{
`to_subgraph` makes the assumption that all graphs share a common set of
nodes like it is common with graph analysis of the brain.
}
describe("to_subgraph", {
data("graph_list")
it("creates a graph only containing the specified nodes", {
to_keep <- c("Precentral_L", "Precentral_R")
sub_list <- to_subgraph(graph_list, to_keep)
sub_order <- sapply(sub_list, igraph::gorder, USE.NAMES = FALSE)
expect_true(all(sub_order == length(to_keep)))
})
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment