记录一次大文件读取以及热图简单绘制

2019-01-12  本文已影响0人  EngineerChicken

踩过的坑:

fill :logical. If TRUE then in case the rows have unequal length, blank fields are implicitly added. See ‘Details’.
#此脚本用于提取三代测序中的数据,用于工作中,等技术高了再回来改进!
#2019年1月10日14:50:45
#liyuan
#功能:提取组织中表达所有的基因及表达量,并进行聚类图的绘制。

setwd("~/R_Workspace/DATA/1-11/1_表达谱/1_all/")
#step1, load main
#在这里使用data.table::fread比较好,因为速度贼快!
in_file_main <- "~/R_Workspace/DATA/1-11/gene.description.xls"
input_main <- data.table::fread(in_file_main,header = TRUE,fill = T,quote="",check.names = F)#需要增加fill=T
prefix_out <- "exp_pro.cluster.All" 
out_file_name1 <- paste(prefix_out,".tiff",sep="")
out_file_name2 <- paste(prefix_out,".xls",sep="")

#step2, remove exp <= 0,使用rowSums这个方法一次就能出结果,我还傻乎乎写了半天的for-if
row_index <- which(rowSums(input_table[,c(29:40,45)]) > 0);paste("2_calculate data of diff and save index of diff success !")
#step3,获取diff组织列以及gopath注释列
exp_data <- data.frame(input_table[row_index,c(1,29:40,45,176:185)]) #索引列自动作为row.names  

#step4, draw exp_cluster by above data.
  #step4.1, tran rownames
  x <- "brain   eye fin gill    hood    heart   intestine   muscle  kidney  liver   testis  spleen  skin"#new row
  y <- strsplit(x,split = "\t")
  colnames(exp_data)[2:14] <- unlist(y)
  data.table::fwrite(exp_data,sep="\t",col.names =TRUE,
              row.names = FALSE,file = out_file_name2);paste("3_1_write table of cluster success!")
  
  #step4.2, draw cluster,just for test1:1000
  library(pheatmap)
   p <- pheatmap(log2(exp_data[1:1000,2:14]+1),scale="row",
                 cluster_cols=T,#是否按列聚类
                 cluster_rows=T,#是否按行聚类
                 show_rownames=F,
                 color = colorRampPalette(c("MediumBlue","white","red"))(256),
                 legend_breaks = -10:10,#图例范围
                 fontsize = 18,
                 filename = out_file_name1#保存文件命名
   );paste("3_2_draw cluster success and exit!")
上一篇下一篇

猜你喜欢

热点阅读