Skip to content
Permalink
Browse files

rename 'TReNA' -> 'trena'

git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/trena@131230 bc3139a8-67e5-0310-9ffc-ced21a209358
  • Loading branch information...
mtmorgan committed Jul 14, 2017
0 parents commit 8382780bf169fda58038e5f67d5d8ce5d1b24485
Showing with 264,359 additions and 0 deletions.
  1. +1 −0 .Rbuildignore
  2. +2 −0 .gitignore
  3. +28 −0 DESCRIPTION
  4. +60 −0 NAMESPACE
  5. +114 −0 R/BayesSpikeSolver.R
  6. +95 −0 R/CandidateFilter.R
  7. +317 −0 R/EnsembleSolver.R
  8. +114 −0 R/FootprintFilter.R
  9. +589 −0 R/FootprintFinder.R
  10. +111 −0 R/LassoPVSolver.R
  11. +94 −0 R/LassoSolver.R
  12. +73 −0 R/NullFilter.R
  13. +107 −0 R/PearsonSolver.R
  14. +108 −0 R/RandomForestSolver.R
  15. +96 −0 R/RidgeSolver.R
  16. +129 −0 R/Solver.R
  17. +108 −0 R/SpearmanSolver.R
  18. +198 −0 R/SqrtLassoSolver.R
  19. +182 −0 R/TReNA.R
  20. +99 −0 R/VarianceFilter.R
  21. +53 −0 R/help.R
  22. +142 −0 R/sharedFunctions.R
  23. +37 −0 README.md
  24. +1 −0 _config.yml
  25. 0 inst/NEWS
  26. +1,851 −0 inst/demos/Assess_Distributions.ipynb
  27. +21 −0 inst/demos/demoEnhancersDatabaseOnWhovian.R
  28. +86 −0 inst/demos/findPiez02RegulatorySnps.R
  29. +70 −0 inst/demos/findTFs.R
  30. +41 −0 inst/demos/runLassoSolver.R
  31. BIN inst/demos/test.png
  32. +85 −0 inst/demos/trem2/go.R
  33. +10,590 −0 inst/extdata/all_motifs.meme
  34. BIN inst/extdata/ampAD.154genes.mef2cTFs.278samples.RData
  35. BIN inst/extdata/ampAD.58genes.mef2cTFs.278samples.RData
  36. BIN inst/extdata/genome.sub.db
  37. +9,018 −0 inst/extdata/motifGenes.tsv
  38. BIN inst/extdata/project.sub.db
  39. BIN inst/extdata/yeast-53genes-536-samples.RData
  40. +62 −0 inst/misc/createSQLiteDB.R
  41. +30 −0 inst/misc/footprintFinding/piq/makefile
  42. +55 −0 inst/misc/makeTRN-proximalanddistal-demo.R
  43. +29 −0 inst/misc/makeTRN-proximalonly-demo.R
  44. +100 −0 inst/misc/monteCarloTRN.R
  45. +77 −0 inst/misc/runTReNA-demo.R
  46. +70 −0 inst/notes/fillEnhancerDatabase.txt
  47. +79 −0 inst/prep/dream5.yeast/createTestData.R
  48. +537 −0 inst/prep/dream5.yeast/net4_expression_data.tsv
  49. +5,951 −0 inst/prep/dream5.yeast/net4_gene_ids.tsv
  50. +333 −0 inst/prep/dream5.yeast/net4_transcription_factors.tsv
  51. +227,202 −0 inst/prep/dream5.yeast/yeastGoldStandard.tsv
  52. +48 −0 inst/unitTests/test_BayesSpikeSolver.R
  53. +22 −0 inst/unitTests/test_CandidateFilter.R
  54. +51 −0 inst/unitTests/test_EnsembleSolver.R
  55. +35 −0 inst/unitTests/test_FootprintFilter.R
  56. +267 −0 inst/unitTests/test_FootprintFinder.R
  57. +47 −0 inst/unitTests/test_LassoPVSolver.R
  58. +174 −0 inst/unitTests/test_LassoSolver.R
  59. +23 −0 inst/unitTests/test_NullFilter.R
  60. +42 −0 inst/unitTests/test_PearsonSolver.R
  61. +52 −0 inst/unitTests/test_RandomForestSolver.R
  62. +47 −0 inst/unitTests/test_RidgeSolver.R
  63. +206 −0 inst/unitTests/test_Solver.R
  64. +42 −0 inst/unitTests/test_SpearmanSolver.R
  65. +49 −0 inst/unitTests/test_SqrtLassoSolver.R
  66. +39 −0 inst/unitTests/test_TReNA.R
  67. +26 −0 inst/unitTests/test_VarianceFilter.R
  68. +530 −0 inst/utils/additionalTReNATests.R
  69. +49 −0 inst/utils/createGenomeScaleModel.R
  70. +122 −0 inst/utils/determineSqrtLambda.R
  71. +277 −0 inst/utils/evaluateAllSolvers.R
  72. +134 −0 inst/utils/extraFunctions.R
  73. +548 −0 inst/utils/runTReNA.R
  74. +162 −0 inst/utils/test_runTReNA.R
  75. +10 −0 man/BayesSpikeSolver-class.Rd
  76. +33 −0 man/BayesSpikeSolver.Rd
  77. +54 −0 man/CandidateFilter-class.Rd
  78. +10 −0 man/EnsembleSolver-class.Rd
  79. +33 −0 man/EnsembleSolver.Rd
  80. +36 −0 man/FootprintFilter-class.Rd
  81. +56 −0 man/FootprintFinder-class.Rd
  82. +10 −0 man/LassoPVSolver-class.Rd
  83. +33 −0 man/LassoPVSolver.Rd
  84. +10 −0 man/LassoSolver-class.Rd
  85. +33 −0 man/LassoSolver.Rd
  86. +36 −0 man/NullFilter-class.Rd
  87. +10 −0 man/PearsonSolver-class.Rd
  88. +33 −0 man/PearsonSolver.Rd
  89. +10 −0 man/RandomForestSolver-class.Rd
  90. +32 −0 man/RandomForestSolver.Rd
  91. +10 −0 man/RidgeSolver-class.Rd
  92. +33 −0 man/RidgeSolver.Rd
  93. +58 −0 man/Solver-class.Rd
  94. +10 −0 man/SpearmanSolver-class.Rd
  95. +33 −0 man/SpearmanSolver.Rd
  96. +10 −0 man/SqrtLassoSolver-class.Rd
  97. +33 −0 man/SqrtLassoSolver.Rd
  98. +69 −0 man/TReNA-class.Rd
  99. +55 −0 man/TReNA-package.Rd
  100. +38 −0 man/VarianceFilter-class.Rd
  101. +31 −0 man/closeDatabaseConnections.Rd
  102. +24 −0 man/getAssayData.Rd
  103. +51 −0 man/getCandidates-FootprintFilter-method.Rd
  104. +35 −0 man/getCandidates-NullFilter-method.Rd
  105. +42 −0 man/getCandidates-VarianceFilter-method.Rd
  106. +24 −0 man/getCandidates.Rd
  107. +48 −0 man/getChromLoc.Rd
  108. +24 −0 man/getFilterAssayData.Rd
  109. +54 −0 man/getFootprintsForGene.Rd
  110. +47 −0 man/getFootprintsInRegion.Rd
  111. +57 −0 man/getGenePromoterRegion.Rd
  112. +40 −0 man/getGtfGeneBioTypes.Rd
  113. +40 −0 man/getGtfMoleculeTypes.Rd
  114. +48 −0 man/getPromoterRegionsAllGenes.Rd
  115. +24 −0 man/getSolverName.Rd
  116. +25 −0 man/getSolverObject.Rd
  117. +44 −0 man/mapMotifsToTFsMergeIntoTable.Rd
  118. +35 −0 man/rescalePredictorWeights.Rd
  119. +58 −0 man/solve.BayesSpike.Rd
  120. +69 −0 man/solve.Ensemble.Rd
  121. +53 −0 man/solve.Lasso.Rd
  122. +54 −0 man/solve.LassoPV.Rd
  123. +53 −0 man/solve.Pearson.Rd
  124. +53 −0 man/solve.RandomForest.Rd
  125. +53 −0 man/solve.Rd
  126. +54 −0 man/solve.Ridge.Rd
  127. +53 −0 man/solve.Spearman.Rd
  128. +55 −0 man/solve.SqrtLasso.Rd
  129. +2 −0 tests/runTests.R
  130. +184 −0 vignettes/TReNA_Vignette.Rmd
