OSCR

Identification and validation of central amygdala FGFR1 as a therapeutic target for alcohol use disorder using single-nucleus sequencing in rats.

Code ↔ Paper

4 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 4 matches
  1. [1] § Methods › snRNA-seq data processing › Co-expression network analysis ↔ master.R, lines 783–862 · score 0.94 · soft power, ConstructNetwork, ModuleConnectivity, ModuleEigengenes, SampleID, WGCNA
  2. [2] § Methods › snRNA-seq data processing › Quality control and clustering ↔ master.R, lines 89–145 · score 0.88 · SCTransform, percent.mt, percent.ribo, sample layers, M22, M33
  3. [3] § Methods › snRNA-seq data processing › Differential expression analysis ↔ master.R, lines 1615–1684 · score 0.77 · distinct_test, min_non_zero_cells, name_cluster, name_sample, cpm, matrix
  4. [4] § Methods › snRNA-seq data processing › Subclustering of GABAergic cells ↔ master.R, lines 432–491 · score 0.69 · percent.mt, percent.ribo, sample layers, split, subset, Subclustering

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 · 2,362 lines · 59 KB · MIT · 4 matches

  1. library(Seurat)
  2. library(SeuratDisk)
  3. setwd("D:/Leon/snRNAseq/heilig_data_transfer/R/high_depth")
  4. library(BPCells)
  5. adata.data = open_matrix_anndata_hdf5("D:/Leon/snRNAseq/high_depth_processing/Heilig_aggr_noF1_nonormalize_highdepth/outs/count/high_processing.h5ad")
  6. write_matrix_dir(
  7. mat = adata.data,
  8. dir = "D:/Leon/snRNAseq/heilig_data_transfer/R/high_depth/counts"
  9. )
  10. adata.mat = open_matrix_dir(dir = "D:/Leon/snRNAseq/heilig_data_transfer/R/high_depth/counts")
  11. #library(biomaRt)
  12. #ensembl = useMart("ensembl", dataset = "rnorvegicus_gene_ensembl")
  13. #bm = getBM(attributes = c("ensembl_gene_id", "external_gene_name"), values = rownames(adata.mat), mart = ensembl)
  14. #symbols = bm$external_gene_name[match(rownames(adata.mat), bm$ensembl_gene_id)]
  15. #rownames(adata.mat) = symbols
  16. adata = CreateSeuratObject(counts = adata.mat, min.cells = 3, min.features = 200)
  17. adata
  18. SampleID_barcode <- read.csv("D:/Leon/snRNAseq/high_depth_processing/Heilig_aggr_noF1_nonormalize_highdepth/outs/SampleID.csv")
  19. meta_file<-read.csv("D:/Leon/snRNAseq/high_depth_processing/Heilig_aggr_noF1_nonormalize_highdepth/outs/aggregation.csv")
  20. barcode_sampleid<-merge(SampleID_barcode,meta_file,by.x="SampleID",by.y="sample_id")
  21. rownames(barcode_sampleid)<-barcode_sampleid$Barcode
  22. adata<-AddMetaData(adata,barcode_sampleid)
  23. adata = subset(adata, subset = Sex == "Male")
  24. adata[["RNA"]]$counts <- as(object = adata[["RNA"]]$counts, Class = "dgCMatrix")
  25. Features(adata)
  26. saveRDS(adata, "males_unprocessed_high.Rds")
  27. #-----------------------------------------------QC---------------------------------------
  28. library(Seurat)
  29. library(BPCells)
  30. library(scuttle)
  31. setwd("D:/Leon/snRNAseq/heilig_data_transfer/R/high_depth")
  32. adata = readRDS("males_unprocessed_high.Rds")
  33. adata
  34. library(BiocParallel)
  35. library(scDblFinder)
  36. #adata[["RNA"]]$counts <- as(object = adata[["RNA"]]$counts, Class = "dgCMatrix")
  37. adata = as.SingleCellExperiment(adata)
  38. adata = scDblFinder(adata, samples="SampleID")
  39. table(adata$scDblFinder.class)
  40. adata = as.Seurat(adata, data = NULL)
  41. adata
  42. gc()
  43. Idents(adata) <- "scDblFinder.class"
  44. adata = subset(adata, idents = "singlet") #remove doublets
  45. adata
  46. adata[['percent.mt']] = PercentageFeatureSet(adata, pattern = "^Mt-")
  47. gc()
  48. adata[['percent.ribo']] = PercentageFeatureSet(adata, pattern = "(^Rpl|^Rps|^Mrp)")
  49. gc()
  50. #adata.sce = as.SingleCellExperiment(adata)
  51. #low.total = isOutlier(adata.sce$nCount_RNA, type="lower", log=TRUE, batch = adata.sce$SampleID)
  52. #summary(low.total)
  53. #discard.mito = isOutlier(adata.sce$percent.mt, type="higher", batch=adata.sce$SampleID)
  54. #discard.ribo = isOutlier(adata.sce$percent.ribo, type="higher", batch=adata.sce$SampleID)
  55. #discard.sum = isOutlier(adata.sce$nCount_RNA, type="lower", log=TRUE, batch=adata.sce$SampleID)
  56. #discard.feature = isOutlier(adata.sce$nFeature_RNA, type="lower", log=TRUE, batch=adata.sce$SampleID)
  57. #qc.stats = perCellQCMetrics(adata.sce)
  58. VlnPlot(adata, 'nFeature_RNA', group.by = 'SampleID', pt.size = 0)
  59. VlnPlot(adata, 'nCount_RNA', group.by = 'SampleID', pt.size = 0)
  60. VlnPlot(adata, 'percent.mt', group.by = 'SampleID', pt.size = 0)
  61. VlnPlot(adata, 'percent.ribo', group.by = 'SampleID', pt.size = 0)
  62. FeatureScatter(adata, 'nCount_RNA', 'percent.mt')
  63. FeatureScatter(adata, 'nCount_RNA', 'nFeature_RNA')
  64. adata = adata[, !adata$SampleID=='M22'] #removing bad samples
  65. adata = adata[, !adata$SampleID=='M33']
  66. adata = adata[, !adata$SampleID=='M8']
  67. gc()
  68. adata = subset(adata, subset = nFeature_RNA < 7000)
  69. adata = subset(adata, subset = percent.mt < 5)
  70. adata = subset(adata, subset = percent.ribo < 2.5)
  71. gc()
  72. VlnPlot(adata, 'nFeature_RNA', group.by = 'SampleID', pt.size = 0)
  73. VlnPlot(adata, 'percent.mt', group.by = 'SampleID', pt.size = 0)
  74. VlnPlot(adata, 'percent.ribo', group.by = 'SampleID', pt.size = 0)
  75. adata
  76. FeatureScatter(adata, 'nCount_RNA', 'percent.mt')
  77. FeatureScatter(adata, 'nCount_RNA', 'nFeature_RNA')
  78. saveRDS(adata, "males_filtered_high.rds")
  79. #---------------------------normalization----------------------------------
  80. adata = readRDS("males_filtered_high.rds")
  81. table(adata$Groups)
  82. counts = GetAssayData(adata, assay = "RNA")
  83. #remove mito and ribo genes
  84. discard = which(grepl("^Rpl|^Rps|^Mt-|^Mrp", rownames(counts)))
  85. counts = counts[-c(discard),]
  86. adata = subset(adata, features = rownames(counts))
  87. adata
  88. gc()
  89. adata[["RNA"]] <- split(adata[["RNA"]], f = adata$SampleID) #split the counts into sample-layers
  90. gc()
  91. adata <- SCTransform(adata, vars.to.regress = c("percent.mt", "percent.ribo"))
  92. gc()
  93. saveRDS(adata, "filtered_SCT_high.rds")
  94. #---------------------------------------------- dim reduction and clustering -----------------------------------
  95. library(Seurat)
  96. setwd("D:/Leon/snRNAseq/heilig_data_transfer/R/high_depth")
  97. adata = readRDS("filtered_SCT_high.rds")
  98. gc()
  99. adata
  100. adata = RunPCA(adata)
  101. gc()
  102. ElbowPlot(adata,ndims = 50)
  103. gc()
  104. adata = RunUMAP(adata, dims = 1:50, metric = 'euclidean', reduction.name = 'euclidean_umap')
  105. gc()
  106. #adata = RunUMAP(adata, dims = 1:50, metric = 'correlation', reduction.name = 'correlation_umap')
  107. adata
  108. gc()
  109. DimPlot(adata, reduction = "euclidean_umap", group.by = "SampleID")
  110. DimPlot(adata, reduction = "euclidean_umap", group.by = "Groups")
  111. gc()
  112. adata <- FindNeighbors(adata, dims = 1:50, reduction = "pca")
  113. gc()
  114. adata <- FindClusters(adata, resolution = 0.1, cluster.name = "SCT_clusters")
  115. gc()
  116. DimPlot(adata, reduction = "euclidean_umap", group.by = "SCT_clusters")
  117. gc()
  118. adata = PrepSCTFindMarkers(adata)
  119. gc()
  120. adata.markers = FindAllMarkers(adata, only.pos = TRUE)
  121. saveRDS(adata, "high_clustered.rds")
  122. write.csv(adata.markers, "high_markers.csv")
  123. #---------------------------anotation------------------------------------
  124. library(Seurat)
  125. setwd("D:/Leon/snRNAseq/heilig_data_transfer/R/high_depth")
  126. adata = readRDS("high_clustered.rds")
  127. markers = read.csv('high_markers.csv')
  128. gc()
  129. DimPlot(adata, reduction = "euclidean_umap", group.by = "SCT_clusters", label = TRUE)
  130. markers[markers$gene == "Slc17a7",]
  131. gc()
  132. VlnPlot(adata, features = c(""))
  133. FeaturePlot(adata, features = c("Ndst4"), reduction = "euclidean_umap")
  134. VlnPlot(adata, features = c("Slc17a7"))
  135. #adata = RenameIdents(adata,
  136. "0" = "Oligendrocytes", #Mog, Mobp, Mag
  137. "1"= "Gabaergic", #Rbfox3, Gad1, Gad2,
  138. "2" = "Gabaergic", #Rbfox3, Gad1, Gad2,
  139. "3" = "Hbb-b1_Hbb-a2_Blood?", #,
  140. "4" = "OPC", #Pdgfra, Epn2, Neu4, Pcdh15
  141. "5" = "Microglia", # Itgam, Cx3cr1, P2ry12, Tmem119
  142. "6" = "Gabaergic", #Rbfox3, Gad2, Foxp2,
  143. "7" = "Astrocytes", #Slc1a2, Gfap, Agt, Aqp4,
  144. "8" = "Gabaergic", #Rbfox3, Gad1, Foxp2,
  145. "9" = "Gabaergic", #Rbfox3, Gad1, Gad2,
  146. "10" = "Gabaergic", #Gad1, Gad2,
  147. "11" = "Glutaminergic_Slc17a6", #Rbfox3, Slc17a6,
  148. "12" = "Endothelial", #Cd93, Vwf, Emcn, Flt1
  149. "13" = "Cholinergic", #Slc5a7, Acly,
  150. "14" = "Glutaminergic_Slc17a7", #Slc17a7, Rbfox3,
  151. "15" = "Gabaergic", #Rbfox3, Gad1, Gad2,
  152. "16" = "Microglia", #Itgam, Cx3cr1, P2ry12, Tmem119
  153. "17" = "Microglia ", #Itgam, P2ry12,
  154. )
  155. current.cluster.ids = c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17)
  156. new.cluster.ids = c("Oligendrocytes","Gabaergic","Gabaergic", "Hbb-b1_Hbb-a2_Blood?",
  157. "OPC","Microglia","Gabaergic","Astrocytes","Gabaergic",
  158. "Gabaergic","Gabaergic","Glutaminergic_Slc17a6","Endothelial",
  159. "Cholinergic","Glutaminergic_Slc17a7","Gabaergic","Microglia","Microglia")
  160. library(plyr)
  161. adata$cell_type = plyr::mapvalues(x = adata$SCT_clusters, from = current.cluster.ids, to = new.cluster.ids)
  162. DimPlot(adata, group.by='cell_type', reduction = "euclidean_umap")
  163. #---------------------- cluster exploration------------------------
  164. Idents(adata) = adata$cell_type
  165. RidgePlot(adata, features = "percent.ribo")
  166. RidgePlot(adata, features = "percent.mt")
  167. RidgePlot(adata, features = "nCount_RNA")
  168. RidgePlot(adata, features = "nFeature_RNA")
  169. table(adata$cell_type, adata$SampleID)
  170. DimPlot(adata, group.by='SampleID', reduction = "euclidean_umap")
  171. features = c("Mog", "Mobp", "Mag", "Gad1", "Gad2", "Hbb-b1", "Hba-a2",
  172. "Pdgfra", "Epn2", "Pcdh15", "Csf1r", "Cx3cr1", "P2ry12", "Tmem119",
  173. "Satb1", "Slc17a6","Slc17a7", "Cd93", "Vwf", "Emcn", "Flt1", "Slc5a7",
  174. "Acly", "Slc1a2", "Gfap", "Agt", "Aqp4", "Plp1"
  175. , "Rbfox3")
  176. DotPlot(adata, features = features, group.by = "cell_type") + RotatedAxis()
  177. VlnPlot(adata, "Mog", layer = "scale.data", pt.size = 0)
  178. RidgePlot(adata, features = c("Gad1", "Gad2"), layer = "scale.data", ncol = 2)
  179. RidgePlot(adata, features = c("Rbfox3"), layer = "scale.data", ncol = 1)
  180. RidgePlot(adata, features = c("Pdgfra", "Pcdh15"), layer = "scale.data", ncol = 1)
  181. RidgePlot(adata, features = c("Csf1r", "Cx3cr1", "P2ry12"), layer = "scale.data", ncol = 1)
  182. RidgePlot(adata, features = c("Slc17a7", "Slc17a6"), ncol = 1)
  183. RidgePlot(adata, features = c("Emcn"), layer = "scale.data", ncol = 1)
  184. RidgePlot(adata, features = c("Slc5a7"), layer = "scale.data", ncol = 1)
  185. RidgePlot(adata, features = c("Slc1a2"), layer = "scale.data", ncol = 1)
  186. saveRDS(adata, "high_annotated.rds")
  187. ############################ decontX ###############################
  188. setwd("D:/Leon/snRNAseq/heilig_data_transfer/R/high_depth")
  189. library(Seurat)
  190. library(celda)
  191. library(qs)
  192. adata = readRDS('high_annotated.rds')
  193. gc()
  194. DefaultAssay(adata) = 'RNA'
  195. adata
  196. gc()
  197. adata[['RNA']] = JoinLayers(adata[['RNA']])
  198. gc()
  199. counts = GetAssayData(adata, slot = 'counts')
  200. gc()
  201. sce = SingleCellExperiment(list(counts = counts))
  202. gc()
  203. sce = decontX(sce)
  204. metadata(sce)$decontX$estimates$all_cells$delta
  205. #öka delta här
  206. sce.delta = decontX(sce, delta = c(3.55, 20), estimateDelta = F)
  207. library(scater)
  208. plot(sce$decontX_contamination, sce.delta$decontX_contamination,
  209. xlab = "DecontX estimated priors",
  210. ylab = "Setting priors to estimate higher contamination")
  211. abline(0, 1, col = "red", lwd = 2)
  212. umap = reducedDim(sce.delta, "decontX_UMAP")
  213. plotDimReduceCluster(sce.delta$decontX_clusters,
  214. dim1 = umap[, 1], dim2 = umap[, 2])
  215. plotDecontXContamination(sce)
  216. plotDecontXContamination(sce.delta)
  217. differences_sce = rowMeans(counts) - rowMeans(decontXcounts(sce))
  218. gc()
  219. top_genes_sce = sort(abs(differences_sce), decreasing = T)[1:20]
  220. top_genes_sce
  221. differences_sce_delta = rowMeans(counts) - rowMeans(decontXcounts(sce.delta))
  222. gc()
  223. top_genes_sce_delta = sort(abs(differences_sce_delta), decreasing = T)[1:20]
  224. top_genes_sce_delta
  225. gc()
  226. sum(counts(sce) < decontXcounts(sce))
  227. celltypemappings = list(Oligodendrocytes = 2
  228. )
  229. plotDecontXMarkerExpression(sce,
  230. markers = 'Kcnip4',
  231. groupClusters = celltypemappings
  232. )
  233. adata[["decontXcounts"]] = CreateAssayObject(counts = decontXcounts(sce.delta))
  234. gc()
  235. VlnPlot(adata, 'Gad1', group.by = 'cell_type', pt.size = 0, assay = 'decontXcounts') + NoLegend()
  236. VlnPlot(adata, 'Gad1', group.by = 'cell_type', pt.size = 0, assay = 'RNA') + NoLegend()
  237. rm(counts)
  238. rna_matrix = GetAssayData(adata, assay = "RNA", layer = 'counts')
  239. gc()
  240. decontx_matrix = GetAssayData(adata, assay = "decontXcounts", layer = "counts")
  241. common_genes = intersect(rownames(rna_matrix), rownames(decontx_matrix))
  242. rna_matrix = rna_matrix[common_genes,]
  243. decontx_matrix = decontx_matrix[common_genes,]
  244. gc()
  245. differences = rowMeans(rna_matrix) - rowMeans(decontx_matrix)
  246. gc()
  247. top_genes = names(sort(abs(differences), decreasing = T))[1:20]
  248. top_genes
  249. VlnPlot(adata, group.by = 'cell_type', 'Nkain2', pt.size = 0, assay = 'decontXcounts') + NoLegend()
  250. VlnPlot(adata, group.by = 'cell_type', 'Nkain2', pt.size = 0, assay = 'RNA') + NoLegend()
  251. genes = c('Kcnip4', 'Nkain2')
  252. for (gene in top_genes) {
  253. DefaultAssay(adata) = 'RNA'
  254. FeaturePlot(adata, gene, reduction = 'euclidean_umap', max.cutoff = 1) + NoLegend()
  255. ggsave(paste0('males/decontx/gabaergic/genes/',gene,'_before_decont.jpg'))
  256. DefaultAssay(adata) = 'decontXcounts'
  257. FeaturePlot(adata, gene, reduction = 'euclidean_umap', max.cutoff = 1) + NoLegend()
  258. ggsave(paste0('males/decontx/gabaergic/genes/',gene,'_after_decont.jpg'))
  259. }
  260. qsave(adata, 'high_annotated_males_decontx.qs')
  261. #------------------------------------subclustering GABA------------------------------
  262. setwd("D:/Leon/snRNAseq/heilig_data_transfer/R/high_depth")
  263. library(Seurat)
  264. adata = readRDS("high_annotated_males_decontx.qs")
  265. gc()
  266. adata = subset(adata, subset = cell_type == "Gabaergic")
  267. gc()
  268. DefaultAssay(adata) = "decontXcounts"
  269. VlnPlot(adata, c('percent.mt',
  270. 'percent.ribo',
  271. 'nCount_decontXcounts',
  272. 'nFeature_decontXcounts'),
  273. group.by = 'SampleID',
  274. pt.size = 0,
  275. ncol = 2)
  276. adata = subset(adata, subset = nFeature_decontXcounts > 1500
  277. & nCount_decontXcounts < 20000
  278. & nCount_decontXcounts > 500
  279. & percent.ribo < 1
  280. & percent.mt < 3
  281. )
  282. VlnPlot(adata, c('percent.mt',
  283. 'percent.ribo',
  284. 'nCount_decontXcounts',
  285. 'nFeature_decontXcounts'),
  286. group.by = 'SampleID',
  287. pt.size = 0,
  288. ncol = 2)
  289. p1 = FeatureScatter(adata, 'nCount_decontXcounts', 'percent.mt')
  290. p2 = FeatureScatter(adata, 'nCount_decontXcounts', 'nFeature_decontXcounts')
  291. p3 = FeatureScatter(adata, 'nCount_decontXcounts', 'percent.ribo')
  292. p1+p2+p3
  293. gc()
  294. adata[["decontXcounts"]] <- split(adata[["decontXcounts"]], f = adata$SampleID) #split the counts into sample-layers
  295. DefaultAssay(adata) = 'decontXcounts'
  296. adata
  297. gc()
  298. adata <- SCTransform(adata, vars.to.regress = c("percent.mt", "percent.ribo"),
  299. assay = 'decontXcounts')
  300. gc()
  301. adata = RunPCA(adata)
  302. gc()
  303. ElbowPlot(adata,ndims = 50)
  304. adata <- FindNeighbors(adata, dims = 1:50, reduction = "pca")
  305. gc()
  306. adata <- FindClusters(adata, resolution = 0.1, cluster.name = "gaba_subclusters_0.1")
  307. gc()
  308. adata <- FindClusters(adata, resolution = 0.3, cluster.name = "gaba_subclusters_0.3")
  309. gc()
  310. adata <- FindClusters(adata, resolution = 0.5, cluster.name = "gaba_subclusters_0.5")
  311. gc()
  312. adata <- FindClusters(adata, resolution = 0.6, cluster.name = "gaba_subclusters_0.6")
  313. gc()
  314. adata <- FindClusters(adata, resolution = 0.7, cluster.name = "gaba_subclusters_0.7")
  315. gc()
  316. adata <- FindClusters(adata, resolution = 0.8, cluster.name = "gaba_subclusters_0.8")
  317. gc()
  318. adata = RunUMAP(adata, dims = 1:50, metric = 'euclidean', reduction.name = 'euclidean_umap_gaba')
  319. DimPlot(adata, reduction = "euclidean_umap_gaba", group.by = "gaba_subclusters_0.5", label = TRUE)
  320. adata
  321. gc()
  322. for (sample in 1:length(unique(adata$SampleID))) {
  323. print(sample)
  324. slot(adata@assays$[email hidden][[sample]], name="umi.assay") = "decontXcounts"
  325. }
  326. gc()
  327. adata = PrepSCTFindMarkers(adata)
  328. gc()
  329. Idents(adata) = adata$gaba_subclusters_0.5
  330. markers = FindAllMarkers(adata, only.pos = TRUE)
  331. write.csv(markers, 'gaba_males_subclustered_markers.csv')
  332. gc()
  333. DimPlot(adata, reduction = "euclidean_umap_gaba", group.by = "gaba_subclusters_0.5", label = TRUE)
  334. current.cluster_ids = c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
  335. 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  336. 32, 33, 34, 35, 36, 37, 38, 39)
  337. VlnPlot(adata, 'Sst', pt.size = 0, assay = 'decontXcounts', layer = 'data') + NoLegend()
  338. FeaturePlot(adata, c('Gad2', 'Slc17a6'), reduction = 'euclidean_umap_gaba', blend = T,
  339. max.cutoff = 1, pt.size = 2)
  340. FeaturePlot(adata, 'Sst', reduction = 'euclidean_umap_gaba')
  341. new.cluster_ids = c(
  342. 'CeL_Prkcd',#0
  343. 'CeM_Xylt1',#1
  344. 'Intercalated_Chst9',#2
  345. 'Drd2_Htr2c',#3
  346. 'Ebf1_1',#4
  347. 'Drd2_Calcrl',#5
  348. 'Satb1_Col5a2',#6
  349. 'Dlk1',#7
  350. 'Pallidum',#8
  351. 'Ndst3_Dach2',#9
  352. 'Nxph1_Tcf4',#10
  353. 'Npffr1_Dock11',#11
  354. 'Ebf1_2',#12
  355. 'Nos1_Plagl1_Sst',#13
  356. 'Egfr_Nxph1',#14
  357. 'Intercalated_Nos1',#15
  358. 'Prlr_tac3',#16
  359. 'Vipr2_Pdyn',#17
  360. 'Slc17a6',#18
  361. 'Nxph1_Nxph2',#19
  362. 'Ebf1_2',#20
  363. 'Intercalated_Glp1r',#21
  364. 'Tafa1_Slc17a8',#22
  365. 'Prlr_Esr1',#23
  366. 'Stac_Ndst4',#24
  367. 'Intercalated_Chrm2',#25
  368. 'Ebf1_3',#26
  369. 'Slc17a6',#27
  370. 'Drd2_Rai14',#28
  371. 'Mast4',#29
  372. 'Intercalated_Dach1',#30
  373. 'Lgr6',#31
  374. 'Vip',#32
  375. 'Zbtb7c',#33
  376. 'Sox6_Gpc5',#34
  377. 'Sox6_Ano4',#35
  378. 'Fign_Npsr1',#36
  379. 'Grm3',#37
  380. 'Mast4_Zfp536', #38
  381. 'Tf_Car2'#39
  382. )
  383. library(plyr)
  384. adata$cell_subtype = plyr::mapvalues(x = adata$gaba_subclusters_0.5, from = current.cluster_ids, to = new.cluster_ids)
  385. dir.create('males/subclustering')
  386. dir.create('males/subclustering/gabaergic/')
  387. p = DimPlot(adata, reduction = "euclidean_umap_gaba", group.by = "cell_subtype", label = TRUE,
  388. repel = T, raster = F, label.size = 6) + NoLegend()
  389. pdf('males/subclustering/gabaergic/umap_cellsubtypes.pdf',
  390. height = 15, width = 15)
  391. print(p)
  392. dev.off()
  393. qsave(adata, 'gabaergic_males_subclustered.qs')
  394. adata = qread('gabaergic_males_subclustered.qs')
  395. markers = FindAllMarkers(adata, only.pos = T)
  396. markers$cell_type = markers$cluster
  397. gc()
  398. DefaultAssay(adata) = 'SCT'
  399. #adata = NormalizeData(adata)
  400. #adata = ScaleData(adata)
  401. library(dplyr)
  402. markers %>%
  403. group_by(cell_type) %>%
  404. filter(avg_log2FC > 1) %>%
  405. slice_head(n = 20) %>%
  406. ungroup -> top10
  407. gc()
  408. Idents(adata) = 'cell_subtype'
  409. p = DoHeatmap(subset(adata, downsample = 500), features = top10$gene) + NoLegend()
  410. pdf('males/subclustering/gabaergic/heatmap_cellsubtypes.pdf',
  411. height = 10, width = 20)
  412. print(p)
  413. dev.off()
  414. DefaultAssay(adata) = 'decontXcounts'
  415. adata = NormalizeData(adata)
  416. adata = ScaleData(adata)
  417. gc()
  418. features = c('Prkcd', 'Nr2f2', 'Isl1', 'Crh',
  419. 'Calcrl', 'Sst','Oxtr', 'Nts', 'Tac3',
  420. 'Tacr1', 'Cck', 'Cartpt', 'Cxcl14',
  421. 'Htr2a', 'Htr2c', 'Drd1', 'Drd2',
  422. 'Drd3', 'Cnr1',
  423. 'Oprm1', 'Oprk1', 'Oprd1',
  424. 'Gria1', 'Gria2', 'Gria3', 'Gria4',
  425. 'Grik1', 'Grik2', 'Grik3', 'Grik4',
  426. 'Grik5', 'Grin1', 'Grin2a', 'Grin2b',
  427. 'Grin2c', 'Grin2d', 'Grin3a', 'Grin3b',
  428. 'Grm1', 'Grm5', 'Grm2', 'Grm3',
  429. 'Grm4', 'Grm6', 'Grm7', 'Grm8',
  430. 'Adra1a', 'Adra1b', 'Adra1c',
  431. 'Adra2a', 'Adra2b', 'Adra2c',
  432. 'Adrb1', 'Adrb2', 'Adrb3', 'Chrna1',
  433. 'Chrnb1', 'Chrnd', 'Chrne',
  434. 'Chrm1', 'Chrm2', 'Chrm3', 'Chrm4',
  435. 'Adora1','Adora1a', 'Adora2a', 'Adora3',
  436. 'Il13ra1', 'Il13ra2', 'Il1r1', 'Il6r',
  437. 'Tnfrsf1a', 'Tnfrsf1b'
  438. )
  439. celltype_counts = table(adata$cell_subtype)
  440. celltypes_to_keep = names(celltype_counts[celltype_counts >= 500])
  441. p = DoHeatmap(subset(subset(adata, cells = WhichCells(adata, expression = cell_subtype %in% celltypes_to_keep)), downsample = 500), features = features) + NoLegend()
  442. pdf('males/subclustering/gabaergic/heatmap_cellsubtypes_interesting_stuff.pdf',
  443. height = 15, width = 25)
  444. print(p)
  445. dev.off()
  446. FeaturePlot(adata, "Pde1c", reduction = "euclidean_umap_gaba")
  447. RidgePlot(adata, features = "percent.ribo")
  448. RidgePlot(adata, features = "percent.mt")
  449. RidgePlot(adata, features = "nCount_RNA")
  450. RidgePlot(adata, features = "nFeature_RNA")
  451. VlnPlot(adata, features = "percent.mt", group.by = "SampleID", pt.size = 0)
  452. # hdWGCNA
  453. setwd("D:/Leon/snRNAseq/heilig_data_transfer/R/high_depth")
  454. library(Seurat)
  455. library(tidyverse)
  456. library(cowplot)
  457. library(patchwork)
  458. library(WGCNA)
  459. library(hdWGCNA)
  460. library(writexl)
  461. library(readxl)
  462. library(qs)
  463. # using the cowplot theme for ggplot
  464. theme_set(theme_cowplot())
  465. # set random seed for reproducibility
  466. set.seed(12345)
  467. # optionally enable multithreading
  468. allowWGCNAThreads(nThreads = 7)
  469. #gabaergic cells only
  470. adata = qread('gabaergic_males_subclustered.qs')
  471. describe(adata$nCount_decontXcounts)
  472. describe(adata$nFeature_decontXcounts)
  473. adata
  474. describe(adata$cell_subtype)
  475. unique(adata$cell_subtype)
  476. gc()
  477. adata
  478. Idents(adata) = 'cell_subtype'
  479. markers = FindAllMarkers(adata, only.pos = T)
  480. write_xlsx(markers, 'Fgfr1_paper/gabaergic_markers.xlsx')
  481. markers$cell_type = markers$cluster
  482. Idents(adata) = 'cell_type'
  483. DefaultAssay(adata) = 'decontXcounts'
  484. gc()
  485. adata
  486. adata[['decontXcounts']] = JoinLayers(adata[['decontXcounts']])
  487. adata = NormalizeData(adata)
  488. adata = SetupForWGCNA(
  489. adata,
  490. gene_select = "fraction",
  491. fraction = 0.05,
  492. wgcna_name = 'gaba_males_consensus'
  493. )
  494. gc()
  495. adata
  496. adata = MetacellsByGroups(
  497. adata,
  498. group.by = c('cell_type', 'SampleID', 'Groups'),
  499. ident.group = 'cell_type',
  500. k = 25,
  501. max_shared = 12,
  502. min_cells = 50,
  503. reduction = 'pca'
  504. )
  505. gc()
  506. adata = NormalizeMetacells(adata)
  507. gc()
  508. adata = SetMultiExpr(
  509. adata,
  510. group_name = 'Gabaergic',
  511. group.by = 'cell_type',
  512. multi.group.by = "Groups"
  513. )
  514. adata = TestSoftPowersConsensus(adata)
  515. plot_list = PlotSoftPowers(adata)
  516. consensus_groups <- unique(adata$Groups)
  517. p_list <- lapply(1:length(consensus_groups), function(i){
  518. cur_group <- consensus_groups[[i]]
  519. plot_list[[i]][[1]] + ggtitle(paste0('Group: ', cur_group)) + theme(plot.title=element_text(hjust=0.5))
  520. })
  521. dir.create('males/wgcna/consensus')
  522. dir.create('males/wgcna/consensus/gabaergic')
  523. dir.create('males/wgcna/consensus/gabaergic/plots/')
  524. pdf('males/wgcna/consensus/gabaergic/plots/soft_powers.pdf')
  525. wrap_plots(p_list, ncol=2)
  526. dev.off()
  527. gc()
  528. adata = ConstructNetwork(
  529. adata,
  530. soft_power = c(9,8,8),
  531. consensus = TRUE,
  532. tom_name = 'gaba_male_consensus'
  533. )
  534. pdf('males/wgcna/consensus/gabaergic/plots/dendrogram.pdf')
  535. PlotDendrogram(adata, main = 'Groups consensus dendrogram')
  536. dev.off()
  537. adata = ScaleData(adata)
  538. gc()
  539. adata = ModuleEigengenes(
  540. adata,
  541. group.by.vars = "SampleID"
  542. )
  543. hMEs = GetMEs(adata)
  544. MEs = GetMEs(adata, harmonized=FALSE)
  545. adata = ModuleConnectivity(
  546. adata,
  547. group.by = 'cell_type', group_name = 'Gabaergic'
  548. )
  549. adata = ResetModuleNames(
  550. adata,
  551. new_name = "Gaba-M"
  552. )
  553. gc()
  554. p = PlotKMEs(adata, ncol = 6)
  555. pdf('males/wgcna/consensus/gabaergic/plots/kMEs.pdf',
  556. width = 10, height = 10)
  557. p
  558. dev.off()
  559. modules = GetModules(adata) %>% subset(module != 'grey')
  560. head(modules[,1:6])
  561. write_xlsx(modules, 'males/wgcna/consensus/gabaergic/consensus_modules.xlsx')
  562. qsave(adata, 'males/wgcna/consensus/gabaergic/wgcna_consensus_gaba_males.qs')
  563. ############################ network visualization
  564. setwd("D:/Leon/snRNAseq/heilig_data_transfer/R/high_depth")
  565. library(Seurat)
  566. library(tidyverse)
  567. library(cowplot)
  568. library(patchwork)
  569. library(WGCNA)
  570. library(hdWGCNA)
  571. library(igraph)
  572. library(qs)
  573. theme_set(theme_cowplot())
  574. set.seed(12345)
  575. gc()
  576. adata = qread('males/wgcna/consensus/gabaergic/wgcna_consensus_gaba_males.qs')
  577. hMEs <- GetMEs(adata)
  578. modules = GetModules(adata)
  579. mods = levels(modules$module); mods = mods[mods != 'grey']
  580. [email hidden] = cbind([email hidden], hMEs)
  581. ################### Make files fo rGEO ##################################
  582. metadata = [email hidden]
  583. write.csv(metadata, 'males/wgcna/consensus/gabaergic/metadata.csv')
  584. dir.create('Fgfr1_paper/for_geo')
  585. gc()
  586. library(Matrix)
  587. raw_counts = adata@assays$RNA@layers$counts
  588. write.table(colnames(raw_counts), "Fgfr1_paper/for_geo/barcodes.tsv")
  589. write.table(rownames(raw_counts), "Fgfr1_paper/for_geo/genes.tsv")
  590. gc()
  591. writeMM(raw_counts, file = 'Fgfr1_paper/for_geo/raw_counts.mtx')
  592. rm(raw_counts)
  593. gc()
  594. decont_counts = adata@assays$decontXcounts@layers$counts
  595. writeMM(decont_counts, file = 'Fgfr1_paper/for_geo/decontXcounts_counts.mtx')
  596. rm(decont_counts)
  597. gc()
  598. decont_SCT_data = adata@assays$SCT@data
  599. write.table(rownames(decont_SCT_data), "Fgfr1_paper/for_geo/genes_SCT.tsv")
  600. writeMM(decont_SCT_data, file = 'Fgfr1_paper/for_geo/decontXcounts_SCT_data.mtx')
  601. p = DotPlot(adata, features = mods ,group.by = 'cell_subtype')
  602. p = p +
  603. RotatedAxis() +
  604. scale_color_gradient2(high = 'red', mid = 'grey95', low = 'blue') +
  605. coord_flip() +
  606. theme(
  607. axis.text.x = element_text(size = 16, face = "bold"), # x-axis labels
  608. axis.text.y = element_text(size = 16, face = "bold"), # y-axis labels
  609. axis.title.x = element_text(size = 2, face = "bold"), # x-axis title
  610. axis.title.y = element_text(size = 2, face = "bold") # y-axis title
  611. )
  612. p
  613. pdf('males/wgcna/consensus/gabaergic/plots/modules_dotplot.pdf',
  614. height = 10, width = 20)
  615. print(p)
  616. dev.off()
  617. PlotKMEs_1 <- function(
  618. seurat_obj,
  619. n_hubs=10,
  620. text_size=2,
  621. ncol = 5,
  622. plot_widths = c(3,2),
  623. wgcna_name = NULL
  624. ){
  625. if(is.null(wgcna_name)){wgcna_name <- seurat_obj@misc$active_wgcna}
  626. modules <- GetModules(seurat_obj, wgcna_name) %>% subset(module != 'grey')
  627. mods <- levels(modules$module); mods <- mods[mods != 'grey']
  628. mod_colors <- modules %>% subset(module %in% mods) %>%
  629. dplyr::select(c(module, color)) %>%
  630. dplyr::distinct()
  631. # get hub genes:
  632. hub_df <- GetHubGenes(seurat_obj, n_hubs=n_hubs, wgcna_name=wgcna_name)
  633. plot_list <- lapply(mods, function(x){
  634. cur_color <- subset(mod_colors, module == x) %>% .$color
  635. cur_df <- subset(hub_df, module == x)
  636. top_genes <- cur_df %>% dplyr::top_n(n_hubs, wt=kME) %>% .$gene_name
  637. p <- cur_df %>% ggplot(aes(x = reorder(gene_name, kME), y = kME)) +
  638. geom_bar(stat='identity', width=1, color = cur_color, fill=cur_color) +
  639. ggtitle(x) +
  640. ylim(0, 1) +
  641. #xlab(paste0('kME_', x)) +
  642. theme(
  643. axis.ticks.x = element_blank(),
  644. axis.text.x = element_blank(),
  645. plot.title = element_text(hjust=0.5, size = 36, face = 'bold'),
  646. axis.title.x = element_blank(),
  647. axis.line.x = element_blank()
  648. )
  649. p_anno <- ggplot() + annotate(
  650. "label",
  651. x = 0,
  652. y = 0,
  653. label = paste0(top_genes, collapse="\n"),
  654. size=text_size,
  655. fontface = 'bold',
  656. label.size=0
  657. ) + theme_void()
  658. patch <- p + p_anno + plot_layout(widths=plot_widths)
  659. patch
  660. })
  661. wrap_plots(plot_list, ncol=ncol)
  662. }
  663. p = PlotKMEs_1(adata, ncol = 3, text_size = 4)
  664. p
  665. pdf('males/wgcna/consensus/gabaergic/plots/kMEs.pdf',
  666. width = 20, height = 15)
  667. p
  668. dev.off()
  669. plot_list = ModuleFeaturePlot(
  670. adata,
  671. features = 'hMEs',
  672. order=TRUE,
  673. reduction = 'euclidean_umap_gaba'
  674. )
  675. pdf('males/wgcna/consensus/gabaergic/plots/modules_umap.pdf',
  676. height = 10, width = 10)
  677. wrap_plots(plot_list, ncol = 6)
  678. dev.off()
  679. p = ModuleRadarPlot(
  680. adata,
  681. group.by = 'cell_subtype', axis.label.size = 3, grid.label.size = 3
  682. )
  683. pdf('males/wgcna/consensus/gabaergic/plots/radar_plot_cell_subtype.pdf',
  684. height = 10, width = 15)
  685. p
  686. dev.off()
  687. ModuleNetworkPlot(
  688. adata,
  689. outdir = 'males/wgcna/consensus/gabaergic/plots/mandala_plots'
  690. )
  691. library(readxl)
  692. ################## DME analysis ##################
  693. # celltypes
  694. dir.create('males/wgcna/consensus/gabaergic/DMEs')
  695. #res vs sen
  696. DMEs <- data.frame()
  697. for (cell_type in unique(adata$cell_subtype)) {
  698. print(cell_type)
  699. # group1 = [email hidden] %>% subset(cell_subtype == cell_type & Groups == 'Resistant') %>% rownames
  700. # group2 = [email hidden] %>% subset(cell_subtype == cell_type & Groups == 'Sensitive') %>% rownames
  701. group1 <- rownames(
  702. [email hidden][
  703. as.character([email hidden]$cell_subtype) == cell_type &
  704. [email hidden]$Groups == "Resistant", ]
  705. )
  706. group2 <- rownames(
  707. [email hidden][
  708. as.character([email hidden]$cell_subtype) == cell_type &
  709. [email hidden]$Groups == "Sensitive", ]
  710. )
  711. dir.create('males/wgcna/consensus/gabaergic/DMEs/res_vs_sen')
  712. dir.create(paste0('males/wgcna/consensus/gabaergic/DMEs/res_vs_sen/',cell_type))
  713. cur_DMEs <- FindDMEs(
  714. adata,
  715. barcodes1 = group1,
  716. barcodes2 = group2,
  717. test.use='wilcox',
  718. wgcna_name='gaba_males_consensus'
  719. )
  720. cur_DMEs$celltype = cell_type
  721. DMEs = rbind(DMEs, cur_DMEs)
  722. p = PlotDMEsLollipop(
  723. adata,
  724. cur_DMEs,
  725. wgcna_name='gaba_males_consensus',
  726. pvalue = "p_val_adj"
  727. )
  728. pdf(paste0('males/wgcna/consensus/gabaergic/DMEs/res_vs_sen/',cell_type,'/lollipop.pdf'))
  729. print(p)
  730. dev.off()
  731. }
  732. modules <- GetModules(adata)
  733. mods <- levels(modules$module); mods <- mods[mods != 'grey']
  734. plot_df <- DMEs
  735. plot_df$module <- factor(as.character(plot_df$module), levels=mods)
  736. maxval <- 0.5; minval <- -0.5
  737. plot_df$avg_log2FC <- ifelse(plot_df$avg_log2FC > maxval, maxval, plot_df$avg_log2FC)
  738. plot_df$avg_log2FC <- ifelse(plot_df$avg_log2FC < minval, minval, plot_df$avg_log2FC)
  739. plot_df$Significance <- gtools::stars.pval(plot_df$p_val_adj)
  740. plot_df$textcolor <- ifelse(plot_df$avg_log2FC > 0.2, 'black', 'white')
  741. p <- plot_df %>%
  742. ggplot(aes(y=celltype, x=module, fill=avg_log2FC)) +
  743. geom_tile()
  744. p <- p +
  745. geom_text(label=plot_df$Significance, color=plot_df$textcolor)
  746. p <- p +
  747. scale_fill_gradient2(low='purple', mid='black', high='yellow') +
  748. RotatedAxis() +
  749. theme(
  750. panel.border = element_rect(fill=NA, color='black', size=1),
  751. axis.line.x = element_blank(),
  752. axis.line.y = element_blank(),
  753. plot.margin=margin(0,0,0,0)
  754. ) + xlab('') + ylab('') +
  755. coord_equal() +
  756. ggtitle("Resistant vs Sensitive")
  757. pdf('males/wgcna/consensus/gabaergic/DMEs/res_vs_sen/dmes_heatmap_celltype.pdf',
  758. height = 10, width = 10)
  759. p
  760. dev.off()
  761. library(writexl)
  762. write_xlsx(DMEs, 'males/wgcna/consensus/gabaergic/DMEs/res_vs_sen/dmes_celltype.xlsx')
  763. #res vs yok
  764. DMEs <- data.frame()
  765. for (cell_type in unique(adata$cell_subtype)) {
  766. print(cell_type)
  767. # group1 = [email hidden] %>% subset(cell_subtype == cell_type & Groups == 'Resistant') %>% rownames
  768. # group2 = [email hidden] %>% subset(cell_subtype == cell_type & Groups == 'Sensitive') %>% rownames
  769. group1 <- rownames(
  770. [email hidden][
  771. as.character([email hidden]$cell_subtype) == cell_type &
  772. [email hidden]$Groups == "Resistant", ]
  773. )
  774. group2 <- rownames(
  775. [email hidden][
  776. as.character([email hidden]$cell_subtype) == cell_type &
  777. [email hidden]$Groups == "Yoked", ]
  778. )
  779. dir.create('males/wgcna/consensus/gabaergic/DMEs/res_vs_yok')
  780. dir.create(paste0('males/wgcna/consensus/gabaergic/DMEs/res_vs_yok/',cell_type))
  781. cur_DMEs <- FindDMEs(
  782. adata,
  783. barcodes1 = group1,
  784. barcodes2 = group2,
  785. test.use='wilcox',
  786. wgcna_name='gaba_males_consensus'
  787. )
  788. cur_DMEs$celltype = cell_type
  789. DMEs = rbind(DMEs, cur_DMEs)
  790. p = PlotDMEsLollipop(
  791. adata,
  792. cur_DMEs,
  793. wgcna_name='gaba_males_consensus',
  794. pvalue = "p_val_adj"
  795. )
  796. pdf(paste0('males/wgcna/consensus/gabaergic/DMEs/res_vs_yok/',cell_type,'/lollipop.pdf'))
  797. print(p)
  798. dev.off()
  799. }
  800. modules <- GetModules(adata)
  801. mods <- levels(modules$module); mods <- mods[mods != 'grey']
  802. plot_df <- DMEs
  803. plot_df$module <- factor(as.character(plot_df$module), levels=mods)
  804. maxval <- 0.5; minval <- -0.5
  805. plot_df$avg_log2FC <- ifelse(plot_df$avg_log2FC > maxval, maxval, plot_df$avg_log2FC)
  806. plot_df$avg_log2FC <- ifelse(plot_df$avg_log2FC < minval, minval, plot_df$avg_log2FC)
  807. plot_df$Significance <- gtools::stars.pval(plot_df$p_val_adj)
  808. plot_df$textcolor <- ifelse(plot_df$avg_log2FC > 0.2, 'black', 'white')
  809. p <- plot_df %>%
  810. ggplot(aes(y=celltype, x=module, fill=avg_log2FC)) +
  811. geom_tile()
  812. p <- p +
  813. geom_text(label=plot_df$Significance, color=plot_df$textcolor)
  814. p <- p +
  815. scale_fill_gradient2(low='purple', mid='black', high='yellow') +
  816. RotatedAxis() +
  817. theme(
  818. panel.border = element_rect(fill=NA, color='black', size=1),
  819. axis.line.x = element_blank(),
  820. axis.line.y = element_blank(),
  821. plot.margin=margin(0,0,0,0)
  822. ) + xlab('') + ylab('') +
  823. coord_equal() +
  824. ggtitle("Resistant vs Yoked")
  825. pdf('males/wgcna/consensus/gabaergic/DMEs/res_vs_yok/dmes_heatmap_celltype.pdf',
  826. height = 10, width = 10)
  827. p
  828. dev.off()
  829. library(writexl)
  830. write_xlsx(DMEs, 'males/wgcna/consensus/gabaergic/DMEs/res_vs_yok/dmes_celltype.xlsx')
  831. #Enrichment
  832. setwd("D:/Leon/snRNAseq/heilig_data_transfer/R/high_depth")
  833. library(Seurat)
  834. library(tidyverse)
  835. library(cowplot)
  836. library(patchwork)
  837. library(WGCNA)
  838. library(hdWGCNA)
  839. library(igraph)
  840. library(qs)
  841. theme_set(theme_cowplot())
  842. set.seed(12345)
  843. gc()
  844. adata = qread('males/wgcna/consensus/gabaergic/wgcna_consensus_gaba_males.qs')
  845. library(enrichR)
  846. library(GeneOverlap)
  847. dbs = c('GO_Biological_Process_2025',
  848. 'GO_Cellular_Component_2025',
  849. 'GO_Molecular_Function_2025')
  850. adata = RunEnrichr(
  851. adata,
  852. dbs=dbs,
  853. max_genes = 100
  854. )
  855. enrich_df = GetEnrichrTable(adata)
  856. dir.create('males/wgcna/consensus/gabaergic/enrichment')
  857. write_xlsx(enrich_df, 'males/wgcna/consensus/gabaergic/enrichment/modules_enrichment.xlsx')
  858. EnrichrBarPlot_1 <- function(
  859. seurat_obj,
  860. outdir = "enrichr_plots",
  861. n_terms = 25,
  862. p_cutoff = 0.05,
  863. p_adj = TRUE,
  864. plot_size = c(6,15),
  865. logscale=FALSE,
  866. plot_bar_color=NULL,
  867. plot_text_color=NULL,
  868. wgcna_name=NULL
  869. ){
  870. # get data from active assay if wgcna_name is not given
  871. if(is.null(wgcna_name)){wgcna_name <- seurat_obj@misc$active_wgcna}
  872. # get modules:
  873. modules <- GetModules(seurat_obj, wgcna_name)
  874. mods <- levels(modules$module)
  875. mods <- mods[mods != 'grey']
  876. # get Enrichr table
  877. enrichr_df <- GetEnrichrTable(seurat_obj, wgcna_name)
  878. dbs <- as.character(unique(enrichr_df$db))
  879. # subset based on significance level:
  880. if(p_adj){
  881. enrichr_df <- subset(enrichr_df, Adjusted.P.value <= p_cutoff)
  882. } else{
  883. enrichr_df <- subset(enrichr_df, P.value <= p_cutoff)
  884. }
  885. # helper function to wrap text
  886. wrapText <- function(x, len) {
  887. sapply(x, function(y) paste(strwrap(y, len), collapse = "\n"), USE.NAMES = FALSE)
  888. }
  889. # make output dir if it doesn't exist:
  890. if(!dir.exists(outdir)){dir.create(outdir)}
  891. # loop through modules:
  892. for(i in 1:length(mods)){
  893. cur_mod <- mods[i]
  894. cur_terms <- subset(enrichr_df, module == cur_mod)
  895. print(cur_mod)
  896. # get color for this module:
  897. cur_color <- modules %>% subset(module == cur_mod) %>% .$color %>% unique %>% as.character
  898. if(!is.null(plot_bar_color)){
  899. cur_color <- plot_bar_color
  900. }
  901. cur_color <- grDevices::adjustcolor(cur_color, alpha.f = 0.6)
  902. # skip if there are not any terms for this module:
  903. if(nrow(cur_terms) == 0){next}
  904. cur_terms$wrap <- wrapText(cur_terms$Term, 45)
  905. # plot top n_terms as barplot
  906. plot_list <- list()
  907. for(cur_db in dbs){
  908. plot_df <- subset(cur_terms, db==cur_db) %>%
  909. slice_max(order_by=Combined.Score, n=n_terms)
  910. # text color:
  911. if(is.null(plot_text_color)){
  912. if(cur_color == 'black'){
  913. text_color = 'grey'
  914. } else {
  915. text_color = 'black'
  916. }
  917. } else{
  918. text_color <- plot_text_color
  919. }
  920. # logscale?
  921. if(logscale){
  922. plot_df$Combined.Score <- log(plot_df$Combined.Score)
  923. lab <- 'Enrichment log(combined score)'
  924. x <- 0.2
  925. } else{lab <- 'Enrichment (combined score)'; x <- 5}
  926. # make bar plot:
  927. plot_list[[cur_db]] <- ggplot(plot_df, aes(x=Combined.Score, y=reorder(wrap, Combined.Score)))+
  928. geom_bar(stat='identity', position='identity', color='white', fill=cur_color) +
  929. geom_text(aes(label=wrap), x=x, color=text_color, size=8, hjust='left') +
  930. scale_x_continuous(expand = c(0, 0), limits = c(0, NA)) +
  931. xlab(lab) + ylab('') + ggtitle(cur_db) +
  932. theme(
  933. panel.grid.major=element_blank(),
  934. panel.grid.minor=element_blank(),
  935. legend.title = element_blank(),
  936. axis.ticks.y=element_blank(),
  937. axis.text.y=element_blank(),
  938. plot.title = element_text(hjust = 0.5),
  939. axis.line.y=element_blank()
  940. )
  941. }
  942. # make pdfs in output dir
  943. pdf(paste0(outdir, '/', cur_mod, '.pdf'), width=plot_size[1], height=plot_size[2])
  944. for(plot in plot_list){
  945. print(plot)
  946. }
  947. dev.off()
  948. }
  949. }
  950. EnrichrBarPlot_1(
  951. adata,
  952. outdir = 'males/wgcna/consensus/gabaergic/enrichment',
  953. n_terms = 5,
  954. plot_size = c(10,10),
  955. logscale = TRUE, p_cutoff = 0.1
  956. )
  957. p = EnrichrDotPlot(
  958. adata,
  959. mods = "all", # use all modules (default)
  960. database = "GO_Biological_Process_2025", # this must match one of the dbs used previously
  961. n_terms=2, # number of terms per module
  962. term_size=10, # font size for the terms
  963. p_adj = FALSE # show the p-val or adjusted p-val?
  964. ) + scale_color_stepsn(colors=rev(viridis::magma(256)))
  965. pdf('males/wgcna/consensus/gabaergic/enrichment/enrichment_dotplot_bio_process.pdf',
  966. height = 15, width = 15)
  967. print(p)
  968. dev.off()
  969. p = EnrichrDotPlot(
  970. adata,
  971. mods = "all", # use all modules (default)
  972. database = "GO_Cellular_Component_2025", # this must match one of the dbs used previously
  973. n_terms=2, # number of terms per module
  974. term_size=10, # font size for the terms
  975. p_adj = FALSE # show the p-val or adjusted p-val?
  976. ) + scale_color_stepsn(colors=rev(viridis::magma(256)))
  977. pdf('males/wgcna/consensus/gabaergic/enrichment/enrichment_dotplot_cell_process.pdf',
  978. height = 15, width = 15)
  979. print(p)
  980. dev.off()
  981. p = EnrichrDotPlot(
  982. adata,
  983. mods = "all", # use all modules (default)
  984. database = "GO_Molecular_Function_2025", # this must match one of the dbs used previously
  985. n_terms=2, # number of terms per module
  986. term_size=10, # font size for the terms
  987. p_adj = FALSE # show the p-val or adjusted p-val?
  988. ) + scale_color_stepsn(colors=rev(viridis::magma(256)))
  989. pdf('males/wgcna/consensus/gabaergic/enrichment/enrichment_dotplot_mol_function.pdf',
  990. height = 15, width = 15)
  991. print(p)
  992. dev.off()
  993. ################### modules in the same direction ##################
  994. library(readxl)
  995. res_vs_sen = read_excel('males/wgcna/consensus/gabaergic/DMEs/res_vs_sen/dmes_celltype.xlsx')
  996. res_vs_yok = read_excel('males/wgcna/consensus/gabaergic/DMEs/res_vs_yok/dmes_celltype.xlsx')
  997. res_vs_sen$comparison = 'res_vs_sen'
  998. res_vs_yok$comparison = 'res_vs_yok'
  999. df1_sig = subset(res_vs_sen, p_val_adj < 0.05)
  1000. df2_sig = subset(res_vs_yok, p_val_adj < 0.05)
  1001. library(dplyr)
  1002. combined_data = merge(df1_sig, df2_sig, c('celltype', 'module'))
  1003. combined_data$avg_log2FC.x <- as.numeric(combined_data$avg_log2FC.x)
  1004. combined_data$avg_log2FC.y <- as.numeric(combined_data$avg_log2FC.y)
  1005. df_filtered <- combined_data %>%
  1006. filter(
  1007. (avg_log2FC.x > 0 & avg_log2FC.y > 0 | avg_log2FC.x < 0 & avg_log2FC.y < 0) &
  1008. abs(avg_log2FC.x) > 0.2 &
  1009. abs(avg_log2FC.y) > 0.2 &
  1010. pct.1.x > 0.5 &
  1011. pct.1.y > 0.5 &
  1012. pct.2.x > 0.5 &
  1013. pct.2.y > 0.5
  1014. )
  1015. write_xlsx(df_filtered, 'Fgfr1_paper/DMEs_for_paper.xlsx')
  1016. long_data <- df_filtered %>%
  1017. pivot_longer(
  1018. cols = c(avg_log2FC.x, avg_log2FC.y),
  1019. names_to = "comparison",
  1020. names_pattern = "avg_log2FC\\.(.)",
  1021. values_to = "logFC"
  1022. ) %>%
  1023. mutate(
  1024. comparison_label = ifelse(comparison == "x", "Res vs Sen", "Res vs Yok"),
  1025. module_label = paste0(module, " (", comparison_label, ")")
  1026. )
  1027. write_xlsx(long_data, 'Fgfr1_paper/DMEs_for_paper.xlsx')
  1028. #################### Distinct #####################
  1029. setwd('outputs/distinct/males/')
  1030. library(Seurat)
  1031. library(SingleCellExperiment)
  1032. library(distinct)
  1033. library(qs)
  1034. library(writexl)
  1035. library(readxl)
  1036. adata = qread('../../../objects/gabaergic_males_subclustered.qs')
  1037. DefaultAssay(adata) = 'decontXcounts'
  1038. adata[['decontXcounts']] = JoinLayers(adata[['decontXcounts']])
  1039. adata
  1040. sce = as.SingleCellExperiment(adata)
  1041. rm(adata)
  1042. sce
  1043. gc()
  1044. sce
  1045. cpm_mat = scater::calculateCPM(counts(sce))
  1046. assay(sce, "cpm") = cpm_mat
  1047. sce = scater::logNormCounts(sce)
  1048. sce
  1049. gc()
  1050. colData(sce)
  1051. gc()
  1052. sce$SampleID = as.factor(sce$SampleID)
  1053. sce$Groups = as.factor(sce$Groups)
  1054. sample_md <- unique(as.data.frame(colData(sce)[, c("SampleID", "Groups")]))
  1055. design <- model.matrix(~Groups, data = sample_md)
  1056. rownames(design) <- sample_md$SampleID
  1057. design
  1058. rownames(design)
  1059. set.seed(1234)
  1060. ###################################
  1061. sce_sub <- sce[, sce$Groups %in% c("Resistant", "Sensitive")]
  1062. unique(sce_sub$Groups)
  1063. sce_sub$Groups = droplevels(sce_sub$Groups)
  1064. unique(sce_sub$Groups)
  1065. set.seed(123)
  1066. sample_md <- unique(as.data.frame(colData(sce_sub)[, c("SampleID", "Groups")]))
  1067. design_sub <- model.matrix(~ Groups, data = sample_md)
  1068. rownames(design_sub) <- sample_md$SampleID
  1069. design_sub
  1070. gc()
  1071. sce_sub
  1072. sum(logcounts(sce_sub)["Sik2", ] > 0)
  1073. res_sen <- distinct_test(
  1074. x = sce_sub,
  1075. name_assays_expression = "cpm",
  1076. name_cluster = "cell_subtype",
  1077. name_sample = "SampleID",
  1078. design = design_sub,
  1079. column_to_test = 2,
  1080. min_non_zero_cells = 2000,
  1081. n_cores = 10,
  1082. P_4 = 20000
  1083. )
  1084. res_sen = log2_FC(res = res_sen,
  1085. x = sce_sub,
  1086. name_assays_expression = 'cpm',
  1087. name_group = "Groups",
  1088. name_cluster = "cell_subtype")
  1089. top = top_results(res_sen,
  1090. significance = 0.05, global = T)
  1091. plot_densities(x = sce_sub,
  1092. gene = 'Cdk10',
  1093. cluster = 'Drd2_Calcrl',
  1094. name_assays_expression = 'cpm',
  1095. name_cluster = 'cell_subtype',
  1096. name_sample = 'SampleID',
  1097. name_group = 'Groups', group_level = F)
  1098. plot_densities(x = sce_sub,
  1099. gene = 'Cdk10',
  1100. cluster = 'Drd2_Calcrl',
  1101. name_assays_expression = 'cpm',
  1102. name_cluster = 'cell_subtype',
  1103. name_sample = 'SampleID',
  1104. name_group = 'Groups', group_level = T)
  1105. write_xlsx(x = top, 'res_sen.xlsx')
  1106. #########################################
  1107. sce_sub <- sce[, sce$Groups %in% c("Resistant", "Yoked")]
  1108. unique(sce_sub$Groups)
  1109. sce_sub$Groups = droplevels(sce_sub$Groups)
  1110. unique(sce_sub$Groups)
  1111. set.seed(123)
  1112. sample_md <- unique(as.data.frame(colData(sce_sub)[, c("SampleID", "Groups")]))
  1113. design_sub <- model.matrix(~ Groups, data = sample_md)
  1114. rownames(design_sub) <- sample_md$SampleID
  1115. design_sub
  1116. gc()
  1117. sce_sub
  1118. sum(logcounts(sce_sub)["Slc17a7", ] > 0)
  1119. res_yok <- distinct_test(
  1120. x = sce_sub,
  1121. name_assays_expression = "cpm",
  1122. name_cluster = "cell_subtype",
  1123. name_sample = "SampleID",
  1124. design = design_sub,
  1125. column_to_test = 2,
  1126. min_non_zero_cells = 2000,
  1127. n_cores = 10,
  1128. P_4 = 20000
  1129. )
  1130. res_yok = log2_FC(res = res_yok,
  1131. x = sce_sub,
  1132. name_assays_expression = 'cpm',
  1133. name_group = "Groups",
  1134. name_cluster = "cell_subtype")
  1135. top = top_results(res_yok,
  1136. significance = 0.05, global = T)
  1137. plot_densities(x = sce_sub,
  1138. gene = 'Cdk10',
  1139. cluster = 'Drd2_Calcrl',
  1140. name_assays_expression = 'cpm',
  1141. name_cluster = 'cell_subtype',
  1142. name_sample = 'SampleID',
  1143. name_group = 'Groups', group_level = F)
  1144. plot_densities(x = sce_sub,
  1145. gene = 'Cdk10',
  1146. cluster = 'Drd2_Calcrl',
  1147. name_assays_expression = 'cpm',
  1148. name_cluster = 'cell_subtype',
  1149. name_sample = 'SampleID',
  1150. name_group = 'Groups', group_level = T)
  1151. write_xlsx(x = top, 'res_yok.xlsx')
  1152. gc()
  1153. ######################### Analysis of results #################################
  1154. res_sen = read_excel('res_sen.xlsx')
  1155. res_yok = read_excel('res_yok.xlsx')
  1156. head(res_sen)
  1157. head(res_yok)
  1158. library(dplyr)
  1159. overlap <- inner_join(
  1160. res_sen %>% select(gene, cluster_id, everything()),
  1161. res_yok %>% select(gene, cluster_id, everything()),
  1162. by = c("gene", "cluster_id"),
  1163. suffix = c("_sen", "_yok")
  1164. )
  1165. overlap_same_direction <- overlap %>%
  1166. filter(
  1167. (`log2FC_Resistant/Sensitive` > 0 & `log2FC_Resistant/Yoked` > 0) |
  1168. (`log2FC_Resistant/Sensitive` < 0 & `log2FC_Resistant/Yoked` < 0)
  1169. )
  1170. overlap_same_direction$average_log2FC = (overlap_same_direction$`log2FC_Resistant/Sensitive`+overlap_same_direction$`log2FC_Resistant/Yoked`)/2
  1171. overlap_same_direction$average_p_adj = (overlap_same_direction$p_adj.glb_sen + overlap_same_direction$p_adj.glb_yok)/2
  1172. write_xlsx(overlap_same_direction, 'DEG_list_males_gabaergic.xlsx')
  1173. for_ipa = overlap_same_direction %>% select(gene, average_log2FC, average_p_adj, cluster_id)
  1174. dir.create('for_ipa')
  1175. celltypes <- unique(df$cluster_id)
  1176. for (ct in celltypes) {
  1177. sub <- for_ipa %>% filter(cluster_id == ct)
  1178. write.csv(sub, paste0("for_ipa/IPA_", ct, ".csv"), row.names = FALSE)
  1179. }
  1180. ################################# Volcanoplots ############################3
  1181. overlap_same_direction = read_xlsx('DEG_list_males_gabaergic.xlsx')
  1182. library(dplyr)
  1183. library(ggpubr)
  1184. library(viridis)
  1185. library(dplyr)
  1186. library(ggplot2)
  1187. library(patchwork)
  1188. library(ggrepel)
  1189. df = overlap_same_direction
  1190. df <- df %>%
  1191. mutate(
  1192. reg_sen = case_when(
  1193. p_adj.glb_sen < 0.05 & `log2FC_Resistant/Sensitive` > 0.1 ~ "Up",
  1194. p_adj.glb_sen < 0.05 & `log2FC_Resistant/Sensitive` < -0.1 ~ "Down",
  1195. TRUE ~ "NS"
  1196. ),
  1197. reg_yok = case_when(
  1198. p_adj.glb_yok < 0.05 & `log2FC_Resistant/Yoked` > 0.1 ~ "Up",
  1199. p_adj.glb_yok < 0.05 & `log2FC_Resistant/Yoked` < -0.1 ~ "Down",
  1200. TRUE ~ "NS"
  1201. )
  1202. )
  1203. make_volcano_pair <- function(df, cluster) {
  1204. df_clust <- df %>% filter(cluster_id == cluster)
  1205. p_sen <- ggplot(df_clust, aes(
  1206. x = `log2FC_Resistant/Sensitive`,
  1207. y = -log10(p_adj.glb_sen)
  1208. )) +
  1209. geom_point(aes(color = reg_sen), size = 1.2, alpha = 0.7) +
  1210. geom_vline(xintercept = c(-0.1, 0.1), linetype = "dashed") +
  1211. geom_hline(yintercept = -log10(0.05), linetype = "dashed") +
  1212. geom_text_repel(
  1213. data = df_clust %>% filter(reg_sen != "NS"),
  1214. aes(label = gene),
  1215. size = 3,
  1216. max.overlaps = 20
  1217. ) +
  1218. scale_color_manual(
  1219. values = c(Up = "red", Down = "blue", NS = "grey70")
  1220. ) +
  1221. labs(
  1222. title = "Resistant vs Sensitive",
  1223. x = "log2FC",
  1224. y = "-log10(adj p-value)"
  1225. ) +
  1226. theme_classic() +
  1227. theme(legend.position = "none")
  1228. p_yok <- ggplot(df_clust, aes(
  1229. x = `log2FC_Resistant/Yoked`,
  1230. y = -log10(p_adj.glb_yok)
  1231. )) +
  1232. geom_point(aes(color = reg_yok), size = 1.2, alpha = 0.7) +
  1233. geom_vline(xintercept = c(-0.1, 0.1), linetype = "dashed") +
  1234. geom_hline(yintercept = -log10(0.05), linetype = "dashed") +
  1235. geom_text_repel(
  1236. data = df_clust %>% filter(reg_yok != "NS"),
  1237. aes(label = gene),
  1238. size = 3,
  1239. max.overlaps = 20
  1240. ) +
  1241. scale_color_manual(
  1242. values = c(Up = "red", Down = "blue", NS = "grey70")
  1243. ) +
  1244. labs(
  1245. title = "Resistant vs Yoked",
  1246. x = "log2FC",
  1247. y = "-log10(adj p-value)"
  1248. ) +
  1249. theme_classic() +
  1250. theme(legend.position = "none")
  1251. (p_sen | p_yok) + plot_annotation(title = cluster)
  1252. }
  1253. clusters <- unique(df$cluster_id)
  1254. volcano_plots <- lapply(clusters, function(cl) {
  1255. make_volcano_pair(df, cl)
  1256. })
  1257. volcano_plots[[1]]
  1258. dir.create('volcano_plots')
  1259. clusters <- unique(df$cluster_id)
  1260. for (cl in clusters) {
  1261. p <- make_volcano_pair(df, cl)
  1262. ggsave(
  1263. filename = paste0("volcano_plots/volcano_", cl, ".pdf"),
  1264. plot = p,
  1265. width = 15,
  1266. height = 10,
  1267. units = "in"
  1268. )
  1269. }
  1270. ################################################################################
  1271. df_plot <- overlap_same_direction %>% count(cluster_id)
  1272. p = ggbarplot(
  1273. df_plot,
  1274. x = "cluster_id",
  1275. y = "n",
  1276. fill = "cluster_id",
  1277. palette = viridis(nrow(df_plot)),
  1278. label = TRUE,
  1279. lab.vjust = -0.5,
  1280. sort.val = "desc", # sort bars by height (largest at top)
  1281. sort.by.groups = FALSE,
  1282. x.text.angle = 45,
  1283. legend = "none" # remove legend
  1284. ) +
  1285. labs(
  1286. title = "Number of DEGs per cluster",
  1287. x = "Cluster ID",
  1288. y = "Gene Count"
  1289. )
  1290. p
  1291. pdf('number_of_degs_per_cluster.pdf')
  1292. print(p)
  1293. dev.off()
  1294. m8 = read_excel('modules/M8_consensus.xlsx', col_names = 'gene')
  1295. m5 = read_excel('modules/M5_consensus.xlsx', col_names = 'gene')
  1296. m4 = read_excel('modules/M4_consensus.xlsx', col_names = 'gene')
  1297. m2 = read_excel('modules/M2_consensus.xlsx', col_names = 'gene')
  1298. degs_in_m8 = overlap_same_direction %>%
  1299. filter(gene %in% m8$gene)
  1300. degs_in_m5 = overlap_same_direction %>%
  1301. filter(gene %in% m5$gene)
  1302. degs_in_m4 = overlap_same_direction %>%
  1303. filter(gene %in% m4$gene)
  1304. degs_in_m2 = overlap_same_direction %>%
  1305. filter(gene %in% m2$gene)
  1306. adata = qread('../../../objects/gabaergic_males_subclustered.qs')
  1307. FeaturePlot(adata, reduction = 'euclidean_umap_gaba', 'Tmcc3')
  1308. p = DotPlot(
  1309. adata,
  1310. c('Pdzrn3', 'Sox5', 'Tmcc3', 'Arhgap6', 'Hdac9', 'Ankfn1', 'Dock10',
  1311. 'Palmd', 'Pde7b', 'Maml2', 'Fgfr1', 'Slc35f3', 'Spata13', 'Epb41l4b',
  1312. 'Kalrn', 'Shank2', 'Sec14l1', 'Camk4', 'Rap1gap', 'Mbnl1', 'Ptpro',
  1313. 'Cnih3', 'Glis3', 'Vat1l', 'Dgkg'),
  1314. group.by = 'cell_subtype'
  1315. )
  1316. p = p + theme(axis.text.x = element_text(angle = 45, hjust = 1))
  1317. dir.create('../../males')
  1318. dir.create('../../males/misc_plots')
  1319. pdf('../../males/misc_plots/dotplot_hubgenes_celltypes.pdf',
  1320. width = 20, height = 20)
  1321. print(p)
  1322. dev.off()
  1323. ################################ Main celltypes ##################################################
  1324. setwd("~/Documents/Projects/Compulsivity/snRNAseq_males_and_females/compulsive_snrnaseq_females_males")
  1325. dir.create('outputs/distinct/males/main_celltypes')
  1326. setwd('outputs/distinct/males/main_celltypes')
  1327. library(Seurat)
  1328. library(SingleCellExperiment)
  1329. library(distinct)
  1330. library(qs)
  1331. library(writexl)
  1332. library(readxl)
  1333. library(dplyr)
  1334. adata = readRDS('../../../../objects/high_annotated_males_decontx.rds')
  1335. DefaultAssay(adata) = 'decontXcounts'
  1336. adata
  1337. adata$cell_type = recode(
  1338. adata$cell_type,
  1339. "Oligendrocytes" = "Oligodendrocytes",
  1340. "Hbb-b1_Hbb-a2_Blood?" = "Blood",
  1341. "Glutaminergic_Slc17a6" = "Glutamatergic_Vglut2",
  1342. "Glutaminergic_Slc17a7" = "Glutamatergic_Vglut1"
  1343. )
  1344. unique(adata$cell_type)
  1345. sce = as.SingleCellExperiment(adata)
  1346. rm(adata)
  1347. sce
  1348. gc()
  1349. cpm_mat = scater::calculateCPM(counts(sce))
  1350. assay(sce, "cpm") = cpm_mat
  1351. gc()
  1352. sce = scater::logNormCounts(sce)
  1353. sce
  1354. gc()
  1355. colData(sce)
  1356. gc()
  1357. sce$SampleID = as.factor(sce$SampleID)
  1358. sce$Groups = as.factor(sce$Groups)
  1359. rm(cpm_mat)
  1360. gc()
  1361. ###################################
  1362. sce_sub <- sce[, sce$Groups %in% c("Resistant", "Sensitive")]
  1363. res_list = list()
  1364. clusters = unique(sce_sub$cell_type)
  1365. #clusters = 'Microglia'
  1366. set.seed(123)
  1367. gc()
  1368. for (cl in clusters) {
  1369. #cl = 'Microglia'
  1370. cat("Processing cluster:", cl, "\n")
  1371. sce_cl <- sce_sub[, sce_sub$cell_type == cl]
  1372. sce_cl$Groups = droplevels(sce_cl$Groups)
  1373. sce_cl$cell_type = droplevels(sce_cl$cell_type)
  1374. sample_md <- unique(as.data.frame(colData(sce_cl)[, c("SampleID", "Groups")]))
  1375. design_sub <- model.matrix(~ Groups, data = sample_md)
  1376. rownames(design_sub) <- sample_md$SampleID
  1377. design_sub
  1378. gc()
  1379. res_cl <- distinct_test(
  1380. x = sce_cl,
  1381. name_assays_expression = "cpm",
  1382. name_cluster = "cell_type", # single cluster, doesn't matter
  1383. name_sample = "SampleID",
  1384. design = design_sub,
  1385. column_to_test = 2,
  1386. min_non_zero_cells = 2000,
  1387. n_cores = 10,
  1388. P_4 = 5000
  1389. )
  1390. # Compute log2 FC
  1391. res_cl <- log2_FC(
  1392. res = res_cl,
  1393. x = sce_cl,
  1394. name_assays_expression = "cpm",
  1395. name_group = "Groups",
  1396. name_cluster = "cell_type"
  1397. )
  1398. # Store results with cluster name
  1399. res_list[[cl]] <- res_cl
  1400. gc()
  1401. }
  1402. res_sen <- bind_rows(res_list, .id = "cell_type")
  1403. top <- top_results(res_sen, significance = 0.05, global = TRUE)
  1404. write_xlsx(top, "res_sen_by_cluster.xlsx")
  1405. gc()
  1406. unique(sce_sub$Groups)
  1407. sce_sub$Groups = droplevels(sce_sub$Groups)
  1408. unique(sce_sub$Groups)
  1409. design_sub
  1410. gc()
  1411. sce_sub
  1412. sum(logcounts(sce_sub)["Sik2", ] > 0)
  1413. table(sce$cell_type)
  1414. res_sen <- distinct_test(
  1415. x = sce_sub,
  1416. name_assays_expression = "cpm",
  1417. name_cluster = "cell_type",
  1418. name_sample = "SampleID",
  1419. design = design_sub,
  1420. column_to_test = 2,
  1421. min_non_zero_cells = 200,
  1422. n_cores = 1,
  1423. P_4 = 20000
  1424. )
  1425. res_sen = log2_FC(res = res_sen,
  1426. x = sce_sub,
  1427. name_assays_expression = 'cpm',
  1428. name_group = "Groups",
  1429. name_cluster = "cell_subtype")
  1430. top = top_results(res_sen,
  1431. significance = 0.05, global = T)
  1432. plot_densities(x = sce_sub,
  1433. gene = 'Cdk10',
  1434. cluster = 'Drd2_Calcrl',
  1435. name_assays_expression = 'cpm',
  1436. name_cluster = 'cell_subtype',
  1437. name_sample = 'SampleID',
  1438. name_group = 'Groups', group_level = F)
  1439. plot_densities(x = sce_sub,
  1440. gene = 'Cdk10',
  1441. cluster = 'Drd2_Calcrl',
  1442. name_assays_expression = 'cpm',
  1443. name_cluster = 'cell_subtype',
  1444. name_sample = 'SampleID',
  1445. name_group = 'Groups', group_level = T)
  1446. write_xlsx(x = top, 'res_sen.xlsx')
  1447. #########################################
  1448. sce_sub <- sce[, sce$Groups %in% c("Resistant", "Yoked")]
  1449. unique(sce_sub$Groups)
  1450. sce_sub$Groups = droplevels(sce_sub$Groups)
  1451. unique(sce_sub$Groups)
  1452. set.seed(123)
  1453. sample_md <- unique(as.data.frame(colData(sce_sub)[, c("SampleID", "Groups")]))
  1454. design_sub <- model.matrix(~ Groups, data = sample_md)
  1455. rownames(design_sub) <- sample_md$SampleID
  1456. design_sub
  1457. gc()
  1458. sce_sub
  1459. sum(logcounts(sce_sub)["Slc17a7", ] > 0)
  1460. res_yok <- distinct_test(
  1461. x = sce_sub,
  1462. name_assays_expression = "cpm",
  1463. name_cluster = "cell_subtype",
  1464. name_sample = "SampleID",
  1465. design = design_sub,
  1466. column_to_test = 2,
  1467. min_non_zero_cells = 2000,
  1468. n_cores = 10,
  1469. P_4 = 20000
  1470. )
  1471. res_yok = log2_FC(res = res_yok,
  1472. x = sce_sub,
  1473. name_assays_expression = 'cpm',
  1474. name_group = "Groups",
  1475. name_cluster = "cell_subtype")
  1476. top = top_results(res_yok,
  1477. significance = 0.05, global = T)
  1478. plot_densities(x = sce_sub,
  1479. gene = 'Cdk10',
  1480. cluster = 'Drd2_Calcrl',
  1481. name_assays_expression = 'cpm',
  1482. name_cluster = 'cell_subtype',
  1483. name_sample = 'SampleID',
  1484. name_group = 'Groups', group_level = F)
  1485. plot_densities(x = sce_sub,
  1486. gene = 'Cdk10',
  1487. cluster = 'Drd2_Calcrl',
  1488. name_assays_expression = 'cpm',
  1489. name_cluster = 'cell_subtype',
  1490. name_sample = 'SampleID',
  1491. name_group = 'Groups', group_level = T)
  1492. write_xlsx(x = top, 'res_yok.xlsx')
  1493. gc()
  1494. ######################### Analysis of results #################################
  1495. res_sen = read_excel('res_sen.xlsx')
  1496. res_yok = read_excel('res_yok.xlsx')
  1497. head(res_sen)
  1498. head(res_yok)
  1499. library(dplyr)
  1500. overlap <- inner_join(
  1501. res_sen %>% select(gene, cluster_id, everything()),
  1502. res_yok %>% select(gene, cluster_id, everything()),
  1503. by = c("gene", "cluster_id"),
  1504. suffix = c("_sen", "_yok")
  1505. )
  1506. overlap_same_direction <- overlap %>%
  1507. filter(
  1508. (`log2FC_Resistant/Sensitive` > 0 & `log2FC_Resistant/Yoked` > 0) |
  1509. (`log2FC_Resistant/Sensitive` < 0 & `log2FC_Resistant/Yoked` < 0)
  1510. )
  1511. overlap_same_direction$average_log2FC = (overlap_same_direction$`log2FC_Resistant/Sensitive`+overlap_same_direction$`log2FC_Resistant/Yoked`)/2
  1512. overlap_same_direction$average_p_adj = (overlap_same_direction$p_adj.glb_sen + overlap_same_direction$p_adj.glb_yok)/2
  1513. write_xlsx(overlap_same_direction, 'DEG_list_males_main_celltypes.xlsx')
  1514. for_ipa = overlap_same_direction %>% select(gene, average_log2FC, average_p_adj, cluster_id)
  1515. dir.create('for_ipa')
  1516. celltypes <- unique(df$cluster_id)
  1517. for (ct in celltypes) {
  1518. sub <- for_ipa %>% filter(cluster_id == ct)
  1519. write.csv(sub, paste0("for_ipa/IPA_", ct, ".csv"), row.names = FALSE)
  1520. }
  1521. library(dplyr)
  1522. library(ggpubr)
  1523. library(viridis)
  1524. ##########################################################################
  1525. overlap_same_direction = read_xlsx('DEG_list_males_main_celltypes.xlsx')
  1526. library(dplyr)
  1527. library(ggpubr)
  1528. library(viridis)
  1529. library(dplyr)
  1530. library(ggplot2)
  1531. library(patchwork)
  1532. library(ggrepel)
  1533. df = overlap_same_direction
  1534. df <- df %>%
  1535. mutate(
  1536. reg_sen = case_when(
  1537. p_adj.glb_sen < 0.05 & `log2FC_Resistant/Sensitive` > 0.1 ~ "Up",
  1538. p_adj.glb_sen < 0.05 & `log2FC_Resistant/Sensitive` < -0.1 ~ "Down",
  1539. TRUE ~ "NS"
  1540. ),
  1541. reg_yok = case_when(
  1542. p_adj.glb_yok < 0.05 & `log2FC_Resistant/Yoked` > 0.1 ~ "Up",
  1543. p_adj.glb_yok < 0.05 & `log2FC_Resistant/Yoked` < -0.1 ~ "Down",
  1544. TRUE ~ "NS"
  1545. )
  1546. )
  1547. make_volcano_pair <- function(df, cluster) {
  1548. df_clust <- df %>% filter(cluster_id == cluster)
  1549. p_sen <- ggplot(df_clust, aes(
  1550. x = `log2FC_Resistant/Sensitive`,
  1551. y = -log10(p_adj.glb_sen)
  1552. )) +
  1553. geom_point(aes(color = reg_sen), size = 1.2, alpha = 0.7) +
  1554. geom_vline(xintercept = c(-0.1, 0.1), linetype = "dashed") +
  1555. geom_hline(yintercept = -log10(0.05), linetype = "dashed") +
  1556. geom_text_repel(
  1557. data = df_clust %>% filter(reg_sen != "NS"),
  1558. aes(label = gene),
  1559. size = 3,
  1560. max.overlaps = 20
  1561. ) +
  1562. scale_color_manual(
  1563. values = c(Up = "red", Down = "blue", NS = "grey70")
  1564. ) +
  1565. labs(
  1566. title = "Resistant vs Sensitive",
  1567. x = "log2FC",
  1568. y = "-log10(adj p-value)"
  1569. ) +
  1570. theme_classic() +
  1571. theme(legend.position = "none")
  1572. p_yok <- ggplot(df_clust, aes(
  1573. x = `log2FC_Resistant/Yoked`,
  1574. y = -log10(p_adj.glb_yok)
  1575. )) +
  1576. geom_point(aes(color = reg_yok), size = 1.2, alpha = 0.7) +
  1577. geom_vline(xintercept = c(-0.1, 0.1), linetype = "dashed") +
  1578. geom_hline(yintercept = -log10(0.05), linetype = "dashed") +
  1579. geom_text_repel(
  1580. data = df_clust %>% filter(reg_yok != "NS"),
  1581. aes(label = gene),
  1582. size = 3,
  1583. max.overlaps = 20
  1584. ) +
  1585. scale_color_manual(
  1586. values = c(Up = "red", Down = "blue", NS = "grey70")
  1587. ) +
  1588. labs(
  1589. title = "Resistant vs Yoked",
  1590. x = "log2FC",
  1591. y = "-log10(adj p-value)"
  1592. ) +
  1593. theme_classic() +
  1594. theme(legend.position = "none")
  1595. (p_sen | p_yok) + plot_annotation(title = cluster)
  1596. }
  1597. clusters <- unique(df$cluster_id)
  1598. volcano_plots <- lapply(clusters, function(cl) {
  1599. make_volcano_pair(df, cl)
  1600. })
  1601. volcano_plots[[1]]
  1602. dir.create('volcano_plots')
  1603. clusters <- unique(df$cluster_id)
  1604. for (cl in clusters) {
  1605. p <- make_volcano_pair(df, cl)
  1606. ggsave(
  1607. filename = paste0("volcano_plots/volcano_", cl, ".pdf"),
  1608. plot = p,
  1609. width = 15,
  1610. height = 10,
  1611. units = "in"
  1612. )
  1613. }
  1614. ################################################################################
  1615. df_plot <- overlap_same_direction %>% count(cluster_id)
  1616. p = ggbarplot(
  1617. df_plot,
  1618. x = "cluster_id",
  1619. y = "n",
  1620. fill = "cluster_id",
  1621. palette = viridis(nrow(df_plot)),
  1622. label = TRUE,
  1623. lab.vjust = -0.5,
  1624. sort.val = "desc", # sort bars by height (largest at top)
  1625. sort.by.groups = FALSE,
  1626. x.text.angle = 45,
  1627. legend = "none" # remove legend
  1628. ) +
  1629. labs(
  1630. title = "Number of DEGs per cluster",
  1631. x = "Cluster ID",
  1632. y = "Gene Count"
  1633. )
  1634. p
  1635. pdf('number_of_degs_per_cluster.pdf')
  1636. print(p)
  1637. dev.off()

