OSCR

Simultaneous profiling of native-state proteomes and transcriptomes of neural cell types using proximity labeling.

Code ↔ Paper

5 matches between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

The 5 matches
  1. [1] § Methods › Data analysis and visualization ↔ Astrocyte-RiboTag_mRNA seq analysis.R, lines 1407 to 1451 · score 0.79 · Bader Lab website, GOparallel, DESeq2, GMT, ANOVA, GSEA · Report a mismatch
  2. [2] § Methods › Protein identification and quantification ↔ HEK293 DIA LFQ-MS analysis.R, lines 1 to 41 · score 0.75 · MaxQuant, log2 transformation, tryptic, DDA, UniProt, DIA · Report a mismatch
  3. [3] § Methods › Data analysis and visualization ↔ HEK293 DIA LFQ-MS analysis.R, lines 1542 to 1602 · score 0.74 · Bader Lab website, GOparallel, GMT, GSEA, Fisher, symbol · Report a mismatch
  4. [4] § Methods › RNA-sequencing and processing ↔ Astrocyte-RiboTag_mRNA seq analysis.R, lines 1 to 42 · score 0.70 · smRNA, DESeq2, gene expression, RiboTag, Spliced, library · Report a mismatch
  5. [5] § Methods › RNA-sequencing and processing ↔ Astrocyte and neuron-TurboID mRNA-seq analysis.R, lines 1 to 43 · score 0.63 · smRNA, DESeq2, gene expression, Spliced, library, raw · Report a mismatch

Paper

Loaded from Europe PMC by your browser; OSCR does not store it: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