@@ -0,0 +1 @@
^.*\.tsv$
@@ -0,0 +1,2 @@
.Rhistory
inst/doc
@@ -0,0 +1,28 @@
Package: trena
Type: Package
Title: Fit transcriptional regulatory networks using gene expression,
priors, machine learning
Version: 0.99.10
Date: 2017-04-24
Author: Seth Ament <seth.ament@systemsbiology.org>, Paul Shannon
<pshannon@systemsbioloyg.org>, Matthew Richards
<mrichard@systemsbiology.org>
Maintainer: Matthew Richards <mrichard@systemsbiology.org>
Imports: RSQLite, lassopv, randomForest, flare, vbsr, foreach,
doParallel, RPostgreSQL, methods, DBI, GenomicRanges
Depends: R (>= 3.4.0), utils, glmnet (>= 2.0.3),
Suggests: RUnit, limma, plyr, knitr, BiocGenerics, rmarkdown
VignetteBuilder: knitr
Description: Methods for reconstructing transcriptional regulatory
networks, especially in species for which genome-wide TF
binding site information is available.
License: GPL-3
biocViews: Transcription, GeneRegulation, NetworkInference,
FeatureExtraction, Regression, SystemsBiology, GeneExpression
Collate: 'Solver.R' 'BayesSpikeSolver.R' 'CandidateFilter.R'
'EnsembleSolver.R' 'FootprintFilter.R' 'FootprintFinder.R'
'LassoPVSolver.R' 'LassoSolver.R' 'NullFilter.R'
'PearsonSolver.R' 'RandomForestSolver.R' 'RidgeSolver.R'
'SpearmanSolver.R' 'SqrtLassoSolver.R' 'TReNA.R'
'VarianceFilter.R' 'help.R' 'sharedFunctions.R'
RoxygenNote: 6.0.1
@@ -0,0 +1,60 @@
exportClasses(
TReNA,
NullFilter,
VarianceFilter,
FootprintFilter)