master.R at commit 115c830, under MIT · at the source

Overview

  1. Center for Social and Affective Neuroscience, BKV, Linköping University, Linköping, Sweden
  2. Waggoner Center for Alcohol and Addiction Research and Departments of Neuroscience and Neurology, University of Texas at Austin, Austin, TX USA
  3. Department of Pharmacy and Biotechnology, Alma Mater Studiorum – University of Bologna, Bologna, Italy
  4. Center for Neuroscience, University of Camerino, Camerino, Italy
Journal: Nature communications, volume 17, issue 1, article 9407
Dates: received 7 April 2026; accepted 20 August 2026; published online 2 September 2026
Type: Research article · Language: English
License: CC BY
Identifiers: DOI 10.1038/s41467-026-77302-9 · PMID 42686758 · PMCID PMC13538410 · OpenAlex W7206173153
Open access: gold, a free copy (OpenAlex)
Status: code verified
Categories: genetics / omics (modality), rat (organism), other condition (population), cellular / molecular (subfield)
Methods: Statistics, Smoothing, state filtering, decompositions, Machine learning, Preprocessing, Evoked potentials, Spectral & time-frequency
Keywords: Molecular neuroscience, Addiction
MeSH: Alcoholism*, Central Amygdaloid Nucleus*, Receptor, Fibroblast Growth Factor, Type 1*, Animals, Disease Models, Animal, Ethanol, Male, Neurons, Protein Kinase C-delta, Pyrimidines, Rats, Self Administration (* major topic)
Topic: Neurotransmitter Receptor Influence on Behavior (Cellular and Molecular Neuroscience, Neuroscience), according to OpenAlex
Funding: Vetenskapsrådet (Swedish Research Council) (2019-01138, 2013-07434, 2022-06568, 2024-02537); NIAAA NIH HHS (U01 AA013520, K00 AA029955, R01 AA012404, R01 AA028807, U01 AA020926); U.S. Department of Health & Human Services | National Institutes of Health (NIH) (K00AA029955, K00AA029955 (NAS), R01AA012404, U01AA020926, U01AA020926(RDM), R01AA012404(RDM)); U.S. Department of Health & Human Services | NIH | National Institute on Alcohol Abuse and Alcoholism (NIAAA) (AA013520, AA028807)
Citations: not cited yet (Europe PMC); 37 references in the paper
Research resources: The University of Texas at Austin RRID:SCR_021713

