Skip to content

Commit

Permalink
begin adding main functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
jhrcook committed Oct 13, 2019
1 parent c9cb86f commit 47591b0
Show file tree
Hide file tree
Showing 77 changed files with 2,996 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@
^appveyor\.yml$
^codecov\.yml$
^LICENSE\.md$
^data-raw$
^inst/extdata/output_simple$
^inst/extdata/output_consensus$
9 changes: 8 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ Suggests:
knitr,
rmarkdown,
covr,
spelling
spelling,
testthat (>= 2.1.0)
VignetteBuilder: knitr
RoxygenNote: 6.1.1
Language: en-US
Imports:
glue,
readr,
tibble,
dplyr,
rlang
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(conforms_to_delta_fileorg)
export(get_hn2_subnetworks)
importFrom(dplyr,"%>%")
importFrom(rlang,"!!")
32 changes: 32 additions & 0 deletions R/conforms_to_delta_fileorg.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#' Checks if a directory for a delta value conforms to the expected output
#'
#' Returns \code{TRUE} or \{FALSE} for whether a directory conforms to the
#' expected organization of the delta directory output by HotNet2.
#'
#' @param delta_dir The delta directory.
#'
#' @return A boolean value for wether the directory conforms to the expected file organization.
#'
#' @export conforms_to_delta_fileorg
conforms_to_delta_fileorg <- function(delta_dir) {

components_txt <- file.path(delta_dir, "components.txt")
if (!check_for_file(components_txt)) return(FALSE)

results_json <- file.path(delta_dir, "results.json")
if (!check_for_file(results_json)) return(FALSE)

significance_txt <- file.path(delta_dir, "significance.txt")
if (!check_for_file(significance_txt)) return(FALSE)

return(TRUE)
}


check_for_file <- function(fname) {
if (!file.exists(fname)) {
message(glue::glue("Expected file at {fname} is not available."))
return(FALSE)
}
return(TRUE)
}
33 changes: 33 additions & 0 deletions R/get_best_delta.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#' Finds the best delta for a the HotNet2 results
#'
#' Briefly, ... (explain how the best delta is chosen). More is explained in the
#' vignette "...".
#'
#' @param delta_tib A data frame (or tibble) with the columns ... for all of the delta values.
#' @param pval_cutoff The maximum p-value to use for statistical significance.
#'
#' @return The best delta value to use or \code{NA} if none can be used.
#'
#' @importFrom dplyr %>%
#' @importFrom rlang !!
get_best_delta <- function(delta_df, pval_cutoff = 0.05) {
delta_best <- delta_df %>%
dplyr::group_by(delta) %>%
dplyr::summarise(sig_ks = sum(pval < !!pval_cutoff)) %>%
dplyr::ungroup() %>%
dplyr::filter(sig_ks > 0) %>%
dplyr::arrange(dplyr::desc(sig_ks), delta) %>%
dplyr::slice(1) %>%
dplyr::pull(delta)
if (length(delta_best) > 0) {
return(delta_best)
} else {
# if no significant deltas
return(NA)
}
}

utils::globalVariables(
c("delta", "sig_ks", "pval"),
add = TRUE
)
24 changes: 24 additions & 0 deletions R/get_hn2_subnetworks.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#' Read in HotNet2 results
#'
#' Point this function at the output directory from HotNet2 and it will retrieve
#' the results from that analysis.
#'
#' @param output_dir The output directory from HotNet2.
#'
#' @return An S3 object with the parsed results from HotNet2.
#'
#' @export get_hn2_subnetworks
get_hn2_subnetworks <- function(output_dir) {

# check if the output directory exists
if (!dir.exists(output_dir)) {
stop(glue::glue("The directory {output_dir} is not accessible or does not exist."))
}







}
12 changes: 12 additions & 0 deletions R/get_k_for_delta.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#' Read in the "k" values for a delta directory
#'
#' @param delta_dir The direcotry for a delta value.
#'
#' @return A tibble with columns "size", "expected", "actual", and "pval".
get_k_for_delta <- function(delta_dir) {
sig_tib <- readr::read_tsv(
paste0(delta_dir, "/significance.txt"),
progress = FALSE, col_types = readr::cols())
colnames(sig_tib) <- c("size", "expected", "actual", "pval")
return(sig_tib)
}
1 change: 1 addition & 0 deletions docs/articles/index.html

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

140 changes: 140 additions & 0 deletions docs/articles/standard-use.html

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

3 changes: 1 addition & 2 deletions docs/pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pandoc: 2.7.3
pkgdown: 1.4.0
pkgdown_sha: ~
articles:
HotNet2-setup-and-example: HotNet2-setup-and-example.html
articles: []

Loading

0 comments on commit 47591b0

Please sign in to comment.