comparison cluster.tools/cutree.R @ 2:b442996b66ae draft

Uploaded
author peter-waltman
date Wed, 27 Feb 2013 20:17:04 -0500
parents
children
comparison
equal deleted inserted replaced
1:e25d2bece0a2 2:b442996b66ae
1 #!/usr/bin/env Rscript
2 argspec <- c("tab.2.cdt.R converts a data matrix to cdt format
3
4 Usage:
5 tab.2.cdt.R -d <data.file>
6 Optional:
7 -o <output_file>
8 \n\n")
9 args <- commandArgs(TRUE)
10 if ( length( args ) == 1 && args =="--help") {
11 write(argspec, stderr())
12 q();
13 }
14
15 lib.load.quiet <- function( package ) {
16 package <- as.character(substitute(package))
17 suppressPackageStartupMessages( do.call( "library", list( package=package ) ) )
18 }
19
20 lib.load.quiet( getopt )
21 lib.load.quiet( ctc )
22 if ( any( c( 'flashClust', 'fastcluster' ) %in% installed.packages() ) ) {
23 if ( 'flashClust' %in% installed.packages() ) {
24 lib.load.quiet( flashClust )
25 } else {
26 if ( 'fastcluster' %in% installed.packages() ) {
27 lib.load.quiet( fastcluster )
28 }
29 }
30 }
31
32 spec <- matrix( c( "dataset", "d", 1, "character",
33 "num.k", "k", 1, "integer",
34 "output.fname", "o", 2, "character"
35 ),
36 nc=4,
37 byrow=TRUE
38 )
39
40
41 opt <- getopt( spec=spec )
42 if ( is.null( opt$output.fname ) ) { opt$output.fname <- file.path( opt$output.report.dir, paste( "data", opt$output.format, sep="." ) ) }
43
44
45 load( opt$dataset ) ## should load the cl, treecl.res (or partcl.res) and data
46 if ( exists( 'treecl.res' ) ) {
47 cutree.res <- cutree( treecl.res, k=opt$num.k )
48 cl <- cutree.res
49 save( file=opt$output.name, treecl.res, cl, data )
50 } else {
51 }