Abstract

A significant minority of alcohol users develop alcohol addiction, characterized by continued use despite negative consequences, referred to as compulsive-like. We previously showed that vulnerability to compulsive-like alcohol use can be modeled in rats using punished alcohol self-administration and in male rats is mediated by PKCδ+ neurons in the central nucleus of the amygdala (CeA). Here, we used cell-type-specific transcriptomics to identify molecular mechanisms underlying individual differences in this behavior. Transcriptional changes were restricted to a limited number of CeA neuronal populations, including PKCδ+ neurons, where weighted Gene Co-expression Network Analysis identified an upregulated co-expression module in punishment-resistant rats with FGFR1 as a druggable upstream regulator. Selective silencing of FgfR1 in PKCδ+ neurons normalized elevated PKCδ+ expression, and reduced punishment-resistant alcohol self-administration. This effect was recapitulated by systemic administration of the FgfR1-antagonist PD173074. These findings identify distinct CeA circuits that promote addiction vulnerability, and position FGFR1 as potential therapeutic targets.

Reproduced under the paper's license (CC BY), from the paper cited above.

Repository

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

leohog/Fgfr1_analysis

License: MIT
State: the link answers, verified on 26 September 2026
Evidence: files inventoried
Commit: 115c830f9e669f8eae77446eaca0d9d75e1e7ab0, 20 April 2026
Languages: R (1)
Size: 4 files, 1 script
Software Heritage: not archived
Found in: “Code availability”
Holds: README, license file
Not found: CITATION.cff, environment file, tests, continuous integration, documentation
Tools: cowplot (1 file), ggplot2 (1 file), ggpubr (1 file), igraph (1 file), patchwork (1 file), Seurat (1 file), SingleCellExperiment (1 file), tidyverse (1 file), WGCNA (1 file)
Availability: 1 check, the latest on 26 September 2026: the link answers
  • 26 September 2026: the link answers
3 files

Code availability

The code used to perform these analyses is publicly available on GitHub at https://github.com/leohog/Fgfr1_analysis. For package version information, see supplementary data 3.

Reproduced under the paper's license (CC BY), from the paper cited above.

Tracing map

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

What the map holds:

  • 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 1 script, each with its path and the digest of its content;
  • 4 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 RNA sequencing data generated in this study have been deposited in the GEO database under accession code GSE310229 (https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE310229) https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE310229. Source data for all figures is provided in this paper. Source data are provided with this paper.

The code used to perform these analyses is publicly available on GitHub at https://github.com/leohog/Fgfr1_analysis. For package version information, see supplementary data 3.

Reproduced under the paper's license (CC BY), from the paper cited above.

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, 27 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 11 authors, 2 keywords, 12 MeSH terms, 4 funders, 36 references, 1 RRID.

Cite

This paper

Barbier, E., Höglund, L., Xu, L., Salem, N. A., Osterndorff-Kahanek, E. A., Barchiesi, R., Lacorte, A., Fenno, L. E., Messing, R. O., Mayfield, R. D., & Heilig, M. (2026). Identification and validation of central amygdala FGFR1 as a therapeutic target for alcohol use disorder using single-nucleus sequencing in rats. Nature communications, 17(1), 9407. https://doi.org/10.1038/s41467-026-77302-9

