-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
142 lines (142 loc) · 3.52 KB
/
.Rhistory
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
knitr::opts_chunk$set(message = FALSE, warning = FALSE)
options(warn = -1)
suppressPackageStartupMessages({
library(preprocessCore)
library(umap)
library(ggplot2)
library(multcomp)
library(gplots)
library(factoextra)
library(dplyr)
library(kableExtra)
library(gprofiler2)
library(randomForest)
library(caret)
library(cowplot)
library(RColorBrewer)
library(plotly)
})
knitr::opts_chunk$set(message = FALSE, warning = FALSE)
options(warn = -1)
suppressPackageStartupMessages({
library(preprocessCore)
library(umap)
library(ggplot2)
library(multcomp)
library(gplots)
library(factoextra)
library(dplyr)
library(kableExtra)
library(gprofiler2)
library(randomForest)
library(caret)
library(cowplot)
library(RColorBrewer)
library(plotly)
})
# Read file
data = read.delim(file = "Raw_common18704genes_antiTNF.tsv",
header = T,
row.names = 1,
sep = "\t")
knitr::opts_chunk$set(message = FALSE, warning = FALSE)
options(warn = -1)
suppressPackageStartupMessages({
library(preprocessCore)
library(umap)
library(ggplot2)
library(multcomp)
library(gplots)
library(factoextra)
library(dplyr)
library(kableExtra)
library(gprofiler2)
library(randomForest)
library(caret)
library(cowplot)
library(RColorBrewer)
library(plotly)
})
# Read file
data = read.delim(file = "Raw_common18704genes_antiTNF.tsv",
header = T,
row.names = 1,
sep = "\t")
#| label: fig-boxplot
#| fig-cap: "Boxplot of data before quantile normalization"
boxplot(data, horizontal = T, las = 1, cex.axis = 0.5)
# Show head of dataframe
kable(head(data)) |>
kable_styling(bootstrap_options = c("striped")) |>
scroll_box(width = "100%", height = "100%") |>
kable_classic()
# Check genes_data for missing values
colSums(is.na(data))
#| label: fig-distribution
#| fig-cap: "Data distribution before quantile normalization"
# Adjust the layout and margins
par(mfrow = c(8, 9), mar = c(1, 1, 2.5, 1))
for (col in colnames(data)) {
plot(density(data[[col]]),
main = col,
xlab = col, col = "#009AEF", lwd = 2)
}
data %>%
select_if(is.numeric) %>%
apply(2, function(x) round(summary(x), 3)) %>%
kbl() %>%
kable_styling(bootstrap_options = c("striped", "bordered")) %>%
kable_classic() %>%
scroll_box(width = "100%", height = "100%")
calculate_metrics = function(data.frame) {
max <- apply(data.frame, 2, max)
min <- apply(data.frame, 2, min)
mean <- (max + min) / 2
dt_matrix = data.frame(name = colnames(data.frame),
min = as.numeric(as.character(min)),
max = as.numeric(as.character(max)),
mean = as.numeric(as.character(mean)))
return(dt_matrix)
}
# Calculate metrics for each condition
c_metrics = calculate_metrics(data)
c_metrics
# Convert dataframe to matrix
data = as.matrix(data)
# Normalize data
data = normalize.quantiles(data , copy=TRUE)
# Convert matrix to dataframe
data = data.frame(data)
# Add column names to dataframe
colnames(data) = Sample
#| label: fig-boxplot
#| fig-cap: "Boxplot of data after quantile normalization"
boxplot(data, horizontal = T, las = 1, cex.axis = 0.5)
# Convert dataframe to matrix
data = as.matrix(data)
# Normalize data
data = normalize.quantiles(data , copy=TRUE)
# Convert matrix to dataframe
data = data.frame(data)
# Add column names to dataframe
colnames(data) = Sample
knitr::opts_chunk$set(message = FALSE, warning = FALSE)
options(warn = -1)
suppressPackageStartupMessages({
library(preprocessCore)
library(umap)
library(ggplot2)
library(multcomp)
library(gplots)
library(factoextra)
library(dplyr)
library(kableExtra)
library(gprofiler2)
library(randomForest)
library(caret)
library(cowplot)
library(RColorBrewer)
library(plotly)
})
# Get the cluster assignments
mt <- as.hclust(heatmap$rowDendrogram)