diff cluster.tools/rdata.2.out.R @ 8:a58527c632b7 draft

Uploaded
author peter-waltman
date Mon, 11 Mar 2013 16:31:29 -0400
parents 0decf3fd54bc
children
line wrap: on
line diff
--- a/cluster.tools/rdata.2.out.R	Mon Mar 04 04:11:28 2013 -0500
+++ b/cluster.tools/rdata.2.out.R	Mon Mar 11 16:31:29 2013 -0400
@@ -12,6 +12,15 @@
   q();
 }
 
+## some helper fn's
+write.2.tab <- function( mat,
+                         fname ) {
+  mat <- rbind( colnames( mat ), mat )
+  mat <- cbind( c( "ID", rownames( mat )[-1] ),
+                      mat )
+  write.table( mat, fname, sep="\t", row.names=FALSE, col.names=FALSE, quote=FALSE )
+}
+
 lib.load.quiet <- function( package ) {
    package <- as.character(substitute(package))
    suppressPackageStartupMessages( do.call( "library", list( package=package ) ) )
@@ -51,11 +60,10 @@
 if ( opt$output.format %in% c( "cls-only", "newick" ) ) {
   if ( opt$output.format == "cls-only" ) {
 
-    cl <- cbind( names( cl ), as.numeric( cl ) )
-    colnames( cl ) <- c( "ID", "Class" )
+    cl <- matrix( as.numeric( cl ), nc=1, dimnames=list( names(cl), "Class" ) )
+    opt$output.fname <- gsub( "cls-only$", "tab", opt$output.fname )
 
-    opt$output.fname <- gsub( "cls-only$", "tab", opt$output.fname )
-    write.table( cl, opt$output.fname, sep="\t", quote=FALSE, row.names=FALSE, col.names=FALSE )
+    write.2.tab( cl, opt$output.fname )
   } else {
     ##if ( opt$output.format == "newick" ) {