Takes an input of hierarchical clusterings of clusters and returns estimates of number of proportion of non-null and merges those below a certain cutoff.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
## S4 method for signature 'matrixOrHDF5' mergeClusters(x, cl, dendro = NULL, mergeMethod = c("none", "Storey", "PC", "adjP", "locfdr", "MB", "JC"), plotInfo = "none", nodePropTable = NULL, calculateAll = TRUE, showWarnings = FALSE, cutoff = 0.05, plot = TRUE, isCount = TRUE, logFCcutoff = 0, ...) ## S4 method for signature 'ClusterExperiment' mergeClusters(x, eraseOld = FALSE, isCount = FALSE, mergeMethod = "none", plotInfo = "all", clusterLabel = "mergeClusters", leafType = c("samples", "clusters"), plotType = c("colorblock", "name", "ids"), plot = TRUE, ...) ## S4 method for signature 'ClusterExperiment' nodeMergeInfo(x) ## S4 method for signature 'ClusterExperiment' mergeCutoff(x) ## S4 method for signature 'ClusterExperiment' mergeMethod(x) ## S4 method for signature 'ClusterExperiment' mergeClusterIndex(x) ## S4 method for signature 'ClusterExperiment' getMergeCorrespond(x, by = c("merge", "original"))
data to perform the test on. It can be a matrix or a
A numeric vector with cluster assignments to compare to. “-1” indicates the sample was not assigned to a cluster.
dendrogram providing hierarchical clustering of clusters in cl.
If x is a matrix, then the default is
method for calculating proportion of non-null that will be used to merge clusters (if 'none', no merging will be done). See details for description of methods.
what type of information about the merging will be shown on
the dendrogram. If 'all', then all the estimates of proportion non-null
will be plotted at each node of the dendrogram; if 'mergeMethod', then only
the value used in the
Only for matrix version. Matrix of results from previous
logical. Whether to calculate the estimates for all
methods. This reduces computation costs for any future calls to
logical. Whether to show warnings given by the methods.
The 'locfdr' method in particular frequently spits out warnings (which may
indicate that its estimates are not reliable). Setting
minimimum value required for NOT merging a cluster, i.e. two clusters with the proportion of DE below cutoff will be merged. Must be a value between 0, 1, where lower values will make it harder to merge clusters.
logical as to whether to plot the dendrogram with the merge results
logical as to whether input data is a count matrix. See details.
Relevant only if the
logical. Only relevant if input
a string used to describe the type of clustering. By default it is equal to "mergeClusters", to indicate that this clustering is the result of a call to mergeClusters (only if x is a ClusterExperiment object)
if plotting, whether the leaves should be the clusters or the
samples. Choosing 'samples' allows for visualization of how many samples
are in the merged clusters (only if x is a ClusterExperiment object), which
is the main difference between choosing "clusters" and "samples",
if plotting, then whether leaves of dendrogram should be labeled by rectangular blocks of color ("colorblock") or with the names of the leaves ("name") (only if x is a ClusterExperiment object).
indicates whether output from
Estimation of Proportion non-null "Storey" refers to the
method of Storey (2002). "PC" refers to the method of Pounds and Cheng
(2004). "JC" refers to the method of Ji and Cai (2007), and implementation
of "JC" method is copied from code available on Jiashin Ji's website,
December 16, 2015
refers to the method of Efron (2004) and is implemented in the package
locfdr. "MB" refers to the method of Meinshausen and Buhlmann
(2005) and is implemented in the package
refers to the proportion of genes that are found significant based on a FDR
adjusted p-values (method "BH") and a cutoff of 0.05.
Count correction If
isCount=TRUE, and the input is
log2(count + 1) will be used for
makeDendrogram and the original data with voom correction
will be used in
getBestFeatures). If input is
ClusterExperiment, then setting
means that the log2(1+count) will be used as the transformation, like for
the matrix case as well as the voom calculation, and will NOT use the
transformation stored in the object. If FALSE, then transformData(x) will be
given to the input and will be used for both
getBestFeatures, with no voom correction.
Control of Plotting If
mergeMethod is not equal to
'none' then the plotting will indicate where the clusters will be merged by
making dotted lines of edges that are merged together (assuming
plotInfo is not 'none').
plotInfo controls simultaneously
what information will be plotted on the nodes as well as whether the dotted
lines will be shown for the merged cluster. Notice that the choice of
plotInfo (as long as it is not 'none') has no effect on how the
dotted edges are drawn – they are always drawn based on the
mergeMethod. If you choose
plotInfo to not be equal to the
mergeMethod, then you will have a confusing picture where the dotted
edges will be based on the clustering created by
the information on the nodes is based on a different method. Note that you
plotInfo by setting
(passed to plot.phylo), so that no information is plotted on the nodes, but
the dotted edges are still drawn. If you just want plot of the dendrogram,
with no merging performed nor demonstrated on the plot, see
If the dendrogram was made with option
unassignedSamples="cluster" (i.e. unassigned were clustered in with
other samples), then you cannot choose the option
leafType='samples'. This is because the current code cannot reliably
link up the internal nodes of the sample dendrogram to the internal nodes
of the cluster dendrogram when the unassigned samples are intermixed.
When the input is a
ClusterExperiment object, the function
attempts to update the merge information in that object. This is done by
checking that the existing dendrogram stored in the object (and run on
the clustering stored in the slot
dendro_index) is the same
clustering that is stored in the slot
For this reason, new calls to
makeDendrogram will erase the merge
information saved in the object.
mergeClusters is run with
function may still calculate the proportions per node if
not equal to "none" or
calculateAll=TRUE. If the input object was a
ClusterExperiment object, the resulting information will be still
saved, though no new clustering was created; if there was not an existing
merge method, the slot
merge_dendrocluster_index will be updated.
If 'x' is a matrix, it returns (invisibly) a list with elements
clustering a vector of length equal to ncol(x)
giving the integer-valued cluster ids for each sample. "-1" indicates the
sample was not clustered.
oldClToNew A table of the old
cluster labels to the new cluster labels.
nodeProp A table of
the proportions that are DE on each node.
nodeMerge A table of indicating for each node whether merged or not and the cluster id in the new clustering that corresponds to the node
originalClusterDendro The dendrogram on which the merging
was based (based on the original clustering).
cutoff The cutoff value for merging.
If 'x' is a
ClusterExperiment, it returns a new
ClusterExperiment object with an additional clustering based on the
merging. This becomes the new primary clustering.
nodeMergeInfo returns information collected about the nodes
during merging as a data.frame with the following entries:
Node Name of the node
contrast compared at each node, in terms of the cluster ids
isMerged Logical as to whether samples from that node which were
merged into one cluster during merging
mergeClusterId If a
node corresponds to a new, merged cluster, gives the cluster id it
corresponds to. Otherwise NA
...The remaining columns give
the estimated proportion of genes differentially expressed for each method. A
column of NAs means that the method in question hasn't been calculated yet.
mergeCutoff returns the cutoff used for the current merging.
mergeMethod returns the method used for the current merge.
mergeClusterIndex returns the index of the clustering used for the current merge.
getMergeCorrespond returns the correspondence between the
merged cluster and its originating cluster. If
a named vector, where the names of the vector are the cluster ids of the
originating cluster and the values of the vector are the cluster ids of the
merged cluster. If
by="merge" the results returned are organized by
the merged clusters. This will generally be a list, with the names of the
list equal to the clusterIds of the merge clusters and the entries the
clusterIds of the originating clusters. However, if there was no merging
done (so that the clusters are identical) the output will be a vector like
Ji and Cai (2007), "Estimating the Null and the Proportion of Nonnull Effects in Large-Scale Multiple Comparisons", JASA 102: 495-906.
Efron (2004) "Large-scale simultaneous hypothesis testing: the choice of a null hypothesis," JASA, 99: 96-104.
Meinshausen and Buhlmann (2005) "Lower bounds for the number of false null hypotheses for multiple testing of associations", Biometrika 92(4): 893-907.
Storey (2002) "A direct approach to false discovery rates", J. R. Statist. Soc. B 64 (3)": 479-498.
Pounds and Cheng (2004). "Improving false discovery rate estimation." Bioinformatics 20(11): 1737-1745.
makeDendrogram, plotDendrogram, getBestFeatures
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
data(simData) #create a clustering, for 8 clusters (truth was 3) cl<-clusterSingle(simData, subsample=FALSE, sequential=FALSE, mainClusterArgs=list(clusterFunction="pam", clusterArgs=list(k=8))) #give more interesting names to clusters: newNames<- paste("Cluster",clusterLegend(cl)[][,"name"],sep="") clusterLegend(cl)[][,"name"]<-newNames #make dendrogram cl <- makeDendrogram(cl) #plot showing the before and after clustering #(Note argument 'use.edge.length' can improve #readability) merged <- mergeClusters(cl, plotInfo="all", mergeMethod="adjP", use.edge.length=FALSE) #Simpler plot with just dendrogram and single method merged <- mergeClusters(cl, plotInfo="mergeMethod", mergeMethod="adjP", use.edge.length=FALSE, leafType="clusters",plotType="name") #compare merged to original tableClusters(merged,whichClusters=c("mergeClusters","clusterSingle"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.