OSCR

Dynamic transcriptomic remodeling in grafted human neural progenitor cells uncovers mechanisms for vision preservation in a rat model of retinitis pigmentosa.

Code ↔ Paper

8 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 8 matches
  1. [1] § Methods › Efficacy evaluation › Removing low-quality cells and identification of cell types ↔ Rat/20230922_rat_retina_with_GEO.R, lines 1133–1177 · score 0.85 · SelectIntegrationFeatures, FindIntegrationAnchors, downstream integration, ScaleData, RunPCA, gene
  2. [2] § Methods › Efficacy evaluation › Removing low-quality cells and identification of cell types ↔ Rat/20230922_rat_retina_with_GEO.R, lines 1133–1177 · score 0.74 · FindIntegrationAnchors, IntegrateData, ScaleData, RunPCA, gene
  3. [3] § Methods › Efficacy evaluation › Removing low-quality cells and identification of cell types ↔ hNPC/hNPC_Script.Rmd, lines 623–633 · score 0.69 · FindClusters, FindNeighbors, RunUMAP, Dimensionality reduction, PCA, clustering
  4. [4] § Methods › Efficacy evaluation › Removing low-quality cells and identification of cell types ↔ hNPC/hNPC_Script.Rmd, lines 623–633 · score 0.69 · FindClusters, FindNeighbors, RunUMAP, Dimensionality reduction, PCA, clustering
  5. [5] § Results › Grafted hNPCs mature into astrocytic cells in the degenerative retina ↔ hNPC/hNPC_Script.Rmd, lines 836–850 · score 0.67 · SLC1A3, S100B, HOPX, SOX9, OLIG1, CD44
  6. [6] § Results › Retinal transcriptomic remodeling following hNPC transplantation ↔ Rat/20230922_rat_retina_with_GEO.R, lines 2037–2083 · score 0.60 · amacrine cells, retinal ganglion cells, bipolar cells, microglia, retinas
  7. [7] § Results › Grafted hNPCs mature into astrocytic cells in the degenerative retina ↔ hNPC/hNPC_Script.Rmd, lines 1239–1264 · score 0.55 · S100B, PDGFRA, OLIG1, CD44, MBP, NES
  8. [8] § Results › Temporal transcriptomic shifts reveal hNPC-mediated retinal protection ↔ Rat/20230922_rat_retina_with_GEO.R, lines 4520–4563 · score 0.53 · C1qb, C1qa, Aif1, Ctsd

Paper

Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

