-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01_phenocluster.R
121 lines (102 loc) · 3.7 KB
/
01_phenocluster.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
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
#############################################################################
# Title: LN phenoclusters
# Function: Creating clusters from binary data
# Author: Murat Guler ([email protected], [email protected])
# Date: Jan 23th 2022
# Note: Please let me know if you have any trouble
#############################################################################
# Free R memory and remove prior environment
rm(list=ls())
gc()
#############################################################################
# Packages
# Install required packages, if not installed
install_if_missing <- function(package) {
if (!require(package, character.only = TRUE)) {
install.packages(package, dependencies = TRUE)
library(package, character.only = TRUE)
}
}
# List of packages to install and load
packages <- c("data.table", "colorspace", "dplyr", "dendextend", "gplots", "tidyverse")
# Install and load each package
for (package in packages) {
install_if_missing(package)
}
# Load required packages
library(data.table)
library(colorspace)
library(dplyr)
library(dendextend)
library(gplots)
library(tidyverse)
# Approved drugs data
# Upload data file
drug_data <- fread("SData2.txt", sep = "\t")
# Modify format of data
drug_data <- drug_data %>%
remove_rownames() %>%
column_to_rownames(var = 'Drug')
drug_data <- drug_data %>% mutate_if(is.numeric,as.logical)
# Create dendrogram
# Dendrogram for drugs
dend_r <- drug_data %>% dist(method = "binary") %>% hclust(method = "ward.D2") %>% as.dendrogram %>% ladderize
# Dendrogram for LNs
dend_c <- t(drug_data) %>% dist(method = "binary") %>% hclust(method = "ward.D2") %>% as.dendrogram %>% ladderize%>% color_branches(k=3)
# Plot heatmap
tiff("drug_plot.tiff", width = 8, height = 10, units = "in", res = 300)
gplots::heatmap.2(as.matrix(drug_data-1),
main = "Approved Drugs",
srtCol = 70,
Rowv = dend_r,
Colv = dend_c,
labRow= TRUE,
trace="none",
margins =c(6,3),
key.xlab = "no / yes",
ylab="Drugs",
xlab="LN Subtypes",
denscol = "grey",
scale="none",
density.info = "none",
key = FALSE,
symkey=FALSE,
adjRow =c(0,NA)
)
dev.off()
# Somatic mutation data
# Upload data file
somatic_data <- fread("SData1.txt", sep = "\t")
# Modify format of data
somatic_data <- somatic_data %>%
remove_rownames() %>%
column_to_rownames(var = 'Gene')
somatic_data <- somatic_data %>% mutate_if(is.numeric,as.logical)
# Create dendrogram
# Dendrogram for genes
dend_r <- somatic_data %>% dist(method = "binary") %>% hclust(method = "ward.D2") %>% as.dendrogram %>% ladderize
# Dendrogram for LNs
dend_c <- t(somatic_data) %>% dist(method = "binary") %>% hclust(method = "ward.D2") %>% as.dendrogram %>% ladderize%>% color_branches(k=3)
# Plot heatmap
tiff("somatic_plot.tiff", width = 8, height = 10, units = "in", res = 300)
gplots::heatmap.2(as.matrix(somatic_data-1),
main = "Somatic Mutations",
srtCol = 90,
Rowv = dend_r,
Colv = dend_c,
labRow= TRUE,
trace="none",
margins =c(9,3),
key.xlab = "no / yes",
ylab="Mutated Genes",
xlab="LN Subtypes",
denscol = "grey",
scale="none",
density.info = "none",
na.color = "White",
key = FALSE,
symkey=FALSE,
adjRow =c(0,NA)
)
dev.off()
#End (Line:117)