view build_matrix.R @ 21:7e22d880e551 draft

Uploaded
author greg
date Fri, 11 Aug 2017 09:29:18 -0400
parents 50f64f662726
children f8e36f4b71c7
line wrap: on
line source

#!/usr/bin/env Rscript

suppressPackageStartupMessages(library("optparse"))

option_list <- list(
    make_option(c("-i", "--input"), action="store", dest="input", help="Input .bed.gz file produced by prepMat"),
    make_option(c("-o", "--output"), action="store", dest="output", help="Output file"),
    make_option(c("-w", "--work_dir"), action="store", dest="work_dir", help="Working directory")
)

parser <- OptionParser(usage="%prog [options] file", option_list=option_list)
args <- parse_args(parser, positional_arguments=TRUE)
opt <- args$options

#data_table <- read.table(opt$input)
#as.matrix(data_table)
#status <- match(data_table[,3], missing)
#data_table[,3] <- paste(opt$work_dir, data_table[,1], ".", data_table[,2], ".bed.gz", sep="")
#data_table <- data_table[is.na(status)==TRUE,]
#write.table(array(data_table, dim=c(length(data_table)/3, 3)), file=opt$output, quote=FALSE, row.names=FALSE, col.names=FALSE)

x=as.matrix(read.table(opt$input))
t=match(x[,3],missing)
x[,3]=paste(opt$work_dir, x[,1],".",x[,2],".bed.gz", sep="")
x=x[is.na(t)==T,]
write.table(array(x,dim=c(length(x)/3,3)), opt$output, quote=F,row.names=F,col.names=F)