# R version 4.3.3 (2024-02-29 ucrt)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# Running under: Windows 10 x64 (build 19045)
# 
# Matrix products: default
# 
# 
# locale:
#   [1] LC_COLLATE=Arabic_World.utf8  LC_CTYPE=Arabic_World.utf8   
# [3] LC_MONETARY=Arabic_World.utf8 LC_NUMERIC=C                 
# [5] LC_TIME=Arabic_World.utf8 
# if (!require("BiocManager", quietly = TRUE))
#   install.packages("BiocManager")
# 
# BiocManager::install("ComplexHeatmap")

#install.packages("viridis")
#install.packages("hrbrthemes") 
library(readr)
library(ggfortify)
## Loading required package: ggplot2
library(rgl)
library("scatterplot3d") 
library(matrixStats)
library(devtools)
## Loading required package: usethis
library(ComplexHeatmap)
## Loading required package: grid
## ========================================
## ComplexHeatmap version 2.18.0
## Bioconductor page: http://bioconductor.org/packages/ComplexHeatmap/
## Github page: https://github.com/jokergoo/ComplexHeatmap
## Documentation: http://jokergoo.github.io/ComplexHeatmap-reference
## 
## If you use it in published research, please cite either one:
## - Gu, Z. Complex Heatmap Visualization. iMeta 2022.
## - Gu, Z. Complex heatmaps reveal patterns and correlations in multidimensional 
##     genomic data. Bioinformatics 2016.
## 
## 
## The new InteractiveComplexHeatmap package can directly export static 
## complex heatmaps into an interactive Shiny app with zero effort. Have a try!
## 
## This message can be suppressed by:
##   suppressPackageStartupMessages(library(ComplexHeatmap))
## ========================================
library(circlize)
## ========================================
## circlize version 0.4.16
## CRAN page: https://cran.r-project.org/package=circlize
## Github page: https://github.com/jokergoo/circlize
## Documentation: https://jokergoo.github.io/circlize_book/book/
## 
## If you use it in published research, please cite:
## Gu, Z. circlize implements and enhances circular visualization
##   in R. Bioinformatics 2014.
## 
## This message can be suppressed by:
##   suppressPackageStartupMessages(library(circlize))
## ========================================
library(cluster)
library(viridis)
## Loading required package: viridisLite
library(hrbrthemes)
library(ggplot2)
setwd("D:/bioinform/BCB/MODA")
data <- read.delim("D:/bioinform/BCB/MODA/Parkinson_exp.txt", row.names=1)
metadata <- read.delim("D:/bioinform/BCB/MODA/Parkinson_phenotable.txt", row.names=1)
summary (data)
##   C_F_69_1156      C_F_72_1152      C_F_74_1157      C_M_68_1151    
##  Min.   : 6.554   Min.   : 6.465   Min.   : 6.527   Min.   : 6.549  
##  1st Qu.: 6.953   1st Qu.: 6.966   1st Qu.: 6.940   1st Qu.: 6.966  
##  Median : 7.113   Median : 7.152   Median : 7.093   Median : 7.120  
##  Mean   : 7.236   Mean   : 7.256   Mean   : 7.225   Mean   : 7.245  
##  3rd Qu.: 7.328   3rd Qu.: 7.389   3rd Qu.: 7.305   3rd Qu.: 7.336  
##  Max.   :14.033   Max.   :14.012   Max.   :14.035   Max.   :14.004  
##   C_M_73_1020      C_M_75_1150      C_M_78_1147      C_M_79_1024    
##  Min.   : 6.528   Min.   : 6.557   Min.   : 6.558   Min.   : 6.564  
##  1st Qu.: 6.941   1st Qu.: 6.971   1st Qu.: 6.959   1st Qu.: 6.977  
##  Median : 7.088   Median : 7.135   Median : 7.106   Median : 7.122  
##  Mean   : 7.227   Mean   : 7.286   Mean   : 7.242   Mean   : 7.248  
##  3rd Qu.: 7.295   3rd Qu.: 7.388   3rd Qu.: 7.315   3rd Qu.: 7.333  
##  Max.   :14.013   Max.   :11.700   Max.   :13.504   Max.   :13.965  
##   C_M_89_1022      PD_F_81_1144     PD_F_81_1158     PD_F_84_1154   
##  Min.   : 6.544   Min.   : 6.550   Min.   : 6.590   Min.   : 6.598  
##  1st Qu.: 6.966   1st Qu.: 6.976   1st Qu.: 6.966   1st Qu.: 6.970  
##  Median : 7.119   Median : 7.141   Median : 7.130   Median : 7.121  
##  Mean   : 7.248   Mean   : 7.260   Mean   : 7.246   Mean   : 7.245  
##  3rd Qu.: 7.340   3rd Qu.: 7.374   3rd Qu.: 7.368   3rd Qu.: 7.338  
##  Max.   :13.946   Max.   :13.897   Max.   :14.062   Max.   :14.022  
##   PD_M_71_1155     PD_M_72_1146     PD_M_73_1148     PD_M_77_1143   
##  Min.   : 6.603   Min.   : 6.571   Min.   : 6.575   Min.   : 6.592  
##  1st Qu.: 6.976   1st Qu.: 6.960   1st Qu.: 6.970   1st Qu.: 6.978  
##  Median : 7.132   Median : 7.129   Median : 7.132   Median : 7.130  
##  Mean   : 7.267   Mean   : 7.245   Mean   : 7.249   Mean   : 7.258  
##  3rd Qu.: 7.360   3rd Qu.: 7.367   3rd Qu.: 7.353   3rd Qu.: 7.353  
##  Max.   :13.433   Max.   :14.064   Max.   :13.998   Max.   :13.767  
##   PD_M_77_1153     PD_M_79_1145     PD_M_83_1149   
##  Min.   : 6.566   Min.   : 6.601   Min.   : 6.583  
##  1st Qu.: 6.982   1st Qu.: 6.971   1st Qu.: 6.962  
##  Median : 7.135   Median : 7.128   Median : 7.133  
##  Mean   : 7.260   Mean   : 7.253   Mean   : 7.246  
##  3rd Qu.: 7.363   3rd Qu.: 7.350   3rd Qu.: 7.375  
##  Max.   :13.859   Max.   :13.965   Max.   :14.061
boxplot(data) #boxplot shows if there is an abnormal sample that should be excluded (i.e above or below the others) 
dat <- stack(as.data.frame(data[,1:dim(data)[2]])) #converting the columns into two columns (value and index) for plotting. 
#plotting the converted data in density plot. Density plot shows the general distribution of the data
ggplot(dat, aes(x=values, fill=ind)) + geom_density(alpha=0.3)

