Skip to content

Commit

Permalink
Merge pull request #26 from SysBioChalmers/dev
Browse files Browse the repository at this point in the history
feat: add some description
  • Loading branch information
hongzhonglu authored Apr 25, 2019
2 parents e8baad2 + 41c3755 commit ed57a32
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 33 deletions.
85 changes: 52 additions & 33 deletions R/visualization_using_R.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,36 @@
#------------------------------------------------------------------
# visualization using R platform
#------------------------------------------------------------------
# function to define the node in a R graph
#' function to define the node in a R graph
#'
#'
#' @param rxn_core_carbon_inf a dataframe contains the detailed annotation of rxn_core
#' @param currency_metabolites_inf a vector of currency metabolites
#'
#' @return
#' @export node_all a dataframe contains the node information for a R graph
#'
#' @examples
creatRnode <- function(rxn_core_carbon_inf, currency_metabolites_inf){
#input
#rxn_core_carbon_inf a dataframe contains the detailed annotation of rxn_core
#currency_metabolites_inf a vector of currency metabolites
#output
#node_all a dataframe contains the node information for a R graph


rxn_core_carbon_inf$rxnID <- str_replace_all(rxn_core_carbon_inf$rxnID, "r_", "R_")
# analysis the metabolite and remove these currency metabolites
# choose the rxn based met
# choose the rxn based met
met_analysis <- rxn_core_carbon_inf %>%
count(name) %>%
arrange(., desc(n))
arrange(., desc(n))
#currency_metabolite_R_map <- c("h", "h2o", "atp", "pi", "adp", "nadp", "nadph", "nad", "nadh", "ppi", "amp" )
met_analysis$name_no_compartment <- str_replace_all(met_analysis$name, "\\[.*?\\]", "")
met_analysis$currency_sign <- met_analysis$name_no_compartment %in% currency_metabolites_inf
met_analysis <- filter(met_analysis, currency_sign==FALSE)


# define the node
label_all <- unique(c(rxn_core_carbon_inf$rxnID, met_analysis$name))
id_all <- 1:length(label_all)

node_all <- data.frame(id=id_all, label=label_all, stringsAsFactors = FALSE)

from0 <- vector()
to0 <- vector()
for (i in seq_along(rxn_core_carbon_inf$rxnID)){
Expand All @@ -40,19 +44,27 @@ creatRnode <- function(rxn_core_carbon_inf, currency_metabolites_inf){
to0[i] <- rxn_core_carbon_inf$name[i]
}
}

return(node_all)

}

# function to define the edge



#' function to define the edge
#'
#'
#' @param rxn_core_carbon_inf a dataframe contains the detailed annotation of rxn_core
#' @param rxn_rev_list a vector contains the reversible reactions
#' @param node_inf a dataframe contains the node definition for a R graph
#'
#' @return
#' @export edge4 a dataframe defines the edge between the nodes
#'
#' @examples
creatRedge <- function(rxn_core_carbon_inf, rxn_rev_list, node_inf){
#input
#rxn_core_carbon_inf a dataframe contains the detailed annotation of rxn_core
#rxn_rev_list, a vector contains the reversible reactions
#node_inf, a dataframe contains the node definition for a R graph
#output
#edge4, a dataframe defines the edge between the nodes

rxn_core_carbon_inf$rxnID <- str_replace_all(rxn_core_carbon_inf$rxnID, "r_", "R_")
from0 <- vector()
to0 <- vector()
Expand All @@ -66,9 +78,9 @@ creatRedge <- function(rxn_core_carbon_inf, rxn_rev_list, node_inf){
to0[i] <- rxn_core_carbon_inf$name[i]
}
}

edge0 <- data.frame(from1 = from0, to1 = to0, stringsAsFactors = FALSE)

# add the reversiblity reaction
rxn_rev <- rxn_rev_list
edge0$rev_sign1 <- edge0$from1 %in% rxn_rev
Expand All @@ -78,25 +90,32 @@ creatRedge <- function(rxn_core_carbon_inf, rxn_rev_list, node_inf){
edge2_n <- edge2_o
edge2_n$from1 <- edge2_o$to1
edge2_n$to1 <- edge2_o$from1

edge3 <- rbind.data.frame(edge0[,1:2], edge2_n)
edge3$from <- getSingleReactionFormula(node_inf$id,node_inf$label,edge3$from1)
edge3$to <- getSingleReactionFormula(node_inf$id,node_inf$label,edge3$to1)

edge_all <- edge3[,c('from','to')]
edge_all$from <- as.numeric(edge_all$from)
edge_all$to <- as.numeric(edge_all$to)
return(edge_all)
}

# function to creat the R graph based on the R platform



#' function to creat the R graph based on the R platform
#'
#'
#' @param nodes a dataframe contains the id and label information of each node
#' @param edges a dataframe defining the connection of the metabolite
#'
#' @return
#' @export i_graph_x3 a graph format in R
#'
#' @examples
creatRmap <- function (nodes, edges){
# input
# nodes, a dataframe contains the id and label information of each node
# edges, a dataframe defining the connection of the metabolite
# output
# i_graph_x3, a graph format in R


# Create the graph object
i_graph_x1 <-
create_graph()
Expand Down
18 changes: 18 additions & 0 deletions man/creatRedge.Rd

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

16 changes: 16 additions & 0 deletions man/creatRmap.Rd

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

16 changes: 16 additions & 0 deletions man/creatRnode.Rd

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

0 comments on commit ed57a32

Please sign in to comment.