记录一次获取top1000表达量以及字符串简单处理

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

目的:

1,提取指定列表达量之和排名前1000的id
2,修改ID列为指定名称(字符串split)

过程:

#step1, load origin data
input_table <- fread(in_file_main,header = T,fill=T,quote=""); #load file;
  paste("1_load file success!\n")
#step2,进行top1000fpkm表达量的计算
input_table$sum_top1000 <- rowSums(input_table[,c(29:40,45)])
  paste("2_calculate data of sum fpkm success!\n")
  #head(input_table$sum_top1000)

#step3,获取top1000的fpkm以及gopath注释
  #step3.1 get index of top 1000
  sort_index <- as.data.frame(sort(input_table$sum_top1000, decreasing = TRUE,index.return = TRUE ))
  sort_index_top1000 <- sort_index[1:1000,2]
  #step3.2 get data by index of top 1000
  exp_data <- data.frame(input_table[sort_index_top1000,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")
  z <- unlist(y)
  
  colnames(exp_data)[2:14] <- z
  
  write.table(exp_data,sep="\t",col.names =TRUE,row.names = FALSE,file = out_file_name2) 
  paste("4_1_write table of cluster success!")
上一篇下一篇

猜你喜欢

热点阅读