# base_size <- 11.5
# base_family = "Arial Narrow"
# subtitle_family = base_family
# theme_ipsum(
#   base_family = "Arial Narrow",
#   base_size = 11.5,
#   plot_title_family = base_family,
#   plot_title_size = 18,
#   plot_title_face = "bold",
#   plot_title_margin = 10,
#   subtitle_family = base_family,
#   subtitle_size = 12,
#   subtitle_face = "plain",
#   subtitle_margin = 15,
#   strip_text_family = base_family,
#   strip_text_size = 12,
#   strip_text_face = "plain",
#   caption_family = base_family,
#   caption_size = 9,
#   caption_face = "italic",
#   caption_margin = 10,
#   axis_text_size = base_size,
#   axis_title_family = subtitle_family,
#   axis_title_size = 9,
#   axis_title_face = "plain",
#   axis_title_just = "rt",
#   plot_margin = margin(30, 30, 30, 30),
#   grid_col = "#cccccc",
#   grid = TRUE,
#   axis_col = "#cccccc",
#   axis = FALSE,
#   ticks = FALSE
# )
# # Code coming from @drob: https://gist.github.com/dgrtwo/eb7750e74997891d7c20#file-geom_flat_violin-r
# "%||%" <- function(a, b) {
#   if (!is.null(a)) a else b
# }
# 
# geom_flat_violin <- function(mapping = NULL, data = NULL, stat = "ydensity",
#                         position = "dodge", trim = TRUE, scale = "area",
#                         show.legend = NA, inherit.aes = TRUE, ...) {
#   layer(
#     data = dat,
#     mapping = mapping,
#     stat = stat,
#     geom = GeomFlatViolin,
#     position = position,
#     show.legend = show.legend,
#     inherit.aes = inherit.aes,
#     params = list(
#       trim = trim,
#       scale = scale,
#       ...
#     )
#   )
# }
# 
# #' @rdname ggplot2-ggproto
# #' @format NULL
# #' @usage NULL
# #' @export
# GeomFlatViolin <-
#   ggproto("GeomFlatViolin", Geom,
#           setup_data = function(data, params) {
#             data$width <- data$width %||%
#               params$width %||% (resolution(data$x, FALSE) * 0.9)
# 
#             # ymin, ymax, xmin, and xmax define the bounding rectangle for each group
#             data %>%
#               group_by(group) %>%
#               mutate(ymin = min(y),
#                      ymax = max(y),
#                      xmin = x,
#                      xmax = x + width / 2)
# 
#           },
# 
#           draw_group = function(data, panel_scales, coord) {
#             # Find the points for the line to go all the way around
#             data <- transform(data, xminv = x,
#                               xmaxv = x + violinwidth * (xmax - x))
# 
#             # Make sure it's sorted properly to draw the outline
#             newdata <- rbind(plyr::arrange(transform(data, x = xminv), y),
#                              plyr::arrange(transform(data, x = xmaxv), -y))
# 
#             # Close the polygon: set first and last point the same
#             # Needed for coord_polar and such
#             newdata <- rbind(newdata, newdata[1,])
# 
#             ggplot2:::ggname("geom_flat_violin", GeomPolygon$draw_panel(newdata, panel_scales, coord))
#           },
# 
#           draw_key = draw_key_polygon,
# 
#           default_aes = aes(weight = 1, colour = "grey20", fill = "white", size = 0.5,
#                             alpha = NA, linetype = "solid"),
# 
#           required_aes = c("x", "y")
# )