R · 2,134 lines · 96 KB · MIT · 2 matches

  1. ########################################################################################################
  2. # Code for performing Differential Gene Expression Analysis on Exp. 8-1 (Aldh1l1-RiboTag) and Exp. 9-2 (Aldh1l1-TurboID)
  3. # row means >=10 filter before dds and splicing
  4. # Christina Ramelow, MS
  5. # Date: 06/18/2024
  6. ##################################################################################################################
  7. ##################################################################################################################
  8. ## Part 1: Data processing and clean up
  9. # steps:
  10. # 1. Filter out low counts
  11. # a. Venns: keep a gene if row mean count >= 10/sample group
  12. # b. PCAs, correlations, diffex: keep a gene if row mean count >= 10 across all samples
  13. # 2. DESeq2 normalization
  14. # a. median of ratios approach (one file with all samples and 1 file w/o neg.pulldowns)
  15. ##################################################################################################################
  16. #load Libraries
  17. library(DESeq2)
  18. library(tidyverse)
  19. library(biomaRt)
  20. library(pheatmap)
  21. library(ggplot2)
  22. library(ggrepel)
  23. stringsAsFactors = FALSE
  24. rootdir <- setwd("/Users/christina/Desktop/Exp. 8-1 mRNA-seq analysis")
  25. # load Exp. 9-2 feature_counts.txt file
  26. raw_counts_Aldh_Turbo <- read.table("Exp. 1-4, 9-2 and 10-1_feature_counts.txt", sep = "\t", header = TRUE, row.names = 1)
  27. dim(raw_counts_Aldh_Turbo)
  28. # [1] 35976 55
  29. # remove the first 5 columns that are primarily categorical
  30. raw_counts_TurboID_2 <- raw_counts_Aldh_Turbo[,c(6:55)]
  31. dim(raw_counts_TurboID_2)
  32. # [1] 35976 50
  33. # remove the smRNA-seq samples that were accidentally included
  34. raw_counts_TurboID_3 <- raw_counts_TurboID_2[,c(1:20, 27:50)]
  35. dim(raw_counts_TurboID_3)
  36. # [1] 35976 44
  37. # 21047FL-134-01-22 - 21047FL-134-01-27 should be removed. CR: checked
  38. # check if there are NAs in the counts df
  39. sum(is.na(raw_counts_TurboID_3))
  40. #[1] 0
  41. # create a geneID column and move it to the front of the df
  42. raw_counts_TurboID_3$geneID <- rownames(raw_counts_TurboID_3)
  43. raw_counts_TurboID_3 <- raw_counts_TurboID_3[, c("geneID", setdiff(names(raw_counts_TurboID_3), "geneID"))]
  44. # load Exp. 8-1 feature_counts.txt file
  45. raw_counts_Aldh_RiboTag <- read.table("Exp. 8-1 feature_counts.txt", sep = "\t", header = TRUE, row.names = 1)
  46. dim(raw_counts_Aldh_RiboTag)
  47. # [1] 35976 15
  48. # remove the first 5 columns that are primarily categorical
  49. raw_counts_RiboTag_2 <- raw_counts_Aldh_RiboTag[,c(6:15)]
  50. dim(raw_counts_RiboTag_2)
  51. # [1] 35976 10
  52. # check if there are NAs in the counts df
  53. sum(is.na(raw_counts_RiboTag_2))
  54. #[1] 0
  55. # create a geneID column and move it to the front of the df
  56. raw_counts_RiboTag_2$geneID <- rownames(raw_counts_RiboTag_2)
  57. raw_counts_RiboTag_2 <- raw_counts_RiboTag_2[, c("geneID", setdiff(names(raw_counts_RiboTag_2), "geneID"))]
  58. # combine the two featurecounts.txt files by shared geneIDs
  59. TurboID_RiboTag_merged_raw_counts <- merge(raw_counts_TurboID_3, raw_counts_RiboTag_2, by = "geneID")
  60. dim(TurboID_RiboTag_merged_raw_counts)
  61. # [1] 35976 55
  62. # set the geneID column back as row names
  63. rownames(TurboID_RiboTag_merged_raw_counts) <- TurboID_RiboTag_merged_raw_counts$geneID
  64. # remove the geneID column
  65. TurboID_RiboTag_merged_raw_counts <- TurboID_RiboTag_merged_raw_counts[, -which(names(TurboID_RiboTag_merged_raw_counts) == "geneID")]
  66. dim(TurboID_RiboTag_merged_raw_counts)
  67. # [1] 35976 54
  68. # load Exp. 1-4, 9-2, 10-1 and 8-1 RNA traits file
  69. traits <- read.csv("Exp. 1-4, 9-2, 10-1 and 8-1 combined traits_RNA.csv", header = TRUE, row.names = 1)
  70. dim(traits)
  71. # [1] 54 2
  72. # rename the column name of the merged_raw_counts df to match traits df
  73. # Extract row names from traits
  74. new_col_names <- rownames(traits)
  75. # Assign row names of traits as column names
  76. names(TurboID_RiboTag_merged_raw_counts) <- new_col_names
  77. # check that the row names of the traits df and the column names of the counts df are the same
  78. raw_counts_clean <- TurboID_RiboTag_merged_raw_counts[,match(rownames(traits), colnames(TurboID_RiboTag_merged_raw_counts))]
  79. #sanity check 1 colnames in counts file = rownames in traits file
  80. all(colnames(raw_counts_clean) %in% rownames(traits))
  81. #TRUE
  82. #sanity check 2 colnames in counts file = rownames in traits file
  83. all(colnames(raw_counts_clean) == rownames(traits))
  84. #TRUE
  85. # Exp. 9-2 and 8-1 splced
  86. raw_counts_clean_9_2_8_1 <- raw_counts_clean[,c(21:41, 45:54)]
  87. dim(raw_counts_clean_9_2_8_1)
  88. # [1] 35976 31
  89. colnames(raw_counts_clean_9_2_8_1)
  90. # should be "21047FL-134-01-28" - "21047FL-134-01-48" and "23238R-04-01" - "23238R-04-10" CR: checked
  91. # write .csv file for raw_counts_clean for Exp. 9-2 and 8-1
  92. write.csv(raw_counts_clean_9_2_8_1, file=paste0("0.Exp. 9-2 and 8-1_RNA-seq_raw_counts_clean_unfiltered-",dim(raw_counts_clean_9_2_8_1)[1],"x",dim(raw_counts_clean_9_2_8_1)[2],"_CR_06182024.csv"))
  93. ################################################################################
  94. ################################################################################
  95. ## Step 1a: Filter out low counts using a row mean >/= 10 by group for Venn diagrams
  96. # Exp. 9-2 and 8-1
  97. # 1. subset the traits and counts dfs by sample group to create list of genes for Venn diagrams
  98. # 2. calculate the row mean
  99. # 3. filter for genes with a row mean >= 10
  100. # 4. write a .csv file for each sample group
  101. ################################################################################
  102. # subset the traits file to only include Exp. 9-2 and 8-1
  103. traits_9_2_8_1 <- traits[c(21:41, 45:54),]
  104. dim(traits_9_2_8_1)
  105. # [1] 31 2
  106. write.csv(traits_9_2_8_1, file = "Exp. 9-2 and 8-1 RNA traits.csv")
  107. ################################################################################
  108. # row mean >= 10 Aldh1l1.bulk.cortex
  109. counts_Aldh1l1.bulk.cortex <- raw_counts_clean_9_2_8_1[,c(4:6)]
  110. dim(counts_Aldh1l1.bulk.cortex)
  111. # [1] 35976 3
  112. traits_Aldh1l1.bulk.cortex <- traits_9_2_8_1[c(4:6),]
  113. traits_Aldh1l1.bulk.cortex
  114. # Sample.ID.. Group
  115. # 21047FL-134-01-31 4-RNA 30L Aldh1l1.bulk.cortex
  116. # 21047FL-134-01-32 5-RNA 31B Aldh1l1.bulk.cortex
  117. # 21047FL-134-01-33 6-RNA 24L Aldh1l1.bulk.cortex
  118. rownames(traits_Aldh1l1.bulk.cortex)
  119. # [1] "21047FL-134-01-31" "21047FL-134-01-32" "21047FL-134-01-33"
  120. colnames(counts_Aldh1l1.bulk.cortex)
  121. # [1] "21047FL-134-01-31" "21047FL-134-01-32" "21047FL-134-01-33"
  122. # calculate row mean
  123. Aldh1l1.bulk.cortex_row_mean <- rowMeans(counts_Aldh1l1.bulk.cortex)
  124. # subset rows where row means >= 10
  125. Aldh1l1.bulk.cortex_filtered_rows <- counts_Aldh1l1.bulk.cortex[Aldh1l1.bulk.cortex_row_mean >= 10, ]
  126. dim(Aldh1l1.bulk.cortex_filtered_rows)
  127. # [1] 16737 3
  128. # write .csv file
  129. write.csv(Aldh1l1.bulk.cortex_filtered_rows, file=paste0("1a.Exp. 9-2 and 8-1_RNA-seq_Aldh1l1.bulk.cortex_Venn filter-",dim(Aldh1l1.bulk.cortex_filtered_rows)[1],"x",dim(Aldh1l1.bulk.cortex_filtered_rows)[2],"_CR_06182024.csv"))
  130. ################################################################################
  131. # row mean >= 10 RiboTag bulk.cortex
  132. counts_RiboTag.bulk.cortex <- raw_counts_clean_9_2_8_1[,c(22:23)]
  133. dim(counts_RiboTag.bulk.cortex)
  134. # [1] 35976 2
  135. traits_RiboTag.bulk.cortex <- traits_9_2_8_1[c(22:23),]
  136. traits_RiboTag.bulk.cortex
  137. # Sample.ID.. Group
  138. # 23238R-04-01 CR1 RiboTag.bulk.cortex
  139. # 23238R-04-02 CR2 RiboTag.bulk.cortex
  140. rownames(traits_RiboTag.bulk.cortex)
  141. # [1] "23238R-04-01" "23238R-04-02"
  142. colnames(counts_RiboTag.bulk.cortex)
  143. # [1] "23238R-04-01" "23238R-04-02"
  144. # calculate row mean
  145. RiboTag.bulk.cortex_row_mean <- rowMeans(counts_RiboTag.bulk.cortex)
  146. # subset rows where row means >= 10
  147. RiboTag.bulk.cortex_filtered_rows <- counts_RiboTag.bulk.cortex[RiboTag.bulk.cortex_row_mean >= 10, ]
  148. dim(RiboTag.bulk.cortex_filtered_rows)
  149. # [1] 17584 2
  150. # write .csv file
  151. write.csv(RiboTag.bulk.cortex_filtered_rows, file=paste0("1a.Exp. 9-2 and 8-1_RNA-seq_RiboTag.bulk.cortex_Venn filter-",dim(RiboTag.bulk.cortex_filtered_rows)[1],"x",dim(RiboTag.bulk.cortex_filtered_rows)[2],"_CR_06182024.csv"))
  152. ###############################################################################
  153. # row mean >= 10 Aldh1l1.RiboTag.bulk.cortex
  154. counts_Aldh1l1.RiboTag.bulk.cortex <- raw_counts_clean_9_2_8_1[,c(24:26)]
  155. dim(counts_Aldh1l1.RiboTag.bulk.cortex)
  156. # [1] 35976 3
  157. traits_Aldh1l1.RiboTag.bulk.cortex <- traits_9_2_8_1[c(24:26),]
  158. traits_Aldh1l1.RiboTag.bulk.cortex
  159. # Sample.ID.. Group
  160. # 23238R-04-03 CR3 Aldh1l1.RiboTag.bulk.cortex
  161. # 23238R-04-04 CR4 Aldh1l1.RiboTag.bulk.cortex
  162. # 23238R-04-05 CR5 Aldh1l1.RiboTag.bulk.cortex
  163. rownames(traits_Aldh1l1.RiboTag.bulk.cortex)
  164. # [1] "23238R-04-03" "23238R-04-04" "23238R-04-05"
  165. colnames(counts_Aldh1l1.RiboTag.bulk.cortex)
  166. # [1] "23238R-04-03" "23238R-04-04" "23238R-04-05"
  167. # calculate row mean
  168. Aldh1l1.RiboTag.bulk.cortex_row_mean <- rowMeans(counts_Aldh1l1.RiboTag.bulk.cortex)
  169. # subset rows where row means >= 10
  170. Aldh1l1.RiboTag.bulk.cortex_filtered_rows <- counts_Aldh1l1.RiboTag.bulk.cortex[Aldh1l1.RiboTag.bulk.cortex_row_mean >= 10, ]
  171. dim(Aldh1l1.RiboTag.bulk.cortex_filtered_rows)
  172. # [1] 17583 3
  173. # write .csv file
  174. write.csv(Aldh1l1.RiboTag.bulk.cortex_filtered_rows, file=paste0("1a.Exp. 9-2 and 8-1_RNA-seq_Aldh1l1.RiboTag.bulk.cortex_Venn filter-",dim(Aldh1l1.RiboTag.bulk.cortex_filtered_rows)[1],"x",dim(Aldh1l1.RiboTag.bulk.cortex_filtered_rows)[2],"_CR_06182024.csv"))
  175. ################################################################################
  176. # row mean >= 10 Aldh1l1.pos.pulldown
  177. counts_Aldh1l1.pos.pulldown <- raw_counts_clean_9_2_8_1[,c(14:16)]
  178. dim(counts_Aldh1l1.pos.pulldown)
  179. # [1] 35976 3
  180. traits_Aldh1l1.pos.pulldown <- traits_9_2_8_1[c(14:16),]
  181. traits_Aldh1l1.pos.pulldown
  182. # Sample.ID.. Group
  183. # 21047FL-134-01-41 15-RNA 30L Aldh1l1.pos.pulldown
  184. # 21047FL-134-01-42 16-RNA 31B Aldh1l1.pos.pulldown
  185. # 21047FL-134-01-43 17-RNA 24L Aldh1l1.pos.pulldown
  186. rownames(traits_Aldh1l1.pos.pulldown)
  187. # [1] "21047FL-134-01-41" "21047FL-134-01-42" "21047FL-134-01-43"
  188. colnames(counts_Aldh1l1.pos.pulldown)
  189. # [1] "21047FL-134-01-41" "21047FL-134-01-42" "21047FL-134-01-43"
  190. # calculate row mean
  191. Aldh1l1.pos.pulldown_row_mean <- rowMeans(counts_Aldh1l1.pos.pulldown)
  192. # subset rows where row means >= 10
  193. Aldh1l1.pos.pulldown_filtered_rows <- counts_Aldh1l1.pos.pulldown[Aldh1l1.pos.pulldown_row_mean >= 10, ]
  194. dim(Aldh1l1.pos.pulldown_filtered_rows)
  195. # [1] 16632 3
  196. # write .csv file
  197. write.csv(Aldh1l1.pos.pulldown_filtered_rows, file=paste0("1a.Exp. 9-2 and 8-1_RNA-seq_Aldh1l1.pos.pulldown_Venn filter-",dim(Aldh1l1.pos.pulldown_filtered_rows)[1],"x",dim(Aldh1l1.pos.pulldown_filtered_rows)[2],"_CR_06182024.csv"))
  198. ################################################################################
  199. # row mean >= 10 Aldh1l1.RiboTag.pos.pulldown
  200. counts_Aldh1l1.RiboTag.pos.pulldown<- raw_counts_clean_9_2_8_1[,c(29:31)]
  201. dim(counts_Aldh1l1.RiboTag.pos.pulldown)
  202. # [1] 35976 3
  203. traits_Aldh1l1.RiboTag.pos.pulldown<- traits_9_2_8_1[c(29:31),]
  204. traits_Aldh1l1.RiboTag.pos.pulldown
  205. # Sample.ID.. Group
  206. # 23238R-04-08 CR8 Aldh1l1.RiboTag.pos.pulldown
  207. # 23238R-04-09 CR9 Aldh1l1.RiboTag.pos.pulldown
  208. # 23238R-04-10 CR10 Aldh1l1.RiboTag.pos.pulldown
  209. rownames(traits_Aldh1l1.RiboTag.pos.pulldown)
  210. # [1] "23238R-04-08" "23238R-04-09" "23238R-04-10"
  211. colnames(counts_Aldh1l1.RiboTag.pos.pulldown)
  212. # [1] "23238R-04-08" "23238R-04-09" "23238R-04-10"
  213. # calculate row mean
  214. Aldh1l1.RiboTag.pos.pulldown_row_mean <- rowMeans(counts_Aldh1l1.RiboTag.pos.pulldown)
  215. # subset rows where row means >= 10
  216. Aldh1l1.RiboTag.pos.pulldown_filtered_rows <- counts_Aldh1l1.RiboTag.pos.pulldown[Aldh1l1.RiboTag.pos.pulldown_row_mean >= 10, ]
  217. dim(Aldh1l1.RiboTag.pos.pulldown_filtered_rows)
  218. # [1] 16737 3
  219. # write .csv file
  220. write.csv(Aldh1l1.RiboTag.pos.pulldown_filtered_rows, file=paste0("1a.Exp. 9-2 and 8-1_RNA-seq_Aldh1l1.RiboTag.pos.pulldown_Venn filter-",dim(Aldh1l1.RiboTag.pos.pulldown_filtered_rows)[1],"x",dim(Aldh1l1.RiboTag.pos.pulldown_filtered_rows)[2],"_CR_06182024.csv"))
  221. ################################################################################
  222. ################################################################################
  223. # clean up filtered row dfs to only include gene lists
  224. # Aldh1l1.bulk.cortex_filtered_rows
  225. Aldh1l1.bulk.cortex_genes <- as.matrix(rownames(Aldh1l1.bulk.cortex_filtered_rows))
  226. dim(Aldh1l1.bulk.cortex_genes)
  227. # [1] 16737 1
  228. # Aldh1l1.RiboTag.bulk.cortex_filtered_rows
  229. Aldh1l1.RiboTag.bulk.cortex_genes <- as.matrix(rownames(Aldh1l1.RiboTag.bulk.cortex_filtered_rows))
  230. dim(Aldh1l1.RiboTag.bulk.cortex_genes)
  231. # [1] 17583 1
  232. # RiboTag.bulk.cortex_filtered_rows
  233. RiboTag.bulk.cortex_genes <- as.matrix(rownames(RiboTag.bulk.cortex_filtered_rows))
  234. dim(RiboTag.bulk.cortex_genes)
  235. # [1] 17584 1
  236. # Aldh1l1.pos.pulldown_filtered_rows
  237. Aldh1l1.pos.pulldown_genes <- as.matrix(rownames(Aldh1l1.pos.pulldown_filtered_rows))
  238. dim(Aldh1l1.pos.pulldown_genes)
  239. # [1] 16632 1
  240. # Aldh1l1.RiboTag.pos.pulldown_filtered_rows
  241. Aldh1l1.RiboTag.pos.pulldown_genes <- as.matrix(rownames(Aldh1l1.RiboTag.pos.pulldown_filtered_rows))
  242. dim(Aldh1l1.RiboTag.pos.pulldown_genes)
  243. # [1] 16737 1
  244. ################################################################################
  245. # Create Venn diagrams for each comparison
  246. list_z <- NULL
  247. # #import fonts to use Arial in output pdf
  248. # https://r-coder.com/custom-fonts-r/
  249. library(extrafont)
  250. font_import()
  251. fonts()
  252. loadfonts(device = "pdf", quiet = TRUE)
  253. # load library to create Venn's
  254. # GUI: https://www.biovenn.nl/
  255. # R package: https://cran.r-project.org/web/packages/BioVenn/index.html
  256. library(BioVenn)
  257. ## Create Venn diagrams and output as a pdf ##
  258. pdf(file = "1a. Exp. 9-2 and 8-1_RNA-seq_Venns_CR_06182024.pdf", height = 11, width = 8.5, family = "Arial")
  259. par(mfrow= c(2,1)) # centers plot on single page (I think)
  260. # Aldh1l1.bulk.cortex vs Aldh1l1.RiboTag.bulk.cortex
  261. biovenn1 <- draw.venn(Aldh1l1.bulk.cortex_genes, Aldh1l1.RiboTag.bulk.cortex_genes, list_z,
  262. t_fb = 2,
  263. t_s = 1.5,
  264. t_c = "black",
  265. t_f = "Arial",
  266. title="Aldh1l1.TurboID vs Aldh1l1.RiboTag bulk.cortex RNA",
  267. xtitle = "Aldh1l1.bulk.cortex",
  268. xt_f = "Arial",
  269. xt_fb = 2,
  270. xt_s = 1,
  271. xt_c = "black",
  272. ytitle = "Aldh1l1.RiboTag.bulk.cortex",
  273. yt_f = "Arial",
  274. yt_fb = 2,
  275. yt_s = 1,
  276. yt_c = "black",
  277. nrtype = "abs",
  278. nr_f = "Arial",
  279. nr_fb = 2,
  280. nr_s = 1,
  281. nr_c = "black",
  282. x_c = "purple",
  283. y_c = "red",
  284. # z_c = "blue",
  285. bg_c = "white",
  286. width = 1000,
  287. height = 1000,
  288. #output = "screen",
  289. filename = NULL,
  290. map2ens = FALSE)
  291. # [1] "x bulk.cortex: 16737"
  292. # [1] "y bulk.cortex: 17583"
  293. # [1] "z bulk.cortex: 0"
  294. # [1] "x only: 245"
  295. # [1] "y only: 1091"
  296. # [1] "z only: 0"
  297. # [1] "x-y bulk.cortex overlap: 16492"
  298. # Aldh1l1.RiboTag.bulk.cortex vs Aldh1l1.RiboTag.pos.pulldown
  299. biovenn2 <- draw.venn(Aldh1l1.RiboTag.bulk.cortex_genes, Aldh1l1.RiboTag.pos.pulldown_genes, list_z,
  300. t_fb = 2,
  301. t_s = 1.5,
  302. t_c = "black",
  303. t_f = "Arial",
  304. title="Aldh1l1.RiboTag.bulk.cortex vs Aldh1l1.RiboTag.pos.pulldown RNA",
  305. xtitle = "Aldh1l1.RiboTag.bulk.cortex",
  306. xt_f = "Arial",
  307. xt_fb = 2,
  308. xt_s = 1,
  309. xt_c = "black",
  310. ytitle = "Aldh1l1.RiboTag.pos.pulldown",
  311. yt_f = "Arial",
  312. yt_fb = 2,
  313. yt_s = 1,
  314. yt_c = "black",
  315. nrtype = "abs",
  316. nr_f = "Arial",
  317. nr_fb = 2,
  318. nr_s = 1,
  319. nr_c = "black",
  320. x_c = "grey",
  321. y_c = "red",
  322. # z_c = "blue",
  323. bg_c = "white",
  324. width = 1000,
  325. height = 1000,
  326. #output = "screen",
  327. filename = NULL,
  328. map2ens = FALSE)
  329. # [1] "x bulk.cortex: 17583"
  330. # [1] "y bulk.cortex: 16737"
  331. # [1] "z bulk.cortex: 0"
  332. # [1] "x only: 1319"
  333. # [1] "y only: 473"
  334. # [1] "z only: 0"
  335. # [1] "x-y bulk.cortex overlap: 16264"
  336. # Aldh1l1.pos.pulldown vs Aldh1l1.RiboTag.pos.pulldown
  337. biovenn3 <- draw.venn(Aldh1l1.pos.pulldown_genes, Aldh1l1.RiboTag.pos.pulldown_genes, list_z,
  338. t_fb = 2,
  339. t_s = 1.5,
  340. t_c = "black",
  341. t_f = "Arial",
  342. title="Aldh1l1.TurboID vs Aldh1l1.RiboTag pulldown RNA",
  343. xtitle = "Aldh1l1.TurboID",
  344. xt_f = "Arial",
  345. xt_fb = 2,
  346. xt_s = 1,
  347. xt_c = "black",
  348. ytitle = "Aldh1l1.RiboTag",
  349. yt_f = "Arial",
  350. yt_fb = 2,
  351. yt_s = 1,
  352. yt_c = "black",
  353. nrtype = "abs",
  354. nr_f = "Arial",
  355. nr_fb = 2,
  356. nr_s = 1,
  357. nr_c = "black",
  358. x_c = "purple4",
  359. y_c = "red4",
  360. # z_c = "blue",
  361. bg_c = "white",
  362. width = 1000,
  363. height = 1000,
  364. #output = "screen",
  365. filename = NULL,
  366. map2ens = FALSE)
  367. # [1] "x bulk.cortex: 16632"
  368. # [1] "y bulk.cortex: 16737"
  369. # [1] "z bulk.cortex: 0"
  370. # [1] "x only: 666"
  371. # [1] "y only: 771"
  372. # [1] "z only: 0"
  373. # [1] "x-y bulk.cortex overlap: 15966"
  374. # [1] "x-z bulk.cortex overlap: 0"
  375. # [1] "y-z bulk.cortex overlap: 0"
  376. # [1] "x-y only overlap: 15966"
  377. dev.off()
  378. ################################################################################
  379. ################################################################################
  380. ## Step 1b: Create row mean filter >=10 across all samples for downstream diffex analysis
  381. # calculate row mean
  382. counts_clean_row_mean <- rowMeans(raw_counts_clean_9_2_8_1)
  383. # subset rows where row means >= 10
  384. counts_clean_filtered_rows_9_2_8_1 <- raw_counts_clean_9_2_8_1[counts_clean_row_mean >= 10, ]
  385. dim(counts_clean_filtered_rows_9_2_8_1)
  386. # [1] 17054 31
  387. # write .csv file
  388. write.csv(counts_clean_filtered_rows_9_2_8_1, file=paste0("1b.Exp. 9-2 and 8-1_RNA-seq_clean_counts_diffex filter-",dim(counts_clean_filtered_rows_9_2_8_1)[1],"x",dim(counts_clean_filtered_rows_9_2_8_1)[2],"_CR_06182024.csv"))
  389. ################################################################################
  390. ################################################################################
  391. ## Step 2: DESeq2 normalization of counts based on median of ratios
  392. # load library
  393. library(DESeq2)
  394. # create DESeq data set matrix (dds) for all 31 samples
  395. dds_all9_2_8_1 <- DESeqDataSetFromMatrix(countData = counts_clean_filtered_rows_9_2_8_1,
  396. colData = traits_9_2_8_1,
  397. design = ~Group)
  398. dim(dds_all9_2_8_1)
  399. # [1] 17054 31
  400. # set the factor level
  401. dds_all9_2_8_1$Group <- relevel(dds_all9_2_8_1$Group, ref = "Aldh1l1.bulk.cortex")
  402. # run DESeq
  403. dds_all9_2_8_1<- DESeq(dds_all9_2_8_1)
  404. View(counts(dds_all9_2_8_1))
  405. dds <- dds_all9_2_8_1
  406. dds <- estimateSizeFactors(dds)
  407. sizeFactors(dds)
  408. # 21047FL-134-01-28 21047FL-134-01-29 21047FL-134-01-30 21047FL-134-01-31 21047FL-134-01-32 21047FL-134-01-33
  409. # 0.8893720 0.8049612 0.7749720 0.8572228 1.0256973 1.1482553
  410. # 21047FL-134-01-34 21047FL-134-01-35 21047FL-134-01-36 21047FL-134-01-37 21047FL-134-01-38 21047FL-134-01-39
  411. # 0.9989146 0.6364181 0.7855086 0.9811747 0.9203750 1.2266314
  412. # 21047FL-134-01-40 21047FL-134-01-41 21047FL-134-01-42 21047FL-134-01-43 21047FL-134-01-44 21047FL-134-01-45
  413. # 1.5524386 1.0284815 1.0962545 0.8934085 1.0540818 0.7051570
  414. # 21047FL-134-01-46 21047FL-134-01-47 21047FL-134-01-48 23238R-04-01 23238R-04-02 23238R-04-03
  415. # 0.8453669 0.8415983 0.8265650 1.1347803 1.2736475 1.3087446
  416. # 23238R-04-04 23238R-04-05 23238R-04-06 23238R-04-07 23238R-04-08 23238R-04-09
  417. # 1.2948424 1.0700477 1.2484744 1.2103432 0.8805125 1.1037337
  418. # 23238R-04-10
  419. # 1.2092379
  420. normalized_counts_1 <- counts(dds, normalized=TRUE)
  421. write.csv(normalized_counts_1, file=paste0("2a.Exp. 9-2 and 8-1_RNA-seq_clean_filtered_DESeq2 norm counts_diffex filter-",dim(normalized_counts_1)[1],"x",dim(normalized_counts_1)[2],"_CR_06182024.csv"))
  422. ################################################################################
  423. # updated clean_counts with neg.pulldowns removed
  424. all9_2_8_1_no_negs_clean_counts <- counts_clean_filtered_rows_9_2_8_1[,c(1:11, 14:26, 29:31)]
  425. # udated traits with neg.pulldowns removed
  426. all9_2_8_1_no_negs_traits <- traits_9_2_8_1[c(1:11, 14:26, 29:31),]
  427. all9_2_8_1_no_negs_traits
  428. # create DESeq data set matrix dds for all 22 samples
  429. dds_all9_2_8_1_no_negs <- DESeqDataSetFromMatrix(countData = all9_2_8_1_no_negs_clean_counts,
  430. colData = all9_2_8_1_no_negs_traits,
  431. design = ~Group)
  432. dim(dds_all9_2_8_1_no_negs)
  433. # [1] 17054 27
  434. # set the factor level
  435. dds_all9_2_8_1_no_negs$Group <- relevel(dds_all9_2_8_1_no_negs$Group, ref = "Aldh1l1.bulk.cortex")
  436. # run DESeq
  437. dds_all9_2_8_1_no_negs<- DESeq(dds_all9_2_8_1_no_negs)
  438. View(counts(dds_all9_2_8_1_no_negs))
  439. dds <- dds_all9_2_8_1_no_negs
  440. dds <- estimateSizeFactors(dds)
  441. sizeFactors(dds)
  442. # 21047FL-134-01-28 21047FL-134-01-29 21047FL-134-01-30 21047FL-134-01-31 21047FL-134-01-32 21047FL-134-01-33
  443. # 0.9213783 0.8349613 0.8023031 0.8899217 1.0636470 1.1919804
  444. # 21047FL-134-01-34 21047FL-134-01-35 21047FL-134-01-36 21047FL-134-01-37 21047FL-134-01-38 21047FL-134-01-41
  445. # 1.0358285 0.6600755 0.8153691 1.0210895 0.9576344 1.0654161
  446. # 21047FL-134-01-42 21047FL-134-01-43 21047FL-134-01-44 21047FL-134-01-45 21047FL-134-01-46 21047FL-134-01-47
  447. # 1.1313599 0.9255927 1.0888734 0.7342807 0.8767168 0.8755041
  448. # 21047FL-134-01-48 23238R-04-01 23238R-04-02 23238R-04-03 23238R-04-04 23238R-04-05
  449. # 0.8588437 1.1870658 1.3348204 1.3673661 1.3577919 1.1199568
  450. # 23238R-04-08 23238R-04-09 23238R-04-10
  451. # 0.9121930 1.1422150 1.2556182
  452. normalized_counts_2 <- counts(dds, normalized=TRUE)
  453. write.csv(normalized_counts_2, file=paste0("2a.Exp. 9-2 and 8-1_RNA-seq_clean_filtered_DESeq2 norm counts_no negs_diffex filter-",dim(normalized_counts_2)[1],"x",dim(normalized_counts_2)[2],"_CR_06182024.csv"))
  454. ## end of data processing and clean up ##
  455. ################################################################################
  456. ################################################################################
  457. ## Part II: Data analysis and visualization
  458. # Exp. 9-2 and 8-1 mRNA-seq analysis
  459. # steps:
  460. # 1. PCAs
  461. # 1b. all groups w/o neg.pulldowns
  462. # 1c. Aldh1l1.pos.pulldown (n=3/group) vs Aldh1l1.RiboTag.pos.pulldown (n=3/group)
  463. # 2. Correlations
  464. # a. Aldh1l1.bulk.cortex vs Aldh1l1.RiboTag.bulk.cortex (n=2/group)
  465. # b. Aldh1l1.RiboTag.bulk.cortex (n=2/group) vs Aldh1l1.RiboTag.pos.pulldown (n=3/group)
  466. # c. Aldh1l1.pos.pulldown (n=3/group) vs Aldh1l1.RiboTag.pos.pulldown (n=3/group)
  467. # 3. Diffex volcanoes & GSEA
  468. # a. Aldh1l1.bulk.cortex vs Aldh1l1.RiboTag.bulk.cortex (n=2/group)
  469. # b. Aldh1l1.RiboTag.bulk.cortex (n=2/group) vs Aldh1l1.RiboTag.pos.pulldown (n=3/group)
  470. # c. Aldh1l1.pos.pulldown (n=3/group) vs Aldh1l1.RiboTag.pos.pulldown (n=3/group)
  471. ################################################################################
  472. ## Step 1: Generate PCA plots
  473. library(DESeq2)
  474. library(ggplot2)
  475. # 1a: all groups
  476. # create DESeq data set matrix dds for all 20 samples
  477. dds_all9_2_8_1 <- DESeqDataSetFromMatrix(countData = counts_clean_filtered_rows_9_2_8_1,
  478. colData = traits_9_2_8_1,
  479. design = ~Group)
  480. dim(dds_all9_2_8_1)
  481. # [1] 17054 31
  482. # set the factor level
  483. dds_all9_2_8_1$Group <- relevel(dds_all9_2_8_1$Group, ref = "Aldh1l1.bulk.cortex")
  484. # run DESeq
  485. dds_all9_2_8_1<- DESeq(dds_all9_2_8_1)
  486. # create pdf output file
  487. pdf(file = "1a-1. Exp. 9-2 and 8-1_RNA-seq_all groups_DESeq2_PCA_CR_06182024.pdf", width = 8, height = 8.5)
  488. layout(matrix(c(1,1,2, 1,1,3, 4,5,6), nrow = 3, ncol = 3, byrow=TRUE),
  489. heights = c(1.3,0.7,1.3), # Heights of the rows
  490. widths = c(0.65,0.65,0.7)) # Widths of the columns -- the distance to squash the second plot to the left, (because we do not duplicate legends)
  491. # perform DESeq2-basedPCA on rlog transformed data of all 20 samples
  492. rldr <- rlog(dds_all9_2_8_1, blind = TRUE)
  493. plotPCA(rldr, intgroup = "Group") # plots based on normalized counts
  494. pcaData <- plotPCA(rldr, intgroup = "Group", returnData=TRUE)
  495. percentVar <- round(100 * attr(pcaData, "percentVar"))
  496. pca1 <- ggplot(pcaData, aes(PC1, PC2, color=Group)) +
  497. geom_point(size=3) +
  498. xlab(paste0("PC1: ",percentVar[1],"% variance")) +
  499. ylab(paste0("PC2: ",percentVar[2],"% variance")) +
  500. ggtitle("DESeq2 PCA plot for log2(mean mRNA counts)") +
  501. theme(panel.background = element_rect(fill = "transparent", color = "black"),
  502. legend.background = element_rect(fill = "transparent"),
  503. legend.key = element_rect(fill = "transparent"),
  504. plot.title = element_text(hjust = 0.5)) + # Center the title
  505. labs(color = "Transcriptome groups") +
  506. coord_fixed()
  507. print(pca1)
  508. dev.off()
  509. ################################################################################
  510. # load library
  511. library(limma)
  512. # 1b: all groups w/o neg.pulldowns
  513. pdf(file = "1b-1. Exp. 9-2 and 8-1_RNA-seq_all groups_nonegs_DESeq2_PCA_CR_06182024.pdf", width = 8, height = 8.5)
  514. # perform DESeq2-basedPCA on rlog transformed data of 18 samples w/o neg pulldowns
  515. rldr <- rlog(dds_all9_2_8_1_no_negs, blind = TRUE)
  516. plotPCA(rldr, intgroup = "Group") # plots based on normalized counts
  517. pcaData <- plotPCA(rldr, intgroup = "Group", returnData=TRUE)
  518. percentVar <- round(100 * attr(pcaData, "percentVar"))
  519. pca2 <- ggplot(pcaData, aes(PC1, PC2, color=Group)) +
  520. geom_point(size=3) +
  521. xlab(paste0("PC1: ",percentVar[1],"% variance")) +
  522. ylab(paste0("PC2: ",percentVar[2],"% variance")) +
  523. ggtitle("DESeq2 PCA plot for log2(mean mRNA counts)") +
  524. theme(panel.background = element_rect(fill = "transparent", color = "black"),
  525. legend.background = element_rect(fill = "transparent"),
  526. legend.key = element_rect(fill = "transparent"),
  527. plot.title = element_text(hjust = 0.5)) + # Center the title
  528. labs(color = "Transcriptome groups") +
  529. coord_fixed()
  530. print(pca2)
  531. dev.off()
  532. ###############################################################################
  533. # CR didn't edit 06/20/2024
  534. # perform limma:plotMDS-based PCA w/o neg pulldowns
  535. library(limma)
  536. pdf(file = "1b-2. Exp. 9-2 and 8-1_RNA-seq_all groups_nonegs_Limma_PCA_CR_06182024.pdf", width = 8, height = 8.5)
  537. layout(matrix(c(1,1,2, 1,1,3, 4,5,6), nrow = 3, ncol = 3, byrow=TRUE),
  538. heights = c(1.3,0.7,1.3), # Heights of the rows
  539. widths = c(0.65,0.65,0.7)) # Widths of the columns -- the distance to squash the second plot to the left, (because we do not duplicate legends)
  540. Grouping_vector <- traits_9_2_8_1$Group[c(1:11, 14:24)]
  541. pch_values <- ifelse(Grouping_vector == "control.bulk.cortex", 16,
  542. ifelse(Grouping_vector == "control.LPS.bulk.cortex", 16,
  543. ifelse(Grouping_vector == "Aldh1l1.bulk.cortex", 16,
  544. ifelse(Grouping_vector == "Aldh1l1.RiboTag.bulk.cortex", 16,
  545. ifelse(Grouping_vector == "Aldh1l1.pos.pulldown", 16,
  546. ifelse(Grouping_vector == "Aldh1l1.LPS.pos.pulldown", 16,
  547. ifelse(Grouping_vector == "RiboTag.bulk.cortex", 16, NA)))))))
  548. pt_colors <- ifelse(Grouping_vector == "control.bulk.cortex", "magenta",
  549. ifelse(Grouping_vector == "control.LPS.bulk.cortex", "pink4",
  550. ifelse(Grouping_vector == "Aldh1l1.bulk.cortex", "coral",
  551. ifelse(Grouping_vector == "Aldh1l1.RiboTag.bulk.cortex", "green3",
  552. ifelse(Grouping_vector == "Aldh1l1.pos.pulldown", "purple2",
  553. ifelse(Grouping_vector == "Aldh1l1.LPS.pos.pulldown", "darkturquoise",
  554. ifelse(Grouping_vector == "RiboTag.bulk.cortex", "dodgerblue", NA)))))))
  555. legend_groups <- c("control.bulk.cortex", "control.LPS.bulk.cortex", "Aldh1l1.bulk.cortex", "Aldh1l1.RiboTag.bulk.cortex", "Aldh1l1.pos.pulldown","Aldh1l1.LPS.pos.pulldown", "RiboTag.bulk.cortex")
  556. plotMDS_1_4_allgroups_nonegs <- plotMDS(log2(normalized_counts_2), #top = 500,
  557. labels = NULL, pch = pch_values, col = pt_colors,
  558. cex = 3, dim.plot = c(1,2), gene.selection = "pairwise",
  559. xlab = NULL, ylab = NULL, plot = TRUE, var.explained = TRUE)
  560. mtext(side=3, text="MDS Plot for log2(mean mRNA counts)", cex=1, line=2)
  561. plot.new()
  562. legend("topright", legend = legend_groups, col = c("magenta", "pink4", "coral", "green3", "purple", "darkturquoise", "dodgerblue"),
  563. pch = 16, title = "Transcriptome groups",cex=1.4)
  564. dev.off()
  565. ###############################################################################
  566. # DESeq2-based PCA for Aldh1l1.bulk.cortex, Aldh1l1.RiboTag.bulk.cortex, Aldh1l1.pos.pulldown and Aldh1l1.RiboTag.pos.pulldown
  567. dim(counts_clean_filtered_rows_9_2_8_1)
  568. # [1] 17054 31
  569. dim(traits_9_2_8_1)
  570. # [1] 31 2
  571. # updated clean_counts
  572. TurboID_Vs_RiboTag.bulk.cortexs_pulls_clean_counts <- counts_clean_filtered_rows_9_2_8_1[,c(4:6, 14:16, 24:26, 29:31)]
  573. # updated traits
  574. TurboID_Vs_RiboTag.bulk.cortexs_pulls_traits <- traits_9_2_8_1[c(4:6, 14:16, 24:26, 29:31),]
  575. # Sample.ID.. Group
  576. # 21047FL-134-01-31 4-RNA 30L Aldh1l1.bulk.cortex
  577. # 21047FL-134-01-32 5-RNA 31B Aldh1l1.bulk.cortex
  578. # 21047FL-134-01-33 6-RNA 24L Aldh1l1.bulk.cortex
  579. # 21047FL-134-01-41 15-RNA 30L Aldh1l1.pos.pulldown
  580. # 21047FL-134-01-42 16-RNA 31B Aldh1l1.pos.pulldown
  581. # 21047FL-134-01-43 17-RNA 24L Aldh1l1.pos.pulldown
  582. # 23238R-04-03 CR3 Aldh1l1.RiboTag.bulk.cortex
  583. # 23238R-04-04 CR4 Aldh1l1.RiboTag.bulk.cortex
  584. # 23238R-04-05 CR5 Aldh1l1.RiboTag.bulk.cortex
  585. # 23238R-04-08 CR8 Aldh1l1.RiboTag.pos.pulldown
  586. # 23238R-04-09 CR9 Aldh1l1.RiboTag.pos.pulldown
  587. # 23238R-04-10 CR10 Aldh1l1.RiboTag.pos.pulldown
  588. # create DESeq data set matrix dds for all 20 samples
  589. dds_TurboID_Vs_RiboTag.bulk.cortexs_pulls <- DESeqDataSetFromMatrix(countData = TurboID_Vs_RiboTag.bulk.cortexs_pulls_clean_counts,
  590. colData = TurboID_Vs_RiboTag.bulk.cortexs_pulls_traits,
  591. design = ~Group)
  592. dim(dds_TurboID_Vs_RiboTag.bulk.cortexs_pulls)
  593. # [1] 17054 12
  594. # set the factor level
  595. dds_TurboID_Vs_RiboTag.bulk.cortexs_pulls$Group <- relevel(dds_TurboID_Vs_RiboTag.bulk.cortexs_pulls$Group, ref = "Aldh1l1.bulk.cortex")
  596. # run DESeq
  597. dds_TurboID_Vs_RiboTag.bulk.cortexs_pulls <- DESeq(dds_TurboID_Vs_RiboTag.bulk.cortexs_pulls)
  598. # create pdf output file
  599. pdf(file = "1c-1. Exp. 9-2 and 8-1_RNA-seq_TurboID_Vs_RiboTag.bulk.cortexs_pulls_DESeq2_PCA_CR_06182024.pdf", width = 8, height = 8.5)
  600. layout(matrix(c(1,1,2, 1,1,3, 4,5,6), nrow = 3, ncol = 3, byrow=TRUE),
  601. heights = c(1.3,0.7,1.3), # Heights of the rows
  602. widths = c(0.65,0.65,0.7)) # Widths of the columns -- the distance to squash the second plot to the left, (because we do not duplicate legends)
  603. # perform DESeq2-basedPCA on rlog transformed data of all 20 samples
  604. rldr <- rlog(dds_TurboID_Vs_RiboTag.bulk.cortexs_pulls, blind = TRUE)
  605. plotPCA(rldr, intgroup = "Group") # plots based on normalized counts
  606. pcaData <- plotPCA(rldr, intgroup = "Group", returnData=TRUE)
  607. percentVar <- round(100 * attr(pcaData, "percentVar"))
  608. pca3 <- ggplot(pcaData, aes(PC1, PC2, color=Group)) +
  609. geom_point(size=3) +
  610. xlab(paste0("PC1: ",percentVar[1],"% variance")) +
  611. ylab(paste0("PC2: ",percentVar[2],"% variance")) +
  612. ggtitle("DESeq2 PCA plot for log2(mean mRNA counts)") +
  613. theme(panel.background = element_rect(fill = "transparent", color = "black"),
  614. legend.background = element_rect(fill = "transparent"),
  615. legend.key = element_rect(fill = "transparent"),
  616. plot.title = element_text(hjust = 0.5)) + # Center the title
  617. labs(color = "Transcriptome groups") +
  618. coord_fixed()
  619. print(pca3)
  620. dev.off()
  621. ################################################################################
  622. # 1d Aldh1l1.pos.pulldown vs Aldh1l1.Ribotag.pos.pulldown
  623. # subset DESeq2 norm counts to only include Aldh1l1 samples
  624. #Updated clean_counts
  625. Aldh1l1_clean_counts <- counts_clean_filtered_rows_9_2_8_1[,c(14:16, 29:31)]
  626. #Updated traits
  627. Aldh1l1_traits <- traits_9_2_8_1[c(14:16, 29:31),]
  628. rownames(Aldh1l1_traits)
  629. # [1] "21047FL-134-01-41" "21047FL-134-01-42" "21047FL-134-01-43" "23238R-04-08" "23238R-04-09"
  630. # [6] "23238R-04-10"
  631. colnames(Aldh1l1_clean_counts)
  632. # [1] "21047FL-134-01-41" "21047FL-134-01-42" "21047FL-134-01-43" "23238R-04-08" "23238R-04-09"
  633. # [6] "23238R-04-10"
  634. #create DESeq data set (dds) matrix for the 3 Aldh1l1 and 3 Camk2a pos.pulldowns
  635. Aldh1l1_dds <- DESeqDataSetFromMatrix(countData = Aldh1l1_clean_counts, #filtered, unnorm counts is the input here
  636. colData = Aldh1l1_traits,
  637. design = ~Group)
  638. dim(Aldh1l1_dds)
  639. # [1] 17054 6
  640. # set the factor level
  641. Aldh1l1_dds$Group <- relevel(Aldh1l1_dds$Group, ref = "Aldh1l1.RiboTag.pos.pulldown")
  642. #Run DESeq
  643. Aldh1l1_dds<- DESeq(Aldh1l1_dds)
  644. # Create PCA plots
  645. pdf(file = "1d-1. Exp. 9-2 and 8-1_RNA-seq_Aldh1l1 pulldown groups_DESeq2_PCA_CR_06182024.pdf", width = 8, height = 8.5)
  646. # perform DESeq2-basedPCA on rlog transformed data of 16 samples w/o neg pulldowns
  647. rldr <- rlog(Aldh1l1_dds, blind = TRUE)
  648. plotPCA(rldr, intgroup = "Group") # plots based on normalized counts
  649. pcaData <- plotPCA(rldr, intgroup = "Group", returnData=TRUE)
  650. percentVar <- round(100 * attr(pcaData, "percentVar"))
  651. pca4 <- ggplot(pcaData, aes(PC1, PC2, color=Group)) +
  652. geom_point(size=3) +
  653. xlab(paste0("PC1: ",percentVar[1],"% variance")) +
  654. ylab(paste0("PC2: ",percentVar[2],"% variance")) +
  655. ggtitle("DESeq2 PCA plot for log2(mean mRNA counts)") +
  656. theme(panel.background = element_rect(fill = "transparent", color = "black"),
  657. legend.background = element_rect(fill = "transparent"),
  658. legend.key = element_rect(fill = "transparent"),
  659. plot.title = element_text(hjust = 0.5)) + # Center the title
  660. labs(color = "Transcriptome groups") +
  661. coord_fixed()
  662. print(pca4)
  663. dev.off()
  664. ################################################################################
  665. # perform limma:plotMDS-based PCA of 18 samples w/o neg pulldowns
  666. pdf(file = "1c-2. Exp. 9-2 and 8-1_RNA-seq_Aldh1l1 groups_Limma_PCA_CR_06182024.pdf", width = 8, height = 8.5)
  667. layout(matrix(c(1,1,2, 1,1,3, 4,5,6), nrow = 3, ncol = 3, byrow=TRUE),
  668. heights = c(1.3,0.7,1.3), # Heights of the rows
  669. widths = c(0.65,0.65,0.7)) # Widths of the columns -- the distance to squash the second plot to the left, (because we do not duplicate legends)
  670. Grouping_vector_Aldh1l1 <- Aldh1l1_traits$Group
  671. Aldh1l1_norm_counts <- normalized_counts_2[,c(4:11, 14:21)]
  672. pch_values <- ifelse(Grouping_vector_Aldh1l1== "Aldh1l1.bulk.cortex", 16,
  673. ifelse(Grouping_vector_Aldh1l1== "Aldh1l1.RiboTag.bulk.cortex", 16,
  674. ifelse(Grouping_vector_Aldh1l1== "Aldh1l1.pos.pulldown", 16,
  675. ifelse(Grouping_vector_Aldh1l1== "Aldh1l1.LPS.pos.pulldown", 16, NA))))
  676. pt_colors <- ifelse(Grouping_vector_Aldh1l1== "Aldh1l1.bulk.cortex", "coral",
  677. ifelse(Grouping_vector_Aldh1l1== "Aldh1l1.RiboTag.bulk.cortex", "green3",
  678. ifelse(Grouping_vector_Aldh1l1== "Aldh1l1.pos.pulldown", "purple",
  679. ifelse(Grouping_vector_Aldh1l1== "Aldh1l1.LPS.pos.pulldown", "darkturquoise", NA))))
  680. legend_groups <- c("Aldh1l1.bulk.cortex", "Aldh1l1.RiboTag.bulk.cortex", "Aldh1l1.pos.pulldown","Aldh1l1.LPS.pos.pulldown")
  681. plotMDS_Aldh1l1<- plotMDS(log2(Aldh1l1_norm_counts), #top = 500,
  682. labels = NULL, pch = pch_values, col = pt_colors,
  683. cex = 3, dim.plot = c(1,2), gene.selection = "pairwise",
  684. xlab = NULL, ylab = NULL, plot = TRUE, var.explained = TRUE)
  685. mtext(side=3, text="MDS Plot for log2(mean mRNA counts)", cex=1, line=2)
  686. plot.new()
  687. legend("topright", legend = legend_groups, col = c("coral", "green3", "purple", "darkturquoise"),
  688. pch = 16, title = "Transcriptome groups", cex = 1.4)
  689. dev.off()
  690. ###############################################################################
  691. # 1d. Aldh1l1.pos.pulldowns vs RiboTag.bulk.cortexs
  692. # subset DESeq2 norm counts to only include Aldh1l1 and RiboTag.bulk.cortex samples
  693. #Updated clean_counts
  694. Aldh1l1_Vs_RiboTag.bulk.cortex_clean_counts <- counts_clean_filtered_rows_9_2_8_1[,c(14:16, 22:23)]
  695. #Updated traits
  696. Aldh1l1_Vs_RiboTag.bulk.cortex_traits <- traits_9_2_8_1[c(14:16, 22:23),]
  697. # Sample.ID.. Group
  698. # 21047FL-134-01-41 15-RNA 30L Aldh1l1.pos.pulldown
  699. # 21047FL-134-01-42 16-RNA 31B Aldh1l1.pos.pulldown
  700. # 21047FL-134-01-43 17-RNA 24L Aldh1l1.pos.pulldown
  701. # 23238R-04-01 CR1 RiboTag.bulk.cortex
  702. # 23238R-04-02 CR2 RiboTag.bulk.cortex
  703. colnames(Aldh1l1_Vs_RiboTag.bulk.cortex_clean_counts)
  704. # [1] "21047FL-134-01-41" "21047FL-134-01-42" "21047FL-134-01-43" "23238R-04-01" "23238R-04-02"
  705. #create DESeq data set (dds) matrix for the 3 Aldh1l1 and 3 Camk2a pos.pulldowns
  706. Aldh1l1_Vs_RiboTag.bulk.cortex_dds <- DESeqDataSetFromMatrix(countData = Aldh1l1_Vs_RiboTag.bulk.cortex_clean_counts, #filtered, unnorm counts is the input here
  707. colData = Aldh1l1_Vs_RiboTag.bulk.cortex_traits,
  708. design = ~Group)
  709. dim(Aldh1l1_Vs_RiboTag.bulk.cortex_dds)
  710. # [1] 16825 6
  711. # set the factor level
  712. Aldh1l1_Vs_RiboTag.bulk.cortex_dds$Group <- relevel(Aldh1l1_Vs_RiboTag.bulk.cortex_dds$Group, ref = "RiboTag.bulk.cortex")
  713. #Run DESeq
  714. Aldh1l1_Vs_RiboTag.bulk.cortex_dds<- DESeq(Aldh1l1_Vs_RiboTag.bulk.cortex_dds)
  715. # Create PCA plots
  716. pdf(file = "1d-1. Exp. 9-2 and 8-1_RNA-seq_Aldh1l1 vs RiboTag.bulk.cortexs_DESeq2_PCA_CR_06182024.pdf", width = 8, height = 8.5)
  717. # perform DESeq2-basedPCA on rlog transformed data of 16 samples w/o neg pulldowns
  718. rldr <- rlog(Aldh1l1_Vs_RiboTag.bulk.cortex_dds, blind = TRUE)
  719. plotPCA(rldr, intgroup = "Group") # plots based on normalized counts
  720. pcaData <- plotPCA(rldr, intgroup = "Group", returnData=TRUE)
  721. percentVar <- round(100 * attr(pcaData, "percentVar"))
  722. pca3 <- ggplot(pcaData, aes(PC1, PC2, color=Group)) +
  723. geom_point(size=3) +
  724. xlab(paste0("PC1: ",percentVar[1],"% variance")) +
  725. ylab(paste0("PC2: ",percentVar[2],"% variance")) +
  726. theme(panel.background = element_rect(fill = "transparent", color = "black"),
  727. legend.background = element_rect(fill = "transparent"),
  728. legend.key = element_rect(fill = "transparent")) +
  729. labs(color = "Transcriptome groups") +
  730. coord_fixed()
  731. dev.off()
  732. # perform limma:plotMDS-based PCA of 18 samples w/o neg pulldowns
  733. pdf(file = "1d-2. Exp. 9-2 and 8-1_RNA-seq_Aldh1l1 vs Camk2a_Limma_PCA_CR_06182024.pdf", width = 8, height = 8.5)
  734. layout(matrix(c(1,1,2, 1,1,3, 4,5,6), nrow = 3, ncol = 3, byrow=TRUE),
  735. heights = c(1.3,0.7,1.3), # Heights of the rows
  736. widths = c(0.65,0.65,0.7)) # Widths of the columns -- the distance to squash the second plot to the left, (because we do not duplicate legends)
  737. Grouping_vector_Aldh1l1VsCamk2a <- Aldh1l1VsCamk2a_traits$Group
  738. Aldh1l1VsCamk2a_norm_counts <- normalized_counts_2[,c(12:14, 20:22)]
  739. colnames(Aldh1l1VsCamk2a_norm_counts)
  740. # [1] "21047FL-134-01-41" "21047FL-134-01-42" "21047FL-134-01-43" "22082R-12-01" "22082R-12-02"
  741. # [6] "22082R-12-03"
  742. pch_values <- ifelse(Grouping_vector_Aldh1l1VsCamk2a== "Aldh1l1.pos.pulldown", 16,
  743. ifelse(Grouping_vector_Aldh1l1VsCamk2a== "RiboTag.bulk.cortex", 16, NA))
  744. pt_colors <- ifelse(Grouping_vector_Aldh1l1VsCamk2a== "Aldh1l1.pos.pulldown", "purple",
  745. ifelse(Grouping_vector_Aldh1l1VsCamk2a== "RiboTag.bulk.cortex", "dodgerblue", NA))
  746. legend_groups <- c("Aldh1l1.pos.pulldown", "RiboTag.bulk.cortex")
  747. plotMDS_Aldh1l1<- plotMDS(log2(Aldh1l1VsCamk2a_norm_counts), #top = 500,
  748. labels = NULL, pch = pch_values, col = pt_colors,
  749. cex = 3, dim.plot = c(1,2), gene.selection = "pairwise",
  750. xlab = NULL, ylab = NULL, plot = TRUE, var.explained = TRUE)
  751. mtext(side=3, text="MDS Plot for log2(mean mRNA counts)", cex=1, line=2)
  752. plot.new()
  753. legend("topright", legend = legend_groups, col = c("purple", "dodgerblue"),
  754. pch = 16, title = "Transcriptome groups", cex = 1.4)
  755. dev.off()
  756. ################################################################################
  757. ################################################################################
  758. # Step 2. Correlations of mean mRNA counts
  759. # a. Aldh1l1.bulk.cortex (n=3/group) vs Aldh1l1.RiboTag.bulk.cortex (n=2/group)
  760. # b. Aldh1l1.RiboTag.bulk.cortex (n=2/group) vs Aldh1l1.RiboTag.pos.pulldown (n=3/group)
  761. # c. Aldh1l1.pos.pulldown (n=3/group) vs Aldh1l1.RiboTag.pos.pulldown (n=3/group)
  762. # check for finite values
  763. any(is.finite(normalized_counts_2))
  764. # [1] TRUE zeroes are considered finite
  765. dim(normalized_counts_2)
  766. # [1] 17054 27 (4 neg pulldowns removed)
  767. # CR: Because there are zeroes in the DESeq2 normalized counts data matrix,
  768. # the log2 transformation changes these values to infinite values (-ifn).
  769. # A correlation coefficient cannot be calculated with infinite values, so
  770. # I am going to add a "pseudocount" of + 1 to all the counts values to
  771. # avoid taking a log of 0.
  772. norm_counts_pseudo <- normalized_counts_2 + 1
  773. any(is.finite(norm_counts_pseudo))
  774. norm_counts_log <- log2(norm_counts_pseudo)
  775. any(is.finite(norm_counts_log))
  776. dim(norm_counts_log)
  777. # [1] 17054 27 (4 neg pulldowns removed)
  778. # load library to generate plot
  779. library(ggplot2)
  780. ################################################################################
  781. # 2a. Aldh1l1.bulk.cortex (n=3/group) vs Aldh1l1.RiboTag.bulk.cortex (n=2/group)
  782. pdf(file = "2a-c. Exp. 9-2 and 8-1_RNA-seq_counts correlations_CR_06182024.pdf", width = 6, height = 6, family = "Arial")
  783. par(mfrow= c(2,1)) # centers plot on single page (I think)
  784. # subset into groups of interest and take the row mean
  785. Aldh1l1.bulk.cortex <- rowMeans(norm_counts_log[,c(4:6)])
  786. Aldh1l1.RiboTag.bulk.cortex <- rowMeans(norm_counts_log[,c(22:24)])
  787. # generate a linear correlation
  788. correlation_2a <- cor(Aldh1l1.bulk.cortex, Aldh1l1.RiboTag.bulk.cortex)
  789. correlation_2a
  790. # [1] 0.9788304
  791. # convert data to a data frame
  792. df_2a <- data.frame(Aldh1l1.bulk.cortex = Aldh1l1.bulk.cortex, Aldh1l1.RiboTag.bulk.cortex = Aldh1l1.RiboTag.bulk.cortex)
  793. # create correlation plot
  794. correlation_plot_2a <- ggplot(df_2a, aes(x = Aldh1l1.bulk.cortex, y = Aldh1l1.RiboTag.bulk.cortex)) +
  795. geom_point(color = "black", fill = "grey", pch = 21, alpha = 0.5, size = 3) +
  796. labs(x = "Aldh1l1.bulk.cortex log2(mean mRNA counts)",
  797. y = "Aldh1l1.RiboTag.bulk.cortex log2(mean mRNA counts)") +
  798. ggtitle("2a. Aldh1l1.bulk.cortex vs Aldh1l1.RiboTag.bulk.cortex") +
  799. theme_minimal() +
  800. theme(
  801. panel.background = element_blank(), # Remove panel background
  802. panel.grid.major = element_blank(), # Remove major grid lines
  803. panel.grid.minor = element_blank(), # Remove minor grid lines
  804. axis.line = element_line(color = "black"), # Add black x and y axes
  805. axis.ticks = element_line(color = "black"), # Add ticks to the axes
  806. plot.title = element_text(hjust = 0.5) # Center the title
  807. ) +
  808. annotate("text", x = max(Aldh1l1.bulk.cortex), y = min(Aldh1l1.RiboTag.bulk.cortex),
  809. label = paste("Correlation coefficient:", round(correlation_2a, 2)),
  810. hjust = 1, vjust = 0, color = "black") +
  811. annotate("text", x = min(df_2a$Aldh1l1.bulk.cortex), y = min(df_2a$Aldh1l1.RiboTag.bulk.cortex) - 2,
  812. label = paste("\nNumber of genes:", nrow(df_2a)),
  813. hjust = 0, vjust = 1, color = "black") + # Adjusted y coordinate
  814. scale_x_continuous(breaks = seq(0, 20, by = 5), limits = c(0, 20)) +
  815. scale_y_continuous(breaks = seq(0, 20, by = 5), limits = c(0, 20))
  816. print(correlation_plot_2a)
  817. ################################################################################
  818. # 2b. Aldh1l1.RiboTag.bulk.cortex (n=2/group) vs Aldh1l1.RiboTag.pos.pulldown (n=3/group)
  819. # subset into groups of interest and take the row mean
  820. Aldh1l1.RiboTag.bulk.cortex <- rowMeans(norm_counts_log[,c(22:24)])
  821. Aldh1l1.RiboTag.pos.pulldown <- rowMeans(norm_counts_log[,c(25:27)])
  822. # convert data to a data frame
  823. df_2b <- data.frame(Aldh1l1.RiboTag.bulk.cortex = Aldh1l1.RiboTag.bulk.cortex, Aldh1l1.RiboTag.pos.pulldown = Aldh1l1.RiboTag.pos.pulldown)
  824. # calculate correlation coefficient
  825. correlation_2b <- cor(Aldh1l1.RiboTag.bulk.cortex, Aldh1l1.RiboTag.pos.pulldown) # cor() is based on Pearson's correlation by default, can change if needed by adding method = "spearman" or others
  826. correlation_2b
  827. # [1] 0.9169184
  828. correlation_plot_2b <- ggplot(df_2b, aes(x = Aldh1l1.RiboTag.bulk.cortex, y = Aldh1l1.RiboTag.pos.pulldown)) +
  829. geom_point(color = "black", fill = "red4", pch = 21, alpha = 0.5, size = 3) +
  830. labs(x = "Aldh1l1.RiboTag.bulk.cortex log2(mean mRNA counts)",
  831. y = "Aldh1l1.RiboTag.pos.pulldown log2(mean mRNA counts)") +
  832. ggtitle("2b. Aldh1l1.Ribotag bulk.cortex vs pulldown") +
  833. theme_minimal() +
  834. theme(
  835. panel.background = element_blank(), # Remove panel background
  836. panel.grid.major = element_blank(), # Remove major grid lines
  837. panel.grid.minor = element_blank(), # Remove minor grid lines
  838. axis.line = element_line(color = "black"), # Add black x and y axes
  839. axis.ticks = element_line(color = "black"), # Add ticks to the axes
  840. plot.title = element_text(hjust = 0.5) # Center the title
  841. ) +
  842. annotate("text", x = max(Aldh1l1.RiboTag.bulk.cortex), y = min(Aldh1l1.RiboTag.pos.pulldown),
  843. label = paste("Correlation coefficient:", round(correlation_2b, 2)),
  844. hjust = 1, vjust = 0, color = "black") +
  845. annotate("text", x = min(df_2b$Aldh1l1.RiboTag.bulk.cortex), y = min(df_2b$Aldh1l1.RiboTag.pos.pulldown) - 2,
  846. label = paste("Number of genes:", nrow(df_2a)), # # of genes are the same for each df
  847. hjust = 0, vjust = 1, color = "black") + # Adjusted y coordinate
  848. scale_x_continuous(breaks = seq(0, 20, by = 5), limits = c(0, 20)) +
  849. scale_y_continuous(breaks = seq(0, 20, by = 5), limits = c(0, 20))
  850. print(correlation_plot_2b)
  851. ################################################################################
  852. # 2c.Aldh1l1.pos.pulldown (n=3/group) vs Aldh1l1.RiboTag.pos.pulldown (n=3/group)
  853. # subset into groups of interest and take the row mean
  854. Aldh1l1.pos.pulldown <- rowMeans(norm_counts_log[,c(12:14)])
  855. Aldh1l1.RiboTag.pos.pulldown <- rowMeans(norm_counts_log[,c(25:27)])
  856. # convert data to a data frame
  857. df_2c <- data.frame(Aldh1l1.pos.pulldown = Aldh1l1.pos.pulldown, Aldh1l1.RiboTag.pos.pulldown = Aldh1l1.RiboTag.pos.pulldown)
  858. # calculate correlation coefficient
  859. correlation_2c <- cor(Aldh1l1.pos.pulldown, Aldh1l1.RiboTag.pos.pulldown) # cor() is based on Pearson's correlation by default, can change if needed by adding method = "spearman" or others
  860. correlation_2c
  861. # [1] 0.9326028
  862. correlation_plot_2c <- ggplot(df_2c, aes(x = Aldh1l1.pos.pulldown, y = Aldh1l1.RiboTag.pos.pulldown)) +
  863. geom_point(color = "black", fill = "red2", pch = 21, alpha = 0.5, size = 3) +
  864. labs(x = "Aldh1l1.pos.pulldown log2(mean mRNA counts)",
  865. y = "Aldh1l1.RiboTag log2(mean mRNA counts)") +
  866. ggtitle("2c. Aldh1l1 TurboID vs RiboTag pulldown RNA") +
  867. theme_minimal() +
  868. theme(
  869. panel.background = element_blank(), # Remove panel background
  870. panel.grid.major = element_blank(), # Remove major grid lines
  871. panel.grid.minor = element_blank(), # Remove minor grid lines
  872. axis.line = element_line(color = "black"), # Add black x and y axes
  873. axis.ticks = element_line(color = "black"), # Add ticks to the axes
  874. plot.title = element_text(hjust = 0.5) # Center the title
  875. ) +
  876. annotate("text", x = max(Aldh1l1.pos.pulldown), y = min(Aldh1l1.RiboTag.pos.pulldown),
  877. label = paste("Correlation coefficient:", round(correlation_2c, 2)),
  878. hjust = 1, vjust = 0, color = "black") +
  879. annotate("text", x = min(df_2c$Aldh1l1.pos.pulldown), y = min(df_2c$Aldh1l1.RiboTag.pos.pulldown) - 2,
  880. label = paste("Number of genes:", nrow(df_2a)), # # of genes are the same for each df
  881. hjust = 1, vjust = 0, color = "black") + # Adjusted y coordinate
  882. scale_x_continuous(breaks = seq(0, 20, by = 5), limits = c(0, 20)) +
  883. scale_y_continuous(breaks = seq(0, 20, by = 5), limits = c(0, 20))
  884. print(correlation_plot_2c)
  885. dev.off()
  886. ################################################################################
  887. ################################################################################
  888. # Step 3 Part I: Diffex volcanoes
  889. # C2: Astrocyte-RiboTag pulldown vs bulk.cortex
  890. # C4: Astrocyte-RiboTag vs astrocyte-TurboID pulldown
  891. ################################################################################
  892. #load Libraries
  893. library(DESeq2)
  894. library(tidyverse)
  895. library(biomaRt)
  896. library(pheatmap)
  897. library(ggplot2)
  898. library(ggrepel)
  899. ################################################################################
  900. # C2: Astrocyte-RiboTag pulldown vs bulk.cortex
  901. pdf(file = "C2_Aldh1l1.RiboTag.pulldown vs Aldh1l1.RiboTag.bulk.cortex_rowmeans_17054_Diffex_06182024.pdf", height = 8, width = 8.5)
  902. layout(matrix(c(1,1,2, 1,1,3, 4,5,6), nrow = 3, ncol = 3, byrow=TRUE),
  903. heights = c(1.3,0.7,1.3), # Heights of the rows
  904. widths = c(0.65,0.65,0.7)) # Widths of the columns -- the distance to squash the second plot to the left, (because we do not duplicate legends)
  905. final_clean_counts <- counts_clean_filtered_rows_9_2_8_1
  906. dim(final_clean_counts)
  907. # [1] 17054 31
  908. #Updated clean_counts for comparison 1
  909. C2_clean_counts <- final_clean_counts[,c(24:26, 29:31)]
  910. #Updated traits_9_2_8_1 for comparison 1
  911. C2_traits_9_2_8_1 <- traits_9_2_8_1[c(24:26, 29:31),]
  912. C2_traits_9_2_8_1
  913. # Sample.ID.. Group
  914. # 23238R-04-03 CR3 Aldh1l1.RiboTag.bulk.cortex
  915. # 23238R-04-04 CR4 Aldh1l1.RiboTag.bulk.cortex
  916. # 23238R-04-05 CR5 Aldh1l1.RiboTag.bulk.cortex
  917. # 23238R-04-08 CR8 Aldh1l1.RiboTag.pos.pulldown
  918. # 23238R-04-09 CR9 Aldh1l1.RiboTag.pos.pulldown
  919. # 23238R-04-10 CR10 Aldh1l1.RiboTag.pos.pulldown
  920. #Deseq2 data matrix is needed for downstream analysis
  921. dds2 <- DESeqDataSetFromMatrix(countData = C2_clean_counts,
  922. colData = C2_traits_9_2_8_1,
  923. design = ~Group)
  924. dim(dds2)
  925. # [1] 17054 6
  926. dds2
  927. # set the factor level
  928. dds2$Group <- relevel(dds2$Group, ref = "Aldh1l1.RiboTag.bulk.cortex")
  929. #Run DESeq
  930. dds2 <- DESeq(dds2)
  931. #diff p adj value
  932. res05 <- results(dds2, alpha = 0.05)
  933. res05 #table w statistics
  934. #diff ex analysis
  935. summary(res05)
  936. # out of 17051 with nonzero bulk.cortex read count
  937. # adjusted p-value < 0.05
  938. # LFC > 0 (up) : 5895, 35%
  939. # LFC < 0 (down) : 5347, 31%
  940. # outliers [1] : 0, 0%
  941. # low counts [2] : 0, 0%
  942. # (mean count < 0)
  943. dim(res05)
  944. # [1] 17054 6
  945. #contrasts
  946. resultsNames(dds2)
  947. # [1] "Intercept"
  948. # [2] "Group_Aldh1l1.RiboTag.pos.pulldown_vs_Aldh1l1.RiboTag.bulk.cortex"
  949. #plot MA
  950. #In DESeq2, the function plotMA shows the log2 fold changes attributable to a given variable over the mean of normalized counts for all the samples in the DESeqDataSet. Points will be colored red if the adjusted p value is less than 0.1. Points which fall out of the window are plotted as open triangles pointing either up or down.
  951. plotMA(res05, main = "Comparison 2: Aldh1l1.RiboTag.pulldown vs Aldh1l1.RiboTag.bulk.cortex")
  952. #use the log transform on the data set
  953. #The above will plot the most varied genes across all conditions
  954. rld <- rlog(dds2, blind=TRUE)
  955. de2 <- as.data.frame(res05)
  956. de2$padj[is.na(de2$padj)] <- 1
  957. write.csv(de2, file = "C2_Aldh1l1.RiboTag.pulldown vs Aldh1l1.RiboTag.bulk.cortex_rowmeans_17054_Diffex_06182024.csv")
  958. var <- order(de2$padj, decreasing=F)
  959. #topAdjpGenes <- which(var <= 20)
  960. #allows you to hold your enrs ids and sample names in a df
  961. #Most sig genes! Top 50
  962. matrix <- assay(rld)[ var[1:50], ]
  963. matrix <- matrix - rowMeans(matrix)
  964. matrixx <- matrix
  965. #thresh_val <- min(abs(max(matrix)),abs(min(matrix)))
  966. thresh_val <- 0.5
  967. matrixx[matrixx < -thresh_val] <- -thresh_val
  968. matrixx[matrixx > thresh_val] <- thresh_val
  969. annotation_data <- as.data.frame(colData(rld)[c("Group")])
  970. pheatmap(matrixx, annotation_col=annotation_data, show_rownames = T,show_colnames = T, cluster_cols=TRUE, main = "Top 50 padj C2_Aldh1l1.RiboTag.pulldown vs Aldh1l1.RiboTag.bulk.cortex_rowmeans_17054")
  971. #up and down list created to pull out diff ex genes
  972. up <- res05[which(res05$log2FoldChange > 1 & res05$padj < .05),]
  973. down <- res05[which(res05$log2FoldChange < -1 & res05$padj < .05),]
  974. write.csv(up, file = "C2_Aldh1l1.RiboTag.pulldown vs Aldh1l1.RiboTag.bulk.cortex_rowmeans_17054_Diffex_Up_06182024.csv")
  975. write.csv(down, file = "C2_Aldh1l1.RiboTag.pulldown vs Aldh1l1.RiboTag.bulk.cortex_rowmeans_17054_Diffex_Down_06182024.csv")
  976. #The counts here need to match with the one counter above by the model!
  977. up_genes <- read.csv("C2_Aldh1l1.RiboTag.pulldown vs Aldh1l1.RiboTag.bulk.cortex_rowmeans_17054_Diffex_Up_06182024.csv", header = TRUE, row.names = 1)
  978. down_genes <- read.csv("C2_Aldh1l1.RiboTag.pulldown vs Aldh1l1.RiboTag.bulk.cortex_rowmeans_17054_Diffex_Down_06182024.csv", header = TRUE, row.names = 1)
  979. #bulk.cortex df of up and down genes based on a criteria that were extracted!
  980. up_down_genes <- rbind(up_genes,down_genes)
  981. dim(up_down_genes)
  982. # [1] 5512 6
  983. #volcano plot of diffex with padj df
  984. de2 <- read.csv("C2_Aldh1l1.RiboTag.pulldown vs Aldh1l1.RiboTag.bulk.cortex_rowmeans_17054_Diffex_06182024.csv")
  985. de2$diffexpressed <- "NS"
  986. de2$diffexpressed[de2$log2FoldChange > 1.0 & de2$padj < 0.05] <- "UP"
  987. de2$diffexpressed[de2$log2FoldChange < -1.0 & de2$padj < 0.05] <- "DOWN"
  988. de2$delabel <- NA
  989. de2$delabel[de2$diffexpressed != "NS"] <- de2$X[de2$diffexpressed != "NS"]
  990. ggplot(data=de2, aes(x=log2FoldChange, y=-log10(padj), col=diffexpressed, label=delabel)) +
  991. geom_point() +
  992. ggtitle(label = "C2_Aldh1l1.RiboTag.pulldown vs Aldh1l1.RiboTag.bulk.cortex_rowmeans_17054") +
  993. theme_minimal() +
  994. geom_text_repel(segment.colour = NA, max.overlaps = getOption("ggrepel.max.overlaps", default = 15)) +
  995. scale_color_manual(values=c("black", "grey", "red4")) +
  996. geom_vline(xintercept=c(-1.0, 1.0), linetype = "longdash", col="black") +
  997. geom_hline(yintercept=-log10(0.05), linetype = "longdash", col="black") +
  998. theme(legend.position="none") +
  999. scale_y_continuous(name = "-log10(padj)",
  1000. limits = c(-5, 300)) +
  1001. scale_x_continuous(name = "log2(difference)
  1002. Aldh1l1.RiboTag.pulldown - Aldh1l1.RiboTag bulk.cortex RNA",
  1003. limits = c(-10, 10))
  1004. #Perform PCA on rlog transformed data
  1005. rldr <- rlog(dds2, blind = TRUE)
  1006. plotPCA(rldr, intgroup = "Group")
  1007. dev.off()
  1008. ################################################################################
  1009. ################################################################################
  1010. # C4: Astrocyte-RiboTag pulldown vs Astrocyte-TurboID pulldown
  1011. #use base pdf function to extract plots into a single pdf
  1012. pdf(file = "C4_Aldh1l1.TurboID vs Aldh1l1.RiboTag pulldowns_rowmeans_17054_Diffex_06182024.pdf", height = 8, width = 8.5)
  1013. layout(matrix(c(1,1,2, 1,1,3, 4,5,6), nrow = 3, ncol = 3, byrow=TRUE),
  1014. heights = c(1.3,0.7,1.3), # Heights of the rows
  1015. widths = c(0.65,0.65,0.7)) # Widths of the columns -- the distance to squash the second plot to the left, (because we do not duplicate legends)
  1016. final_clean_counts <- counts_clean_filtered_rows_9_2_8_1
  1017. dim(final_clean_counts)
  1018. # [1] 17054 31
  1019. #Updated clean_counts for comparison 1
  1020. C4_clean_counts <- final_clean_counts[,c(14:16, 29:31)]
  1021. #Updated traits_9_2_8_1 for comparison 1
  1022. C4_traits_9_2_8_1 <- traits_9_2_8_1[c(14:16, 29:31),]
  1023. C4_traits_9_2_8_1
  1024. # Sample.ID.. Group
  1025. # 21047FL-134-01-41 15-RNA 30L Aldh1l1.pos.pulldown
  1026. # 21047FL-134-01-42 16-RNA 31B Aldh1l1.pos.pulldown
  1027. # 21047FL-134-01-43 17-RNA 24L Aldh1l1.pos.pulldown
  1028. # 23238R-04-08 CR8 Aldh1l1.RiboTag.pos.pulldown
  1029. # 23238R-04-09 CR9 Aldh1l1.RiboTag.pos.pulldown
  1030. # 23238R-04-10 CR10 Aldh1l1.RiboTag.pos.pulldown
  1031. #Deseq2 data matrix is needed for downstream analysis
  1032. dds4 <- DESeqDataSetFromMatrix(countData = C4_clean_counts,
  1033. colData = C4_traits_9_2_8_1,
  1034. design = ~Group)
  1035. dim(dds4)
  1036. # [1] 17054 6
  1037. dds4
  1038. # set the factor level
  1039. dds4$Group <- relevel(dds4$Group, ref = "Aldh1l1.RiboTag.pos.pulldown")
  1040. #Run DESeq
  1041. dds4 <- DESeq(dds4)
  1042. #diff p adj value
  1043. res05 <- results(dds4, alpha = 0.05)
  1044. res05 #table w statistics
  1045. #diff ex analysis
  1046. summary(res05)
  1047. # out of 17054 with nonzero bulk.cortex read count
  1048. # adjusted p-value < 0.05
  1049. # LFC > 0 (up) : 4519, 26%
  1050. # LFC < 0 (down) : 4555, 27%
  1051. # outliers [1] : 0, 0%
  1052. # low counts [2] : 0, 0%
  1053. # (mean count < 1)
  1054. dim(res05)
  1055. # [1] 17054 6
  1056. #contrasts
  1057. resultsNames(dds4)
  1058. # [1] "Intercept"
  1059. # [2] "Group_Aldh1l1.pos.pulldown_vs_Aldh1l1.RiboTag.pos.pulldown"
  1060. #plot MA
  1061. #In DESeq2, the function plotMA shows the log2 fold changes attributable to a given variable over the mean of normalized counts for all the samples in the DESeqDataSet. Points will be colored red if the adjusted p value is less than 0.1. Points which fall out of the window are plotted as open triangles pointing either up or down.
  1062. plotMA(res05, main = "Comparison 4: Aldh1l1.pos.pulldown vs Aldh1l1.RiboTag.pos.pulldown")
  1063. #use the log transform on the data set
  1064. #The above will plot the most varied genes across all conditions
  1065. rld <- rlog(dds4, blind=TRUE)
  1066. de4 <- as.data.frame(res05)
  1067. de4$padj[is.na(de4$padj)] <- 1
  1068. write.csv(de4, file = "C4_Aldh1l1.pos.pulldown vs Aldh1l1.RiboTag.pos.pulldown_rowmeans_17054_Diffex_06182024.csv")
  1069. var <- order(de4$padj, decreasing=F)
  1070. #topAdjpGenes <- which(var <= 20)
  1071. #allows you to hold your enrs ids and sample names in a df
  1072. #Most sig genes! Top 50
  1073. matrix <- assay(rld)[ var[1:50], ]
  1074. matrix <- matrix - rowMeans(matrix)
  1075. matrixx <- matrix
  1076. #thresh_val <- min(abs(max(matrix)),abs(min(matrix)))
  1077. thresh_val <- 0.5
  1078. matrixx[matrixx < -thresh_val] <- -thresh_val
  1079. matrixx[matrixx > thresh_val] <- thresh_val
  1080. annotation_data <- as.data.frame(colData(rld)[c("Group")])
  1081. pheatmap(matrixx, annotation_col=annotation_data, show_rownames = T,show_colnames = T, cluster_cols=TRUE, main = "Top 50 padj C4_Aldh1l1.pos.pulldown vs Aldh1l1.RiboTag.pos.pulldown_rowmeans_17054")
  1082. #up and down list created to pull out diff ex genes
  1083. up <- res05[which(res05$log2FoldChange > 1 & res05$padj < .05),]
  1084. down <- res05[which(res05$log2FoldChange < -1 & res05$padj < .05),]
  1085. write.csv(up, file = "C4_Aldh1l1.pos.pulldown vs Aldh1l1.RiboTag.pos.pulldown_rowmeans_17054_Diffex_Up_06182024.csv")
  1086. write.csv(down, file = "C4_Aldh1l1.pos.pulldown vs Aldh1l1.RiboTag.pos.pulldown_rowmeans_17054_Diffex_Down_06182024.csv")
  1087. #The counts here need to match with the one counter above by the model!
  1088. up_genes <- read.csv("C4_Aldh1l1.pos.pulldown vs Aldh1l1.RiboTag.pos.pulldown_rowmeans_17054_Diffex_Up_06182024.csv", header = TRUE, row.names = 1)
  1089. down_genes <- read.csv("C4_Aldh1l1.pos.pulldown vs Aldh1l1.RiboTag.pos.pulldown_rowmeans_17054_Diffex_Down_06182024.csv", header = TRUE, row.names = 1)
  1090. #bulk.cortex df of up and down genes based on a criteria that were extracted!
  1091. up_down_genes <- rbind(up_genes,down_genes)
  1092. dim(up_down_genes)
  1093. # [1] 4362 6
  1094. #volcano plot of diffex with padj df
  1095. de4 <- read.csv("C4_Aldh1l1.pos.pulldown vs Aldh1l1.RiboTag.pos.pulldown_rowmeans_17054_Diffex_06182024.csv")
  1096. de4$diffexpressed <- "NS"
  1097. de4$diffexpressed[de4$log2FoldChange > 1.0 & de4$padj < 0.05] <- "UP"
  1098. de4$diffexpressed[de4$log2FoldChange < -1.0 & de4$padj < 0.05] <- "DOWN"
  1099. de4$delabel <- NA
  1100. de4$delabel[de4$diffexpressed != "NS"] <- de4$X[de4$diffexpressed != "NS"]
  1101. ggplot(data=de4, aes(x=log2FoldChange, y=-log10(padj), col=diffexpressed, label=delabel)) +
  1102. geom_point() +
  1103. ggtitle(label = "C4_Aldh1l1.pos.pulldown vs Aldh1l1.RiboTag.pos.pulldown_rowmeans_17054") +
  1104. theme_minimal() +
  1105. geom_text_repel(segment.colour = NA, max.overlaps = getOption("ggrepel.max.overlaps", default = 15)) +
  1106. scale_color_manual(values=c("red4", "grey", "purple4")) +
  1107. geom_vline(xintercept=c(-1.0, 1.0), linetype = "longdash", col="black") +
  1108. geom_hline(yintercept=-log10(0.05), linetype = "longdash", col="black") +
  1109. theme(legend.position="none") +
  1110. scale_y_continuous(name = "-log10(padj)",
  1111. limits = c(-5, 200)) +
  1112. scale_x_continuous(name = "log2(difference)
  1113. Aldh1l1.TurboID - Aldh1l1.RiboTag pulldown RNA",
  1114. limits = c(-30, 30))
  1115. #Perform PCA on rlog transformed data
  1116. rldr <- rlog(dds1, blind = TRUE)
  1117. plotPCA(rldr, intgroup = "Group")
  1118. dev.off()
  1119. ################################################################################
  1120. ################################################################################
  1121. # Step 3 Part II: Diffex GSEA
  1122. ################################################################################
  1123. # Gene set erichment analysis with Eric Dammer's GOparallel pipeline
  1124. # https://github.com/edammer/GOparallel
  1125. # performs hypergeometric overlap with Fisher Exact Test for enrichment p<0.05 and 5 minimum genes per ontology
  1126. # currently outputs files that can be used as GO-Elite input, not read by this script...
  1127. # outputs Z score barplots for each input list (module, or DiffEx Protein list) across 6 ontology types in the larger GMT files available from the Bader Lab website.
  1128. # Parameters for GOparallel GSEA on volcano-defined DEG lists
  1129. source("GOparallel-FET.R")
  1130. ## Parameters saved to variables in memory.
  1131. filePath <- getwd()
  1132. #Folder that (may) contain the input file specified above, and which will contain the outFilename project Folder.
  1133. modulesInMemory=FALSE
  1134. ANOVAgroups=TRUE #change to FALSE if using inputFile
  1135. #if true, modulesInMemory ignored. Volcano pipeline code should already have been run!
  1136. #inputFile will be ignored
  1137. maxBarsPerOntology=6
  1138. panelDimensions=c(2,2) #dimensions of the individual parblots within a page of the main barplot PDF output
  1139. pageDimensions=c(8.5,11) #main barplot PDF output page dimensions, in inches
  1140. parallelThreads=7 # need at least 2 threads to run
  1141. removeRedundantGOterms=TRUE
  1142. #if true, the 3 GO ontology types are collapased into a minimal set of less redundant terms using the below OBO file
  1143. cocluster=FALSE
  1144. #If TRUE, output PDF of signed Zscore coclustering on GO:cellular component terms (useful for WGCNA modules)
  1145. # "Clean up" to run before GOPar
  1146. rm(ANOVAout)
  1147. ###############################################################################
  1148. # Relevant diffex comparisons:
  1149. # C2_Aldh1l1.RiboTag.pulldown vs Aldh1l1.RiboTag.bulk.cortex_rowmeans_17054_Diffex_06182024.csv
  1150. # C4_Aldh1l1.pos.pulldown vs Aldh1l1.RiboTag.pos.pulldown_rowmeans_17054_Diffex_06182024.csv
  1151. ###############################################################################
  1152. # Comparsion 2: Aldh1l1.RiboTag.pulldown vs Aldh1l1.RiboTag.bulk.cortex
  1153. # organize DESeq2 diffex output file to mirror LFQ-MS ANOVAout file
  1154. C2_ANOVA<-read.csv("C2_Aldh1l1.RiboTag.pulldown vs Aldh1l1.RiboTag.bulk.cortex_rowmeans_17054_Diffex_06182024.csv", header=TRUE, row.names=1)
  1155. C2_ANOVAout<-C2_ANOVA[,c(4,1,5,2)]
  1156. colnames(C2_ANOVAout)[c(3,4)]<-c("Aldh1l1.RiboTag.pull-Aldh1l1.RiboTag.bulk.cortex","diff Aldh1l1.RiboTag.pull.Aldh1l1.RiboTag.bulk.cortex")
  1157. write.csv(C2_ANOVAout, file = "C2_RNA_ANOVAout_Aldh1l1.RiboTag.pulldown vs Aldh1l1.RiboTag.bulk.cortex_rowmeans_17054_Diffex_06182024.csv")
  1158. # GOpar
  1159. flip=c(0)
  1160. outFilename <- "C2_RNA_Aldh1l1.RiboTag.pulldown vs Aldh1l1.RiboTag.bulk.cortex_pval_DEGs-GO"
  1161. GMTdatabaseFile="Mouse_GO_AllPathways_with_GO_iea_November_07_2023_symbol.gmt"
  1162. GOparallel(C2_ANOVAout) # parameters are set in global environment as above; if not set, the function falls back to defaults and looks for all inputs available.
  1163. ###############################################################################
  1164. # Comparison 4: Astrocyte-TurboID pulldown vs Astrocyte-RiboTag pulldown
  1165. # organize DESeq2 diffex output file to mirror LFQ-MS ANOVAout file
  1166. C4_ANOVA<-read.csv("C4_Aldh1l1.pos.pulldown vs Aldh1l1.RiboTag.pos.pulldown_rowmeans_17054_Diffex_06182024.csv", header=TRUE, row.names=1)
  1167. C4_ANOVAout<-C4_ANOVA[,c(4,1,5,2)]
  1168. colnames(C4_ANOVAout)[c(3,4)]<-c("Aldh1l1.TurboID-Aldh1l1.RiboTag","diff Aldh1l1.TurboID.Aldh1l1.Ribotag")
  1169. write.csv(C4_ANOVAout, file = "C4_RNA_ANOVAout_Aldh1l1.pos.pulldown vs Aldh1l1.RiboTag.pos.pulldown_rowmeans_17054_Diffex_06182024.csv")
  1170. # GOpar
  1171. flip=c(0)
  1172. outFilename <- "C4_RNA_Aldh1l1.TurboID vs Aldh1l1.RiboTag pulldowns_pval_DEGs-GO"
  1173. GMTdatabaseFile="Mouse_GO_AllPathways_with_GO_iea_November_07_2023_symbol.gmt"
  1174. GOparallel(C4_ANOVAout) # parameters are set in global environment as above; if not set, the function falls back to defaults and looks for all inputs available.
  1175. ####################################################
  1176. # heatmap of bulk vs pulldown RNA
  1177. #Load necessary libraries
  1178. library(pheatmap)
  1179. library(dplyr)
  1180. library(grDevices) # for colorRampPalette
  1181. # Load top 50 cell-type gene list from Barres lab
  1182. top50_cell_type_genes_Sloan <- read.csv("mouse_cell_markers_Sloan_03062023.csv", header = TRUE)
  1183. # Create a mapping of genes to cell types
  1184. gene_to_cell_type <- stack(top50_cell_type_genes_Sloan)
  1185. colnames(gene_to_cell_type) <- c("Gene", "CellType")
  1186. # Load expression data
  1187. final_clean_counts <- read.csv("1b.Exp. 9-2 and 8-1_RNA-seq_clean_counts_diffex filter-17054x31_CR_06182024.csv", row.names = 1, check.names=FALSE)
  1188. dim(final_clean_counts)
  1189. # [1] 17054 31
  1190. # Load traits data
  1191. traits_9_2_8_1 <- read.csv("Exp. 9-2 and 8-1 RNA traits.csv", row.names = 1)
  1192. dim(traits_9_2_8_1)
  1193. # [1] 31 2
  1194. ################################################################################
  1195. # Comparison 2: Aldh1l1.RiboTag.pos.pulldown vs Aldh1l1.RiboTag.bulk.cortex
  1196. # subset counts data
  1197. # Subset counts data
  1198. Aldh1l1.RiboTag_pullVsBulk_clean_counts <- final_clean_counts[,c(24:26, 29:31)]
  1199. # Updated traits_9_2_8_1
  1200. Aldh1l1.RiboTag_pullVsBulk_traits <- traits_9_2_8_1[c(24:26, 29:31),]
  1201. Aldh1l1.RiboTag_pullVsBulk_traits
  1202. # Sample.ID.. Group
  1203. # 23238R-04-03 CR3 Aldh1l1.RiboTag.bulk.cortex
  1204. # 23238R-04-04 CR4 Aldh1l1.RiboTag.bulk.cortex
  1205. # 23238R-04-05 CR5 Aldh1l1.RiboTag.bulk.cortex
  1206. # 23238R-04-08 CR8 Aldh1l1.RiboTag.pos.pulldown
  1207. # 23238R-04-09 CR9 Aldh1l1.RiboTag.pos.pulldown
  1208. # 23238R-04-10 CR10 Aldh1l1.RiboTag.pos.pulldown
  1209. # Check if sample names match
  1210. if(!all(row.names(Aldh1l1.RiboTag_pullVsBulk_traits) %in% colnames(Aldh1l1.RiboTag_pullVsBulk_clean_counts))) {
  1211. stop("Sample names in traits file do not match column names in expression data.")
  1212. }
  1213. group_info <- Aldh1l1.RiboTag_pullVsBulk_traits$Group
  1214. names(group_info) <- row.names(Aldh1l1.RiboTag_pullVsBulk_traits)
  1215. annotation_col <- data.frame(Group = group_info)
  1216. rownames(annotation_col) <- names(group_info)
  1217. # Filter for astrocyte genes
  1218. astrocyte_genes <- gene_to_cell_type %>% filter(CellType == "Astrocyte") %>% pull(Gene)
  1219. # Filter counts for astrocyte genes
  1220. Aldh1l1.RiboTag_pullVsBulk_filtered_data <- Aldh1l1.RiboTag_pullVsBulk_clean_counts[rownames(Aldh1l1.RiboTag_pullVsBulk_clean_counts) %in% astrocyte_genes, ]
  1221. # Calculate row z-scores
  1222. row_z_scores <- t(apply(Aldh1l1.RiboTag_pullVsBulk_filtered_data, 1, function(x) scale(x, center = TRUE, scale = TRUE)))
  1223. colnames(row_z_scores) <- colnames(Aldh1l1.RiboTag_pullVsBulk_filtered_data)
  1224. # Adjust row names to include cell type information
  1225. new_row_names <- paste(rownames(row_z_scores), "Astrocyte", sep = " | ")
  1226. rownames(row_z_scores) <- new_row_names
  1227. pdf(file = "C2_Exp. 8-1_RNA-seq_Aldh1l1.RiboTag_pullVsBulk_Zhang_heatmap_07022024.pdf", width = 8, height = 8)
  1228. layout(matrix(c(1,1,2, 1,1,3, 4,5,6), nrow = 3, ncol = 3, byrow=TRUE),
  1229. heights = c(1,1,1), # Equal heights for all rows
  1230. widths = c(1,1,1)) # Equal widths for all columns
  1231. # Define a custom color palette
  1232. custom_colors <- colorRampPalette(c("lightblue", "white", "darkblue"))(100)
  1233. # Create the heatmap with annotation and custom colors
  1234. RiboTag_astrocyte_heatmap <- pheatmap(row_z_scores,
  1235. cluster_rows = FALSE,
  1236. cluster_cols = FALSE,
  1237. annotation_col = annotation_col,
  1238. show_rownames = TRUE,
  1239. show_colnames = TRUE,
  1240. color = custom_colors)
  1241. ###############################################################################
  1242. # Filter for neuronal genes
  1243. neuronal_genes <- gene_to_cell_type %>% filter(CellType == "Neuron") %>% pull(Gene)
  1244. # Filter counts for astrocyte genes
  1245. Aldh1l1.RiboTag_pullVsBulk_filtered_data <- Aldh1l1.RiboTag_pullVsBulk_clean_counts[rownames(Aldh1l1.RiboTag_pullVsBulk_clean_counts) %in% neuronal_genes, ]
  1246. # Calculate row z-scores
  1247. row_z_scores <- t(apply(Aldh1l1.RiboTag_pullVsBulk_filtered_data, 1, function(x) scale(x, center = TRUE, scale = TRUE)))
  1248. colnames(row_z_scores) <- colnames(Aldh1l1.RiboTag_pullVsBulk_filtered_data)
  1249. # Adjust row names to include cell type information
  1250. new_row_names <- paste(rownames(row_z_scores), "Neuron", sep = " | ")
  1251. rownames(row_z_scores) <- new_row_names
  1252. # Define a custom color palette
  1253. custom_colors <- colorRampPalette(c("lightblue", "white", "darkblue"))(100)
  1254. # Create the heatmap with annotation and custom colors
  1255. RiboTag_neuron_heatmap <- pheatmap(row_z_scores,
  1256. cluster_rows = FALSE,
  1257. cluster_cols = FALSE,
  1258. annotation_col = annotation_col,
  1259. show_rownames = TRUE,
  1260. show_colnames = TRUE,
  1261. color = custom_colors)
  1262. dev.off()
  1263. ################################################################################
  1264. ################################################################################
  1265. # Comparison 4: Astrocyte-TurboID pulldown vs Astrocyte-RiboTag pulldown
  1266. # Subset counts data
  1267. Aldh1l1_TurboVsRibo_clean_counts <- final_clean_counts[,c(4:6, 29:31)]
  1268. # Updated traits_9_2_8_1
  1269. Aldh1l1_TurboVsRibo_traits <- traits_9_2_8_1[c(14:16, 29:31),]
  1270. # Sample.ID.. Group
  1271. # 21047FL-134-01-41 15-RNA 30L Aldh1l1.pos.pulldown
  1272. # 21047FL-134-01-42 16-RNA 31B Aldh1l1.pos.pulldown
  1273. # 21047FL-134-01-43 17-RNA 24L Aldh1l1.pos.pulldown
  1274. # 23238R-04-08 CR8 Aldh1l1.RiboTag.pos.pulldown
  1275. # 23238R-04-09 CR9 Aldh1l1.RiboTag.pos.pulldown
  1276. # 23238R-04-10 CR10 Aldh1l1.RiboTag.pos.pulldown
  1277. # Check if sample names match
  1278. if(!all(row.names(Aldh1l1_TurboVsRibo_traits) %in% colnames(Aldh1l1_TurboVsRibo_clean_counts))) {
  1279. stop("Sample names in traits file do not match column names in expression data.")
  1280. }
  1281. group_info <- Aldh1l1_TurboVsRibo_traits$Group
  1282. names(group_info) <- row.names(Aldh1l1_TurboVsRibo_traits)
  1283. annotation_col <- data.frame(Group = group_info)
  1284. rownames(annotation_col) <- names(group_info)
  1285. # Filter for astrocyte genes
  1286. astrocyte_genes <- gene_to_cell_type %>% filter(CellType == "Astrocyte") %>% pull(Gene)
  1287. # Filter counts for astrocyte genes
  1288. Aldh1l1_TurboVsRibo_filtered_data <- Aldh1l1_TurboVsRibo_clean_counts[rownames(Aldh1l1_TurboVsRibo_clean_counts) %in% astrocyte_genes, ]
  1289. # Calculate row z-scores
  1290. row_z_scores <- t(apply(Aldh1l1_TurboVsRibo_filtered_data, 1, function(x) scale(x, center = TRUE, scale = TRUE)))
  1291. colnames(row_z_scores) <- colnames(Aldh1l1_TurboVsRibo_filtered_data)
  1292. # Adjust row names to include cell type information
  1293. new_row_names <- paste(rownames(row_z_scores), "Astrocyte", sep = " | ")
  1294. rownames(row_z_scores) <- new_row_names
  1295. pdf(file = "C4_Exp. 8-1_RNA-seq_Aldh1l1_TurboVsRibo_pulls_Zhang_heatmap_07022024.pdf", width = 8, height = 8)
  1296. layout(matrix(c(1,1,2, 1,1,3, 4,5,6), nrow = 3, ncol = 3, byrow=TRUE),
  1297. heights = c(1,1,1), # Equal heights for all rows
  1298. widths = c(1,1,1)) # Equal widths for all columns
  1299. # Define a custom color palette
  1300. custom_colors <- colorRampPalette(c("lightblue", "white", "darkblue"))(100)
  1301. # Create the heatmap with annotation and custom colors
  1302. Aldh1l1_pulls_astrocyte_heatmap <- pheatmap(row_z_scores,
  1303. cluster_rows = FALSE,
  1304. cluster_cols = FALSE,
  1305. annotation_col = annotation_col,
  1306. show_rownames = TRUE,
  1307. show_colnames = TRUE,
  1308. color = custom_colors)
  1309. ###############################################################################
  1310. # Filter for neuronal genes
  1311. neuronal_genes <- gene_to_cell_type %>% filter(CellType == "Neuron") %>% pull(Gene)
  1312. # Filter counts for astrocyte genes
  1313. Aldh1l1_TurboVsRibo_filtered_data <- Aldh1l1_TurboVsRibo_clean_counts[rownames(Aldh1l1_TurboVsRibo_clean_counts) %in% neuronal_genes, ]
  1314. # Calculate row z-scores
  1315. row_z_scores <- t(apply(Aldh1l1_TurboVsRibo_filtered_data, 1, function(x) scale(x, center = TRUE, scale = TRUE)))
  1316. colnames(row_z_scores) <- colnames(Aldh1l1_TurboVsRibo_filtered_data)
  1317. # Adjust row names to include cell type information
  1318. new_row_names <- paste(rownames(row_z_scores), "Neuron", sep = " | ")
  1319. rownames(row_z_scores) <- new_row_names
  1320. # Define a custom color palette
  1321. custom_colors <- colorRampPalette(c("lightblue", "white", "darkblue"))(100)
  1322. # Create the heatmap with annotation and custom colors
  1323. Aldh1l1_pulls_neuron_heatmap <- pheatmap(row_z_scores,
  1324. cluster_rows = FALSE,
  1325. cluster_cols = FALSE,
  1326. annotation_col = annotation_col,
  1327. show_rownames = TRUE,
  1328. show_colnames = TRUE,
  1329. color = custom_colors)
  1330. dev.off()
  1331. ################################################################################
  1332. ##################################################################################
  1333. # Filtering for cell-type markers from Zhang et al., 2014 and Sharma et al., 2015
  1334. # load Zhang and Sharma cell-type marker union list from Johnson et al. 2022 Nat Neurosci
  1335. Zhang_Sharma_markers <- read.csv("Johnson et al.. 2022 Nat Neurosci Sharma and Zhang marker union list_mouse_from Eric.csv", header = TRUE)
  1336. # Create a mapping of genes to cell types
  1337. gene_to_cell_type_2 <- stack(Zhang_Sharma_markers)
  1338. colnames(gene_to_cell_type_2) <- c("Gene", "CellType")
  1339. ################################################################################
  1340. # Comparison 2: Aldh1l1.RiboTag.pos.pulldown vs Aldh1l1.RiboTag.bulk.cortex
  1341. # subset counts data
  1342. # Subset counts data
  1343. Aldh1l1.RiboTag_pullVsBulk_clean_counts <- final_clean_counts[,c(24:26, 29:31)]
  1344. # Updated traits_9_2_8_1
  1345. Aldh1l1.RiboTag_pullVsBulk_traits <- traits_9_2_8_1[c(24:26, 29:31),]
  1346. Aldh1l1.RiboTag_pullVsBulk_traits
  1347. # Sample.ID.. Group
  1348. # 23238R-04-03 CR3 Aldh1l1.RiboTag.bulk.cortex
  1349. # 23238R-04-04 CR4 Aldh1l1.RiboTag.bulk.cortex
  1350. # 23238R-04-05 CR5 Aldh1l1.RiboTag.bulk.cortex
  1351. # 23238R-04-08 CR8 Aldh1l1.RiboTag.pos.pulldown
  1352. # 23238R-04-09 CR9 Aldh1l1.RiboTag.pos.pulldown
  1353. # 23238R-04-10 CR10 Aldh1l1.RiboTag.pos.pulldown
  1354. # Check if sample names match
  1355. if(!all(row.names(Aldh1l1.RiboTag_pullVsBulk_traits) %in% colnames(Aldh1l1.RiboTag_pullVsBulk_clean_counts))) {
  1356. stop("Sample names in traits file do not match column names in expression data.")
  1357. }
  1358. group_info <- Aldh1l1.RiboTag_pullVsBulk_traits$Group
  1359. names(group_info) <- row.names(Aldh1l1.RiboTag_pullVsBulk_traits)
  1360. annotation_col <- data.frame(Group = group_info)
  1361. rownames(annotation_col) <- names(group_info)
  1362. # Filter for astrocyte genes
  1363. astrocyte_genes_2 <- gene_to_cell_type_2 %>% filter(CellType == "Astrocytes") %>% pull(Gene)
  1364. # Filter counts for astrocyte genes
  1365. Aldh1l1.RiboTag_pullVsBulk_filtered_data_2 <- Aldh1l1.RiboTag_pullVsBulk_clean_counts[rownames(Aldh1l1.RiboTag_pullVsBulk_clean_counts) %in% astrocyte_genes_2, ]
  1366. # Calculate row z-scores
  1367. row_z_scores <- t(apply(Aldh1l1.RiboTag_pullVsBulk_filtered_data_2, 1, function(x) scale(x, center = TRUE, scale = TRUE)))
  1368. colnames(row_z_scores) <- colnames(Aldh1l1.RiboTag_pullVsBulk_filtered_data_2)
  1369. # Adjust row names to include cell type information
  1370. new_row_names <- paste(rownames(row_z_scores), "Astrocyte", sep = " | ")
  1371. rownames(row_z_scores) <- new_row_names
  1372. sum(is.na(row_z_scores))
  1373. # [1] 12
  1374. sum(is.nan(row_z_scores))
  1375. # [1] 12
  1376. sum(is.infinite(row_z_scores))
  1377. # [1] 0
  1378. # Identify rows with NA, NaN values
  1379. rows_with_na <- apply(row_z_scores, 1, function(x) any(is.na(x)))
  1380. rows_with_nan <- apply(row_z_scores, 1, function(x) any(is.nan(x)))
  1381. # Print the indices of rows with NA values
  1382. which(rows_with_na)
  1383. # Eif2s3y Kdm5d
  1384. # 320 525
  1385. which(rows_with_nan)
  1386. # Eif2s3y Kdm5d
  1387. # 320 525
  1388. #rows_to_remove <- c(320, 525)
  1389. #row_z_scores_clean <- row_z_scores[-rows_to_remove, ]
  1390. row_z_scores_clean <- na.omit(row_z_scores)
  1391. rows_with_na <- apply(row_z_scores_clean, 1, function(x) any(is.na(x)))
  1392. which(rows_with_na)
  1393. # named integer(0)
  1394. pdf(file = "C2_Exp. 8-1_RNA-seq_Aldh1l1.RiboTag_pullVsBulk_Zhang and Sharma_heatmaps_07112024.pdf", width = 8, height = 8)
  1395. layout(matrix(c(1,1,2, 1,1,3, 4,5,6), nrow = 3, ncol = 3, byrow=TRUE),
  1396. heights = c(1,1,1), # Equal heights for all rows
  1397. widths = c(1,1,1)) # Equal widths for all columns
  1398. # Define a custom color palette
  1399. custom_colors <- colorRampPalette(c("lightblue", "white", "darkblue"))(100)
  1400. # Create the heatmap with annotation and custom colors
  1401. RiboTag_astrocyte_heatmap_2 <- pheatmap(row_z_scores_clean,
  1402. cluster_rows = TRUE,
  1403. cluster_cols = TRUE,
  1404. annotation_col = annotation_col,
  1405. show_rownames = FALSE,
  1406. show_colnames = TRUE,
  1407. color = custom_colors,
  1408. main = "Top astrocytic markers from Zhang and Sharma")
  1409. ###############################################################################
  1410. # Filter for neuronal genes
  1411. neuronal_genes_2 <- gene_to_cell_type_2 %>% filter(CellType == "Neurons") %>% pull(Gene)
  1412. # Filter counts for astrocyte genes
  1413. Aldh1l1.RiboTag_pullVsBulk_filtered_data_2 <- Aldh1l1.RiboTag_pullVsBulk_clean_counts[rownames(Aldh1l1.RiboTag_pullVsBulk_clean_counts) %in% neuronal_genes_2, ]
  1414. # Calculate row z-scores
  1415. row_z_scores <- t(apply(Aldh1l1.RiboTag_pullVsBulk_filtered_data_2, 1, function(x) scale(x, center = TRUE, scale = TRUE)))
  1416. colnames(row_z_scores) <- colnames(Aldh1l1.RiboTag_pullVsBulk_filtered_data_2)
  1417. # Adjust row names to include cell type information
  1418. new_row_names <- paste(rownames(row_z_scores), "Neuron", sep = " | ")
  1419. rownames(row_z_scores) <- new_row_names
  1420. # Define a custom color palette
  1421. custom_colors <- colorRampPalette(c("lightblue", "white", "darkblue"))(100)
  1422. # Create the heatmap with annotation and custom colors
  1423. RiboTag_neuron_heatmap_2 <- pheatmap(row_z_scores,
  1424. cluster_rows = TRUE,
  1425. cluster_cols = TRUE,
  1426. annotation_col = annotation_col,
  1427. show_rownames = FALSE,
  1428. show_colnames = TRUE,
  1429. color = custom_colors,
  1430. main = "Top neuronal markers from Zhang and Sharma")
  1431. dev.off()
  1432. ################################################################################
  1433. ###############################################################################
  1434. # Filter for neuronal genes
  1435. neuronal_genes <- gene_to_cell_type %>% filter(CellType == "Neuron") %>% pull(Gene)
  1436. # Filter counts for astrocyte genes
  1437. TurboVsRibo_bulk.cortexs_filtered_data <- TurboVsRibo_bulk.cortexs_clean_counts[rownames(TurboVsRibo_bulk.cortexs_clean_counts) %in% neuronal_genes, ]
  1438. # Calculate row z-scores
  1439. row_z_scores <- t(apply(TurboVsRibo_bulk.cortexs_filtered_data, 1, function(x) scale(x, center = TRUE, scale = TRUE)))
  1440. colnames(row_z_scores) <- colnames(TurboVsRibo_bulk.cortexs_filtered_data)
  1441. # Adjust row names to include cell type information
  1442. new_row_names <- paste(rownames(row_z_scores), "Neuron", sep = " | ")
  1443. rownames(row_z_scores) <- new_row_names
  1444. # Define a custom color palette
  1445. custom_colors <- colorRampPalette(c("lightblue", "white", "darkblue"))(100)
  1446. # Create the heatmap with annotation and custom colors
  1447. Aldh1l1_bulk.cortexs_neuron_heatmap <- pheatmap(row_z_scores,
  1448. cluster_rows = FALSE,
  1449. cluster_cols = FALSE,
  1450. annotation_col = annotation_col,
  1451. show_rownames = TRUE,
  1452. show_colnames = TRUE,
  1453. color = custom_colors)
  1454. dev.off()
  1455. # Subset counts data
  1456. Aldh1l1_TurboVsRibo_clean_counts <- final_clean_counts[,c(14:16, 29:31)]
  1457. # Updated traits_9_2_8_1
  1458. Aldh1l1_TurboVsRibo_traits <- traits_9_2_8_1[c(14:16, 29:31),]
  1459. Aldh1l1_TurboVsRibo_traits
  1460. # Sample.ID.. Group
  1461. # 21047FL-134-01-41 15-RNA 30L Aldh1l1.pos.pulldown
  1462. # 21047FL-134-01-42 16-RNA 31B Aldh1l1.pos.pulldown
  1463. # 21047FL-134-01-43 17-RNA 24L Aldh1l1.pos.pulldown
  1464. # 23238R-04-08 CR8 Aldh1l1.RiboTag.pos.pulldown
  1465. # 23238R-04-09 CR9 Aldh1l1.RiboTag.pos.pulldown
  1466. # 23238R-04-10 CR10 Aldh1l1.RiboTag.pos.pulldown
  1467. # Check if sample names match
  1468. if(!all(row.names(Aldh1l1_TurboVsRibo_traits) %in% colnames(Aldh1l1_TurboVsRibo_clean_counts))) {
  1469. stop("Sample names in traits file do not match column names in expression data.")
  1470. }
  1471. group_info <- Aldh1l1_TurboVsRibo_traits$Group
  1472. names(group_info) <- row.names(Aldh1l1_TurboVsRibo_traits)
  1473. annotation_col <- data.frame(Group = group_info)
  1474. rownames(annotation_col) <- names(group_info)
  1475. # Filter for astrocyte genes
  1476. astrocyte_genes_2 <- gene_to_cell_type_2 %>% filter(CellType == "Astrocytes") %>% pull(Gene)
  1477. # Filter counts for astrocyte genes
  1478. Aldh1l1_TurboVsRibo_filtered_data_2 <- Aldh1l1_TurboVsRibo_clean_counts[rownames(Aldh1l1_TurboVsRibo_clean_counts) %in% astrocyte_genes_2, ]
  1479. # Calculate row z-scores
  1480. row_z_scores <- t(apply(Aldh1l1_TurboVsRibo_filtered_data_2, 1, function(x) scale(x, center = TRUE, scale = TRUE)))
  1481. colnames(row_z_scores) <- colnames(Aldh1l1_TurboVsRibo_filtered_data_2)
  1482. # Adjust row names to include cell type information
  1483. new_row_names <- paste(rownames(row_z_scores), "Astrocyte", sep = " | ")
  1484. rownames(row_z_scores) <- new_row_names
  1485. pdf(file = "C4_Exp. 8-1_RNA-seq_Aldh1l1_TurboVsRibo_pulls_Zhang and Sharma_heatmaps_07112024.pdf", width = 8, height = 8)
  1486. layout(matrix(c(1,1,2, 1,1,3, 4,5,6), nrow = 3, ncol = 3, byrow=TRUE),
  1487. heights = c(1,1,1), # Equal heights for all rows
  1488. widths = c(1,1,1)) # Equal widths for all columns
  1489. # Define a custom color palette
  1490. custom_colors <- colorRampPalette(c("lightblue", "white", "darkblue"))(100)
  1491. # Create the heatmap with annotation and custom colors
  1492. Aldh1l1_pulls_astrocyte_heatmap_2 <- pheatmap(row_z_scores,
  1493. cluster_rows = TRUE,
  1494. cluster_cols = TRUE,
  1495. annotation_col = annotation_col,
  1496. show_rownames = FALSE,
  1497. show_colnames = TRUE,
  1498. color = custom_colors,
  1499. main = "Top astrocytic markers from Zhang and Sharma")
  1500. ###############################################################################
  1501. # Filter for neuronal genes
  1502. neuronal_genes_2 <- gene_to_cell_type_2 %>% filter(CellType == "Neurons") %>% pull(Gene)
  1503. # Filter counts for astrocyte genes
  1504. Aldh1l1_TurboVsRibo_filtered_data_2 <- Aldh1l1_TurboVsRibo_clean_counts[rownames(Aldh1l1_TurboVsRibo_clean_counts) %in% neuronal_genes_2, ]
  1505. # Calculate row z-scores
  1506. row_z_scores <- t(apply(Aldh1l1_TurboVsRibo_filtered_data_2, 1, function(x) scale(x, center = TRUE, scale = TRUE)))
  1507. colnames(row_z_scores) <- colnames(Aldh1l1_TurboVsRibo_filtered_data_2)
  1508. # Adjust row names to include cell type information
  1509. new_row_names <- paste(rownames(row_z_scores), "Neuron", sep = " | ")
  1510. rownames(row_z_scores) <- new_row_names
  1511. # Define a custom color palette
  1512. custom_colors <- colorRampPalette(c("lightblue", "white", "darkblue"))(100)
  1513. # Create the heatmap with annotation and custom colors
  1514. Aldh1l1_pulls_neuron_heatmap_2 <- pheatmap(row_z_scores,
  1515. cluster_rows = TRUE,
  1516. cluster_cols = TRUE,
  1517. annotation_col = annotation_col,
  1518. show_rownames = FALSE,
  1519. show_colnames = TRUE,
  1520. color = custom_colors,
  1521. main = "Top neuronal markers from Zhang and Sharma")
  1522. dev.off()
  1523. ################################################################################
  1524. #################################################################################
  1525. # load Seyfried et al., 2017 Zhang only list
  1526. Zhang_markers <- read.csv("Seyfried et al., 2017 Cell Syst S4 Table (Zhang list).csv", header = TRUE)
  1527. gene_to_cell_type_3 <- stack(Zhang_markers)
  1528. colnames(gene_to_cell_type_3) <- c("Gene", "CellType")
  1529. # Load expression data
  1530. final_clean_counts <- read.csv("1b.Exp. 9-2 and 8-1_RNA-seq_clean_counts_diffex filter-17054x31_CR_06182024.csv", row.names = 1, check.names=FALSE)
  1531. dim(final_clean_counts)
  1532. # [1] 17054 31
  1533. # Load traits data
  1534. traits_9_2_8_1 <- read.csv("Exp. 9-2 and 8-1 RNA traits.csv", row.names = 1)
  1535. dim(traits_9_2_8_1)
  1536. # [1] 31 2
  1537. ##################################################################################
  1538. ##################################################################################
  1539. # Comparison 2: Aldh1l1.RiboTag.pos.pulldown vs Aldh1l1.RiboTag.bulk.cortex
  1540. # Subset counts data
  1541. Aldh1l1.RiboTag_pullVsBulk_clean_counts <- final_clean_counts[,c(24:26, 29:31)]
  1542. # Updated traits_9_2_8_1
  1543. Aldh1l1.RiboTag_pullVsBulk_traits <- traits_9_2_8_1[c(24:26, 29:31),]
  1544. Aldh1l1.RiboTag_pullVsBulk_traits
  1545. # Sample.ID.. Group
  1546. # 23238R-04-03 CR3 Aldh1l1.RiboTag.bulk.cortex
  1547. # 23238R-04-04 CR4 Aldh1l1.RiboTag.bulk.cortex
  1548. # 23238R-04-05 CR5 Aldh1l1.RiboTag.bulk.cortex
  1549. # 23238R-04-08 CR8 Aldh1l1.RiboTag.pos.pulldown
  1550. # 23238R-04-09 CR9 Aldh1l1.RiboTag.pos.pulldown
  1551. # 23238R-04-10 CR10 Aldh1l1.RiboTag.pos.pulldown
  1552. # Check if sample names match
  1553. if(!all(row.names(Aldh1l1.RiboTag_pullVsBulk_traits) %in% colnames(Aldh1l1.RiboTag_pullVsBulk_clean_counts))) {
  1554. stop("Sample names in traits file do not match column names in expression data.")
  1555. }
  1556. group_info <- Aldh1l1.RiboTag_pullVsBulk_traits$Group
  1557. names(group_info) <- row.names(Aldh1l1.RiboTag_pullVsBulk_traits)
  1558. annotation_col <- data.frame(Group = group_info)
  1559. rownames(annotation_col) <- names(group_info)
  1560. # Filter for Astrocytes genes
  1561. Astrocyte_genes_3 <- gene_to_cell_type_3 %>% filter(CellType == "Astrocytes") %>% pull(Gene)
  1562. # Filter counts for Astrocytes genes
  1563. Aldh1l1.RiboTag_pullVsBulk_filtered_data_3 <- Aldh1l1.RiboTag_pullVsBulk_clean_counts[rownames(Aldh1l1.RiboTag_pullVsBulk_clean_counts) %in% Astrocyte_genes_3, ]
  1564. # Calculate row z-scores
  1565. row_z_scores <- t(apply(Aldh1l1.RiboTag_pullVsBulk_filtered_data_3, 1, function(x) scale(x, center = TRUE, scale = TRUE)))
  1566. colnames(row_z_scores) <- colnames(Aldh1l1.RiboTag_pullVsBulk_filtered_data_3)
  1567. # Adjust row names to include cell type information
  1568. new_row_names <- paste(rownames(row_z_scores), "Astrocytes", sep = " | ")
  1569. rownames(row_z_scores) <- new_row_names
  1570. sum(is.na(row_z_scores))
  1571. # [1] 12
  1572. sum(is.nan(row_z_scores))
  1573. # [1] 12
  1574. sum(is.infinite(row_z_scores))
  1575. # [1] 0
  1576. # Identify rows with NA, NaN values
  1577. rows_with_na <- apply(row_z_scores, 1, function(x) any(is.na(x)))
  1578. rows_with_nan <- apply(row_z_scores, 1, function(x) any(is.nan(x)))
  1579. # Print the indices of rows with NA values
  1580. which(rows_with_na)
  1581. # Eif2s3y Kdm5d
  1582. # 320 525
  1583. which(rows_with_nan)
  1584. # Eif2s3y Kdm5d
  1585. # 320 525
  1586. #rows_to_remove <- c(320, 525)
  1587. #row_z_scores_clean <- row_z_scores[-rows_to_remove, ]
  1588. row_z_scores_clean <- na.omit(row_z_scores)
  1589. rows_with_na <- apply(row_z_scores_clean, 1, function(x) any(is.na(x)))
  1590. which(rows_with_na)
  1591. # named integer(0)
  1592. pdf(file = "C2_Exp. 8-1_RNA-seq_Aldh1l1.RiboTag_pullVsBulk_Zhang all_heatmap_07122024.pdf", width = 8, height = 8)
  1593. layout(matrix(c(1,1,2, 1,1,3, 4,5,6), nrow = 3, ncol = 3, byrow=TRUE),
  1594. heights = c(1,1,1), # Equal heights for all rows
  1595. widths = c(1,1,1)) # Equal widths for all columns
  1596. # Define a custom color palette
  1597. custom_colors <- colorRampPalette(c("lightblue", "white", "darkblue"))(100)
  1598. # Create the heatmap with annotation and custom colors
  1599. RiboTag_Astrocytes_heatmap_3 <- pheatmap(row_z_scores_clean,
  1600. cluster_rows = TRUE,
  1601. cluster_cols = TRUE,
  1602. annotation_col = annotation_col,
  1603. show_rownames = FALSE,
  1604. show_colnames = TRUE,
  1605. color = custom_colors,
  1606. main = "Top astrocytic markers from Zhang")
  1607. ###############################################################################
  1608. # Filter for neuronal genes
  1609. neuronal_genes_3 <- gene_to_cell_type_3 %>% filter(CellType == "Neurons") %>% pull(Gene)
  1610. # Filter counts for Astrocytes genes
  1611. Aldh1l1.RiboTag_pullVsBulk_filtered_data_3 <- Aldh1l1.RiboTag_pullVsBulk_clean_counts[rownames(Aldh1l1.RiboTag_pullVsBulk_clean_counts) %in% neuronal_genes_3, ]
  1612. # Calculate row z-scores
  1613. row_z_scores <- t(apply(Aldh1l1.RiboTag_pullVsBulk_filtered_data_3, 1, function(x) scale(x, center = TRUE, scale = TRUE)))
  1614. colnames(row_z_scores) <- colnames(Aldh1l1.RiboTag_pullVsBulk_filtered_data_3)
  1615. # Adjust row names to include cell type information
  1616. new_row_names <- paste(rownames(row_z_scores), "Neuron", sep = " | ")
  1617. rownames(row_z_scores) <- new_row_names
  1618. # Define a custom color palette
  1619. custom_colors <- colorRampPalette(c("lightblue", "white", "darkblue"))(100)
  1620. # Create the heatmap with annotation and custom colors
  1621. RiboTag_neuron_heatmap_3 <- pheatmap(row_z_scores,
  1622. cluster_rows = TRUE,
  1623. cluster_cols = TRUE,
  1624. annotation_col = annotation_col,
  1625. show_rownames = FALSE,
  1626. show_colnames = TRUE,
  1627. color = custom_colors,
  1628. main = "Top neuronal markers from Zhang")
  1629. dev.off()
  1630. ################################################################################
  1631. # Comparison 4: Astrocyte-TurboID pulldown vs Astrocyte-RiboTag pulldown
  1632. # Subset counts data
  1633. Aldh1l1_TurboVsRibo_clean_counts <- final_clean_counts[,c(14:16, 29:31)]
  1634. # Updated traits_9_2_8_1
  1635. Aldh1l1_TurboVsRibo_traits <- traits_9_2_8_1[c(14:16, 29:31),]
  1636. Aldh1l1_TurboVsRibo_traits
  1637. # Sample.ID.. Group
  1638. # 21047FL-134-01-41 15-RNA 30L Aldh1l1.pos.pulldown
  1639. # 21047FL-134-01-42 16-RNA 31B Aldh1l1.pos.pulldown
  1640. # 21047FL-134-01-43 17-RNA 24L Aldh1l1.pos.pulldown
  1641. # 23238R-04-08 CR8 Aldh1l1.RiboTag.pos.pulldown
  1642. # 23238R-04-09 CR9 Aldh1l1.RiboTag.pos.pulldown
  1643. # 23238R-04-10 CR10 Aldh1l1.RiboTag.pos.pulldown
  1644. # Check if sample names match
  1645. if(!all(row.names(Aldh1l1_TurboVsRibo_traits) %in% colnames(Aldh1l1_TurboVsRibo_clean_counts))) {
  1646. stop("Sample names in traits file do not match column names in expression data.")
  1647. }
  1648. group_info <- Aldh1l1_TurboVsRibo_traits$Group
  1649. names(group_info) <- row.names(Aldh1l1_TurboVsRibo_traits)
  1650. annotation_col <- data.frame(Group = group_info)
  1651. rownames(annotation_col) <- names(group_info)
  1652. # Filter for Astrocytes genes
  1653. Astrocyte_genes_3 <- gene_to_cell_type_3 %>% filter(CellType == "Astrocytes") %>% pull(Gene)
  1654. # Filter counts for Astrocytes genes
  1655. Aldh1l1_TurboVsRibo_filtered_data_3 <- Aldh1l1_TurboVsRibo_clean_counts[rownames(Aldh1l1_TurboVsRibo_clean_counts) %in% Astrocyte_genes_3, ]
  1656. # Calculate row z-scores
  1657. row_z_scores <- t(apply(Aldh1l1_TurboVsRibo_filtered_data_3, 1, function(x) scale(x, center = TRUE, scale = TRUE)))
  1658. colnames(row_z_scores) <- colnames(Aldh1l1_TurboVsRibo_filtered_data_3)
  1659. # Adjust row names to include cell type information
  1660. new_row_names <- paste(rownames(row_z_scores), "Astrocytes", sep = " | ")
  1661. rownames(row_z_scores) <- new_row_names
  1662. pdf(file = "C4_Exp. 8-1_RNA-seq_Aldh1l1_TurboVsRibo_pulls_Zhang all_heatmaps_07122024.pdf", width = 8, height = 8)
  1663. layout(matrix(c(1,1,2, 1,1,3, 4,5,6), nrow = 3, ncol = 3, byrow=TRUE),
  1664. heights = c(1,1,1), # Equal heights for all rows
  1665. widths = c(1,1,1)) # Equal widths for all columns
  1666. # Define a custom color palette
  1667. custom_colors <- colorRampPalette(c("lightblue", "white", "darkblue"))(100)
  1668. # Create the heatmap with annotation and custom colors
  1669. Aldh1l1_pulls_Astrocytes_heatmap_3 <- pheatmap(row_z_scores,
  1670. cluster_rows = TRUE,
  1671. cluster_cols = TRUE,
  1672. annotation_col = annotation_col,
  1673. show_rownames = FALSE,
  1674. show_colnames = TRUE,
  1675. color = custom_colors,
  1676. main = "Top astrocytic markers from Zhang")
  1677. ###############################################################################
  1678. # Filter for neuronal genes
  1679. neuronal_genes_3 <- gene_to_cell_type_3 %>% filter(CellType == "Neurons") %>% pull(Gene)
  1680. # Filter counts for Astrocytes genes
  1681. Aldh1l1_TurboVsRibo_filtered_data_3 <- Aldh1l1_TurboVsRibo_clean_counts[rownames(Aldh1l1_TurboVsRibo_clean_counts) %in% neuronal_genes_3, ]
  1682. # Calculate row z-scores
  1683. row_z_scores <- t(apply(Aldh1l1_TurboVsRibo_filtered_data_3, 1, function(x) scale(x, center = TRUE, scale = TRUE)))
  1684. colnames(row_z_scores) <- colnames(Aldh1l1_TurboVsRibo_filtered_data_3)
  1685. # Adjust row names to include cell type information
  1686. new_row_names <- paste(rownames(row_z_scores), "Neuron", sep = " | ")
  1687. rownames(row_z_scores) <- new_row_names
  1688. # Define a custom color palette
  1689. custom_colors <- colorRampPalette(c("lightblue", "white", "darkblue"))(100)
  1690. # Create the heatmap with annotation and custom colors
  1691. Aldh1l1_pulls_neuron_heatmap_3 <- pheatmap(row_z_scores,
  1692. cluster_rows = TRUE,
  1693. cluster_cols = TRUE,
  1694. annotation_col = annotation_col,
  1695. show_rownames = FALSE,
  1696. show_colnames = TRUE,
  1697. color = custom_colors,
  1698. main = "Top neuronal markers from Zhang")
  1699. dev.off()
  1700. ################################################################################
  1701. # end of data analysis and visualization

