preprocessCore分位数标准化

library("preprocessCore")
library("ggplot2")
data <- read.table("mouse_gc.xls",sep="\t",header = TRUE)
rownames(data) <- data$GeneID
#rownames(data) <- data[,1]
#data_mat <- data.matrix(data[,-1]) 
quantile_normalisation <- function(df){
  df_rank <- apply(df,2,rank,ties.method="min")
  df_sorted <- data.frame(apply(df, 2, sort))
  df_mean <- apply(df_sorted, 1, mean)

  index_to_mean <- function(my_index, my_mean){
    return(my_mean[my_index])
  }

  df_final <- apply(df_rank, 2, index_to_mean, my_mean=df_mean)
  rownames(df_final) <- rownames(df)
  return(df_final)
}
new_data <- quantile_normalisation(data[,2:19])
boxplot(data)
boxplot(new_data)
write.table(new_data, file="111.xls", sep="\t", quote=F, row.names=T, col.names=T)
##############################################################
col_names <- colnames(data)
row_names <- rownames(data)
data <- as.matrix(data)
b=normalize.quantiles(data)
boxplot(b)
##使用normalize.quantiles函数和上面结果相同

Posted

in

,

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *