-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmatrix_matrix_operation.R
executable file
·59 lines (39 loc) · 1.47 KB
/
matrix_matrix_operation.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env Rscript
##------------
## LIBRARIES
##------------
suppressPackageStartupMessages(library("optparse"))
options(stringsAsFactors=F)
##################
# OPTION PARSING
##################
option_list <- list(
make_option(c("-A", "--matrix_A"),
help="the matrix you want to subtract from, WITH header (A-B)"),
make_option(c("-B", "--matrix_B"),
help="the matrix you want to subtract, WITH header (A-B)"),
make_option(c("-r", "--replace_NA_with"), type="numeric",
help="value you want to replace NA with, if null NAs are not replaced and difference will be NA"),
make_option(c("-o", "--output"), default="out.tsv",
help="additional prefix for otuput [default=%default]"),
make_option(c("-e", "--expression"),
help="expression you want to corresponding cells of the matrices, e.g. A-B"),
make_option(c("-v", "--verbose"), action="store_true", default=FALSE,
help="verbose output [default=%default]")
)
parser <- OptionParser(usage = "%prog [options] file", option_list=option_list)
arguments <- parse_args(parser, positional_arguments = TRUE)
opt <- arguments$options
if(opt$verbose) {print(opt)}
###################
# BEGIN #
###################
A = read.table(opt$matrix_A, h=T)
B = read.table(opt$matrix_B, h=T)
if (!is.null(opt$replace_NA_with)) {
A <- replace(A, is.na(A), opt$replace_NA_with)
B <- replace(B, is.na(B), opt$replace_NA_with)
}
M = eval(parse(text=opt$expression))
write.table(M, opt$output, quote=F, row.names=T, sep="\t")
q(save='no')