export(
TReNA,
Solver,
BayesSpikeSolver,
EnsembleSolver,
LassoPVSolver,
LassoSolver,
PearsonSolver,
RandomForestSolver,
RidgeSolver,
SpearmanSolver,
SqrtLassoSolver,
CandidateFilter,
FootprintFilter,
NullFilter,
VarianceFilter,
FootprintFinder
)

exportMethods(
closeDatabaseConnections,
getCandidates,
getAssayData,
getFilterAssayData,
getChromLoc,
getFootprintsForGene,
getFootprintsInRegion,
getGenePromoterRegion,
getGtfGeneBioTypes,
getGtfMoleculeTypes,
getPromoterRegionsAllGenes,
getSolverName,
getSolverObject,
mapMotifsToTFsMergeIntoTable,
rescalePredictorWeights,
solve
)

import(
DBI,
doParallel,
flare,
foreach,
glmnet,
lassopv,
methods,
randomForest,
vbsr
)

importFrom(RSQLite, SQLite)
importFrom(RPostgreSQL, PostgreSQL)
importFrom(GenomicRanges, makeGRangesFromDataFrame)
importFrom(utils, head)
@@ -0,0 +1,114 @@
#----------------------------------------------------------------------------------------------------
#' An S4 class to represent a Bayes Spike solver
#'
#' @import vbsr
#' @import methods
#'
#' @include Solver.R
#' @name BayesSpikeSolver-class

