Skip to content

Commit

Permalink
Update hush functions to work on windows; remove random phenotype exa…
Browse files Browse the repository at this point in the history
…mples to reduce computation time
  • Loading branch information
katelynqueen98 committed May 4, 2023
1 parent 5e82415 commit e81d840
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 139 deletions.
Binary file modified .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
^\.Rproj\.user$
^cran-comments\.md$
^revdep$
^CRAN-SUBMISSION$
3 changes: 3 additions & 0 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Version: 1.0.0
Date: 2023-05-03 18:27:23 UTC
SHA: 5e8241576dcf70e63d13d9c1004c7643edecef95
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Imports:
ggplot2,
partition,
doParallel,
parallel,
utils,
stats,
tidyr
Expand Down
18 changes: 10 additions & 8 deletions R/ACDC.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
#' @import CCP
#' @import utils
#' @import stats
#' @import tidyr
#' @import foreach
#' @import doParallel
#' @import parallel
ACDC <- function(fullData, ILC = 0.50, externalVar, identifierList = colnames(fullData), numNodes = 1) {

# to remove "no visible binding" note
Expand All @@ -62,7 +66,7 @@ ACDC <- function(fullData, ILC = 0.50, externalVar, identifierList = colnames(fu
## function to suppress output
# use for p.asym
hush = function(code){
sink("/dev/null")
sink(nullfile())
tmp = code
sink()
return(tmp)
Expand All @@ -78,6 +82,9 @@ ACDC <- function(fullData, ILC = 0.50, externalVar, identifierList = colnames(fu
if(ncol(fullData) != length(identifierList)) stop("identifierList must be the same length as the number of columns in fullData.")
if(0 > ILC | 1 < ILC) stop("ILC must be between 0 and 1.")

# iteration counter
i = 0

# partition and find modules
part <- partition(fullData, threshold = ILC)
modules <- part$mapping_key[which(grepl("reduced_var_", part$mapping_key$variable)), ]$indices
Expand All @@ -86,13 +93,8 @@ ACDC <- function(fullData, ILC = 0.50, externalVar, identifierList = colnames(fu
if(length(modules) == 0) stop("No modules identified. Try a smaller ILC.")

# parallel set up
my.cluster <- parallel::makeCluster(
numNodes,
type = "PSOCK")
doParallel::registerDoParallel(cl = my.cluster)

# iteration counter
i = 0
my.cluster <- parallel::makeCluster(numNodes)
doParallel::registerDoParallel(my.cluster)

# for each module...
results <- foreach (i = 1:length(modules),
Expand Down
13 changes: 2 additions & 11 deletions R/ACDChighdim.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,7 @@
#' # load dataset
#' data("nutrimouse")
#'
#' # generate random phenotype
#' r.pheno <- rnorm(nrow(nutrimouse$lipid))
#'
#' # run function for random phenotype
#' ACDChighdim(moduleIdentifier = 1,
#' moduleCols = list(1:ncol(nutrimouse$lipid)),
#' fullData = nutrimouse$lipid,
#' externalVar = r.pheno)
#'
#' # run function for diet and genotype (non-random)
#' # run function for diet and genotype
#' ACDChighdim(moduleIdentifier = 1,
#' moduleCols = list(1:ncol(nutrimouse$lipid)),
#' fullData = nutrimouse$lipid,
Expand Down Expand Up @@ -73,7 +64,7 @@ ACDChighdim <- function(moduleIdentifier = 1, moduleCols, fullData, externalVar,
## function to suppress output
# use for p.asym
hush = function(code){
sink("/dev/null")
sink(nullfile())
tmp = code
sink()
return(tmp)
Expand Down
26 changes: 8 additions & 18 deletions R/ACDCmod.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,12 @@
#' # load dataset
#' data("nutrimouse")
#'
#' # generate random phenotype
#' r.pheno <- rnorm(nrow(nutrimouse$lipid))
#'
#' # partition dataset and save modules
#' library(partition)
#' part <- partition(nutrimouse$lipid, threshold = 0.50)
#' mods <- part$mapping_key[which(grepl("reduced_var_", part$mapping_key$variable)), ]$mapping
#'
#' # run function for random phenotype
#' ACDCmod(fullData = nutrimouse$lipid,
#' modules=mods,
#' externalVar = r.pheno)
#'
#' # run function for diet and genotype (non-random)
#' # run function for diet and genotype
#' ACDCmod(fullData = nutrimouse$lipid,
#' modules = mods,
#' externalVar = data.frame(diet=as.numeric(nutrimouse$diet),
Expand Down Expand Up @@ -66,10 +58,10 @@
#' @import CCP
#' @import utils
#' @import stats
#' @import parallel
#' @import tidyr
#' @import foreach
#' @import doParallel
#' @import tidyr
#' @import parallel
ACDCmod <- function(fullData, modules, externalVar, identifierList=colnames(fullData), numNodes = 1) {

# to remove "no visible binding" note
Expand All @@ -78,7 +70,7 @@ ACDCmod <- function(fullData, modules, externalVar, identifierList=colnames(full
## function to suppress output
# use for p.asym
hush = function(code){
sink("/dev/null")
sink(nullfile())
tmp = code
sink()
return(tmp)
Expand All @@ -94,15 +86,13 @@ ACDCmod <- function(fullData, modules, externalVar, identifierList=colnames(full
if(ncol(fullData) != length(identifierList)) stop("identifierList must be the same length as the number of columns in fullData.")
if(length(modules) == 0) stop("No modules input.")

# parallel set up
my.cluster <- parallel::makeCluster(
numNodes,
type = "PSOCK")
doParallel::registerDoParallel(cl = my.cluster)

# iteration counter
i = 0

# parallel set up
my.cluster <- parallel::makeCluster(numNodes)
doParallel::registerDoParallel(my.cluster)

# for each module...
results <- foreach (i = 1:length(modules),
.combine = rbind,
Expand Down
21 changes: 3 additions & 18 deletions R/OSCA_par.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,6 @@
#' # load dataset
#' data("nutrimouse")
#'
#' # generate random phenotype
#' r.pheno <- rnorm(nrow(nutrimouse$gene))
#'
#' ## random phenotype
#' # run function; input path to OSCA software
#' # OSCA_par(df = nutrimouse$gene,
#' # externalVar = r.pheno,
#' # ILCincrement = 0.25,
#' # oscaPath = "pathHere",
#' # numNodes = detectCores()-1,
#' # permute = T)
#'
#' ## observed external variable
#' # run function; input path to OSCA software
#' # OSCA_par(df = nutrimouse$gene,
#' # externalVar = as.numeric(nutrimouse$diet),
Expand All @@ -70,9 +57,9 @@
#' @export
#' @import data.table
#' @import partition
#' @import parallel
#' @import foreach
#' @import doParallel
#' @import parallel
OSCA_par <- function(df, externalVar, ILCincrement = 0.05, oscaPath, numNodes = 1, permute = T) {

# check correct dimensions of input
Expand All @@ -94,10 +81,8 @@ OSCA_par <- function(df, externalVar, ILCincrement = 0.05, oscaPath, numNodes =
externalVar_permute <- sample(externalVar)

# parallel set up
my.cluster <- parallel::makeCluster(
numNodes,
type = "PSOCK")
doParallel::registerDoParallel(cl = my.cluster)
my.cluster <- parallel::makeCluster(numNodes)
doParallel::registerDoParallel(my.cluster)

# PVE for each value with permutations or PVE for each value without permutations
if (permute == T) {
Expand Down
16 changes: 0 additions & 16 deletions R/OSCA_parPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,6 @@
#' # load dataset
#' data("nutrimouse")
#'
#' # generate random phenotype
#' r.pheno <- rnorm(nrow(nutrimouse$gene))
#'
#' ## random phenotype
#' # run OSCA_par and save output; input path to OSCA software
#' # r.par <- OSCA_par(df = nutrimouse$gene,
#' # externalVar = r.pheno,
#' # ILCincrement = 0.25,
#' # oscaPath = "pathHere",
#' # numNodes = detectCores()-1,
#' # permute = T)
#'
#' # run function
#' #OSCA_parPlot(df=r.par, externalVarName = "Random Phenotype", dataName = "Nutritional Issue Genes")
#'
#' ## observed external variables
#' # run OSCA_par and save output; input path to OSCA software
#' # par <- OSCA_par(df = nutrimouse$gene,
#' # externalVar = as.numeric(nutrimouse$diet),
Expand Down
10 changes: 0 additions & 10 deletions R/OSCA_singleValue.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,7 @@
#'
#' # load dataset
#' data("nutrimouse")
#'
#' # generate random phenotype
#' r.pheno <- rnorm(nrow(nutrimouse$gene))
#'
#' ## random phenotype
#' # run function; input path to OSCA software
#' # OSCA_singleValue(df = nutrimouse$gene,
#' # externalVar= r.pheno,
#' # oscaPath = "pathHere")
#'
#' ## observed external variable
#' # run function; input path to OSCA software
#' # OSCA_singleValue(df = nutrimouse$gene,
#' # externalVar = as.numeric(nutrimouse$diet),
Expand Down
11 changes: 1 addition & 10 deletions man/ACDChighdim.Rd

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

10 changes: 1 addition & 9 deletions man/ACDCmod.Rd

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

13 changes: 0 additions & 13 deletions man/OSCA_par.Rd

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

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

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

10 changes: 0 additions & 10 deletions man/OSCA_singleValue.Rd

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

0 comments on commit e81d840

Please sign in to comment.