2022-09-30 14:30:49 -05:00

513 lines
16 KiB
R

plot(mddTree)
d
sort(d)
d
mddCorr
max(mddCorr)
min(mddCorr)
d
max(d)
mddCorr[0.3660906]
avg(d)
average(d)
mean(d)
which(d>mean(d))
d[8]
which(d>2*mean(d))
which(d>3*mean(d))
quartile(d)
quantile(d)
quantile(d)[3]
quantile(d)[4]
which(d>1.5*quantile(d)[4])
which(d>1.5*quantile(d)[1])
quanitle(d)
quantile(d)
quantile(d)[1]
quantile(d)[2]
which(d<1.5*quantile(d)[2])
summary(d)
max(d)
min(d)
hist(d)
boxplot(d)
hist(d)
geom_vline(xintercept=quantile, color="red", linetype="dashed", size=1)
geom_vline(xintercept=quantile, color="red", linetype="dashed", size=1)
ApproxQuantile(d)
ApproxMean(d)
quantile(d)
max(d)
which(d=09.3660906)
which(d=0.3660906)
which(d, d=0.3660906)
which(d=0)
which(d d=0)
d[0]
d[1]
max(d)
which(max(d))
plot(mddTree)
d(AA365)
mddCorr
mddTree[AA365]
mddTree
mddTree$labels
mddTree$AA365
mddTree[AA365]
mddTree
mddTree$height
d2 <- d<0.35
d2
d2 <- which(d<0.35)
d2
d2 <- d[<0.35]
d2 <- d[d<0.35]
d2
d2 <- d[d<0.35]
rownames(d2)
mddTree2 = hclust(as.dist(d2))
mddTree2$labels <- phenos.df$X
if (!require("umap")) install.packages("umap")
obs_mds = cmdscale(d, k=2)
#add colors for MDD/HC
colors = rep("black",nrow(SxG.df))
#add colors for MDD/HC
colors = rep("black",nrow(GxS.df))
#### Optional 2: Compare MDS and UMAP clustering
obs_mds = cmdscale(d, k=2)
#add colors for MDD/HC
colors = rep("black",nrow(GxS.covfilter))
colors[startsWith(rownames(GxS.covfilter),"MDD")] <- "red"
plot(obs_mds, col=colors,
main="mds of observations", xlab="mds dim1", ylab="mds dim2")
if (!require("umap")) install.packages("umap")
library(umap)
SxG.df <- data.frame(t(GxS.covfilter))
# change umap config parameters
custom.config = umap.defaults
custom.config$random_state = 123
custom.config$n_epochs = 500
obs_umap = umap(SxG.df, config=custom.config)
#add colors for MDD/HC
colors = rep("black",nrow(top_gene_data))
#add colors for MDD/HC
colors = rep("black",nrow(top_genes))
nrow(top_genes)
top_genes <- as.character(ttest_allgene.sorted[1:top_cutoff,1])
nrow(top_genes)
top_genes
ncol(top_genes)
numrow
count(top_genes)
length(top_genes)
#add colors for MDD/HC
colors = rep("black",length(top_genes))
rownames(top_genes)
colors[startsWith(top_genes,"MDD")] <- "red"
plot(obs_umap$layout, col=colors,
main="umap of observations", xlab="umap dim1", ylab="umap dim2")
colors
top_genes
top_genes$labels
top_genes
#### Optional 2: Compare MDS and UMAP clustering
if (!require("umap")) install.packages("umap")
library(umap)
# change umap config parameters
custom.config = umap.defaults
custom.config$random_state = 123
custom.config$n_epochs = 500
SxG.df <- data.frame(t(GxS.covfilter))
obs_mds = cmdscale(d, k=2)
#add colors for MDD/HC
colors = rep("black",nrow(SxG.df))
colors[startsWith(rownames(SxG.df),"MDD")] <- "red"
plot(obs_mds, col=colors,
main="mds of observations", xlab="mds dim1", ylab="mds dim2")
obs_umap = umap(SxG.df, config=custom.config)
#add colors for MDD/HC
colors = rep("black",nrow(top_gene_data))
obs_umap = umap(SxG.df, config=custom.config)
#add colors for MDD/HC
colors = rep("black",nrow(SxG.df))
colors[startsWith(rownames(SxG.df),"MDD")] <- "red"
plot(obs_umap$layout, col=colors,
main="umap of observations", xlab="umap dim1", ylab="umap dim2")
#### Optional 3: WGCNA and UMAP of Genes
if (!require("BiocManager")) install.packages("BiocManager")
library(BiocManager)
if (!require("WGCNA")) BiocManager::install("WGCNA")
library(WGCNA)
obs_mds = cmdscale(d, k=2)
#add colors for MDD/HC
colors = rep("black",nrow(GxS.covfilter))
colors[startsWith(rownames(GxS.covfilter),"MDD")] <- "red"
plot(obs_mds, col=colors,
main="mds of subject observations", xlab="mds dim1", ylab="mds dim2")
nrow(SxG.dgf)
nrow(SxG.df)
#add colors for MDD/HC
colors = rep("black",nrow(data.frame(GxS.covfilter)))
colors[startsWith(rownames(data.frame(GxS.covfilter)),"MDD")] <- "red"
plot(obs_mds, col=colors,
main="mds of subject observations", xlab="mds dim1", ylab="mds dim2")
colors
GxS.df <- data.frame(GxS.covfilter)
GxS.df
#add colors for MDD/HC
colors = rep("black",nrow(GxS.df))
colors
colors[startsWith(GxS.df),"MDD")] <- "red"
colors[startsWith(rownames(GxS.df),"MDD")] <- "red"
colors
rownames(GxS.df)
rownames(SxG.df)
colors[startsWith(colnames(GxS.df),"MDD")] <- "red"
colors
obs_mds = cmdscale(d, k=1)
#add colors for MDD/HC
colors = rep("black",nrow(GxS.df))
colors[startsWith(colnames(GxS.df),"MDD")] <- "red"
plot(obs_mds, col=colors,
main="mds of subject observations", xlab="mds dim1", ylab="mds dim2")
obs_umap = umap(GxS.df, config=custom.config)
?umap
# Plot the dendrogram and colors underneath
sizeGrWindow(8,6)
dynamicMods = cutreeDynamic(dendro = mddTree, distM = d,
deepSplit = 2, pamRespectsDendro = FALSE,
minClusterSize = 2)
mddColors = labels2colors(dynamicMods)
table(mddColors)
mddColorstable <- table(mddColors,names(mddCuts))
# Plot the dendrogram and colors underneath
mddCuts <- cutree(mddTree,k=num.clust)
sizeGrWindow(8,6)
dynamicMods = cutreeDynamic(dendro = mddTree, distM = d,
deepSplit = 2, pamRespectsDendro = FALSE,
minClusterSize = 2)
mddColors = labels2colors(dynamicMods)
table(mddColors)
mddColorstable <- table(mddColors,names(mddCuts))
# Plot the dendrogram and colors underneath
mddCuts <- cutree(mddTree,k=num.clust)
# Plot the dendrogram and colors underneath
num.clust <- 5
mddCuts <- cutree(mddTree,k=num.clust)
sizeGrWindow(8,6)
dynamicMods = cutreeDynamic(dendro = mddTree, distM = d,
deepSplit = 2, pamRespectsDendro = FALSE,
minClusterSize = 2)
mddColors = labels2colors(dynamicMods)
table(mddColors)
mddColorstable <- table(mddColors,names(mddCuts))
prop.table(mddColorstable, margin = 1)
plotDendroAndColors(mddTree, mddColors, "Dynamic Clusters",
dendroLabels = NULL, # hang = -1,
addGuide = TRUE, #guideHang = 0.05,
main = "Clustering with WGCNA")
names(dynamicMods)
# Plot the dendrogram and colors underneath
num.clust <- 2
mddCuts <- cutree(mddTree,k=num.clust)
sizeGrWindow(8,6)
dynamicMods = cutreeDynamic(dendro = mddTree, distM = d,
deepSplit = 2, pamRespectsDendro = FALSE,
minClusterSize = 2)
mddColors = labels2colors(dynamicMods)
table(mddColors)
mddColorstable <- table(mddColors,names(mddCuts))
prop.table(mddColorstable, margin = 1)
plotDendroAndColors(mddTree, mddColors, "Dynamic Clusters",
dendroLabels = NULL, # hang = -1,
addGuide = TRUE, #guideHang = 0.05,
main = "Clustering with WGCNA")
custom.config
custom.config$random_state = 123
custom.config$n_epochs = 100
custom.config$n_neighbors=50
GxS.df <- data.frame(GxS.covfilter)
obs_umap = umap(GxS.df, config=custom.config)
custom.config$n_epochs = 15
custom.config$n_neighbors=10
GxS.df <- data.frame(GxS.covfilter)
obs_umap = umap(GxS.df, config=custom.config)
#add colors for MDD/HC
colors = rep("black",nrow(GxS.df))
colors[startsWith(colnames(GxS.df),"MDD")] <- "red"
plot(obs_umap$layout, col=colors,
main="umap of subject observations", xlab="umap dim1", ylab="umap dim2")
custom.config$n_neighbors=15
plot(obs_umap$layout, col=colors,
main="umap of subject observations", xlab="umap dim1", ylab="umap dim2")
custom.config$random_state = 123
custom.config$n_epochs = 15
custom.config$n_neighbors=15
GxS.df <- data.frame(GxS.covfilter)
obs_umap = umap(GxS.df, config=custom.config)
#add colors for MDD/HC
colors = rep("black",nrow(GxS.df))
colors[startsWith(colnames(GxS.df),"MDD")] <- "red"
plot(obs_umap$layout, col=colors,
main="umap of subject observations", xlab="umap dim1", ylab="umap dim2")
plot(obs_umap$layout, col=colors,
main="umap of subject observations", xlab="umap dim1", ylab="umap dim2")
# change umap config parameters
custom.config = umap.defaults
custom.config$random_state = 123
custom.config$n_epochs = 15
custom.config$n_neighbors=15
GxS.df <- data.frame(GxS.covfilter)
obs_umap = umap(GxS.df, config=custom.config)
#add colors for MDD/HC
colors = rep("black",nrow(GxS.df))
colors[startsWith(colnames(GxS.df),"MDD")] <- "red"
plot(obs_umap$layout, col=colors,
main="umap of subject observations", xlab="umap dim1", ylab="umap dim2")
custom.config$n_neighbors=30
obs_umap = umap(GxS.df, config=custom.config)
plot(obs_umap$layout, col=colors,
main="umap of subject observations", xlab="umap dim1", ylab="umap dim2")
plot(obs_umap$layout, col=colors,
main="umap of subject observations", xlab="umap dim1", ylab="umap dim2")
custom.config$n_epochs = 50
custom.config$n_neighbors=30
obs_umap = umap(GxS.df, config=custom.config)
plot(obs_umap$layout, col=colors,
main="umap of subject observations", xlab="umap dim1", ylab="umap dim2")
mddCuts
dynamicMods
dynamicMods = cutreeDynamic(dendro = mddTree, distM = d,
deepSplit = 2, pamRespectsDendro = FALSE,
minClusterSize = 2, maxClusterSize = 2)
mddCuts
mddTree
?cutree
?cutreeDynamic
dynamicMods = cutreeDynamic(dendro = mddTree, distM = d,
deepSplit = 2, pamRespectsDendro = FALSE,
minClusterSize = 2, method = "hybrid")
mddColors = labels2colors(dynamicMods)
table(mddColors)
mddColorstable <- table(mddColors,names(mddCuts))
prop.table(mddColorstable, margin = 1)
plotDendroAndColors(mddTree, mddColors, "Dynamic Clusters",
dendroLabels = NULL, # hang = -1,
addGuide = TRUE, #guideHang = 0.05,
main = "Clustering with WGCNA")
mnist_labels = colnames(GxS.df)
mnist_labels
mnist_labels = c("MDD", "HC")
mnist_labels
umap_dat <- umap(GxS.df)
plot(umap_dat)
obs_umap = umap(SxG.df, config=custom.config)
#add colors for MDD/HC
colors = rep("black",nrow(SxG.df))
colors[startsWith(rownames(SxG.df),"MDD")] <- "red"
plot(obs_umap$layout, col=colors,
main="umap of observations", xlab="umap dim1", ylab="umap dim2")
obs_umap = umap(GxS.df, config=custom.config)
#add colors for MDD/HC
colors = rep("black",nrow(SxG.df))
colors[startsWith(rownames(SxG.df),"MDD")] <- "red"
plot(obs_umap$layout, col=colors,
main="umap of observations", xlab="umap dim1", ylab="umap dim2")
# Plot the dendrogram and colors underneath
num.clust <- 2
plot(obs_umap$layout, col=colors,
main="umap of observations", xlab="umap dim1", ylab="umap dim2")
GxS.df
rownames(GxS.df)
colnames(GxS.df)
rownames(GxS.df)
#add colors for MDD/HC
colors = rep("black",nrow(GxS.df))
colors[startsWith(colnames(GxS.df),"MDD")] <- "red"
plot(obs_umap$layout, col=colors,
main="umap of observations", xlab="umap dim1", ylab="umap dim2")
#add colors for MDD/HC
colors = rep("black",ncol(GxS.df))
colors[startsWith(colnames(GxS.df),"MDD")] <- "red"
plot(obs_umap$layout, col=colors,
main="umap of observations", xlab="umap dim1", ylab="umap dim2")
?umap
custom.config
custom.config$random_state = 123
custom.config$n_epochs = 50
custom.config$n_neighbors=30
custom.config$min_dist = 0.001
GxS.df <- data.frame(GxS.covfilter)
obs_umap = umap(GxS.df, config=custom.config)
#add colors for MDD/HC
colors = rep("black",nrow(GxS.df))
colors[startsWith(colnames(GxS.df),"MDD")] <- "red"
plot(obs_umap$layout, col=colors,
main="umap of observations", xlab="umap dim1", ylab="umap dim2")
obs_umap
obs_umap$layout
obs_umap
obs_umap$knn
obs_umap$data
custom.config$random_state = 123
custom.config$n_epochs = 50
custom.config$n_neighbors=30
custom.config$min_dist = 0.5
custom.config$metric = "sl_dist"
GxS.df <- data.frame(GxS.covfilter)
obs_umap = umap(GxS.df, config=custom.config)
custom.config$metric = 'sl_dist'
obs_umap = umap(GxS.df, config=custom.config)
custom.config$metric = 'correlation'
obs_umap = umap(GxS.df, config=custom.config)
custom.config$metric = "correlation"
obs_umap = umap(GxS.df, config=custom.config)
custom.config
f
obs_umap = umap(GxS.df, config=custom.config)
# change umap config parameters
custom.config = umap.defaults
custom.config$random_state = 123
custom.config$n_epochs = 50
custom.config$n_neighbors=30
custom.config$min_dist = 0.5
obs_umap = umap(GxS.df, config=custom.config, metric=correlation)
obs_umap = umap(GxS.df, config=custom.config, metric="correlation")
?umap
umap.defaults
custom.config$metric = "correlation"
obs_umap = umap(GxS.df, config=custom.config)
custom.config$metric = "manhattan"
obs_umap = umap(GxS.df, config=custom.config)
#add colors for MDD/HC
colors = rep("black",nrow(GxS.df))
colors[startsWith(colnames(GxS.df),"MDD")] <- "red"
plot(obs_umap$layout, col=colors,
main="umap of observations", xlab="umap dim1", ylab="umap dim2")
custom.config$metric = "chebyshev"
obs_umap = umap(GxS.df, config=custom.config)
custom.config$metric = "hamming"
GxS.df <- data.frame(GxS.covfilter)
obs_umap = umap(GxS.df, config=custom.config)
custom.config$metric = "minkowski"
GxS.df <- data.frame(GxS.covfilter)
obs_umap = umap(GxS.df, config=custom.config)
custom.config$metric = "canberra"
obs_umap = umap(GxS.df, config=custom.config)
config
custom.config$metric
?umap.defaults
custom.config$metric = "pearson"
GxS.df <- data.frame(GxS.covfilter)
obs_umap = umap(GxS.df, config=custom.config)
plot(obs_umap$layout, col=colors,
main="umap of observations", xlab="umap dim1", ylab="umap dim2")
custom.config$min_dist = 0.2
custom.config$metric = "pearson"
GxS.df <- data.frame(GxS.covfilter)
obs_umap = umap(GxS.df, config=custom.config)
plot(obs_umap$layout, col=colors,
main="umap of observations", xlab="umap dim1", ylab="umap dim2")
custom.config
custom.config$input = "dist"
GxS.df <- data.frame(GxS.covfilter)
obs_umap = umap(GxS.df, config=custom.config)
plot(obs_umap$layout, col=colors,
main="umap of observations", xlab="umap dim1", ylab="umap dim2")
custom.config$min_dist = 0.5
obs_umap = umap(GxS.df, config=custom.config)
plot(obs_umap$layout, col=colors,
main="umap of observations", xlab="umap dim1", ylab="umap dim2")
custom.config$alpha = 0.75
custom.config$gamma = 0.5
GxS.df <- data.frame(GxS.covfilter)
obs_umap = umap(GxS.df, config=custom.config)
plot(obs_umap$layout, col=colors,
main="umap of observations", xlab="umap dim1", ylab="umap dim2")
custom.config$spread = 5
custom.config$verbose = "integer"
obs_umap = umap(GxS.df, config=custom.config)
custom.config$verbose = integer
obs_umap = umap(GxS.df, config=custom.config)
custom.config$verbose = "logical"
obs_umap = umap(GxS.df, config=custom.config)
custom.config$verbose
obs_umap = umap(GxS.df, config=custom.config)
# change umap config parameters
custom.config = umap.defaults
custom.config$random_state = 123
custom.config$n_epochs = 50
custom.config$n_neighbors=30
custom.config$min_dist = 0.5
custom.config$metric = "pearson"
custom.config$input = "dist"
custom.config$alpha = 0.75
custom.config$gamma = 0.5
custom.config$spread = 5
GxS.df <- data.frame(GxS.covfilter)
obs_umap = umap(GxS.df, config=custom.config)
plot(obs_umap$layout, col=colors,
main="umap of observations", xlab="umap dim1", ylab="umap dim2")
custom.config$spread = 0.25
custom.config$a = 1
custom.config$b = 1
# change umap config parameters
custom.config = umap.defaults
custom.config$random_state = 123
custom.config$n_epochs = 50
custom.config$n_neighbors=30
custom.config$metric = "pearson"
custom.config$input = "dist"
custom.config$a = 1
custom.config$b = 1
GxS.df <- data.frame(GxS.covfilter)
obs_umap = umap(GxS.df, config=custom.config)
plot(obs_umap$layout, col=colors,
main="umap of observations", xlab="umap dim1", ylab="umap dim2")
custom.config$a = 1.5
obs_umap = umap(GxS.df, config=custom.config)
plot(obs_umap$layout, col=colors,
main="umap of observations", xlab="umap dim1", ylab="umap dim2")
custom.config$a = 0.5
obs_umap = umap(GxS.df, config=custom.config)
plot(obs_umap$layout, col=colors,
main="umap of observations", xlab="umap dim1", ylab="umap dim2")
custom.config$a = 1.5
custom.config$b = 1.2
obs_umap = umap(GxS.df, config=custom.config)
plot(obs_umap$layout, col=colors,
main="umap of observations", xlab="umap dim1", ylab="umap dim2")
custom.config$b = 0.8
obs_umap = umap(GxS.df, config=custom.config)
plot(obs_umap$layout, col=colors,
main="umap of observations", xlab="umap dim1", ylab="umap dim2")
custom.config$b = 1.3
obs_umap = umap(GxS.df, config=custom.config)
plot(obs_umap$layout, col=colors,
main="umap of observations", xlab="umap dim1", ylab="umap dim2")
custom.config$b = 1.5
obs_umap = umap(GxS.df, config=custom.config)
plot(obs_umap$layout, col=colors,
main="umap of observations", xlab="umap dim1", ylab="umap dim2")
custom.config$a = 2.5
custom.config$b = 1.5
obs_umap = umap(GxS.df, config=custom.config)
plot(obs_umap$layout, col=colors,
main="umap of observations", xlab="umap dim1", ylab="umap dim2")
custom.config$a = 7.5
custom.config$b = 1.5
obs_umap = umap(GxS.df, config=custom.config)
plot(obs_umap$layout, col=colors,
main="umap of observations", xlab="umap dim1", ylab="umap dim2")
custom.config$a = 9.0
custom.config$b = 1.5
obs_umap = umap(GxS.df, config=custom.config)
plot(obs_umap$layout, col=colors,
main="umap of observations", xlab="umap dim1", ylab="umap dim2")
custom.config$a = 9.5
custom.config$b = 0.5
obs_umap = umap(GxS.df, config=custom.config)
plot(obs_umap$layout, col=colors,
main="umap of observations", xlab="umap dim1", ylab="umap dim2")