Mercurial > repos > ynewton > plot_distribution
comparison plot_distribution.r @ 2:cf8d0d54bc78 draft
Uploaded
author | ynewton |
---|---|
date | Fri, 18 Jan 2013 12:18:04 -0500 |
parents | f91478b63ec6 |
children |
comparison
equal
deleted
inserted
replaced
1:81d08949af15 | 2:cf8d0d54bc78 |
---|---|
1 #!/usr/bin/Rscript | 1 #!/usr/bin/Rscript |
2 | 2 |
3 #usage, options and doc goes here | 3 #usage, options and doc goes here |
4 argspec <- c("normalize.r - takes any flat file and normalizes the rows or the columns using various normalizations (median_shift, mean_shift, t_statistic (z-score), exp_fit, normal_fit, weibull_0.5_fit, weibull_1_fit, weibull_1.5_fit, weibull_5_fit). Requires a single header line and a single cloumn of annotation. | 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. |
5 Usage: | 5 Usage: |
6 normalize.r input.tab norm_type norm_by > output.tab | 6 plot_distribution.r input_matrix.tab output_file.pdf |
7 Example: | 7 Example: |
8 Rscript normalize.r test_matrix.tab median_shift column > output.tab | 8 Rscript plot_distribution.r input_matrix.tab output_file.pdf |
9 Rscript normalize.r test_matrix.tab mean_shift row normals.tab > output.tab | |
10 Options: | 9 Options: |
11 input matrix (annotated by row and column names) | 10 input file name |
12 normalization type; available options: | 11 output file name") |
13 median_shift - shifts all values by the median or the row/column if no normals are specified, otherwise shifts by the median of normals | |
14 mean_shift - shifts all values by the mean or the row/column if no normals are specified, otherwise shifts by the mean of normals | |
15 t_statistic - converts all values to z-scores; if normals are specified then converts to z-scores within normal and non-normal classes separately | |
16 exp_fit - (only by column) ranks data and transforms exponential CDF | |
17 normal_fit - (only by column) ranks data and transforms normal CDF | |
18 weibull_0.5_fit - (only by column) ranks data and transforms Weibull CDF with scale parameter = 1 and shape parameter = 0.5 | |
19 weibull_1_fit - (only by column) ranks data and transforms Weibull CDF with scale parameter = 1 and shape parameter = 1 | |
20 weibull_1.5_fit - (only by column) ranks data and transforms Weibull CDF with scale parameter = 1 and shape parameter = 1.5 | |
21 weibull_5_fit - (only by column) ranks data and transforms Weibull CDF with scale parameter = 1 and shape parameter = 5 | |
22 normalization by: | |
23 row | |
24 column | |
25 normals_file is an optional parameter which contains a list of column headers from the input matrix, which should be considered as normals | |
26 output file is specified through redirect character >") | |
27 | 12 |
28 read_matrix <- function(in_file){ | 13 read_matrix <- function(in_file){ |
29 header <- strsplit(readLines(con=in_file, n=1), "\t")[[1]] | 14 header <- strsplit(readLines(con=in_file, n=1), "\t")[[1]] |
30 cl.cols<- 1:length(header) > 1 | 15 cl.cols<- 1:length(header) > 1 |
31 data_matrix.df <- read.delim(in_file, header=TRUE, row.names=NULL, stringsAsFactors=FALSE, na.strings="NA", check.names=FALSE) | 16 data_matrix.df <- read.delim(in_file, header=TRUE, row.names=NULL, stringsAsFactors=FALSE, na.strings="NA", check.names=FALSE) |
38 in_file <- argv[1] | 23 in_file <- argv[1] |
39 out_file <- argv[2] | 24 out_file <- argv[2] |
40 sink('/dev/null') | 25 sink('/dev/null') |
41 | 26 |
42 input_data <- read_matrix(in_file) | 27 input_data <- read_matrix(in_file) |
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)] | |
43 | 32 |
44 pdf(out_file, bg="white") | 33 pdf(out_file, bg="white") |
45 par(mfrow=c(1,1)) | 34 par(mfrow=c(1,1)) |
46 hist(input_data, col="lightblue", labels=TRUE, main="Histogram", xlab="") | 35 hist(input_data.nona, col="lightblue", labels=TRUE, main="Histogram", xlab="") |
47 plot(density(input_data), type="l", col="blue", main="Density") | 36 plot(density(input_data.nona), type="l", col="blue", main="Density") |
48 dev.off() | 37 dev.off() |
49 } | 38 } |
50 | |
51 main(commandArgs(TRUE)) | 39 main(commandArgs(TRUE)) |