TSHeatmaps5dev2.R 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. #!/usr/bin/env Rscript
  2. # Makes heat maps of multiple experiments
  3. #
  4. # Updated 240724 Bryan C Roessler to improve file operations and portability
  5. # I tried to leave as much logic intact as possible, just feeding in vars in a better way
  6. # NOTE: The script now has 7 required arguments and a variable number of input experiments
  7. # @arg $1 string StudyInfo.csv file
  8. # @arg $2 string gene_ontology_edit.obo file
  9. # @arg $3 string go_terms.tab file
  10. # @arg $4 string All_SGD_GOTerms_for_QHTCPtk.csv
  11. # @arg $5 string base directory
  12. # @arg $6 string output directory
  13. library("ontologyIndex")
  14. library("ggplot2")
  15. library("RColorBrewer")
  16. library("grid")
  17. library("ggthemes")
  18. # library("plotly")
  19. # library("htmlwidgets")
  20. library("extrafont")
  21. library("stringr")
  22. library("org.Sc.sgd.db")
  23. library("ggrepel")
  24. library("gplots")
  25. # Load arguments
  26. args <- commandArgs(TRUE)
  27. study_info_file <- args[1]
  28. ontology_file <- args[2]
  29. sgd_terms_tfile <- args[3]
  30. all_sgd_terms_csv <- args[4]
  31. base_dir <- args[5]
  32. output_dir <- args[6]
  33. study_nums <- args[7:length(args)]
  34. # Import standard tables used in Sean's code That should be copied to each ExpStudy
  35. labels <- read.csv(file = study_info_file, stringsAsFactors = FALSE)
  36. Ontology <- get_ontology(file = ontology_file, propagate_relationships = "is_a", extract_tags = "minimal")
  37. GO2ALLORFs <- as.list(org.Sc.sgdGO2ALLORFS) # all ORFs associated with GO term
  38. Terms <- read.delim(file = sgd_terms_tfile,
  39. header = FALSE,
  40. quote = "",
  41. col.names = c("GO_ID", "GO_Term", "GO_Aspect", "GO_Term_Definition")
  42. )
  43. XX3 <- read.csv(file = all_sgd_terms_csv, stringsAsFactors = FALSE, header = TRUE)
  44. XX3[, 1] <- paste0("GO:", formatC(XX3[, 1], width = 7, flag = "0"))
  45. XX3[, 2] <- gsub(pattern = " ", replacement = "_", x = XX3[, 2])
  46. XX3[, 2] <- gsub(pattern = "/", replacement = "_", x = XX3[, 2])
  47. # Load input files
  48. for (study_num in study_nums) {
  49. input_file <- file.path(base_dir, paste("Exp", study_num), zscores, "zscores_interaction.csv")
  50. if (file.exists(input_file)) {
  51. assign(paste(X, study_num), read.csv(file = input_file, stringsAsFactors = FALSE, header = TRUE))
  52. assign(paste(Name, study_num), labels[study_num, 2])
  53. }
  54. }
  55. for (study_num in study_nums) {
  56. eval(paste("function", study_num))
  57. }
  58. if (length(study_nums) > 0) {
  59. X1$ORF <- X1$OrfRep
  60. X1$ORF <- gsub("_1", "", x = X1$ORF)
  61. X1$ORF <- gsub("_2", "", x = X1$ORF)
  62. X1$ORF <- gsub("_3", "", x = X1$ORF)
  63. X1$ORF <- gsub("_4", "", x = X1$ORF)
  64. X1$Score_L <- "No Effect"
  65. try(X1[is.na(X1$Z_lm_L), ]$Score_L <- "No Growth")
  66. try(X1[!is.na(X1$Z_lm_L) & X1$Z_lm_L >= 2, ]$Score_L <- "Deletion Enhancer")
  67. try(X1[!is.na(X1$Z_lm_L) & X1$Z_lm_L <= -2, ]$Score_L <- "Deletion Suppressor")
  68. X1$Score_K <- "No Effect"
  69. try(X1[is.na(X1$Z_lm_K), ]$Score_K <- "No Growth")
  70. try(X1[!is.na(X1$Z_lm_K) & X1$Z_lm_K >= 2, ]$Score_K <- "Deletion Suppressor")
  71. try(X1[!is.na(X1$Z_lm_K) & X1$Z_lm_K <= -2, ]$Score_K <- "Deletion Enhancer")
  72. # Express the na data as 0.001 in X1 for K and L
  73. X1[is.na(X1$Z_lm_L), ]$Z_lm_L <- 0.001
  74. X1[is.na(X1$Z_lm_K), ]$Z_lm_K <- 0.001
  75. X1$Rank_L <- rank(X1$Z_lm_L)
  76. X1$Rank_K <- rank(X1$Z_lm_K)
  77. X1 <- X1[order(X1$OrfRep, decreasing = FALSE), ]
  78. colnames(X1) <- paste0(colnames(X1), "_X1")
  79. }
  80. if (length(study_nums) > 1) {
  81. X2$ORF <- X2$OrfRep
  82. X2$ORF <- gsub("_1", "", x = X2$ORF)
  83. X2$ORF <- gsub("_2", "", x = X2$ORF)
  84. X2$ORF <- gsub("_3", "", x = X2$ORF)
  85. X2$ORF <- gsub("_4", "", x = X2$ORF)
  86. X2$Score_L <- "No Effect"
  87. try(X2[is.na(X2$Z_lm_L), ]$Score_L <- "No Growth")
  88. try(X2[!is.na(X2$Z_lm_L) & X2$Z_lm_L >= 2, ]$Score_L <- "Deletion Enhancer")
  89. try(X2[!is.na(X2$Z_lm_L) & X2$Z_lm_L <= -2, ]$Score_L <- "Deletion Suppressor")
  90. X2$Score_K <- "No Effect"
  91. try(X2[is.na(X2$Z_lm_K), ]$Score_K <- "No Growth")
  92. try(X2[!is.na(X2$Z_lm_K) & X2$Z_lm_K >= 2, ]$Score_K <- "Deletion Suppressor")
  93. try(X2[!is.na(X2$Z_lm_K) & X2$Z_lm_K <= -2, ]$Score_K <- "Deletion Enhancer")
  94. #express the na data as 0.001 in X2
  95. X2[is.na(X2$Z_lm_L), ]$Z_lm_L <- 0.001
  96. X2[is.na(X2$Z_lm_K), ]$Z_lm_K <- 0.001
  97. X2$Rank_L <- rank(X2$Z_lm_L)
  98. X2$Rank_K <- rank(X2$Z_lm_K)
  99. X2 <- X2[order(X2$OrfRep, decreasing = FALSE), ]
  100. colnames(X2) <- paste0(colnames(X2), "_X2")
  101. X <- cbind(X1, X2)
  102. }
  103. if (length(study_nums) > 2) {
  104. X3$ORF <- X3$OrfRep
  105. X3$ORF <- gsub("_1", "", x = X3$ORF)
  106. X3$ORF <- gsub("_2", "", x = X3$ORF)
  107. X3$ORF <- gsub("_3", "", x = X3$ORF)
  108. X3$ORF <- gsub("_4", "", x = X3$ORF)
  109. X3$Score_L <- "No Effect"
  110. try(X3[is.na(X3$Z_lm_L), ]$Score_L <- "No Growth")
  111. try(X3[!is.na(X3$Z_lm_L) & X3$Z_lm_L >= 2, ]$Score_L <- "Deletion Enhancer")
  112. try(X3[!is.na(X3$Z_lm_L) & X3$Z_lm_L <= -2, ]$Score_L <- "Deletion Suppressor")
  113. X3$Score_K <- "No Effect"
  114. try(X3[is.na(X3$Z_lm_K), ]$Score_K <- "No Growth")
  115. try(X3[!is.na(X3$Z_lm_K) & X3$Z_lm_K >= 2, ]$Score_K <- "Deletion Suppressor")
  116. try(X3[!is.na(X3$Z_lm_K) & X3$Z_lm_K <= -2, ]$Score_K <- "Deletion Enhancer")
  117. # Express the na data as 0.001 in X3
  118. X3[is.na(X3$Z_lm_L), ]$Z_lm_L <- 0.001
  119. X3[is.na(X3$Z_lm_K), ]$Z_lm_K <- 0.001
  120. X3$Rank_L <- rank(X3$Z_lm_L)
  121. X3$Rank_K <- rank(X3$Z_lm_K)
  122. X3 <- X3[order(X3$OrfRep, decreasing = FALSE), ]
  123. colnames(X3) <- paste0(colnames(X3), "_X3")
  124. X <- cbind(X, X3)
  125. }
  126. if (length(study_nums) > 3) {
  127. X4$ORF <- X4$OrfRep
  128. X4$ORF <- gsub("_1", "", x = X4$ORF)
  129. X4$ORF <- gsub("_2", "", x = X4$ORF)
  130. X4$ORF <- gsub("_3", "", x = X4$ORF)
  131. X4$ORF <- gsub("_4", "", x = X4$ORF)
  132. X4$Score_L <- "No Effect"
  133. try(X4[is.na(X4$Z_lm_L), ]$Score_L <- "No Growth")
  134. try(X4[!is.na(X4$Z_lm_L) & X4$Z_lm_L >= 2, ]$Score_L <- "Deletion Enhancer")
  135. try(X4[!is.na(X4$Z_lm_L) & X4$Z_lm_L <= -2, ]$Score_L <- "Deletion Suppressor")
  136. X4$Score_K <- "No Effect"
  137. try(X4[is.na(X4$Z_lm_K), ]$Score_K <- "No Growth")
  138. try(X4[!is.na(X4$Z_lm_K) & X4$Z_lm_K >= 2, ]$Score_K <- "Deletion Suppressor")
  139. try(X4[!is.na(X4$Z_lm_K) & X4$Z_lm_K <= -2, ]$Score_K <- "Deletion Enhancer")
  140. # Express the na data as 0.001 in X4
  141. X4[is.na(X4$Z_lm_L), ]$Z_lm_L <- 0.001
  142. X4[is.na(X4$Z_lm_K), ]$Z_lm_K <- 0.001
  143. X4$Rank_L <- rank(X4$Z_lm_L)
  144. X4$Rank_K <- rank(X4$Z_lm_K)
  145. X4 <- X4[order(X4$OrfRep, decreasing = FALSE), ]
  146. colnames(X4) <- paste0(colnames(X4), "_X4")
  147. X <- cbind(X, X4)
  148. }
  149. if (length(study_nums) > 4) {
  150. X5$ORF <- X5$OrfRep
  151. X5$ORF <- gsub("_1", "", x = X5$ORF)
  152. X5$ORF <- gsub("_2", "", x = X5$ORF)
  153. X5$ORF <- gsub("_3", "", x = X5$ORF)
  154. X5$ORF <- gsub("_4", "", x = X5$ORF)
  155. X5$Score_L <- "No Effect"
  156. try(X5[is.na(X5$Z_lm_L), ]$Score_L <- "No Growth")
  157. try(X5[!is.na(X5$Z_lm_L) & X5$Z_lm_L >= 2, ]$Score_L <- "Deletion Enhancer")
  158. try(X5[!is.na(X5$Z_lm_L) & X5$Z_lm_L <= -2, ]$Score_L <- "Deletion Suppressor")
  159. X5$Score_K <- "No Effect"
  160. try(X5[is.na(X5$Z_lm_K), ]$Score_K <- "No Growth")
  161. try(X5[!is.na(X5$Z_lm_K) & X5$Z_lm_K >= 2, ]$Score_K <- "Deletion Suppressor")
  162. try(X5[!is.na(X5$Z_lm_K) & X5$Z_lm_K <= -2, ]$Score_K <- "Deletion Enhancer")
  163. # Express the na data as 0.001 in X5
  164. X5[is.na(X5$Z_lm_L), ]$Z_lm_L <- 0.001
  165. X5[is.na(X5$Z_lm_K), ]$Z_lm_K <- 0.001
  166. X5$Rank_L <- rank(X5$Z_lm_L)
  167. X5$Rank_K <- rank(X5$Z_lm_K)
  168. X5 <- X5[order(X5$OrfRep, decreasing = FALSE), ]
  169. colnames(X5) <- paste0(colnames(X5), "_X5")
  170. X <- cbind(X, X5)
  171. }
  172. X$ORF <- X$OrfRep_X1
  173. if (length(study_nums) > 1) {
  174. X$ORF <- gsub("_1", "", x = X$ORF)
  175. try(X[X$Gene_X1 == "", ]$Gene_X1 <- X[X$Gene_X1 == "", ]$OrfRep_X1)
  176. try(X[X$Gene_X2 == "", ]$Gene_X2 <- X[X$Gene_X2 == "", ]$OrfRep_X2)
  177. X_heatmap <-
  178. X[colnames(X) == "ORF" | colnames(X) == "Gene_X1" |
  179. colnames(X) == "Z_Shift_K_X1" | colnames(X) == "Z_lm_K_X1" |
  180. colnames(X) == "Z_Shift_K_X2" | colnames(X) == "Z_lm_K_X2" |
  181. colnames(X) == "Z_Shift_L_X1" | colnames(X) == "Z_lm_L_X1" |
  182. colnames(X) == "Z_Shift_L_X2" | colnames(X) == "Z_lm_L_X2"]
  183. X_heatmap <- X_heatmap[, c(10, 1, 4, 5, 8, 9, 2, 3, 6, 7)]
  184. colnames(X_heatmap) <- gsub(pattern = "X1", replacement = Name1, colnames(X_heatmap))
  185. colnames(X_heatmap) <- gsub(pattern = "X2", replacement = Name2, colnames(X_heatmap))
  186. colnames(X_heatmap)[2] <- "Gene"
  187. }
  188. if (length(study_nums) > 2) {
  189. X$ORF <- gsub("_1", "", x = X$ORF)
  190. X$ORF <- gsub("_2", "", x = X$ORF)
  191. try(X[X$Gene_X1 == "", ]$Gene_X1 <- X[X$Gene_X1 == "", ]$OrfRep_X1)
  192. try(X[X$Gene_X2 == "", ]$Gene_X2 <- X[X$Gene_X2 == "", ]$OrfRep_X2)
  193. try(X[X$Gene_X3 == "", ]$Gene_X3 <- X[X$Gene_X3 == "", ]$OrfRep_X3)
  194. X_heatmap <-
  195. X[colnames(X) == "ORF" | colnames(X) == "Gene_X1" |
  196. colnames(X) == "Z_Shift_K_X1" | colnames(X) == "Z_lm_K_X1" |
  197. colnames(X) == "Z_Shift_K_X2" | colnames(X) == "Z_lm_K_X2" |
  198. colnames(X) == "Z_Shift_K_X3" | colnames(X) == "Z_lm_K_X3" |
  199. colnames(X) == "Z_Shift_L_X1" | colnames(X) == "Z_lm_L_X1" |
  200. colnames(X) == "Z_Shift_L_X2" | colnames(X) == "Z_lm_L_X2" |
  201. colnames(X) == "Z_Shift_L_X3" | colnames(X) == "Z_lm_L_X3"]
  202. # Reorder columns
  203. X_heatmap <- X_heatmap[, c(14, 1, 4, 5, 8, 9, 12, 13, 2, 3, 6, 7, 10, 11)]
  204. colnames(X_heatmap) <- gsub(pattern = "X1", replacement = Name1, colnames(X_heatmap))
  205. colnames(X_heatmap) <- gsub(pattern = "X2", replacement = Name2, colnames(X_heatmap))
  206. colnames(X_heatmap) <- gsub(pattern = "X3", replacement = Name3, colnames(X_heatmap))
  207. colnames(X_heatmap)[2] <- "Gene"
  208. }
  209. if (length(study_nums) > 3) {
  210. X$ORF <- gsub("_1", "", x = X$ORF)
  211. X$ORF <- gsub("_2", "", x = X$ORF)
  212. X$ORF <- gsub("_3", "", x = X$ORF)
  213. try(X[X$Gene_X1 == "", ]$Gene_X1 <- X[X$Gene_X1 == "", ]$OrfRep_X1)
  214. try(X[X$Gene_X2 == "", ]$Gene_X2 <- X[X$Gene_X2 == "", ]$OrfRep_X2)
  215. try(X[X$Gene_X3 == "", ]$Gene_X3 <- X[X$Gene_X3 == "", ]$OrfRep_X3)
  216. try(X[X$Gene_X4 == "", ]$Gene_X4 <- X[X$Gene_X4 == "", ]$OrfRep_X4)
  217. X_heatmap <-
  218. X[colnames(X) == "ORF" | colnames(X) == "Gene_X1" |
  219. colnames(X) == "Z_Shift_K_X1" | colnames(X) == "Z_lm_K_X1" |
  220. colnames(X) == "Z_Shift_K_X2" | colnames(X) == "Z_lm_K_X2" |
  221. colnames(X) == "Z_Shift_K_X3" | colnames(X) == "Z_lm_K_X3" |
  222. colnames(X) == "Z_Shift_K_X4" | colnames(X) == "Z_lm_K_X4" |
  223. colnames(X) == "Z_Shift_L_X1" | colnames(X) == "Z_lm_L_X1" |
  224. colnames(X) == "Z_Shift_L_X2" | colnames(X) == "Z_lm_L_X2" |
  225. colnames(X) == "Z_Shift_L_X3" | colnames(X) == "Z_lm_L_X3" |
  226. colnames(X) == "Z_Shift_L_X4" | colnames(X) == "Z_lm_L_X4"]
  227. # Reorder columns
  228. X_heatmap <- X_heatmap[, c(18, 1, 4, 5, 8, 9, 12, 13, 16, 17, 2, 3, 6, 7, 10, 11, 14, 15)]
  229. colnames(X_heatmap) <- gsub(pattern = "X1", replacement = Name1, colnames(X_heatmap))
  230. colnames(X_heatmap) <- gsub(pattern = "X2", replacement = Name2, colnames(X_heatmap))
  231. colnames(X_heatmap) <- gsub(pattern = "X3", replacement = Name3, colnames(X_heatmap))
  232. colnames(X_heatmap) <- gsub(pattern = "X4", replacement = Name4, colnames(X_heatmap))
  233. colnames(X_heatmap)[2] <- "Gene"
  234. }
  235. if (length(study_nums) > 4) {
  236. X$ORF <- gsub("_1", "", x = X$ORF)
  237. X$ORF <- gsub("_2", "", x = X$ORF)
  238. X$ORF <- gsub("_3", "", x = X$ORF)
  239. X$ORF <- gsub("_4", "", x = X$ORF)
  240. try(X[X$Gene_X1 == "", ]$Gene_X1 <- X[X$Gene_X1 == "", ]$OrfRep_X1)
  241. try(X[X$Gene_X2 == "", ]$Gene_X2 <- X[X$Gene_X2 == "", ]$OrfRep_X2)
  242. try(X[X$Gene_X3 == "", ]$Gene_X3 <- X[X$Gene_X3 == "", ]$OrfRep_X3)
  243. try(X[X$Gene_X4 == "", ]$Gene_X4 <- X[X$Gene_X4 == "", ]$OrfRep_X4)
  244. try(X[X$Gene_X5 == "", ]$Gene_X5 <- X[X$Gene_X5 == "", ]$OrfRep_X5)
  245. X_heatmap <-
  246. X[colnames(X) == "ORF" | colnames(X) == "Gene_X1" |
  247. colnames(X) == "Z_Shift_K_X1" | colnames(X) == "Z_lm_K_X1" |
  248. colnames(X) == "Z_Shift_K_X2" | colnames(X) == "Z_lm_K_X2" |
  249. colnames(X) == "Z_Shift_K_X3" | colnames(X) == "Z_lm_K_X3" |
  250. colnames(X) == "Z_Shift_K_X4" | colnames(X) == "Z_lm_K_X4" |
  251. colnames(X) == "Z_Shift_K_X5" | colnames(X) == "Z_lm_K_X5" |
  252. colnames(X) == "Z_Shift_L_X1" | colnames(X) == "Z_lm_L_X1" |
  253. colnames(X) == "Z_Shift_L_X2" | colnames(X) == "Z_lm_L_X2" |
  254. colnames(X) == "Z_Shift_L_X3" | colnames(X) == "Z_lm_L_X3" |
  255. colnames(X) == "Z_Shift_L_X4" | colnames(X) == "Z_lm_L_X4" |
  256. colnames(X) == "Z_Shift_L_X5" | colnames(X) == "Z_lm_L_X5"]
  257. # Reorder columns
  258. X_heatmap <- X_heatmap[, c(22, 1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 2, 3, 6, 7, 10, 11, 14, 15, 18, 19)]
  259. colnames(X_heatmap) <- gsub(pattern = "X1", replacement = Name1, colnames(X_heatmap))
  260. colnames(X_heatmap) <- gsub(pattern = "X2", replacement = Name2, colnames(X_heatmap))
  261. colnames(X_heatmap) <- gsub(pattern = "X3", replacement = Name3, colnames(X_heatmap))
  262. colnames(X_heatmap) <- gsub(pattern = "X4", replacement = Name4, colnames(X_heatmap))
  263. colnames(X_heatmap) <- gsub(pattern = "X5", replacement = Name5, colnames(X_heatmap))
  264. colnames(X_heatmap)[2] <- "Gene"
  265. }
  266. # Theme elements for plots
  267. theme_Publication <- function(base_size = 14, base_family = "sans") {
  268. (theme_foundation(base_size = base_size, base_family = base_family) +
  269. theme(
  270. plot.title = element_text(face = "bold", size = rel(1.2), hjust = 0.5),
  271. text = element_text(),
  272. panel.background = element_rect(colour = NA),
  273. plot.background = element_rect(colour = NA),
  274. panel.border = element_rect(colour = NA),
  275. axis.title = element_text(face = "bold", size = rel(1)),
  276. axis.title.y = element_text(angle = 90, vjust = 2),
  277. axis.title.x = element_text(vjust = -0.2),
  278. axis.text = element_text(),
  279. axis.line = element_line(colour = "black"),
  280. axis.ticks = element_line(),
  281. panel.grid.major = element_line(colour = "#f0f0f0"),
  282. panel.grid.minor = element_blank(),
  283. legend.key = element_rect(colour = NA),
  284. legend.position = "bottom",
  285. legend.direction = "horizontal",
  286. legend.key.size = unit(0.2, "cm"),
  287. legend.spacing = unit(0, "cm"),
  288. legend.title = element_text(face = "italic"),
  289. plot.margin = unit(c(10, 5, 5, 5), "mm"),
  290. strip.background = element_rect(colour = "#f0f0f0", fill = "#f0f0f0"),
  291. strip.text = element_text(face = "bold")
  292. )
  293. )
  294. }
  295. scale_fill_Publication <- function(...) {
  296. library(scales)
  297. discrete_scale(
  298. "fill",
  299. "Publication",
  300. manual_pal(values = c("#386cb0", "#fdb462", "#7fc97f", "#ef3b2c", "#662506", "#a6cee3", "#fb9a99", "#984ea3", "#ffff33")),
  301. ...
  302. )
  303. }
  304. scale_colour_Publication <- function(...) {
  305. discrete_scale(
  306. "colour",
  307. "Publication",
  308. manual_pal(values = c("#386cb0", "#fdb462", "#7fc97f", "#ef3b2c", "#662506", "#a6cee3", "#fb9a99", "#984ea3", "#ffff33")),
  309. ...
  310. )
  311. }
  312. theme_Publication_legend_right <- function(base_size = 14, base_family = "sans") {
  313. (theme_foundation(base_size = base_size, base_family = base_family) +
  314. theme(
  315. plot.title = element_text(face = "bold", size = rel(1.2), hjust = 0.5),
  316. text = element_text(),
  317. panel.background = element_rect(colour = NA),
  318. plot.background = element_rect(colour = NA),
  319. panel.border = element_rect(colour = NA),
  320. axis.title = element_text(face = "bold", size = rel(1)),
  321. axis.title.y = element_text(angle = 90, vjust = 2),
  322. axis.title.x = element_text(vjust = -0.2),
  323. axis.text = element_text(),
  324. axis.line = element_line(colour = "black"),
  325. axis.ticks = element_line(),
  326. panel.grid.major = element_line(colour = "#f0f0f0"),
  327. panel.grid.minor = element_blank(),
  328. legend.key = element_rect(colour = NA),
  329. legend.position = "right",
  330. legend.direction = "vertical",
  331. legend.key.size = unit(0.5, "cm"),
  332. legend.spacing = unit(0, "cm"),
  333. legend.title = element_text(face = "italic"),
  334. plot.margin = unit(c(10, 5, 5, 5), "mm"),
  335. strip.background = element_rect(colour = "#f0f0f0", fill = "#f0f0f0"),
  336. strip.text = element_text(face = "bold")
  337. )
  338. )
  339. }
  340. scale_fill_Publication <- function(...) {
  341. discrete_scale(
  342. "fill",
  343. "Publication",
  344. manual_pal(values = c("#386cb0", "#fdb462", "#7fc97f", "#ef3b2c", "#662506", "#a6cee3", "#fb9a99", "#984ea3", "#ffff33")),
  345. ...
  346. )
  347. }
  348. scale_colour_Publication <- function(...) {
  349. discrete_scale(
  350. "colour",
  351. "Publication",
  352. manual_pal(values = c("#386cb0", "#fdb462", "#7fc97f", "#ef3b2c", "#662506", "#a6cee3", "#fb9a99", "#984ea3", "#ffff33")),
  353. ...
  354. )
  355. }
  356. Ontology <- get_ontology(file = ontology_file, propagate_relationships = "is_a", extract_tags = "minimal")
  357. print(Ontology)
  358. # All ORFs associated with GO term
  359. GO2ALLORFs <- as.list(org.Sc.sgdGO2ALLORFS)
  360. # Terms is the GO term list jwr moved up to TAABLES
  361. Terms <- read.delim(file = sgd_terms_tfile,
  362. header = FALSE,
  363. quote = "",
  364. col.names = c("GO_ID", "GO_Term", "GO_Aspect", "GO_Term_Definition")
  365. )
  366. colormapbreaks <- c(-12, -10, -8, -6, -4, -2, 2, 4, 6, 8, 10, 12)
  367. for (s in 1:dim(XX3)[1]) {
  368. # Ontology <-
  369. # get_ontology(file = "Documents/Hartman_Lab/SGD_Downloads/gene_ontology_edit.obo",
  370. # propagate_relationships = "is_a", extract_tags = "minimal")
  371. # Ontology_Everything <-
  372. # get_ontology(file = "Documents/Hartman_Lab/SGD_Downloads/gene_ontology_edit.obo",
  373. # propagate_relationships = "is_a", extract_tags = "everything")
  374. #
  375. # GO_ID_Arg <- "GO:0006325"
  376. GO_ID_Arg_loop <- as.character(XX3[s, 1])
  377. GOTerm_parent <- get_descendants(Ontology, roots = GO_ID_Arg_loop)
  378. # GOTerm_parent <- get_descendants(Ontology,roots = "GO:0006325")
  379. # Only make plots if parent term has fewer than 500 children
  380. Parent_Size <- length(as.vector(GO2ALLORFs[GO_ID_Arg_loop][[1]]))
  381. if (length(GOTerm_parent) > 100) {
  382. next()
  383. }
  384. Parent_Size <- length(as.vector(GO2ALLORFs[GO_ID_Arg_loop][[1]])) # TODO why twice?
  385. if (Parent_Size < 2) {
  386. next()
  387. }
  388. if (Parent_Size > 2000) {
  389. pdf(
  390. file = file.path(output_dir, paste0(XX3[s, 2], ".pdf")),
  391. width = 12,
  392. height = 45,
  393. onefile = TRUE
  394. )
  395. for (i in 1:length(GOTerm_parent)) {
  396. GO_Term <- GOTerm_parent[i]
  397. GO_Term_Num <- as.integer(str_split_fixed(as.character(GO_Term), "\\:", 2)[, 2])
  398. GO_Term_Name <- as.character(Terms[Terms$GO_ID == GO_Term_Num, ]$GO_Term)
  399. # Genes_Annotated_to_Term <- Gene_Association[Gene_Association$GO_ID == GO_Term, ]
  400. All_Genes_Annotated_to_Term <- as.vector(GO2ALLORFs[GO_Term][[1]])
  401. Genes_Annotated_to_Term <- X_heatmap[X_heatmap$ORF %in% All_Genes_Annotated_to_Term, ]
  402. X0 <- as.matrix(Genes_Annotated_to_Term[, 3:dim(Genes_Annotated_to_Term)[2]])
  403. if (dim(Genes_Annotated_to_Term)[1] > 2) {
  404. try(heatmap.2(
  405. x = X0,
  406. Rowv = TRUE, Colv = NA, distfun = dist, hclustfun = hclust,
  407. dendrogram = "row", cexCol = 0.7, cexRow = 0.5, scale = "none",
  408. breaks = colormapbreaks, symbreaks = FALSE, colsep = c(2, 4, 6), sepcolor = "white", offsetCol = 0.1,
  409. ylab = "Gene",
  410. cellnote = round(X0, digits = 0), notecex = 0.5, key = TRUE,
  411. keysize = 0.5, trace = "none", density.info = c("none"), margins = c(10, 8),
  412. na.color = "red", col = brewer.pal(11, "PuOr"),
  413. main = GO_Term_Name,
  414. # ColSideColors = ev_repeat,
  415. labRow = as.character(Genes_Annotated_to_Term$Gene)
  416. ))
  417. }
  418. }
  419. dev.off()
  420. }
  421. if (Parent_Size >= 1000 && Parent_Size <= 2000) {
  422. pdf(
  423. file = file.path(output_dir, paste0(XX3[s, 2], ".pdf")),
  424. width = 12,
  425. height = 35,
  426. onefile = TRUE
  427. )
  428. for (i in 1:length(GOTerm_parent)) {
  429. GO_Term <- GOTerm_parent[i]
  430. GO_Term_Num <- as.integer(str_split_fixed(as.character(GO_Term), "\\:", 2)[, 2])
  431. GO_Term_Name <- as.character(Terms[Terms$GO_ID == GO_Term_Num, ]$GO_Term)
  432. # Genes_Annotated_to_Term <- Gene_Association[Gene_Association$GO_ID == GO_Term, ]
  433. All_Genes_Annotated_to_Term <- as.vector(GO2ALLORFs[GO_Term][[1]])
  434. Genes_Annotated_to_Term <- X_heatmap[X_heatmap$ORF %in% All_Genes_Annotated_to_Term, ]
  435. X0 <- as.matrix(Genes_Annotated_to_Term[, 3:dim(Genes_Annotated_to_Term)[2]])
  436. if (dim(Genes_Annotated_to_Term)[1] > 2) {
  437. try(heatmap.2(
  438. x = X0,
  439. Rowv = TRUE, Colv = NA, distfun = dist, hclustfun = hclust,
  440. dendrogram = "row", cexCol = 0.7, cexRow = 0.6, scale = "none",
  441. breaks = colormapbreaks, symbreaks = FALSE, colsep = c(2, 4, 6), sepcolor = "white", offsetCol = 0.1,
  442. ylab = "Gene",
  443. cellnote = round(X0, digits = 0), notecex = 0.5, key = TRUE,
  444. keysize = 0.5, trace = "none", density.info = c("none"), margins = c(10, 8),
  445. na.color = "red", col = brewer.pal(11, "PuOr"),
  446. main = GO_Term_Name,
  447. # ColSideColors = ev_repeat,
  448. labRow = as.character(Genes_Annotated_to_Term$Gene)
  449. ))
  450. }
  451. }
  452. dev.off()
  453. }
  454. if (Parent_Size >= 500 && Parent_Size <= 1000) {
  455. pdf(
  456. file = file.path(output_dir, paste0(XX3[s, 2], ".pdf")),
  457. width = 12,
  458. height = 30,
  459. onefile = TRUE
  460. )
  461. for (i in 1:length(GOTerm_parent)) {
  462. GO_Term <- GOTerm_parent[i]
  463. GO_Term_Num <- as.integer(str_split_fixed(as.character(GO_Term), "\\:", 2)[, 2])
  464. GO_Term_Name <- as.character(Terms[Terms$GO_ID == GO_Term_Num, ]$GO_Term)
  465. # Genes_Annotated_to_Term <- Gene_Association[Gene_Association$GO_ID == GO_Term, ]
  466. All_Genes_Annotated_to_Term <- as.vector(GO2ALLORFs[GO_Term][[1]])
  467. Genes_Annotated_to_Term <- X_heatmap[X_heatmap$ORF %in% All_Genes_Annotated_to_Term, ]
  468. X0 <- as.matrix(Genes_Annotated_to_Term[, 3:dim(Genes_Annotated_to_Term)[2]])
  469. if (dim(Genes_Annotated_to_Term)[1] > 2) {
  470. try(heatmap.2(
  471. x = X0,
  472. Rowv = TRUE, Colv = NA, distfun = dist, hclustfun = hclust,
  473. dendrogram = "row", cexCol = 0.7, cexRow = 0.6, scale = "none",
  474. breaks = colormapbreaks, symbreaks = FALSE, colsep = c(2, 4, 6), sepcolor = "white", offsetCol = 0.1,
  475. ylab = "Gene",
  476. cellnote = round(X0, digits = 0), notecex = 0.5, key = TRUE,
  477. keysize = 0.5, trace = "none", density.info = c("none"), margins = c(10, 8),
  478. na.color = "red", col = brewer.pal(11, "PuOr"),
  479. main = GO_Term_Name,
  480. # ColSideColors = ev_repeat,
  481. labRow = as.character(Genes_Annotated_to_Term$Gene)
  482. ))
  483. }
  484. }
  485. dev.off()
  486. }
  487. if (Parent_Size >= 200 && Parent_Size <= 500) {
  488. pdf(
  489. file = file.path(output_dir, paste0(XX3[s, 2], ".pdf")),
  490. width = 12,
  491. height = 25,
  492. onefile = TRUE
  493. )
  494. for (i in 1:length(GOTerm_parent)) {
  495. GO_Term <- GOTerm_parent[i]
  496. GO_Term_Num <- as.integer(str_split_fixed(as.character(GO_Term), "\\:", 2)[, 2])
  497. GO_Term_Name <- as.character(Terms[Terms$GO_ID == GO_Term_Num, ]$GO_Term)
  498. # Genes_Annotated_to_Term <- Gene_Association[Gene_Association$GO_ID == GO_Term, ]
  499. All_Genes_Annotated_to_Term <- as.vector(GO2ALLORFs[GO_Term][[1]])
  500. Genes_Annotated_to_Term <- X_heatmap[X_heatmap$ORF %in% All_Genes_Annotated_to_Term, ]
  501. X0 <- as.matrix(Genes_Annotated_to_Term[, 3:dim(Genes_Annotated_to_Term)[2]])
  502. if (dim(Genes_Annotated_to_Term)[1] > 2) {
  503. try(heatmap.2(
  504. x = X0,
  505. Rowv = TRUE, Colv = NA, distfun = dist, hclustfun = hclust,
  506. dendrogram = "row", cexCol = 0.7, cexRow = 0.7, scale = "none",
  507. breaks = colormapbreaks, symbreaks = FALSE, colsep = c(2, 4, 6), sepcolor = "white", offsetCol = 0.1,
  508. ylab = "Gene",
  509. cellnote = round(X0, digits = 0), notecex = 0.5, key = TRUE,
  510. keysize = 0.5, trace = "none", density.info = c("none"), margins = c(10, 8),
  511. na.color = "red", col = brewer.pal(11, "PuOr"),
  512. main = GO_Term_Name,
  513. # ColSideColors = ev_repeat,
  514. labRow = as.character(Genes_Annotated_to_Term$Gene)
  515. ))
  516. }
  517. }
  518. dev.off()
  519. }
  520. if (Parent_Size >= 100 && Parent_Size <= 200) {
  521. pdf(
  522. file = file.path(output_dir, paste0(XX3[s, 2], ".pdf")),
  523. width = 12,
  524. height = 20,
  525. onefile = TRUE
  526. )
  527. for (i in 1:length(GOTerm_parent)) {
  528. GO_Term <- GOTerm_parent[i]
  529. GO_Term_Num <- as.integer(str_split_fixed(as.character(GO_Term), "\\:", 2)[, 2])
  530. GO_Term_Name <- as.character(Terms[Terms$GO_ID == GO_Term_Num, ]$GO_Term)
  531. # Genes_Annotated_to_Term <- Gene_Association[Gene_Association$GO_ID == GO_Term, ]
  532. All_Genes_Annotated_to_Term <- as.vector(GO2ALLORFs[GO_Term][[1]])
  533. Genes_Annotated_to_Term <- X_heatmap[X_heatmap$ORF %in% All_Genes_Annotated_to_Term, ]
  534. X0 <- as.matrix(Genes_Annotated_to_Term[, 3:dim(Genes_Annotated_to_Term)[2]])
  535. if (dim(Genes_Annotated_to_Term)[1] > 2) {
  536. try(heatmap.2(
  537. x = X0,
  538. Rowv = TRUE, Colv = NA, distfun = dist, hclustfun = hclust,
  539. dendrogram = "row", cexCol = 0.7, cexRow = 0.7, scale = "none",
  540. breaks = colormapbreaks, symbreaks = FALSE, colsep = c(2, 4, 6), sepcolor = "white", offsetCol = 0.1,
  541. ylab = "Gene",
  542. cellnote = round(X0, digits = 0), notecex = 0.5, key = TRUE,
  543. keysize = 0.5, trace = "none", density.info = c("none"), margins = c(10, 8),
  544. na.color = "red", col = brewer.pal(11, "PuOr"),
  545. main = GO_Term_Name,
  546. # ColSideColors = ev_repeat,
  547. labRow = as.character(Genes_Annotated_to_Term$Gene)
  548. ))
  549. }
  550. }
  551. dev.off()
  552. }
  553. if (Parent_Size >= 60 && Parent_Size <= 100) {
  554. pdf(
  555. file = file.path(output_dir, paste0(XX3[s, 2], ".pdf")),
  556. width = 12,
  557. height = 15,
  558. onefile = TRUE
  559. )
  560. for (i in 1:length(GOTerm_parent)) {
  561. GO_Term <- GOTerm_parent[i]
  562. GO_Term_Num <- as.integer(str_split_fixed(as.character(GO_Term), "\\:", 2)[, 2])
  563. GO_Term_Name <- as.character(Terms[Terms$GO_ID == GO_Term_Num, ]$GO_Term)
  564. # Genes_Annotated_to_Term <- Gene_Association[Gene_Association$GO_ID == GO_Term, ]
  565. All_Genes_Annotated_to_Term <- as.vector(GO2ALLORFs[GO_Term][[1]])
  566. Genes_Annotated_to_Term <- X_heatmap[X_heatmap$ORF %in% All_Genes_Annotated_to_Term, ]
  567. X0 <- as.matrix(Genes_Annotated_to_Term[, 3:dim(Genes_Annotated_to_Term)[2]])
  568. if (dim(Genes_Annotated_to_Term)[1] > 2) {
  569. try(heatmap.2(
  570. x = X0,
  571. Rowv = TRUE, Colv = NA, distfun = dist, hclustfun = hclust,
  572. dendrogram = "row", cexCol = 0.7, cexRow = 0.7, scale = "none",
  573. breaks = colormapbreaks, symbreaks = FALSE, colsep = c(2, 4, 6), sepcolor = "white", offsetCol = 0.1,
  574. ylab = "Gene",
  575. cellnote = round(X0, digits = 0), notecex = 0.5, key = TRUE,
  576. keysize = 0.5, trace = "none", density.info = c("none"), margins = c(10, 8),
  577. na.color = "red", col = brewer.pal(11, "PuOr"),
  578. main = GO_Term_Name,
  579. # ColSideColors = ev_repeat,
  580. labRow = as.character(Genes_Annotated_to_Term$Gene)
  581. ))
  582. }
  583. }
  584. dev.off()
  585. }
  586. if (Parent_Size >= 30 && Parent_Size <= 60) {
  587. pdf(
  588. file = file.path(output_dir, paste0(XX3[s, 2], ".pdf")),
  589. width = 12,
  590. height = 10,
  591. onefile = TRUE
  592. )
  593. for (i in 1:length(GOTerm_parent)) {
  594. GO_Term <- GOTerm_parent[i]
  595. GO_Term_Num <- as.integer(str_split_fixed(as.character(GO_Term), "\\:", 2)[, 2])
  596. GO_Term_Name <- as.character(Terms[Terms$GO_ID == GO_Term_Num, ]$GO_Term)
  597. # Genes_Annotated_to_Term <- Gene_Association[Gene_Association$GO_ID == GO_Term, ]
  598. All_Genes_Annotated_to_Term <- as.vector(GO2ALLORFs[GO_Term][[1]])
  599. Genes_Annotated_to_Term <- X_heatmap[X_heatmap$ORF %in% All_Genes_Annotated_to_Term, ]
  600. X0 <- as.matrix(Genes_Annotated_to_Term[, 3:dim(Genes_Annotated_to_Term)[2]])
  601. if (dim(Genes_Annotated_to_Term)[1] > 2) {
  602. try(heatmap.2(
  603. x = X0,
  604. Rowv = TRUE, Colv = NA, distfun = dist, hclustfun = hclust,
  605. dendrogram = "row", cexCol = 0.7, cexRow = 0.7, scale = "none",
  606. breaks = colormapbreaks, symbreaks = FALSE, colsep = c(2, 4, 6), sepcolor = "white", offsetCol = 0.1,
  607. ylab = "Gene",
  608. cellnote = round(X0, digits = 0), notecex = 0.5, key = TRUE,
  609. keysize = 0.5, trace = "none", density.info = c("none"), margins = c(10, 8),
  610. na.color = "red", col = brewer.pal(11, "PuOr"),
  611. main = GO_Term_Name,
  612. # ColSideColors = ev_repeat,
  613. labRow = as.character(Genes_Annotated_to_Term$Gene)
  614. ))
  615. }
  616. if (dim(Genes_Annotated_to_Term)[1] <= 2 && dim(Genes_Annotated_to_Term)[1] > 0) {
  617. try(heatmap.2(
  618. x = X0,
  619. Rowv = TRUE, Colv = NA, distfun = dist, hclustfun = hclust,
  620. dendrogram = "none", cexCol = 0.7, cexRow = 0.7, scale = "none",
  621. breaks = colormapbreaks, symbreaks = FALSE, colsep = c(2, 4, 6), sepcolor = "white", offsetCol = 0.1,
  622. ylab = "Gene",
  623. cellnote = round(X0, digits = 0), notecex = 0.5, key = TRUE,
  624. keysize = 0.5, trace = "none", density.info = c("none"), margins = c(10, 8),
  625. na.color = "red", col = brewer.pal(11, "PuOr"),
  626. main = GO_Term_Name,
  627. # ColSideColors = ev_repeat,
  628. labRow = as.character(Genes_Annotated_to_Term$Gene)
  629. ))
  630. }
  631. }
  632. dev.off()
  633. }
  634. if (Parent_Size >= 3 && Parent_Size <= 30) {
  635. pdf(
  636. file = file.path(output_dir, paste0(XX3[s, 2], ".pdf")),
  637. width = 12,
  638. height = 7,
  639. onefile = TRUE
  640. )
  641. for (i in 1:length(GOTerm_parent)) {
  642. GO_Term <- GOTerm_parent[i]
  643. GO_Term_Num <- as.integer(str_split_fixed(as.character(GO_Term), "\\:", 2)[, 2])
  644. GO_Term_Name <- as.character(Terms[Terms$GO_ID == GO_Term_Num, ]$GO_Term)
  645. # Genes_Annotated_to_Term <- Gene_Association[Gene_Association$GO_ID == GO_Term, ]
  646. All_Genes_Annotated_to_Term <- as.vector(GO2ALLORFs[GO_Term][[1]])
  647. Genes_Annotated_to_Term <- X_heatmap[X_heatmap$ORF %in% All_Genes_Annotated_to_Term, ]
  648. X0 <- as.matrix(Genes_Annotated_to_Term[, 3:dim(Genes_Annotated_to_Term)[2]])
  649. if (dim(Genes_Annotated_to_Term)[1] > 2) {
  650. try(heatmap.2(
  651. x = X0,
  652. Rowv = TRUE, Colv = NA, distfun = dist, hclustfun = hclust,
  653. dendrogram = "row", cexCol = 0.7, cexRow = 0.7, scale = "none",
  654. breaks = colormapbreaks, symbreaks = FALSE, colsep = c(2, 4, 6), sepcolor = "white", offsetCol = 0.1,
  655. ylab = "Gene",
  656. cellnote = round(X0, digits = 0), notecex = 0.5, key = TRUE,
  657. keysize = 0.5, trace = "none", density.info = c("none"), margins = c(10, 8),
  658. na.color = "red", col = brewer.pal(11, "PuOr"),
  659. main = GO_Term_Name,
  660. # ColSideColors = ev_repeat,
  661. labRow = as.character(Genes_Annotated_to_Term$Gene)
  662. ))
  663. }
  664. if (dim(Genes_Annotated_to_Term)[1] <= 2 && dim(Genes_Annotated_to_Term)[1] > 0) {
  665. try(heatmap.2(
  666. x = X0,
  667. Rowv = TRUE, Colv = NA, distfun = dist, hclustfun = hclust,
  668. dendrogram = "none", cexCol = 0.7, cexRow = 0.7, scale = "none",
  669. breaks = colormapbreaks, symbreaks = FALSE, colsep = c(2, 4, 6), sepcolor = "white", offsetCol = 0.1,
  670. ylab = "Gene",
  671. cellnote = round(X0, digits = 0), notecex = 0.5, key = TRUE,
  672. keysize = 0.5, trace = "none", density.info = c("none"), margins = c(10, 8),
  673. na.color = "red", col = brewer.pal(11, "PuOr"),
  674. main = GO_Term_Name,
  675. # ColSideColors = ev_repeat,
  676. labRow = as.character(Genes_Annotated_to_Term$Gene)
  677. ))
  678. }
  679. }
  680. dev.off()
  681. }
  682. if (Parent_Size == 2) {
  683. pdf(
  684. file = file.path(output_dir, paste0(XX3[s, 2], ".pdf")),
  685. width = 12,
  686. height = 7,
  687. onefile = TRUE
  688. )
  689. for (i in 1:length(GOTerm_parent)) {
  690. GO_Term <- GOTerm_parent[i]
  691. GO_Term_Num <- as.integer(str_split_fixed(as.character(GO_Term), "\\:", 2)[, 2])
  692. GO_Term_Name <- as.character(Terms[Terms$GO_ID == GO_Term_Num, ]$GO_Term)
  693. # Genes_Annotated_to_Term <- Gene_Association[Gene_Association$GO_ID == GO_Term, ]
  694. All_Genes_Annotated_to_Term <- as.vector(GO2ALLORFs[GO_Term][[1]])
  695. Genes_Annotated_to_Term <- X_heatmap[X_heatmap$ORF %in% All_Genes_Annotated_to_Term, ]
  696. X0 <- as.matrix(Genes_Annotated_to_Term[, 3:dim(Genes_Annotated_to_Term)[2]])
  697. if (dim(Genes_Annotated_to_Term)[1] > 2) {
  698. try(heatmap.2(
  699. x = X0,
  700. Rowv = TRUE, Colv = NA, distfun = dist, hclustfun = hclust,
  701. dendrogram = "row", cexCol = 0.7, cexRow = 0.7, scale = "none",
  702. breaks = colormapbreaks, symbreaks = FALSE, colsep = c(2, 4, 6), sepcolor = "white", offsetCol = 0.1,
  703. ylab = "Gene",
  704. cellnote = round(X0, digits = 0), notecex = 0.5, key = TRUE,
  705. keysize = 0.5, trace = "none", density.info = c("none"), margins = c(10, 8),
  706. na.color = "red", col = brewer.pal(11, "PuOr"),
  707. main = GO_Term_Name,
  708. # ColSideColors = ev_repeat,
  709. labRow = as.character(Genes_Annotated_to_Term$Gene)
  710. ))
  711. }
  712. if (dim(Genes_Annotated_to_Term)[1] <= 2 && dim(Genes_Annotated_to_Term)[1] > 0) {
  713. try(heatmap.2(
  714. x = X0,
  715. Rowv = TRUE, Colv = NA, distfun = dist, hclustfun = hclust,
  716. dendrogram = "none", cexCol = 0.7, cexRow = 0.7, scale = "none",
  717. breaks = colormapbreaks, symbreaks = FALSE, colsep = c(2, 4, 6), sepcolor = "white", offsetCol = 0.1,
  718. ylab = "Gene",
  719. cellnote = round(X0, digits = 0), notecex = 0.5, key = TRUE,
  720. keysize = 0.5, trace = "none", density.info = c("none"), margins = c(10, 8),
  721. na.color = "red", col = brewer.pal(11, "PuOr"),
  722. main = GO_Term_Name,
  723. # ColSideColors = ev_repeat,
  724. labRow = as.character(Genes_Annotated_to_Term$Gene)
  725. ))
  726. }
  727. }
  728. dev.off()
  729. }
  730. }