Mercurial > repos > peter-waltman > ucsc_cluster_tools2
diff cluster.tools/cutree.R @ 0:0decf3fd54bc draft
Uploaded
author | peter-waltman |
---|---|
date | Thu, 28 Feb 2013 01:45:39 -0500 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cluster.tools/cutree.R Thu Feb 28 01:45:39 2013 -0500 @@ -0,0 +1,52 @@ +#!/usr/bin/env Rscript +argspec <- c("tab.2.cdt.R converts a data matrix to cdt format + + Usage: + tab.2.cdt.R -d <data.file> + Optional: + -o <output_file> + \n\n") +args <- commandArgs(TRUE) +if ( length( args ) == 1 && args =="--help") { + write(argspec, stderr()) + q(); +} + +lib.load.quiet <- function( package ) { + package <- as.character(substitute(package)) + suppressPackageStartupMessages( do.call( "library", list( package=package ) ) ) +} + +lib.load.quiet( getopt ) +lib.load.quiet( ctc ) +if ( any( c( 'flashClust', 'fastcluster' ) %in% installed.packages() ) ) { + if ( 'flashClust' %in% installed.packages() ) { + lib.load.quiet( flashClust ) + } else { + if ( 'fastcluster' %in% installed.packages() ) { + lib.load.quiet( fastcluster ) + } + } +} + +spec <- matrix( c( "dataset", "d", 1, "character", + "num.k", "k", 1, "integer", + "output.fname", "o", 2, "character" + ), + nc=4, + byrow=TRUE + ) + + +opt <- getopt( spec=spec ) +if ( is.null( opt$output.fname ) ) { opt$output.fname <- file.path( opt$output.report.dir, paste( "data", opt$output.format, sep="." ) ) } + + +load( opt$dataset ) ## should load the cl, treecl.res (or partcl.res) and data +if ( exists( 'treecl.res' ) ) { + cutree.res <- cutree( treecl.res, k=opt$num.k ) + cl <- cutree.res + save( file=opt$output.fname, treecl.res, cl, data ) +} else { + stop( "no hierarchical clustering result found!\n" ) +}