-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetRandomizedData.R
39 lines (28 loc) · 1.48 KB
/
getRandomizedData.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/Rscript
#####################################################################################
#####################################################################################
####### Function to prepare randomized inout dataset for NMF (Factorization Ranks) ##
#####################################################################################
#####################################################################################
library(fpc);
library(NMF);
args <- commandArgs(trailingOnly = TRUE)
options("scipen"=1000)
input.datamatrix <- args[1];
output.dir <- args[2];
## Import the real data matrix and split between genomic coordinates and numeric values
mx <- read.table(file=input.datamatrix, header=FALSE, stringsAsFactors=FALSE, sep="\t")
genomic.bins <- mx[,c(1:3)];
mx <- as.matrix(mx[,c(4:ncol(mx))] )
#colnames(genomic.bins) <- c("chrom", "chromStart", "chromEnd")
rmx <- randomize(mx);
# Define the randomized data matrix file name:
parts <- unlist(strsplit(input.datamatrix, split="/"))
filename <- parts[length(parts)]
outputfilename <- gsub("Filtered", "Random", filename);
if (!(dir.exists(file.path(output.dir, "random") ) ) ) { dir.create(file.path(output.dir,"random")) }
random.matrix <- data.frame(genomic.bins, rmx, stringsAsFactors=FALSE)
# Export output file
output.dir <- file.path(output.dir, "random")
write.table(random.matrix, file=file.path(output.dir, outputfilename), col.names=FALSE, row.names=FALSE, sep="\t", quote=FALSE, dec=".")
## End script