# # Final plot inspired from @jbburant: https://gist.github.com/jbburant/b3bd4961f3f5b03aeb542ed33a8fe062
# data %>%
#   #sample_frac(0.4) %>%
#   ggplot(aes(x = ind, y = values, fill = values)) + 
#     geom_flat_violin(scale = "count", trim = FALSE, width=2) + 
#     scale_fill_viridis(discrete = TRUE) +
#     stat_summary(fun.data = mean_sdl, fun.args = list(mult = 1), geom = "pointrange", position = position_nudge(4.9)) + 
#     geom_dotplot(binaxis = "y", dotsize = 0.8, stackdir = "down", binwidth = 0.3, position = position_nudge(-0.025)) + 
#     theme_ipsum() +
#     theme(
#       legend.position = "none"
#     ) + 
#     ylab("value")
data.pca=prcomp(t(data),scale=T, cor=TRUE, scores=TRUE)
## Warning: In prcomp.default(t(data), scale = T, cor = TRUE, scores = TRUE) :
##  extra arguments 'cor', 'scores' will be disregarded
autoplot(data.pca, data = metadata, colour = 'sample.type',frame = F)

autoplot(data.pca, data = metadata, colour = 'sample.type',frame = T, frame.type="norm")

autoplot(data.pca, data = metadata, colour = 'gender',frame = F)

autoplot(data.pca, data = metadata, colour = 'sample.type',frame = F,shape="gender", label = TRUE, label.size = 2)