Astrocyte-RiboTag_mRNA seq analysis.R at commit 4303bf0, under MIT · at the source

Overview

Authors: Christina C Ramelow1,2,3, Eric B Dammer2,4, Hailian Xiao1,2, Lihong Cheng1,5, Prateek Kumar6, Claudia Espinosa-Garcia6, Maureen M Sampson3, Dilpreet Kour6, Ruth S Nelson6, Sneha Malepati6, Rashmi Kumari6, Wooyoung Eric Jang6, Qi Guo2,4, Pritha Bagchi7, Duc M Duong2,7, Nicholas T Seyfried1,2,4,7, Steven A Sloan3, Srikant Rangaraju1,5
  1. Department of Neurology, Emory University, Atlanta, GA USA
  2. Center for Neurodegenerative Disease, Emory University, Atlanta, GA USA
  3. Department of Human Genetics, Emory University, Atlanta, GA USA
  4. Department of Biochemistry, Emory University, Atlanta, GA USA
  5. Department of Pharmacology and Chemical Biology, Emory University, Atlanta, GA USA
  6. Department of Neurology, Yale University, New Haven, CT USA
  7. Emory Integrated Proteomics Core, Emory University, Atlanta, GA USA
Institutions: Emory University (United States); Yale University (United States)
Journal: Nature communications, volume 17, issue 1, article 4636
Dates: received 31 January 2025; accepted 10 March 2026; published online 31 March 2026
Type: Research article · Language: English
License: CC BY-NC-ND
Identifiers: DOI 10.1038/s41467-026-71098-4 · PMID 41917013 · PMCID PMC13199526 · OpenAlex W7143899533
Open access: gold, a free copy (OpenAlex)
Status: code verified (how the code is found and verified)
Categories: genetics / omics (modality), human (organism), mouse (organism), cellular / molecular (subfield)
Methods: Statistics, Evoked potentials
Keywords: Molecular neuroscience, Gene expression analysis, Proteomic analysis, Cellular neuroscience, Bioinformatics
MeSH: Gene Expression Profiling*, Neurons*, Proteome*, Proteomics*, Transcriptome*, Animals, Astrocytes, HEK293 Cells, Humans, Lipopolysaccharides, Mice, Microglia, Multiomics, RNA, Messenger (* major topic)
Topic: Biotin and Related Studies (Cell Biology, Biochemistry, Genetics and Molecular Biology), according to OpenAlex
Funding: U.S. Department of Health &amp; Human Services | NIH | National Institute on Aging (R01AG075820, 1F31AG079597-01A1); NIA NIH HHS (R01 AG071587, R01 AG075820); U.S. Department of Health &amp; Human Services | NIH | National Institute of Mental Health (NIMH) (R01MH125956)
Citations: cited by 3 papers (Europe PMC); 155 references in the paper

