"agglomOutput" <-
function(matrix, params) {
##if(params$method == "upgma"){
clustMethod <- params$clustMethod
distfunc <- params$distfunc
k <- params$k
id <- params$id
weights <- params$weights
##}
##else{
##clustMethod <- "average"
##distfunc <- "euclidean"
##height <- 2
##}
##check to see if input is a matrix
##otherwise, stop
if(is.matrix(matrix)) {
##calculate appropriate distance matrix
distmatrix <- switch(distfunc, euclidean = dist(matrix),
correlation = as.dist(1 - cor(t(matrix))), weightedeuclidean=distweight(matrix, weights=weights))
##do clustering
tree <- hclust(distmatrix, method = clustMethod)
##if k is numeric
##cut tree at height that corresponds to cluster number
if(is.numeric(k)) {
tmp <- cutree(as.hclust(tree), k=k)}
##else, inspect tree to cut into clusters
else {tmp <- inspectTree(tree, id)}
##output data file with cluster info
#output <- as.data.frame(cbind(tmp, matrix))
output <- as.data.frame(tmp)
##sort output file
#output <- output[order(output[,1]),]
##output file
output
}
else{
stop("Input is not a matrix.")
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.