.BayesSpikeSolver <- setClass ("BayesSpikeSolver", contains="Solver")
#----------------------------------------------------------------------------------------------------
#' Create a Solver class object using the Bayes Spike Solver
#'
#' @param mtx.assay An assay matrix of gene expression data
#' @param quiet A logical denoting whether or not the solver should print output
#'
#' @export
#'
#' @return A Solver class object with Bayes Spike as the solver
#'
#' @family Solver class objects
#'
#' @seealso \code{\link{solve.BayesSpike}}, \code{\link{getAssayData}}
#'
#' @examples
#' solver <- BayesSpikeSolver()

BayesSpikeSolver <- function(mtx.assay=matrix(), quiet=TRUE)
{
obj <- .BayesSpikeSolver(Solver(mtx.assay=mtx.assay, quiet=quiet))

# Send a warning if there's a row of zeros
if(!is.na(max(mtx.assay)) & any(rowSums(mtx.assay) == 0))
warning("One or more gene has zero expression; this may cause difficulty when using Bayes Spike. You may want to try 'lasso' or 'ridge' instead.")

obj

} # BayesSpikeSolver, the constructor
#----------------------------------------------------------------------------------------------------
#' Run the Bayes Spike Solver
#'
#' @rdname solve.BayesSpike
#' @aliases run.BayesSpikeSolver solve.BayesSpike
#'
#' @description Given a TReNA object with Bayes Spike as the solver, use the \code{\link{vbsr}}
#' function to estimate coefficients for each transcription factor as a predictor of the target
#' gene's expression level. This method should be called using the \code{\link{solve}} method on an
#' appropriate TReNA object.
#'
#' @param obj An object of the class Solver with "bayesSpike" as the solver string
#' @param target.gene A designated target gene that should be part of the mtx.assay data
#' @param tfs The designated set of transcription factors that could be associated with the target gene.
#' @param tf.weights A set of weights on the transcription factors (default = rep(1, length(tfs)))
#' @param extraArgs Modifiers to the Bayes Spike solver; this includes \code{n_orderings}, the
#' number of random starts used by the solver
#'
#' @return A data frame containing the coefficients relating the target gene to each transcription factor,
#' plus other fit parameters
#'
#' @seealso \code{\link{vbsr}}, \code{\link{BayesSpikeSolver}}
#'
#' @family solver methods
#'
#' @examples
#' # Load included Alzheimer's data, create a TReNA object with Bayes Spike as solver, and solve
#' load(system.file(package="TReNA", "extdata/ampAD.154genes.mef2cTFs.278samples.RData"))
#' trena <- TReNA(mtx.assay = mtx.sub, solver = "bayesSpike")
#' target.gene <- "MEF2C"
#' tfs <- setdiff(rownames(mtx.sub), target.gene)
#' tbl <- solve(trena, target.gene, tfs)
#'
#' # Solve the same Alzheimer's problem, but this time set the number of random starts to 100
#' tbl <- solve(trena, target.gene, tfs, extraArgs = list("n_orderings" = 100))

setMethod("run", "BayesSpikeSolver",

function (obj, target.gene, tfs, tf.weights=rep(1,length(tfs)), extraArgs=list()){

# Check if target.gene is in the bottom 10% in mean expression; if so, send a warning
if(rowMeans(getAssayData(obj))[target.gene] < stats::quantile(rowMeans(getAssayData(obj)), probs = 0.1)){
warning("Target gene mean expression is in the bottom 10% of all genes in the assay matrix")
}

n_orderings <- 10

# Check for n_orderings parameter and adopt a supplied one
if("n_orderings" %in% names(extraArgs))
n_orderings <- extraArgs[["n_orderings"]]

# we don't try to handle tf self-regulation
deleters <- grep(target.gene, tfs)
if(length(deleters) > 0){
tfs <- tfs[-deleters]
tf.weights <- tf.weights[-deleters]
message(sprintf("BayesSpikeSolver removing target.gene from candidate regulators: %s", target.gene))
}

mtx <- getAssayData(obj)
stopifnot(target.gene %in% rownames(mtx))
stopifnot(all(tfs %in% rownames(mtx)))
features <- t(mtx[tfs, ])
target <- as.numeric(mtx[target.gene,])
result <- vbsr(target, features, family='normal', n_orderings = n_orderings)
tbl.out <- data.frame(beta=result$beta, pval=result$pval, z=result$z, post=result$post)
rownames(tbl.out) <- tfs
tbl.out$score <- -log10(tbl.out$pval)
tbl.out <- tbl.out[order(tbl.out$score, decreasing=TRUE),]

gene.cor <- sapply(rownames(tbl.out), function(tf) stats::cor(mtx[tf,], mtx[target.gene,]))
tbl.out$gene.cor <- as.numeric(gene.cor)
tbl.out
})
#----------------------------------------------------------------------------------------------------