Abstract

The abstract is not reproduced here: the paper's license (CC BY-NC-ND) does not allow it. Read it in the paper, at the publisher or on Europe PMC.

Repository

Its files are read in the Code ↔ Paper reader above, with 5 matches between paragraphs and lines of code.

cramelow/SPARO

License: MIT
State: the link answers, verified on 30 September 2026
Evidence: files inventoried
Commit: 4303bf04063009a22d82e7b276f59d38f83692dc, 5 March 2026
Languages: R (7)
Size: 8 files, 7 scripts
Software Heritage: not archived
Found in: “Code availability”
Holds: license file
Not found: README, CITATION.cff, environment file, tests, continuous integration, documentation
Tools: ggplot2 (7 files), limma (7 files), tidyverse (7 files), DESeq2 (4 files), pheatmap (4 files), WGCNA (3 files), data.table (1 file)
Availability: 1 check, the latest on 30 September 2026: the link answers
  • 30 September 2026: the link answers
8 files

Code availability statement

The paper has a code availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:

Read it in the paper: doi.org/10.1038/s41467-026-71098-4.

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 7 scripts, each with its path and the digest of its content;
  • 5 matches between paragraphs of the paper and lines of the code (method lexical-v1);
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

Datasets cited

Data availability statement

The paper has a data availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:

