找回密码
 立即注册
查看: 6208|回复: 0

基因表达分析

[复制链接]
发表于 2014-10-25 18:12:40 | 显示全部楼层 |阅读模式
本帖最后由 上善若水 于 2014-10-25 18:16 编辑

求大家来帮我解答下  R语言这样做的对吗



  1. library(hgu133a.db);

  2. oriInData<-read.table("D:/实验1/GSE15852_series_matrix.txt",header=TRUE,sep="\t")
  3. for(i in 2:length(oriInData[1,])){
  4. oriInData[,i]<-log2(oriInData[,i])
  5. }
  6. label<-read.table("D:/实验1/classlable15852.txt")
  7. ##############################################################
  8. ###############处理数据###########################3
  9. ###############################################################
  10. x<-hgu133aENTREZID;
  11. probeGene<-toTable(x);
  12. #Normally, len should be equal to the number of rows of relationship inforinDataion.
  13. locations<-match(as.character(oriInData[,1]),probeGene$probe_id);
  14. probegene<-probeGene$gene_id[locations];
  15. oriInData[,length(oriInData[1,])+1]<-probegene
  16. oriInData<-na.omit(oriInData)
  17. gene<-oriInData[,length(oriInData[1,])];
  18. probe<-unique(gene)
  19. inData<-matrix(0,nrow=length(probe), ncol=length(oriInData[1,])-2)
  20. for(i in 1:length(probe)){
  21.     if(length(which(gene==probe))==1){
  22.      inData[i,]<-as.numeric(oriInData[which(gene==probe),2:(length(oriInData)-1)])
  23.      }
  24.      else if(length(which(gene==probe))>1){
  25.      inData[i,]<-as.numeric(colMeans(oriInData[which(gene==probe),2:(length(oriInData)-1)]))
  26.      }
  27. }     
  28. inData<-as.data.frame(inData,row.names=probe)
  29. names(inData)<-names(oriInData)[2:(length(oriInData[1,])-1)]
  30. ###############处理类标签######################################
  31. b<-as.vector(label[1,])
  32. b[which(b=="normal breast tissue")]<-rep(0,length(which(b=="normal breast tissue")))
  33. b[which(b=="1breast tumor tissue")]<-rep(1,length(which(b=="breast tumor tissue")))
  34. classLabel<-as.numeric(b)
  35. #########################计算T-test函数######################################     
  36. calT <- function(inData, classLabel) {
  37.         m <- length(ind1 <- which(classLabel == 1))
  38.         n <- length(ind2 <- which(classLabel == 0))
  39.         inData1 <- inData[, ind1]
  40.         inData2 <- inData[, ind2]
  41.         rmean1 <- rowMeans(inData1)
  42.         rmean2 <- rowMeans(inData2)
  43.         ss1 <- rowSums((inData1 - rmean1)^2)
  44.         ss2 <- rowSums((inData2 - rmean2)^2)
  45.         tt <- (m + n - 2)^0.5 * (rmean2 - rmean1)/((1/m + 1/n) *
  46.             (ss1 + ss2))^0.5
  47.         return(list(T = tt, df = m + n - 2))
  48.     }
  49. deGene<-calT(inData,classLabel)[[1]];
  50. ####################################################################
复制代码

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|R语言中文网

GMT+8, 2024-11-22 14:09 , Processed in 0.024215 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表