annotate normalize.r @ 5:6eb6f52c9562 draft

Deleted selected files
author ynewton
date Tue, 02 Oct 2012 12:10:23 -0400
parents 710627b47962
children 600872152be6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
1 #!/usr/bin/Rscript
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
2
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
3 #usage, options and doc goes here
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
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.
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
5 Usage:
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
6 normalize.r input.tab norm_type norm_by > output.tab
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
7 Example:
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
8 Rscript normalize.r test_matrix.tab median_shift column > output.tab
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
9 Rscript normalize.r test_matrix.tab mean_shift row normals.tab > output.tab
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
10 Options:
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
11 input matrix (annotated by row and column names)
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
12 normalization type; available options:
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
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
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
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
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
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
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
16 exp_fit - (only by column) ranks data and transforms exponential CDF
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
17 normal_fit - (only by column) ranks data and transforms normal CDF
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
18 weibull_0.5_fit - (only by column) ranks data and transforms Weibull CDF with scale parameter = 1 and shape parameter = 0.5
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
19 weibull_1_fit - (only by column) ranks data and transforms Weibull CDF with scale parameter = 1 and shape parameter = 1
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
20 weibull_1.5_fit - (only by column) ranks data and transforms Weibull CDF with scale parameter = 1 and shape parameter = 1.5
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
21 weibull_5_fit - (only by column) ranks data and transforms Weibull CDF with scale parameter = 1 and shape parameter = 5
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
22 normalization by:
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
23 row
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
24 column
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
25 normals_file is an optional parameter which contains a list of column headers from the input matrix, which should be considered as normals
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
26 output file is specified through redirect character >")
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
27
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
28 read_matrix <- function(in_file){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
29 header <- strsplit(readLines(con=in_file, n=1), "\t")[[1]]
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
30 cl.cols<- 1:length(header) > 1
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
31 data_matrix.df <- read.delim(in_file, header=TRUE, row.names=NULL, stringsAsFactors=FALSE, na.strings="NA", check.names=FALSE)
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
32 data_matrix <- as.matrix(data_matrix.df[,cl.cols])
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
33 rownames(data_matrix) <- data_matrix.df[,1]
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
34 return(data_matrix)
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
35
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
36 #read_mtrx <- as.matrix(read.table(in_file, header=TRUE, sep="", row.names=NULL, stringsAsFactors=FALSE, na.strings="NA")) #separate on white characters
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
37 #read_mtrx[,1]
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
38
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
39 #return(as.matrix(read.table(in_file, header=TRUE, sep="", row.names=1))) #separate on white characters
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
40 #mtrx <- read.delim(in_file, header=TRUE, sep="", row.names=NULL, stringsAsFactors=FALSE, na.strings="NA")
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
41 #print(mtrx[1,])
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
42 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
43
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
44 write_matrix <- function(data_matrix){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
45 header <- append(c("Genes"), colnames(data_matrix))
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
46 write.table(t(header), stdout(), quote=FALSE, sep="\t", row.names=FALSE, col.names=FALSE)
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
47 write.table(data_matrix, stdout(), quote=FALSE, sep="\t", row.names=TRUE, col.names=FALSE)
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
48 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
49
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
50 read_normals <- function(in_file){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
51 return(as.matrix(read.table(in_file, header=FALSE, sep="", as.is = TRUE))[, 1])
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
52 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
53
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
54 normalize <- function(data_matrix, norm_type, normals_list, tumors_list){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
55 if(norm_type == 'MEDIAN_SHIFT'){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
56 return(shift(data_matrix, 'MEDIAN', normals_list, tumors_list))
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
57 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
58 else if(norm_type == 'MEAN_SHIFT'){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
59 return(shift(data_matrix, 'MEAN', normals_list, tumors_list))
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
60 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
61 else if(norm_type == 'T_STATISTIC'){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
62 return(compute_z_score(data_matrix, normals_list, tumors_list))
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
63 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
64 else if(norm_type == 'EXPONENTIAL_FIT'){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
65 return(fit_distribution(data_matrix, 'EXPONENTIAL'))
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
66 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
67 else if(norm_type == 'NORMAL_FIT'){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
68 return(fit_distribution(data_matrix, 'NORMAL'))
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
69 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
70 else if(norm_type == 'WEIBULL_0.5_FIT'){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
71 return(fit_distribution(data_matrix, 'WEIBULL_0.5'))
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
72 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
73 else if(norm_type == 'WEIBULL_1_FIT'){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
74 return(fit_distribution(data_matrix, 'WEIBULL_1'))
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
75 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
76 else if(norm_type == 'WEIBULL_1.5_FIT'){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
77 return(fit_distribution(data_matrix, 'WEIBULL_1.5'))
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
78 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
79 else if(norm_type == 'WEIBULL_5_FIT'){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
80 return(fit_distribution(data_matrix, 'WEIBULL_5'))
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
81 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
82 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
83
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
84 shift <- function(data_matrix, shift_type, normals_list, tumors_list){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
85 return(t(apply(data_matrix, 1, shift_normalize_row, norm_type=shift_type, normals_list=normals_list, tumors_list=tumors_list)))
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
86 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
87
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
88 shift_normalize_row <- function(data_row, norm_type, normals_list, tumors_list){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
89 if(length(normals_list) == 0){ #no normals are specified
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
90 if(norm_type == 'MEDIAN'){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
91 row_stat <- median(data_row)
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
92 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
93 else if(norm_type == 'MEAN'){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
94 row_stat <- mean(data_row)
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
95 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
96 return(unlist(lapply(data_row, function(x){return(x - row_stat);})))
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
97 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
98 else{ #normals are specified
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
99 normal_values <- data_row[normals_list]
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
100 tumor_columns <- data_row[tumors_list]
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
101
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
102 if(norm_type == 'MEDIAN'){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
103 row_stat <- median(normal_values)
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
104 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
105 else if(norm_type == 'MEAN'){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
106 row_stat <- mean(normal_values)
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
107 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
108 return(unlist(lapply(tumor_columns, function(x){return(x - row_stat);})))
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
109 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
110 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
111
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
112 compute_z_score <- function(data_matrix, normals_list, tumors_list){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
113 return(t(apply(data_matrix, 1, t_stat_normalize_row, normals_list=normals_list, tumors_list=tumors_list)))
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
114 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
115
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
116 t_stat_normalize_row <- function(data_row, normals_list, tumors_list){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
117 if(length(normals_list) == 0){ #no normals are specified
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
118 row_mean <- mean(data_row)
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
119 row_sd <- sd(data_row)
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
120 return(unlist(lapply(data_row, function(x){return((x - row_mean)/row_sd);})))
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
121 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
122 else{ #normals are specified
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
123 normal_values <- data_row[normals_list]
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
124 normal_mean <- mean(normal_values)
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
125 normal_sd <- sd(normal_values)
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
126 normalized_normals <- unlist(lapply(normal_values, function(x){return((x - normal_mean)/normal_sd);}))
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
127
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
128 tumor_values <- data_row[tumors_list]
1
710627b47962 Uploaded
ynewton
parents: 0
diff changeset
129 normalized_tumors <- unlist(lapply(tumor_values, function(x){return((x - normal_mean)/normal_sd);}))
0
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
130
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
131 return(append(normalized_normals, normalized_tumors))
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
132 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
133 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
134
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
135 rankNA <- function(col){ #originally written by Dan Carlin
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
136 col[!is.na(col)]<-(rank(col[!is.na(col)])/sum(!is.na(col)))-(1/sum(!is.na(col)))
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
137 return(col)
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
138 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
139
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
140 fit_distribution <- function(data_matrix, dist){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
141 if(dist == 'EXPONENTIAL'){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
142 ranked_data_matrix <- apply(data_matrix,2,rankNA) #idea by Dan Carlin
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
143 return(apply(ranked_data_matrix, c(1,2), qexp))
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
144 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
145 else if(dist == 'NORMAL'){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
146 ranked_data_matrix <- apply(data_matrix,2,rankNA)
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
147 #return(apply(ranked_data_matrix, c(1,2), function(x){return(qnorm(mean=mean(x), sd=sd(x)));}))
1
710627b47962 Uploaded
ynewton
parents: 0
diff changeset
148 return(apply(ranked_data_matrix, c(1,2), qnorm, mean=0, sd=1))
0
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
149 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
150 else if(dist == 'WEIBULL_0.5'){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
151 ranked_data_matrix <- apply(data_matrix,2,rankNA)
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
152 return(apply(ranked_data_matrix, c(1,2), qweibull, scale=1, shape=0.5))
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
153 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
154 else if(dist == 'WEIBULL_1'){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
155 ranked_data_matrix <- apply(data_matrix,2,rankNA)
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
156 return(apply(ranked_data_matrix, c(1,2), qweibull, scale=1, shape=1))
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
157 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
158 else if(dist == 'WEIBULL_1.5'){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
159 ranked_data_matrix <- apply(data_matrix,2,rankNA)
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
160 return(apply(ranked_data_matrix, c(1,2), qweibull, scale=1, shape=1.5))
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
161 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
162 else if(dist == 'WEIBULL_5'){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
163 ranked_data_matrix <- apply(data_matrix,2,rankNA)
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
164 return(apply(ranked_data_matrix, c(1,2), qweibull, scale=1, shape=5))
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
165 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
166 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
167
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
168 main <- function(argv) {
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
169 #determine if correct number of arguments are specified and if normals are specified
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
170 with_normals = FALSE
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
171
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
172 if(length(argv) == 1){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
173 if(argv==c('--help')){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
174 write(argspec, stderr());
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
175 q();
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
176 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
177 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
178
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
179 if(!(length(argv) == 3 || length(argv) == 4)){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
180 write("ERROR: invalid number of arguments is specified", stderr());
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
181 q();
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
182 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
183
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
184 if(length(argv) == 4){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
185 with_normals = TRUE
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
186 normals_file <- argv[4]
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
187 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
188
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
189 #store command line arguments in variables:
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
190 input_file <- argv[1]
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
191 norm_type <- toupper(argv[2])
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
192 norm_by <- toupper(argv[3])
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
193
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
194 #read the input file(s):
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
195 data_matrix <- read_matrix(input_file)
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
196
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
197 if(with_normals){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
198 normals_list <- read_normals(normals_file)
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
199 normals_indices <- which(colnames(data_matrix) %in% normals_list)
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
200 tumor_indices <- which(!(colnames(data_matrix) %in% normals_list))
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
201 norm_by <- 'ROW'
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
202 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
203 else{
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
204 normals_indices <- c()
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
205 tumor_indices <- c()
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
206 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
207
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
208 #if normalize by columns then transpose the matrix:
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
209 if(norm_by == 'COLUMN'){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
210 data_matrix <- t(data_matrix)
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
211 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
212
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
213 #normalize:
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
214 data_matrix <- normalize(data_matrix, norm_type, normals_indices, tumor_indices)
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
215
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
216 #if normalize by columns then transpose the matrix again since we normalized the transposed matrix by row:
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
217 if(norm_by == 'COLUMN'){
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
218 data_matrix <- t(data_matrix)
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
219 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
220
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
221 write_matrix(data_matrix)
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
222 #print(data_matrix)
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
223 }
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
224
31cfcab40d8f Uploaded
ynewton
parents:
diff changeset
225 main(commandArgs(TRUE))