Mercurial > repos > peter-waltman > ucsc_cluster_tools2
comparison cluster.tools/remove.nulls.R @ 0:0decf3fd54bc draft
Uploaded
author | peter-waltman |
---|---|
date | Thu, 28 Feb 2013 01:45:39 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:0decf3fd54bc |
---|---|
1 #!/usr/bin/env Rscript | |
2 argspec <- c("remove.degenerate.values.R replaces degenerate values (NaNs & Infs) with a user-specified value | |
3 | |
4 Usage: | |
5 remove.degenerate.values.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 lib.load.quiet(getopt) | |
20 | |
21 spec <- matrix( c( "data.fname", "d", 1, "character", | |
22 "output.fname", "o", 2, "character" | |
23 ), | |
24 nc=4, | |
25 byrow=TRUE | |
26 ) | |
27 | |
28 opt <- getopt( spec=spec ) | |
29 if ( is.null( opt$output.fname ) ) { opt$output.fname <- 'merge_merge.reals.tab' } | |
30 | |
31 mat <- as.matrix( read.delim( opt$data.fname, row.names=1, check.names=FALSE ) ) | |
32 cnames <- sapply( strsplit( colnames( mat ), "\\s+" ), function(x) x[1] ) | |
33 colnames( mat ) <- cnames | |
34 nulls <- mat[ , grepl( "^na", cnames ) ] | |
35 reals <- mat[ , !grepl( "^na", cnames ) ] | |
36 | |
37 reals <- cbind( rownames( reals ), reals ); rownames( reals ) <- NULL | |
38 reals <- rbind( colnames( reals ), reals ); colnames( reals ) <- NULL | |
39 reals[1,1] <- "ID" | |
40 write.table( reals, opt$output.fname, quote=FALSE, sep="\t", row.names=FALSE, col.names=FALSE ) |