summary(data.pca)
## Importance of components:
##                            PC1     PC2     PC3      PC4      PC5      PC6
## Standard deviation     75.2909 61.7205 51.2346 43.19331 37.46963 31.53900
## Proportion of Variance  0.2544  0.1710  0.1178  0.08373  0.06301  0.04464
## Cumulative Proportion   0.2544  0.4254  0.5432  0.62688  0.68989  0.73453
##                             PC7      PC8      PC9    PC10     PC11     PC12
## Standard deviation     28.95386 25.52281 24.89589 23.3183 22.67543 21.53917
## Proportion of Variance  0.03762  0.02923  0.02782  0.0244  0.02307  0.02082
## Cumulative Proportion   0.77215  0.80138  0.82920  0.8536  0.87667  0.89749
##                            PC13    PC14     PC15     PC16    PC17     PC18
## Standard deviation     21.10347 20.4699 20.23369 19.29639 18.2830 17.42787
## Proportion of Variance  0.01999  0.0188  0.01837  0.01671  0.0150  0.01363
## Cumulative Proportion   0.91748  0.9363  0.95466  0.97137  0.9864  1.00000
##                             PC19
## Standard deviation     4.239e-13
## Proportion of Variance 0.000e+00
## Cumulative Proportion  1.000e+00
data.pca$x
##                     PC1          PC2        PC3         PC4          PC5
## C_F_69_1156   -75.60301   65.4525786   6.626959  -19.251293   16.7641294
## C_F_72_1152   -29.70676 -125.6147546 140.229593   18.748439   66.8317738
## C_F_74_1157   -39.60072  103.3914674  15.305508   -3.469030   31.5898507
## C_M_68_1151    41.97571   20.4779798 -10.746490   20.045924   18.7294434
## C_M_73_1020   -39.78672  131.1151617  34.062105  -10.792591   24.2655930
## C_M_75_1150   124.04257  -30.2992513   6.432806 -154.167137    0.4303546
## C_M_78_1147    62.10851   86.1120402  30.776401    9.341532   -2.1668798
## C_M_79_1024    52.57128  -10.4874854 -42.835953   51.365796  -12.2813567
## C_M_89_1022    58.45209   12.1090208 -12.955981   24.659891   14.3576900
## PD_F_81_1144   57.89452  -59.6690635 -21.984996    9.947777   30.2602050
## PD_F_81_1158 -117.13408  -45.3586267 -62.633500  -13.312952  -18.3831826
## PD_F_84_1154   33.10378    2.5984270 -33.388611   34.939744   -1.4010779
## PD_M_71_1155  -28.26782   -0.3621644  94.886828   -3.345118 -125.8648207
## PD_M_72_1146 -120.74156  -22.8274868 -49.127090  -30.561152    4.2194102
## PD_M_73_1148  -65.15931  -33.8366024  30.342498   29.457382  -10.6225824
## PD_M_77_1143   56.02363   -9.0566221 -19.259920   25.703535  -24.9298201
## PD_M_77_1153   84.14781  -47.6488852 -41.679882   21.269892  -18.7078687
## PD_M_79_1145   61.20012    7.6576831  -9.419044   14.064027    4.1886404
## PD_M_83_1149 -115.52004  -43.7534164 -54.631228  -24.644667    2.7204985
##                     PC6        PC7         PC8        PC9       PC10       PC11
## C_F_69_1156   11.275991  14.357228 -28.9569836  25.426501   5.203210  30.920648
## C_F_72_1152  -18.964608  17.249856 -10.3300356 -10.817400  -5.839618  -5.574849
## C_F_74_1157  -35.625940  23.480075  37.5453232   4.229006  30.557561 -44.654634
## C_M_68_1151   15.175489 -20.709962  28.7423745 -15.805913   1.498140  22.921077
## C_M_73_1020  -14.403079   3.552480 -12.8163298  30.796617 -22.939354  10.636700
## C_M_75_1150  -18.398802 -26.249104   1.1585762   5.550726   3.785788  -3.809884
## C_M_78_1147   37.145582 -14.967701 -35.1934678 -56.478684 -35.056579 -13.415294
## C_M_79_1024  -88.090160 -24.905385 -48.4165189  -9.528058  24.023000  16.053598
## C_M_89_1022    6.162941   2.315195  24.4708504 -26.181010  23.289298  -8.609989
## PD_F_81_1144  34.694558  19.964699   6.4456262   8.666935  20.567865  25.564918
## PD_F_81_1158 -10.537155  -9.908557  -0.3829595 -30.376013 -14.477635 -36.259340
## PD_F_84_1154 -22.909029 -14.410260  49.6229444   5.584899 -23.764512  23.409446
## PD_M_71_1155  -6.844159  22.955465  17.2117908  -7.818022  10.389795  16.501658
## PD_M_72_1146  15.689394  11.951830 -14.7827099 -12.594863   6.206323  18.538862
## PD_M_73_1148  24.950906 -89.250265   7.2240346  39.782232  -5.355376 -15.071586
## PD_M_77_1143  46.610129  12.398881 -31.8337006  29.185058  38.868302 -33.389519
## PD_M_77_1153 -13.907670  47.124363  -3.7566212  36.881758 -54.765528 -21.692175
## PD_M_79_1145  32.267689   8.877905   7.1601831  -8.666937   1.753731  10.286204
## PD_M_83_1149   5.707923  16.173258   6.8876235  -7.836832  -3.944411   7.644160
##                     PC12        PC13       PC14       PC15        PC16
## C_F_69_1156  -12.7561564   5.8975486 -20.580111  28.788264 -47.7806764
## C_F_72_1152   11.8905757  -1.0406967  -6.000162  10.239965   4.1191848
## C_F_74_1157  -10.8349181 -21.8356479   8.865740 -12.326571 -10.0832010
## C_M_68_1151   -5.7928179  35.7375437 -13.988448   7.543272  23.2152689
## C_M_73_1020   18.5945321  27.8883744  18.109273 -10.487225  32.9945241
## C_M_75_1150    3.2029534  -1.8123075  -3.107898   2.790906  -0.4572260
## C_M_78_1147    2.9471397 -19.8204990  -6.505372 -22.134823 -12.8551255
## C_M_79_1024   -6.4268076  -6.1162545   8.242624  -3.907687   2.9157409
## C_M_89_1022  -31.1964907  20.7972290 -32.921103   8.284762   3.8150701
## PD_F_81_1144   0.9551349  16.6257550  31.609245 -49.320030 -24.5297927
## PD_F_81_1158  18.3348895  42.4459390  22.557810  15.143248 -19.2242195
## PD_F_84_1154  50.6105504 -23.7806832 -17.044130   6.092894 -16.5739780
## PD_M_71_1155  -3.7879688   5.3366903   3.552004  -6.640781  -0.3719524
## PD_M_72_1146 -10.7338753 -17.4945976 -16.043028  -5.727409  26.4102447
## PD_M_73_1148 -24.8437832 -10.5628697   3.465478  -8.576397  -2.6512935
## PD_M_77_1143  42.0995045  -0.5366841 -17.987202   8.354000  12.6363485
## PD_M_77_1153 -30.7550068   2.7321555  -9.673932  -2.139208   1.7056945
## PD_M_79_1145 -12.3424281 -26.1594670  52.477841  48.891181  10.6668429
## PD_M_83_1149   0.8349726 -28.3015283  -5.028627 -14.868361  16.0485458
##                     PC17        PC18         PC19
## C_F_69_1156    8.2612665   5.2719559 4.646262e-13
## C_F_72_1152    0.9992159  -1.0787535 3.642529e-13
## C_F_74_1157   16.1975156 -12.3384387 4.145765e-13
## C_M_68_1151   50.1450606  -7.1050316 4.030527e-13
## C_M_73_1020  -21.4745068   9.4937487 4.282880e-13
## C_M_75_1150   -0.5034387   0.4094081 2.716707e-13
## C_M_78_1147    4.4646952  -0.2028761 3.097691e-13
## C_M_79_1024    4.1903415   2.4047843 1.329041e-13
## C_M_89_1022  -43.5636866  18.4735541 3.463894e-13
## PD_F_81_1144  -5.8211145  -3.9637117 4.095157e-13
## PD_F_81_1158  -3.1391344  -3.2753201 3.815529e-13
## PD_F_84_1154 -13.5024044  -7.9651164 3.615411e-13
## PD_M_71_1155   0.6287463  -0.4316228 4.113992e-13
## PD_M_72_1146 -14.6838948 -46.1579599 4.459723e-13
## PD_M_73_1148  -3.7808614  -0.2962268 4.052378e-13
## PD_M_77_1143   5.6648858   1.4488836 3.627655e-13
## PD_M_77_1153   6.6284064  -6.3736657 1.851748e-13
## PD_M_79_1145  -5.3172207   1.3594613 3.499144e-13
## PD_M_83_1149  14.6061285  50.3269275 5.220312e-13
mycolors= rep("lightgreen",dim(metadata)[1])
mycolors[which(metadata$sample.type=="PD")]="navy"
plot3d(data.pca$x[,1:3], pch=30 ,col=mycolors , size = 9)
snapshot3d()
## Warning in snapshot3d(): webshot = TRUE requires the webshot2 package and
## Chrome browser; using rgl.snapshot() instead
s3d <- scatterplot3d(data.pca$x[,1:3], pch=".",col.axis="blue", col.grid="lightblue")
s3d$points3d(data.pca$x[1:9,1:3], pch="o",col="lightgreen", cex=1)
s3d$points3d(data.pca$x[10:19,1:3], pch="o",col="navy", cex=1)

