0
|
1 #!/usr/bin/env Rscript
|
|
2 argspec <- c("remove.tcga.normals.R removes TCGA normal samples from a given matrix
|
|
3
|
|
4 Usage:
|
|
5 remove.tcga.normals.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.tumors.tab' }
|
|
30
|
|
31 mat <- as.matrix( read.delim( opt$data.fname, row.names=1, check.names=FALSE ) )
|
|
32 if ( length( strsplit( colnames( mat ), "-" )[[1]] ) == 4 ) {
|
|
33 cnames <- sapply( strsplit( colnames( mat ), "-" ), function(x) x[4] )
|
|
34 norms <- grepl( "^1", cnames )
|
|
35
|
|
36 if ( sum( norms ) > 0 ) {
|
|
37 tumors <- ! norms
|
|
38 mat <- mat[, tumors ]
|
|
39 }
|
|
40 }
|
|
41 write.table( mat, opt$output.fname, quote=FALSE, sep="\t", col.names=NA )
|