@@ -0,0 +1,95 @@
#' @import methods
#'
#' @name CandidateFilter-class
#' @rdname CandidateFilter-class
#' @aliases CandidateFilter
#'
#' @slot mtx.assay An assay matrix of gene expression data
#' @slot quiet A logical denoting whether or not the CandidateFilter object should print output
#'
#' @family Filtering objects

.CandidateFilter <- setClass("CandidateFilter",
slots = c(mtx.assay = "matrix",
quiet = "logical"
)
)
#----------------------------------------------------------------------------------------------------
printf <- function(...) print(noquote(sprintf(...)))
#----------------------------------------------------------------------------------------------------
#' Get candidate genes using a CandidateFilter object
#'
#' @rdname getCandidates
#' @aliases getCandidates
#'
#' @param obj An object of a CandidateFilter class
#' @param extraArgs A named list of extra arguments corresponding to the chosen filter
#'
#' @return A vector containing genes from the assay matrix that are selected by the filter
#'
#' @family getCandidate Methods
#' @export
setGeneric("getCandidates", signature="obj", function(obj,extraArgs) standardGeneric("getCandidates"))

#' Retrieve the assay matrix of gene expression data
#'
#' @aliases getFilterAssayData
#'
#' @param obj An object of a CandidateFilter class
#'
#' @return The assay matrix of gene expression data associated with a CandidateFilter object
#'
#' @examples
#'
#' # Create a CandidateFilter object using the included Alzheimer's data and retrieve the matrix
#' load(system.file(package="TReNA", "extdata/ampAD.154genes.mef2cTFs.278samples.RData"))
#' my.filter <- CandidateFilter(mtx.sub)
#' mtx <- getFilterAssayData(my.filter)

#' @export
setGeneric("getFilterAssayData", signature="obj", function(obj) standardGeneric ("getFilterAssayData"))
#----------------------------------------------------------------------------------------------------
#' CandidateFilter
#'
#' A CandidateFilter is an S4 class to represent a gene candidate filter. These filters can employ a variety of methods
#' to reduce the number of transcription factors used as predictors for solving a TReNA object.
#'
#' @rdname CandidateFilter-class
#' @aliases CandidateFilter
#'
#' @param mtx.assay An assay matrix of gene expression data
#' @param quiet A logical denoting whether or not the CandidateFilter object should print output
#'
#' @return An object of the Candidate filter class
#'
#' @seealso \code{\link{getCandidates}}, \code{\link{getFilterAssayData}}
#'
#' @export
#'
#' @examples
#' # Create an empty candidate filter
#' candidate.filter <- CandidateFilter(mtx.assay = matrix(), quiet=TRUE)

CandidateFilter <- function(mtx.assay = matrix(), quiet = TRUE)
{
.CandidateFilter(mtx.assay = mtx.assay, quiet = quiet)

} # CandidateFilter, the constructor
#----------------------------------------------------------------------------------------------------
#' @describeIn CandidateFilter Retrieve the assay matrix of gene expression data
#'
#' @param obj An object of a CandidateFilter class
#'
#' @examples
#'
#' # Create a CandidateFilter object using the included Alzheimer's data and retrieve the matrix
#' load(system.file(package="TReNA", "extdata/ampAD.154genes.mef2cTFs.278samples.RData"))
#' my.filter <- CandidateFilter(mtx.sub)
#' mtx <- getFilterAssayData(my.filter)

setMethod("getFilterAssayData", "CandidateFilter",

function (obj){
obj@mtx.assay
})
#----------------------------------------------------------------------------------------------------

0 comments on commit 8382780

Please sign in to comment.
You can’t perform that action at this time.