data.pca1 <- princomp(data,cor=T,scores = TRUE,)
names(data.pca1)
## [1] "sdev"     "loadings" "center"   "scale"    "n.obs"    "scores"   "call"
plot(data.pca1$loadings[,1],data.pca1$loadings[,2] )

View(data.pca1$loadings[,])
data=data.matrix(data, rownames.force = NA)
sds=rowSds(data)
data.sds=as.data.frame(cbind(data,sds))
data.sds.sorted=data.sds[order(data.sds$sds, decreasing = T),]
top100genes=rownames(data.sds.sorted)[1:100]
top100genes
##   [1] "204141_at TUBB2A"       "203282_at GBE1"         "200799_at NA"          
##   [4] "202581_at NA"           "200633_at UBB"          "202482_x_at RANBP1"    
##   [7] "200863_s_at RAB11A"     "209118_s_at TUBA1A"     "208609_s_at NA"        
##  [10] "208845_at VDAC3"        "207985_at NA"           "217963_s_at NGFRAP1"   
##  [13] "33767_at NEFH"          "208641_s_at RAC1"       "212971_at CARS"        
##  [16] "214925_s_at SPTAN1"     "211458_s_at NA"         "200655_s_at NA"        
##  [19] "201553_s_at LAMP1"      "209409_at GRB10"        "216333_x_at NA"        
##  [22] "200006_at PARK7"        "216290_x_at NA"         "201035_s_at HADH"      
##  [25] "218353_at RGS5"         "206093_x_at NA"         "203378_at PCF11"       
##  [28] "214290_s_at NA"         "200602_at APP"          "207198_s_at NA"        
##  [31] "203999_at SYT1"         "213451_x_at NA"         "210601_at CDH6"        
##  [34] "203933_at RAB11FIP3"    "214247_s_at DKK3"       "212098_at MGAT5"       
##  [37] "203057_s_at PRDM2"      "208503_s_at GATAD1"     "203182_s_at SRPK2"     
##  [40] "216038_x_at DAXX"       "201090_x_at TUBA1B"     "204038_s_at LPAR1"     
##  [43] "200607_s_at RAD21"      "214687_x_at ALDOA"      "201429_s_at RPL37A"    
##  [46] "203627_at IGF1R"        "213646_x_at TUBA1B"     "218332_at BEX1"        
##  [49] "214211_at FTH1"         "203485_at RTN1"         "206169_x_at ZC3H7B"    
##  [52] "200966_x_at ALDOA"      "201242_s_at ATP1B1"     "205192_at MAP3K14"     
##  [55] "211600_at PTPRO"        "209556_at NCDN"         "215131_at IQCK"        
##  [58] "202483_s_at RANBP1"     "205113_at NEFM"         "210794_s_at MEG3"      
##  [61] "221829_s_at TNPO1"      "217714_x_at NA"         "202967_at GSTA4"       
##  [64] "218566_s_at CHORDC1"    "210825_s_at PEBP1"      "221619_s_at MTCH1"     
##  [67] "217446_x_at NA"         "216955_at TAF1"         "209638_x_at RGS12"     
##  [70] "214629_x_at RTN4"       "205202_at PCMT1"        "211076_x_at ATN1"      
##  [73] "41220_at SEPT9"         "214023_x_at TUBB2B"     "202228_s_at NPTN"      
##  [76] "200021_at CFL1"         "209469_at GPM6A"        "200884_at CKB"         
##  [79] "222315_at LOC100996756" "205347_s_at NA"         "204106_at TESK1"       
##  [82] "205628_at PRIM2"        "202252_at RAB13"        "209167_at GPM6B"       
##  [85] "212987_at FBXO9"        "203277_at DFFA"         "210466_s_at SERBP1"    
##  [88] "203130_s_at KIF5C"      "200912_s_at NA"         "200603_at PRKAR1A"     
##  [91] "212639_x_at TUBA1B"     "211802_x_at CACNA1G"    "204515_at HSD3B1"      
##  [94] "206998_x_at PRB3"       "211774_s_at MMACHC"     "204743_at TAGLN3"      
##  [97] "205353_s_at PEBP1"      "201319_at MYL12A"       "207556_s_at DGKZ"      
## [100] "219657_s_at KLF3"
top.100=data[top100genes,]
part1=abs(top.100[1:10, ])
part2=abs(top.100[11:20, ])
part3=abs(top.100[21:30, ])
part4=abs(top.100[31:40, ])
part5=abs(top.100[41:50, ])
part6=abs(top.100[51:60, ])
part7=abs(top.100[61:70, ])
part8=abs(top.100[71:80, ])
part9=abs(top.100[81:90, ])
part10=abs(top.100[91:100, ])
col_fun = colorRamp2(c(min(top.100, na.rm=T), mean(top.100, na.rm=T), max(top.100, na.rm=T) ), c("blue", "white", "red"))
column_ha = HeatmapAnnotation(Sample.type= metadata$sample.type, Age = metadata$age, Sex= metadata$gender,annotation_name_gp = gpar(fontsize = 9, fontface = "bold"))
Heatmap(part1,name = "Part 1_top.100 genes", column_title = "samples", row_title = "genes", col=col_fun, cluster_rows = diana,cluster_columns = agnes,top_annotation = column_ha, row_names_gp = gpar(fontsize = 7), column_names_gp = gpar(fontsize = 7) )

