Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1.  
  2. ##### #####
  3. # Practical training: Microarray data analysis #
  4. ##### #####
  5.  
  6. ####
  7. # Part1 : Correction of experimental biases
  8. ####
  9.  
  10. # all graphs will be saved in a PDF file
  11.  
  12. pdf("normAnalysis.pdf")
  13.  
  14. # setwd("/home/cyril/session1_microarray/data_forStudent")
  15. # reading of GPR file
  16. GprFile = "dataFile1_normAnalysis.gpr"
  17. library(marray)
  18. rawdata = read.GenePix(GprFile)
  19.  
  20. # intensity values in red channel
  21. rawdata@maRf
  22. # intensity values in green channel
  23. rawdata@maGf
  24.  
  25. # visualization of background signals
  26. image(rawdata, xvar = "maRb", main = "Red background (with flags)")
  27. image(rawdata, xvar = "maGb", main = "Green background (with flags)")
  28.  
  29. # spots that are flaggued will be eliminated from further analyses
  30. # their intensity values are replaced by NA (missing values)
  31. copyRawData <- rawdata
  32. copyRawData@maRb[rawdata@maW < 0] = NA
  33. copyRawData@maGb[rawdata@maW < 0] = NA
  34.  
  35. # visualization of background signals
  36. image(copyRawData, xvar = "maRb", main = "Red background (without flag)")
  37. image(copyRawData, xvar = "maGb", main = "Green background (without flag)")
  38.  
  39. # flag location on the slide
  40. MyColor = maPalette(low = "blue", high = "white" , k = 10)
  41. image(rawdata, xvar = "maW", col = MyColor, zlim = c(min(rawdata@maW), max(rawdata@maW)), main = "Location of Flags on the slide")
  42.  
  43. # spots that are flaggued are excluded from the analysis
  44. rawdataWithoutFlags = rawdata
  45.  
  46. rawdataWithoutFlags@maRb[rawdataWithoutFlags@maW < 0] = NA
  47. rawdataWithoutFlags@maGb[rawdataWithoutFlags@maW < 0] = NA
  48. rawdataWithoutFlags@maRf[rawdataWithoutFlags@maW < 0] = NA
  49. rawdataWithoutFlags@maGf[rawdataWithoutFlags@maW < 0] = NA
  50.  
  51. # no background correction is performed here
  52. rawdataWithoutFlags@maGb[] = 0
  53. rawdataWithoutFlags@maRb[] = 0
  54.  
  55. # comparison of Cy5 and Cy3 signals
  56. plot(rawdataWithoutFlags, main = "MA plot before normalization")
  57. boxplot(rawdataWithoutFlags, main = "Boxplot before normalization")
  58.  
  59. # three different procedures for signal normalization
  60. rawdataWithoutFlagsNorm <- maNorm(rawdataWithoutFlags, norm = "median", echo = T)
  61. rawdataWithoutFlagsNorm2 <- maNorm(rawdataWithoutFlags, norm = "loess", echo = T)
  62. rawdataWithoutFlagsNorm3 <- maNorm(rawdataWithoutFlags, norm = "printTipLoess", echo = T)
  63.  
  64. # several plots allow for comparison of the normalization methods
  65. plot(rawdataWithoutFlagsNorm, legend.func = NULL, main = "norm = Median")
  66. plot(rawdataWithoutFlagsNorm2, legend.func = NULL, main = "norm = Loess")
  67. plot(rawdataWithoutFlagsNorm3, legend.func = NULL, main = "norm = printTipLoess")
  68.  
  69. boxplot(rawdataWithoutFlagsNorm, main = "norm = Median")
  70. boxplot(rawdataWithoutFlagsNorm2, main = "norm = Loess")
  71. boxplot(rawdataWithoutFlagsNorm3, main = "norm = printTipLoess")
  72.  
  73. plot(density(maM(rawdataWithoutFlagsNorm2),na.rm = T), lwd = 2, col = 2, main = "Distribution of log(Ratio)")
  74. lines(density(maM(rawdataWithoutFlags), na.rm = T), lwd = 2)
  75. abline(v = 0)
  76. legend(2,0.8,c("Before normalization","After normalization"), fill = c(1,2))
  77.  
  78. # close PDF image file
  79. dev.off()
  80.  
  81.  
  82. #####
  83. # Part2: Search for differentially expressed genes
  84. #####
  85.  
  86. # Replicated data
  87. dataFile <- "dataFile_diffAnalysis.txt"
  88. data <- as.matrix(read.table(dataFile, row.names = 1, header = T))
  89.  
  90. # library LIMMA
  91. library(limma)
  92.  
  93. # Linear model estimation
  94. fit <- lmFit(data)
  95.  
  96. # Bayesian statistics
  97. limma.res <- eBayes(fit)
  98.  
  99. # selection of differentially expressed genes (p-vlaue threshold = 0.01 here)
  100. allgenes.limma <- topTable(limma.res, number = nrow(data))
  101. siggenes.limma <- allgenes.limma[allgenes.limma[,4] < 0.01,]
  102. dim(siggenes.limma[siggenes.limma[,2] > 0,])[1]
  103. dim(siggenes.limma[siggenes.limma[,2] < 0,])[1]
  104.  
  105. write.table(siggenes.limma[siggenes.limma[,2] > 0,],
  106. row.names = T, quote = F, sep = "\t",
  107. file = "limma_up_signif_genes.txt")
  108.  
  109. write.table(siggenes.limma[siggenes.limma[,2] < 0,],
  110. row.names = T, quote = F, sep = "\t",
  111. file = "limma_low_signif_genes.txt")
  112.  
  113. # Volcano plot
  114. volcanoplot(limma.res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement