-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGSE183325 Script.R
More file actions
2362 lines (1373 loc) · 69.7 KB
/
Copy pathGSE183325 Script.R
File metadata and controls
2362 lines (1373 loc) · 69.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#* title: "PEC GSE183325 RNASeq Analysis SCRIPT"
#* author: "Jason Lubega"
#* date: "06.Mar.2025"
##* Background
##* Myelodysplastic syndromes (MDS) are clonal hematopoietic stem cell (HSC) malignancies characterized by ineffective hematopoiesis with increased incidence in elderly individuals. Genetic alterations do not fully explain the molecular pathogenesis of the disease, indicating that other types of lesions may play a role in its development. In this work, we will analyze the transcriptional lesions of human HSCs to explore how aging and MDS are characterized.
## Plan
# Load Data
# EDA - Data Exploration
# DEA - Differential Expression (Used DeSeq2)
# GO - Pathway Analysis
#### Set working directory
setwd("C:/Users/Lenovo/MIB Assignments/NOTES/Bioinformatica/Bioinformatics Practice R/PEC GSE183325 NereaB")
#### Load libraries
#Getting GEOData
library(Biobase)
library(GEOquery)
#EDA, DEA packages
library(edgeR)
library(limma)
library(DESeq2)
#Data visualisation
library(ggplot2)
library(ggrepel)
suppressPackageStartupMessages(library(ComplexHeatmap))
#Data manipulation
library(tidyverse)
library(dplyr)
library(reshape2)
##****** Human gene annotation package
#if (!require("BiocManager", quietly = TRUE))
#install.packages("BiocManager")
#BiocManager::install("org.Hs.eg.db")
library(org.Hs.eg.db)
#BiocManager::install("biomaRt")
library(biomaRt)
#BiocManager::install("AnnotationDbi")
library(AnnotationDbi)
#Pathway Analysis
library(clusterProfiler)
library(enrichplot)
##**** LOAD DATA
# Loading metadata files from GEO and Raw Counts (locally)
# counts data
counts_rawdata <- read.csv('GSE183325_RawCounts_matrix_Young_Elderly_MDS.csv' , sep = "", header = TRUE)
#View(counts_rawdata)
# ATTEMPT 2 on sample Metadata
library(GEOquery)
options(download.file.method = "libcurl")
GSE183325_allmetadata <- getGEO("GSE183325", GSEMatrix = TRUE)
#this is a list that contains all sections
#I am interested in the "phenoData" and the "featureData"
#Expression DataSet extraction
url("http://www.google.com")
# Store the GEO dataset as "GSE60450_gse"
GSE183325_gse <- GSE183325_allmetadata[[1]]
# Get the names of samples
sample_id <- sampleNames(GSE183325_gse)
#View(sample_id)
# Get the expression matrix
#View(exprs(GSE183325_gse)) #empty
#samples metadata
sample_metadata <- pData(GSE183325_gse)
#View(sample_metadata)
#Changing column headings to sample Names
#colnames(counts_rawdata) == rownames(sample_metadata) #ALL TRUE
colnames(counts_rawdata) <- rownames(sample_metadata) #success
##**Obtaining gene metadata - GENE MAPPING**
#We do nOt have a gene metadata file. Therefore we created one using the ENSEMBL Gene IDs in the counts data. This requires us to first convert ENSEMBL Gene IDs to ENTREZ Gene IDs
#**org.Hs.eg.db vs biomaRt**
#In order to obtain the gene metadata, I performed gene mapping using both *biomaRt* and *org.Hs.eg.db*.
#**org.Hs.eg.db**
#GETTING gene_metadata #***********
#* Using org.Hs.eg.db
#columns(org.Hs.eg.db)
ensembl_geneIDs <- rownames(counts_rawdata)
#View(ensembl_geneIDs)
entrez_geneIDS <- mapIds(org.Hs.eg.db, keys = ensembl_geneIDs, column = "ENTREZID", keytype = "ENSEMBL", multiVals = "first")
entrez_geneIDS_df <- data.frame(entrez_geneIDS)
colnames(entrez_geneIDS_df) <- c("ENTREZID")
#View(entrez_geneIDs_df)
gene_metadata_annotated <- AnnotationDbi::select(org.Hs.eg.db,keys=entrez_geneIDS_df$ENTREZID,columns=c("ENTREZID","SYMBOL","GENENAME"))
#entrez_geneIDS_df$ENTREZID == gene_metadata_annotated$ENTREZID #TRUE
rownames(gene_metadata_annotated) <- rownames(entrez_geneIDS_df) #success
#renamed rownames of the gene_metadata_annotated file to contain ENSEMBL gene IDs as some genes lack the Entrez ID.
head(gene_metadata_annotated)
#Alot of N/A s Unannotated genes therefore we will try again with biomaRt.
## **biomaRt**
#********BIOMART gene mapping
#Therefore we will turn to using biomaRt instead
#As it contains the updated ensembl data.
ensembl <- useEnsembl(biomart = "genes", dataset = "hsapiens_gene_ensembl")
# Query Ensembl for gene symbols
# We will use the "ensembl_geneIDs" object created in the previous chunk.
gene_mapping <- getBM(
attributes = c("ensembl_gene_id","entrezgene_id", "hgnc_symbol","description"),
filters = "ensembl_gene_id",
values = ensembl_geneIDs,
mart = ensembl
)
#Are the rownames in the same order as our gene metadata file???
#gene_mapping$ensembl_gene_id==rownames(gene_metadata_annotated) #FALSE
# View results
head(gene_mapping)
gene_mapping_backup <- gene_mapping #unmodified gene mapping data
#from now non gene_mapping will be modified to suit my data
gene_mapping_annotated <- gene_mapping[match(rownames(gene_metadata_annotated), gene_mapping$ensembl_gene_id), ]
library(dplyr)
gene_mapping <- gene_mapping %>%
group_by(ensembl_gene_id) %>%
summarise(hgnc_symbol = paste(unique(hgnc_symbol), collapse = "; ")) # Merge duplicate symbols
rownames(gene_mapping) <- gene_mapping$ensembl_gene_id
#Since gene_mapping lacks the other important rows we will add them from gene_mapping_annotated
gene_mapping_combined <- full_join(gene_mapping, gene_mapping_annotated,
by = "ensembl_gene_id")
head(gene_mapping_combined)
#**** gene_mapping_annotated has all IDs but some are duplicated
#* gene_mapping has unique ensembl Ids (no duplications)
#*
#*
gene_mapping_metadata_COMPLETE <- merge.data.frame(gene_metadata_annotated, gene_mapping_annotated, by.x=0, by.y="ensembl_gene_id" )
#** gene_mapping_metadata_COMPLETE has is the BEST gene metadata set as it contains all fields from both "org.Hs.eg.db" and "BiomaRt"
##*****Exploratory Data Analysis (EDA)**
### Raw Counts vs Normalised Counts
#**Data filtering**
# I will use filterByExpr() function with a default parameters.
# The default parameters exclude a lot of genes as seen below.
#myge_filter FALSE=42022 AND TRUE =16713
colSums(counts_rawdata)
group_age <- sample_metadata$`condition:ch1`
table(group_age)
#creating filtering criteria
library(edgeR)
myge_filter <- filterByExpr(counts_rawdata, group = group_age, min.count = 10, min.total.count = 15)
#table(myge_filter)
## Using filter to keep only TRUE values
counts_raw_filtered <- counts_rawdata[myge_filter,]
#dim(counts_raw_filtered) #success [1] 16713 by 37
#**Normalized Counts**
#Using TMM normalisation, normLibSizes() What method does DeSeq2 analysis need?
#tmm normalization - requires edgeR library
dge <- DGEList(counts = counts_raw_filtered, group= group_age)
norm_counts <- normLibSizes(dge, method = "TMM")
counts_normalized <- cpm(norm_counts, normalized.lib.sizes = TRUE)
counts_norm_log2 <- log2(counts_normalized+1)
#**Depth Chart (Raw vs Normalised)**
#Non normalised filtered counts
counts_rawfiltrd_plot <- data.frame(sample_id=colnames(counts_raw_filtered),depth=colSums(counts_raw_filtered))
#Normalised filtered counts
counts_norm_to_plot <- data.frame(sample_id=colnames(counts_norm_log2),norm_depth=colSums(counts_norm_log2))
library(ggplot2)
#PLOTS
#Non-normalised Data PLOT
p_raw <- ggplot(counts_rawfiltrd_plot,aes(x=sample_id, y=depth, fill=sample_id)) +
ggtitle("Sequence depth of Raw Filtered Data")+
geom_col() +
scale_y_log10() +
theme_classic() +
theme(axis.text.x = element_text(angle=90))
#Normalised Data PLOT
p_norm <- ggplot(counts_norm_to_plot,aes(x=sample_id, y=norm_depth, fill=sample_id)) +
ggtitle("Sequence depth of Filtered and Normalised Data")+
geom_col() +
theme_classic() +
theme(axis.text.x = element_text(angle=90))+
ylab("norm_depth (log2)")
par(mfrow = c(1, 2))
p_raw
p_norm
par(mfrow = c(1, 1))
#################--------------
#**Distribution Chart (Raw vs Normalised)**
## Counts (RAW) distribution
counts_boxplot_data <- stack(counts_raw_filtered)
#View(counts_boxplot_data)
bp_raw <- ggplot(counts_boxplot_data,aes(x=ind, y=values)) +
ggtitle("Counts Distribution of Filtered Raw Counts")+
geom_boxplot(color="blue") +
scale_y_log10() +
theme_classic() +
theme(axis.text.x = element_text(angle=90), axis.line = element_line(color = "#008140"))
##******************
##* Counts (NORMALIZED) distribution
counts_norm_boxplot_data <- data.frame(counts_normalized)
counts_norm_boxplot_data <- stack(counts_norm_boxplot_data)
#View(counts_norm_boxplot_data)
#change colnames
colnames(counts_norm_boxplot_data) <- c("values", "ind")
bp_norm <- ggplot(counts_norm_boxplot_data,aes(x=ind, y=values)) +
ggtitle("Counts Distribution of Normalized Counts")+
geom_boxplot(color="blue") +
scale_y_log10()+
theme_classic() +
theme(axis.text.x = element_text(angle=90), axis.line = element_line(color = "#008140"))
par(mfrow = c(2, 1))
bp_raw
bp_norm
par(mfrow = c(1, 1))
#################--------------
#*****Principal Component Analysis - PCA Plot**
# Check variance in the dataset. Anomalies or Outliers.
# I used the normalized Counts data
## Principal component Analysis
pca_output <- prcomp(t(counts_norm_log2))
# to compute for samples we need to provide it by rows
# so we transpose our matrix.
pca_df <- data.frame(PC1=pca_output$x[,1],
PC2=pca_output$x[,2],
Group=group_age)
ggplot(pca_df,aes(x=PC1, y=PC2, color=Group)) +
geom_point(size=4) +
theme_classic() +
xlab("PC1 (13.93%)") +
ylab("PC2 (11.23%)")+
geom_text_repel(aes(label=rownames(pca_df), size=1.5))
#################--------------
##***Differential Gene Expression (DEA)**
# What parameter are we contrasting by?
#* Young vs Elderly, Healthy vs Untreated MDS*
# Method: DESeq2
######### DESeq2 #########
library(dplyr)
# Include the group variable as a factor
sample_metadata$group <- factor(dplyr::recode(sample_metadata$`condition:ch1`,
"Young healthy donor"="Young_healthy",
"Elderly healthy donor"="Elderly_healthy", "Untreated MDS patient" = "MDS_Untreated"),
levels=c("Young_healthy","Elderly_healthy","MDS_Untreated"))
#Also include group2 of Healthy vs MDS sick.
sample_metadata$group2 <- factor(dplyr::recode(sample_metadata$`condition:ch1`,
"Young healthy donor"="Healthy",
"Elderly healthy donor"="Healthy", "Untreated MDS patient" = "MDS_Untreated"),
levels=c("Healthy","MDS_Untreated"))
# Create DESeqDataSet object with count data, sample metadata, and design matrix
library("DESeq2")
dds <- DESeqDataSetFromMatrix(countData = counts_rawdata,
colData = sample_metadata,
design = ~ 0 + group)
#View(dds)
# Filter out low expressed genes
dds.filt <- dds[myge_filter,]
dim(dds.filt) #[1] 16713 37
# Differential expression analysis
dds.filt.dea <- DESeq(dds.filt)
##########################
#### Results:DESEq2
##**Significantly Differentially Expressed Genes**
# log2FoldChange >0.58 & padj<=0.05
# Biological significance vs Statistical Significance.
res <- results(dds.filt.dea) # shows the contrast by default based on group factor order.
saveRDS(res, "DEA_DESeq2_GSE183325.rds")
#dim(res) #[1] 16713 6
#***SIGNIFICANTLY DEA Genes***
sig_Genes <- res[res$padj<=0.05 & res$log2FoldChange>0.58, ]
sig_Genes <- data.frame(sig_Genes)
#dim(sig_Genes) #[1] 1346 6
n_sig_Genes <- nrow(sig_Genes) # number of significantly Diff expressed genes
head(sig_Genes)
# > Therefore *1346* genes out of the filtered *16713* are statisticaly and biologically significant.
##############-------------------------------
### DEA visualization plots
#**Volcano Plot**
# Biological significance vs Statistical Significance
# I used the res object (consult if it was the appropriate choice)
ggplot(res, aes(x = log2FoldChange, y = -log10(padj))) +
geom_point(color = "black", alpha = 0.3) +
#Overexpressed genes = RED
geom_point(data=res[res$log2FoldChange > 0.58 & res$padj <= 0.05,],
aes(x = log2FoldChange, y = -log10(padj)), color="red", alpha = 0.7) +
#Under expressed genes = BLUE
geom_point(data=res[res$log2FoldChange < -0.58 & res$padj <= 0.05,],
aes(x = log2FoldChange, y = -log10(padj)), color="blue", alpha = 0.7) +
#ref lines
geom_hline(yintercept = -log10(0.05), linetype = "dashed", color = "blue") +
geom_vline(xintercept = c(0.58, -0.58), linetype = "dashed", color = "gray") +
theme_minimal() +
labs(title = "Volcano Plot - Differential Expression",
x = "Log2 Fold Change",
y = "-Log10 adj-P-value")
# RED dots = Differentially Overexpressed genes.
# BLUE dots = Differentially Underexpressed genes.
#### **Heatmap Top 50 genes (Labeled with Gene SYMBOLS)**
# I tried to replace the ENSEMBL IDs with Gene Symbols, however, the matching was erroneous when **%in%** was used. I resolved this by using **match()** instead of **%in%**.
# And I have randomly checked for rownames in my annotated object vs "SYMBOL" in the gene_metadata file to proof read.
# The DESeq output is not normalised.
# Apply vst() to stabilise variances
vsd <- vst(dds.filt.dea, blind = TRUE)
dds.filt.dea_norm <- assay(vsd)
# Apply Z-transformation
Z_score <- t(scale(t(dds.filt.dea_norm), center = TRUE, scale = TRUE))
#View(Z_score)
#Order by Fc from Big to Small
sig_Genes_ordFch <- sig_Genes[order(sig_Genes$log2FoldChange, decreasing = TRUE),]
#Annotate SigGenes
sig_Genes_ordFch_metadata <- gene_metadata_annotated[match(rownames(sig_Genes_ordFch), rownames(gene_metadata_annotated)), c("SYMBOL", "GENENAME")]
sig_Genes_ordFch_annotated <- cbind(sig_Genes_ordFch, sig_Genes_ordFch_metadata) #success
#head(sig_Genes_ordFch_annotated)
group_colors <- c(
"Elderly healthy donor" = "#EE4D09",
"Young healthy donor" = "#22BA1A",
"Untreated MDS patient" = "#AB2087")
# Column annotation
column_ha <- HeatmapAnnotation(
age_status = group_age, #dev stage grouping
col = list(age_status = group_colors) #dev stage coloring
)
#Plot Heatmap (ComplexHeatmap)
DEGenes_heatmap <- Heatmap(Z_score[rownames(sig_Genes_ordFch)[1:50],],
row_names_gp = gpar(fontsize = 6),
top_annotation = column_ha,
row_names_side = "left",
row_labels = sig_Genes_ordFch_annotated$SYMBOL[1:50]
)
DEGenes_heatmap
#### **COMPARISONS and CONTRASTS**
#**DDIT3 across age and health status**
# symbol: DDIT3
# ensembl: ENSG00000175197
# Description: DNA damage inducible transcript 3
grouped_samples <- sample_metadata[,c("geo_accession", "condition:ch1")]
View(grouped_samples)
young_ids <- grouped_samples$geo_accession[grouped_samples$`condition:ch1` == "Young healthy donor"]
elderly_ids <- grouped_samples$geo_accession[grouped_samples$`condition:ch1` == "Elderly healthy donor"]
mds_ids <- grouped_samples$geo_accession[grouped_samples$`condition:ch1` == "Untreated MDS patient"]
healthy_ids <- c(young_ids,elderly_ids) #healthy ids both Young and Elderly
##** grouped_samples add a column for Healthy, MDS Sick
grouped_samples$status <- c("Healthy", "Healthy", "Healthy","Healthy","Healthy","Healthy","Healthy","Healthy","Healthy","Healthy","Healthy","Healthy","Healthy","Healthy","Healthy","Healthy","Healthy","Healthy","Healthy","Healthy","Healthy","Healthy","Healthy","Healthy","Healthy", "MDS", "MDS","MDS","MDS","MDS","MDS","MDS","MDS","MDS","MDS","MDS","MDS")
###****DDIT3 plot
ddit3_boxplot_data <- as.data.frame(t(dds.filt.dea_norm["ENSG00000175197", c(young_ids, elderly_ids, mds_ids)]))
#View(ddit3_boxplot_data)
ddit3_boxplot_data <- cbind(t(ddit3_boxplot_data), grouped_samples[,c("condition:ch1", "status")])
#change colnames
colnames(ddit3_boxplot_data) <- c("norm_counts", "ind", "status")
#str(ddit3_boxplot_data) #oops even the values are characters!!
ddit3_boxplot_data <- as.data.frame(ddit3_boxplot_data) # Convert to data frame
ddit3_boxplot_data$norm_counts <- as.numeric(ddit3_boxplot_data$norm_counts) # Convert to numeric
#plot
ggplot(ddit3_boxplot_data, aes(x=ind, y=norm_counts, fill=group_age)) +
ggtitle("DDIT3 expression: Young vs Elderly vs MDS")+
geom_boxplot(size = 0.5) +
theme_classic() +
theme(axis.text.x = element_text(angle=270), axis.line = element_line(color = "#008140"))+
ylab("Gene Expression")
#**DDIT3 in Healthy vs MDS**
# Here, the young and elderly donors were combined to form a healthy population to compare with the sick (Untreated MDS patients).
ggplot(ddit3_boxplot_data, aes(x=status, y=norm_counts, color=status)) +
ggtitle("DDIT3 expression: Healthy donors vs MDS patients")+
geom_boxplot(size = 1) +
theme_classic() +
theme(axis.text.x = element_text(angle=360), axis.line = element_line(color = "#008140"))
# > Untreated MDS patients express higher DDIT3 levels than both healthy young and elderly populations. Hence MDS could be characterised by a higher occcurence of DNA damage pathways.
#### **SOMATIC MUTATIONS**
# Broadly, the most common genes with recurrent somatic mutations in MDS include **ASXL1** (10–20%), EZH2 (5–10%), NRAS (5–10%), **RUNX1** (10–15%), **SF3B1** (20–30%), **SRSF2** (10–15%), STAG2 (5–10%), **TET2** (20–30%), **TP53** (10–12%), and U2AF1 (5–12%).
# For this, I will only check those that have an occurrence greater than 10% (in Bold).
library(gridExtra)
###****** COMMON SOMATIC MUTATIONS GENES plot
###*
###* COMMMON GENES AS PER LLITERATURE
#list of genes
som_mut_ids <- gene_mapping_metadata_COMPLETE$Row.names[gene_mapping_metadata_COMPLETE$hgnc_symbol %in% c("ASXL1", "RUNX1", "SF3B1", "SRSF2", "TET2", "TP53")]
som_mut_data_to_plot <- as.data.frame(t(dds.filt.dea_norm[som_mut_ids, ]))
# Created named vector, id_to_symbol, Ensembl IDs as names, Gene Symbols as values
id_to_symbol <- c(
"ENSG00000171456" = "ASXL1",
"ENSG00000159216" = "RUNX1",
"ENSG00000115524" = "SF3B1",
"ENSG00000161547" = "SRSF2",
"ENSG00000168769" = "TET2",
"ENSG00000141510" = "TP53"
)
# Replace column names using the named vector
colnames(som_mut_data_to_plot) <- id_to_symbol[colnames(som_mut_data_to_plot)]
# add sample groups column
som_mut_data_to_plot$group<- sample_metadata[,c("group")]
# PLOTS
# Convert from wide to long format
som_mut_data_to_plot_long <- som_mut_data_to_plot %>%
pivot_longer(cols = -group, names_to = "gene", values_to = "expression")
#View(som_mut_data_to_plot_long)
# Generate individual plots for each gene
plots <- lapply(unique(som_mut_data_to_plot_long$gene), function(g) {
ggplot(som_mut_data_to_plot_long %>% filter(gene == g), aes(x = group, y = expression, fill = group)) +
geom_boxplot() +
ggtitle(g) +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
})
# Arrange plots in a grid
grid.arrange(grobs = plots, ncol = 3)
#### **MORE Comparisons and Contrasts**
#COMPARISONS and CONTRASTS
# To get the changes for each comparison we need to define a contrast
Young_vs_Elderly_DESeq2 <- results(dds.filt.dea, contrast=c("group", "Young_healthy", "Elderly_healthy"))
Healthy_Yg_vs_MDS_DESeq2 <- results(dds.filt.dea, contrast=c("group", "Young_healthy", "MDS_Untreated"))
Healthy_El_vs_MDS_DESeq2 <- results(dds.filt.dea, contrast=c("group", "Elderly_healthy", "MDS_Untreated"))
#Healthy_yg_El_vs_MDS <- results(dds.filt.dea, contrast=c("group2", "Healthy", "MDS_Untreated")) #This comparison needs its own DEA model matrix. Its group is **dds.filt.dea$group2**
# Save in a list including the gene info
DEA_output <- list(Young_vs_Elderly=merge(data.frame(Young_vs_Elderly_DESeq2),gene_mapping_metadata_COMPLETE,by.x=0, by.y="Row.names"),
Healthy_Yg_vs_MDS=merge(data.frame(Healthy_Yg_vs_MDS_DESeq2),gene_mapping_metadata_COMPLETE,by.x=0, by.y="Row.names"),
Healthy_El_vs_MDS=merge(data.frame(Healthy_El_vs_MDS_DESeq2),gene_mapping_metadata_COMPLETE,by.x=0, by.y="Row.names"))
#colnames(gene_mapping_metadata_COMPLETE)
#View(Healthy_Yg_vs_MDS_DESeq2)
#****** It MERGED SUCCESSFULLY...
# TO BE REVISED
#****** PLAN B
#1-yOUNG healthy vs ELDERLY healthy
result_yg_vs_El_DF <- data.frame(Young_vs_Elderly_DESeq2)
Young_vs_Elderly_DESeq2_metadata <- gene_metadata_annotated[rownames(gene_metadata_annotated) %in% rownames(result_yg_vs_El_DF), c("SYMBOL", "GENENAME")]
Young_vs_Elderly_DESeq2_annotated <- cbind(result_yg_vs_El_DF, Young_vs_Elderly_DESeq2_metadata) #success
#head(Young_vs_Elderly_DESeq2_annotated[order(Young_vs_Elderly_DESeq2_annotated$log2FoldChange, decreasing = TRUE),]) #check
#2-yOUNG healthy vs MDS Untreated Patient
result_yg_vs_MDS_DF <- data.frame(Healthy_Yg_vs_MDS_DESeq2)
Healthy_Yg_vs_MDS_DESeq2_metadata <- gene_metadata_annotated[rownames(gene_metadata_annotated) %in% rownames(result_yg_vs_MDS_DF), c("SYMBOL", "GENENAME")]
Healthy_Yg_vs_MDS_DESeq2_annotated <- cbind(result_yg_vs_MDS_DF, Healthy_Yg_vs_MDS_DESeq2_metadata) #success
#3-ELDERLY healthy vs MDS Untreated Patient
result_El_vs_MDS_DF <- data.frame(Healthy_El_vs_MDS_DESeq2)
Healthy_El_vs_MDS_DESeq2_metadata <- gene_metadata_annotated[rownames(gene_metadata_annotated) %in% rownames(result_El_vs_MDS_DF), c("SYMBOL", "GENENAME")]
Healthy_El_vs_MDS_DESeq2_annotated <- cbind(result_El_vs_MDS_DF, Healthy_El_vs_MDS_DESeq2_metadata) #success
##**Visualizing contrasts**
# **Healthy: Young vs Elderly**
# *Top 5 Over and Underexpressed*
# Prepare a joint data frame with the data to plot
contrasts_to_plot <- data.frame(gene=rownames(Young_vs_Elderly_DESeq2_annotated),
log2FC_yg_vs_El=Young_vs_Elderly_DESeq2_annotated$log2FoldChange,
padj_yg_vs_El = Young_vs_Elderly_DESeq2_annotated$padj,
log2FC_yg_vs_MDS=Healthy_Yg_vs_MDS_DESeq2_annotated$log2FoldChange,
padj_yg_vs_MDS = Healthy_Yg_vs_MDS_DESeq2_annotated$padj,
log2FC_El_vs_MDS=Healthy_El_vs_MDS_DESeq2_annotated$log2FoldChange,
padj_El_vs_MDS = Healthy_El_vs_MDS_DESeq2_annotated$padj)
#*****young vs elderly PLOT
#Order this dataframe according to fold change
yg_vs_el_plot_ordFch <- contrasts_to_plot[,c("gene", "log2FC_yg_vs_El", "padj_yg_vs_El")]
#Order by Fc from Big to Small
yg_vs_el_plot_ordFch <- yg_vs_el_plot_ordFch[order(yg_vs_el_plot_ordFch$log2FC_yg_vs_El, decreasing = TRUE),]
#Putting these in the same plot (5 of each)
yg_el_five_ordFch <- rbind(yg_vs_el_plot_ordFch[1:5, ], tail(yg_vs_el_plot_ordFch, n=5) )
yg_el_five_ordFch <- yg_el_five_ordFch %>%
mutate(expression = ifelse(log2FC_yg_vs_El > 0, "UP", "DOWN"))
yg_el_five_ordFch$hgnc_symbol <- gene_mapping_metadata_COMPLETE[match(yg_el_five_ordFch$gene, gene_mapping_metadata_COMPLETE$Row.names), c("hgnc_symbol") ]
ggplot(data = yg_el_five_ordFch , mapping=aes(x=hgnc_symbol, y=log2FC_yg_vs_El, fill = expression)) +
ggtitle("Young vs Elderly: Top 5 Overexpressed & Underexpressed genes")+
geom_col()+
scale_fill_manual(values = c("UP" = "red", "DOWN" = "blue")) +
coord_flip() +
theme(axis.text.x = element_text(angle = 90,hjust=1))
#**Young Healthy vs MDS**
# Top 5 over expressed and top 5 Underexpressed.
# Here, we would like to retrieve 10 overexpressed genes and 10 Underexpressed genes between the Healthy donors and the Sick Untreated MDS patients.
# Therefore we would have to perform a contrast between the two populations.
#++++ Young HEALTHY VS MDS (PLOT) ++++#
#Order this dataframe according to fold change
#Order by Fc from Big to Small
yg_vs_MDS_plot_ordFch <- contrasts_to_plot[,c("gene", "log2FC_yg_vs_MDS")]
yg_vs_MDS_plot_ordFch <- yg_vs_MDS_plot_ordFch[order(yg_vs_MDS_plot_ordFch$log2FC_yg_vs_MDS, decreasing = TRUE),]
#Putting these in the same plot (5 of each)
yg_MDS_five_ordFch <- rbind(yg_vs_MDS_plot_ordFch[1:5, ], tail(yg_vs_MDS_plot_ordFch, n=5) )
yg_MDS_five_ordFch <- yg_MDS_five_ordFch %>%
mutate(expression = ifelse(log2FC_yg_vs_MDS > 0, "UP", "DOWN"))
yg_MDS_five_ordFch$hgnc_symbol <- gene_mapping_metadata_COMPLETE[match(yg_MDS_five_ordFch$gene, gene_mapping_metadata_COMPLETE$Row.names), c("hgnc_symbol") ]
ggplot(data = yg_MDS_five_ordFch , mapping=aes(x=hgnc_symbol, y=log2FC_yg_vs_MDS, fill = expression)) +
geom_col()+
scale_fill_manual(values = c("UP" = "red", "DOWN" = "blue")) +
coord_flip() +
ggtitle("Young vs MDS: Top 5 Overexpressed vs Underexpressed genes")+
theme(axis.text.x = element_text(angle = 90,hjust=1))
##**PATHWAY ANALYSIS** (GO: Gene Ontology)
# Now that differentially expressed genes have been identified, we will analyse enriched pathways in our data groups. This will help us make biological meaning of the actual changes happening in our data.
# There are three known methods for performing the pathway analysis namely; ORA , GSEA , GSVA. We will start with the **Over Representation Analysis (ORA)** method.
#### **ORA GO**
# **Young Vs Elderly** 1. Up REGULATED
# Over Representation Analysis (ORA)
# --------------------------------------------------------------------------
# Define the set of genes to test: Young vs Elderly --- up-regulated genes:
sig_UP_regulated_genes <- DEA_output$Young_vs_Elderly[DEA_output$Young_vs_Elderly$padj<0.05 & DEA_output$Young_vs_Elderly$log2FoldChange>0.58,]
#dim(sig_UP_regulated_genes)
# Define the ranked genes list based on logFCh.
sig_UP_regulated_genes <- sig_UP_regulated_genes[order(sig_UP_regulated_genes$log2FoldChange, decreasing = TRUE),]
head(sig_UP_regulated_genes)
# Keep the UP-regulated genes
up_regulated_genes <- sig_UP_regulated_genes$entrezgene_id
# Perform the ORA based on GO terms
# GO over-representation analysis
ora_go_up <- enrichGO(gene = up_regulated_genes,
universe = DEA_output$Young_vs_Elderly$entrezgene_id,
OrgDb = org.Hs.eg.db,
ont = "BP",
pAdjustMethod = "BH",
pvalueCutoff = 0.01,
qvalueCutoff = 0.05,
readable = TRUE)
#ora_go_up
#View(ora_go_up@result)
# Results visualization
layout(matrix(c(1, 2, 3), nrow = 1, ncol = 3, byrow = TRUE))
# Barplot
barplot(ora_go_up, showCategory=10, title ="GO_UP: Young vs Elderly")
# Network
cnetplot(ora_go_up, node_label="category",
cex.params = list(cex_label_category = 1.2))
cnetplot(ora_go_up, node_label="gene",
cex.params = list(cex_label_category = 1.2))
# 2. *Down REGULATED: Young vs Elderly*
# We are going to assess the up-regulated genes:
sig_DOWN_regulated_genes <- DEA_output$Young_vs_Elderly[DEA_output$Young_vs_Elderly$padj<0.05 & DEA_output$Young_vs_Elderly$log2FoldChange< -0.58,]
#dim(sig_DOWN_regulated_genes)
head(sig_DOWN_regulated_genes)
# Define the ranked genes list based on logFCh.
sig_DOWN_regulated_genes <- sig_DOWN_regulated_genes[order(sig_DOWN_regulated_genes$log2FoldChange, decreasing = TRUE),]
head(sig_DOWN_regulated_genes)
# Keep the UP-regulated genes
dw_regulated_genes <- sig_DOWN_regulated_genes$entrezgene_id
# Perform the ORA based on GO terms
# GO over-representation analysis
ora_go_dw <- enrichGO(gene = dw_regulated_genes,
universe = DEA_output$Young_vs_Elderly$entrezgene_id,
OrgDb = org.Hs.eg.db,
ont = "BP",
pAdjustMethod = "BH",
pvalueCutoff = 0.01,
qvalueCutoff = 0.05,
readable = TRUE)
#head(ora_go_dw@result)
# Results visualization
layout(matrix(c(1, 2, 3), nrow = 1, ncol = 3, byrow = TRUE))
# Barplot
barplot(ora_go_dw, showCategory=10, title ="GO_DOWN: Young vs Elderly")
# Network
cnetplot(ora_go_dw, node_label="category",
cex.params = list(cex_label_category = 1.2))
cnetplot(ora_go_dw, node_label="gene",
cex.params = list(cex_label_category = 1.2))
#**Young Healthy Vs Untreated MDS **
# 1. *ORA > Up REGULATED*
# Over Representation Analysis (ORA)
# --------------------------------------------------------------------------
# Define the set of genes to test: Young vs MDS _up-regulated genes:
sig_UP_regulated_ym_genes <- DEA_output$Healthy_Yg_vs_MDS[DEA_output$Healthy_Yg_vs_MDS$padj<0.05 & DEA_output$Healthy_Yg_vs_MDS$log2FoldChange>0.58,]
#dim(sig_UP_regulated_genes)
# Define the ranked genes list based on logFCh.
sig_UP_regulated_ym_genes <- sig_UP_regulated_ym_genes[order(sig_UP_regulated_ym_genes$log2FoldChange, decreasing = TRUE),]
head(sig_UP_regulated_ym_genes)
# Keep the UP-regulated genes
up_regulated_ym_genes <- sig_UP_regulated_ym_genes$entrezgene_id
# GO over-representation analysis
ora_go_up_ym <- enrichGO(gene = up_regulated_ym_genes,
universe = DEA_output$Healthy_Yg_vs_MDS$entrezgene_id,
OrgDb = org.Hs.eg.db,
ont = "BP",
pAdjustMethod = "BH",
pvalueCutoff = 0.01,
qvalueCutoff = 0.05,
readable = TRUE)
#ora_go_up_ym
#View(ora_go_up_ym@result)
# Results visualization
layout(matrix(c(1, 2, 3), nrow = 1, ncol = 3, byrow = TRUE))
# Barplot
barplot(ora_go_up_ym, showCategory=10, title ="GO_UP: Young vs MDS")
# Network
cnetplot(ora_go_up_ym, node_label="category",
cex.params = list(cex_label_category = 1.2))
cnetplot(ora_go_up_ym, node_label="gene",
cex.params = list(cex_label_category = 1.2))
##***** Elderly Healthy Vs Untreated MDS **
# *ORA > Up REGULATED*
# Over Representation Analysis (ORA)
# --------------------------------------------------------------------------
# Define the set of genes to test: Elderly vs MDS up-regulated genes
sig_UP_regulated_elm_genes <- DEA_output$Healthy_El_vs_MDS[DEA_output$Healthy_El_vs_MDS$padj<0.05 & DEA_output$Healthy_El_vs_MDS$log2FoldChange>0.58,]
#dim(sig_UP_regulated_genes)
# Define the ranked genes list based on logFCh.
sig_UP_regulated_elm_genes <- sig_UP_regulated_elm_genes[order(sig_UP_regulated_elm_genes$log2FoldChange, decreasing = TRUE),]
head(sig_UP_regulated_elm_genes, n=5)
# Keep the UP-regulated genes
up_regulated_elm_genes <- sig_UP_regulated_elm_genes$entrezgene_id