Heatmap(part2,name = "Part 2_top.100 genes", column_title = "samples", row_title = "genes", col=col_fun , cluster_rows = diana,cluster_columns = agnes,top_annotation = column_ha, row_names_gp = gpar(fontsize = 7), column_names_gp = gpar(fontsize = 7))

Heatmap(part3,name = "Part 3_top.100 genes", column_title = "samples", row_title = "genes", col=col_fun, cluster_rows = diana,cluster_columns = agnes,top_annotation = column_ha, row_names_gp = gpar(fontsize = 7), column_names_gp = gpar(fontsize = 7))

Heatmap(part4,name = "Part 4_top.100 genes", column_title = "samples", row_title = "genes", col=col_fun, cluster_rows = diana,cluster_columns = agnes,top_annotation = column_ha, row_names_gp = gpar(fontsize = 7), column_names_gp = gpar(fontsize = 7))

Heatmap(part5,name = "Part 5_top.100 genes", column_title = "samples", row_title = "genes", col=col_fun, cluster_rows = diana,cluster_columns = agnes,top_annotation = column_ha, row_names_gp = gpar(fontsize = 7), column_names_gp = gpar(fontsize = 7))

Heatmap(part6,name = "Part 6_top.100 genes", column_title = "samples", row_title = "genes", col=col_fun, cluster_rows = diana,cluster_columns = agnes,top_annotation = column_ha, row_names_gp = gpar(fontsize = 7), column_names_gp = gpar(fontsize = 7))

Heatmap(part7,name = "Part 7_top.100 genes", column_title = "samples", row_title = "genes", col=col_fun, cluster_rows = diana,cluster_columns = agnes,top_annotation = column_ha, row_names_gp = gpar(fontsize = 7), column_names_gp = gpar(fontsize = 7))

Heatmap(part8,name = "Part 8_top.100 genes", column_title = "samples", row_title = "genes", col=col_fun, cluster_rows = diana,cluster_columns = agnes,top_annotation = column_ha, row_names_gp = gpar(fontsize = 7), column_names_gp = gpar(fontsize = 7))

Heatmap(part9,name = "Part 9_top.100 genes", column_title = "samples", row_title = "genes", col=col_fun, cluster_rows = diana,cluster_columns = agnes,top_annotation = column_ha, row_names_gp = gpar(fontsize = 7), column_names_gp = gpar(fontsize = 7))

Heatmap(part10,name = "Part 10_top.100 genes", column_title = "samples", row_title = "genes", col=col_fun, cluster_rows = diana,cluster_columns = agnes,top_annotation = column_ha, row_names_gp = gpar(fontsize = 7), column_names_gp = gpar(fontsize = 7))