Read it in the paper: doi.org/10.1038/s41467-026-71098-4.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 1, 30 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 18 authors, 5 keywords, 14 MeSH terms, 3 funders, 154 references.

Cite

This paper

Ramelow, C. C., Dammer, E. B., Xiao, H., Cheng, L., Kumar, P., Espinosa-Garcia, C., Sampson, M. M., Kour, D., Nelson, R. S., Malepati, S., Kumari, R., Jang, W. E., Guo, Q., Bagchi, P., Duong, D. M., Seyfried, N. T., Sloan, S. A., & Rangaraju, S. (2026). Simultaneous profiling of native-state proteomes and transcriptomes of neural cell types using proximity labeling. Nature communications, 17(1), 4636. https://doi.org/10.1038/s41467-026-71098-4

BibTeX

@article{ramelow2026simultaneous,
author = {Ramelow, Christina C and Dammer, Eric B and Xiao, Hailian and Cheng, Lihong and Kumar, Prateek and Espinosa-Garcia, Claudia and Sampson, Maureen M and Kour, Dilpreet and Nelson, Ruth S and Malepati, Sneha and Kumari, Rashmi and Jang, Wooyoung Eric and Guo, Qi and Bagchi, Pritha and Duong, Duc M and Seyfried, Nicholas T and Sloan, Steven A and Rangaraju, Srikant},
title = {{Simultaneous profiling of native-state proteomes and transcriptomes of neural cell types using proximity labeling}},
journal = {Nature communications},
year = {2026},
month = mar,
volume = {17},
number = {1},
pages = {4636},
publisher = {Nature Publishing Group},
issn = {2041-1723},
doi = {10.1038/s41467-026-71098-4},
url = {https://doi.org/10.1038/s41467-026-71098-4},
pmid = {41917013},
pmcid = {PMC13199526}
}

RIS

TY - JOUR
AU - Ramelow, Christina C
AU - Dammer, Eric B
AU - Xiao, Hailian
AU - Cheng, Lihong
AU - Kumar, Prateek
AU - Espinosa-Garcia, Claudia
AU - Sampson, Maureen M
AU - Kour, Dilpreet
AU - Nelson, Ruth S
AU - Malepati, Sneha
AU - Kumari, Rashmi
AU - Jang, Wooyoung Eric
AU - Guo, Qi
AU - Bagchi, Pritha
AU - Duong, Duc M
AU - Seyfried, Nicholas T
AU - Sloan, Steven A
AU - Rangaraju, Srikant
TI - Simultaneous profiling of native-state proteomes and transcriptomes of neural cell types using proximity labeling
T2 - Nature communications
J2 - Nat Commun
PY - 2026
DA - 2026/03/31
VL - 17
IS - 1
SP - 4636
SN - 2041-1723
PB - Nature Publishing Group
DO - 10.1038/s41467-026-71098-4
UR - https://doi.org/10.1038/s41467-026-71098-4
LA - en
ER -

CSL-JSON

{
"id": "10.1038/s41467-026-71098-4",
"type": "article-journal",
"title": "Simultaneous profiling of native-state proteomes and transcriptomes of neural cell types using proximity labeling",
"container-title": "Nature communications",
"author": [
{
"family": "Ramelow",
"given": "Christina C"
},
{
"family": "Dammer",
"given": "Eric B"
},
{
"family": "Xiao",
"given": "Hailian"
},
{
"family": "Cheng",
"given": "Lihong"
},
{
"family": "Kumar",
"given": "Prateek"
},
{
"family": "Espinosa-Garcia",
"given": "Claudia"
},
{
"family": "Sampson",
"given": "Maureen M"
},
{
"family": "Kour",
"given": "Dilpreet"
},
{
"family": "Nelson",
"given": "Ruth S"
},
{
"family": "Malepati",
"given": "Sneha"
},
{
"family": "Kumari",
"given": "Rashmi"
},
{
"family": "Jang",
"given": "Wooyoung Eric"
},
{
"family": "Guo",
"given": "Qi"
},
{
"family": "Bagchi",
"given": "Pritha"
},
{
"family": "Duong",
"given": "Duc M"
},
{
"family": "Seyfried",
"given": "Nicholas T"
},
{
"family": "Sloan",
"given": "Steven A"
},
{
"family": "Rangaraju",
"given": "Srikant"
}
],
"container-title-short": "Nat Commun",
"volume": "17",
"issue": "1",
"page": "4636",
"DOI": "10.1038/s41467-026-71098-4",
"PMID": "41917013",
"PMCID": "PMC13199526",
"ISSN": "2041-1723",
"publisher": "Nature Publishing Group",
"URL": "https://doi.org/10.1038/s41467-026-71098-4",
"language": "en",
"issued": {
"date-parts": [
[
2026,
3,
31
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.1038/s41467-024-47028-7 [code]
Native-state proteomics of Parvalbumin interneurons identifies unique molecular signatures and vulnerabilities to early Alzheimer's pathology.
Journal: Nature communications
In common: WGCNA, ggplot2, genetics / omics, mouse, cellular / molecular, 13 references, 6 authors
[2] doi:10.1016/j.mcpro.2025.101458 [code]
Proximity Labeling of the Tau Repeat Domain Enriches RNA-Binding Proteins That Are Altered in Alzheimer's Disease and Related Tauopathies.
Journal: Molecular & cellular proteomics : MCP
In common: WGCNA, ggplot2, genetics / omics, cellular / molecular, 10 references, 3 authors
[3] doi:10.1016/j.mcpro.2023.100546 [code]
Cellular Proteomic Profiling Using Proximity Labeling by TurboID-NES in Microglial and Neuronal Cell Lines.
Journal: Molecular & cellular proteomics : MCP
In common: tidyverse, genetics / omics, mouse, cellular / molecular, 13 references, 2 authors
[4] doi:10.1038/s41467-024-52297-3 [code]
Entorhinal cortex vulnerability to human APP expression promotes hyperexcitability and tau pathology.
Journal: Nature communications
In common: mouse, 4 references, 4 authors
[5] doi:10.1016/j.mcpro.2023.100678 [code]
Identification of State-Specific Proteomic and Transcriptomic Signatures of Microglia-Derived Extracellular Vesicles.
Journal: Molecular & cellular proteomics : MCP
In common: WGCNA, DESeq2, pheatmap, 2 other tools, genetics / omics, mouse, cellular / molecular, 3 references, 2 authors
[6] doi:10.1016/j.celrep.2022.111474 [code]
Activity-dependent translation dynamically alters the proteome of the perisynaptic astrocyte process.
Journal: Cell reports
In common: limma, data.table, ggplot2, 1 other tool, genetics / omics, cellular / molecular, 12 references
[7] doi:10.1016/j.mcpro.2022.100422
Deciphering Spatial Protein-Protein Interactions in Brain Using Proximity Labeling.
Journal: Molecular & cellular proteomics : MCP
In common: genetics / omics, cellular / molecular, 12 references
[8] doi:10.1038/s41467-025-63119-5 [code]
An integrated transcriptomic and proteomic map of the mouse hippocampus at synaptic resolution.
Journal: Nature communications
In common: DESeq2, pheatmap, data.table, 2 other tools, genetics / omics, mouse, cellular / molecular, 11 references
[9] doi:10.1038/s41467-025-64328-8 [code]
Integrative brain omics approach highlights sn-1 lysophosphatidylethanolamine in Alzheimer's dementia.
Journal: Nature communications
In common: WGCNA, limma, pheatmap, 3 other tools, genetics / omics, 2 references, 2 authors
[10] doi:10.1186/s13024-023-00638-z [code]
Quantitative proteomics of cerebrospinal fluid from African Americans and Caucasians reveals shared and divergent changes in Alzheimer's disease.
Journal: Molecular neurodegeneration
In common: WGCNA, ggplot2, tidyverse, genetics / omics, 5 references, 2 authors

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Add the badge to the code's README

OSCR: the badge of this paper

If you are an author or a maintainer of this paper's code, you can add this badge. It says what OSCR knows of the paper (its code, its validated tracing map) and links the code to this page. Paste one of these snippets under the README's title. Keep the two marks around it, so that the badge can be replaced in place and is never added twice. OSCR changes nothing in your repository.

Markdown
<!-- oscr-badge:start -->
[![OSCR](https://openscicode.org/badge/doi/10.1038/s41467-026-71098-4.svg)](https://openscicode.org/badge/doi/10.1038/s41467-026-71098-4)
<!-- oscr-badge:end -->
reStructuredText
.. oscr-badge:start

.. image:: https://openscicode.org/badge/doi/10.1038/s41467-026-71098-4.svg
   :target: https://openscicode.org/badge/doi/10.1038/s41467-026-71098-4
   :alt: OSCR

.. oscr-badge:end
HTML
<!-- oscr-badge:start -->
<a href="https://openscicode.org/badge/doi/10.1038/s41467-026-71098-4"><img src="https://openscicode.org/badge/doi/10.1038/s41467-026-71098-4.svg" alt="OSCR"></a>
<!-- oscr-badge:end -->

On GitHub, open the README, choose Edit (the pencil), paste the snippet under the title, then "Commit changes".

If you choose to, you can have the badge kept up to date for you, with oscr badge --write from the command line or with the GitHub Action in your repository's workflows. Every other form and option (a card, AsciiDoc, LaTeX, shields.io) is on the badge page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: code errors and mismatches between the code and the paper about this paper and its code, from readers and its authors, beside the paper and its tracing map.

Report a mismatch between the code and the paper · Report a code error (signed in)

Reproductions: reports from readers who ran the authors' code and did not get the paper's result, what they ran, with which environment, commit and data.

Report a reproduction failure (signed in)

Versions of its code: the releases of its code tied to a version of this paper (the preprint, the accepted manuscript, the version of record…), each with the tracing map versioned with it.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.