Skip to content

Commit

Permalink
change mostVar to var, update documentation, vignette
Browse files Browse the repository at this point in the history
  • Loading branch information
epurdom committed May 11, 2016
1 parent c244a6d commit b0bea24
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 67 deletions.
2 changes: 1 addition & 1 deletion R/clusterMany.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#' all distances give 0-1 values for the distance (and hence are possible
#' for both type "01" and "K" algorithms).
#' @param nVarDims vector of the number of the most variable features to keep
#' (when "mostVar" is identified in \code{dimReduce}). If NA is included, then
#' (when "var" is identified in \code{dimReduce}). If NA is included, then
#' the full dataset will also be included.
#' @param nPCADims vector of the number of PCs to use (when 'PCA' is identified
#' in \code{dimReduce}). If NA is included, then the full dataset will also be
Expand Down
6 changes: 3 additions & 3 deletions R/clusterSingle.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#' before clustering.
#' @param dimReduce character A character identifying what type of
#' dimensionality reduction to perform before clustering. Options are
#' "none","PCA", and "mostVar".
#' "none","PCA", and "var".
#' @param ndims integer An integer identifying how many dimensions to reduce to
#' in the reduction specified by \code{dimReduce}
#' @param ... arguments to be passed on to the method for signature
Expand Down Expand Up @@ -72,7 +72,7 @@ setMethod(
definition = function(x, subsample=TRUE, sequential=FALSE,
clusterFunction=c("tight", "hierarchical01", "pam","hierarchicalK"),
clusterDArgs=NULL, subsampleArgs=NULL, seqArgs=NULL,
isCount=FALSE,transFun=NULL, dimReduce=c("none","PCA","mostVar"),
isCount=FALSE,transFun=NULL, dimReduce=c("none","PCA","var"),
ndims=NA) {

origX <- x #ngenes x nsamples
Expand All @@ -87,7 +87,7 @@ setMethod(
warning("specifying ndims has no effect if dimReduce==`none`")
}
nPCADims <- ifelse(dimReduce=="PCA", ndims, NA)
nVarDims <- ifelse(dimReduce=="mostVar", ndims, NA)
nVarDims <- ifelse(dimReduce=="var", ndims, NA)
transObj <- .transData(x, nPCADims=nPCADims, nVarDims=nVarDims,
dimReduce=dimReduce, transFun=transFun,
isCount=isCount)
Expand Down
4 changes: 2 additions & 2 deletions R/makeDendrogram.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
setMethod(
f = "makeDendrogram",
signature = "ClusterExperiment",
definition = function(x, whichCluster="primaryCluster",dimReduce=c("none", "PCA", "mostVar"),
definition = function(x, whichCluster="primaryCluster",dimReduce=c("none", "PCA", "var"),
ndims=NA,unassignedSamples=c("outgroup", "cluster"),...)
{
unassignedSamples<-match.arg(unassignedSamples)
Expand All @@ -84,7 +84,7 @@ setMethod(
}
origX <- assay(x)
nPCADims <- ifelse(dimReduce=="PCA", ndims, NA)
nVarDims <- ifelse(dimReduce=="mostVar", ndims, NA)
nVarDims <- ifelse(dimReduce=="var", ndims, NA)
transObj <- .transData(origX, nPCADims=nPCADims, nVarDims=nVarDims,
dimReduce=dimReduce, transFun=transformation(x))
dat <- transObj$x
Expand Down
14 changes: 7 additions & 7 deletions R/plotHeatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
#' @param ... for signature \code{matrix}, arguments passed to \code{aheatmap}.
#' For the other signatures, passed to the method for signature \code{matrix}.
#' @param nFeatures integer indicating how many features should be used (if
#' \code{clusterFeaturesData} is 'mostVar' or 'PCA').
#' \code{clusterFeaturesData} is 'var' or 'PCA').
#' @param isSymmetric logical. if TRUE indicates that the input matrix is
#' symmetric. Useful when plotting a co-clustering matrix or other sample by
#' sample matrices (e.g., correlation).
Expand Down Expand Up @@ -127,7 +127,7 @@
#' clusterings will be shown closest to data (i.e. on bottom).
#' @details If \code{data} is a \code{ClusterExperiment} object,
#' \code{clusterFeaturesData} is not a dataset, but instead indicates which
#' features should be shown in the heatmap. "mostVar" selects the
#' features should be shown in the heatmap. "var" selects the
#' \code{nFeatures} most variable genes (based on
#' \code{transformation(assay(data))}); "PCA" results in a heatmap of the top
#' \code{nFeatures} PCAs of the \code{transformation(assay(data))}.
Expand Down Expand Up @@ -239,7 +239,7 @@ setMethod(
signature = signature(data = "ClusterExperiment"),
definition = function(data,
clusterSamplesData=c("hclust","dendrogramValue","orderSamplesValue","primaryCluster"),
clusterFeaturesData=c("mostVar","all","PCA"), nFeatures=NULL,
clusterFeaturesData=c("var","all","PCA"), nFeatures=NULL,
visualizeData=c("transformed","centeredAndScaled","original"),
whichClusters= c("primary","workflow","all","none"),
sampleData=NULL,clusterFeatures=TRUE,
Expand All @@ -261,12 +261,12 @@ setMethod(
clusterFeaturesData<-unlist(clusterFeaturesData)
}
else groupFeatures<-NULL
if(all(clusterFeaturesData %in% c("mostVar","all","PCA"))){ #
if(all(clusterFeaturesData %in% c("var","all","PCA"))){ #
dimReduce=switch(clusterFeaturesData,
"mostVar"="mostVar",
"var"="var",
"PCA"="PCA",
"all"="none")
if(is.null(nFeatures)) nFeatures<-min(switch(clusterFeaturesData,"mostVar"=500,"all"=nFeatures(data),"PCA"=50),nFeatures(data))
if(is.null(nFeatures)) nFeatures<-min(switch(clusterFeaturesData,"var"=500,"all"=nFeatures(data),"PCA"=50),nFeatures(data))
wh<-1:NROW(data)
}
else{
Expand All @@ -289,7 +289,7 @@ setMethod(
}
transObj<-.transData(transFun = transformation(data), x=assay(data[wh,]), nPCADims=nFeatures,nVarDims = nFeatures,dimReduce = dimReduce)
if(dimReduce%in%"PCA") wh<-1:nFeatures
if(dimReduce=="mostVar") wh<-transObj$whMostVar #give indices that will pull
if(dimReduce=="var") wh<-transObj$whMostVar #give indices that will pull
#########
##Assign visualization data and clusterFeaturesData
#########
Expand Down
16 changes: 8 additions & 8 deletions R/transformFunction.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
#' @param nVarDims Numeric vector giving the number of features (e.g. genes) to
#' keep, based on MAD variability.
#' @param dimReduce Character vector specifying the dimensionality reduction to
#' perform, any combination of 'none', 'PCA' and 'mostVar'. See details.
#' perform, any combination of 'none', 'PCA' and 'var'. See details.
#'
#' @details The data matrix defined by \code{assay(x)} is transformed based on
#' the transformation function defined in x. If \code{dimReduce="none"} the
#' transformed matrix is returned. Otherwise, the user can request
#' dimensionality reduction of the transformed data via \code{dimReduce}.
#' 'PCA' refers to PCA of the transformed data with the top nPCADims kept.
#' 'mostVar' refers to keeping the top most variable features (defined by
#' 'var' refers to keeping the top most variable features (defined by
#' taking the MAD across all samples), and nVarDims defines how many such
#' features to keep.
#' @details The PCA uses prcomp on \code{t(assay(x))} with \code{center=TRUE}
Expand Down Expand Up @@ -47,7 +47,7 @@
#' x <- transform(cc, dimReduce="PCA", nPCADims=3)
#'
#' #transform and take return untransformed, top 5 features, and top 10 features
#' y <- transform(cc, dimReduce="mostVar", nVarDims=c(NA, 5, 10))
#' y <- transform(cc, dimReduce="var", nVarDims=c(NA, 5, 10))
#' names(y)
#'
#' z<-transform(cc) #just return tranformed data
Expand All @@ -71,7 +71,7 @@ setMethod(
# if npcs=NA or length of npcs=1, transformed data is matrix; otherwise returns list of data matrices.
# 2nd element is the transformation function
# The 2nd element is useful if function allows user to say isCount=TRUE so you can then actually get the transformation function out for defining ClusterExperiment Object)
# 3rd element is the index of most variable (if dimReduce="mostVar" and returns a simple matrix) otherwise NULL
# 3rd element is the index of most variable (if dimReduce="var" and returns a simple matrix) otherwise NULL
.transData<-function(x,transFun=NULL,isCount=FALSE,
nPCADims,nVarDims,dimReduce)
{
Expand All @@ -92,7 +92,7 @@ setMethod(
listReturn<-FALSE
whFeatures<-NULL
#check valid options for dimReduce
if(any(!dimReduce %in% c("none","PCA","mostVar"))) stop("invalid options for 'dimReduce' must be one of: 'none','PCA',or 'mostVar'")
if(any(!dimReduce %in% c("none","PCA","var"))) stop("invalid options for 'dimReduce' must be one of: 'none','PCA',or 'var'")
if(any(dimReduce!="none")){
if(any(is.na(nPCADims)) & "PCA" %in% dimReduce){
if(length(nPCADims)==1){
Expand All @@ -105,10 +105,10 @@ setMethod(
nPCADims<-nPCADims[!is.na(nPCADims)]
}
}
if(any(is.na(nVarDims)) & "mostVar" %in% dimReduce){
if(any(is.na(nVarDims)) & "var" %in% dimReduce){
if(length(nVarDims)==1){
if(length(dimReduce)==1) dimReduce<-"none" #assume user goofed and meant to do none
if(length(dimReduce)>1) dimReduce<-dimReduce[-match("mostVar",dimReduce)] #assume user goofed and didn't mean to also include
if(length(dimReduce)>1) dimReduce<-dimReduce[-match("var",dimReduce)] #assume user goofed and didn't mean to also include

}
else{#assume user meant to do none as well as dimReduce with other values.
Expand Down Expand Up @@ -148,7 +148,7 @@ setMethod(
listReturn<-TRUE
}
}
if("mostVar" %in% dimReduce & all(!is.na(nVarDims))){ #do PCA dim reduction
if("var" %in% dimReduce & all(!is.na(nVarDims))){ #do PCA dim reduction
if(max(nVarDims)>NROW(x)) stop("the number of most variable features must be strictly less than the number of rows of input data matrix")
if(min(nVarDims)<1) stop("the number of most variable features must be equal to 1 or greater")
if(min(nVarDims)<50 & NROW(x)>1000) warning("the number of most variable features to be selected is less than 50. Are you sure you meant to choose to use the top most variable features rather than PCA dimensionality reduction?")
Expand Down
4 changes: 2 additions & 2 deletions man/clusterMany.Rd

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

6 changes: 3 additions & 3 deletions man/clusterSingle.Rd

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

2 changes: 1 addition & 1 deletion man/makeDendrogram.Rd

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

6 changes: 3 additions & 3 deletions man/plotHeatmap.Rd

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

6 changes: 3 additions & 3 deletions man/transform.Rd

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

6 changes: 3 additions & 3 deletions tests/testthat/test_clusterMany.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ test_that("`clusterMany` works with matrix, list of data, ClusterExperiment obje
})
test_that("`clusterMany` works changing parameters", {
#check dim reduce
cc <- clusterMany(mat, ks=c(3,4),nVarDim=c(10,15),nPCADim=c(3,4),dimReduce=c("none","PCA","mostVar"),clusterFunction="pam",
cc <- clusterMany(mat, ks=c(3,4),nVarDim=c(10,15),nPCADim=c(3,4),dimReduce=c("none","PCA","var"),clusterFunction="pam",
subsample=FALSE, sequential=FALSE,verbose=FALSE,
isCount=FALSE)
#check giving paramMatrix
param <- clusterMany(mat, ks=c(3,4),nVarDim=c(10,15),nPCADim=c(3,4),dimReduce=c("none","PCA","mostVar"),clusterFunction="pam",
param <- clusterMany(mat, ks=c(3,4),nVarDim=c(10,15),nPCADim=c(3,4),dimReduce=c("none","PCA","var"),clusterFunction="pam",
subsample=FALSE, sequential=FALSE,run=FALSE,verbose=FALSE,
isCount=FALSE)
# cc2 <- clusterMany(mat, ks=c(3,4),nVarDim=c(10, 15),nPCADim=c(3,4),dimReduce=c("none","PCA","mostVar"),clusterFunction="pam",
# cc2 <- clusterMany(mat, ks=c(3,4),nVarDim=c(10, 15),nPCADim=c(3,4),dimReduce=c("none","PCA","var"),clusterFunction="pam",
# subsample=FALSE, sequential=FALSE,verbose=FALSE,
# isCount=FALSE,paramMatrix=param$paramMatrix,clusterDArgs=param$clusterDArgs,seqArgs=param$seqArgs,subsampleArgs=param$subsampleArgs)
# expect_equal(cc,cc2)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test_clusterSingle.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@ test_that("Different options of `clusterSingle` ", {
#check var reduction
clustndims <- clusterSingle(mat, clusterFunction="pam",
subsample=FALSE, sequential=FALSE,
dimReduce="mostVar", ndims=3,
dimReduce="var", ndims=3,
clusterDArgs=list(k=3), isCount=FALSE)
expect_error(clusterSingle(mat, clusterFunction="pam",
subsample=FALSE, sequential=FALSE,
dimReduce="mostVar", ndims=NROW(mat)+1,
dimReduce="var", ndims=NROW(mat)+1,
clusterDArgs=list(k=3),isCount=FALSE),
"the number of most variable features must be strictly less than the number of rows of input data matrix")
expect_warning(clusterSingle(mat, clusterFunction="pam",
Expand Down
20 changes: 10 additions & 10 deletions tests/testthat/test_constructor.R
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,17 @@ test_that("accessing transformed data works as promised",
#check all of the option handling on the dimensionality reduction arguments
expect_equal(dim(transform(cc)), dim(assay(cc)))
expect_equal(dim(transform(cc,dimReduce="PCA",nPCADims=3)), c(3,NCOL(assay(cc))))
expect_equal(dim(transform(cc,dimReduce="mostVar",nVarDims=3)), c(3,NCOL(assay(cc))))
expect_equal(dim(transform(cc,dimReduce=c("PCA","mostVar"),nVarDims=2)),c(2,NCOL(assay(cc))))
expect_equal(dim(transform(cc,dimReduce=c("PCA","mostVar"),nPCADims=2)),c(2,NCOL(assay(cc))))
expect_equal(length(transform(cc,dimReduce="mostVar",nVarDims=c(2,3))),2)
expect_equal(dim(transform(cc,dimReduce="var",nVarDims=3)), c(3,NCOL(assay(cc))))
expect_equal(dim(transform(cc,dimReduce=c("PCA","var"),nVarDims=2)),c(2,NCOL(assay(cc))))
expect_equal(dim(transform(cc,dimReduce=c("PCA","var"),nPCADims=2)),c(2,NCOL(assay(cc))))
expect_equal(length(transform(cc,dimReduce="var",nVarDims=c(2,3))),2)
expect_equal(length(transform(cc,dimReduce="PCA",nPCADims=c(2,3))),2)
expect_equal(length(transform(cc,dimReduce=c("PCA","mostVar"),nPCADims=c(2,3))),2)
expect_equal(length(transform(cc,dimReduce=c("PCA","mostVar"),nVarDims=c(2,3))),2)
expect_equal(length(transform(cc,dimReduce=c("PCA","mostVar"),nPCADims=c(2,3),nVarDims=4)),3)
expect_equal(length(transform(cc,dimReduce=c("PCA","mostVar"),nPCADims=c(3),nVarDims=4)),2)
expect_equal(length(transform(cc,dimReduce=c("PCA","mostVar"),nPCADims=c(2),nVarDims=c(3,4))),3)
expect_equal(dim(transform(cc,dimReduce=c("PCA","mostVar"),nPCADims=NA,nVarDims=NA)),dim(assay(cc)))
expect_equal(length(transform(cc,dimReduce=c("PCA","var"),nPCADims=c(2,3))),2)
expect_equal(length(transform(cc,dimReduce=c("PCA","var"),nVarDims=c(2,3))),2)
expect_equal(length(transform(cc,dimReduce=c("PCA","var"),nPCADims=c(2,3),nVarDims=4)),3)
expect_equal(length(transform(cc,dimReduce=c("PCA","var"),nPCADims=c(3),nVarDims=4)),2)
expect_equal(length(transform(cc,dimReduce=c("PCA","var"),nPCADims=c(2),nVarDims=c(3,4))),3)
expect_equal(dim(transform(cc,dimReduce=c("PCA","var"),nPCADims=NA,nVarDims=NA)),dim(assay(cc)))
expect_equal(dim(transform(cc,dimReduce=c("PCA"),nPCADims=NA,nVarDims=3)),dim(assay(cc)))
expect_equal(length(transform(cc,dimReduce=c("PCA"),nPCADims=c(NA,3),nVarDims=4)),2)

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test_plotting.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ test_that("`plotHeatmap` visualization choices/feature choices all work", {
plotHeatmap(smSimCE,visualizeData="transformed",clusterSamplesData=c(3,4,5))

plotHeatmap(smSimCE,visualizeData="transform",clusterFeaturesData="all")
plotHeatmap(smSimCE,visualizeData="transform",clusterFeaturesData="mostVar",nFeatures=3)
plotHeatmap(smSimCE,visualizeData="transform",clusterFeaturesData="var",nFeatures=3)
plotHeatmap(smSimCE,visualizeData="transform",clusterFeaturesData=3:5,nFeatures=3)
expect_error(plotHeatmap(smSimCE,visualizeData="transform",clusterFeaturesData=paste("Gene",3:5),nFeatures=3))
row.names(smSimCE)<-paste("Gene",1:NROW(smSimCE))
Expand Down

0 comments on commit b0bea24

Please sign in to comment.