fg_add_summary: Adds a feature summary.

View source: R/01_flowgraph_modifiers.R

fg_add_summaryR Documentation

Adds a feature summary.

Description

Adds a feature summary into a given flowGraph object. Only use this function if your summary statistic cannot be calcuated using the fg_summary function.

Usage

fg_add_summary(
  fg,
  type = "node",
  summary_meta = NULL,
  p = NULL,
  summ_fun = NULL,
  overwrite = FALSE,
  ...
)

Arguments

fg

flowGraph object.

type

A string indicating feature type the summary was created for; 'node' or 'edge'.

summary_meta

The user must provide type and summary_meta.

summary_meta is a list containing feature (feature name), test_name (summary statistic name), class (class), label1, and label2 (class labels compared). See fg_get_summary_desc for details.

p

A list containing summary values; this list contains elements: values (a vector containing summary statistics e.g. p-values; this vector should be named by their associated phenotype or edge name), test_custom (a function of the statistical test used), and adjust_custom (a function of the p-value correction method used). This list must contain the values element.

summ_fun

A function that ouputs a feature summary matrix as in p given fg and other optional parameters.

overwrite

A logical variable indicating whether or not the function should replace the existing feature summary with the same name if one is already in fg.

...

Other parameters that would be used as input into summ_fun.

Details

fg_add_summary adds the given feature summary list p or the output of the given function summ_fun to the given flowGraph object fg updating slots summary and summary_desc. See flowGraph-class slot summary and summary_desc for what should be in these slots. We do not recommend users directly use this function unless what is required is duly in the above slots is well understood — note these slots are used in plotting functions e.g. fg_plot. We instead recommend users to use the fg_summary function.

Value

flowGraph object.

See Also

flowGraph-class fg_summary fg_get_summary fg_rm_summary fg_get_summary_desc fg_add_feature

Examples


 no_cores <- 1
 data(fg_data_pos30)
 fg <- flowGraph(fg_data_pos30$count, class=fg_data_pos30$meta$class,
                 no_cores=no_cores)

 # get samples that we are going to compare
 m <- fg_get_feature(fg, type="node", feature="prop")
 m1_ <- m[fg_data_pos30$meta$class=="control",,drop=FALSE]
 m2_ <- m[fg_data_pos30$meta$class=="exp",,drop=FALSE]

 # define test or summary function to conduct comparison
 test_custom <- function(x,y)
     tryCatch(stats::t.test(x,y)$p.value, error=function(e) 1)
 values_p <- sapply(seq_len(ncol(m)), function(j)
     test_custom(m1_[,j], m2_[,j]) )
 values_p <- p.adjust(values_p , method="BY")

 # the user can choose to fill either parameter "p" or "summ_fun",
 # the latter of which must output a list with the same elements as "p".
 # see documentation for ?flowGraph-class, slot "summary" for
 # details on what should be in "p".
 p <- list(values=values_p, test_fun=test_custom, adjust_fun="BY")
 fg <- fg_add_summary(fg, type="node", summary_meta=list(
      feature="prop", test_name="wilcox_BY",
      class="class", label1="control", label2="exp"), p=p)

 fg_get_summary_desc(fg)



aya49/flowGraph documentation built on Feb. 4, 2024, 6:40 p.m.