0
|
1 #!/usr/bin/Rscript
|
|
2
|
|
3 #usage, options and doc goes here
|
2
|
4 argspec <- c("plot_distribution.r - plots distribution of the value in the list or the matrix. Assumes the first line and the first column are annotations.
|
0
|
5 Usage:
|
2
|
6 plot_distribution.r input_matrix.tab output_file.pdf
|
0
|
7 Example:
|
2
|
8 Rscript plot_distribution.r input_matrix.tab output_file.pdf
|
0
|
9 Options:
|
2
|
10 input file name
|
|
11 output file name")
|
0
|
12
|
|
13 read_matrix <- function(in_file){
|
|
14 header <- strsplit(readLines(con=in_file, n=1), "\t")[[1]]
|
|
15 cl.cols<- 1:length(header) > 1
|
|
16 data_matrix.df <- read.delim(in_file, header=TRUE, row.names=NULL, stringsAsFactors=FALSE, na.strings="NA", check.names=FALSE)
|
|
17 data_matrix <- as.matrix(data_matrix.df[,cl.cols])
|
|
18 rownames(data_matrix) <- data_matrix.df[,1]
|
|
19 return(data_matrix)
|
|
20 }
|
|
21
|
|
22 main <- function(argv) {
|
|
23 in_file <- argv[1]
|
|
24 out_file <- argv[2]
|
|
25 sink('/dev/null')
|
|
26
|
|
27 input_data <- read_matrix(in_file)
|
2
|
28 input_data.df <- as.data.frame(input_data)
|
|
29 input_data.lst <- as.list(input_data.df)
|
|
30 input_data.unlst <- unlist(input_data.lst)
|
|
31 input_data.nona <- input_data.unlst[!is.na(input_data.unlst)]
|
0
|
32
|
|
33 pdf(out_file, bg="white")
|
|
34 par(mfrow=c(1,1))
|
2
|
35 hist(input_data.nona, col="lightblue", labels=TRUE, main="Histogram", xlab="")
|
|
36 plot(density(input_data.nona), type="l", col="blue", main="Density")
|
|
37 dev.off()
|
0
|
38 }
|
|
39 main(commandArgs(TRUE)) |