Skip to content

Commit

Permalink
getter functions documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
noriakis committed Nov 19, 2023
1 parent e5299cc commit a4c0b5f
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 4 deletions.
17 changes: 16 additions & 1 deletion R/module_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,25 @@ setMethod("show",
}
)


#' get_module_attribute
#'
#' get slot from `kegg_module` class
#'
#' @param x kegg_module class object
#' @param attribute pass to get_module_attribute
#' @return attribute of kegg_module
#' @export
setGeneric("get_module_attribute",
function(x, ...) standardGeneric("get_module_attribute"))
function(x, attribute) standardGeneric("get_module_attribute"))

#' get_module_attribute
#'
#' get the kegg_module class attribute
#'
#' @param x kegg_module class object
#' @param attribute slot name
#' @return attribute of kegg_module
setMethod("get_module_attribute", "kegg_module",
function(x, attribute) attr(x, attribute))

Expand Down
16 changes: 15 additions & 1 deletion R/network_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,24 @@ setMethod("show",
}
)

#' get_network_attribute
#'
#' get slot from `kegg_network` class
#'
#' @param x kegg_network class object
#' @param attribute pass to get_network_attribute
#' @return attribute of kegg_network
#' @export
setGeneric("get_network_attribute",
function(x, ...) standardGeneric("get_network_attribute"))
function(x, attribute) standardGeneric("get_network_attribute"))

#' get_network_attribute
#'
#' get the kegg_network class attribute
#'
#' @param x kegg_network class object
#' @param attribute slot name
#' @return attribute of kegg_module
setMethod("get_network_attribute", "kegg_network",
function(x, attribute) attr(x, attribute))

Expand Down
13 changes: 12 additions & 1 deletion R/pathway_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,15 @@ process_line <- function(g, invert_y=TRUE, verbose=FALSE) {
#'
#' @param g graph
#' @param single_edge discard one edge when edge type is `reversible`
#' @param keep_no_reaction keep edges not related to reaction
#' @importFrom tidygraph bind_nodes bind_edges
#' @export
#' @return tbl_graph
#' @examples
#' gm_test <- create_test_pathway(line=TRUE)
#' test <- process_reaction(gm_test)
#'
process_reaction <- function(g, single_edge=FALSE) {
process_reaction <- function(g, single_edge=FALSE, keep_no_reaction=TRUE) {
## This is perhaps dirty ways to obtain edges. Perhaps directly
## parsing substrate -> product would be reasonable with
## assigning "reversible" and "irreversible"
Expand All @@ -366,6 +367,7 @@ process_reaction <- function(g, single_edge=FALSE) {

## Obtain raw edges
eds <- g |> activate("edges") |> data.frame()
no_reacs <- eds[is.na(eds$reaction_id),]
reacs <- eds$reaction_id |> unique()
reacs <- reacs[!is.na(reacs)]
## Prepare new edges
Expand Down Expand Up @@ -427,6 +429,15 @@ process_reaction <- function(g, single_edge=FALSE) {
new_eds <- new_eds[!duplicated(new_eds),]
new_eds$from <- as.integer(new_eds$from)
new_eds$to <- as.integer(new_eds$to)
if (keep_no_reaction) {
for (coln in colnames(no_reacs)) {
if (!coln %in% colnames(new_eds)) {
new_eds[[coln]] <- NA
}
}
new_eds <- new_eds[,colnames(no_reacs)]
new_eds <- rbind(no_reacs, new_eds)
}
new_g <- tbl_graph(nodes=nds, edges=new_eds)
new_g
}
Expand Down
19 changes: 19 additions & 0 deletions man/get_module_attribute-kegg_module-method.Rd

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

19 changes: 19 additions & 0 deletions man/get_module_attribute.Rd

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

19 changes: 19 additions & 0 deletions man/get_network_attribute-kegg_network-method.Rd

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

19 changes: 19 additions & 0 deletions man/get_network_attribute.Rd

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

4 changes: 3 additions & 1 deletion man/process_reaction.Rd

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

0 comments on commit a4c0b5f

Please sign in to comment.