R · 5,960 lines · 195 KB · Apache-2.0 · 4 matches

  1. # 20230922_rat_retina_with_GEO.R
  2. #### SETUP ####
  3. #### Samples and path variables ####
  4. # Rat retina treated with human cells
  5. # WT rat retina samples from GEO GSE209872
  6. # ALIGNED to RAT ref rnor
  7. # samples used:
  8. #
  9. # rnor_08182_P90_Treated_rat_human_cells_outs
  10. # rnor_13933_P60_Treated_rat_cells_outs
  11. # rnor_13933_P60_Untreated_rat_cells_outs
  12. # rnor_16573_P90_Treated_rat_cells_outs
  13. # rnor_16573_P90_Untreated_rat_cells_outs
  14. # rnor_18482_P60_Treated_rat_cells_outs
  15. # rnor_18482_P60_Untreated_rat_cells_outs
  16. # rnor_19328_P60_Treated_rat_cells_outs
  17. # rnor_19328_P60_Untreated_rat_cells_outs
  18. # rnor_SRR20570827_outs
  19. # rnor_SRR20570828_outs
  20. date <- "20230922"
  21. project <- "Rat_retina_with_GEO"
  22. datadir <- "/Users/bells/Library/CloudStorage/Box-Box/20230922_rat_retina_with_GEO"
  23. sourcedir1 <- "/Users/bells/Library/CloudStorage/Box-Box/20230317_rnor_outs_copy"
  24. sourcedir2 <- "/Users/bells/Library/CloudStorage/Box-Box/20230926_rnor_wang_geo_outs_copy"
  25. #### Load required packages ####
  26. library(Seurat)
  27. library(tidyverse)
  28. library(Matrix)
  29. library(cowplot)
  30. library(viridis)
  31. library(patchwork)
  32. library(pheatmap)
  33. library(irlba)
  34. library(beepr)
  35. library(SeuratDisk)
  36. library(EnhancedVolcano)
  37. library(Vennerable)
  38. #### Set working dir and save session info ####
  39. setwd(datadir)
  40. sessionInfo()
  41. sink(paste0(date,"_",project,"_devtools_sessionInfo3.txt"))
  42. devtools::session_info()
  43. sink()
  44. sink(paste0(date,"_",project,"_sessionInfo3.txt"))
  45. sessionInfo()
  46. sink()
  47. #### Functions for saving images in hires ####
  48. hirestiff <- function(saveas){
  49. ggsave(
  50. saveas,
  51. plot = last_plot(),
  52. device = "tiff",
  53. scale = 1,
  54. dpi = 600,
  55. limitsize = TRUE
  56. )
  57. }
  58. lowrestiff <- function(saveas){
  59. ggsave(
  60. saveas,
  61. plot = last_plot(),
  62. device = "tiff",
  63. scale = 1,
  64. dpi = 100,
  65. limitsize = TRUE
  66. )
  67. }
  68. hirestiffsquare <- function(saveas){
  69. ggsave(
  70. saveas,
  71. plot = last_plot(),
  72. device = "tiff",
  73. scale = 1,
  74. dpi = 600,
  75. limitsize = TRUE,
  76. bg = "white",
  77. width = 9,
  78. height = 9,
  79. units = c("in")
  80. )
  81. }
  82. lowrestiffsquare <- function(saveas){
  83. ggsave(
  84. saveas,
  85. plot = last_plot(),
  86. device = "tiff",
  87. scale = 1,
  88. dpi = 100,
  89. limitsize = TRUE,
  90. bg = "white",
  91. width = 9,
  92. height = 9,
  93. units = c("in")
  94. )
  95. }
  96. savepdf <- function(saveas){
  97. ggsave(
  98. saveas,
  99. plot = last_plot(),
  100. device = "pdf",
  101. scale = 1,
  102. dpi = 600,
  103. limitsize = TRUE
  104. )
  105. }
  106. savepdfsquare <- function(saveas){
  107. ggsave(
  108. saveas,
  109. plot = last_plot(),
  110. device = "pdf",
  111. scale = 1,
  112. dpi = 600,
  113. width = 9,
  114. height = 9,
  115. limitsize = TRUE
  116. )
  117. }
  118. #### restore prefixes ####
  119. # only save after determining cluster resolution
  120. # must enter at minimum the date variable and datadir
  121. setwd(datadir)
  122. # for sct data:
  123. # save(datadir, date, ident_res, meaningful.PCs,
  124. # prefixPC, prefixPCres, project, res, sourcedir,
  125. # hirestiff, hirestiffsquare,
  126. # lowrestiff, lowrestiffsquare,
  127. # savepdf, savepdfsquare,
  128. # file = paste0(datadir,"/",date,"_",project,"_","prefixes.rdata"))
  129. # load(paste0(datadir,"/",date,"_",project,"_","prefixes.rdata"))
  130. # for integrated data:
  131. # save(datadir, date, ident_res, meaningful.PCs, prefixPC, prefixPCres,
  132. # project, res, sourcedir1, sourcedir2,
  133. # hirestiff, hirestiffsquare,
  134. # lowrestiff, lowrestiffsquare,
  135. # savepdf, savepdfsquare,
  136. # palopal, sorted_palopal,
  137. # file = paste0(datadir,"/",date,"_",project,"_","prefixes.rdata"))
  138. project <- "Rat_retina_with_GEO_int"
  139. load(paste0(datadir,"/",date,"_",project,"_","prefixes.rdata"))
  140. seurat_sct <- readRDS(file = paste0(prefixPCres,"_seurat_after_RNAnorm_CELLTYPES.rds"))
  141. #### LOAD DATA ####
  142. #### Load data from Cellranger output ####
  143. sample_list <- c(
  144. "rnor_08182_P90_Treated_rat_human_cells_outs",
  145. "rnor_13933_P60_Treated_rat_cells_outs",
  146. "rnor_13933_P60_Untreated_rat_cells_outs",
  147. "rnor_16573_P90_Treated_rat_cells_outs",
  148. "rnor_16573_P90_Untreated_rat_cells_outs",
  149. "rnor_18482_P60_Treated_rat_cells_outs",
  150. "rnor_18482_P60_Untreated_rat_cells_outs",
  151. "rnor_19328_P60_Treated_rat_cells_outs",
  152. "rnor_19328_P60_Untreated_rat_cells_outs",
  153. "rnor_SRR20570827_outs",
  154. "rnor_SRR20570828_outs"
  155. )
  156. # since we have data from two separate source directories
  157. # we make two filelists and pathlists
  158. filelist1 <- list.files(path = sourcedir1)
  159. filelist1 <- as.data.frame(filelist1, files = list.files(path = sourcedir1))
  160. path_list1 <- paste0(sourcedir1,"/",filelist1[,1],"/filtered_feature_bc_matrix")
  161. filelist2 <- list.files(path = sourcedir2)
  162. filelist2 <- as.data.frame(filelist2, files = list.files(path = sourcedir2))
  163. path_list2 <- paste0(sourcedir2,"/",filelist2[,1],"/filtered_feature_bc_matrix")
  164. path_list <- c(path_list1,path_list2)
  165. path_list
  166. # check that all files exist
  167. all(file.exists(path_list))
  168. # check that the sample list and path list are in the same order
  169. for (i in 1:length(sample_list)) {
  170. TF <- grepl(sample_list[i],path_list[i])
  171. print(paste0(sample_list[i]," ",TF))
  172. }
  173. # make an empty list to store data into
  174. data_list <- vector("list")
  175. # make a list of all the 10X data
  176. for (i in 1:length(sample_list)) {
  177. # read in cellranger output
  178. cellranger <- Read10X(data.dir = path_list[i])
  179. # append data to the list
  180. data_list <- c(data_list,cellranger)
  181. }
  182. updated_samps <- c("08182.p90.TR",
  183. "13933.p60.TR",
  184. "13933.p60.UT",
  185. "16573.p90.TR",
  186. "16573.p90.UT",
  187. "18482.p60.TR",
  188. "18482.p60.UT",
  189. "19328.p60.TR",
  190. "19328.p60.UT",
  191. "GEO27.p00.WT",
  192. "GEO28.p00.WT")
  193. names(data_list) <- updated_samps
  194. #### Seurat Object ####
  195. # Initialize the Seurat object with the raw (non-normalized data).
  196. # Keep all genes expressed in >= 1 cell
  197. # make an empty list to store data into
  198. seurat_list <- vector("list")
  199. # make a list of all the 10X data
  200. for (i in 1:length(data_list)) {
  201. # create seurat object
  202. s.data <- CreateSeuratObject(counts = data_list[[i]],
  203. project = updated_samps[i],
  204. min.cells = 1,
  205. min.features = 0)
  206. # append data to the list
  207. seurat_list <- c(seurat_list,s.data)
  208. }
  209. names(seurat_list) <- updated_samps
  210. seurat_list
  211. #### Add metadata ####
  212. # Create lists for metadata attributes
  213. time_point <- c(
  214. "08182.p90.TR" = "p90",
  215. "13933.p60.TR" = "p60",
  216. "13933.p60.UT" = "p60",
  217. "16573.p90.TR" = "p90",
  218. "16573.p90.UT" = "p90",
  219. "18482.p60.TR" = "p60",
  220. "18482.p60.UT" = "p60",
  221. "19328.p60.TR" = "p60",
  222. "19328.p60.UT" = "p60",
  223. "GEO27.p00.WT" = "WT",
  224. "GEO28.p00.WT" = "WT"
  225. )
  226. treatment <- c(
  227. "08182.p90.TR" = "Cell_Treated",
  228. "13933.p60.TR" = "Cell_Treated",
  229. "13933.p60.UT" = "Untreated",
  230. "16573.p90.TR" = "Cell_Treated",
  231. "16573.p90.UT" = "Untreated",
  232. "18482.p60.TR" = "Cell_Treated",
  233. "18482.p60.UT" = "Untreated",
  234. "19328.p60.TR" = "Cell_Treated",
  235. "19328.p60.UT" = "Untreated",
  236. "GEO27.p00.WT" = "Untreated",
  237. "GEO28.p00.WT" = "Untreated"
  238. )
  239. batch <- c(
  240. "08182.p90.TR" = "08182",
  241. "13933.p60.TR" = "13933",
  242. "13933.p60.UT" = "13933",
  243. "16573.p90.TR" = "16573",
  244. "16573.p90.UT" = "16573",
  245. "18482.p60.TR" = "18482",
  246. "18482.p60.UT" = "18482",
  247. "19328.p60.TR" = "19328",
  248. "19328.p60.UT" = "19328",
  249. "GEO27.p00.WT" = "GSE209872",
  250. "GEO28.p00.WT" = "GSE209872"
  251. )
  252. orig.ident <- c(
  253. "08182.p90.TR" = "08182.p90.TR",
  254. "13933.p60.TR" = "13933.p60.TR",
  255. "13933.p60.UT" = "13933.p60.UT",
  256. "16573.p90.TR" = "16573.p90.TR",
  257. "16573.p90.UT" = "16573.p90.UT",
  258. "18482.p60.TR" = "18482.p60.TR",
  259. "18482.p60.UT" = "18482.p60.UT",
  260. "19328.p60.TR" = "19328.p60.TR",
  261. "19328.p60.UT" = "19328.p60.UT",
  262. "GEO27.p00.WT" = "GEO27.WT.UT",
  263. "GEO28.p00.WT" = "GEO28.WT.UT"
  264. )
  265. # Iterate through the Seurat objects and assign metadata
  266. for (key in names(time_point)) {
  267. seurat_list[[key]][["time_point"]] <- time_point[key]
  268. seurat_list[[key]][["treatment"]] <- treatment[key]
  269. seurat_list[[key]][["batch"]] <- batch[key]
  270. seurat_list[[key]][["time_point_treatment"]] <- paste(time_point[key], treatment[key], sep = "_")
  271. seurat_list[[key]][["time_point_batch"]] <- paste(time_point[key], batch[key], sep = "_")
  272. seurat_list[[key]][["treatment_batch"]] <- paste(treatment[key], batch[key], sep = "_")
  273. seurat_list[[key]][["time_point_treatment_batch"]] <- paste(time_point[key], treatment[key], batch[key], sep = "_")
  274. seurat_list[[key]][["orig.ident"]] <- orig.ident[key]
  275. }
  276. #### Merge all data into a single seurat object ####
  277. tenx1 <- merge(seurat_list$"08182.p90.TR",
  278. y = c(
  279. seurat_list$"13933.p60.TR",
  280. seurat_list$"13933.p60.UT",
  281. seurat_list$"16573.p90.TR",
  282. seurat_list$"16573.p90.UT",
  283. seurat_list$"18482.p60.TR",
  284. seurat_list$"18482.p60.UT",
  285. seurat_list$"19328.p60.TR",
  286. seurat_list$"19328.p60.UT",
  287. seurat_list$"GEO27.p00.WT",
  288. seurat_list$"GEO28.p00.WT"
  289. ),
  290. add.cell.ids = c(
  291. "08182.p90.TR",
  292. "13933.p60.TR",
  293. "13933.p60.UT",
  294. "16573.p90.TR",
  295. "16573.p90.UT",
  296. "18482.p60.TR",
  297. "18482.p60.UT",
  298. "19328.p60.TR",
  299. "19328.p60.UT",
  300. "GEO27.p00.WT",
  301. "GEO28.p00.WT"
  302. ),
  303. project = project)
  304. tenx1
  305. rm(cellranger,
  306. data_list,
  307. filelist1,
  308. filelist2,
  309. s.data,
  310. seurat_list,
  311. batch,
  312. i,
  313. key,
  314. path_list,
  315. path_list1,
  316. path_list2,
  317. sample_list,
  318. TF,
  319. time_point,
  320. treatment,
  321. updated_samps)
  322. # save merged seurat object
  323. # saveRDS(tenx1, file = paste0("./",date,"_",project,"_merged_seurat_prefilter.rds"))
  324. # tenx1 <- read_rds(file = paste0("./",date,"_",project,"_merged_seurat_prefilter.rds"))
  325. #### QC FILTERING ####
  326. #### QC Setup ####
  327. # copy tenx1 to another object data just in case
  328. data <- tenx1
  329. # check to make sure pattern is correct and not grepping other genes
  330. grep("^Mt-",rownames(data),value = T) # mitochondrial genes
  331. grep("^Rp[sl]",rownames(data),value = T) # ribosomal genes
  332. grep("^Mrp[sl]",rownames(data),value = T) # mitochondrial-ribosomal genes
  333. grep("^Hb[abq]",rownames(data),value = T) # hemoglobin genes
  334. # Add PercentageFeatureSet of various factors to metadata
  335. data[["percent.mt"]] <- PercentageFeatureSet(data, pattern = "^Mt-")
  336. data[["percent.ribo"]] <- PercentageFeatureSet(data, pattern = "^Rp[sl]")
  337. data[["percent.mt.ribo"]] <- PercentageFeatureSet(data, pattern = "^Mrp[sl]")
  338. data[["percent.hb"]] <- PercentageFeatureSet(data, pattern = "^Hb[abq]")
  339. #### Prefiltered Plots ####
  340. vp <- VlnPlot(data, features = "nCount_RNA", pt.size = 0) +
  341. NoLegend() +
  342. ggtitle("nCount_RNA prefiltered")
  343. vp
  344. pdf(paste0("./",date,"_",project,"_prefilter_","nCount_RNA",".pdf"))
  345. print(vp)
  346. dev.off()
  347. vp <- VlnPlot(data, features = "nFeature_RNA", pt.size = 0) +
  348. NoLegend() +
  349. ggtitle("nFeature_RNA prefiltered")
  350. vp
  351. pdf(paste0("./",date,"_",project,"_prefilter_","nFeature_RNA",".pdf"))
  352. print(vp)
  353. dev.off()
  354. vp <- VlnPlot(data, features = "percent.mt", pt.size = 0) +
  355. NoLegend() +
  356. ggtitle("percent.mt prefiltered")
  357. vp
  358. pdf(paste0("./",date,"_",project,"_prefilter_","percent.mt",".pdf"))
  359. print(vp)
  360. dev.off()
  361. vp <- VlnPlot(data, features = "percent.ribo", pt.size = 0) +
  362. NoLegend() +
  363. ggtitle("percent.ribo prefiltered")
  364. vp
  365. pdf(paste0("./",date,"_",project,"_prefilter_","percent.ribo",".pdf"))
  366. print(vp)
  367. dev.off()
  368. vp <- VlnPlot(data, features = "percent.mt.ribo", pt.size = 0) +
  369. NoLegend() +
  370. ggtitle("percent.mt.ribo prefiltered")
  371. vp
  372. pdf(paste0("./",date,"_",project,"_prefilter_","percent.mt.ribo",".pdf"))
  373. print(vp)
  374. dev.off()
  375. vp <- VlnPlot(data, features = "percent.hb", pt.size = 0) +
  376. NoLegend() +
  377. ggtitle("percent.hb prefiltered")
  378. vp
  379. pdf(paste0("./",date,"_",project,"_prefilter_","percent.hb",".pdf"))
  380. print(vp)
  381. dev.off()
  382. p1 <- FeatureScatter(data, feature1 = "nCount_RNA", feature2 = "percent.mt")
  383. p2 <- FeatureScatter(data, feature1 = "nCount_RNA", feature2 = "nFeature_RNA")
  384. p1 + p2
  385. pdf(paste0("./",date,"_",project,"_prefilter_","scatterplots",".pdf"))
  386. print(p1 + p2)
  387. dev.off()
  388. #### Additional Prefiltered QC metrics and plots ####
  389. qc.metrics <- as_tibble(data[[c("nCount_RNA",
  390. "nFeature_RNA",
  391. "percent.mt",
  392. "percent.ribo",
  393. "percent.mt.ribo",
  394. "percent.hb")]],
  395. rownames="Cell.Barcode")
  396. sp <- qc.metrics %>%
  397. arrange(percent.mt) %>%
  398. ggplot(aes(nCount_RNA,nFeature_RNA,colour=percent.mt)) +
  399. geom_point() +
  400. scale_color_gradientn(colors=c("black","blue","green2","red","yellow")) +
  401. ggtitle("QC metrics - percent Mitochondial DNA Prefiltered")
  402. sp
  403. pdf(paste0("./",date,"_",project,"_QC_Metrics_pct.mt_prefilter",".pdf"))
  404. print(sp)
  405. dev.off()
  406. sp <- qc.metrics %>%
  407. arrange(percent.ribo) %>%
  408. ggplot(aes(nCount_RNA,nFeature_RNA,colour=percent.ribo)) +
  409. geom_point() +
  410. scale_color_gradientn(colors=c("black","blue","green2","red","yellow")) +
  411. ggtitle("QC metrics - percent Ribosomal DNA Prefiltered")
  412. sp
  413. pdf(paste0("./",date,"_",project,"_QC_Metrics_pct.ribo_prefilter",".pdf"))
  414. print(sp)
  415. dev.off()
  416. sp <- qc.metrics %>%
  417. arrange(percent.mt.ribo) %>%
  418. ggplot(aes(nCount_RNA,nFeature_RNA,colour=percent.mt.ribo)) +
  419. geom_point() +
  420. scale_color_gradientn(colors=c("black","blue","green2","red","yellow")) +
  421. ggtitle("QC metrics - percent Mito-Ribosomal DNA Prefiltered")
  422. sp
  423. pdf(paste0("./",date,"_",project,"_QC_Metrics_pct.mt.ribo_prefilter",".pdf"))
  424. print(sp)
  425. dev.off()
  426. sp <- qc.metrics %>%
  427. arrange(percent.hb) %>%
  428. ggplot(aes(nCount_RNA,nFeature_RNA,colour=percent.hb)) +
  429. geom_point() +
  430. scale_color_gradientn(colors=c("black","blue","green2","red","yellow")) +
  431. ggtitle("QC metrics - percent Hemoglobin DNA Prefiltered")
  432. sp
  433. pdf(paste0("./",date,"_",project,"_QC_Metrics_pct.hb_prefilter",".pdf"))
  434. print(sp)
  435. dev.off()
  436. sp <- qc.metrics %>%
  437. ggplot(aes(percent.mt)) +
  438. geom_histogram(binwidth = 0.5, fill="yellow", colour="black") +
  439. ggtitle("Distribution of Percentage of reads from Mitochondria Prefiltered")
  440. sp
  441. pdf(paste0("./",date,"_",project,"_Dist_mito_prefilter",".pdf"))
  442. print(sp)
  443. dev.off()
  444. sp <- qc.metrics %>%
  445. ggplot(aes(percent.ribo)) +
  446. geom_histogram(binwidth = 0.5, fill="yellow", colour="black") +
  447. ggtitle("Distribution of Percentage of reads from Ribosomes Prefiltered")
  448. sp
  449. pdf(paste0("./",date,"_",project,"_Dist_ribo_prefilter",".pdf"))
  450. print(sp)
  451. dev.off()
  452. sp <- qc.metrics %>%
  453. ggplot(aes(percent.mt.ribo)) +
  454. geom_histogram(binwidth = 0.05, fill="yellow", colour="black") +
  455. ggtitle("Distribution of Percentage of reads from Mito-Ribosomes Prefiltered")
  456. sp
  457. pdf(paste0("./",date,"_",project,"_Dist_mt_ribo_prefilter",".pdf"))
  458. print(sp)
  459. dev.off()
  460. sp <- qc.metrics %>%
  461. ggplot(aes(percent.hb)) +
  462. geom_histogram(binwidth = 0.5, fill="yellow", colour="black") +
  463. ggtitle("Distribution of Percentage of reads from Hemoglobin Prefiltered")
  464. sp
  465. pdf(paste0("./",date,"_",project,"_Dist_hb_prefilter",".pdf"))
  466. print(sp)
  467. dev.off()
  468. #### Add Z-scores ####
  469. data[["nUMI.z"]] <- scale(data$nCount_RNA)
  470. data[["nGene.z"]] <- scale(data$nFeature_RNA)
  471. data[["percent.mt.z"]] <- scale(data$percent.mt)
  472. data[["percent.ribo.z"]] <- scale(data$percent.ribo)
  473. data[["percent.mt.ribo.z"]] <- scale(data$percent.mt.ribo)
  474. data[["percent.hb.z"]] <- scale(data$percent.hb)
  475. #### Prefiltered QC data ####
  476. length([email hidden]$orig.ident)
  477. mean([email hidden]$percent.mt)
  478. mean([email hidden]$percent.ribo)
  479. mean([email hidden]$percent.mt.ribo)
  480. mean([email hidden]$percent.hb)
  481. mean([email hidden]$nCount_RNA)
  482. median([email hidden]$nCount_RNA)
  483. mean([email hidden]$nFeature_RNA)
  484. median([email hidden]$nFeature_RNA)
  485. max([email hidden]$nCount_RNA)
  486. # save prefilter QC data
  487. sink(paste0("./",date,"_",project,"_prefilter_QC_metrics.txt"))
  488. cat("length")
  489. length([email hidden]$orig.ident)
  490. cat("mean percent mito")
  491. mean([email hidden]$percent.mt)
  492. cat("mean percent ribo")
  493. mean([email hidden]$percent.ribo)
  494. cat("mean percent mito-ribo")
  495. mean([email hidden]$percent.mt.ribo)
  496. cat("mean hemoglobin")
  497. mean([email hidden]$percent.hb)
  498. cat("mean percent counts")
  499. mean([email hidden]$nCount_RNA)
  500. cat("median counts")
  501. median([email hidden]$nCount_RNA)
  502. cat("mean features")
  503. mean([email hidden]$nFeature_RNA)
  504. cat("median features")
  505. median([email hidden]$nFeature_RNA)
  506. cat("max counts")
  507. max([email hidden]$nCount_RNA)
  508. sink()
  509. #### Filter cells based on Z-score ####
  510. data <- subset(data, subset = percent.mt.z < 3)
  511. data <- subset(data, subset = percent.ribo.z < 3)
  512. data <- subset(data, subset = percent.mt.ribo.z < 3)
  513. data <- subset(data, subset = percent.hb.z < 3)
  514. # data <- subset(data, subset = nGene.z < 3)
  515. # data <- subset(data, subset = nUMI.z < 3)
  516. #### Postfiltered QC data ####
  517. length([email hidden]$orig.ident)
  518. mean([email hidden]$percent.mt)
  519. mean([email hidden]$percent.ribo)
  520. mean([email hidden]$percent.hb)
  521. mean([email hidden]$nCount_RNA)
  522. median([email hidden]$nCount_RNA)
  523. mean([email hidden]$nFeature_RNA)
  524. median([email hidden]$nFeature_RNA)
  525. max([email hidden]$nCount_RNA)
  526. # save postfilter QC data
  527. sink(paste0("./",date,"_",project,"_postfilter_QC_metrics.txt"))
  528. cat("length")
  529. length([email hidden]$orig.ident)
  530. cat("mean percent mito")
  531. mean([email hidden]$percent.mt)
  532. cat("mean percent ribo")
  533. mean([email hidden]$percent.ribo)
  534. cat("mean percent mito-ribo")
  535. mean([email hidden]$percent.mt.ribo)
  536. cat("mean hemoglobin")
  537. mean([email hidden]$percent.hb)
  538. cat("mean percent counts")
  539. mean([email hidden]$nCount_RNA)
  540. cat("median counts")
  541. median([email hidden]$nCount_RNA)
  542. cat("mean features")
  543. mean([email hidden]$nFeature_RNA)
  544. cat("median features")
  545. median([email hidden]$nFeature_RNA)
  546. cat("max counts")
  547. max([email hidden]$nCount_RNA)
  548. sink()
  549. #### Postfiltered Plots ####
  550. vp <- VlnPlot(data, features = "nCount_RNA", pt.size = 0, group.by = "orig.ident") +
  551. NoLegend() +
  552. ggtitle("nCount_RNA filtered")
  553. vp
  554. pdf(paste0("./",date,"_",project,"_filtered_","nCount_RNA",".pdf"))
  555. print(vp)
  556. dev.off()
  557. vp <- VlnPlot(data, features = "nFeature_RNA", pt.size = 0, group.by = "orig.ident") +
  558. NoLegend() +
  559. ggtitle("nFeature_RNA filtered")
  560. vp
  561. pdf(paste0("./",date,"_",project,"_filtered_","nFeature_RNA",".pdf"))
  562. print(vp)
  563. dev.off()
  564. vp <- VlnPlot(data, features = "percent.mt", pt.size = 0, group.by = "orig.ident") +
  565. NoLegend() +
  566. ggtitle("percent.mt filtered")
  567. vp
  568. pdf(paste0("./",date,"_",project,"_filtered_","percent.mt",".pdf"))
  569. print(vp)
  570. dev.off()
  571. vp <- VlnPlot(data, features = "percent.ribo", pt.size = 0, group.by = "orig.ident") +
  572. NoLegend() +
  573. ggtitle("percent.ribo filtered")
  574. vp
  575. pdf(paste0("./",date,"_",project,"_filtered_","percent.ribo",".pdf"))
  576. print(vp)
  577. dev.off()
  578. vp <- VlnPlot(data, features = "percent.mt.ribo", pt.size = 0) +
  579. NoLegend() +
  580. ggtitle("percent.mt.ribo filtered")
  581. vp
  582. pdf(paste0("./",date,"_",project,"_filtered_","percent.mt.ribo",".pdf"))
  583. print(vp)
  584. dev.off()
  585. vp <- VlnPlot(data, features = "percent.hb", pt.size = 0) +
  586. NoLegend() +
  587. ggtitle("percent.hb filtered")
  588. vp
  589. pdf(paste0("./",date,"_",project,"_filtered_","percent.hb",".pdf"))
  590. print(vp)
  591. dev.off()
  592. p1 <- FeatureScatter(data, feature1 = "nCount_RNA", feature2 = "percent.mt")
  593. p2 <- FeatureScatter(data, feature1 = "nCount_RNA", feature2 = "nFeature_RNA")
  594. p1 + p2
  595. pdf(paste0("./",date,"_",project,"_filtered_","scatterplots",".pdf"))
  596. print(p1 + p2)
  597. dev.off()
  598. #### Additional postfiltered QC metrics and plots ####
  599. qc.metrics <- as_tibble(data[[c("nCount_RNA",
  600. "nFeature_RNA",
  601. "percent.mt",
  602. "percent.ribo",
  603. "percent.mt.ribo",
  604. "percent.hb")]],
  605. rownames="Cell.Barcode")
  606. sp <- qc.metrics %>%
  607. arrange(percent.mt) %>%
  608. ggplot(aes(nCount_RNA,nFeature_RNA,colour=percent.mt)) +
  609. geom_point() +
  610. scale_color_gradientn(colors=c("black","blue","green2","red","yellow")) +
  611. ggtitle("QC metrics - percent Mitochondial DNA Postfilter")
  612. sp
  613. pdf(paste0("./",date,"_",project,"_QC_Metrics_pct.mt_postfilter",".pdf"))
  614. print(sp)
  615. dev.off()
  616. sp <- qc.metrics %>%
  617. arrange(percent.ribo) %>%
  618. ggplot(aes(nCount_RNA,nFeature_RNA,colour=percent.ribo)) +
  619. geom_point() +
  620. scale_color_gradientn(colors=c("black","blue","green2","red","yellow")) +
  621. ggtitle("QC metrics - percent Ribosomal DNA Postfilter")
  622. sp
  623. pdf(paste0("./",date,"_",project,"_QC_Metrics_pct.ribo_postfilter",".pdf"))
  624. print(sp)
  625. dev.off()
  626. sp <- qc.metrics %>%
  627. arrange(percent.mt.ribo) %>%
  628. ggplot(aes(nCount_RNA,nFeature_RNA,colour=percent.mt.ribo)) +
  629. geom_point() +
  630. scale_color_gradientn(colors=c("black","blue","green2","red","yellow")) +
  631. ggtitle("QC metrics - percent Mito-Ribosomal DNA Postfilter")
  632. sp
  633. pdf(paste0("./",date,"_",project,"_QC_Metrics_pct.mt.ribo_postfilter",".pdf"))
  634. print(sp)
  635. dev.off()
  636. sp <- qc.metrics %>%
  637. arrange(percent.hb) %>%
  638. ggplot(aes(nCount_RNA,nFeature_RNA,colour=percent.hb)) +
  639. geom_point() +
  640. scale_color_gradientn(colors=c("black","blue","green2","red","yellow")) +
  641. ggtitle("QC metrics - percent Hemoglobin DNA Postfilter")
  642. sp
  643. pdf(paste0("./",date,"_",project,"_QC_Metrics_pct.hb_postfilter",".pdf"))
  644. print(sp)
  645. dev.off()
  646. sp <- qc.metrics %>%
  647. ggplot(aes(percent.mt)) +
  648. geom_histogram(binwidth = 0.25, fill="yellow", colour="black") +
  649. ggtitle("Distribution of Percentage of reads from Mitochondria Postfilter")
  650. sp
  651. pdf(paste0("./",date,"_",project,"_Dist_mito_postfilter",".pdf"))
  652. print(sp)
  653. dev.off()
  654. sp <- qc.metrics %>%
  655. ggplot(aes(percent.ribo)) +
  656. geom_histogram(binwidth = 0.5, fill="yellow", colour="black") +
  657. ggtitle("Distribution of Percentage of reads from Ribosomes Postfilter")
  658. sp
  659. pdf(paste0("./",date,"_",project,"_Dist_ribo_postfilter",".pdf"))
  660. print(sp)
  661. dev.off()
  662. sp <- qc.metrics %>%
  663. ggplot(aes(percent.mt.ribo)) +
  664. geom_histogram(binwidth = 0.05, fill="yellow", colour="black") +
  665. ggtitle("Distribution of Percentage of reads from Mito-Ribosomes Postfilter")
  666. sp
  667. pdf(paste0("./",date,"_",project,"_Dist_mt_ribo_postfilter",".pdf"))
  668. print(sp)
  669. dev.off()
  670. sp <- qc.metrics %>%
  671. ggplot(aes(percent.hb)) +
  672. geom_histogram(binwidth = 0.05, fill="yellow", colour="black") +
  673. ggtitle("Distribution of Percentage of reads from Hemoglobin Postfilter")
  674. sp
  675. pdf(paste0("./",date,"_",project,"_Dist_hb_postfilter",".pdf"))
  676. print(sp)
  677. dev.off()
  678. #### post QC cleanup ####
  679. tenx1
  680. data
  681. tenx1 <- data
  682. rm(vp,sp,p1,p2,
  683. qc.metrics,data)
  684. #### set factor levels ####
  685. seurat_sct <- tenx1
  686. seurat_sct$orig.ident <- factor(
  687. x = seurat_sct$orig.ident,
  688. levels = c(
  689. "GEO27.WT.UT",
  690. "GEO28.WT.UT",
  691. "08182.p90.TR",
  692. "13933.p60.TR",
  693. "13933.p60.UT",
  694. "16573.p90.TR",
  695. "16573.p90.UT",
  696. "18482.p60.TR",
  697. "18482.p60.UT",
  698. "19328.p60.TR",
  699. "19328.p60.UT"
  700. )
  701. )
  702. seurat_sct$treatment <- factor(
  703. x = seurat_sct$treatment,
  704. levels = c(
  705. "Untreated",
  706. "Cell_Treated"
  707. )
  708. )
  709. seurat_sct$batch <- factor(
  710. x = seurat_sct$batch,
  711. levels = c(
  712. "GSE209872",
  713. "08182",
  714. "13933",
  715. "16573",
  716. "18482",
  717. "19328"
  718. )
  719. )
  720. seurat_sct$time_point <- factor(
  721. x = seurat_sct$time_point,
  722. levels = c(
  723. "WT",
  724. "p60",
  725. "p90"
  726. )
  727. )
  728. seurat_sct$time_point_treatment <- factor(
  729. x = seurat_sct$time_point_treatment,
  730. levels = c(
  731. "WT_Untreated",
  732. "p60_Cell_Treated",
  733. "p60_Untreated",
  734. "p90_Cell_Treated",
  735. "p90_Untreated"
  736. )
  737. )
  738. seurat_sct$time_point_batch <- factor(
  739. x = seurat_sct$time_point_batch,
  740. levels = c(
  741. "WT_GSE209872",
  742. "p60_13933",
  743. "p60_18482",
  744. "p60_19328",
  745. "p90_08182",
  746. "p90_16573"
  747. )
  748. )
  749. seurat_sct$treatment_batch <- factor(
  750. x = seurat_sct$treatment_batch,
  751. levels = c(
  752. "Untreated_GSE209872",
  753. "Untreated_13933",
  754. "Untreated_18482",
  755. "Untreated_19328",
  756. "Untreated_16573",
  757. "Cell_Treated_13933",
  758. "Cell_Treated_18482",
  759. "Cell_Treated_19328",
  760. "Cell_Treated_08182",
  761. "Cell_Treated_16573"
  762. )
  763. )
  764. seurat_sct$time_point_treatment_batch <- factor(
  765. x = seurat_sct$time_point_treatment_batch,
  766. levels = c(
  767. "WT_Untreated_GSE209872",
  768. "p60_Untreated_13933",
  769. "p60_Untreated_18482",
  770. "p60_Untreated_19328",
  771. "p90_Untreated_16573",
  772. "p60_Cell_Treated_13933",
  773. "p60_Cell_Treated_18482",
  774. "p60_Cell_Treated_19328",
  775. "p90_Cell_Treated_08182",
  776. "p90_Cell_Treated_16573"
  777. )
  778. )
  779. rm(tenx1)
  780. #### SCTransform ####
  781. seurat_sct
  782. seurat_sct <- SCTransform(seurat_sct,
  783. ncells = 11848, #total cells / 10 (118478/10 = 11848)
  784. vars.to.regress = c("percent.mt","percent.ribo"),
  785. verbose = TRUE)
  786. #### PCA ####
  787. # this performs PCA on the seurat object
  788. seurat_sct <- RunPCA(seurat_sct, npcs = 50, verbose = TRUE)
  789. # make PC coordinate object a data frame
  790. xx.coord <- as.data.frame(seurat_sct@reductions$[email hidden])
  791. # make PC feature loadings object a data frame
  792. xx.gload <- as.data.frame(seurat_sct@reductions$[email hidden])
  793. # calculate eigenvalues for arrays
  794. # generate squares of all sample coordinates
  795. sq.xx.coord <- as.data.frame(xx.coord^2)
  796. # create empty list for eigenvalues first
  797. eig <- c()
  798. # calculate the eigenvalue for each PC in sq.xx.coord by taking the sqrt of the sum of squares
  799. for(i in 1:ncol(sq.xx.coord))
  800. eig[i] = sqrt(sum(sq.xx.coord[,i]))
  801. # calculate the total variance by adding up all the eigenvalues
  802. sum.eig <- sum(eig)
  803. # calculate the expected contribution of all PCs if they all contribute equally to the total variance
  804. expected.contribution <- sum.eig/(length(xx.coord)-1)
  805. # return the number of principal components with an eigenvalue greater than expected by equal variance
  806. meaningful.PCs <- sum(eig > expected.contribution)
  807. # create empty list for eigenvalue percentage
  808. eig.percent <- c()
  809. # calculate the percentage of the total variance by each PC eigenvalue
  810. for(i in 1:length(eig))
  811. eig.percent[i] = 100*eig[i]/sum.eig
  812. # sum of all eig.percent should total to 100
  813. sum(eig.percent)
  814. # create empty list for scree values
  815. scree <- c()
  816. # calculate a running total of variance contribution
  817. for(i in 1:length(eig))
  818. if(i == 1) scree[i] = eig.percent[i] else scree[i] = scree[i-1] + eig.percent[i]
  819. # create data frame for eigenvalue summaries
  820. eigenvalues <- data.frame("PC" = colnames(xx.coord), "eig" = eig, "percent" = eig.percent, "scree" = scree)
  821. # write csv for eigenvalues
  822. # write.csv(eigenvalues, file = paste0("./",date,"_",project,"_PCA_eigenvalues.csv"), row.names = F)
  823. # plot scree values
  824. plot(eigenvalues$percent, ylim = c(0,100), type = "S", xlab = "PC", ylab = "Percent of variance",
  825. main = paste0(date,"_",project," scree plot all samples PCA"))
  826. points(eigenvalues$scree, ylim = c(0,100), type = "p", pch = 16)
  827. lines(eigenvalues$scree)
  828. # add red line to indicate cut-off
  829. cut.off <- 100/(length(eig)-1)
  830. abline(h = cut.off, col = "red")
  831. # add blue line to indicate which PCs are meaningful and kept
  832. abline(v = meaningful.PCs, col = "blue")
  833. text(meaningful.PCs, cut.off, label = paste("cutoff PC",meaningful.PCs),
  834. adj = c(-0.1, -0.5))
  835. dev.copy(pdf, paste0("./",date,"_",project,"_scree_plot.pdf"))
  836. dev.off()
  837. rm(eigenvalues,sq.xx.coord,xx.coord,xx.gload,cut.off,
  838. eig,eig.percent,expected.contribution,i,scree,sum.eig)
  839. # meaningful.PCs <- 15
  840. #### Run UMAP and look at UMAP plots ####
  841. seurat_sct <- RunUMAP(seurat_sct, reduction = "pca", dims = 1:meaningful.PCs, verbose = TRUE)
  842. # update prefixed variable
  843. prefixPC <- paste0("./",date,"_",project,"_",meaningful.PCs,"PCs")
  844. ## UMAP plot by sample name ("orig.ident")
  845. DimPlot(seurat_sct,
  846. reduction = "umap",
  847. label = FALSE,
  848. pt.size = .25,
  849. group.by = "orig.ident",
  850. raster = F
  851. )
  852. hirestiff(paste0(prefixPC,"_UMAP_by_sample_hires.tiff"))
  853. lowrestiff(paste0(prefixPC,"_UMAP_by_sample_lowres.tiff"))
  854. DimPlot(seurat_sct,
  855. reduction = "umap",
  856. label = FALSE,
  857. pt.size = .25,
  858. group.by = "treatment",
  859. raster = F
  860. )
  861. hirestiff(paste0(prefixPC,"_UMAP_by_treatment_hires.tiff"))
  862. lowrestiff(paste0(prefixPC,"_UMAP_by_treatment_lowres.tiff"))
  863. DimPlot(seurat_sct,
  864. reduction = "umap",
  865. label = FALSE,
  866. pt.size = .25,
  867. split.by = "treatment",
  868. group.by = "treatment",
  869. raster = F
  870. )
  871. hirestiff(paste0(prefixPC,"_UMAP_split_by_treatment_hires.tiff"))
  872. lowrestiff(paste0(prefixPC,"_UMAP_split_by_treatment_lowres.tiff"))
  873. DimPlot(seurat_sct,
  874. reduction = "umap",
  875. label = FALSE,
  876. pt.size = .25,
  877. group.by = "batch",
  878. raster = F
  879. )
  880. hirestiff(paste0(prefixPC,"_UMAP_by_batch_hires.tiff"))
  881. lowrestiff(paste0(prefixPC,"_UMAP_by_batch_lowres.tiff"))
  882. DimPlot(seurat_sct,
  883. reduction = "umap",
  884. label = FALSE,
  885. pt.size = .25,
  886. group.by = "batch",
  887. split.by = "batch",
  888. raster = F
  889. )
  890. hirestiff(paste0(prefixPC,"_UMAP_split_by_batch_hires.tiff"))
  891. lowrestiff(paste0(prefixPC,"_UMAP_split_by_batch_lowres.tiff"))
  892. DimPlot(seurat_sct,
  893. reduction = "umap",
  894. label = FALSE,
  895. pt.size = .25,
  896. group.by = "time_point",
  897. raster = F
  898. )
  899. hirestiff(paste0(prefixPC,"_UMAP_by_time_point_hires.tiff"))
  900. lowrestiff(paste0(prefixPC,"_UMAP_by_time_point_lowres.tiff"))
  901. DimPlot(seurat_sct,
  902. reduction = "umap",
  903. label = FALSE,
  904. pt.size = .25,
  905. split.by = "time_point",
  906. group.by = "time_point",
  907. raster = F
  908. )
  909. hirestiff(paste0(prefixPC,"_UMAP_split_by_time_point_hires.tiff"))
  910. lowrestiff(paste0(prefixPC,"_UMAP_split_by_time_point_lowres.tiff"))
  911. # saveRDS(seurat_sct, file = paste0(prefixPC,"_seurat_integrated_preclustering.rds"))
  912. # seurat_sct <- read_rds(file = paste0(prefixPC,"_seurat_integrated_preclustering.rds"))
  913. #### (skip to integration) ####
  914. #### SCT Clustering and Resolution ####
  915. # DefaultAssay(seurat_sct) <- "SCT"
  916. # Determine the K-nearest neighbor graph
  917. seurat_sct <- FindNeighbors(object = seurat_sct, reduction = "pca", dims = 1:meaningful.PCs)
  918. # Determine the clusters
  919. seurat_sct <- FindClusters(object = seurat_sct,
  920. resolution = c(0.1,0.2,0.3,0.4,0.5))
  921. res <- "_res.0.1"
  922. ident_res <- paste0("SCT_snn",res)
  923. Idents(seurat_sct) <- ident_res
  924. DimPlot(seurat_sct, reduction = "umap", label = TRUE, label.size = 5, pt.size = 0.8) +
  925. NoLegend() +
  926. ggtitle(paste0(ident_res))
  927. #update prefix
  928. prefixPCres <- paste0(prefixPC,res)
  929. # Plot the UMAP
  930. DimPlot(seurat_sct, reduction = "umap", label = TRUE, label.size = 5, pt.size = 0.8) +
  931. NoLegend() +
  932. ggtitle(paste0(ident_res))
  933. hirestiff(paste0(prefixPCres,"_UMAP","_by_","cluster","_hires.tiff"))
  934. lowrestiff(paste0(prefixPCres,"_UMAP","_by_","cluster","_lowres.tiff"))
  935. # UMAP of cells in each cluster by treatment without cluster labels
  936. DimPlot(seurat_sct, reduction = "umap", label = FALSE, split.by = "treatment", pt.size = 0.8) + NoLegend()
  937. hirestiff(paste0(prefixPCres,"_UMAP","_by_","treatment","_no_labels","_hires.tiff"))
  938. lowrestiff(paste0(prefixPCres,"_UMAP","_by_","treatment","_no_labels","_lowres.tiff"))
  939. # UMAP of cells in each cluster by treatment with cluster labels
  940. DimPlot(seurat_sct, reduction = "umap", label = TRUE,
  941. split.by = "treatment", pt.size = 0.8, label.size = 5) + NoLegend()
  942. hirestiff(paste0(prefixPCres,"_UMAP","_by_","treatment","_with_clusters_labels","_hires.tiff"))
  943. lowrestiff(paste0(prefixPCres,"_UMAP","_by_","treatment","_with_clusters_labels","_lowres.tiff"))
  944. # UMAP of cells in each cluster by batch without cluster labels
  945. DimPlot(seurat_sct, reduction = "umap", label = FALSE, split.by = "batch", pt.size = 0.8) + NoLegend()
  946. hirestiff(paste0(prefixPCres,"_UMAP","_by_","batch","_no_labels","_hires.tiff"))
  947. lowrestiff(paste0(prefixPCres,"_UMAP","_by_","batch","_no_labels","_lowres.tiff"))
  948. # UMAP of cells in each cluster by batch with cluster labels
  949. DimPlot(seurat_sct, reduction = "umap", label = TRUE,
  950. split.by = "batch", pt.size = 0.8, label.size = 5) + NoLegend()
  951. hirestiff(paste0(prefixPCres,"_UMAP","_by_","batch","_with_clusters_labels","_hires.tiff"))
  952. lowrestiff(paste0(prefixPCres,"_UMAP","_by_","batch","_with_clusters_labels","_lowres.tiff"))
  953. # UMAP of cells in each cluster by time_point without cluster labels
  954. DimPlot(seurat_sct, reduction = "umap", label = FALSE, split.by = "time_point", pt.size = 0.8) + NoLegend()
  955. hirestiff(paste0(prefixPCres,"_UMAP","_by_","time_point","_no_labels","_hires.tiff"))
  956. lowrestiff(paste0(prefixPCres,"_UMAP","_by_","time_point","_no_labels","_lowres.tiff"))
  957. # UMAP of cells in each cluster by time_point with cluster labels
  958. DimPlot(seurat_sct, reduction = "umap", label = TRUE,
  959. split.by = "time_point", pt.size = 0.8, label.size = 5) + NoLegend()
  960. hirestiff(paste0(prefixPCres,"_UMAP","_by_","time_point","_with_clusters_labels","_hires.tiff"))
  961. lowrestiff(paste0(prefixPCres,"_UMAP","_by_","time_point","_with_clusters_labels","_lowres.tiff"))
  962. #### Extract number of cells per cluster per orig.ident ####
  963. n_cells <- FetchData(seurat_sct, vars = c("ident", "orig.ident")) %>%
  964. dplyr::count(ident, orig.ident) %>%
  965. tidyr::spread(ident, n)
  966. write.csv(n_cells, file = paste0(prefixPCres,"_cells_per_cluster.csv"))
  967. rm(n_cells)
  968. #### save RDS containing reduction and cluster idents ####
  969. saveRDS(seurat_sct, paste0(prefixPCres,"_seurat_after_clustering.rds"))
  970. # seurat_sct <- readRDS(file = paste0(prefixPCres,"_seurat_after_clustering.rds"))
  971. #### normalize rna slot ####
  972. # Select the RNA counts slot to be the default assay for visualization purposes
  973. DefaultAssay(seurat_sct) <- "RNA"
  974. # Normalize, find variable features, scale data
  975. seurat_sct <- NormalizeData(seurat_sct)
  976. seurat_sct <- FindVariableFeatures(seurat_sct)
  977. all.genes <- rownames(seurat_sct)
  978. seurat_sct <- ScaleData(seurat_sct, features = all.genes)
  979. # save object containing RNA normalized data
  980. saveRDS(seurat_sct, paste0(prefixPCres,"_seurat_after_RNAnorm.rds"))
  981. seurat_sct <- readRDS(file = paste0(prefixPCres,"_seurat_after_RNAnorm.rds"))
  982. # SaveH5Seurat(seurat_sct,
  983. # filename = paste0(prefixPCres,"_seurat_after_RNAnorm.h5Seurat"))
  984. #
  985. # seurat_sct_test <- LoadH5Seurat(file = paste0(prefixPCres,"_seurat_after_RNAnorm.h5Seurat"))
  986. #### ####
  987. #### Run integration (RPCA method) ####
  988. DefaultAssay(seurat_sct) <- "RNA"
  989. s.list <- SplitObject(seurat_sct, split.by = "orig.ident")
  990. # normalize data and find variable features
  991. s.list <- lapply(X = s.list, FUN = function(x) {
  992. x <- NormalizeData(x, verbose = FALSE)
  993. x <- FindVariableFeatures(x, verbose = FALSE)
  994. })
  995. # Next, select features for downstream integration, and run PCA on each
  996. # object in the list, which is required for running the alternative
  997. # reciprocal PCA workflow.
  998. features <- SelectIntegrationFeatures(object.list = s.list)
  999. s.list <- lapply(X = s.list, FUN = function(x) {
  1000. x <- ScaleData(x, features = features, verbose = FALSE)
  1001. x <- RunPCA(x, features = features, verbose = FALSE)
  1002. })
  1003. anchors <- FindIntegrationAnchors(object.list = s.list,
  1004. reduction = "rpca",
  1005. k.anchor = 10) # default is 5
  1006. s.integrated <- IntegrateData(anchorset = anchors, dims = 1:50)
  1007. s.integrated <- ScaleData(s.integrated, verbose = FALSE)
  1008. # saveRDS(s.integrated, file = paste0("./",date,"_",project,"_seurat_integrated.rds"))
  1009. # s.integrated <- read_rds(file = paste0("./",date,"_",project,"_seurat_integrated.rds"))
  1010. seurat_sct <- s.integrated
  1011. rm(s.list,anchors,s.integrated)
  1012. #### set factor levels ####
  1013. seurat_sct$orig.ident <- factor(
  1014. x = seurat_sct$orig.ident,
  1015. levels = c(
  1016. "GEO27.WT.UT",
  1017. "GEO28.WT.UT",
  1018. "08182.p90.TR",
  1019. "13933.p60.TR",
  1020. "13933.p60.UT",
  1021. "16573.p90.TR",
  1022. "16573.p90.UT",
  1023. "18482.p60.TR",
  1024. "18482.p60.UT",
  1025. "19328.p60.TR",
  1026. "19328.p60.UT"
  1027. )
  1028. )
  1029. seurat_sct$treatment <- factor(
  1030. x = seurat_sct$treatment,
  1031. levels = c(
  1032. "Untreated",
  1033. "Cell_Treated"
  1034. )
  1035. )
  1036. seurat_sct$batch <- factor(
  1037. x = seurat_sct$batch,
  1038. levels = c(
  1039. "GSE209872",
  1040. "08182",
  1041. "13933",
  1042. "16573",
  1043. "18482",
  1044. "19328"
  1045. )
  1046. )
  1047. seurat_sct$time_point <- factor(
  1048. x = seurat_sct$time_point,
  1049. levels = c(
  1050. "WT",
  1051. "p60",
  1052. "p90"
  1053. )
  1054. )
  1055. seurat_sct$time_point_treatment <- factor(
  1056. x = seurat_sct$time_point_treatment,
  1057. levels = c(
  1058. "WT_Untreated",
  1059. "p60_Cell_Treated",
  1060. "p60_Untreated",
  1061. "p90_Cell_Treated",
  1062. "p90_Untreated"
  1063. )
  1064. )
  1065. seurat_sct$time_point_batch <- factor(
  1066. x = seurat_sct$time_point_batch,
  1067. levels = c(
  1068. "WT_GSE209872",
  1069. "p60_13933",
  1070. "p60_18482",
  1071. "p60_19328",
  1072. "p90_08182",
  1073. "p90_16573"
  1074. )
  1075. )
  1076. seurat_sct$treatment_batch <- factor(
  1077. x = seurat_sct$treatment_batch,
  1078. levels = c(
  1079. "Untreated_GSE209872",
  1080. "Untreated_13933",
  1081. "Untreated_18482",
  1082. "Untreated_19328",
  1083. "Untreated_16573",
  1084. "Cell_Treated_13933",
  1085. "Cell_Treated_18482",
  1086. "Cell_Treated_19328",
  1087. "Cell_Treated_08182",
  1088. "Cell_Treated_16573"
  1089. )
  1090. )
  1091. seurat_sct$time_point_treatment_batch <- factor(
  1092. x = seurat_sct$time_point_treatment_batch,
  1093. levels = c(
  1094. "WT_Untreated_GSE209872",
  1095. "p60_Untreated_13933",
  1096. "p60_Untreated_18482",
  1097. "p60_Untreated_19328",
  1098. "p90_Untreated_16573",
  1099. "p60_Cell_Treated_13933",
  1100. "p60_Cell_Treated_18482",
  1101. "p60_Cell_Treated_19328",
  1102. "p90_Cell_Treated_08182",
  1103. "p90_Cell_Treated_16573"
  1104. )
  1105. )
  1106. #### update project variable to include integration ####
  1107. project <- paste0(project,"_int")
  1108. #### INT PCA ####
  1109. # this performs PCA on the seurat object
  1110. seurat_sct <- RunPCA(seurat_sct, npcs = 50, verbose = TRUE)
  1111. # make PC coordinate object a data frame
  1112. xx.coord <- as.data.frame(seurat_sct@reductions$[email hidden])
  1113. # make PC feature loadings object a data frame
  1114. xx.gload <- as.data.frame(seurat_sct@reductions$[email hidden])
  1115. # calculate eigenvalues for arrays
  1116. # generate squares of all sample coordinates
  1117. sq.xx.coord <- as.data.frame(xx.coord^2)
  1118. # create empty list for eigenvalues first
  1119. eig <- c()
  1120. # calculate the eigenvalue for each PC in sq.xx.coord by taking the sqrt of the sum of squares
  1121. for(i in 1:ncol(sq.xx.coord))
  1122. eig[i] = sqrt(sum(sq.xx.coord[,i]))
  1123. # calculate the total variance by adding up all the eigenvalues
  1124. sum.eig <- sum(eig)
  1125. # calculate the expected contribution of all PCs if they all contribute equally to the total variance
  1126. expected.contribution <- sum.eig/(length(xx.coord)-1)
  1127. # return the number of principal components with an eigenvalue greater than expected by equal variance
  1128. meaningful.PCs <- sum(eig > expected.contribution)
  1129. # create empty list for eigenvalue percentage
  1130. eig.percent <- c()
  1131. # calculate the percentage of the total variance by each PC eigenvalue
  1132. for(i in 1:length(eig))
  1133. eig.percent[i] = 100*eig[i]/sum.eig
  1134. # sum of all eig.percent should total to 100
  1135. sum(eig.percent)
  1136. # create empty list for scree values
  1137. scree <- c()
  1138. # calculate a running total of variance contribution
  1139. for(i in 1:length(eig))
  1140. if(i == 1) scree[i] = eig.percent[i] else scree[i] = scree[i-1] + eig.percent[i]
  1141. # create data frame for eigenvalue summaries
  1142. eigenvalues <- data.frame("PC" = colnames(xx.coord), "eig" = eig, "percent" = eig.percent, "scree" = scree)
  1143. # write csv for eigenvalues
  1144. # write.csv(eigenvalues, file = paste0("./",date,"_",project,"_PCA_eigenvalues.csv"), row.names = F)
  1145. # plot scree values
  1146. plot(eigenvalues$percent, ylim = c(0,100), type = "S", xlab = "PC", ylab = "Percent of variance",
  1147. main = paste0(date,"_",project," scree plot all samples PCA"))
  1148. points(eigenvalues$scree, ylim = c(0,100), type = "p", pch = 16)
  1149. lines(eigenvalues$scree)
  1150. # add red line to indicate cut-off
  1151. cut.off <- 100/(length(eig)-1)
  1152. abline(h = cut.off, col = "red")
  1153. # add blue line to indicate which PCs are meaningful and kept
  1154. abline(v = meaningful.PCs, col = "blue")
  1155. text(meaningful.PCs, cut.off, label = paste("cutoff PC",meaningful.PCs),
  1156. adj = c(-0.1, -0.5))
  1157. dev.copy(pdf, paste0("./",date,"_",project,"_scree_plot.pdf"))
  1158. dev.off()
  1159. rm(eigenvalues,sq.xx.coord,xx.coord,xx.gload,cut.off,
  1160. eig,eig.percent,expected.contribution,i,scree,sum.eig)
  1161. # meaningful.PCs <- 12
  1162. #### INT Run UMAP and look at UMAP plots ####
  1163. seurat_sct <- RunUMAP(seurat_sct,
  1164. reduction = "pca",
  1165. dims = 1:meaningful.PCs,
  1166. verbose = TRUE)
  1167. # update prefixed variable
  1168. prefixPC <- paste0("./",date,"_",project,"_",meaningful.PCs,"PCs")
  1169. ## UMAP plot by sample name ("orig.ident")
  1170. DimPlot(seurat_sct,
  1171. reduction = "umap",
  1172. label = FALSE,
  1173. pt.size = .25,
  1174. group.by = "orig.ident",
  1175. raster = F
  1176. )
  1177. hirestiff(paste0(prefixPC,"_UMAP_by_sample_hires.tiff"))
  1178. lowrestiff(paste0(prefixPC,"_UMAP_by_sample_lowres.tiff"))
  1179. DimPlot(seurat_sct,
  1180. reduction = "umap",
  1181. label = FALSE,
  1182. pt.size = .25,
  1183. group.by = "treatment",
  1184. raster = F
  1185. )
  1186. hirestiff(paste0(prefixPC,"_UMAP_by_treatment_hires.tiff"))
  1187. lowrestiff(paste0(prefixPC,"_UMAP_by_treatment_lowres.tiff"))
  1188. DimPlot(seurat_sct,
  1189. reduction = "umap",
  1190. label = FALSE,
  1191. pt.size = .25,
  1192. split.by = "treatment",
  1193. group.by = "treatment",
  1194. raster = F
  1195. )
  1196. hirestiff(paste0(prefixPC,"_UMAP_split_by_treatment_hires.tiff"))
  1197. lowrestiff(paste0(prefixPC,"_UMAP_split_by_treatment_lowres.tiff"))
  1198. DimPlot(seurat_sct,
  1199. reduction = "umap",
  1200. label = FALSE,
  1201. pt.size = .25,
  1202. group.by = "batch",
  1203. raster = F
  1204. )
  1205. hirestiff(paste0(prefixPC,"_UMAP_by_batch_hires.tiff"))
  1206. lowrestiff(paste0(prefixPC,"_UMAP_by_batch_lowres.tiff"))
  1207. DimPlot(seurat_sct,
  1208. reduction = "umap",
  1209. label = FALSE,
  1210. pt.size = .25,
  1211. group.by = "batch",
  1212. split.by = "batch",
  1213. raster = F
  1214. )
  1215. hirestiff(paste0(prefixPC,"_UMAP_split_by_batch_hires.tiff"))
  1216. lowrestiff(paste0(prefixPC,"_UMAP_split_by_batch_lowres.tiff"))
  1217. DimPlot(seurat_sct,
  1218. reduction = "umap",
  1219. label = FALSE,
  1220. pt.size = .25,
  1221. group.by = "time_point",
  1222. raster = F
  1223. )
  1224. hirestiff(paste0(prefixPC,"_UMAP_by_time_point_hires.tiff"))
  1225. lowrestiff(paste0(prefixPC,"_UMAP_by_time_point_lowres.tiff"))
  1226. DimPlot(seurat_sct,
  1227. reduction = "umap",
  1228. label = FALSE,
  1229. pt.size = .25,
  1230. split.by = "time_point",
  1231. group.by = "time_point",
  1232. raster = F
  1233. )
  1234. hirestiff(paste0(prefixPC,"_UMAP_split_by_time_point_hires.tiff"))
  1235. lowrestiff(paste0(prefixPC,"_UMAP_split_by_time_point_lowres.tiff"))
  1236. DimPlot(seurat_sct,
  1237. reduction = "umap",
  1238. label = FALSE,
  1239. pt.size = .25,
  1240. group.by = "time_point_treatment",
  1241. raster = F
  1242. )
  1243. hirestiff(paste0(prefixPC,"_UMAP_by_time_point_treatment_hires.tiff"))
  1244. lowrestiff(paste0(prefixPC,"_UMAP_by_time_point_treatment_lowres.tiff"))
  1245. DimPlot(seurat_sct,
  1246. reduction = "umap",
  1247. label = FALSE,
  1248. pt.size = .25,
  1249. split.by = "time_point_treatment",
  1250. group.by = "time_point_treatment",
  1251. raster = F
  1252. )
  1253. hirestiff(paste0(prefixPC,"_UMAP_split_by_time_point_treatment_hires.tiff"))
  1254. lowrestiff(paste0(prefixPC,"_UMAP_split_by_time_point_treatment_lowres.tiff"))
  1255. DimPlot(seurat_sct,
  1256. reduction = "umap",
  1257. label = FALSE,
  1258. pt.size = .25,
  1259. group.by = "time_point_batch",
  1260. raster = F
  1261. )
  1262. hirestiff(paste0(prefixPC,"_UMAP_by_time_point_batch_hires.tiff"))
  1263. lowrestiff(paste0(prefixPC,"_UMAP_by_time_point_batch_lowres.tiff"))
  1264. DimPlot(seurat_sct,
  1265. reduction = "umap",
  1266. label = FALSE,
  1267. pt.size = .25,
  1268. split.by = "time_point_batch",
  1269. group.by = "time_point_batch",
  1270. raster = F
  1271. )
  1272. hirestiff(paste0(prefixPC,"_UMAP_split_by_time_point_batch_hires.tiff"))
  1273. lowrestiff(paste0(prefixPC,"_UMAP_split_by_time_point_batch_lowres.tiff"))
  1274. DimPlot(seurat_sct,
  1275. reduction = "umap",
  1276. label = FALSE,
  1277. pt.size = .25,
  1278. group.by = "treatment_batch",
  1279. raster = F
  1280. )
  1281. hirestiff(paste0(prefixPC,"_UMAP_by_treatment_batch_hires.tiff"))
  1282. lowrestiff(paste0(prefixPC,"_UMAP_by_treatment_batch_lowres.tiff"))
  1283. DimPlot(seurat_sct,
  1284. reduction = "umap",
  1285. label = FALSE,
  1286. pt.size = .25,
  1287. split.by = "treatment_batch",
  1288. group.by = "treatment_batch",
  1289. raster = F
  1290. )
  1291. hirestiff(paste0(prefixPC,"_UMAP_split_by_treatment_batch_hires.tiff"))
  1292. lowrestiff(paste0(prefixPC,"_UMAP_split_by_treatment_batch_lowres.tiff"))
  1293. DimPlot(seurat_sct,
  1294. reduction = "umap",
  1295. label = FALSE,
  1296. pt.size = .25,
  1297. group.by = "time_point_treatment_batch",
  1298. raster = F
  1299. )
  1300. hirestiff(paste0(prefixPC,"_UMAP_by_time_point_treatment_batch_hires.tiff"))
  1301. lowrestiff(paste0(prefixPC,"_UMAP_by_time_point_treatment_batch_lowres.tiff"))
  1302. DimPlot(seurat_sct,
  1303. reduction = "umap",
  1304. label = FALSE,
  1305. pt.size = .25,
  1306. split.by = "time_point_treatment_batch",
  1307. group.by = "time_point_treatment_batch",
  1308. raster = F
  1309. )
  1310. hirestiff(paste0(prefixPC,"_UMAP_split_by_time_point_treatment_batch_hires.tiff"))
  1311. lowrestiff(paste0(prefixPC,"_UMAP_split_by_time_point_treatment_batch_lowres.tiff"))
  1312. # saveRDS(seurat_sct, file = paste0(prefixPC,"_seurat_integrated_preclustering.rds"))
  1313. # seurat_sct <- read_rds(file = paste0(prefixPC,"_seurat_integrated_preclustering.rds"))
  1314. #### INT Clustering and Resolution ####
  1315. # DefaultAssay(seurat_sct) <- "integrated"
  1316. # Determine the K-nearest neighbor graph
  1317. seurat_sct <- FindNeighbors(object = seurat_sct,
  1318. reduction = "pca",
  1319. dims = 1:meaningful.PCs)
  1320. # Determine the clusters
  1321. # seurat_sct <- FindClusters(object = seurat_sct,
  1322. # resolution = c(0.1,0.2,0.3,0.4,0.5))
  1323. seurat_sct <- FindClusters(object = seurat_sct,
  1324. resolution = c(0.5))
  1325. res <- "_res.0.5"
  1326. ident_res <- paste0("integrated_snn",res)
  1327. Idents(seurat_sct) <- ident_res
  1328. DimPlot(seurat_sct,
  1329. reduction = "umap",
  1330. label = TRUE,
  1331. label.size = 5,
  1332. pt.size = 0.8,
  1333. raster = F
  1334. ) +
  1335. NoLegend() +
  1336. ggtitle(paste0(ident_res))
  1337. # set cluster colors with Palo (makes sure adjacent colors are different)
  1338. palopal <- Palo::Palo(seurat_sct[["umap"]]@cell.embeddings,
  1339. as.character(Idents(seurat_sct)),
  1340. scales::hue_pal()(length(levels(seurat_sct))))
  1341. # sort these so they are in numeric order and can be transferred to new idents
  1342. sorted_palopal <- palopal[order(as.numeric(names(palopal)))]
  1343. # test resolution with Palo colors
  1344. DimPlot(seurat_sct,
  1345. reduction = "umap",
  1346. label = TRUE,
  1347. label.size = 5,
  1348. pt.size = 0.8,
  1349. cols = sorted_palopal,
  1350. raster = F
  1351. ) +
  1352. NoLegend() +
  1353. ggtitle(paste0(ident_res))
  1354. #update prefix
  1355. prefixPCres <- paste0(prefixPC,res)
  1356. # Plot the UMAP
  1357. DimPlot(seurat_sct,
  1358. reduction = "umap",
  1359. label = TRUE,
  1360. label.size = 5,
  1361. pt.size = 0.8,
  1362. cols = sorted_palopal,
  1363. raster = F
  1364. ) +
  1365. NoLegend() +
  1366. ggtitle(paste0(ident_res))
  1367. hirestiff(paste0(prefixPCres,"_UMAP","_by_","cluster","_hires.tiff"))
  1368. lowrestiff(paste0(prefixPCres,"_UMAP","_by_","cluster","_lowres.tiff"))
  1369. # UMAP of cells in each cluster by treatment without cluster labels
  1370. DimPlot(seurat_sct,
  1371. reduction = "umap",
  1372. label = FALSE,
  1373. split.by = "treatment",
  1374. pt.size = 0.8,
  1375. cols = sorted_palopal,
  1376. raster = F
  1377. ) +
  1378. NoLegend()
  1379. hirestiff(paste0(prefixPCres,"_UMAP","_by_","treatment",
  1380. "_no_labels","_hires.tiff"))
  1381. lowrestiff(paste0(prefixPCres,"_UMAP","_by_","treatment",
  1382. "_no_labels","_lowres.tiff"))
  1383. # UMAP of cells in each cluster by treatment with cluster labels
  1384. DimPlot(seurat_sct,
  1385. reduction = "umap",
  1386. label = TRUE,
  1387. split.by = "treatment",
  1388. pt.size = 0.8,
  1389. label.size = 5,
  1390. cols = sorted_palopal,
  1391. raster = F
  1392. ) +
  1393. NoLegend()
  1394. hirestiff(paste0(prefixPCres,"_UMAP","_by_","treatment",
  1395. "_with_clusters_labels","_hires.tiff"))
  1396. lowrestiff(paste0(prefixPCres,"_UMAP","_by_","treatment",
  1397. "_with_clusters_labels","_lowres.tiff"))
  1398. # UMAP of cells in each cluster by batch without cluster labels
  1399. DimPlot(seurat_sct,
  1400. reduction = "umap",
  1401. label = FALSE,
  1402. split.by = "batch",
  1403. pt.size = 0.8,
  1404. cols = sorted_palopal,
  1405. raster = F
  1406. ) +
  1407. NoLegend()
  1408. hirestiff(paste0(prefixPCres,"_UMAP","_by_","batch",
  1409. "_no_labels","_hires.tiff"))
  1410. lowrestiff(paste0(prefixPCres,"_UMAP","_by_","batch",
  1411. "_no_labels","_lowres.tiff"))
  1412. # UMAP of cells in each cluster by batch with cluster labels
  1413. DimPlot(seurat_sct,
  1414. reduction = "umap",
  1415. label = TRUE,
  1416. split.by = "batch",
  1417. pt.size = 0.8,
  1418. label.size = 3,
  1419. cols = sorted_palopal,
  1420. raster = F
  1421. ) +
  1422. NoLegend()
  1423. hirestiff(paste0(prefixPCres,"_UMAP","_by_","batch",
  1424. "_with_clusters_labels","_hires.tiff"))
  1425. lowrestiff(paste0(prefixPCres,"_UMAP","_by_","batch",
  1426. "_with_clusters_labels","_lowres.tiff"))
  1427. # UMAP of cells in each cluster by time_point without cluster labels
  1428. DimPlot(seurat_sct,
  1429. reduction = "umap",
  1430. label = FALSE,
  1431. split.by = "time_point",
  1432. pt.size = 0.8,
  1433. cols = sorted_palopal,
  1434. raster = F
  1435. ) +
  1436. NoLegend()
  1437. hirestiff(paste0(prefixPCres,"_UMAP","_by_","time_point",
  1438. "_no_labels","_hires.tiff"))
  1439. lowrestiff(paste0(prefixPCres,"_UMAP","_by_","time_point",
  1440. "_no_labels","_lowres.tiff"))
  1441. # UMAP of cells in each cluster by time_point with cluster labels
  1442. DimPlot(seurat_sct,
  1443. reduction = "umap",
  1444. label = TRUE,
  1445. split.by = "time_point",
  1446. pt.size = 0.8,
  1447. label.size = 5,
  1448. cols = sorted_palopal,
  1449. raster = F
  1450. ) +
  1451. NoLegend()
  1452. hirestiff(paste0(prefixPCres,"_UMAP","_by_","time_point",
  1453. "_with_clusters_labels","_hires.tiff"))
  1454. lowrestiff(paste0(prefixPCres,"_UMAP","_by_","time_point",
  1455. "_with_clusters_labels","_lowres.tiff"))
  1456. # UMAP of cells in each cluster by time_point without cluster labels
  1457. DimPlot(seurat_sct,
  1458. reduction = "umap",
  1459. label = FALSE,
  1460. split.by = "time_point_treatment",
  1461. pt.size = 0.8,
  1462. cols = sorted_palopal,
  1463. raster = F
  1464. ) +
  1465. NoLegend()
  1466. hirestiff(paste0(prefixPCres,"_UMAP","_by_","time_point_treatment",
  1467. "_no_labels","_hires.tiff"))
  1468. lowrestiff(paste0(prefixPCres,"_UMAP","_by_","time_point_treatment",
  1469. "_no_labels","_lowres.tiff"))
  1470. # UMAP of cells in each cluster by time_point with cluster labels
  1471. DimPlot(seurat_sct,
  1472. reduction = "umap",
  1473. label = TRUE,
  1474. split.by = "time_point_treatment",
  1475. pt.size = 0.8,
  1476. label.size = 5,
  1477. cols = sorted_palopal,
  1478. raster = F
  1479. ) +
  1480. NoLegend()
  1481. hirestiff(paste0(prefixPCres,"_UMAP","_by_","time_point_treatment",
  1482. "_with_clusters_labels","_hires.tiff"))
  1483. lowrestiff(paste0(prefixPCres,"_UMAP","_by_","time_point_treatment",
  1484. "_with_clusters_labels","_lowres.tiff"))
  1485. #### INT Extract number of cells per cluster per orig.ident ####
  1486. n_cells <- FetchData(seurat_sct, vars = c("ident", "orig.ident")) %>%
  1487. dplyr::count(ident, orig.ident) %>%
  1488. tidyr::spread(ident, n)
  1489. write.csv(n_cells, file = paste0(prefixPCres,"_cells_per_cluster.csv"))
  1490. rm(n_cells)
  1491. #### INT save RDS containing reduction and cluster idents ####
  1492. # saveRDS(seurat_sct, paste0(prefixPCres,"_seurat_after_clustering.rds"))
  1493. # seurat_sct <- readRDS(file = paste0(prefixPCres,"_seurat_after_clustering.rds"))
  1494. #### INT normalize rna slot ####
  1495. # Select the RNA counts slot to be the default assay for visualization purposes
  1496. DefaultAssay(seurat_sct) <- "RNA"
  1497. # Normalize, find variable features, scale data
  1498. seurat_sct <- NormalizeData(seurat_sct)
  1499. seurat_sct <- FindVariableFeatures(seurat_sct)
  1500. all.genes <- rownames(seurat_sct)
  1501. seurat_sct <- ScaleData(seurat_sct, features = all.genes)
  1502. # Export normalized counts
  1503. norm_counts <- GetAssayData(seurat_sct, slot = "data")
  1504. save(norm_counts, file = paste0(prefixPCres,"_normalized_counts_RNA_sparse_matrix.rdata"))
  1505. rm(norm_counts)
  1506. # save RDS containing RNA normalized data
  1507. # saveRDS(seurat_sct, paste0(prefixPCres,"_seurat_after_RNAnorm.rds"))
  1508. # seurat_sct <- readRDS(file = paste0(prefixPCres,"_seurat_after_RNAnorm.rds"))
  1509. # save RDS containing RNA normalized data AND CELLTYPE LABELS
  1510. # saveRDS(seurat_sct, paste0(prefixPCres,"_seurat_after_RNAnorm_CELLTYPES.rds"))
  1511. # seurat_sct <- readRDS(file = paste0(prefixPCres,"_seurat_after_RNAnorm_CELLTYPES.rds"))
  1512. #### INT Cluster QC ####
  1513. # Look at QC metrics for clustering by cell quality
  1514. VlnPlot(seurat_sct,
  1515. features = "nCount_RNA",
  1516. raster = F) +
  1517. NoLegend()
  1518. hirestiff(paste(prefixPCres,"vln","plot","QC","nCount_RNA","hires.tiff", sep = "_"))
  1519. lowrestiff(paste(prefixPCres,"vln","plot","QC","nCount_RNA","lowres.tiff", sep = "_"))
  1520. # Low count clusters: nothing obvious
  1521. VlnPlot(seurat_sct,
  1522. features = "nFeature_RNA",
  1523. raster = F) +
  1524. NoLegend()
  1525. hirestiff(paste(prefixPCres,"vln","plot","QC","nFeature_RNA","hires.tiff", sep = "_"))
  1526. lowrestiff(paste(prefixPCres,"vln","plot","QC","nFeature_RNA","lowres.tiff", sep = "_"))
  1527. # Low feature clusters: nothing obvious
  1528. VlnPlot(seurat_sct,
  1529. features = "percent.mt",
  1530. raster = F) +
  1531. NoLegend()
  1532. hirestiff(paste(prefixPCres,"vln","plot","QC","percent.mt","hires.tiff", sep = "_"))
  1533. lowrestiff(paste(prefixPCres,"vln","plot","QC","percent.mt","lowres.tiff", sep = "_"))
  1534. # High percent mito clusters: various
  1535. VlnPlot(seurat_sct,
  1536. features = "percent.ribo",
  1537. raster = F) +
  1538. NoLegend()
  1539. hirestiff(paste(prefixPCres,"vln","plot","QC","percent.ribo","hires.tiff", sep = "_"))
  1540. lowrestiff(paste(prefixPCres,"vln","plot","QC","percent.ribo","lowres.tiff", sep = "_"))
  1541. # High percent ribo clusters: varies
  1542. #### PLOTS ####
  1543. #### Test Plots ####
  1544. # apoptosis genes (bax and casp3 up, other two down)
  1545. FeaturePlot(seurat_sct,
  1546. reduction = "umap",
  1547. features = c("Bax","Casp3","Bnip3","Bcl2"),
  1548. order = TRUE,
  1549. min.cutoff = 'q10',
  1550. label = TRUE,
  1551. label.size = 3,
  1552. pt.size = 0.5,
  1553. raster = F)
  1554. # Plot the UMAP
  1555. DimPlot(seurat_sct,
  1556. reduction = "umap",
  1557. label = TRUE,
  1558. label.size = 5,
  1559. pt.size = 0.8) +
  1560. NoLegend()
  1561. # Plot the UMAP split by Treatment
  1562. DimPlot(seurat_sct,
  1563. reduction = "umap",
  1564. label = TRUE,
  1565. split.by = "treatment",
  1566. pt.size = 0.8) +
  1567. NoLegend()
  1568. Rods <- c("Rho","Gnat1","Nrl","Pde6a","Pde6b","Cngb1")
  1569. Rods1 <- c("Rho","Gnat1","Nrl")
  1570. Rods2 <- c("Pde6a","Pde6b","Cngb1")
  1571. Cones <- c("Arr3","Opn1sw","Gnat2","Pde6h")
  1572. Mueller_Glia <- c("Glul","Rlbp1")
  1573. Astrocytes <- c("Gfap","Aqp4","Gpr37")
  1574. Microglia <- c("Tyrobp","Cx3cr1","Tmem119","Clec7a")
  1575. Bipolar <- c("Scgn","Vsx1","Vsx2")
  1576. Retinal_Ganglion <- c("Rbpms","Pou4f1","Pou4f2")
  1577. Amacrine <- c("Calb1","Gad1","Gad2")
  1578. Horizontal <- c("Onecut2")
  1579. Pericytes <- c("Pecam1","Acta2")
  1580. Reticulocytes <- c("Hbb-bs")
  1581. default_FP <- function(obj,features){
  1582. FeaturePlot(obj,
  1583. reduction = "umap",
  1584. features = features,
  1585. order = TRUE,
  1586. # min.cutoff = 'q10',
  1587. label = TRUE,
  1588. label.size = 3,
  1589. pt.size = 0.5)
  1590. }
  1591. #### Genes from Dr. Wang ####
  1592. FeaturePlot(seurat_sct,
  1593. reduction = "umap",
  1594. features = c("Ifitm3","Socs3","Slpi","Ch25h"),
  1595. order = TRUE,
  1596. min.cutoff = 'q10',
  1597. label = TRUE,
  1598. label.size = 3,
  1599. pt.size = 0.5)
  1600. FeaturePlot(seurat_sct,
  1601. reduction = "umap",
  1602. features = c("Rlbp1", # Rlbp1 = Crlbp1
  1603. "Anxa1","Anxa2","Nfkbia"),
  1604. order = TRUE,
  1605. min.cutoff = 'q10',
  1606. label = TRUE,
  1607. label.size = 3,
  1608. pt.size = 0.5)
  1609. FeaturePlot(seurat_sct,
  1610. reduction = "umap",
  1611. features = c("Aif1", # Aif1 = Iba1
  1612. "Adgre1", # Adgre1 = F4/80
  1613. "Cd68"),
  1614. order = TRUE,
  1615. min.cutoff = 'q10',
  1616. label = TRUE,
  1617. label.size = 3,
  1618. pt.size = 0.5)
  1619. FeaturePlot(seurat_sct,
  1620. reduction = "umap",
  1621. features = c("Aifm1","Aif1"),
  1622. order = TRUE,
  1623. min.cutoff = 'q10',
  1624. label = TRUE,
  1625. label.size = 3,
  1626. pt.size = 0.5)
  1627. FeaturePlot(seurat_sct,
  1628. reduction = "umap",
  1629. features = c("Mydgf","Kdelr1","Kdelr2","Ern1"),
  1630. order = TRUE,
  1631. min.cutoff = 'q10',
  1632. label = TRUE,
  1633. label.size = 3,
  1634. pt.size = 0.5)
  1635. FeaturePlot(seurat_sct,
  1636. reduction = "umap",
  1637. features = c("Mydgf"),
  1638. order = TRUE,
  1639. min.cutoff = 'q10',
  1640. label = TRUE,
  1641. label.size = 3,
  1642. pt.size = 0.5,
  1643. split.by = "time_point_treatment")
  1644. FeaturePlot(seurat_sct,
  1645. reduction = "umap",
  1646. features = c("Kdelr1"),
  1647. order = TRUE,
  1648. min.cutoff = 'q10',
  1649. label = TRUE,
  1650. label.size = 3,
  1651. pt.size = 0.5,
  1652. split.by = "time_point_treatment")
  1653. FeaturePlot(seurat_sct,
  1654. reduction = "umap",
  1655. features = c("Kdelr2"),
  1656. order = TRUE,
  1657. min.cutoff = 'q10',
  1658. label = TRUE,
  1659. label.size = 3,
  1660. pt.size = 0.5,
  1661. split.by = "time_point_treatment")
  1662. FeaturePlot(seurat_sct,
  1663. reduction = "umap",
  1664. features = c("Ern1"),
  1665. order = TRUE,
  1666. min.cutoff = 'q10',
  1667. label = TRUE,
  1668. label.size = 3,
  1669. pt.size = 0.5,
  1670. split.by = "time_point_treatment")
  1671. FeaturePlot(seurat_sct,
  1672. reduction = "umap",
  1673. features = c("Manf"),
  1674. order = TRUE,
  1675. min.cutoff = 'q10',
  1676. label = TRUE,
  1677. label.size = 3,
  1678. pt.size = 0.5,
  1679. split.by = "time_point_treatment")
  1680. VlnPlot(seurat_sct,
  1681. idents = c("ROD","CONE"),
  1682. features = c("Mydgf","Kdelr1","Kdelr2","Ern1","Manf"),
  1683. split.by = "time_point_treatment",
  1684. stack = T,
  1685. flip = T)
  1686. FeaturePlot(seurat_sct,
  1687. reduction = "umap",
  1688. features = c("Creb1",
  1689. "Crem"),
  1690. order = TRUE,
  1691. min.cutoff = 'q10',
  1692. label = TRUE,
  1693. label.size = 3,
  1694. pt.size = 0.5)
  1695. FeaturePlot(seurat_sct,
  1696. reduction = "umap",
  1697. features = c("Tmem119","P2ry13","P2ry12","Siglech"),
  1698. order = TRUE,
  1699. min.cutoff = 'q10',
  1700. label = TRUE,
  1701. label.size = 3,
  1702. pt.size = 0.5)
  1703. #### retina genes from Saba SCT ####
  1704. # Rod Photoreceptors
  1705. # Cluster 7
  1706. VlnPlot(seurat_sct,
  1707. features = c("Rho","Gnat1","Nrl",
  1708. "Pde6a","Pde6b","Cngb1"),
  1709. stack = TRUE,
  1710. flip = TRUE) +
  1711. NoLegend() +
  1712. ggtitle("Rod Photoreceptors")
  1713. hirestiff(paste(prefixPCres,"VLN","Rod","Photoreceptors","hires.tiff", sep = "_"))
  1714. lowrestiff(paste(prefixPCres,"VLN","Rod","Photoreceptors","lowres.tiff", sep = "_"))
  1715. # Cone Photoreceptors
  1716. # Cluster 8
  1717. VlnPlot(seurat_sct,
  1718. features = c("Arr3","Opn1sw","Gnat2","Pde6h"),
  1719. stack = TRUE,
  1720. flip = TRUE) +
  1721. NoLegend() +
  1722. ggtitle("Cone Photoreceptors")
  1723. hirestiff(paste(prefixPCres,"VLN","Cone","Photoreceptors","hires.tiff", sep = "_"))
  1724. lowrestiff(paste(prefixPCres,"VLN","Cone","Photoreceptors","lowres.tiff", sep = "_"))
  1725. # Muller Glia
  1726. # Clusters 4, 10, 12
  1727. VlnPlot(seurat_sct,
  1728. features = c("Glul","Rlbp1","Nes","Vim"),
  1729. stack = TRUE,
  1730. flip = TRUE) +
  1731. NoLegend() +
  1732. ggtitle("Muller Glia")
  1733. hirestiff(paste(prefixPCres,"VLN","Muller","Glia","hires.tiff", sep = "_"))
  1734. lowrestiff(paste(prefixPCres,"VLN","Muller","Glia","lowres.tiff", sep = "_"))
  1735. # Retinal Astrocytes
  1736. # Clusters 4, 10, 12
  1737. VlnPlot(seurat_sct,
  1738. features = c("Gfap","Aqp4","Gpr37"),
  1739. stack = TRUE,
  1740. flip = TRUE) +
  1741. NoLegend() +
  1742. ggtitle("Retinal Astrocytes")
  1743. hirestiff(paste(prefixPCres,"VLN","Retinal","Astrocytes","hires.tiff", sep = "_"))
  1744. lowrestiff(paste(prefixPCres,"VLN","Retinal","Astrocytes","lowres.tiff", sep = "_"))
  1745. # Microglia
  1746. # Clusters 3, 13, 16
  1747. VlnPlot(seurat_sct,
  1748. features = c("Tyrobp","Cx3cr1","Tmem119"),
  1749. stack = TRUE,
  1750. flip = TRUE) +
  1751. NoLegend() +
  1752. ggtitle("Microglia")
  1753. hirestiff(paste(prefixPCres,"VLN","Microglia","hires.tiff", sep = "_"))
  1754. lowrestiff(paste(prefixPCres,"VLN","Microglia","lowres.tiff", sep = "_"))
  1755. # Bipolar Cells
  1756. # Clusters 0, 1, (4), 6, 9, (10), ?11 ,(12,14)
  1757. VlnPlot(seurat_sct,
  1758. features = c("Scgn","Vsx1","Vsx2"),
  1759. stack = TRUE,
  1760. flip = TRUE) +
  1761. NoLegend() +
  1762. ggtitle("Bipolar Cells")
  1763. hirestiff(paste(prefixPCres,"VLN","Bipolar","Cells","hires.tiff", sep = "_"))
  1764. lowrestiff(paste(prefixPCres,"VLN","Bipolar","Cells","lowres.tiff", sep = "_"))
  1765. # Retinal Ganglion Cells
  1766. # Clusters 2, 5, 13, 14, 16
  1767. VlnPlot(seurat_sct,
  1768. features = c("Rbpms","Pou4f1","Pou4f2"),
  1769. stack = TRUE,
  1770. flip = TRUE) +
  1771. NoLegend() +
  1772. ggtitle("Retinal Ganglion Cells")
  1773. hirestiff(paste(prefixPCres,"VLN","Retinal","Ganglion","Cells","hires.tiff", sep = "_"))
  1774. lowrestiff(paste(prefixPCres,"VLN","Retinal","Ganglion","Cells","lowres.tiff", sep = "_"))
  1775. # Amacrine Cells
  1776. # Part of Cluster 6
  1777. VlnPlot(seurat_sct,
  1778. features = c("Calb1","Gad1","Gad2"),
  1779. stack = TRUE,
  1780. flip = TRUE) +
  1781. NoLegend() +
  1782. ggtitle("Amacrine Cells")
  1783. hirestiff(paste(prefixPCres,"VLN","Amacrine","Cells","hires.tiff", sep = "_"))
  1784. lowrestiff(paste(prefixPCres,"VLN","Amacrine","Cells","lowres.tiff", sep = "_"))
  1785. # Horizontal Cells
  1786. # Cluster
  1787. VlnPlot(seurat_sct,
  1788. features = c("Onecut2"),
  1789. # stack = TRUE,
  1790. flip = TRUE,
  1791. pt.size = 0) +
  1792. NoLegend() +
  1793. ggtitle("Horizontal Cells")
  1794. hirestiff(paste(prefixPCres,"VLN","Horizontal","Cells","hires.tiff", sep = "_"))
  1795. lowrestiff(paste(prefixPCres,"VLN","Horizontal","Cells","lowres.tiff", sep = "_"))
  1796. # Pericytes
  1797. # Clusters 2,16
  1798. VlnPlot(seurat_sct,
  1799. features = c(#"Pecam1",
  1800. "Acta2"),
  1801. # stack = TRUE,
  1802. flip = TRUE,
  1803. pt.size = 0) +
  1804. NoLegend() #+ ggtitle("Pericytes")
  1805. hirestiff(paste(prefixPCres,"VLN","Pericytes","hires.tiff", sep = "_"))
  1806. lowrestiff(paste(prefixPCres,"VLN","Pericytes","lowres.tiff", sep = "_"))
  1807. # Reticulocytes
  1808. # Cluster 15
  1809. VlnPlot(seurat_sct,
  1810. features = c(#"Pecam1",
  1811. "Hbb-bs"),
  1812. # stack = TRUE,
  1813. flip = TRUE,
  1814. pt.size = 0) +
  1815. NoLegend() #+ ggtitle("Pericytes")
  1816. hirestiff(paste(prefixPCres,"VLN","Pericytes","hires.tiff", sep = "_"))
  1817. lowrestiff(paste(prefixPCres,"VLN","Pericytes","lowres.tiff", sep = "_"))
  1818. #### retina genes from Saba Integrated ####
  1819. VlnPlot(seurat_sct,
  1820. features = c("Nfe2l2"),
  1821. # stack = TRUE,
  1822. flip = TRUE) +
  1823. NoLegend()
  1824. default_FP(seurat_sct,c("Nfe2l2"))
  1825. VlnPlot(seurat_sct,
  1826. features = c(RPEpi,"Mertk"),
  1827. stack = TRUE,
  1828. flip = TRUE) +
  1829. NoLegend()
  1830. # Rod Photoreceptors
  1831. # Cluster 8
  1832. VlnPlot(seurat_sct,
  1833. features = Rods,
  1834. stack = TRUE,
  1835. flip = TRUE) +
  1836. NoLegend() +
  1837. ggtitle("Rod Photoreceptors")
  1838. hirestiff(paste(prefixPCres,"VLN","Rod","Photoreceptors","hires.tiff", sep = "_"))
  1839. lowrestiff(paste(prefixPCres,"VLN","Rod","Photoreceptors","lowres.tiff", sep = "_"))
  1840. default_FP(seurat_sct,Rods1)
  1841. hirestiff(paste(prefixPCres,"UMAP","Rod","genes1","hires.tiff", sep = "_"))
  1842. lowrestiff(paste(prefixPCres,"UMAP","Rod","genes1","lowres.tiff", sep = "_"))
  1843. default_FP(seurat_sct,Rods2)
  1844. hirestiff(paste(prefixPCres,"UMAP","Rod","genes2","hires.tiff", sep = "_"))
  1845. lowrestiff(paste(prefixPCres,"UMAP","Rod","genes2","lowres.tiff", sep = "_"))
  1846. default_FP(seurat_sct,"Grm6")
  1847. default_FP(seurat_sct,c("Pou4f1","Pou4f2","Pou4f3"))
  1848. VlnPlot(seurat_sct,
  1849. features = c("Onecut1","Onecut2"),
  1850. stack = TRUE,
  1851. flip = TRUE) +
  1852. NoLegend()
  1853. # Cone Photoreceptors
  1854. # Cluster 9
  1855. VlnPlot(seurat_sct,
  1856. features = Cones,
  1857. stack = TRUE,
  1858. flip = TRUE) +
  1859. NoLegend() +
  1860. ggtitle("Cone Photoreceptors")
  1861. hirestiff(paste(prefixPCres,"VLN","Cone","Photoreceptors","hires.tiff", sep = "_"))
  1862. lowrestiff(paste(prefixPCres,"VLN","Cone","Photoreceptors","lowres.tiff", sep = "_"))
  1863. default_FP(seurat_sct,Cones)
  1864. hirestiff(paste(prefixPCres,"UMAP","Cone","genes","hires.tiff", sep = "_"))
  1865. lowrestiff(paste(prefixPCres,"UMAP","Cone","genes","lowres.tiff", sep = "_"))
  1866. FeaturePlot(seurat_sct,
  1867. reduction = "umap",
  1868. features = Cones,
  1869. order = TRUE,
  1870. min.cutoff = 'q10',
  1871. label = TRUE,
  1872. label.size = 3,
  1873. pt.size = 0.5)
  1874. # Muller Glia
  1875. # Clusters 10,11,14,15,16,20,24,27,29
  1876. VlnPlot(seurat_sct,
  1877. features = c(Mueller_Glia,"Gfap","Aqp4","S100b"),
  1878. stack = TRUE,
  1879. flip = TRUE) +
  1880. NoLegend() +
  1881. ggtitle("Muller Glia")
  1882. hirestiff(paste(prefixPCres,"VLN","Muller","Glia","hires.tiff", sep = "_"))
  1883. lowrestiff(paste(prefixPCres,"VLN","Muller","Glia","lowres.tiff", sep = "_"))
  1884. default_FP(seurat_sct,Mueller_Glia)
  1885. hirestiff(paste(prefixPCres,"UMAP","Mueller_Glia","genes","hires.tiff", sep = "_"))
  1886. lowrestiff(paste(prefixPCres,"UMAP","Mueller_Glia","genes","lowres.tiff", sep = "_"))
  1887. Macroglia <- c("Apoe","Slc1a3","Trpm3","Glul","Clu" )
  1888. FeaturePlot(seurat_sct,
  1889. reduction = "umap",
  1890. features = Macroglia,
  1891. order = TRUE,
  1892. min.cutoff = 'q10',
  1893. label = TRUE,
  1894. label.size = 3,
  1895. pt.size = 0.5)
  1896. FeaturePlot(seurat_sct,
  1897. reduction = "umap",
  1898. features = Mueller_Glia,
  1899. order = TRUE,
  1900. min.cutoff = 'q10',
  1901. label = TRUE,
  1902. label.size = 3,
  1903. pt.size = 0.5)
  1904. FeaturePlot(seurat_sct,
  1905. reduction = "umap",
  1906. features = c("Glul"),
  1907. order = TRUE,
  1908. min.cutoff = 'q10',
  1909. label = TRUE,
  1910. label.size = 3,
  1911. pt.size = 0.5,
  1912. split.by = "time_point")
  1913. FeaturePlot(TRseurat,
  1914. reduction = "umap",
  1915. features = c("Glul"),
  1916. order = TRUE,
  1917. min.cutoff = 'q10',
  1918. label = TRUE,
  1919. label.size = 3,
  1920. pt.size = 0.5,
  1921. split.by = "time_point")
  1922. FeaturePlot(UTseurat,
  1923. reduction = "umap",
  1924. features = c("Glul"),
  1925. order = TRUE,
  1926. min.cutoff = 'q10',
  1927. label = TRUE,
  1928. label.size = 3,
  1929. pt.size = 0.5,
  1930. split.by = "time_point")
  1931. # Retinal Astrocytes
  1932. # Clusters 10,11,14,15,16,20,24,27,29
  1933. VlnPlot(seurat_sct,
  1934. features = Astrocytes,
  1935. stack = TRUE,
  1936. flip = TRUE) +
  1937. NoLegend() +
  1938. ggtitle("Retinal Astrocytes")
  1939. hirestiff(paste(prefixPCres,"VLN","Retinal","Astrocytes","hires.tiff", sep = "_"))
  1940. lowrestiff(paste(prefixPCres,"VLN","Retinal","Astrocytes","lowres.tiff", sep = "_"))
  1941. default_FP(seurat_sct,Astrocytes)
  1942. hirestiff(paste(prefixPCres,"UMAP","Astrocytes","genes","hires.tiff", sep = "_"))
  1943. lowrestiff(paste(prefixPCres,"UMAP","Astrocytes","genes","lowres.tiff", sep = "_"))
  1944. # Microglia
  1945. # Clusters 5,7,13,21,22,26,28,29
  1946. VlnPlot(seurat_sct,
  1947. features = Microglia,
  1948. stack = TRUE,
  1949. flip = TRUE) +
  1950. NoLegend() +
  1951. ggtitle("Microglia")
  1952. hirestiff(paste(prefixPCres,"VLN","Microglia","hires.tiff", sep = "_"))
  1953. lowrestiff(paste(prefixPCres,"VLN","Microglia","lowres.tiff", sep = "_"))
  1954. default_FP(seurat_sct,Microglia)
  1955. hirestiff(paste(prefixPCres,"UMAP","Microglia","genes","hires.tiff", sep = "_"))
  1956. lowrestiff(paste(prefixPCres,"UMAP","Microglia","genes","lowres.tiff", sep = "_"))
  1957. # Bipolar Cells
  1958. # Clusters (0),1,2,3
  1959. VlnPlot(seurat_sct,
  1960. features = c(Bipolar,"Snap25","Neto1"),
  1961. stack = TRUE,
  1962. flip = TRUE) +
  1963. NoLegend() +
  1964. ggtitle("Bipolar Cells")
  1965. hirestiff(paste(prefixPCres,"VLN","Bipolar","Cells","hires.tiff", sep = "_"))
  1966. lowrestiff(paste(prefixPCres,"VLN","Bipolar","Cells","lowres.tiff", sep = "_"))
  1967. default_FP(seurat_sct,Bipolar)
  1968. hirestiff(paste(prefixPCres,"UMAP","Bipolar","genes","hires.tiff", sep = "_"))
  1969. lowrestiff(paste(prefixPCres,"UMAP","Bipolar","genes","lowres.tiff", sep = "_"))
  1970. # Retinal Ganglion Cells
  1971. # Clusters 4,6,12,18,19,21,24,25,26,28
  1972. VlnPlot(seurat_sct,
  1973. features = c(Retinal_Ganglion,
  1974. "Slc17a6","Pou4f3","Cacna1c"),
  1975. stack = TRUE,
  1976. flip = TRUE,
  1977. raster = F) +
  1978. NoLegend() +
  1979. ggtitle("Retinal Ganglion Cells")
  1980. hirestiff(paste(prefixPCres,"VLN","Retinal","Ganglion","Cells","hires.tiff", sep = "_"))
  1981. lowrestiff(paste(prefixPCres,"VLN","Retinal","Ganglion","Cells","lowres.tiff", sep = "_"))
  1982. default_FP(seurat_sct,Retinal_Ganglion)
  1983. hirestiff(paste(prefixPCres,"UMAP","Retinal_Ganglion","genes","hires.tiff", sep = "_"))
  1984. lowrestiff(paste(prefixPCres,"UMAP","Retinal_Ganglion","genes","lowres.tiff", sep = "_"))
  1985. FeaturePlot(seurat_sct,
  1986. reduction = "umap",
  1987. features = c(Retinal_Ganglion,
  1988. "Slc17a6","Pou4f3"),
  1989. order = TRUE,
  1990. min.cutoff = 'q10',
  1991. label = TRUE,
  1992. label.size = 3,
  1993. pt.size = 0.5,
  1994. raster = F)
  1995. # Amacrine Cells
  1996. # Cluster 17
  1997. VlnPlot(seurat_sct,
  1998. features = Amacrine,
  1999. stack = TRUE,
  2000. flip = TRUE) +
  2001. NoLegend() +
  2002. ggtitle("Amacrine Cells")
  2003. hirestiff(paste(prefixPCres,"VLN","Amacrine","Cells","hires.tiff", sep = "_"))
  2004. lowrestiff(paste(prefixPCres,"VLN","Amacrine","Cells","lowres.tiff", sep = "_"))
  2005. default_FP(seurat_sct,Amacrine)
  2006. hirestiff(paste(prefixPCres,"UMAP","Amacrine","genes","hires.tiff", sep = "_"))
  2007. lowrestiff(paste(prefixPCres,"UMAP","Amacrine","genes","lowres.tiff", sep = "_"))
  2008. # Horizontal Cells
  2009. # Clusters ?
  2010. VlnPlot(seurat_sct,
  2011. features = c(Horizontal,"Onecut1","Gfap"),
  2012. stack = TRUE,
  2013. flip = TRUE,
  2014. pt.size = 0) +
  2015. NoLegend() +
  2016. ggtitle("Horizontal Cells")
  2017. hirestiff(paste(prefixPCres,"VLN","Horizontal","Cells","hires.tiff", sep = "_"))
  2018. lowrestiff(paste(prefixPCres,"VLN","Horizontal","Cells","lowres.tiff", sep = "_"))
  2019. default_FP(seurat_sct,Horizontal)
  2020. hirestiff(paste(prefixPCres,"UMAP","Horizontal","genes","hires.tiff", sep = "_"))
  2021. lowrestiff(paste(prefixPCres,"UMAP","Horizontal","genes","lowres.tiff", sep = "_"))
  2022. # Pericytes
  2023. # Cluster 4,12,18,24,25,26
  2024. VlnPlot(seurat_sct,
  2025. features = c(Pericytes,"Cacna1c"),
  2026. stack = TRUE,
  2027. flip = TRUE,
  2028. pt.size = 0) +
  2029. NoLegend() +
  2030. ggtitle("Pericytes")
  2031. hirestiff(paste(prefixPCres,"VLN","Pericytes","hires.tiff", sep = "_"))
  2032. lowrestiff(paste(prefixPCres,"VLN","Pericytes","lowres.tiff", sep = "_"))
  2033. default_FP(seurat_sct,Pericytes)
  2034. hirestiff(paste(prefixPCres,"UMAP","Pericytes","genes","hires.tiff", sep = "_"))
  2035. lowrestiff(paste(prefixPCres,"UMAP","Pericytes","genes","lowres.tiff", sep = "_"))
  2036. # Reticulocytes 23
  2037. VlnPlot(seurat_sct,
  2038. features = c(Reticulocytes,"Gfap"),
  2039. stack = TRUE,
  2040. flip = TRUE,
  2041. pt.size = 0) +
  2042. NoLegend() +
  2043. ggtitle("Reticulocytes")
  2044. hirestiff(paste(prefixPCres,"VLN","Reticulocytes","hires.tiff", sep = "_"))
  2045. lowrestiff(paste(prefixPCres,"VLN","Reticulocytes","lowres.tiff", sep = "_"))
  2046. default_FP(seurat_sct,Reticulocytes)
  2047. hirestiff(paste(prefixPCres,"UMAP","Reticulocytes","genes","hires.tiff", sep = "_"))
  2048. lowrestiff(paste(prefixPCres,"UMAP","Reticulocytes","genes","lowres.tiff", sep = "_"))
  2049. #### retinal genes ####
  2050. Rods <- c("Rho","Gnat1","Nrl","Pde6a","Pde6b","Cngb1")
  2051. Rods1 <- c("Rho","Gnat1","Nrl")
  2052. Rods2 <- c("Pde6a","Pde6b","Cngb1")
  2053. Cones <- c("Arr3","Opn1sw","Gnat2","Pde6h")
  2054. Mueller_Glia <- c("Glul","Rlbp1")
  2055. Astrocytes <- c("Gfap","Aqp4","Gpr37")
  2056. Microglia <- c("Tyrobp","Cx3cr1","Tmem119")
  2057. Bipolar <- c("Scgn","Vsx1","Vsx2")
  2058. Retinal_Ganglion <- c("Rbpms","Pou4f1","Pou4f2")
  2059. Amacrine <- c("Calb1","Gad1","Gad2")
  2060. Horizontal <- c("Onecut2")
  2061. Pericytes <- c("Pecam1","Acta2")
  2062. Reticulocytes <- c("Hbb-bs")
  2063. RPEpi <- c("Mitf","Tjp1","Rpe65","Rlbp1","Best1")
  2064. retina_genes <- c(Rods,Cones,Mueller_Glia,Astrocytes,
  2065. Microglia,Bipolar,Retinal_Ganglion,
  2066. Amacrine,Horizontal,Reticulocytes)
  2067. FeaturePlot(seurat_sct,
  2068. reduction = "umap",
  2069. features = c(Horizontal,"Lhx1","Isl1","Prox1"),
  2070. order = TRUE,
  2071. min.cutoff = 'q10',
  2072. label = TRUE,
  2073. label.size = 3,
  2074. pt.size = 0.5)
  2075. FeaturePlot(seurat_sct,
  2076. reduction = "umap",
  2077. features = c("Ntrk2"),
  2078. order = TRUE,
  2079. min.cutoff = 'q10',
  2080. label = TRUE,
  2081. label.size = 3,
  2082. pt.size = 0.5)
  2083. #### retinal genes from Chen et al 2022 ####
  2084. Rods <- c("Rho","Nr2e3","Nrl","Pdc","Rp1")
  2085. Cones <- c("Opn1sw","Opn1mw","Pde6h","Arr3","Gnat2")
  2086. Mueller_Glia <- c("Zfp36l1","Dbi","Apoe","Slc1a3","Sparc")
  2087. Bipolar <- c("Pcp2","Isl1","Grm6","Trnp1")
  2088. Amacrine <- c("C1ql1","Snhg11","Tfap2b","Pcsk1n")
  2089. Horizontal <- c("Slc4a3","Calb1","Septin4","Tpm3")
  2090. Microglia <- c("Ctsd","Ccl4","C1qb","C1qc")
  2091. Vascular <- c("Trpm1","Igfbp7")
  2092. # Astrocytes <- c("Gfap","Aqp4","Gpr37")
  2093. # Retinal_Ganglion <- c("Rbpms","Pou4f1","Pou4f2")
  2094. # Pericytes <- c("Pecam1","Acta2")
  2095. # Reticulocytes <- c("Hbb-bs")
  2096. retina_genes <- c(Rods,Cones,Mueller_Glia,Bipolar,
  2097. Amacrine,Horizontal,Microglia,Vascular)
  2098. Idents(seurat_sct) <- ident_res
  2099. Idents(seurat_sct) <- "Cell.Type"
  2100. Idents(seurat_sct) <- "Cluster.Type"
  2101. VlnPlot(seurat_sct,
  2102. features = c("Olig2","Apc","Cnp",
  2103. "Nes","Fabp7","Pax6"),
  2104. stack = T,
  2105. flip = T) + NoLegend()
  2106. VlnPlot(seurat_sct,
  2107. features = c("Casp3","Casp6","Bax",
  2108. "Bcl2","Fas","Faslg","Tnfrsf1a"),
  2109. stack = T,
  2110. flip = T) + NoLegend()
  2111. VlnPlot(seurat_sct,
  2112. features = Rods,
  2113. stack = T,
  2114. flip = T) + NoLegend()
  2115. VlnPlot(seurat_sct,
  2116. features = Cones,
  2117. stack = T,
  2118. flip = T) + NoLegend()
  2119. VlnPlot(seurat_sct,
  2120. features = Mueller_Glia,
  2121. stack = T,
  2122. flip = T) + NoLegend()
  2123. VlnPlot(seurat_sct,
  2124. features = Retinal_Ganglion,
  2125. stack = T,
  2126. flip = T) + NoLegend()
  2127. VlnPlot(seurat_sct,
  2128. features = c("Glul","Rlbp1","Gfap","S100b"),
  2129. stack = T,
  2130. flip = T) + NoLegend()
  2131. VlnPlot(seurat_sct,
  2132. features = Bipolar,
  2133. stack = T,
  2134. flip = T) + NoLegend()
  2135. VlnPlot(seurat_sct,
  2136. features = c("Isl1","Grm6","Scgn","Vsx2","Prdm8",
  2137. "Prkca","Pcp2","Bhlhe23","Cabp5","Car8",
  2138. "Trpm1","Slc5a8","Cacna2d3","Adamts5"),
  2139. stack = T,
  2140. flip = T) + NoLegend()
  2141. VlnPlot(seurat_sct,
  2142. features = c("Gsg1","Tmem215","Trnp1"),
  2143. stack = T,
  2144. flip = T) + NoLegend()
  2145. VlnPlot(seurat_sct,
  2146. features = Amacrine,
  2147. stack = T,
  2148. flip = T) + NoLegend()
  2149. VlnPlot(seurat_sct,
  2150. features = c("Snhg11","Tfap2b","Gad1","Gad2"),
  2151. stack = T,
  2152. flip = T) + NoLegend()
  2153. VlnPlot(seurat_sct,
  2154. features = Horizontal,
  2155. stack = T,
  2156. flip = T) + NoLegend()
  2157. VlnPlot(seurat_sct,
  2158. features = Microglia,
  2159. stack = T,
  2160. flip = T) + NoLegend()
  2161. VlnPlot(seurat_sct,
  2162. features = c("Ccl4","C1qb","C1qc","Tyrobp","Cx3cr1","Tmem119"),
  2163. stack = T,
  2164. flip = T) + NoLegend()
  2165. VlnPlot(seurat_sct,
  2166. features = Vascular,
  2167. stack = T,
  2168. flip = T) + NoLegend()
  2169. VlnPlot(seurat_sct,
  2170. features = Retinal_Ganglion,
  2171. stack = T,
  2172. flip = T) + NoLegend()
  2173. VlnPlot(seurat_sct,
  2174. features = Reticulocytes,
  2175. # stack = T,
  2176. flip = T) + NoLegend()
  2177. VlnPlot(seurat_sct,
  2178. features = c("Ruvbl1","Tfrc","Ucp3","Folr1",
  2179. "Ube2o","Cd36","Itga4","Slc11a2"),
  2180. stack = T,
  2181. flip = T) + NoLegend() # reticulocyte markers
  2182. VlnPlot(seurat_sct,
  2183. features = c("Tfrc","Cga","Wrn","Kit","Piezo1",
  2184. "Kmt5a","Tal1","Gata1","Lmo2","Eng",
  2185. "Cfp","Itgb1","Use1","Grsf1","Lrp8",
  2186. "Lmnb1","Gypa","Tfr2","Igbp1","Epor",
  2187. "Ets1","Bpgm","Cd44","Cdh1"),
  2188. stack = T,
  2189. flip = T) + NoLegend() # Erythroblast markers
  2190. DotPlot(seurat_sct,
  2191. features = c("Tfrc","Cga","Wrn","Kit","Piezo1",
  2192. "Kmt5a","Tal1","Gata1","Lmo2","Eng",
  2193. "Cfp","Itgb1","Use1","Grsf1","Lrp8",
  2194. "Lmnb1","Gypa","Tfr2","Igbp1","Epor",
  2195. "Ets1","Bpgm","Cd44","Cdh1"),
  2196. cluster.idents = T)
  2197. # Erythroid-like and erythroid precursor cells
  2198. DotPlot(seurat_sct,
  2199. features = c("Ahsp","Hba-a1","Hba-a2","Hbb-bs"),
  2200. cluster.idents = T)
  2201. # Muller
  2202. DotPlot(seurat_sct,
  2203. features = c("S100a16","Dbi","Gnai2","Crb1",
  2204. "Rdh10","Abca8a","Crot","Dapl1",
  2205. "Itm2b"),
  2206. cluster.idents = T)
  2207. default_FP(seurat_sct,Rods)
  2208. default_FP(seurat_sct,Cones)
  2209. default_FP(seurat_sct,Mueller_Glia)
  2210. default_FP(seurat_sct,Bipolar)
  2211. default_FP(seurat_sct,Amacrine)
  2212. default_FP(seurat_sct,Horizontal)
  2213. default_FP(seurat_sct,Microglia)
  2214. default_FP(seurat_sct,Vascular)
  2215. default_FP(seurat_sct,c("Trpm1","Prkca","Pcp2"))
  2216. default_FP(seurat_sct,c("Tp53"))
  2217. VlnPlot(seurat_sct,
  2218. features = c("Tp53")) + NoLegend()
  2219. FeaturePlot(seurat_sct,
  2220. reduction = "umap",
  2221. features = c("Trpm1","Prkca","Pcp2","Bhlhe23"),
  2222. order = TRUE,
  2223. min.cutoff = 'q10',
  2224. label = TRUE,
  2225. label.size = 3,
  2226. pt.size = 0.5)
  2227. FeaturePlot(seurat_sct,
  2228. reduction = "umap",
  2229. features = c("Prdm8","Prkca","Pcp2","Bhlhe23"),
  2230. order = TRUE,
  2231. min.cutoff = 'q10',
  2232. label = TRUE,
  2233. label.size = 3,
  2234. pt.size = 0.5)
  2235. #### dotplots ####
  2236. DotPlot(seurat_sct,
  2237. features = c("Rho", # 7 rods
  2238. "Arr3", # 8 cones
  2239. "Rlbp1", # 4,10,12 muller glia
  2240. "Scgn", # 6 BC
  2241. "Sebox", # 0,1 RBCs
  2242. "Slc6a9", # 8,7,2,6 Gly-AC
  2243. "Gad1", # 2,6 GABA-AC
  2244. "Thy1", # 2,6 GABA-AC / GLY -AC
  2245. "Onecut2",# 6 HC
  2246. "Cx3cr1", # 16,3 MG
  2247. # "Pecam1", # NONE Pericytes
  2248. "Acta2", # 2,16 Pericytes
  2249. "Hbb-bs"),# 15 Reticulocytes
  2250. cluster.idents = TRUE)
  2251. DotPlot(seurat_sct,
  2252. features = c("Rho","Gnat1","Nrl","Pde6a","Pde6b","Cngb1", # rods
  2253. "Arr3","Opn1sw","Gnat2","Pde6h", # cones
  2254. "Glul","Rlbp1", # mueller glia
  2255. "Gfap","Aqp4","Gpr37", # astrocytes
  2256. "Tyrobp","Cx3cr1","Tmem119", # Microglia
  2257. "Scgn","Vsx1","Vsx2", # Bipolar
  2258. "Rbpms","Pou4f1","Pou4f2", # Retinal Ganglion
  2259. "Calb1","Gad1","Gad2", # Amacrine
  2260. "Onecut2", # Horizontal
  2261. "Pecam1","Acta2", # Pericytes
  2262. "Hbb-bs"), # Reticulocytes
  2263. cluster.idents = TRUE) +
  2264. theme(axis.text.x = element_text(angle = 45, vjust = 0.5))
  2265. Idents(p60seurat) <- ident_res
  2266. DotPlot(p60seurat,
  2267. features = c("Rho","Gnat1","Nrl","Pde6a","Pde6b","Cngb1", # rods
  2268. "Arr3","Opn1sw","Gnat2","Pde6h", # cones
  2269. "Glul","Rlbp1", # mueller glia
  2270. "Gfap","Aqp4","Gpr37", # astrocytes
  2271. "Tyrobp","Cx3cr1","Tmem119", # Microglia
  2272. "Scgn","Vsx1","Vsx2", # Bipolar
  2273. "Rbpms","Pou4f1","Pou4f2", # Retinal Ganglion
  2274. "Calb1","Gad1","Gad2", # Amacrine
  2275. "Onecut2", # Horizontal
  2276. "Pecam1","Acta2", # Pericytes
  2277. "Hbb-bs"), # Reticulocytes
  2278. cluster.idents = TRUE) +
  2279. theme(axis.text.x = element_text(angle = 45, vjust = 0.5))
  2280. Idents(p90seurat) <- ident_res
  2281. DotPlot(p90seurat,
  2282. features = c("Rho","Gnat1","Nrl","Pde6a","Pde6b","Cngb1", # rods
  2283. "Arr3","Opn1sw","Gnat2","Pde6h", # cones
  2284. "Glul","Rlbp1", # mueller glia
  2285. "Gfap","Aqp4","Gpr37", # astrocytes
  2286. "Tyrobp","Cx3cr1","Tmem119", # Microglia
  2287. "Scgn","Vsx1","Vsx2", # Bipolar
  2288. "Rbpms","Pou4f1","Pou4f2", # Retinal Ganglion
  2289. "Calb1","Gad1","Gad2", # Amacrine
  2290. "Onecut2", # Horizontal
  2291. "Pecam1","Acta2", # Pericytes
  2292. "Hbb-bs"), # Reticulocytes
  2293. cluster.idents = TRUE) +
  2294. theme(axis.text.x = element_text(angle = 45, vjust = 0.5))
  2295. DotPlot(seurat_sct,
  2296. features = c(Rods,Cones,Mueller_Glia,Astrocytes,
  2297. Microglia,Bipolar,Retinal_Ganglion,
  2298. Amacrine,Horizontal,Pericytes,Reticulocytes),
  2299. cluster.idents = TRUE) +
  2300. theme(axis.text.x = element_text(angle = 45, vjust = 0.5))
  2301. VlnPlot(seurat_sct,
  2302. features = Retinal_Ganglion,
  2303. stack = TRUE,
  2304. flip = TRUE,
  2305. sort = TRUE) + NoLegend()
  2306. # rods 7
  2307. VlnPlot(seurat_sct,
  2308. features = Rods,
  2309. stack = TRUE,
  2310. flip = TRUE,
  2311. sort = FALSE) + NoLegend()
  2312. FeaturePlot()
  2313. # cones 8
  2314. VlnPlot(seurat_sct,
  2315. features = Cones,
  2316. stack = TRUE,
  2317. flip = TRUE,
  2318. sort = TRUE) + NoLegend()
  2319. # Mueller_Glia
  2320. VlnPlot(seurat_sct,
  2321. features = Mueller_Glia,
  2322. stack = TRUE,
  2323. flip = TRUE,
  2324. sort = TRUE) + NoLegend()
  2325. #### Identify cells with non-zero expression for each gene ####
  2326. cells_with_expression <- WhichCells(seurat_sct, expression = )
  2327. all.genes <- rownames(seurat_sct)
  2328. # Create a list of all genes with expression greater than zero
  2329. genes_with_expression <- names(which(Sums(cells_with_expression) > 0))
  2330. which(rowSums(seurat_sct) > 0)
  2331. rowSums(seurat_sct) > 0
  2332. namesgenes <- names(rowSums(seurat_sct) > 0)
  2333. FeaturePlot(seurat_sct,
  2334. reduction = "umap",
  2335. features = c("Opn1sw"),
  2336. order = TRUE,
  2337. min.cutoff = 'q10',
  2338. label = TRUE,
  2339. label.size = 3,
  2340. pt.size = 0.5)
  2341. FeaturePlot(seurat_sct,
  2342. reduction = "umap",
  2343. features = c("Arr3"),
  2344. order = TRUE,
  2345. min.cutoff = 'q10',
  2346. label = TRUE,
  2347. label.size = 3,
  2348. pt.size = 0.5)
  2349. FeaturePlot(seurat_sct,
  2350. reduction = "umap",
  2351. features = c("Pax6","Tfap2b","Gad1","Slc6a9"),
  2352. order = TRUE,
  2353. min.cutoff = 'q10',
  2354. label = TRUE,
  2355. label.size = 3,
  2356. pt.size = 0.5)
  2357. FeaturePlot(seurat_sct,
  2358. reduction = "umap",
  2359. features = c("Tfap2b"),
  2360. order = TRUE,
  2361. min.cutoff = 'q10',
  2362. label = FALSE,
  2363. label.size = 3,
  2364. pt.size = 0.5,
  2365. split.by = "treatment")
  2366. FeaturePlot(seurat_sct,
  2367. reduction = "umap",
  2368. features = c("Tmem119","Adgre1","Tyrobp"),
  2369. order = TRUE,
  2370. min.cutoff = 'q10',
  2371. label = TRUE,
  2372. label.size = 3,
  2373. pt.size = 0.5)
  2374. FeaturePlot(seurat_sct,
  2375. reduction = "umap",
  2376. features = c("Glul"),
  2377. order = TRUE,
  2378. min.cutoff = 'q10',
  2379. label = TRUE,
  2380. label.size = 3,
  2381. pt.size = 0.5)
  2382. FeaturePlot(seurat_sct,
  2383. reduction = "umap",
  2384. features = c("Gfap"),
  2385. order = TRUE,
  2386. min.cutoff = 'q10',
  2387. label = TRUE,
  2388. label.size = 3,
  2389. pt.size = 0.5)
  2390. FeaturePlot(seurat_sct,
  2391. reduction = "umap",
  2392. features = c("Gsg1","Vsx1"),
  2393. order = TRUE,
  2394. min.cutoff = 'q10',
  2395. label = TRUE,
  2396. label.size = 3,
  2397. pt.size = 0.5)
  2398. FeaturePlot(seurat_sct,
  2399. reduction = "umap",
  2400. features = c("Onecut1"),
  2401. order = TRUE,
  2402. min.cutoff = 'q10',
  2403. label = TRUE,
  2404. label.size = 3,
  2405. pt.size = 0.5)
  2406. FeaturePlot(seurat_sct,
  2407. reduction = "umap",
  2408. features = c("Grm6"),
  2409. order = TRUE,
  2410. min.cutoff = 'q10',
  2411. label = TRUE,
  2412. label.size = 3,
  2413. pt.size = 0.5)
  2414. FeaturePlot(seurat_sct,
  2415. reduction = "umap",
  2416. features = c("Rbpms"),
  2417. order = TRUE,
  2418. min.cutoff = 'q10',
  2419. label = TRUE,
  2420. label.size = 3,
  2421. pt.size = 0.5)
  2422. VlnPlot(seurat_sct,
  2423. features = "Grm6",
  2424. flip = TRUE,
  2425. pt.size = 0)
  2426. #### Wang et al 2022 ####
  2427. DimPlot(seurat_sct,
  2428. reduction = "umap",
  2429. label = TRUE,
  2430. label.size = 5,
  2431. pt.size = 1,
  2432. raster = F,
  2433. cols = sorted_palopal) +
  2434. NoLegend()
  2435. DimPlot(seurat_sct,
  2436. reduction = "umap",
  2437. label = TRUE,
  2438. label.size = 5,
  2439. pt.size = 1,
  2440. raster = F,
  2441. cols = sorted_palopal,
  2442. split.by = "time_point") +
  2443. NoLegend()
  2444. # Rod - Pde6a, Rho, Sag, Gnat1, Nrl
  2445. VlnPlot(seurat_sct,
  2446. features = c("Pde6a", "Rho", "Sag", "Gnat1", "Nrl",
  2447. "Map2","Rom1"),
  2448. stack = T,
  2449. flip = T,
  2450. raster = F) + NoLegend()
  2451. FeaturePlot(seurat_sct,
  2452. reduction = "umap",
  2453. features = c("Pde6a", "Rho", "Sag", "Gnat1", "Nrl",
  2454. "Map2"),
  2455. order = TRUE,
  2456. min.cutoff = 'q10',
  2457. label = TRUE,
  2458. label.size = 3,
  2459. pt.size = 0.5,
  2460. raster = F)
  2461. # S Cone - Pde6h, Arr3, Gnat2, Opn1sw, Ccdc136, Ttr
  2462. VlnPlot(seurat_sct,
  2463. features = c("Pde6h", "Arr3", "Gnat2", "Opn1sw", "Ccdc136" ,"Ttr"),
  2464. stack = T,
  2465. flip = T,
  2466. raster = F) + NoLegend()
  2467. FeaturePlot(seurat_sct,
  2468. reduction = "umap",
  2469. features = c("Pde6h", "Arr3", "Gnat2", "Opn1mw"),
  2470. order = TRUE,
  2471. min.cutoff = 'q10',
  2472. label = TRUE,
  2473. label.size = 3,
  2474. pt.size = 0.5,
  2475. raster = F)
  2476. FeaturePlot(seurat_sct,
  2477. reduction = "umap",
  2478. features = c("Ccdc136" ,"Ttr", "Vopp1", "Lmo4"),
  2479. order = TRUE,
  2480. min.cutoff = 'q10',
  2481. label = TRUE,
  2482. label.size = 3,
  2483. pt.size = 0.5,
  2484. raster = F)
  2485. # M/L Cone - Pde6h, Arr3, Gnat2, Opn1mw/Opn1lw, Vopp1, Lmo4
  2486. VlnPlot(seurat_sct,
  2487. features = c("Pde6h", "Arr3", "Gnat2", "Opn1mw",
  2488. "Opn1lw", "Vopp1", "Lmo4"),
  2489. stack = T,
  2490. flip = T,
  2491. raster = F) + NoLegend()
  2492. # HC - Pvalb, Lhx1, Pax6, Onecut1
  2493. VlnPlot(seurat_sct,
  2494. features = c("Pvalb", "Lhx1", "Pax6", "Onecut1"),
  2495. stack = T,
  2496. flip = T,
  2497. raster = F) + NoLegend()
  2498. FeaturePlot(seurat_sct,
  2499. reduction = "umap",
  2500. features = c("Pvalb", "Lhx1", "Pax6", "Onecut1"),
  2501. order = TRUE,
  2502. min.cutoff = 'q10',
  2503. label = TRUE,
  2504. label.size = 3,
  2505. pt.size = 0.5,
  2506. raster = F)
  2507. # AC - Snhg11, Pax6, Slc32a1, Crabp1, Nrxn2, Gad1/Gad2, Maf, Tfap2a, Slc6a9, Ebf3
  2508. VlnPlot(seurat_sct,
  2509. features = c("Snhg11", "Pax6", "Slc32a1", "Crabp1",
  2510. "Nrxn2", "Gad1", "Gad2", "Maf",
  2511. "Tfap2a", "Slc6a9", "Ebf3"),
  2512. stack = T,
  2513. flip = T) + NoLegend()
  2514. hirestiff(paste(prefixPCres,"UMAP","Amacrine","markers","hires.tiff", sep = "_"))
  2515. lowrestiff(paste(prefixPCres,"UMAP","Amacrine","markers","lowres.tiff", sep = "_"))
  2516. # RBC - Gsg1, Pax6, Slc6a9, Vsx2, Otx2, Prkca, Isl1, Grm6, Cabp5, Vstm2b, Casp7, Rpa1
  2517. VlnPlot(seurat_sct,
  2518. features = c("Gsg1", "Pax6", "Slc6a9", "Vsx2", "Otx2",
  2519. "Prkca", "Isl1", "Grm6", "Cabp5", "Vstm2b",
  2520. "Casp7", "Rpa1"),
  2521. stack = T,
  2522. flip = T) + NoLegend()
  2523. FeaturePlot(seurat_sct,
  2524. reduction = "umap",
  2525. features = c("Gsg1", "Pax6", "Slc6a9", "Vsx2", "Otx2",
  2526. "Prkca", "Isl1", "Grm6", "Cabp5", "Vstm2b",
  2527. "Casp7", "Rpa1"),
  2528. order = TRUE,
  2529. min.cutoff = 'q10',
  2530. label = TRUE,
  2531. label.size = 3,
  2532. pt.size = 0.5,
  2533. raster = F)
  2534. # ON CBC - Gsg1, Pax6, Slc6a9, Vsx2, Otx2, App, Scgn, Vsx1, Isl1, Grm6
  2535. VlnPlot(seurat_sct,
  2536. features = c("Gsg1", "Pax6", "Slc6a9", "Vsx2", "Otx2",
  2537. "App", "Scgn", "Vsx1", "Isl1", "Grm6"),
  2538. stack = T,
  2539. flip = T) + NoLegend()
  2540. FeaturePlot(seurat_sct,
  2541. reduction = "umap",
  2542. features = c("App", "Scgn", "Vsx1", "Isl1", "Grm6"),
  2543. order = TRUE,
  2544. min.cutoff = 'q10',
  2545. label = TRUE,
  2546. label.size = 3,
  2547. pt.size = 0.5,
  2548. raster = F)
  2549. # OFF CBC - Gsg1, Pax6, Slc6a9, Vsx2, Otx2, App, Scgn, Vsx1, Grin2b, Grik1
  2550. VlnPlot(seurat_sct,
  2551. features = c("Gsg1", "Pax6", "Slc6a9", "Vsx2", "Otx2",
  2552. "App", "Scgn", "Vsx1", "Grin2b", "Grik1"),
  2553. stack = T,
  2554. flip = T) + NoLegend()
  2555. FeaturePlot(seurat_sct,
  2556. reduction = "umap",
  2557. features = c("App", "Scgn", "Vsx1", "Grin2b", "Grik1"),
  2558. order = TRUE,
  2559. min.cutoff = 'q10',
  2560. label = TRUE,
  2561. label.size = 3,
  2562. pt.size = 0.5,
  2563. raster = F)
  2564. # Müller - Gsta1, Pax6, Rlbp1, Aqp4, Slc1a3, Apoe, Dkk3, Gpr37, Rax, Hes1, Notch1, Glul
  2565. VlnPlot(seurat_sct,
  2566. features = c("Gsta1", "Pax6", "Rlbp1", "Aqp4", "Slc1a3",
  2567. "Apoe", "Dkk3", "Gpr37", "Rax", "Hes1",
  2568. "Notch1", "Glul"),
  2569. stack = T,
  2570. flip = T,
  2571. raster = F) + NoLegend()
  2572. FeaturePlot(seurat_sct,
  2573. reduction = "umap",
  2574. features = c("Gfap", "Aqp4", "S100b"),
  2575. order = TRUE,
  2576. min.cutoff = 'q10',
  2577. label = TRUE,
  2578. label.size = 3,
  2579. pt.size = 0.5,
  2580. raster = F)
  2581. # Microglia - C1qa, Tmem119, Cx3cr1, Apoe, Pax6, P2ry12, Aif1
  2582. VlnPlot(seurat_sct,
  2583. features = c("C1qa", "Tmem119", "Cx3cr1", "Apoe", "Pax6",
  2584. "P2ry12", "Aif1"),
  2585. stack = T,
  2586. flip = T,
  2587. raster = F) + NoLegend()
  2588. FeaturePlot(seurat_sct,
  2589. reduction = "umap",
  2590. features = c("C1qa", "Tmem119", "Cx3cr1",
  2591. "P2ry12", "Aif1"),
  2592. order = TRUE,
  2593. min.cutoff = 'q10',
  2594. label = TRUE,
  2595. label.size = 3,
  2596. pt.size = 0.5,
  2597. raster = F)
  2598. # EC - Vwf, Pecam1, Cldn5, Cdh5, Tek, Kdr, Flt1
  2599. VlnPlot(seurat_sct,
  2600. features = c("Vwf", "Pecam1", "Cldn5", "Cdh5", "Tek",
  2601. "Kdr", "Flt1", "Rbpms"),
  2602. stack = T,
  2603. flip = T,
  2604. raster = F) + NoLegend()
  2605. # Pericyte - Rgs5, Kcnj8, Myl9, Cspg4, Pdgfrb, Myh11, Acta2
  2606. VlnPlot(seurat_sct,
  2607. features = c("Rgs5","Kcnj8","Myl9","Cspg4","Pdgfrb",
  2608. "Myh11","Acta2","Mgp", "Crip1", "Tpm2",
  2609. "Rbpms","Pgf","Igf1","Igf2r","Vegfa",
  2610. "Axl"),
  2611. stack = T,
  2612. flip = T,
  2613. raster = F) + NoLegend()
  2614. VlnPlot(seurat_sct,
  2615. features = c("Dnmbp","Tubb3","Nefl","Nefm","Nefh","Rbfox3","Map2","Syp","Gap43"),
  2616. stack = T,
  2617. flip = T,
  2618. raster = F) + NoLegend()
  2619. FeaturePlot(seurat_sct,
  2620. reduction = "umap",
  2621. features = c("Dnmbp","Tubb3","Nefl","Nefm","Nefh",
  2622. "Rbfox3","Map2","Syp","Gap43"),
  2623. order = TRUE,
  2624. min.cutoff = 'q10',
  2625. label = TRUE,
  2626. label.size = 3,
  2627. pt.size = 0.5,
  2628. raster = F)
  2629. VlnPlot(seurat_sct,
  2630. features = c("Mgp", "Crip1", "Tpm2"),
  2631. stack = T,
  2632. flip = T,
  2633. raster = F) + NoLegend()
  2634. # Macrophage - Cxcr4, Cd53, Ptprc
  2635. VlnPlot(seurat_sct,
  2636. features = c("Cxcr4", "Cd53", "Ptprc"),
  2637. stack = T,
  2638. flip = T,
  2639. raster = F) + NoLegend()
  2640. FeaturePlot(seurat_sct,
  2641. reduction = "umap",
  2642. features = c("Cxcr4", "Cd53", "Ptprc"),
  2643. order = TRUE,
  2644. min.cutoff = 'q10',
  2645. label = TRUE,
  2646. label.size = 3,
  2647. pt.size = 0.5,
  2648. raster = F)
  2649. # RGC - Rbpms
  2650. VlnPlot(seurat_sct,
  2651. features = c("Rbpms","Pou4f1","Pou4f2","Pou4f3","Thy1",
  2652. "Map2","Opn4","Slc17a6","Jam2","Tbr1"),
  2653. stack = T,
  2654. flip = T,
  2655. raster = F) + NoLegend()
  2656. VlnPlot(seurat_sct,
  2657. features = c("Rbpms","Pou4f1","Pou4f2",
  2658. "Jam2","Foxp1","Foxp2"),
  2659. stack = T,
  2660. flip = T,
  2661. raster = F) + NoLegend()
  2662. # Ctxn3+Müller - Cd9, Penk, Ctxn3
  2663. VlnPlot(seurat_sct,
  2664. features = c("Cd9", "Penk", "Ctxn3"),
  2665. stack = T,
  2666. flip = T,
  2667. raster = F) + NoLegend()
  2668. # Ctxn3-Müller - Cd9, Penk
  2669. VlnPlot(seurat_sct,
  2670. features = c("Cd9", "Penk"),
  2671. stack = T,
  2672. flip = T,
  2673. raster = F) + NoLegend()
  2674. # EC - Pltp, Csrp2, Cxcl12, Id1, Ramp2, Slc2a1
  2675. VlnPlot(seurat_sct,
  2676. features = c("Pltp", "Csrp2", "Cxcl12", "Id1",
  2677. "Ramp2", "Slc2a1"),
  2678. stack = T,
  2679. flip = T,
  2680. raster = F) + NoLegend()
  2681. # Pericyte - Mgp, Crip1, Tpm2
  2682. VlnPlot(seurat_sct,
  2683. features = c("Mgp", "Crip1", "Tpm2"),
  2684. stack = T,
  2685. flip = T,
  2686. raster = F) + NoLegend()
  2687. #### Genes from 9/18 ####
  2688. # Egr11 in rods and cones - probably Egr1
  2689. # Amacrine: Snhg11, Pax6, Slc32a1, Crabp1, Nrxn2,
  2690. # Gad1/Gad2, Maf, Tfap2a, Slc6a9, Ebf3 - done above
  2691. # Muller glia and astrocytes:
  2692. # glutamine synthetase (GLUL), clusterin (CLU),
  2693. # and apolipoprotein E (APOE).
  2694. # NxnL1: metabolic dysfunction-glucosse metabolism.
  2695. # Hk2: a key enzyme for aerobic glycolysis and required for survival of photoreceptors during aging.
  2696. # Cebpd: upregulation is related to neuroprotection.
  2697. VlnPlot(seurat_sct,
  2698. features = c("Egr1","Nxnl1","Hk2","Cebpd"),
  2699. stack = T,
  2700. flip = T) + NoLegend()
  2701. hirestiff(paste(prefixPCres,"VLN","Egr1","Nxnl1","Hk2","Cebpd","hires.tiff", sep = "_"))
  2702. lowrestiff(paste(prefixPCres,"VLN","Egr1","Nxnl1","Hk2","Cebpd","lowres.tiff", sep = "_"))
  2703. VlnPlot(seurat_sct,
  2704. features = c("Egr1"),
  2705. flip = T,
  2706. idents = c(8,9),
  2707. split.by = "time_point_treatment")
  2708. VlnPlot(seurat_sct,
  2709. features = c("Egr1"),
  2710. flip = T,
  2711. idents = c("ROD","CONE"),
  2712. split.by = "time_point_treatment")
  2713. hirestiff(paste(prefixPCres,"VLN","Egr1","rod-cone","hires.tiff", sep = "_"))
  2714. lowrestiff(paste(prefixPCres,"VLN","Egr1","rod-cone","lowres.tiff", sep = "_"))
  2715. VlnPlot(seurat_sct,
  2716. features = c("Nxnl1"),
  2717. flip = T,
  2718. idents = c("ROD","CONE"),
  2719. split.by = "time_point_treatment")
  2720. hirestiff(paste(prefixPCres,"VLN","Nxnl1","rod-cone","hires.tiff", sep = "_"))
  2721. lowrestiff(paste(prefixPCres,"VLN","Nxnl1","rod-cone","lowres.tiff", sep = "_"))
  2722. VlnPlot(seurat_sct,
  2723. features = c("Hk2"),
  2724. flip = T,
  2725. idents = c("ROD","CONE"),
  2726. split.by = "time_point_treatment")
  2727. hirestiff(paste(prefixPCres,"VLN","Hk2","rod-cone","hires.tiff", sep = "_"))
  2728. lowrestiff(paste(prefixPCres,"VLN","Hk2","rod-cone","lowres.tiff", sep = "_"))
  2729. VlnPlot(seurat_sct,
  2730. features = c("Cebpd"),
  2731. flip = T,
  2732. idents = c("GLN1","GLN2","MULG"),
  2733. split.by = "time_point_treatment")
  2734. hirestiff(paste(prefixPCres,"VLN","Cebpd","gln_mulg","hires.tiff", sep = "_"))
  2735. lowrestiff(paste(prefixPCres,"VLN","Cebpd","gln_mulg","lowres.tiff", sep = "_"))
  2736. VlnPlot(seurat_sct,
  2737. features = c("Glul", "Clu", "Apoe"),
  2738. stack = T,
  2739. flip = T) + NoLegend()
  2740. hirestiff(paste(prefixPCres,"VLN","Muller","markers","09_18","hires.tiff", sep = "_"))
  2741. lowrestiff(paste(prefixPCres,"VLN","Muller","markers","09_18","lowres.tiff", sep = "_"))
  2742. #### Genes from 9/28 ####
  2743. # VlnPlot(seurat_sct,
  2744. # features = c("Pou4f1", "Pou4f2", "Pou4f3", "Sncg", "Isl1", "Nefl", "Nefm",
  2745. # "Elavl4", "Eomes", "Calb1", "Calb2", "Opn4", "Fes", "Tpbg", "Irx3",
  2746. # "Irx4", "Trb1", "Neurod2", "Penk", "Jam2", "Calca", "Spp1", "Plpp4",
  2747. # "Coch", "Foxp1", "Foxp2", "Tusc5", "Satb2", "Cdk15", "Anxa3", "Slc17a6",
  2748. # "Tbx20", "Serpine2", "Nmb", "Adcyap1", "Nmb", "Cartpt", "Mmp17", "Gpr88",
  2749. # "Fam19a4", "Ebf3", "Col25a1", "A230065H16Rik", "Dcx"),
  2750. # stack = T,
  2751. # flip = T) + NoLegend()
  2752. VlnPlot(seurat_sct,
  2753. features = c("Pou4f1","Pou4f2","Pou4f3","Sncg","Isl1",
  2754. "Nefl","Nefm","Elavl4",#"Eomes",
  2755. "Calb1",
  2756. "Calb2","Opn4","Fes","Tpbg","Irx3"),
  2757. stack = T,
  2758. flip = T,
  2759. idents = c(6,15,20)) + NoLegend() + ggtitle("RGC set 1")
  2760. hirestiff(paste(prefixPCres,"VLN","RGC","set","1","sept_28","hires.tiff", sep = "_"))
  2761. lowrestiff(paste(prefixPCres,"VLN","RGC","set","1","sept_28","lowres.tiff", sep = "_"))
  2762. VlnPlot(seurat_sct,
  2763. features = c("Irx4","Trib1","Neurod2","Penk","Jam2",
  2764. "Calca","Spp1","Plpp4","Coch","Foxp1",
  2765. "Foxp2","Trarg1","Satb2","Cdk15","Anxa3"),
  2766. stack = T,
  2767. flip = T,
  2768. idents = c(6,15,20)) + NoLegend() + ggtitle("RGC set 2")
  2769. hirestiff(paste(prefixPCres,"VLN","RGC","set","2","sept_28","hires.tiff", sep = "_"))
  2770. lowrestiff(paste(prefixPCres,"VLN","RGC","set","2","sept_28","lowres.tiff", sep = "_"))
  2771. VlnPlot(seurat_sct,
  2772. features = c("Slc17a6","Tbx20","Serpine2","Nmb","Adcyap1",
  2773. "Nmb","Cartpt","Mmp17","Gpr88","Tafa4",
  2774. "Ebf3","Col25a1","Lbhd2","Dcx"),
  2775. stack = T,
  2776. flip = T,
  2777. idents = c(6,15,20)) + NoLegend() + ggtitle("RGC set 3")
  2778. hirestiff(paste(prefixPCres,"VLN","RGC","set","3","sept_28","hires.tiff", sep = "_"))
  2779. lowrestiff(paste(prefixPCres,"VLN","RGC","set","3","sept_28","lowres.tiff", sep = "_"))
  2780. # VlnPlot(seurat_sct,
  2781. # features = c("Gldn","Chl1","Qpct","Dgkg","Timp2",
  2782. # "Junb","Ifitm10","Fgf1","Sema5a","Ramp1",
  2783. # "Ostf1","Esrrg","Etl4","Kbtbd11","Ctxn3",
  2784. # "Igf11","Sdk1","Sdk2","Man1a","Ifi27"),
  2785. # stack = T,
  2786. # flip = T) + NoLegend()
  2787. VlnPlot(seurat_sct,
  2788. features = c("Gldn","Chl1","Qpct","Dgkg","Timp2",
  2789. "Junb","Ifitm10","Fgf1","Sema5a","Ramp1"),
  2790. stack = T,
  2791. flip = T,
  2792. idents = c(6,15,20)) + NoLegend() + ggtitle("RGC set 4")
  2793. hirestiff(paste(prefixPCres,"VLN","RGC","set","4","sept_28","hires.tiff", sep = "_"))
  2794. lowrestiff(paste(prefixPCres,"VLN","RGC","set","4","sept_28","lowres.tiff", sep = "_"))
  2795. VlnPlot(seurat_sct,
  2796. features = c("Ostf1","Esrrg","Etl4","Kbtbd11","Ctxn3",
  2797. "Igf2","Sdk1","Sdk2","Man1a1","Ifi27"),
  2798. stack = T,
  2799. flip = T,
  2800. idents = c(6,15,20)) + NoLegend() + ggtitle("RGC set 5")
  2801. hirestiff(paste(prefixPCres,"VLN","RGC","set","5","sept_28","hires.tiff", sep = "_"))
  2802. lowrestiff(paste(prefixPCres,"VLN","RGC","set","5","sept_28","lowres.tiff", sep = "_"))
  2803. VlnPlot(seurat_sct,
  2804. features = c("Pdlim1","Col1a1","Pdgfrb","Rbpms"),
  2805. stack = T,
  2806. flip = T,
  2807. idents = c(6,15,20)) + NoLegend() + ggtitle("Pericytes set 1")
  2808. hirestiff(paste(prefixPCres,"VLN","Pericytes","set","1","sept_28","hires.tiff", sep = "_"))
  2809. lowrestiff(paste(prefixPCres,"VLN","Pericytes","set","1","sept_28","lowres.tiff", sep = "_"))
  2810. VlnPlot(seurat_sct,
  2811. features = c("Rgs5","Kcnj8","Myl9","Cspg4","Pdgfrb",
  2812. "Myh11","Acta2","Mgp","Crip1","Tpm2",
  2813. "Pdlim1","Col1a1"),
  2814. stack = T,
  2815. flip = T,
  2816. idents = c(6,15,20)) + NoLegend() + ggtitle("Pericytes set 1 with Wang et al markers")
  2817. hirestiff(paste(prefixPCres,"VLN","Pericytes","with","wang","markers","sept_28","hires.tiff", sep = "_"))
  2818. lowrestiff(paste(prefixPCres,"VLN","Pericytes","with","wang","markers","sept_28","lowres.tiff", sep = "_"))
  2819. VlnPlot(seurat_sct,
  2820. features = c("Prph","Ebf3","Atp13a5",
  2821. "Cend1","Esrrb","Uchl1"),
  2822. stack = T,
  2823. flip = T,
  2824. idents = c(6,15,20)) +
  2825. NoLegend() +
  2826. ggtitle("New markers 10-6-23")
  2827. hirestiff(paste(prefixPCres,"VLN","new","markers","Oct6","hires.tiff", sep = "_"))
  2828. lowrestiff(paste(prefixPCres,"VLN","new","markers","Oct6","lowres.tiff", sep = "_"))
  2829. Prph, Ebf3
  2830. Pericyte: Atp13a5
  2831. BM88(Cend1), ERRbeta (Esrrb), PGP9.5 (Uchl1)
  2832. FeaturePlot(seurat_sct,
  2833. reduction = "umap",
  2834. features = c("Rbpms"),
  2835. order = TRUE,
  2836. min.cutoff = 'q10',
  2837. label = TRUE,
  2838. label.size = 3,
  2839. pt.size = 0.5,
  2840. raster = F,
  2841. split.by = "time_point")
  2842. FeaturePlot(seurat_sct,
  2843. reduction = "umap",
  2844. features = c("Sncg","Rbpms","Pou4f1","Kcnj8"),
  2845. order = TRUE,
  2846. min.cutoff = 'q10',
  2847. label = TRUE,
  2848. label.size = 3,
  2849. pt.size = 0.5,
  2850. raster = F)
  2851. FeaturePlot(seurat_sct,
  2852. reduction = "umap",
  2853. features = c("Sncg","Rbpms","Isl1","Rbfox3"),
  2854. order = TRUE,
  2855. min.cutoff = 'q10',
  2856. label = TRUE,
  2857. label.size = 3,
  2858. pt.size = 0.5,
  2859. raster = F)
  2860. FeaturePlot(seurat_sct,
  2861. reduction = "umap",
  2862. features = c("Sncg","Rbpms","Pou4f1","Pou4f2"),
  2863. order = TRUE,
  2864. min.cutoff = 'q10',
  2865. label = TRUE,
  2866. label.size = 3,
  2867. pt.size = 0.5,
  2868. raster = F)
  2869. #### Find Cluster Markers for all cells ####
  2870. # find all markers
  2871. cluster_markers <- FindAllMarkers(seurat_sct, only.pos = TRUE, min.pct = 0.50, logfc.threshold = 0.4)
  2872. write.csv(cluster_markers,
  2873. file = paste(prefixPCres,"clustermarkers_pos_only_minpct0.50_logfcthresh0.4.csv", sep = "_"))
  2874. #### find DEGs between treatments ####
  2875. Idents(object = seurat_sct) <- "treatment"
  2876. cluster_markers <- FindAllMarkers(seurat_sct, only.pos = TRUE, min.pct = 0.25, logfc.threshold = 0.4)
  2877. write.csv(cluster_markers, file =
  2878. paste(prefixPCres,"degs_treatment_all_cells_minpct0.25_logfcthresh0.4.csv", sep = "_"))
  2879. Idents(object = seurat_sct) <- ident_res
  2880. #### find DEGs between time points ####
  2881. Idents(object = seurat_sct) <- "time_point"
  2882. cluster_markers <- FindAllMarkers(seurat_sct, only.pos = TRUE, min.pct = 0.25, logfc.threshold = 0.4)
  2883. write.csv(cluster_markers, file =
  2884. paste(prefixPCres,"degs_timepoint_all_cells_minpct0.25_logfcthresh0.4.csv", sep = "_"))
  2885. Idents(object = seurat_sct) <- ident_res
  2886. #### subsets for further DEG analysis ####
  2887. # subset seurat obj by time point for treated vs untreated DEGs
  2888. Idents(object = seurat_sct) <- "time_point"
  2889. p60seurat <- subset(seurat_sct, idents = "p60")
  2890. p90seurat <- subset(seurat_sct, idents = "p90")
  2891. Idents(object = p60seurat) <- "treatment"
  2892. cluster_markers <- FindAllMarkers(p60seurat, only.pos = TRUE, min.pct = 0.25, logfc.threshold = 0.4)
  2893. write.csv(cluster_markers, file =
  2894. paste(prefixPCres,"degs_treatment_p60_minpct0.25_logfcthresh0.4.csv", sep = "_"))
  2895. Idents(object = p90seurat) <- "treatment"
  2896. cluster_markers <- FindAllMarkers(p90seurat, only.pos = TRUE, min.pct = 0.25, logfc.threshold = 0.4)
  2897. write.csv(cluster_markers, file =
  2898. paste(prefixPCres,"degs_treatment_p90_minpct0.25_logfcthresh0.4.csv", sep = "_"))
  2899. # subset seurat obj by treatment for p60 vs p90 DEGs
  2900. Idents(object = seurat_sct) <- "treatment"
  2901. TRseurat <- subset(seurat_sct, idents = "Cell_Treated")
  2902. UTseurat <- subset(seurat_sct, idents = "Untreated")
  2903. Idents(object = TRseurat) <- "time_point"
  2904. cluster_markers <- FindAllMarkers(TRseurat, only.pos = TRUE, min.pct = 0.25, logfc.threshold = 0.4)
  2905. write.csv(cluster_markers, file =
  2906. paste(prefixPCres,"degs_treated_p60_vs_p90_minpct0.25_logfcthresh0.4.csv", sep = "_"))
  2907. Idents(object = UTseurat) <- "time_point"
  2908. cluster_markers <- FindAllMarkers(UTseurat, only.pos = TRUE, min.pct = 0.25, logfc.threshold = 0.4)
  2909. write.csv(cluster_markers, file =
  2910. paste(prefixPCres,"degs_untreated_p60_vs_p90_minpct0.25_logfcthresh0.4.csv", sep = "_"))
  2911. Idents(object = seurat_sct) <- ident_res
  2912. Idents(object = p60seurat) <- ident_res
  2913. Idents(object = p90seurat) <- ident_res
  2914. Idents(object = TRseurat) <- ident_res
  2915. Idents(object = UTseurat) <- ident_res
  2916. #### save subset objects ####
  2917. saveRDS(p60seurat, paste0(prefixPCres,"_p60_seurat.rds"))
  2918. # p60seurat <- readRDS(file = paste0(prefixPCres,"_p60_seurat.rds"))
  2919. saveRDS(p90seurat, paste0(prefixPCres,"_p90_seurat.rds"))
  2920. p90seurat <- readRDS(file = paste0(prefixPCres,"_p90_seurat.rds"))
  2921. saveRDS(TRseurat, paste0(prefixPCres,"_cell_treated_seurat.rds"))
  2922. # TRseurat <- readRDS(file = paste0(prefixPCres,"_cell_treated_seurat.rds"))
  2923. saveRDS(UTseurat, paste0(prefixPCres,"_untreated_seurat.rds"))
  2924. # UTseurat <- readRDS(file = paste0(prefixPCres,"_untreated_seurat.rds"))
  2925. #### for loop for DEGs within clusters ####
  2926. clusterlist <- as.list(0:(max(as.integer([email hidden]$integrated_snn_res.0.2))-1))
  2927. clusterlist
  2928. for (k in 1:length(clusterlist)){
  2929. nam <- paste("clusterDEG_treatment", clusterlist[k], sep = "_")
  2930. assign(nam, FindMarkers(seurat_sct, ident.1 = "Cell_Treated", group.by = "treatment", subset.ident = clusterlist[k]))
  2931. write.csv(get(nam), file = paste(prefixPCres, nam, "list.csv", sep = "_"), row.names = TRUE)
  2932. }
  2933. # positive LFC means upregulation in Cell_Treated cells
  2934. for (k in 1:length(clusterlist)){
  2935. nam <- paste("clusterDEG_timepoint", clusterlist[k], sep = "_")
  2936. assign(nam, FindMarkers(seurat_sct, ident.1 = "p60", group.by = "time_point", subset.ident = clusterlist[k]))
  2937. write.csv(get(nam), file = paste(prefixPCres, nam, "list.csv", sep = "_"), row.names = TRUE)
  2938. }
  2939. # positive LFC means upregulation in p60 cells
  2940. #### LABEL CELL TYPES ####
  2941. #### Label cell types (short name) ####
  2942. seurat_sct <- RenameIdents(object = seurat_sct,
  2943. '0' = "RBC",
  2944. '1' = "RBC",
  2945. '2' = "ROD",
  2946. '3' = "MG",
  2947. '4' = "CBC",
  2948. '5' = "RBC",
  2949. '6' = "RGC",
  2950. '7' = "EC",
  2951. '8' = "ROD",
  2952. '9' = "MULG",
  2953. '10' = "MULG",
  2954. '11' = "CONE",
  2955. '12' = "MG",
  2956. '13' = "MG",
  2957. '14' = "CBC",
  2958. '15' = "RGC",
  2959. '16' = "AC",
  2960. '17' = "MULG",
  2961. '18' = "MULG",
  2962. '19' = "MULG",
  2963. '20' = "RGC",
  2964. '21' = "MG",
  2965. '22' = "EC",
  2966. '23' = "M0",
  2967. '24' = "MULG",
  2968. '25' = "ROD",
  2969. '26' = "EC",
  2970. '27' = "MULG",
  2971. '28' = "MG")
  2972. #### save cell type (short name) as a metadata column ####
  2973. seurat_sct[["Cell.Type"]] <- [email hidden]
  2974. #### dimplots of cell type (short name) labeled clusters ####
  2975. DimPlot(seurat_sct,
  2976. reduction = "umap",
  2977. label = TRUE,
  2978. label.size = 6,
  2979. pt.size = 1,
  2980. raster = F) +
  2981. NoLegend()
  2982. hirestiff(paste(prefixPCres,"UMAP","celltypes","hires.tiff",sep = "_"))
  2983. lowrestiff(paste(prefixPCres,"UMAP","celltypes","lowres.tiff",sep = "_"))
  2984. DimPlot(seurat_sct,
  2985. reduction = "umap",
  2986. label = TRUE,
  2987. label.size = 5,
  2988. pt.size = 1,
  2989. raster = F,
  2990. split.by = "time_point") +
  2991. NoLegend()
  2992. hirestiff(paste(prefixPCres,"UMAP","celltypes","by","time_point","hires.tiff",sep = "_"))
  2993. lowrestiff(paste(prefixPCres,"UMAP","celltypes","by","time_point","lowres.tiff",sep = "_"))
  2994. DimPlot(seurat_sct,
  2995. reduction = "umap",
  2996. label = TRUE,
  2997. label.size = 3,
  2998. pt.size = 1,
  2999. raster = F,
  3000. split.by = "time_point_treatment") +
  3001. NoLegend()
  3002. hirestiff(paste(prefixPCres,"UMAP","celltypes","by","time_point_treatment","hires.tiff",sep = "_"))
  3003. lowrestiff(paste(prefixPCres,"UMAP","celltypes","by","time_point_treatment","lowres.tiff",sep = "_"))
  3004. for (i in 1:length(levels(seurat_sct$time_point_treatment))){
  3005. p <- (DimPlot(seurat_sct,
  3006. reduction = "umap",
  3007. label = TRUE,
  3008. label.size = 8,
  3009. pt.size = 1,
  3010. cells = c(WhichCells(seurat_sct,
  3011. expression =
  3012. time_point_treatment ==
  3013. levels(seurat_sct$time_point_treatment)[i]))) +
  3014. NoLegend() +
  3015. ggtitle(paste0(levels(seurat_sct$time_point_treatment)[i])))
  3016. print(p)
  3017. hirestiff(paste(prefixPCres,"UMAP","split_by","time_point_treatment","with_cluster_labels",
  3018. levels(seurat_sct$time_point_treatment)[i],"hires.tiff",sep = "_"))
  3019. lowrestiff(paste(prefixPCres,"UMAP","split_by","time_point_treatment","with_cluster_labels",
  3020. levels(seurat_sct$time_point_treatment)[i],"lowres.tiff",sep = "_"))
  3021. hirestiffsquare(paste(prefixPCres,"UMAP","split_by","time_point_treatment","with_cluster_labels",
  3022. levels(seurat_sct$time_point_treatment)[i],"hires_square.tiff",sep = "_"))
  3023. lowrestiffsquare(paste(prefixPCres,"UMAP","split_by","time_point_treatment","with_cluster_labels",
  3024. levels(seurat_sct$time_point_treatment)[i],"lowres_square.tiff",sep = "_"))
  3025. }
  3026. rm(p)
  3027. #x#### Label cell types (long name) ####
  3028. seurat_sct <- RenameIdents(object = seurat_sct,
  3029. 'BIP1' = "Bipolar_1",
  3030. 'BIP2' = "Bipolar_2",
  3031. 'GLN1' = "Ganglion_1",
  3032. 'GLN2' = "Ganglion_2",
  3033. 'MG' = "Microglia",
  3034. 'ROD' = "Rods",
  3035. 'CONE' = "Cones",
  3036. 'MULG' = "Müller_Glia",
  3037. 'AMCR' = "Amacrine",
  3038. 'RTIC' = "Reticulocytes")
  3039. #x#### save cell type (long name) as a metadata column ####
  3040. seurat_sct[["Cell.Type.Long"]] <- [email hidden]
  3041. #x#### Label cell types plus cluster number ####
  3042. seurat_sct <- RenameIdents(object = seurat_sct,
  3043. '0' = "RGC0",
  3044. '1' = "BP1",
  3045. '2' = "BP2",
  3046. '3' = "BP_ROD3",
  3047. '4' = "FIB4",
  3048. '5' = "MG5",
  3049. '6' = "FIB6",
  3050. '7' = "MG7",
  3051. '8' = "ROD8",
  3052. '9' = "CONE9",
  3053. '10' = "MULG10",
  3054. '11' = "FIB_MULG_PGMT11",
  3055. '12' = "FIB12",
  3056. '13' = "MG13",
  3057. '14' = "MULG14",
  3058. '15' = "FIB_ASTR15",
  3059. '16' = "FIB_PGMT16",
  3060. '17' = "RGC_AMCR17",
  3061. '18' = "FIB18",
  3062. '19' = "FIB19",
  3063. '20' = "FIB_MEL20",
  3064. '21' = "MG21",
  3065. '22' = "MG22",
  3066. '23' = "BLOOD23",
  3067. '24' = "FIB24",
  3068. '25' = "FIB25",
  3069. '26' = "MG26",
  3070. '27' = "MULG27",
  3071. '28' = "MG28",
  3072. '29' = "MG29")
  3073. #### Label cell types
  3074. seurat_sct <- RenameIdents(object = seurat_sct,
  3075. '0' = "BPC_0",
  3076. '1' = "BPC_1",
  3077. '2' = "BPC_2",
  3078. '3' = "BPC_3",
  3079. '4' = "RGC_4",
  3080. '5' = "MG_5",
  3081. '6' = "RGC_6",
  3082. '7' = "MG_7",
  3083. '8' = "ROD_8",
  3084. '9' = "CONE_9",
  3085. '10' = "MULG_10",
  3086. '11' = "MULG_11",
  3087. '12' = "RGC_12",
  3088. '13' = "MG_13",
  3089. '14' = "MULG_14",
  3090. '15' = "MULG_15",
  3091. '16' = "PGMT_16",
  3092. '17' = "AMCR_17",
  3093. '18' = "RGC_18",
  3094. '19' = "RGC_19",
  3095. '20' = "MEL_20",
  3096. '21' = "MG_21",
  3097. '22' = "MG_22",
  3098. '23' = "RTIC_23",
  3099. '24' = "RGC_24",
  3100. '25' = "RGC_25",
  3101. '26' = "MG_26",
  3102. '27' = "MULG_27",
  3103. '28' = "MG_28",
  3104. '29' = "MG_29")
  3105. #x#### save cell type plus cluster numbers as a metadata column ####
  3106. seurat_sct[["Cluster.Type"]] <- [email hidden]
  3107. seurat_sct[["Type.Cluster"]] <- [email hidden]
  3108. saveRDS(seurat_sct, paste0(prefixPCres,"_seurat_after_RNAnorm_NEW_CELLTYPES.rds"))
  3109. seurat_sct <- readRDS(file = paste0(prefixPCres,"_seurat_after_RNAnorm_NEW_CELLTYPES.rds"))
  3110. #x#### dimplots of cell type (long name) labeled clusters ####
  3111. DimPlot(seurat_sct,
  3112. reduction = "umap",
  3113. label = TRUE,
  3114. label.size = 8,
  3115. pt.size = 1) +
  3116. NoLegend()
  3117. hirestiff(paste(prefixPCres,"UMAP","celltypesLN","hires.tiff",sep = "_"))
  3118. lowrestiff(paste(prefixPCres,"UMAP","celltypesLN","lowres.tiff",sep = "_"))
  3119. DimPlot(seurat_sct,
  3120. reduction = "umap",
  3121. label = TRUE,
  3122. label.size = 6,
  3123. pt.size = 1,
  3124. split.by = "time_point") +
  3125. NoLegend()
  3126. hirestiff(paste(prefixPCres,"UMAP","celltypesLN","by","time_point","hires.tiff",sep = "_"))
  3127. lowrestiff(paste(prefixPCres,"UMAP","celltypesLN","by","time_point","lowres.tiff",sep = "_"))
  3128. DimPlot(seurat_sct,
  3129. reduction = "umap",
  3130. label = TRUE,
  3131. label.size = 6,
  3132. pt.size = 1,
  3133. split.by = "treatment") +
  3134. NoLegend()
  3135. hirestiff(paste(prefixPCres,"UMAP","celltypesLN","by","treatment","hires.tiff",sep = "_"))
  3136. lowrestiff(paste(prefixPCres,"UMAP","celltypesLN","by","treatment","lowres.tiff",sep = "_"))
  3137. DimPlot(seurat_sct,
  3138. reduction = "umap",
  3139. label = TRUE,
  3140. label.size = 4,
  3141. pt.size = 1,
  3142. split.by = "time_point_treatment") +
  3143. NoLegend()
  3144. hirestiff(paste(prefixPCres,"UMAP","celltypesLN","by","time_point_treatment","hires.tiff",sep = "_"))
  3145. lowrestiff(paste(prefixPCres,"UMAP","celltypesLN","by","time_point_treatment","lowres.tiff",sep = "_"))
  3146. # set cluster colors
  3147. clust_cols <- scales::hue_pal()(length(levels(seurat_sct)))
  3148. names(clust_cols) <- levels(seurat_sct)
  3149. levels(seurat_sct)
  3150. # UMAP of cells in each cluster by time_point_treatment without cluster labels
  3151. DimPlot(seurat_sct,
  3152. reduction = "umap",
  3153. label = FALSE,
  3154. cols = clust_cols,
  3155. split.by = "time_point_treatment",
  3156. pt.size = 1) +
  3157. NoLegend() +
  3158. ggtitle(paste0(ident_res))
  3159. hirestiff(paste(prefixPCres,"UMAP","split_by","time_point_treatment","without_cluster_labels","hires.tiff",sep = "_"))
  3160. lowrestiff(paste(prefixPCres,"UMAP","split_by","time_point_treatment","without_cluster_labels","lowres.tiff",sep = "_"))
  3161. for (i in 1:length(levels(seurat_sct$time_point_treatment))){
  3162. p <- (DimPlot(seurat_sct,
  3163. reduction = "umap",
  3164. label = FALSE,
  3165. pt.size = 1,
  3166. cols = clust_cols,
  3167. cells = c(WhichCells(seurat_sct, expression = time_point_treatment == levels(seurat_sct$time_point_treatment)[i]))) +
  3168. NoLegend() +
  3169. ggtitle(paste0(levels(seurat_sct$time_point_treatment)[i])))
  3170. print(p)
  3171. hirestiff(paste(prefixPCres,"UMAP","split_by","time_point_treatment","no_cluster_labels",
  3172. levels(seurat_sct$time_point_treatment)[i],"hires.tiff",sep = "_"))
  3173. lowrestiff(paste(prefixPCres,"UMAP","split_by","time_point_treatment","no_cluster_labels",
  3174. levels(seurat_sct$time_point_treatment)[i],"lowres.tiff",sep = "_"))
  3175. hirestiffsquare(paste(prefixPCres,"UMAP","split_by","time_point_treatment","no_cluster_labels",
  3176. levels(seurat_sct$time_point_treatment)[i],"hires_square.tiff",sep = "_"))
  3177. lowrestiffsquare(paste(prefixPCres,"UMAP","split_by","time_point_treatment","no_cluster_labels",
  3178. levels(seurat_sct$time_point_treatment)[i],"lowres_square.tiff",sep = "_"))
  3179. }
  3180. # UMAP of cells in each cluster by time_point_treatment with cluster labels
  3181. DimPlot(seurat_sct,
  3182. reduction = "umap",
  3183. label = TRUE,
  3184. cols = clust_cols,
  3185. split.by = "time_point_treatment",
  3186. label.size = 5,
  3187. pt.size = 1) +
  3188. NoLegend() +
  3189. ggtitle(paste0(ident_res))
  3190. hirestiff(paste(prefixPCres,"UMAP","split_by","time_point_treatment","with_cluster_labels","hires.tiff",sep = "_"))
  3191. lowrestiff(paste(prefixPCres,"UMAP","split_by","time_point_treatment","with_cluster_labels","lowres.tiff",sep = "_"))
  3192. for (i in 1:length(levels(seurat_sct$time_point_treatment))){
  3193. p <- (DimPlot(seurat_sct,
  3194. reduction = "umap",
  3195. label = TRUE,
  3196. label.size = 8,
  3197. pt.size = 1,
  3198. cols = clust_cols,
  3199. cells = c(WhichCells(seurat_sct, expression = time_point_treatment == levels(seurat_sct$time_point_treatment)[i]))) +
  3200. NoLegend() +
  3201. ggtitle(paste0(levels(seurat_sct$time_point_treatment)[i])))
  3202. print(p)
  3203. hirestiff(paste(prefixPCres,"UMAP","split_by","time_point_treatment","with_cluster_labels",
  3204. levels(seurat_sct$time_point_treatment)[i],"hires.tiff",sep = "_"))
  3205. lowrestiff(paste(prefixPCres,"UMAP","split_by","time_point_treatment","with_cluster_labels",
  3206. levels(seurat_sct$time_point_treatment)[i],"lowres.tiff",sep = "_"))
  3207. hirestiffsquare(paste(prefixPCres,"UMAP","split_by","time_point_treatment","with_cluster_labels",
  3208. levels(seurat_sct$time_point_treatment)[i],"hires_square.tiff",sep = "_"))
  3209. lowrestiffsquare(paste(prefixPCres,"UMAP","split_by","time_point_treatment","with_cluster_labels",
  3210. levels(seurat_sct$time_point_treatment)[i],"lowres_square.tiff",sep = "_"))
  3211. }
  3212. # UMAP of cells in each cluster by time_point_treatment with no cluster labels plus legend
  3213. DimPlot(seurat_sct,
  3214. reduction = "umap",
  3215. label = FALSE,
  3216. cols = clust_cols,
  3217. label.size = 5,
  3218. pt.size = 1) +
  3219. ggtitle(paste0(ident_res))
  3220. hirestiff(paste(prefixPCres,"UMAP","with_no_labels_plus_legend","hires.tiff",sep = "_"))
  3221. lowrestiff(paste(prefixPCres,"UMAP","with_no_labels_plus_legend","lowres.tiff",sep = "_"))
  3222. DimPlot(seurat_sct,
  3223. reduction = "umap",
  3224. label = FALSE,
  3225. cols = clust_cols,
  3226. split.by = "time_point_treatment",
  3227. label.size = 5,
  3228. pt.size = 1) +
  3229. ggtitle(paste0(ident_res))
  3230. hirestiff(paste(prefixPCres,"UMAP","split_by","time_point_treatment","with_no_labels_plus_legend","hires.tiff",sep = "_"))
  3231. lowrestiff(paste(prefixPCres,"UMAP","split_by","time_point_treatment","with_no_labels_plus_legend","lowres.tiff",sep = "_"))
  3232. for (i in 1:length(levels(seurat_sct$time_point_treatment))){
  3233. p <- (DimPlot(seurat_sct,
  3234. reduction = "umap",
  3235. label = FALSE,
  3236. label.size = 8,
  3237. pt.size = 1,
  3238. cols = clust_cols,
  3239. cells = c(WhichCells(seurat_sct, expression = time_point_treatment == levels(seurat_sct$time_point_treatment)[i]))) +
  3240. ggtitle(paste0(levels(seurat_sct$time_point_treatment)[i])))
  3241. print(p)
  3242. hirestiff(paste(prefixPCres,"UMAP","split_by","time_point_treatment","with_no_labels_plus_legend",
  3243. levels(seurat_sct$time_point_treatment)[i],"hires.tiff",sep = "_"))
  3244. lowrestiff(paste(prefixPCres,"UMAP","split_by","time_point_treatment","with_no_labels_plus_legend",
  3245. levels(seurat_sct$time_point_treatment)[i],"lowres.tiff",sep = "_"))
  3246. hirestiffsquare(paste(prefixPCres,"UMAP","split_by","time_point_treatment","with_no_labels_plus_legend",
  3247. levels(seurat_sct$time_point_treatment)[i],"hires_square.tiff",sep = "_"))
  3248. lowrestiffsquare(paste(prefixPCres,"UMAP","split_by","time_point_treatment","with_no_labels_plus_legend",
  3249. levels(seurat_sct$time_point_treatment)[i],"lowres_square.tiff",sep = "_"))
  3250. }
  3251. rm(p,i)
  3252. #### Extract number of cells per cluster per orig.ident ####
  3253. n_cells <- FetchData(seurat_sct, vars = c("ident", "orig.ident")) %>%
  3254. dplyr::count(ident, orig.ident) %>%
  3255. tidyr::spread(ident, n)
  3256. n_cells
  3257. write.csv(n_cells, file = paste0(prefixPCres,"_celltypes_per_sample.csv"))
  3258. rm(n_cells)
  3259. #### switch between cluster numbers and cell type idents ####
  3260. Idents(seurat_sct) <- ident_res
  3261. Idents(seurat_sct) <- "Cell.Type"
  3262. # Idents(seurat_sct) <- "Cell.Type.Long"
  3263. #
  3264. # Idents(seurat_sct) <- "Cluster.Type"
  3265. #
  3266. # Idents(seurat_sct) <- "Type.Cluster"
  3267. #### check which ident is active by dimplot ####
  3268. unique(sort([email hidden]))
  3269. view([email hidden])
  3270. DimPlot(seurat_sct,
  3271. reduction = "umap",
  3272. label = TRUE,
  3273. label.size = 5,
  3274. pt.size = 1,
  3275. raster = F) +
  3276. NoLegend()
  3277. DimPlot(seurat_sct,
  3278. reduction = "umap",
  3279. label = TRUE,
  3280. label.size = 5,
  3281. pt.size = 1,
  3282. cells.highlight = WhichCells(seurat_sct, idents = "Rods")) +
  3283. NoLegend()
  3284. DimPlot(seurat_sct,
  3285. reduction = "umap",
  3286. label = TRUE,
  3287. label.size = 5,
  3288. pt.size = 1,
  3289. cells.highlight = WhichCells(seurat_sct, idents = "Cones")) +
  3290. NoLegend()
  3291. DimPlot(seurat_sct,
  3292. reduction = "umap",
  3293. label = TRUE,
  3294. label.size = 5,
  3295. pt.size = 1,
  3296. cols = palopal) +
  3297. NoLegend()
  3298. #### save RDS containing RNA normalized data AND CELLTYPE LABELS ####
  3299. # saveRDS(seurat_sct, paste0(prefixPCres,"_seurat_after_RNAnorm_CELLTYPES.rds"))
  3300. seurat_sct <- readRDS(file = paste0(prefixPCres,"_seurat_after_RNAnorm_CELLTYPES.rds"))
  3301. seurat_sct <- readRDS("~/Desktop/DEG_and_Pathway_Analysis/20230922_rat_retina_with_GEO/20230922_Rat_retina_with_GEO_int_12PCs_res.0.5_seurat_after_RNAnorm_CELLTYPES.rds")
  3302. View([email hidden])
  3303. DimPlot(seurat_sct, reduction = 'umap', group.by = "Cell.Type", split.by = "treatment",label = T, pt.size = 0.5, raster=FALSE)
  3304. #### save seurat object as an hdf5 file for import into python ####
  3305. SaveH5Seurat(seurat_sct,
  3306. filename = paste(prefixPCres,"H5seurat_obj.H5seurat",sep = "_"),
  3307. overwrite = FALSE,
  3308. verbose = TRUE)
  3309. #### Find Cluster Markers for all cells as celltypes ####
  3310. # find all markers
  3311. cluster_markers <- FindAllMarkers(seurat_sct,
  3312. only.pos = TRUE,
  3313. min.pct = 0.50,
  3314. logfc.threshold = 0.4)
  3315. write.csv(cluster_markers,
  3316. file = paste(prefixPCres,"clustermarkers_CELLTYPES_pos_only_minpct0.50_logfcthresh0.4.csv", sep = "_"))
  3317. #### find DEGs between treatments regardless of cell type ####
  3318. Idents(object = seurat_sct) <- "treatment"
  3319. cluster_markers <- FindAllMarkers(seurat_sct,
  3320. only.pos = TRUE,
  3321. min.pct = 0.25,
  3322. logfc.threshold = 0.4)
  3323. write.csv(cluster_markers, file =
  3324. paste(prefixPCres,"degs_treatment_all_cells_minpct0.25_logfcthresh0.4.csv", sep = "_"))
  3325. Idents(object = seurat_sct) <- ident_res
  3326. #### find DEGs between time points regardless of cell type ####
  3327. Idents(object = seurat_sct) <- "time_point"
  3328. cluster_markers <- FindAllMarkers(seurat_sct,
  3329. only.pos = TRUE,
  3330. min.pct = 0.25,
  3331. logfc.threshold = 0.4)
  3332. write.csv(cluster_markers, file =
  3333. paste(prefixPCres,"degs_timepoint_all_cells_minpct0.25_logfcthresh0.4.csv", sep = "_"))
  3334. Idents(object = seurat_sct) <- ident_res
  3335. #### find DEGs between time points and treatment regardless of cell type ####
  3336. Idents(object = seurat_sct) <- "time_point_treatment"
  3337. cluster_markers <- FindAllMarkers(seurat_sct,
  3338. only.pos = TRUE,
  3339. min.pct = 0.25,
  3340. logfc.threshold = 0.4)
  3341. write.csv(cluster_markers, file =
  3342. paste(prefixPCres,"degs_timepoint_treatment_all_cells_minpct0.25_logfcthresh0.4.csv", sep = "_"))
  3343. Idents(object = seurat_sct) <- ident_res
  3344. Idents(object = seurat_sct) <- "Cell.Type"
  3345. #### for loop for DEGs within clusters TR vs UT ####
  3346. clusterlist <- c(levels([email hidden]$Cell.Type))
  3347. clusterlist
  3348. length(clusterlist)
  3349. for (k in 1:length(clusterlist)){
  3350. message(crayon::red(paste("Calculating DEGs within",
  3351. clusterlist[k],
  3352. sep = " ")))
  3353. nam <- paste("clusterDEG_TR_vs_UT", clusterlist[k], sep = "_")
  3354. assign(nam, FindMarkers(seurat_sct,
  3355. ident.1 = "Cell_Treated",
  3356. group.by = "treatment",
  3357. subset.ident = clusterlist[k]))
  3358. write.csv(get(nam), file = paste(prefixPCres,
  3359. nam,
  3360. "list.csv",
  3361. sep = "_"),
  3362. row.names = TRUE)
  3363. }
  3364. # positive LFC means upregulation in Cell_Treated cells
  3365. #### for loop for DEGs within clusters by time_point ####
  3366. # get the name of clusters
  3367. clusterlist <- c(levels([email hidden]$Cell.Type))
  3368. clusterlist
  3369. # set the groups to compare
  3370. grouplist <- c(levels([email hidden]$time_point))
  3371. grouplist <- c(grouplist, grouplist[1])
  3372. grouplist
  3373. for (i in 1:(length(grouplist)-1)){
  3374. for (k in 1:length(clusterlist)){
  3375. message(crayon::red(paste("Calculating DEGs between",
  3376. grouplist[i],
  3377. "and",
  3378. grouplist[i+1],
  3379. "within the",
  3380. clusterlist[k],
  3381. "cluster",
  3382. sep = " ")))
  3383. nam <- paste("clusterDEG",
  3384. grouplist[i],
  3385. "vs",
  3386. grouplist[i+1],
  3387. "in",
  3388. clusterlist[k],
  3389. sep = "_")
  3390. assign(nam, FindMarkers(seurat_sct,
  3391. ident.1 = grouplist[i],
  3392. ident.2 = grouplist[i+1],
  3393. group.by = "time_point",
  3394. subset.ident = clusterlist[k]))
  3395. write.csv(get(nam), file = paste(prefixPCres,
  3396. nam,
  3397. "list.csv",
  3398. sep = "_"),
  3399. row.names = TRUE)
  3400. }
  3401. }
  3402. #### for loop for DEGs within clusters by time_point ####
  3403. # get the name of clusters
  3404. clusterlist <- c(levels([email hidden]$Cell.Type))
  3405. clusterlist
  3406. # set the groups to compare
  3407. grouplist <- c(levels([email hidden]$time_point_treatment))
  3408. grouplist
  3409. # Loop through each pair of groups (i vs j)
  3410. for (i in 1:(length(grouplist)-1)){
  3411. for (j in (i+1):length(grouplist)){
  3412. group1 <- grouplist[i]
  3413. group2 <- grouplist[j]
  3414. # Run find markers on group1 and group2 for each element of clusterlist
  3415. # print the comparison to the terminal
  3416. for (k in 1:length(clusterlist)){
  3417. message(crayon::red(paste("Calculating DEGs between",
  3418. group1,
  3419. "and",
  3420. group2,
  3421. "within the",
  3422. clusterlist[k],
  3423. "cluster",
  3424. sep = " ")))
  3425. # create the results variable unique to each pair of groups and
  3426. # element of clusterlist
  3427. nam <- paste("clusterDEG",
  3428. group1,
  3429. "vs",
  3430. group2,
  3431. "in",
  3432. clusterlist[k],
  3433. sep = "_")
  3434. # run FindMarkers and save results in the "nam" variable
  3435. assign(nam, FindMarkers(seurat_sct,
  3436. ident.1 = group1,
  3437. ident.2 = group2,
  3438. group.by = "time_point_treatment",
  3439. subset.ident = clusterlist[k]))
  3440. # write out the results
  3441. write.csv(get(nam), file = paste(prefixPCres,
  3442. nam,
  3443. "list.csv",
  3444. sep = "_"),
  3445. row.names = TRUE)
  3446. }
  3447. }
  3448. }
  3449. #### subsets for further DEG analysis ####
  3450. # subset seurat obj by time point for treated vs untreated DEGs
  3451. Idents(seurat_sct) <- "time_point"
  3452. p60seurat <- subset(seurat_sct, idents = "p60")
  3453. rm(seurat_sct)
  3454. p90seurat <- subset(seurat_sct, idents = "p90")
  3455. Idents(p90seurat) <- "Cell.Type"
  3456. Cone_p90seurat <- subset(p90seurat, idents = "CONE")
  3457. Cone <- subset(Cone_p90seurat, subset = Arr3 > .5)
  3458. CONE <- WhichCells(object=Cone_p90seurat, expression = Arr3 > .5)
  3459. Idents(Cone) <- "treatment"
  3460. Cone_DEG <- FindMarkers(Cone,
  3461. logfc.threshold = 0.2,
  3462. min.pct = 0.2,
  3463. ident.1 = "Cell_Treated",
  3464. ident.2 = "Untreated")
  3465. setwd("~/Desktop/DEG_and_Pathway_Analysis/Rat_DEGs/RAT_Pathway_analysis_V5")
  3466. write.csv(Cone_DEG,"Cone_p90seurat1.csv")
  3467. Cone_DEG1 <- FindMarkers(Cone,
  3468. ident.1 = "Cell_Treated",
  3469. ident.2 = "Untreated")
  3470. write.csv(Cone_DEG1,"Cone_p90seurat.csv")
  3471. VlnPlot(Cone, features = "Tyrobp", pt.size=0)
  3472. FeaturePlot(Cone, features = "Apoe", min.cutoff = "q9", split.by = "treatment", cols = c("grey", "blue"), pt.size = .8)
  3473. DimPlot(p90seurat, reduction = 'umap', group.by = "Cell.Type", split.by = "treatment", label = T, pt.size = 0.5, raster=FALSE)
  3474. DimPlot(Cone_p90seurat, reduction = 'umap', split.by = "treatment", label = T, pt.size = 0.5, raster=FALSE)
  3475. View([email hidden])
  3476. View([email hidden])
  3477. Idents(p60seurat) <- "treatment"
  3478. cluster_markers <- FindAllMarkers(p60seurat, only.pos = TRUE, min.pct = 0.25, logfc.threshold = 0.4)
  3479. write.csv(cluster_markers, file =
  3480. paste(prefixPCres,"degs_treatment_p60_minpct0.25_logfcthresh0.4.csv", sep = "_"))
  3481. Idents(p90seurat) <- "treatment"
  3482. cluster_markers <- FindAllMarkers(p90seurat, only.pos = TRUE, min.pct = 0.25, logfc.threshold = 0.4)
  3483. write.csv(cluster_markers, file =
  3484. paste(prefixPCres,"degs_treatment_p90_minpct0.25_logfcthresh0.4.csv", sep = "_"))
  3485. # subset seurat obj by treatment for p60 vs p90 DEGs
  3486. Idents(seurat_sct) <- "treatment"
  3487. TRseurat <- subset(seurat_sct, idents = "Cell_Treated")
  3488. [email hidden] <- droplevels([email hidden])
  3489. UTseurat <- subset(seurat_sct, idents = "Untreated")
  3490. [email hidden] <- droplevels([email hidden])
  3491. Idents(UTseurat) <- "time_point_treatment"
  3492. UTseuratp60p90 <- subset(UTseurat,
  3493. idents = "WT_Untreated",
  3494. invert = T)
  3495. [email hidden] <- droplevels([email hidden])
  3496. Idents(object = seurat_sct) <- "Cell.Type"
  3497. # Idents(object = p60seurat) <- "Cell.Type"
  3498. # Idents(object = p90seurat) <- "Cell.Type"
  3499. Idents(object = TRseurat) <- "Cell.Type"
  3500. Idents(object = UTseurat) <- "Cell.Type"
  3501. Idents(object = UTseuratp60p90) <- "Cell.Type"
  3502. DimPlot(seurat_sct,
  3503. reduction = "umap",
  3504. label = TRUE,
  3505. label.size = 5,
  3506. pt.size = 1,
  3507. raster = F) +
  3508. NoLegend()
  3509. DimPlot(TRseurat,
  3510. reduction = "umap",
  3511. label = TRUE,
  3512. label.size = 5,
  3513. pt.size = 1,
  3514. raster = F) +
  3515. NoLegend()
  3516. DimPlot(UTseurat,
  3517. reduction = "umap",
  3518. label = TRUE,
  3519. label.size = 5,
  3520. pt.size = 1,
  3521. raster = F) +
  3522. NoLegend()
  3523. DimPlot(UTseuratp60p90,
  3524. reduction = "umap",
  3525. label = TRUE,
  3526. label.size = 5,
  3527. pt.size = 1,
  3528. raster = F) +
  3529. NoLegend()
  3530. #### DEGs in RODS Treated p60 vs p90 ####
  3531. rod_tr_tp_markers <- FindMarkers(TRseurat,
  3532. logfc.threshold = 0.4,
  3533. min.pct = 0.25,
  3534. only.pos = F,
  3535. ident.1 = "p60",
  3536. group.by = "time_point",
  3537. subset.ident = "ROD")
  3538. write.csv(rod_tr_tp_markers, file =
  3539. paste(prefixPCres,"degs_ROD_p60_TR_vs_p90_TR",
  3540. "minpct0.25_logfcthresh0.4.csv", sep = "_"))
  3541. #### DEGs in RODS Untreated p60 vs p90 ####
  3542. rod_ut_tp_markers <- FindMarkers(UTseuratp60p90,
  3543. logfc.threshold = 0.4,
  3544. min.pct = 0.25,
  3545. only.pos = F,
  3546. ident.1 = "p60",
  3547. group.by = "time_point",
  3548. subset.ident = "ROD")
  3549. write.csv(rod_tr_tp_markers, file =
  3550. paste(prefixPCres,"degs_ROD_p60_UT_vs_p90_UT",
  3551. "minpct0.25_logfcthresh0.4.csv", sep = "_"))
  3552. #### DEGs in CONES Treated p60 vs p90 ####
  3553. cone_tr_tp_markers <- FindMarkers(TRseurat,
  3554. logfc.threshold = 0.4,
  3555. min.pct = 0.25,
  3556. only.pos = F,
  3557. ident.1 = "p60",
  3558. group.by = "time_point",
  3559. subset.ident = "CONE")
  3560. write.csv(cone_tr_tp_markers, file =
  3561. paste(prefixPCres,"degs_CONE_p60_TR_vs_p90_TR",
  3562. "minpct0.25_logfcthresh0.4.csv", sep = "_"))
  3563. #### DEGs in CONES Untreated p60 vs p90 ####
  3564. cone_ut_tp_markers <- FindMarkers(UTseuratp60p90,
  3565. logfc.threshold = 0.4,
  3566. min.pct = 0.25,
  3567. only.pos = F,
  3568. ident.1 = "p60",
  3569. group.by = "time_point",
  3570. subset.ident = "CONE")
  3571. write.csv(cone_tr_tp_markers, file =
  3572. paste(prefixPCres,"degs_CONE_p60_UT_vs_p90_UT",
  3573. "minpct0.25_logfcthresh0.4.csv", sep = "_"))
  3574. #### DEGs in MULG Treated p60 vs p90 ####
  3575. mulg_tr_tp_markers <- FindMarkers(TRseurat,
  3576. logfc.threshold = 0.4,
  3577. min.pct = 0.25,
  3578. only.pos = F,
  3579. ident.1 = "p60",
  3580. group.by = "time_point",
  3581. subset.ident = "MULG")
  3582. write.csv(mulg_tr_tp_markers, file =
  3583. paste(prefixPCres,"degs_MULG_p60_TR_vs_p90_TR",
  3584. "minpct0.25_logfcthresh0.4.csv", sep = "_"))
  3585. #### DEGs in MULG Untreated p60 vs p90 ####
  3586. mulg_ut_tp_markers <- FindMarkers(UTseuratp60p90,
  3587. logfc.threshold = 0.4,
  3588. min.pct = 0.25,
  3589. only.pos = F,
  3590. ident.1 = "p60",
  3591. group.by = "time_point",
  3592. subset.ident = "MULG")
  3593. write.csv(mulg_tr_tp_markers, file =
  3594. paste(prefixPCres,"degs_MULG_p60_UT_vs_p90_UT",
  3595. "minpct0.25_logfcthresh0.4.csv", sep = "_"))
  3596. #### save subset objects ####
  3597. saveRDS(p60seurat, paste0(prefixPCres,"_p60_seurat.rds"))
  3598. # p60seurat <- readRDS(file = paste0(prefixPCres,"_p60_seurat.rds"))
  3599. saveRDS(p90seurat, paste0(prefixPCres,"_p90_seurat.rds"))
  3600. p90seurat <- readRDS(file = paste0(prefixPCres,"_p90_seurat.rds"))
  3601. saveRDS(TRseurat, paste0(prefixPCres,"_cell_treated_seurat.rds"))
  3602. # TRseurat <- readRDS(file = paste0(prefixPCres,"_cell_treated_seurat.rds"))
  3603. saveRDS(UTseurat, paste0(prefixPCres,"_untreated_seurat.rds"))
  3604. # UTseurat <- readRDS(file = paste0(prefixPCres,"_untreated_seurat.rds"))
  3605. #### p60 TR vs UT DEGs within cell types ####
  3606. Idents(p60seurat) <- "Cell.Type"
  3607. clusterlist <- c(levels([email hidden]$Cell.Type))
  3608. clusterlist
  3609. for (k in 1:length(clusterlist)){
  3610. nam <- paste("p60",
  3611. "clusterDEG_treatment",
  3612. clusterlist[k], sep = "_")
  3613. assign(nam, FindMarkers(p60seurat,
  3614. ident.1 = "Cell_Treated",
  3615. group.by = "treatment",
  3616. subset.ident = clusterlist[k]))
  3617. write.csv(get(nam),
  3618. file = paste(prefixPCres,
  3619. nam,
  3620. "list.csv",
  3621. sep = "_"),
  3622. row.names = TRUE)
  3623. }
  3624. # positive LFC means upregulation in Cell_Treated cells
  3625. #### p90 TR vs UT DEGs within cell types ####
  3626. Idents(p90seurat) <- "Cell.Type"
  3627. clusterlist <- c(levels([email hidden]$Cell.Type))
  3628. clusterlist
  3629. for (k in 1:length(clusterlist)){
  3630. nam <- paste("p90",
  3631. "clusterDEG_treatment",
  3632. clusterlist[k], sep = "_")
  3633. assign(nam, FindMarkers(p90seurat,
  3634. ident.1 = "Cell_Treated",
  3635. group.by = "treatment",
  3636. subset.ident = clusterlist[k]))
  3637. write.csv(get(nam),
  3638. file = paste(prefixPCres,
  3639. nam,
  3640. "list.csv",
  3641. sep = "_"),
  3642. row.names = TRUE)
  3643. }
  3644. # positive LFC means upregulation in Cell_Treated cells
  3645. #### ACTIONet ####
  3646. library(ACTIONet)
  3647. library(SingleCellExperiment)
  3648. # convert seurat object to a single cell experiment
  3649. sce <- Seurat::as.SingleCellExperiment(seurat_sct)
  3650. # convert single cell experiment to an ACTIONet experiment
  3651. ace <- as.ACTIONetExperiment(sce)
  3652. ace = normalize.ace(ace)
  3653. ace = reduce.ace(ace)
  3654. ace = runACTIONet(ace)
  3655. # Annotate cell-types
  3656. data("curatedMarkers_human")
  3657. # markers = c(curatedMarkers_human$Brain$PFC$Mohammadi2020$marker.genes,
  3658. # curatedMarkers_human$Brain$PFC$Velmeshev2019$marker.genes,
  3659. # curatedMarkers_human$Brain$PFC$Schirmer2019$marker.genes,
  3660. # curatedMarkers_human$Brain$PFC$MathysDavila2019$marker.genes,
  3661. # curatedMarkers_human$Brain$PFC$Wang2018$marker.genes,
  3662. # curatedMarkers_human$Brain$PFC$Layers$marker.genes)
  3663. markers <- c(curatedMarkers_human$Retina$marker.genes)
  3664. # List of human gene names
  3665. markers
  3666. h1 <- markers$Rods
  3667. h2 <- markers$Cones
  3668. h3 <- markers$RGCs
  3669. h4 <- markers$BPs
  3670. h5 <- markers$ACs
  3671. h6 <- markers$HCs
  3672. h7 <- markers$Macroglia
  3673. h8 <- markers$Microglia
  3674. h9 <- markers$Endo
  3675. #### convert human genes to rat genes ####
  3676. # Load the biomaRt library
  3677. library(biomaRt)
  3678. # convert human to rat gene names
  3679. # listEnsemblArchives()
  3680. # https://oct2022.archive.ensembl.org DIDN"T WORK
  3681. # https://jul2022.archive.ensembl.org DIDN"T WORK
  3682. # https://apr2022.archive.ensembl.org DIDN"T WORK
  3683. # https://dec2021.archive.ensembl.org THIS ONE WORKED
  3684. # https://may2021.archive.ensembl.org
  3685. human <- useMart("ensembl",
  3686. dataset = "hsapiens_gene_ensembl",
  3687. host = "https://dec2021.archive.ensembl.org")
  3688. rat <- useMart("ensembl",
  3689. dataset = "rnorvegicus_gene_ensembl",
  3690. host = "https://dec2021.archive.ensembl.org")
  3691. r1 = getLDS(attributes = c("hgnc_symbol"),
  3692. filters = "hgnc_symbol",
  3693. values = h1,
  3694. mart = human,
  3695. attributesL = c("rgd_symbol"),
  3696. martL = rat,
  3697. uniqueRows=T)
  3698. r2 <- getLDS(attributes = c("hgnc_symbol"),
  3699. filters = "hgnc_symbol",
  3700. values = h2,
  3701. mart = human,
  3702. attributesL = c("rgd_symbol"),
  3703. martL = rat,
  3704. uniqueRows=T)
  3705. r3 <- getLDS(attributes = c("hgnc_symbol"),
  3706. filters = "hgnc_symbol",
  3707. values = h3,
  3708. mart = human,
  3709. attributesL = c("rgd_symbol"),
  3710. martL = rat,
  3711. uniqueRows=T)
  3712. r4 <- getLDS(attributes = c("hgnc_symbol"),
  3713. filters = "hgnc_symbol",
  3714. values = h4,
  3715. mart = human,
  3716. attributesL = c("rgd_symbol"),
  3717. martL = rat,
  3718. uniqueRows=T)
  3719. r5 <- getLDS(attributes = c("hgnc_symbol"),
  3720. filters = "hgnc_symbol",
  3721. values = h5,
  3722. mart = human,
  3723. attributesL = c("rgd_symbol"),
  3724. martL = rat,
  3725. uniqueRows=T)
  3726. r6 <- getLDS(attributes = c("hgnc_symbol"),
  3727. filters = "hgnc_symbol",
  3728. values = h6,
  3729. mart = human,
  3730. attributesL = c("rgd_symbol"),
  3731. martL = rat,
  3732. uniqueRows=T)
  3733. r7 <- getLDS(attributes = c("hgnc_symbol"),
  3734. filters = "hgnc_symbol",
  3735. values = h7,
  3736. mart = human,
  3737. attributesL = c("rgd_symbol"),
  3738. martL = rat,
  3739. uniqueRows=T)
  3740. r8 <- getLDS(attributes = c("hgnc_symbol"),
  3741. filters = "hgnc_symbol",
  3742. values = h8,
  3743. mart = human,
  3744. attributesL = c("rgd_symbol"),
  3745. martL = rat,
  3746. uniqueRows=T)
  3747. r9 <- getLDS(attributes = c("hgnc_symbol"),
  3748. filters = "hgnc_symbol",
  3749. values = h9,
  3750. mart = human,
  3751. attributesL = c("rgd_symbol"),
  3752. martL = rat,
  3753. uniqueRows=T)
  3754. #### make rat reference list ####
  3755. rat_markers <- list()
  3756. rat_markers$Rods <- r1$RGD.symbol
  3757. rat_markers$Cones <- r2$RGD.symbol
  3758. rat_markers$RGCs <- r3$RGD.symbol
  3759. rat_markers$BPs <- r4$RGD.symbol
  3760. rat_markers$ACs <- r5$RGD.symbol
  3761. rat_markers$HCs <- r6$RGD.symbol
  3762. rat_markers$Macroglia <- r7$RGD.symbol
  3763. rat_markers$Microglia <- r8$RGD.symbol
  3764. rat_markers$Endo <- r9$RGD.symbol
  3765. rat_markers
  3766. rat_markers$Rods <- c("Ahi1","Rho","Gnat1","Nrl","Nr2e3",
  3767. "Pde6a","Pde6b","Cngb1","Pdc","Rp1",
  3768. "Guca1a","Scaper","Ppef2")
  3769. rat_markers$Cones <- c("Arr3","Opn1mw","Opn1sw","Gnat2","Pde6h")
  3770. rat_markers$Mueller <- c("Glul","Rlbp1","Zfp36l1","Dbi","Apoe",
  3771. "Slc1a3","Sparc","Gfap","Aqp4","Gpr37",
  3772. "S100b")
  3773. rat_markers$BPs <- c("Scgn","Vsx1","Vsx2","Pcp2","Isl1",
  3774. "Grm6","Trnp1","Tmem215","Prkca","Camk2b")
  3775. rat_markers$ACs <- c("Calb1","Gad1","Gad2","C1ql1","C1ql2",
  3776. "Snhg11","Tfap2b","Tfap2c","Pcsk1n","Slc6a9")
  3777. rat_markers$HCs <- c("Onecut1","Onecut2","Lhx1","Slc4a3","Calb1",
  3778. "Septin4","Tpm3")
  3779. rat_markers$Macroglia <- c("Apoe","Slc1a3","Trpm3","Glul","Clu" )
  3780. rat_markers$Microglia <- c("Aif1","Tyrobp","Cx3cr1","Tmem119","Ctsd",
  3781. "Ccl4","C1qa","C1qb","C1qc","Cd163")
  3782. rat_markers$RGCs <- c("Rbpms","Pou4f1","Pou4f2","Slc17a6","Nefm",
  3783. "Nefl","Sncg" )
  3784. # rat_markers$Endo <- c("Tm4sf1","Apold1","Adamts9","Igfbp7","Cd34",
  3785. # "Rgs5","Cldn5","Cdh5")
  3786. # rat_markers$RPEpi <- c("Mitf","Tjp1","Rpe65","Rlbp1","Best1")
  3787. # rat_markers$Vascular <- c("Trpm1","Igfbp7")
  3788. # rat_markers$Pericytes <- c("Pecam1","Acta2")
  3789. rat_markers$Ret <- c("Hbb-bs")
  3790. rat_markers
  3791. #### annotate cells and export results to original seurat object ####
  3792. annot.out <- annotate.cells.using.markers(ace, rat_markers)
  3793. ace$ACEcelltypes <- annot.out$Label
  3794. # Export results to the seurat object as a new metadata column
  3795. seurat_sct[["ACEcelltypes"]] <- ace$ACEcelltypes
  3796. # rm(h1,h2,h3,h4,h5,h6,h7,h8,h9,
  3797. # r1,r2,r3,r4,r5,r6,r7,r8,r9,
  3798. # markers,rat_markers,human,rat,sce,
  3799. # curatedMarkers_human,annot.out,ace)
  3800. #### switch to ACEcelltypes ####
  3801. Idents(seurat_sct) <- "ACEcelltypes"
  3802. DimPlot(seurat_sct,
  3803. reduction = "umap",
  3804. label = TRUE,
  3805. label.size = 7,
  3806. pt.size = 1)
  3807. #### Module Scores for custom gene sets ####
  3808. irm_1125 <- read.csv("/Users/bells/Library/CloudStorage/Box-Box/20201124_MG_scRNAseq(old)/gene_module_lists/IRM_11_25.csv", header = FALSE)
  3809. irm_1125$V1 <- as.character(irm_1125$V1)
  3810. irm_1125 <- list(irm_1125$V1)
  3811. seurat_sct <- AddModuleScore(object = seurat_sct, features = irm_1125, search = TRUE, name = "IRM_11_25")
  3812. arm_pos_1125 <- read.csv("/Users/bells/Library/CloudStorage/Box-Box/20201124_MG_scRNAseq(old)/gene_module_lists/ARM_POS_11_25.csv", header = FALSE)
  3813. arm_pos_1125$V1 <- as.character(arm_pos_1125$V1)
  3814. arm_pos_1125 <- list(arm_pos_1125$V1)
  3815. seurat_sct <- AddModuleScore(object = seurat_sct, features = arm_pos_1125, search = TRUE, name = "ARM_POS_11_25")
  3816. arm_neg_1125 <- read.csv("/Users/bells/Library/CloudStorage/Box-Box/20201124_MG_scRNAseq(old)/gene_module_lists/ARM_NEG_11_25.csv", header = FALSE)
  3817. arm_neg_1125$V1 <- as.character(arm_neg_1125$V1)
  3818. arm_neg_1125 <- list(arm_neg_1125$V1)
  3819. seurat_sct <- AddModuleScore(object = seurat_sct, features = arm_neg_1125, search = TRUE, name = "ARM_NEG_11_25")
  3820. default_FP(seurat_sct,"IRM_11_251")
  3821. default_FP(seurat_sct,"ARM_POS_11_251")
  3822. default_FP(seurat_sct,"ARM_NEG_11_251")
  3823. #### expression values for genes of interest ####
  3824. expression_data <- FetchData(object = seurat_sct,
  3825. vars = c("genotype",ident_res,"Cell.Type",
  3826. "ISL1","NEFL","NEFM",
  3827. "NEFH","NGRN","PRPH","ELAVL3",
  3828. "PFKP","RCAN1","SELPLG","STMN2","TARDBP"))
  3829. write.csv(expression_data,
  3830. file = paste(prefixPCres,"expression","in_all_cells","by_genotype.csv", sep = "_"))
  3831. #### VENN compare DEG gene lists ####
  3832. setwd(datadir)
  3833. # load data and convert the output "list" to a tibble
  3834. # with the rownames converted to a column with the name "symbol"
  3835. p60_tr_vs_ut <- read.csv(file = "./20230327_Rat_retina_int_12PCs_res.0.2_degs_treatment_p60_minpct0.25_logfcthresh0.4.csv",
  3836. header = TRUE)
  3837. colnames(p60_tr_vs_ut) <- c("symbol","p_val","ave_log2FC","pct.1","pct.2","p_val_adj","cluster","gene")
  3838. p90_tr_vs_ut <- read.csv(file = "./20230327_Rat_retina_int_12PCs_res.0.2_degs_treatment_p90_minpct0.25_logfcthresh0.4.csv",
  3839. header = TRUE)
  3840. colnames(p90_tr_vs_ut) <- c("symbol","p_val","ave_log2FC","pct.1","pct.2","p_val_adj","cluster","gene")
  3841. p60_tr_vs_ut <- as_tibble(p60_tr_vs_ut)
  3842. p90_tr_vs_ut <- as_tibble(p90_tr_vs_ut)
  3843. # split tibbles by "cluster" and p_val_adj < 0.05
  3844. p60_up_in_tr <- filter(p60_tr_vs_ut, cluster == "Cell_Treated" & p_val_adj < 0.05)
  3845. p60_up_in_ut <- filter(p60_tr_vs_ut, cluster == "Untreated" & p_val_adj < 0.05)
  3846. p90_up_in_tr <- filter(p90_tr_vs_ut, cluster == "Cell_Treated" & p_val_adj < 0.05)
  3847. p90_up_in_ut <- filter(p90_tr_vs_ut, cluster == "Untreated" & p_val_adj < 0.05)
  3848. # venn diagrams of overlapping genes
  3849. ### Up in Treated condition ###
  3850. treated_up <- list(p60_up_in_tr$gene,p90_up_in_tr$gene)
  3851. names(treated_up) <- c("p60_Up_in_Cell_Treated","p90_Up_in_Cell_Treated")
  3852. venn_treated_up <- Venn(treated_up)
  3853. plot(venn_treated_up, doWeights = TRUE, type = "circles")
  3854. v1 <- compute.Venn(venn_treated_up, doWeights = TRUE, type = "circles")
  3855. # change default labels
  3856. setlabels <- VennGetSetLabels(v1)
  3857. setlabels
  3858. facelabels <- VennGetFaceLabels(v1)
  3859. facelabels
  3860. universe <- VennGetUniverseRange(v1)
  3861. universe
  3862. # setlabels[setlabels$Label=="p60_Up_in_Cell_Treated","hjust"] <- "right"
  3863. # setlabels[setlabels$Label=="p90_Up_in_Cell_Treated","hjust"] <- "left"
  3864. # setlabels[setlabels$Label=="YoungV_vs_iMACS_13","x"] <- -1.5
  3865. # setlabels
  3866. # v1 <- VennSetSetLabels(v1,setlabels)
  3867. grid::grid.newpage()
  3868. plot(v1)
  3869. pdf(paste(prefixPCres,"venn","p60","vs","p90","up","in","Cell_Treated","overlapping","DEGs.pdf", sep = "_"))
  3870. print(plot(v1))
  3871. dev.off()
  3872. # get lists of non-overlapping and overlapping genes
  3873. p60_only_tr_up <- v1@IntersectionSets$'10'
  3874. p60_only_tr_up
  3875. overlap_tr_up <- v1@IntersectionSets$'11'
  3876. overlap_tr_up
  3877. p90_only_tr_up <- v1@IntersectionSets$'01'
  3878. p90_only_tr_up
  3879. write.csv(p60_only_tr_up, file = paste(prefixPCres,"venn","genes","up","in","p60","cell_treated.csv",sep = "_"))
  3880. write.csv(overlap_tr_up, file = paste(prefixPCres,"venn","genes","up","in","p60_and_p90","cell_treated.csv",sep = "_"))
  3881. write.csv(p90_only_tr_up, file = paste(prefixPCres,"venn","genes","up","in","p90","cell_treated.csv",sep = "_"))
  3882. ### Up in Untreated condition ###
  3883. untreated_up <- list(p60_up_in_ut$gene,p90_up_in_ut$gene)
  3884. names(untreated_up) <- c("p60_Up_in_Untreated","p90_Up_in_Untreated")
  3885. venn_untreated_up <- Venn(untreated_up)
  3886. plot(venn_untreated_up, doWeights = TRUE, type = "circles")
  3887. v2 <- compute.Venn(venn_untreated_up, doWeights = TRUE, type = "circles")
  3888. # change default labels
  3889. # setlabels <- VennGetSetLabels(v2)
  3890. # setlabels
  3891. # facelabels <- VennGetFaceLabels(v2)
  3892. # facelabels
  3893. # universe <- VennGetUniverseRange(v2)
  3894. # universe
  3895. # setlabels[setlabels$Label=="p60_Up_in_Cell_Treated","hjust"] <- "right"
  3896. # setlabels[setlabels$Label=="p90_Up_in_Cell_Treated","hjust"] <- "left"
  3897. # setlabels[setlabels$Label=="YoungV_vs_iMACS_13","x"] <- -1.5
  3898. # setlabels
  3899. # v1 <- VennSetSetLabels(v1,setlabels)
  3900. grid::grid.newpage()
  3901. plot(v2)
  3902. pdf(paste(prefixPCres,"venn","p60","vs","p90","up","in","Untreated","overlapping","DEGs.pdf", sep = "_"))
  3903. print(plot(v2))
  3904. dev.off()
  3905. # get lists of non-overlapping and overlapping genes
  3906. p60_only_ut_up <- v2@IntersectionSets$'10'
  3907. p60_only_ut_up
  3908. overlap_ut_up <- v2@IntersectionSets$'11'
  3909. overlap_ut_up
  3910. p90_only_ut_up <- v2@IntersectionSets$'01'
  3911. p90_only_ut_up
  3912. write.csv(p60_only_ut_up, file = paste(prefixPCres,"venn","genes","up","in","p60","untreated.csv",sep = "_"))
  3913. write.csv(overlap_ut_up, file = paste(prefixPCres,"venn","genes","up","in","p60_and_p90","untreated.csv",sep = "_"))
  3914. write.csv(p90_only_ut_up, file = paste(prefixPCres,"venn","genes","up","in","p90","untreated.csv",sep = "_"))
  3915. #### Venn in ROD cluster ####
  3916. celltype <- "RODs"
  3917. # function to export DEG lists to csv
  3918. exportListToCSV <- function(data, filename) {
  3919. # Determine the maximum length among all columns
  3920. max_length <- max(sapply(data, length))
  3921. # Pad shorter columns with empty strings
  3922. filled_data <- lapply(data, function(x) {
  3923. c(x, rep("", max_length - length(x)))
  3924. })
  3925. # Convert the list to a data frame
  3926. df <- as.data.frame(filled_data)
  3927. # Set the column names
  3928. colnames(df) <- names(data)
  3929. # Write the data frame to a CSV file
  3930. write.csv(df, filename, row.names = FALSE)
  3931. }
  3932. # load the data
  3933. treatment_DEGs <- read.csv(file = "DEGs_p60_p90_by_treatment_RODs.csv",
  3934. header = TRUE)
  3935. p60_TR_UP <- treatment_DEGs$p60_TR
  3936. p60_UT_UP <- treatment_DEGs$p60_UT
  3937. p90_TR_UP <- treatment_DEGs$p90_TR
  3938. p90_UT_UP <- treatment_DEGs$p90_UT
  3939. rm(treatment_DEGs)
  3940. #### p60-p90 overlap in Treated condition ####
  3941. treated_up <- list(p60_TR_UP,p90_TR_UP)
  3942. names(treated_up) <- c("p60_Up_in_Cell_Treated","p90_Up_in_Cell_Treated")
  3943. venn_treated_up <- Venn(treated_up)
  3944. plot(venn_treated_up, doWeights = TRUE, type = "circles")
  3945. v1 <- compute.Venn(venn_treated_up, doWeights = TRUE, type = "circles")
  3946. grid::grid.newpage()
  3947. plot(v1)
  3948. pdf(paste(prefixPCres,"venn","p60","p90","up","in","Cell_Treated","overlapping","DEGs",celltype,".pdf", sep = "_"))
  3949. print(plot(v1))
  3950. dev.off()
  3951. # get lists of non-overlapping and overlapping genes
  3952. p60_only_tr_up <- v1@IntersectionSets$'10'
  3953. p60_only_tr_up
  3954. overlap_tr_up <- v1@IntersectionSets$'11'
  3955. overlap_tr_up
  3956. p90_only_tr_up <- v1@IntersectionSets$'01'
  3957. p90_only_tr_up
  3958. p60p90_TR_up <- list(p60_only_tr_up = p60_only_tr_up,
  3959. overlap_tr_up = overlap_tr_up,
  3960. p90_only_tr_up = p90_only_tr_up)
  3961. p60p90_TR_up
  3962. exportListToCSV(p60p90_TR_up, paste(prefixPCres,"venn",
  3963. "p60","p90","cell_treated",
  3964. "overlapping","DEGs",celltype,
  3965. ".csv",sep = "_"))
  3966. #### p60 TR p90 UT overlap ####
  3967. treated_up <- list(p60_TR_UP,p90_UT_UP)
  3968. names(treated_up) <- c("p60_Up_in_Cell_Treated","p90_Up_in_Unreated")
  3969. venn_treated_up <- Venn(treated_up)
  3970. plot(venn_treated_up, doWeights = TRUE, type = "circles")
  3971. v1 <- compute.Venn(venn_treated_up, doWeights = TRUE, type = "circles")
  3972. grid::grid.newpage()
  3973. plot(v1)
  3974. pdf(paste(prefixPCres,"venn","p60","TR","p90","UT",
  3975. "overlapping","DEGs",celltype,".pdf", sep = "_"))
  3976. print(plot(v1))
  3977. dev.off()
  3978. # get lists of non-overlapping and overlapping genes
  3979. p60_only_tr_up <- v1@IntersectionSets$'10'
  3980. p60_only_tr_up
  3981. overlap_tr_up <- v1@IntersectionSets$'11'
  3982. overlap_tr_up
  3983. p90_only_ut_up <- v1@IntersectionSets$'01'
  3984. p90_only_ut_up
  3985. p60_TR_p90_UT <- list(p60_only_tr_up = p60_only_tr_up,
  3986. overlap_tr_up = overlap_tr_up,
  3987. p90_only_ut_up = p90_only_ut_up)
  3988. p60_TR_p90_UT
  3989. exportListToCSV(p60_TR_p90_UT, paste(prefixPCres,"venn",
  3990. "p60","TR","p90","UT",
  3991. "overlapping","DEGs",celltype,
  3992. ".csv",sep = "_"))
  3993. #### p60 UT p90 TR overlap ####
  3994. treated_up <- list(p60_UT_UP,p90_TR_UP)
  3995. names(treated_up) <- c("p60_Up_in_Unreated","p90_Up_in_Cell_Treated")
  3996. venn_treated_up <- Venn(treated_up)
  3997. plot(venn_treated_up, doWeights = TRUE, type = "circles")
  3998. v1 <- compute.Venn(venn_treated_up, doWeights = TRUE, type = "circles")
  3999. grid::grid.newpage()
  4000. plot(v1)
  4001. pdf(paste(prefixPCres,"venn","p60","UT","p90","TR",
  4002. "overlapping","DEGs",celltype,".pdf", sep = "_"))
  4003. print(plot(v1))
  4004. dev.off()
  4005. # get lists of non-overlapping and overlapping genes
  4006. p60_only_ut_up <- v1@IntersectionSets$'10'
  4007. p60_only_ut_up
  4008. overlap_tr_up <- v1@IntersectionSets$'11'
  4009. overlap_tr_up
  4010. p90_only_tr_up <- v1@IntersectionSets$'01'
  4011. p90_only_tr_up
  4012. p60_UT_p90_TR <- list(p60_only_ut_up = p60_only_ut_up,
  4013. overlap_tr_up = overlap_tr_up,
  4014. p90_only_tr_up = p90_only_tr_up)
  4015. p60_UT_p90_TR
  4016. exportListToCSV(p60_UT_p90_TR, paste(prefixPCres,"venn",
  4017. "p60","UT","p90","TR",
  4018. "overlapping","DEGs",celltype,
  4019. ".csv",sep = "_"))
  4020. #### p60-p90 overlap in Untreated condition ####
  4021. untreated_up <- list(p60_UT_UP,p90_UT_UP)
  4022. names(untreated_up) <- c("p60_Up_in_Untreated","p90_Up_in_Untreated")
  4023. venn_untreated_up <- Venn(untreated_up)
  4024. plot(venn_untreated_up, doWeights = TRUE, type = "circles")
  4025. v1 <- compute.Venn(venn_untreated_up, doWeights = TRUE, type = "circles")
  4026. grid::grid.newpage()
  4027. plot(v1)
  4028. pdf(paste(prefixPCres,"venn",
  4029. "p60","p90",
  4030. "up","in",
  4031. "Untreated",
  4032. "overlapping","DEGs",
  4033. celltype,".pdf", sep = "_"))
  4034. print(plot(v1))
  4035. dev.off()
  4036. # get lists of non-overlapping and overlapping genes
  4037. p60_only_ut_up <- v1@IntersectionSets$'10'
  4038. p60_only_ut_up
  4039. overlap_ut_up <- v1@IntersectionSets$'11'
  4040. overlap_ut_up
  4041. p90_only_ut_up <- v1@IntersectionSets$'01'
  4042. p90_only_ut_up
  4043. p60p90_UT_up <- list(p60_only_ut_up = p60_only_ut_up,
  4044. overlap_ut_up = overlap_ut_up,
  4045. p90_only_ut_up = p90_only_ut_up)
  4046. p60p90_UT_up
  4047. exportListToCSV(p60p90_UT_up, paste(prefixPCres,"venn",
  4048. "p60","p90","untreated",
  4049. "overlapping","DEGs",celltype,
  4050. ".csv",sep = "_"))
  4051. #### Venn in MG cluster ####
  4052. celltype <- "MG"
  4053. # function to export DEG lists to csv
  4054. exportListToCSV <- function(data, filename) {
  4055. # Determine the maximum length among all columns
  4056. max_length <- max(sapply(data, length))
  4057. # Pad shorter columns with empty strings
  4058. filled_data <- lapply(data, function(x) {
  4059. c(x, rep("", max_length - length(x)))
  4060. })
  4061. # Convert the list to a data frame
  4062. df <- as.data.frame(filled_data)
  4063. # Set the column names
  4064. colnames(df) <- names(data)
  4065. # Write the data frame to a CSV file
  4066. write.csv(df, filename, row.names = FALSE)
  4067. }
  4068. # load the data
  4069. treatment_DEGs <- read.csv(file = "DEGs_p60_p90_by_treatment_MG.csv",
  4070. header = TRUE)
  4071. p60_TR_UP <- treatment_DEGs$p60_TR
  4072. p60_UT_UP <- treatment_DEGs$p60_UT
  4073. p90_TR_UP <- treatment_DEGs$p90_TR
  4074. p90_UT_UP <- treatment_DEGs$p90_UT
  4075. rm(treatment_DEGs)
  4076. #### p60-p90 overlap in Treated condition ####
  4077. treated_up <- list(p60_TR_UP,p90_TR_UP)
  4078. names(treated_up) <- c("p60_Up_in_Cell_Treated","p90_Up_in_Cell_Treated")
  4079. venn_treated_up <- Venn(treated_up)
  4080. plot(venn_treated_up, doWeights = TRUE, type = "circles")
  4081. v1 <- compute.Venn(venn_treated_up, doWeights = TRUE, type = "circles")
  4082. grid::grid.newpage()
  4083. plot(v1)
  4084. pdf(paste(prefixPCres,"venn","p60","p90","up","in","Cell_Treated","overlapping","DEGs",celltype,".pdf", sep = "_"))
  4085. print(plot(v1))
  4086. dev.off()
  4087. # get lists of non-overlapping and overlapping genes
  4088. p60_only_tr_up <- v1@IntersectionSets$'10'
  4089. p60_only_tr_up
  4090. overlap_tr_up <- v1@IntersectionSets$'11'
  4091. overlap_tr_up
  4092. p90_only_tr_up <- v1@IntersectionSets$'01'
  4093. p90_only_tr_up
  4094. p60p90_TR_up <- list(p60_only_tr_up = p60_only_tr_up,
  4095. overlap_tr_up = overlap_tr_up,
  4096. p90_only_tr_up = p90_only_tr_up)
  4097. p60p90_TR_up
  4098. exportListToCSV(p60p90_TR_up, paste(prefixPCres,"venn",
  4099. "p60","p90","cell_treated",
  4100. "overlapping","DEGs",celltype,
  4101. ".csv",sep = "_"))
  4102. #### p60 TR p90 UT overlap ####
  4103. treated_up <- list(p60_TR_UP,p90_UT_UP)
  4104. names(treated_up) <- c("p60_Up_in_Cell_Treated","p90_Up_in_Untreated")
  4105. venn_treated_up <- Venn(treated_up)
  4106. plot(venn_treated_up, doWeights = TRUE, type = "circles")
  4107. v1 <- compute.Venn(venn_treated_up, doWeights = TRUE, type = "circles")
  4108. grid::grid.newpage()
  4109. plot(v1)
  4110. pdf(paste(prefixPCres,"venn","p60","TR","p90","UT",
  4111. "overlapping","DEGs",celltype,".pdf", sep = "_"))
  4112. print(plot(v1))
  4113. dev.off()
  4114. # get lists of non-overlapping and overlapping genes
  4115. p60_only_tr_up <- v1@IntersectionSets$'10'
  4116. p60_only_tr_up
  4117. overlap_tr_up <- v1@IntersectionSets$'11'
  4118. overlap_tr_up
  4119. p90_only_ut_up <- v1@IntersectionSets$'01'
  4120. p90_only_ut_up
  4121. p60_TR_p90_UT <- list(p60_only_tr_up = p60_only_tr_up,
  4122. overlap_tr_up = overlap_tr_up,
  4123. p90_only_ut_up = p90_only_ut_up)
  4124. p60_TR_p90_UT
  4125. exportListToCSV(p60_TR_p90_UT, paste(prefixPCres,"venn",
  4126. "p60","TR","p90","UT",
  4127. "overlapping","DEGs",celltype,
  4128. ".csv",sep = "_"))
  4129. #### p60 UT p90 TR overlap ####
  4130. treated_up <- list(p60_UT_UP,p90_TR_UP)
  4131. names(treated_up) <- c("p60_Up_in_Untreated","p90_Up_in_Cell_Treated")
  4132. venn_treated_up <- Venn(treated_up)
  4133. plot(venn_treated_up, doWeights = TRUE, type = "circles")
  4134. v1 <- compute.Venn(venn_treated_up, doWeights = TRUE, type = "circles")
  4135. grid::grid.newpage()
  4136. plot(v1)
  4137. pdf(paste(prefixPCres,"venn","p60","UT","p90","TR",
  4138. "overlapping","DEGs",celltype,".pdf", sep = "_"))
  4139. print(plot(v1))
  4140. dev.off()
  4141. # get lists of non-overlapping and overlapping genes
  4142. p60_only_ut_up <- v1@IntersectionSets$'10'
  4143. p60_only_ut_up
  4144. overlap_tr_up <- v1@IntersectionSets$'11'
  4145. overlap_tr_up
  4146. p90_only_tr_up <- v1@IntersectionSets$'01'
  4147. p90_only_tr_up
  4148. p60_UT_p90_TR <- list(p60_only_ut_up = p60_only_ut_up,
  4149. overlap_tr_up = overlap_tr_up,
  4150. p90_only_tr_up = p90_only_tr_up)
  4151. p60_UT_p90_TR
  4152. exportListToCSV(p60_UT_p90_TR, paste(prefixPCres,"venn",
  4153. "p60","UT","p90","TR",
  4154. "overlapping","DEGs",celltype,
  4155. ".csv",sep = "_"))
  4156. #### p60-p90 overlap in Untreated condition ####
  4157. untreated_up <- list(p60_UT_UP,p90_UT_UP)
  4158. names(untreated_up) <- c("p60_Up_in_Untreated","p90_Up_in_Untreated")
  4159. venn_untreated_up <- Venn(untreated_up)
  4160. plot(venn_untreated_up, doWeights = TRUE, type = "circles")
  4161. v1 <- compute.Venn(venn_untreated_up, doWeights = TRUE, type = "circles")
  4162. grid::grid.newpage()
  4163. plot(v1)
  4164. pdf(paste(prefixPCres,"venn",
  4165. "p60","p90",
  4166. "up","in",
  4167. "Untreated",
  4168. "overlapping","DEGs",
  4169. celltype,".pdf", sep = "_"))
  4170. print(plot(v1))
  4171. dev.off()
  4172. # get lists of non-overlapping and overlapping genes
  4173. p60_only_ut_up <- v1@IntersectionSets$'10'
  4174. p60_only_ut_up
  4175. overlap_ut_up <- v1@IntersectionSets$'11'
  4176. overlap_ut_up
  4177. p90_only_ut_up <- v1@IntersectionSets$'01'
  4178. p90_only_ut_up
  4179. p60p90_UT_up <- list(p60_only_ut_up = p60_only_ut_up,
  4180. overlap_ut_up = overlap_ut_up,
  4181. p90_only_ut_up = p90_only_ut_up)
  4182. p60p90_UT_up
  4183. exportListToCSV(p60p90_UT_up, paste(prefixPCres,"venn",
  4184. "p60","p90","untreated",
  4185. "overlapping","DEGs",celltype,
  4186. ".csv",sep = "_"))
  4187. #### Trying ggVennDiagram and ggvenn instead of Vennerable ####
  4188. # ggVennDiagram
  4189. if (!require(devtools)) install.packages("devtools")
  4190. devtools::install_github("gaospecial/ggVennDiagram")
  4191. library("ggVennDiagram")
  4192. ggVennDiagram(treated_up,label_alpha = 0) +
  4193. ggplot2::scale_fill_gradient(low="blue",high = "yellow")
  4194. # ggvenn
  4195. if (!require(devtools)) install.packages("devtools")
  4196. devtools::install_github("yanlinlin82/ggvenn")
  4197. library("ggvenn")
  4198. ggvenn(treated_up,
  4199. # fill_color = c("green", "red"),
  4200. stroke_size = 1,
  4201. # set_name_size = 9,
  4202. text_size = 8,
  4203. show_percentage = FALSE,
  4204. auto_scale = FALSE
  4205. )
  4206. ?ggvenn
  4207. ?geom_venn
  4208. #### Heatmap ####
  4209. Idents(seurat_sct) <- "treatment"
  4210. view([email hidden])
  4211. p60_treatment_DEGs <- read_csv(file = "20230327_Rat_retina_int_12PCs_res.0.2_degs_treatment_p60_minpct0.25_logfcthresh0.4.csv")
  4212. p60_treatment_DEGs %>% sort()
  4213. p60_treatment_DEGs <- p60_treatment_DEGs[order(p60_treatment_DEGs$p_val_adj), ]
  4214. DoHeatmap(seurat_sct, features = c(p60_treatment_DEGs$gene[1:30]),
  4215. cells = WhichCells(seurat_sct,
  4216. expression = time_point == "p60"))
  4217. p90_treatment_DEGs <- read_csv(file = "20230327_Rat_retina_int_12PCs_res.0.2_degs_treatment_p90_minpct0.25_logfcthresh0.4.csv")
  4218. DoHeatmap(seurat_sct, features = p90_treatment_DEGs$gene)
  4219. #### volcano plots ####
  4220. p60_treatment_DEGs <- read_csv(file = "20230327_Rat_retina_int_12PCs_res.0.2_degs_treatment_p60_minpct0.25_logfcthresh0.4.csv")
  4221. TR_DEGS <- subset(p60_treatment_DEGs, subset = cluster == "Cell_Treated")
  4222. UT_DEGS <- subset(p60_treatment_DEGs, subset = cluster == "Untreated")
  4223. UT_DEGS$avg_log2FC <- -1 * UT_DEGS$avg_log2FC
  4224. DEGS <- rbind(TR_DEGS,UT_DEGS)
  4225. volc <- DEGS
  4226. for (i in 1:length(volc$p_val_adj)) {
  4227. if (volc$p_val_adj[i] == 0) {
  4228. volc$p_val_adj[i] <- 1e-293
  4229. }
  4230. }
  4231. EnhancedVolcano(volc,
  4232. lab = volc$gene,
  4233. x = 'avg_log2FC',
  4234. y = 'p_val_adj',
  4235. xlim = c(min(volc$avg_log2FC, na.rm = TRUE) - 0.1,
  4236. max(volc$avg_log2FC, na.rm = TRUE) + 0.1),
  4237. ylim = c(0, max(-log10(volc$p_val_adj), na.rm = TRUE) + 100),
  4238. # title = "Aging iMPs vs Aging Veh",
  4239. titleLabSize = 30,
  4240. caption = NULL,
  4241. subtitle = NULL,
  4242. xlab = bquote(bold(~Log["2"] ~ "fold change")),
  4243. ylab = bquote(bold(~"-" ~Log["10"] ~ p_val_adj)),
  4244. axisLabSize = 25,
  4245. # col = volc_colors,
  4246. colAlpha = 1/1,
  4247. legendLabels = c("NS",
  4248. expression(Log[2] ~ FC),
  4249. "p_val_adj",
  4250. expression(p_val_adj ~ and ~ log[2] ~ FC)),
  4251. legendPosition = 'bottom',
  4252. legendLabSize = 25,
  4253. legendIconSize = 7,
  4254. drawConnectors = TRUE,
  4255. min.segment.length = 1,
  4256. labSize = 7,
  4257. max.overlaps = Inf,
  4258. pCutoff = 0.05,
  4259. FCcutoff = 0.58,
  4260. gridlines.major = FALSE,
  4261. gridlines.minor = FALSE,
  4262. arrowheads = FALSE,
  4263. pointSize = 7
  4264. )
  4265. p90_treatment_DEGs <- read_csv(file = "20230327_Rat_retina_int_12PCs_res.0.2_degs_treatment_p90_minpct0.25_logfcthresh0.4.csv")
  4266. TR_DEGS <- subset(p90_treatment_DEGs, subset = cluster == "Cell_Treated")
  4267. UT_DEGS <- subset(p90_treatment_DEGs, subset = cluster == "Untreated")
  4268. UT_DEGS$avg_log2FC <- -1 * UT_DEGS$avg_log2FC
  4269. DEGS <- rbind(TR_DEGS,UT_DEGS)
  4270. volc <- DEGS
  4271. for (i in 1:length(volc$p_val_adj)) {
  4272. if (volc$p_val_adj[i] == 0) {
  4273. volc$p_val_adj[i] <- 1e-293
  4274. }
  4275. }
  4276. EnhancedVolcano(volc,
  4277. lab = volc$gene,
  4278. x = 'avg_log2FC',
  4279. y = 'p_val_adj',
  4280. xlim = c(min(volc$avg_log2FC, na.rm = TRUE) - 0.1,
  4281. max(volc$avg_log2FC, na.rm = TRUE) + 0.1),
  4282. ylim = c(0, max(-log10(volc$p_val_adj), na.rm = TRUE) + 100),
  4283. # title = "Aging iMPs vs Aging Veh",
  4284. titleLabSize = 30,
  4285. caption = NULL,
  4286. subtitle = NULL,
  4287. xlab = bquote(bold(~Log["2"] ~ "fold change")),
  4288. ylab = bquote(bold(~"-" ~Log["10"] ~ p_val_adj)),
  4289. axisLabSize = 25,
  4290. # col = volc_colors,
  4291. colAlpha = 1/1,
  4292. legendLabels = c("NS",
  4293. expression(Log[2] ~ FC),
  4294. "p_val_adj",
  4295. expression(p_val_adj ~ and ~ log[2] ~ FC)),
  4296. legendPosition = 'bottom',
  4297. legendLabSize = 25,
  4298. legendIconSize = 7,
  4299. drawConnectors = TRUE,
  4300. min.segment.length = 1,
  4301. labSize = 3,
  4302. max.overlaps = Inf,
  4303. pCutoff = 0.05,
  4304. FCcutoff = 1,
  4305. gridlines.major = FALSE,
  4306. gridlines.minor = FALSE,
  4307. arrowheads = FALSE,
  4308. pointSize = 3
  4309. )
  4310. #### ####
  4311. #### Rod subset recluster ####
  4312. s_rods <- subset(seurat_sct,
  4313. idents = c("ROD"))
  4314. #### SCT subset ####
  4315. DefaultAssay(s_rods) <- "RNA"
  4316. s_rods <- SCTransform(s_rods,
  4317. vars.to.regress = c("percent.mt","percent.ribo"),
  4318. verbose = TRUE)
  4319. #### update project variable to include subset ####
  4320. project_ROD <- "Rat_retina_RODS"
  4321. #### sub PCA ####
  4322. # this performs PCA on the seurat object
  4323. s_rods <- RunPCA(s_rods, npcs = 50, verbose = TRUE)
  4324. # make PC coordinate object a data frame
  4325. xx.coord <- as.data.frame(s_rods@reductions$[email hidden])
  4326. # make PC feature loadings object a data frame
  4327. xx.gload <- as.data.frame(s_rods@reductions$[email hidden])
  4328. # calculate eigenvalues for arrays
  4329. # generate squares of all sample coordinates
  4330. sq.xx.coord <- as.data.frame(xx.coord^2)
  4331. # create empty list for eigenvalues first
  4332. eig <- c()
  4333. # calculate the eigenvalue for each PC in sq.xx.coord by taking the sqrt of the sum of squares
  4334. for(i in 1:ncol(sq.xx.coord))
  4335. eig[i] = sqrt(sum(sq.xx.coord[,i]))
  4336. # calculate the total variance by adding up all the eigenvalues
  4337. sum.eig <- sum(eig)
  4338. # calculate the expected contribution of all PCs if they all contribute equally to the total variance
  4339. expected.contribution <- sum.eig/(length(xx.coord)-1)
  4340. # return the number of principal components with an eigenvalue greater than expected by equal variance
  4341. meaningful.PCs <- sum(eig > expected.contribution)
  4342. # create empty list for eigenvalue percentage
  4343. eig.percent <- c()
  4344. # calculate the percentage of the total variance by each PC eigenvalue
  4345. for(i in 1:length(eig))
  4346. eig.percent[i] = 100*eig[i]/sum.eig
  4347. # sum of all eig.percent should total to 100
  4348. sum(eig.percent)
  4349. # create empty list for scree values
  4350. scree <- c()
  4351. # calculate a running total of variance contribution
  4352. for(i in 1:length(eig))
  4353. if(i == 1) scree[i] = eig.percent[i] else scree[i] = scree[i-1] + eig.percent[i]
  4354. # create data frame for eigenvalue summaries
  4355. eigenvalues <- data.frame("PC" = colnames(xx.coord), "eig" = eig, "percent" = eig.percent, "scree" = scree)
  4356. # write csv for eigenvalues
  4357. # write.csv(eigenvalues, file = paste0("./",date,"_",project,"_PCA_eigenvalues.csv"), row.names = F)
  4358. # plot scree values
  4359. plot(eigenvalues$percent, ylim = c(0,100), type = "S", xlab = "PC", ylab = "Percent of variance",
  4360. main = paste0(date,"_",project," scree plot all samples PCA"))
  4361. points(eigenvalues$scree, ylim = c(0,100), type = "p", pch = 16)
  4362. lines(eigenvalues$scree)
  4363. # add red line to indicate cut-off
  4364. cut.off <- 100/(length(eig)-1)
  4365. abline(h = cut.off, col = "red")
  4366. # add blue line to indicate which PCs are meaningful and kept
  4367. abline(v = meaningful.PCs, col = "blue")
  4368. text(meaningful.PCs, cut.off, label = paste("cutoff PC",meaningful.PCs),
  4369. adj = c(-0.1, -0.5))
  4370. dev.copy(pdf, paste0("./",date,"_",project_ROD,"_scree_plot.pdf"))
  4371. dev.off()
  4372. rm(eigenvalues,sq.xx.coord,xx.coord,xx.gload,cut.off,
  4373. eig,eig.percent,expected.contribution,i,scree,sum.eig)
  4374. # meaningful.PCs <- 9
  4375. #### sub Run UMAP and look at UMAP plots ####
  4376. s_rods <- RunUMAP(s_rods,
  4377. reduction = "pca",
  4378. dims = 1:meaningful.PCs,
  4379. verbose = TRUE)
  4380. # update prefixed variable
  4381. ROD_prefixPC <- paste0("./",date,"_",project_ROD,"_",meaningful.PCs,"PCs")
  4382. ## UMAP plot by sample name ("orig.ident")
  4383. DimPlot(s_rods, reduction = "umap", label = FALSE,
  4384. pt.size = .25, group.by = "orig.ident")
  4385. hirestiff(paste0(ROD_prefixPC,"_UMAP_by_sample_hires.tiff"))
  4386. lowrestiff(paste0(ROD_prefixPC,"_UMAP_by_sample_lowres.tiff"))
  4387. DimPlot(s_rods, reduction = "umap", label = FALSE,
  4388. pt.size = .25, group.by = "treatment")
  4389. hirestiff(paste0(ROD_prefixPC,"_UMAP_by_treatment_hires.tiff"))
  4390. lowrestiff(paste0(ROD_prefixPC,"_UMAP_by_treatment_lowres.tiff"))
  4391. DimPlot(s_rods, reduction = "umap", label = FALSE,
  4392. pt.size = .25, split.by = "treatment", group.by = "treatment")
  4393. hirestiff(paste0(ROD_prefixPC,"_UMAP_split_by_treatment_hires.tiff"))
  4394. lowrestiff(paste0(ROD_prefixPC,"_UMAP_split_by_treatment_lowres.tiff"))
  4395. DimPlot(s_rods, reduction = "umap", label = FALSE,
  4396. pt.size = .25, group.by = "batch")
  4397. hirestiff(paste0(ROD_prefixPC,"_UMAP_by_batch_hires.tiff"))
  4398. lowrestiff(paste0(ROD_prefixPC,"_UMAP_by_batch_lowres.tiff"))
  4399. DimPlot(s_rods, reduction = "umap", label = FALSE,
  4400. pt.size = .25, group.by = "batch", split.by = "batch")
  4401. hirestiff(paste0(ROD_prefixPC,"_UMAP_split_by_batch_hires.tiff"))
  4402. lowrestiff(paste0(ROD_prefixPC,"_UMAP_split_by_batch_lowres.tiff"))
  4403. DimPlot(s_rods, reduction = "umap", label = FALSE,
  4404. pt.size = .25, group.by = "time_point")
  4405. hirestiff(paste0(ROD_prefixPC,"_UMAP_by_time_point_hires.tiff"))
  4406. lowrestiff(paste0(ROD_prefixPC,"_UMAP_by_time_point_lowres.tiff"))
  4407. DimPlot(s_rods, reduction = "umap", label = FALSE,
  4408. pt.size = .25, split.by = "time_point", group.by = "time_point")
  4409. hirestiff(paste0(ROD_prefixPC,"_UMAP_split_by_time_point_hires.tiff"))
  4410. lowrestiff(paste0(ROD_prefixPC,"_UMAP_split_by_time_point_lowres.tiff"))
  4411. DimPlot(s_rods, reduction = "umap", label = FALSE,
  4412. pt.size = .25, group.by = "time_point_treatment")
  4413. hirestiff(paste0(ROD_prefixPC,"_UMAP_by_time_point_treatment_hires.tiff"))
  4414. lowrestiff(paste0(ROD_prefixPC,"_UMAP_by_time_point_treatment_lowres.tiff"))
  4415. DimPlot(s_rods, reduction = "umap", label = FALSE,
  4416. pt.size = 1, split.by = "time_point_treatment",
  4417. group.by = "time_point_treatment")
  4418. hirestiff(paste0(ROD_prefixPC,"_UMAP_split_by_time_point_treatment_hires.tiff"))
  4419. lowrestiff(paste0(ROD_prefixPC,"_UMAP_split_by_time_point_treatment_lowres.tiff"))
  4420. DimPlot(s_rods, reduction = "umap", label = FALSE, pt.size = .25, group.by = "time_point_batch")
  4421. hirestiff(paste0(ROD_prefixPC,"_UMAP_by_time_point_batch_hires.tiff"))
  4422. lowrestiff(paste0(ROD_prefixPC,"_UMAP_by_time_point_batch_lowres.tiff"))
  4423. DimPlot(s_rods, reduction = "umap", label = FALSE, pt.size = .25, split.by = "time_point_batch", group.by = "time_point_batch")
  4424. hirestiff(paste0(ROD_prefixPC,"_UMAP_split_by_time_point_batch_hires.tiff"))
  4425. lowrestiff(paste0(ROD_prefixPC,"_UMAP_split_by_time_point_batch_lowres.tiff"))
  4426. DimPlot(s_rods, reduction = "umap", label = FALSE, pt.size = .25, group.by = "treatment_batch")
  4427. hirestiff(paste0(ROD_prefixPC,"_UMAP_by_treatment_batch_hires.tiff"))
  4428. lowrestiff(paste0(ROD_prefixPC,"_UMAP_by_treatment_batch_lowres.tiff"))
  4429. DimPlot(s_rods, reduction = "umap", label = FALSE, pt.size = .25, split.by = "treatment_batch", group.by = "treatment_batch")
  4430. hirestiff(paste0(ROD_prefixPC,"_UMAP_split_by_treatment_batch_hires.tiff"))
  4431. lowrestiff(paste0(ROD_prefixPC,"_UMAP_split_by_treatment_batch_lowres.tiff"))
  4432. DimPlot(s_rods, reduction = "umap", label = FALSE, pt.size = .25, group.by = "time_point_treatment_batch")
  4433. hirestiff(paste0(ROD_prefixPC,"_UMAP_by_time_point_treatment_batch_hires.tiff"))
  4434. lowrestiff(paste0(ROD_prefixPC,"_UMAP_by_time_point_treatment_batch_lowres.tiff"))
  4435. DimPlot(s_rods, reduction = "umap", label = FALSE, pt.size = .25, split.by = "time_point_treatment_batch", group.by = "time_point_treatment_batch")
  4436. hirestiff(paste0(ROD_prefixPC,"_UMAP_split_by_time_point_treatment_batch_hires.tiff"))
  4437. lowrestiff(paste0(ROD_prefixPC,"_UMAP_split_by_time_point_treatment_batch_lowres.tiff"))
  4438. # saveRDS(s_rods, file = paste0(ROD_prefixPC,"_seurat_integrated_preclustering.rds"))
  4439. # s_rods <- read_rds(file = paste0(ROD_prefixPC,"_seurat_integrated_preclustering.rds"))
  4440. #### Remove outlier batch 08182 ####
  4441. Idents(s_rods) <- "batch"
  4442. s_rods <- subset(s_rods,
  4443. idents = c("08182"),
  4444. invert = TRUE)
  4445. #### (rerun) SCT subset ####
  4446. DefaultAssay(s_rods) <- "RNA"
  4447. s_rods <- SCTransform(s_rods,
  4448. vars.to.regress = c("percent.mt","percent.ribo"),
  4449. verbose = TRUE)
  4450. #### (rerun) sub PCA ####
  4451. # this performs PCA on the seurat object
  4452. s_rods <- RunPCA(s_rods, npcs = 50, verbose = TRUE)
  4453. # make PC coordinate object a data frame
  4454. xx.coord <- as.data.frame(s_rods@reductions$[email hidden])
  4455. # make PC feature loadings object a data frame
  4456. xx.gload <- as.data.frame(s_rods@reductions$[email hidden])
  4457. # calculate eigenvalues for arrays
  4458. # generate squares of all sample coordinates
  4459. sq.xx.coord <- as.data.frame(xx.coord^2)
  4460. # create empty list for eigenvalues first
  4461. eig <- c()
  4462. # calculate the eigenvalue for each PC in sq.xx.coord by taking the sqrt of the sum of squares
  4463. for(i in 1:ncol(sq.xx.coord))
  4464. eig[i] = sqrt(sum(sq.xx.coord[,i]))
  4465. # calculate the total variance by adding up all the eigenvalues
  4466. sum.eig <- sum(eig)
  4467. # calculate the expected contribution of all PCs if they all contribute equally to the total variance
  4468. expected.contribution <- sum.eig/(length(xx.coord)-1)
  4469. # return the number of principal components with an eigenvalue greater than expected by equal variance
  4470. ROD_meaningful.PCs <- sum(eig > expected.contribution)
  4471. # create empty list for eigenvalue percentage
  4472. eig.percent <- c()
  4473. # calculate the percentage of the total variance by each PC eigenvalue
  4474. for(i in 1:length(eig))
  4475. eig.percent[i] = 100*eig[i]/sum.eig
  4476. # sum of all eig.percent should total to 100
  4477. sum(eig.percent)
  4478. # create empty list for scree values
  4479. scree <- c()
  4480. # calculate a running total of variance contribution
  4481. for(i in 1:length(eig))
  4482. if(i == 1) scree[i] = eig.percent[i] else scree[i] = scree[i-1] + eig.percent[i]
  4483. # create data frame for eigenvalue summaries
  4484. eigenvalues <- data.frame("PC" = colnames(xx.coord), "eig" = eig, "percent" = eig.percent, "scree" = scree)
  4485. # plot scree values
  4486. plot(eigenvalues$percent, ylim = c(0,100), type = "S", xlab = "PC", ylab = "Percent of variance",
  4487. main = paste0(date,"_",project," scree plot all samples PCA"))
  4488. points(eigenvalues$scree, ylim = c(0,100), type = "p", pch = 16)
  4489. lines(eigenvalues$scree)
  4490. # add red line to indicate cut-off
  4491. cut.off <- 100/(length(eig)-1)
  4492. abline(h = cut.off, col = "red")
  4493. # add blue line to indicate which PCs are meaningful and kept
  4494. abline(v = ROD_meaningful.PCs, col = "blue")
  4495. text(meaningful.PCs, cut.off, label = paste("cutoff PC",ROD_meaningful.PCs),
  4496. adj = c(-0.1, -0.5))
  4497. dev.copy(pdf, paste0("./",date,"_",project_ROD,"_scree_plot.pdf"))
  4498. dev.off()
  4499. rm(eigenvalues,sq.xx.coord,xx.coord,xx.gload,cut.off,
  4500. eig,eig.percent,expected.contribution,i,scree,sum.eig)
  4501. # ROD_meaningful.PCs <- 11
  4502. #### (rerun) sub Run UMAP and look at UMAP plots ####
  4503. s_rods <- RunUMAP(s_rods,
  4504. reduction = "pca",
  4505. dims = 1:ROD_meaningful.PCs,
  4506. verbose = TRUE)
  4507. # update prefixed variable
  4508. ROD_prefixPC <- paste0("./",date,"_",project_ROD,"_",ROD_meaningful.PCs,"PCs")
  4509. ## UMAP plot by sample name ("orig.ident")
  4510. DimPlot(s_rods, reduction = "umap", label = FALSE,
  4511. pt.size = .25, group.by = "orig.ident")
  4512. hirestiff(paste0(ROD_prefixPC,"_UMAP_by_sample_hires.tiff"))
  4513. lowrestiff(paste0(ROD_prefixPC,"_UMAP_by_sample_lowres.tiff"))
  4514. DimPlot(s_rods, reduction = "umap", label = FALSE,
  4515. pt.size = .25, group.by = "treatment")
  4516. hirestiff(paste0(ROD_prefixPC,"_UMAP_by_treatment_hires.tiff"))
  4517. lowrestiff(paste0(ROD_prefixPC,"_UMAP_by_treatment_lowres.tiff"))
  4518. DimPlot(s_rods, reduction = "umap", label = FALSE,
  4519. pt.size = .25, split.by = "treatment", group.by = "treatment")
  4520. hirestiff(paste0(ROD_prefixPC,"_UMAP_split_by_treatment_hires.tiff"))
  4521. lowrestiff(paste0(ROD_prefixPC,"_UMAP_split_by_treatment_lowres.tiff"))
  4522. DimPlot(s_rods, reduction = "umap", label = FALSE,
  4523. pt.size = .25, group.by = "batch")
  4524. hirestiff(paste0(ROD_prefixPC,"_UMAP_by_batch_hires.tiff"))
  4525. lowrestiff(paste0(ROD_prefixPC,"_UMAP_by_batch_lowres.tiff"))
  4526. DimPlot(s_rods, reduction = "umap", label = FALSE,
  4527. pt.size = .25, group.by = "batch", split.by = "batch")
  4528. hirestiff(paste0(ROD_prefixPC,"_UMAP_split_by_batch_hires.tiff"))
  4529. lowrestiff(paste0(ROD_prefixPC,"_UMAP_split_by_batch_lowres.tiff"))
  4530. DimPlot(s_rods, reduction = "umap", label = FALSE,
  4531. pt.size = .25, group.by = "time_point")
  4532. hirestiff(paste0(ROD_prefixPC,"_UMAP_by_time_point_hires.tiff"))
  4533. lowrestiff(paste0(ROD_prefixPC,"_UMAP_by_time_point_lowres.tiff"))
  4534. DimPlot(s_rods, reduction = "umap", label = FALSE,
  4535. pt.size = .25, split.by = "time_point", group.by = "time_point")
  4536. hirestiff(paste0(ROD_prefixPC,"_UMAP_split_by_time_point_hires.tiff"))
  4537. lowrestiff(paste0(ROD_prefixPC,"_UMAP_split_by_time_point_lowres.tiff"))
  4538. DimPlot(s_rods, reduction = "umap", label = FALSE,
  4539. pt.size = .25, group.by = "time_point_treatment")
  4540. hirestiff(paste0(ROD_prefixPC,"_UMAP_by_time_point_treatment_hires.tiff"))
  4541. lowrestiff(paste0(ROD_prefixPC,"_UMAP_by_time_point_treatment_lowres.tiff"))
  4542. DimPlot(s_rods, reduction = "umap", label = FALSE,
  4543. pt.size = 1, split.by = "time_point_treatment",
  4544. group.by = "time_point_treatment")
  4545. hirestiff(paste0(ROD_prefixPC,"_UMAP_split_by_time_point_treatment_hires.tiff"))
  4546. lowrestiff(paste0(ROD_prefixPC,"_UMAP_split_by_time_point_treatment_lowres.tiff"))
  4547. DimPlot(s_rods, reduction = "umap", label = FALSE, pt.size = .25, group.by = "time_point_batch")
  4548. hirestiff(paste0(ROD_prefixPC,"_UMAP_by_time_point_batch_hires.tiff"))
  4549. lowrestiff(paste0(ROD_prefixPC,"_UMAP_by_time_point_batch_lowres.tiff"))
  4550. DimPlot(s_rods, reduction = "umap", label = FALSE, pt.size = .25, split.by = "time_point_batch", group.by = "time_point_batch")
  4551. hirestiff(paste0(ROD_prefixPC,"_UMAP_split_by_time_point_batch_hires.tiff"))
  4552. lowrestiff(paste0(ROD_prefixPC,"_UMAP_split_by_time_point_batch_lowres.tiff"))
  4553. DimPlot(s_rods, reduction = "umap", label = FALSE, pt.size = .25, group.by = "treatment_batch")
  4554. hirestiff(paste0(ROD_prefixPC,"_UMAP_by_treatment_batch_hires.tiff"))
  4555. lowrestiff(paste0(ROD_prefixPC,"_UMAP_by_treatment_batch_lowres.tiff"))
  4556. DimPlot(s_rods, reduction = "umap", label = FALSE, pt.size = .25, split.by = "treatment_batch", group.by = "treatment_batch")
  4557. hirestiff(paste0(ROD_prefixPC,"_UMAP_split_by_treatment_batch_hires.tiff"))
  4558. lowrestiff(paste0(ROD_prefixPC,"_UMAP_split_by_treatment_batch_lowres.tiff"))
  4559. DimPlot(s_rods, reduction = "umap", label = FALSE, pt.size = .25, group.by = "time_point_treatment_batch")
  4560. hirestiff(paste0(ROD_prefixPC,"_UMAP_by_time_point_treatment_batch_hires.tiff"))
  4561. lowrestiff(paste0(ROD_prefixPC,"_UMAP_by_time_point_treatment_batch_lowres.tiff"))
  4562. DimPlot(s_rods, reduction = "umap", label = FALSE, pt.size = .25, split.by = "time_point_treatment_batch", group.by = "time_point_treatment_batch")
  4563. hirestiff(paste0(ROD_prefixPC,"_UMAP_split_by_time_point_treatment_batch_hires.tiff"))
  4564. lowrestiff(paste0(ROD_prefixPC,"_UMAP_split_by_time_point_treatment_batch_lowres.tiff"))
  4565. # saveRDS(s_rods, file = paste0(ROD_prefixPC,"_seurat_integrated_preclustering.rds"))
  4566. # s_rods <- read_rds(file = paste0(ROD_prefixPC,"_seurat_integrated_preclustering.rds"))
  4567. #### sub Clustering and Resolution ####
  4568. # DefaultAssay(s_rods) <- "integrated"
  4569. # Determine the K-nearest neighbor graph
  4570. s_rods <- FindNeighbors(object = s_rods, reduction = "pca", dims = 1:ROD_meaningful.PCs)
  4571. # Determine the clusters
  4572. s_rods <- FindClusters(object = s_rods,
  4573. resolution = c(0.1,0.2,0.3,0.4,0.5))
  4574. ROD_res <- "_res.0.1"
  4575. ROD_ident_res <- paste0("SCT_snn",ROD_res)
  4576. Idents(s_rods) <- ROD_ident_res
  4577. DimPlot(s_rods, reduction = "umap", label = TRUE, label.size = 5, pt.size = 0.8) +
  4578. NoLegend() +
  4579. ggtitle(paste0(ROD_ident_res))
  4580. #update prefix
  4581. ROD_prefixPCres <- paste0(ROD_prefixPC,ROD_res)
  4582. # Plot the UMAP
  4583. DimPlot(s_rods, reduction = "umap", label = TRUE, label.size = 6, pt.size = 1) +
  4584. NoLegend() +
  4585. ggtitle(paste0(ROD_ident_res))
  4586. hirestiff(paste0(ROD_prefixPCres,"_UMAP","_by_","cluster","_hires.tiff"))
  4587. lowrestiff(paste0(ROD_prefixPCres,"_UMAP","_by_","cluster","_lowres.tiff"))
  4588. # UMAP of cells in each cluster by treatment without cluster labels
  4589. DimPlot(s_rods, reduction = "umap", label = FALSE, split.by = "treatment", pt.size = 1) + NoLegend()
  4590. hirestiff(paste0(ROD_prefixPCres,"_UMAP","_by_","treatment","_no_labels","_hires.tiff"))
  4591. lowrestiff(paste0(ROD_prefixPCres,"_UMAP","_by_","treatment","_no_labels","_lowres.tiff"))
  4592. # UMAP of cells in each cluster by treatment with cluster labels
  4593. DimPlot(s_rods, reduction = "umap", label = TRUE,
  4594. split.by = "treatment", pt.size = 1, label.size = 6) + NoLegend()
  4595. hirestiff(paste0(ROD_prefixPCres,"_UMAP","_by_","treatment","_with_clusters_labels","_hires.tiff"))
  4596. lowrestiff(paste0(ROD_prefixPCres,"_UMAP","_by_","treatment","_with_clusters_labels","_lowres.tiff"))
  4597. # UMAP of cells in each cluster by batch without cluster labels
  4598. DimPlot(s_rods, reduction = "umap", label = FALSE, split.by = "batch", pt.size = 1) +
  4599. NoLegend() +
  4600. ggtitle("Batch")
  4601. hirestiff(paste0(ROD_prefixPCres,"_UMAP","_by_","batch","_no_labels","_hires.tiff"))
  4602. lowrestiff(paste0(ROD_prefixPCres,"_UMAP","_by_","batch","_no_labels","_lowres.tiff"))
  4603. # UMAP of cells in each cluster by batch with cluster labels
  4604. DimPlot(s_rods, reduction = "umap", label = TRUE,
  4605. split.by = "batch", pt.size = 1, label.size = 6) +
  4606. NoLegend() +
  4607. ggtitle("Batch")
  4608. hirestiff(paste0(ROD_prefixPCres,"_UMAP","_by_","batch","_with_clusters_labels","_hires.tiff"))
  4609. lowrestiff(paste0(ROD_prefixPCres,"_UMAP","_by_","batch","_with_clusters_labels","_lowres.tiff"))
  4610. # UMAP of cells in each cluster by time_point without cluster labels
  4611. DimPlot(s_rods, reduction = "umap", label = FALSE, split.by = "time_point", pt.size = 1) + NoLegend()
  4612. hirestiff(paste0(ROD_prefixPCres,"_UMAP","_by_","time_point","_no_labels","_hires.tiff"))
  4613. lowrestiff(paste0(ROD_prefixPCres,"_UMAP","_by_","time_point","_no_labels","_lowres.tiff"))
  4614. # UMAP of cells in each cluster by time_point with cluster labels
  4615. DimPlot(s_rods, reduction = "umap", label = TRUE,
  4616. split.by = "time_point", pt.size = 1, label.size = 6) + NoLegend()
  4617. hirestiff(paste0(ROD_prefixPCres,"_UMAP","_by_","time_point","_with_clusters_labels","_hires.tiff"))
  4618. lowrestiff(paste0(ROD_prefixPCres,"_UMAP","_by_","time_point","_with_clusters_labels","_lowres.tiff"))
  4619. # UMAP of cells in each cluster by time_point without cluster labels
  4620. DimPlot(s_rods, reduction = "umap", label = FALSE, split.by = "time_point_treatment", pt.size = 1) + NoLegend()
  4621. hirestiff(paste0(ROD_prefixPCres,"_UMAP","_by_","time_point_treatment","_no_labels","_hires.tiff"))
  4622. lowrestiff(paste0(ROD_prefixPCres,"_UMAP","_by_","time_point_treatment","_no_labels","_lowres.tiff"))
  4623. # UMAP of cells in each cluster by time_point with cluster labels
  4624. DimPlot(s_rods, reduction = "umap", label = TRUE,
  4625. split.by = "time_point_treatment", pt.size = 1, label.size = 6) + NoLegend()
  4626. hirestiff(paste0(ROD_prefixPCres,"_UMAP","_by_","time_point_treatment","_with_clusters_labels","_hires.tiff"))
  4627. lowrestiff(paste0(ROD_prefixPCres,"_UMAP","_by_","time_point_treatment","_with_clusters_labels","_lowres.tiff"))
  4628. #### sub Extract number of cells per cluster per orig.ident ####
  4629. n_cells <- FetchData(s_rods, vars = c("ident", "orig.ident")) %>%
  4630. dplyr::count(ident, orig.ident) %>%
  4631. tidyr::spread(ident, n)
  4632. n_cells
  4633. write.csv(n_cells, file = paste0(ROD_prefixPCres,"_cells_per_cluster.csv"))
  4634. rm(n_cells)
  4635. #### sub save RDS containing reduction and cluster idents ####
  4636. # saveRDS(s_rods, paste0(ROD_prefixPCres,"_seurat_after_clustering.rds"))
  4637. # s_rods <- readRDS(file = paste0(ROD_prefixPCres,"_seurat_after_clustering.rds"))
  4638. #### sub normalize rna slot ####
  4639. # Select the RNA counts slot to be the default assay for visualization purposes
  4640. DefaultAssay(s_rods) <- "RNA"
  4641. # Normalize, find variable features, scale data
  4642. s_rods <- NormalizeData(s_rods)
  4643. s_rods <- FindVariableFeatures(s_rods)
  4644. all.genes <- rownames(s_rods)
  4645. s_rods <- ScaleData(s_rods, features = all.genes)
  4646. # Export normalized counts
  4647. # norm_counts <- GetAssayData(s_rods, slot = "data")
  4648. # save(norm_counts, file = paste0(ROD_prefixPCres,"_normalized_counts_RNA_sparse_matrix.rdata"))
  4649. # write.csv(norm_counts, file = paste0(ROD_prefixPCres,"_normalized_counts_RNA.csv"))
  4650. # save RDS containing RNA normalized data
  4651. # saveRDS(s_rods, paste0(ROD_prefixPCres,"_seurat_after_RNAnorm.rds"))
  4652. # s_rods <- readRDS(file = paste0(ROD_prefixPCres,"_seurat_after_RNAnorm.rds"))
  4653. #### Plots ####
  4654. # PLOTS
  4655. VlnPlot(s_rods,
  4656. features = Rods,
  4657. stack = TRUE,
  4658. flip = TRUE) +
  4659. NoLegend() +
  4660. ggtitle("Rod Photoreceptors")
  4661. hirestiff(paste(ROD_prefixPCres,"VLN","Rod","genes","hires.tiff", sep = "_"))
  4662. lowrestiff(paste(ROD_prefixPCres,"VLN","Rod","genes","lowres.tiff", sep = "_"))
  4663. FeaturePlot(s_rods,
  4664. reduction = "umap",
  4665. features = c(Rods1),
  4666. order = TRUE,
  4667. min.cutoff = 'q10',
  4668. label = TRUE,
  4669. label.size = 5,
  4670. pt.size = 0.8)
  4671. hirestiff(paste(ROD_prefixPCres,"FTR","Rod","genes","1","hires.tiff", sep = "_"))
  4672. lowrestiff(paste(ROD_prefixPCres,"FTR","Rod","genes","1","lowres.tiff", sep = "_"))
  4673. FeaturePlot(s_rods,
  4674. reduction = "umap",
  4675. features = c(Rods2),
  4676. order = TRUE,
  4677. min.cutoff = 'q10',
  4678. label = TRUE,
  4679. label.size = 5,
  4680. pt.size = 0.8)
  4681. hirestiff(paste(ROD_prefixPCres,"FTR","Rod","genes","2","hires.tiff", sep = "_"))
  4682. lowrestiff(paste(ROD_prefixPCres,"FTR","Rod","genes","2","lowres.tiff", sep = "_"))
  4683. #### DEGs ####
  4684. #### Find Cluster Markers for ####
  4685. # find all markers
  4686. cluster_markers <- FindAllMarkers(s_rods, only.pos = TRUE, min.pct = 0.50, logfc.threshold = 0.4)
  4687. write.csv(cluster_markers,
  4688. file = paste(ROD_prefixPCres,"clustermarkers_pos_only_minpct0.50_logfcthresh0.4.csv", sep = "_"))
  4689. #### find DEGs between treatments ####
  4690. Idents(object = s_rods) <- "treatment"
  4691. cluster_markers <- FindAllMarkers(s_rods, only.pos = TRUE, min.pct = 0.25, logfc.threshold = 0.4)
  4692. write.csv(cluster_markers, file =
  4693. paste(ROD_prefixPCres,"degs_treatment_all_cells_minpct0.25_logfcthresh0.4.csv", sep = "_"))
  4694. Idents(object = s_rods) <- ident_res
  4695. #### find DEGs between time points ####
  4696. Idents(object = s_rods) <- "time_point"
  4697. cluster_markers <- FindAllMarkers(s_rods, only.pos = TRUE, min.pct = 0.25, logfc.threshold = 0.4)
  4698. write.csv(cluster_markers, file =
  4699. paste(ROD_prefixPCres,"degs_timepoint_all_cells_minpct0.25_logfcthresh0.4.csv", sep = "_"))
  4700. Idents(object = s_rods) <- ident_res
  4701. #### find DEGs between time points and treatment ####
  4702. Idents(object = s_rods) <- "time_point_treatment"
  4703. cluster_markers <- FindAllMarkers(s_rods, only.pos = TRUE, min.pct = 0.25, logfc.threshold = 0.4)
  4704. write.csv(cluster_markers, file =
  4705. paste(ROD_prefixPCres,"degs_timepoint_treatment_all_cells_minpct0.25_logfcthresh0.4.csv", sep = "_"))
  4706. Idents(object = s_rods) <- ident_res
  4707. #### Cone subset recluster ####
  4708. s_cones <- subset(seurat_sct,
  4709. idents = c("CONE9"))
  4710. #### SCT subset ####
  4711. DefaultAssay(s_cones) <- "RNA"
  4712. s_cones <- SCTransform(s_cones,
  4713. vars.to.regress = c("percent.mt","percent.ribo"),
  4714. verbose = TRUE)
  4715. #### update project variable to include subset ####
  4716. project <- "Rat_retina_CONES"
  4717. #### sub PCA ####
  4718. # this performs PCA on the seurat object
  4719. s_cones <- RunPCA(s_cones, npcs = 50, verbose = TRUE)
  4720. # make PC coordinate object a data frame
  4721. xx.coord <- as.data.frame(s_cones@reductions$[email hidden])
  4722. # make PC feature loadings object a data frame
  4723. xx.gload <- as.data.frame(s_cones@reductions$[email hidden])
  4724. # calculate eigenvalues for arrays
  4725. # generate squares of all sample coordinates
  4726. sq.xx.coord <- as.data.frame(xx.coord^2)
  4727. # create empty list for eigenvalues first
  4728. eig <- c()
  4729. # calculate the eigenvalue for each PC in sq.xx.coord by taking the sqrt of the sum of squares
  4730. for(i in 1:ncol(sq.xx.coord))
  4731. eig[i] = sqrt(sum(sq.xx.coord[,i]))
  4732. # calculate the total variance by adding up all the eigenvalues
  4733. sum.eig <- sum(eig)
  4734. # calculate the expected contribution of all PCs if they all contribute equally to the total variance
  4735. expected.contribution <- sum.eig/(length(xx.coord)-1)
  4736. # return the number of principal components with an eigenvalue greater than expected by equal variance
  4737. meaningful.PCs <- sum(eig > expected.contribution)
  4738. # create empty list for eigenvalue percentage
  4739. eig.percent <- c()
  4740. # calculate the percentage of the total variance by each PC eigenvalue
  4741. for(i in 1:length(eig))
  4742. eig.percent[i] = 100*eig[i]/sum.eig
  4743. # sum of all eig.percent should total to 100
  4744. sum(eig.percent)
  4745. # create empty list for scree values
  4746. scree <- c()
  4747. # calculate a running total of variance contribution
  4748. for(i in 1:length(eig))
  4749. if(i == 1) scree[i] = eig.percent[i] else scree[i] = scree[i-1] + eig.percent[i]
  4750. # create data frame for eigenvalue summaries
  4751. eigenvalues <- data.frame("PC" = colnames(xx.coord), "eig" = eig, "percent" = eig.percent, "scree" = scree)
  4752. # write csv for eigenvalues
  4753. # write.csv(eigenvalues, file = paste0("./",date,"_",project,"_PCA_eigenvalues.csv"), row.names = F)
  4754. # plot scree values
  4755. plot(eigenvalues$percent, ylim = c(0,100), type = "S", xlab = "PC", ylab = "Percent of variance",
  4756. main = paste0(date,"_",project," scree plot all samples PCA"))
  4757. points(eigenvalues$scree, ylim = c(0,100), type = "p", pch = 16)
  4758. lines(eigenvalues$scree)
  4759. # add red line to indicate cut-off
  4760. cut.off <- 100/(length(eig)-1)
  4761. abline(h = cut.off, col = "red")
  4762. # add blue line to indicate which PCs are meaningful and kept
  4763. abline(v = meaningful.PCs, col = "blue")
  4764. text(meaningful.PCs, cut.off, label = paste("cutoff PC",meaningful.PCs),
  4765. adj = c(-0.1, -0.5))
  4766. dev.copy(pdf, paste0("./",date,"_",project,"_scree_plot.pdf"))
  4767. dev.off()
  4768. rm(eigenvalues,sq.xx.coord,xx.coord,xx.gload,cut.off,
  4769. eig,eig.percent,expected.contribution,i,scree,sum.eig)
  4770. # meaningful.PCs <- 10
  4771. #### sub Run UMAP and look at UMAP plots ####
  4772. s_cones <- RunUMAP(s_cones,
  4773. reduction = "pca",
  4774. dims = 1:meaningful.PCs,
  4775. verbose = TRUE)
  4776. # update prefixed variable
  4777. prefixPC <- paste0("./",date,"_",project,"_",meaningful.PCs,"PCs")
  4778. ## UMAP plot by sample name ("orig.ident")
  4779. DimPlot(s_cones, reduction = "umap", label = FALSE,
  4780. pt.size = .25, group.by = "orig.ident")
  4781. hirestiff(paste0(prefixPC,"_UMAP_by_sample_hires.tiff"))
  4782. lowrestiff(paste0(prefixPC,"_UMAP_by_sample_lowres.tiff"))
  4783. DimPlot(s_cones, reduction = "umap", label = FALSE,
  4784. pt.size = .25, group.by = "treatment")
  4785. hirestiff(paste0(prefixPC,"_UMAP_by_treatment_hires.tiff"))
  4786. lowrestiff(paste0(prefixPC,"_UMAP_by_treatment_lowres.tiff"))
  4787. DimPlot(s_cones, reduction = "umap", label = FALSE,
  4788. pt.size = .25, split.by = "treatment", group.by = "treatment")
  4789. hirestiff(paste0(prefixPC,"_UMAP_split_by_treatment_hires.tiff"))
  4790. lowrestiff(paste0(prefixPC,"_UMAP_split_by_treatment_lowres.tiff"))
  4791. DimPlot(s_cones, reduction = "umap", label = FALSE,
  4792. pt.size = .25, group.by = "batch")
  4793. hirestiff(paste0(prefixPC,"_UMAP_by_batch_hires.tiff"))
  4794. lowrestiff(paste0(prefixPC,"_UMAP_by_batch_lowres.tiff"))
  4795. DimPlot(s_cones, reduction = "umap", label = FALSE,
  4796. pt.size = .25, group.by = "batch", split.by = "batch")
  4797. hirestiff(paste0(prefixPC,"_UMAP_split_by_batch_hires.tiff"))
  4798. lowrestiff(paste0(prefixPC,"_UMAP_split_by_batch_lowres.tiff"))
  4799. DimPlot(s_cones, reduction = "umap", label = FALSE,
  4800. pt.size = .25, group.by = "time_point")
  4801. hirestiff(paste0(prefixPC,"_UMAP_by_time_point_hires.tiff"))
  4802. lowrestiff(paste0(prefixPC,"_UMAP_by_time_point_lowres.tiff"))
  4803. DimPlot(s_cones, reduction = "umap", label = FALSE,
  4804. pt.size = .25, split.by = "time_point", group.by = "time_point")
  4805. hirestiff(paste0(prefixPC,"_UMAP_split_by_time_point_hires.tiff"))
  4806. lowrestiff(paste0(prefixPC,"_UMAP_split_by_time_point_lowres.tiff"))
  4807. DimPlot(s_cones, reduction = "umap", label = FALSE,
  4808. pt.size = .25, group.by = "time_point_treatment")
  4809. hirestiff(paste0(prefixPC,"_UMAP_by_time_point_treatment_hires.tiff"))
  4810. lowrestiff(paste0(prefixPC,"_UMAP_by_time_point_treatment_lowres.tiff"))
  4811. DimPlot(s_cones, reduction = "umap", label = FALSE,
  4812. pt.size = 1, split.by = "time_point_treatment",
  4813. group.by = "time_point_treatment")
  4814. hirestiff(paste0(prefixPC,"_UMAP_split_by_time_point_treatment_hires.tiff"))
  4815. lowrestiff(paste0(prefixPC,"_UMAP_split_by_time_point_treatment_lowres.tiff"))
  4816. DimPlot(s_cones, reduction = "umap", label = FALSE, pt.size = .25, group.by = "time_point_batch")
  4817. hirestiff(paste0(prefixPC,"_UMAP_by_time_point_batch_hires.tiff"))
  4818. lowrestiff(paste0(prefixPC,"_UMAP_by_time_point_batch_lowres.tiff"))
  4819. DimPlot(s_cones, reduction = "umap", label = FALSE, pt.size = .25, split.by = "time_point_batch", group.by = "time_point_batch")
  4820. hirestiff(paste0(prefixPC,"_UMAP_split_by_time_point_batch_hires.tiff"))
  4821. lowrestiff(paste0(prefixPC,"_UMAP_split_by_time_point_batch_lowres.tiff"))
  4822. DimPlot(s_cones, reduction = "umap", label = FALSE, pt.size = .25, group.by = "treatment_batch")
  4823. hirestiff(paste0(prefixPC,"_UMAP_by_treatment_batch_hires.tiff"))
  4824. lowrestiff(paste0(prefixPC,"_UMAP_by_treatment_batch_lowres.tiff"))
  4825. DimPlot(s_cones, reduction = "umap", label = FALSE, pt.size = .25, split.by = "treatment_batch", group.by = "treatment_batch")
  4826. hirestiff(paste0(prefixPC,"_UMAP_split_by_treatment_batch_hires.tiff"))
  4827. lowrestiff(paste0(prefixPC,"_UMAP_split_by_treatment_batch_lowres.tiff"))
  4828. DimPlot(s_cones, reduction = "umap", label = FALSE, pt.size = .25, group.by = "time_point_treatment_batch")
  4829. hirestiff(paste0(prefixPC,"_UMAP_by_time_point_treatment_batch_hires.tiff"))
  4830. lowrestiff(paste0(prefixPC,"_UMAP_by_time_point_treatment_batch_lowres.tiff"))
  4831. DimPlot(s_cones, reduction = "umap", label = FALSE, pt.size = .25, split.by = "time_point_treatment_batch", group.by = "time_point_treatment_batch")
  4832. hirestiff(paste0(prefixPC,"_UMAP_split_by_time_point_treatment_batch_hires.tiff"))
  4833. lowrestiff(paste0(prefixPC,"_UMAP_split_by_time_point_treatment_batch_lowres.tiff"))
  4834. # saveRDS(s_cones, file = paste0(prefixPC,"_seurat_integrated_preclustering.rds"))
  4835. # s_cones <- read_rds(file = paste0(prefixPC,"_seurat_integrated_preclustering.rds"))
  4836. #### sub Clustering and Resolution ####
  4837. # DefaultAssay(s_cones) <- "integrated"
  4838. # Determine the K-nearest neighbor graph
  4839. s_cones <- FindNeighbors(object = s_cones, reduction = "pca", dims = 1:meaningful.PCs)
  4840. # Determine the clusters
  4841. s_cones <- FindClusters(object = s_cones,
  4842. resolution = c(0.1,0.2,0.3,0.4,0.5))
  4843. view([email hidden])
  4844. res <- "_res.0.1"
  4845. ident_res <- paste0("SCT_snn",res)
  4846. Idents(s_cones) <- ident_res
  4847. DimPlot(s_cones, reduction = "umap", label = TRUE, label.size = 5, pt.size = 0.8) +
  4848. NoLegend() +
  4849. ggtitle(paste0(ident_res))
  4850. #update prefix
  4851. prefixPCres <- paste0(prefixPC,res)
  4852. # Plot the UMAP
  4853. DimPlot(s_cones, reduction = "umap", label = TRUE, label.size = 6, pt.size = 0.8) +
  4854. NoLegend() +
  4855. ggtitle(paste0(ident_res))
  4856. hirestiff(paste0(prefixPCres,"_UMAP","_by_","cluster","_hires.tiff"))
  4857. lowrestiff(paste0(prefixPCres,"_UMAP","_by_","cluster","_lowres.tiff"))
  4858. # UMAP of cells in each cluster by treatment without cluster labels
  4859. DimPlot(s_cones, reduction = "umap", label = FALSE,

20230922_rat_retina_with_GEO.R at commit 0ca5d25, under Apache-2.0 · at the source

Overview

Authors: Saba Shahin1, Shaughn Bell1, Bin Lu1, Somanshu Banerjee2, Vivek Swarup3,4, Hui Xu1, Jason Chetsawang1, Stephany Ramirez1, Jorge S. Alfaro1, Alexander Laperle1, Soshana Svendsen1, Clive N. Svendsen1, Shaomei Wang1
  1. Board of Governors Regenerative Medicine Institute, Department of Biomedical Sciences, Cedars-Sinai Medical Center,Los Angeles, CA USA
  2. Department of Anesthesiology and Perioperative Medicine, University of California,Los Angeles, CA USA
  3. Department of Neurobiology and Behavior, University of California Irvine,Irvine, CA USA
  4. Institute for Memory Impairments and Neurological Disorders (MIND), University of California Irvine,Irvine, CA USA
Institutions: Cedars-Sinai Medical Center (United States); University of California, Los Angeles (United States); University of California, Irvine (United States)
Journal: Nature communications, volume 17, issue 1, article 2164
Dates: received 22 March 2025; accepted 10 February 2026; published online 6 March 2026
Type: Research article · Language: English
License: CC BY-NC-ND
Identifiers: DOI 10.1038/s41467-026-69776-4 · PMID 41792118 · PMCID PMC12966429 · OpenAlex W7134034167
Open access: gold, a free copy (OpenAlex)
Status: code verified
Categories: genetics / omics (modality), human (organism), rat (organism)
Methods: Statistics, Smoothing, state filtering, decompositions, fMRI & imaging
Keywords: Retina, Neural stem cells
MeSH: Neural Stem Cells*, Retinitis Pigmentosa*, Transcriptome*, Vision, Ocular*, Animals, Apoptosis, Cell Differentiation, Disease Models, Animal, Humans, Oxidative Stress, Rats, Retina, Single-Cell Gene Expression Analysis, Stem Cell Transplantation (* major topic)
Topic: Retinal Development and Disorders (Molecular Biology, Biochemistry, Genetics and Molecular Biology), according to OpenAlex
Funding: California Institute for Regenerative Medicine (CIRM) (LSP1-08235, EDUC-0833 &12638); Board of Governors Regenerative Medicine Institute at Cedars-Sinai Medical Center
Citations: not cited yet (Europe PMC); 95 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.

Repositories

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

sshahin07/WangLabCedars_hNPC_Retina_scRNA_Shahin_2025

License: Apache-2.0
State: the link answers, verified on 30 September 2026
Evidence: files inventoried
Commit: 0ca5d25fd25878bd9729e99e600919817b0b7dcb, 26 January 2026
Languages: R (3)
Size: 5 files, 3 scripts
Software Heritage: not archived
Found in: “Code availability”
Holds: README, license file, 2 notebooks
Not found: CITATION.cff, environment file, tests, continuous integration, documentation
Tools: cowplot (3 files), ggplot2 (3 files), patchwork (3 files), Seurat (3 files), tidyverse (3 files), Harmony (2 files), UMAP (2 files), pheatmap (1 file), SingleCellExperiment (1 file)
Availability: 1 check, the latest on 30 September 2026: the link answers
  • 30 September 2026: the link answers
5 files

Zenodo 18374447

License: Apache-2.0
State: the link answers, verified on 30 September 2026
Evidence: files inventoried
Size: 1 file
Software Heritage: not checked
Found in: “Code availability”
Not found: README, license file, CITATION.cff, environment file, tests, continuous integration, documentation
Tools: cowplot (3 files), ggplot2 (3 files), patchwork (3 files), Seurat (3 files), tidyverse (3 files), Harmony (2 files), UMAP (2 files), pheatmap (1 file), SingleCellExperiment (1 file)
Availability: 1 check, the latest on 30 September 2026: the link answers (HTTP 200)
  • 30 September 2026: the link answers (HTTP 200)
5 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-69776-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:

  • 2 repositories of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 6 scripts, each with its path and the digest of its content;
  • 8 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-69776-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, 13 authors, 2 keywords, 14 MeSH terms, 2 funders, 95 references.

Cite

This paper

Shahin, S., Bell, S., Lu, B., Banerjee, S., Swarup, V., Xu, H., Chetsawang, J., Ramirez, S., Alfaro, J. S., Laperle, A., Svendsen, S., Svendsen, C. N., & Wang, S. (2026). Dynamic transcriptomic remodeling in grafted human neural progenitor cells uncovers mechanisms for vision preservation in a rat model of retinitis pigmentosa. Nature communications, 17(1), 2164. https://doi.org/10.1038/s41467-026-69776-4

BibTeX

@article{shahin2026dynamic,
author = {Shahin, Saba and Bell, Shaughn and Lu, Bin and Banerjee, Somanshu and Swarup, Vivek and Xu, Hui and Chetsawang, Jason and Ramirez, Stephany and Alfaro, Jorge S. and Laperle, Alexander and Svendsen, Soshana and Svendsen, Clive N. and Wang, Shaomei},
title = {{Dynamic transcriptomic remodeling in grafted human neural progenitor cells uncovers mechanisms for vision preservation in a rat model of retinitis pigmentosa}},
journal = {Nature communications},
year = {2026},
month = mar,
volume = {17},
number = {1},
pages = {2164},
publisher = {Nature Publishing Group},
issn = {2041-1723},
doi = {10.1038/s41467-026-69776-4},
url = {https://doi.org/10.1038/s41467-026-69776-4},
pmid = {41792118},
pmcid = {PMC12966429}
}

RIS

TY - JOUR
AU - Shahin, Saba
AU - Bell, Shaughn
AU - Lu, Bin
AU - Banerjee, Somanshu
AU - Swarup, Vivek
AU - Xu, Hui
AU - Chetsawang, Jason
AU - Ramirez, Stephany
AU - Alfaro, Jorge S.
AU - Laperle, Alexander
AU - Svendsen, Soshana
AU - Svendsen, Clive N.
AU - Wang, Shaomei
TI - Dynamic transcriptomic remodeling in grafted human neural progenitor cells uncovers mechanisms for vision preservation in a rat model of retinitis pigmentosa
T2 - Nature communications
J2 - Nat Commun
PY - 2026
DA - 2026/03/06
VL - 17
IS - 1
SP - 2164
SN - 2041-1723
PB - Nature Publishing Group
DO - 10.1038/s41467-026-69776-4
UR - https://doi.org/10.1038/s41467-026-69776-4
LA - en
ER -

CSL-JSON

{
"id": "10.1038/s41467-026-69776-4",
"type": "article-journal",
"title": "Dynamic transcriptomic remodeling in grafted human neural progenitor cells uncovers mechanisms for vision preservation in a rat model of retinitis pigmentosa",
"container-title": "Nature communications",
"author": [
{
"family": "Shahin",
"given": "Saba"
},
{
"family": "Bell",
"given": "Shaughn"
},
{
"family": "Lu",
"given": "Bin"
},
{
"family": "Banerjee",
"given": "Somanshu"
},
{
"family": "Swarup",
"given": "Vivek"
},
{
"family": "Xu",
"given": "Hui"
},
{
"family": "Chetsawang",
"given": "Jason"
},
{
"family": "Ramirez",
"given": "Stephany"
},
{
"family": "Alfaro",
"given": "Jorge S."
},
{
"family": "Laperle",
"given": "Alexander"
},
{
"family": "Svendsen",
"given": "Soshana"
},
{
"family": "Svendsen",
"given": "Clive N."
},
{
"family": "Wang",
"given": "Shaomei"
}
],
"container-title-short": "Nat Commun",
"volume": "17",
"issue": "1",
"page": "2164",
"DOI": "10.1038/s41467-026-69776-4",
"PMID": "41792118",
"PMCID": "PMC12966429",
"ISSN": "2041-1723",
"publisher": "Nature Publishing Group",
"URL": "https://doi.org/10.1038/s41467-026-69776-4",
"language": "en",
"issued": {
"date-parts": [
[
2026,
3,
6
]
]
}
}

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.1016/j.xcrm.2026.102766 [code]
A longitudinal single-cell and spatial multiomic atlas of pediatric high-grade glioma.
Journal: Cell reports. Medicine
In common: Harmony, SingleCellExperiment, UMAP, 6 other tools, genetics / omics, 3 references
[2] doi:10.1038/s41467-026-76232-w [code]
Th17 effector cytokines induce shared and distinct microglial and endothelial cell responses in a mouse model for post-streptococcal encephalitis.
Journal: Nature communications
In common: Harmony, SingleCellExperiment, UMAP, 5 other tools, genetics / omics, 4 references
[3] doi:10.1038/s41420-026-02971-w [code]
Multi-omics reveals heterogeneity and functional populations of oligodendrocyte progenitor cells induced by human neural stem cells.
Journal: Cell death discovery
In common: Harmony, SingleCellExperiment, UMAP, 5 other tools, genetics / omics, 3 references
[4] doi:10.1038/s41467-026-70232-6 [code]
Gene expression dynamics of human and mouse craniofacial development at the single-cell level.
Journal: Nature communications
In common: Harmony, SingleCellExperiment, pheatmap, 5 other tools, genetics / omics, 3 references
[5] doi:10.1016/j.celrep.2026.117500 [code]
Spatio-molecular gene expression reflects dorsal anterior cingulate cortex structure and function in the human brain.
Journal: Cell reports
In common: Harmony, SingleCellExperiment, pheatmap, 5 other tools, genetics / omics, 2 references
[6] doi:10.1186/s13073-026-01704-z [code]
Gene expression profiling enables refined parcellation of cortical layers in the heterogeneous human cerebral cortex.
Journal: Genome medicine
In common: Harmony, SingleCellExperiment, UMAP, 6 other tools, genetics / omics
[7] doi:10.1016/j.cell.2026.05.026 [code]
The critical role of the endogenous immune compartment after CAR T cell therapy in recurrent GBM.
Journal: Cell
In common: Harmony, SingleCellExperiment, Seurat, 4 other tools, genetics / omics, 3 references
[8] doi:10.1093/brain/awaf426 [code]
Single-nucleus multiome shows motor neuron glutamate overactivation in amyotrophic lateral sclerosis.
Journal: Brain : a journal of neurology
In common: Harmony, SingleCellExperiment, pheatmap, 4 other tools, genetics / omics, 3 references
[9] doi:10.1038/s41593-026-02367-0 [code]
A reproducible three-dimensional model of human brain tissue to investigate physiological and disease-associated microglia phenotypes.
Journal: Nature neuroscience
In common: Harmony, SingleCellExperiment, pheatmap, 5 other tools, 2 references
[10] doi:10.1038/s41586-026-10612-6 [code]
Acquired genetic and cell-state changes in IDH-mutant glioma progression.
Journal: Nature
In common: Harmony, SingleCellExperiment, pheatmap, 5 other tools, 2 references

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.

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: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.

Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.

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