-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript_clustering_3_Different_clustering_methods.R
93 lines (60 loc) · 2.88 KB
/
script_clustering_3_Different_clustering_methods.R
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
###########################################################
# #
# Clustering.3: Trying out different clustering methods #
# #
###########################################################
library(tidyverse)
library(pheatmap)
library(viridis)
save_pheatmap_png = function(x, filepath, width = 600, height = 1000, res = 750){
png(filepath, width = width, height = height, res = res)
grid::grid.newpage()
grid::grid.draw(x$gtable)
dev.off()
}
annotation = read_rds("result_2019_08_16_clustering_row_annotation")
seven_aa_groups_separated_values = read_rds("result_2019_08_19_seven_aa_groups_separated_values")
seven_aa_groups_separated_values_scored = read_rds("result_2019_08_19_seven_aa_groups_separated_values_scored")
###
scored_dataset = seven_aa_groups_separated_values_scored
###
# https://www.r-bloggers.com/k-means-clustering-in-r/
set.seed(42)
my_kmeans_clustering = kmeans(x = seven_aa_groups_separated_values_scored,
centers = 4,
nstart = 20)
my_kmeans_clustering
# https://www.datanovia.com/en/lessons/k-means-clustering-in-r-algorith-and-practical-examples/
library(factoextra)
fviz_cluster()
classification_annotation_colors = list(
app_class = c(key = "#009900", # green
potency = "#0066ff", # blue
scaffold = "#8c8c8c", # grey
selectivity = "#ff6600"), # orange
Steffi_manual_class = c(key = "#009900", # green
potency = "#0066ff", # blue
scaffold = "#8c8c8c", # grey
selectivity = "#ff6600") # orange
)
my_heatmap = pheatmap(mat = scored_dataset,
cluster_rows = T,
cluster_cols = F,
clustering_distance_rows = "euclidean", # distance measure
clustering_method = "ward.D2", # agglomeration method of the hierarchical clustering (as in hclust)
annotation_row = annotation,
# cutree_rows = 4,
annotation_colors = classification_annotation_colors,
cellwidth = 10,
treeheight_row = 100,
show_rownames = F,
color = viridis(200),
angle_col = 45,
fontsize = 7,
kmeans_k = 4
)
save_pheatmap_png(x = my_heatmap,
filepath = "Z:/users_files/Verena Burger/11_PCA_and_Clustering/plots/M.png",
width = 700,
height = 1200,
res = 150)