BibTeX

@article{barbier2026identification,
author = {Barbier, Estelle and Höglund, Leon and Xu, Li and Salem, Nihal A and Osterndorff-Kahanek, Elizabeth A and Barchiesi, Riccardo and Lacorte, Antonio and Fenno, Lief E and Messing, Robert O and Mayfield, R Dayne and Heilig, Markus},
title = {{Identification and validation of central amygdala FGFR1 as a therapeutic target for alcohol use disorder using single-nucleus sequencing in rats}},
journal = {Nature communications},
year = {2026},
month = sep,
volume = {17},
number = {1},
pages = {9407},
publisher = {Nature Publishing Group},
issn = {2041-1723},
doi = {10.1038/s41467-026-77302-9},
url = {https://doi.org/10.1038/s41467-026-77302-9},
pmid = {42686758},
pmcid = {PMC13538410}
}

RIS

TY - JOUR
AU - Barbier, Estelle
AU - Höglund, Leon
AU - Xu, Li
AU - Salem, Nihal A
AU - Osterndorff-Kahanek, Elizabeth A
AU - Barchiesi, Riccardo
AU - Lacorte, Antonio
AU - Fenno, Lief E
AU - Messing, Robert O
AU - Mayfield, R Dayne
AU - Heilig, Markus
TI - Identification and validation of central amygdala FGFR1 as a therapeutic target for alcohol use disorder using single-nucleus sequencing in rats
T2 - Nature communications
J2 - Nat Commun
PY - 2026
DA - 2026/09/02
VL - 17
IS - 1
SP - 9407
SN - 2041-1723
PB - Nature Publishing Group
DO - 10.1038/s41467-026-77302-9
UR - https://doi.org/10.1038/s41467-026-77302-9
LA - en
ER -

CSL-JSON

{
"id": "10.1038/s41467-026-77302-9",
"type": "article-journal",
"title": "Identification and validation of central amygdala FGFR1 as a therapeutic target for alcohol use disorder using single-nucleus sequencing in rats",
"container-title": "Nature communications",
"author": [
{
"family": "Barbier",
"given": "Estelle"
},
{
"family": "Höglund",
"given": "Leon"
},
{
"family": "Xu",
"given": "Li"
},
{
"family": "Salem",
"given": "Nihal A"
},
{
"family": "Osterndorff-Kahanek",
"given": "Elizabeth A"
},
{
"family": "Barchiesi",
"given": "Riccardo"
},
{
"family": "Lacorte",
"given": "Antonio"
},
{
"family": "Fenno",
"given": "Lief E"
},
{
"family": "Messing",
"given": "Robert O"
},
{
"family": "Mayfield",
"given": "R Dayne"
},
{
"family": "Heilig",
"given": "Markus"
}
],
"container-title-short": "Nat Commun",
"volume": "17",
"issue": "1",
"page": "9407",
"DOI": "10.1038/s41467-026-77302-9",
"PMID": "42686758",
"PMCID": "PMC13538410",
"ISSN": "2041-1723",
"publisher": "Nature Publishing Group",
"URL": "https://doi.org/10.1038/s41467-026-77302-9",
"language": "en",
"issued": {
"date-parts": [
[
2026,
9,
2
]
]
}
}

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

Similar papers

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

[1] doi:10.1038/s41398-026-04200-5 [code]
Postmortem brain single-nucleus and bulk gene expression analyses identify shared and distinct abnormalities in bipolar disorder and major depressive disorder.
Journal: Translational psychiatry
In common: WGCNA, SingleCellExperiment, igraph, 6 other tools, genetics / omics, cellular / molecular, 2 references
[2] 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: WGCNA, SingleCellExperiment, igraph, 6 other tools, genetics / omics, other condition, cellular / molecular, 1 reference
[3] doi:10.1038/s44318-026-00806-z [code]
Interspecific diversity in the neuronal composition of the mammalian cortex arises from heterochrony in neurogenesis.
Journal: The EMBO journal
In common: WGCNA, SingleCellExperiment, igraph, 6 other tools, rat, 1 reference
[4] 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: WGCNA, SingleCellExperiment, igraph, 6 other tools, cellular / molecular, 1 reference
[5] doi:10.1016/j.isci.2026.115573 [code]
Female cortical cellular mosaicism underlies shared MeCP2 and PCB impacted gene pathways.
Journal: iScience
In common: WGCNA, SingleCellExperiment, igraph, 6 other tools, cellular / molecular, 1 reference
[6] doi:10.1038/s41467-026-71542-5 [code]
Astrocyte fatty acid metabolism as a driver of risk for major depressive disorder.
Journal: Nature communications
In common: WGCNA, SingleCellExperiment, igraph, 5 other tools, genetics / omics, cellular / molecular, 1 reference
[7] doi:10.1038/s41593-026-02384-z [code]
cGAS-mediated type I IFN signaling contributes to disease progression in drug-refractory epilepsy.
Journal: Nature neuroscience
In common: WGCNA, SingleCellExperiment, igraph, 5 other tools, cellular / molecular, 1 reference
[8] doi:10.1038/s41467-026-73305-8 [code]
Comparative analysis of the cellular landscape in mammalian striatum.
Journal: Nature communications
In common: WGCNA, SingleCellExperiment, Seurat, 5 other tools, genetics / omics, cellular / molecular, 1 reference
[9] doi:10.1016/j.isci.2026.115196 [code]
Transcriptional and cellular maturation of the chick spinal cord in the context of distinct neuromuscular circuits.
Journal: iScience
In common: WGCNA, SingleCellExperiment, igraph, 6 other tools
[10] doi:10.1038/s41380-026-03629-w [code]
Maternal fasting during early gestation induces epigenetic alterations and schizophrenia-related phenotypes.
Journal: Molecular psychiatry
In common: WGCNA, igraph, Seurat, 4 other tools, genetics / omics, cellular / molecular, 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.