diff --git a/Schrick-Noah_CS-6643_Lab-2.R b/Schrick-Noah_CS-6643_Lab-2.R index bbac39c..0b189ba 100644 --- a/Schrick-Noah_CS-6643_Lab-2.R +++ b/Schrick-Noah_CS-6643_Lab-2.R @@ -38,8 +38,10 @@ my.dist1 <- read.table("distance_matrix.txt",sep="\t", header=T) rownames(my.dist1) = colnames(my.dist1) my.dist1[lower.tri(my.dist1)] = t(my.dist1)[lower.tri(my.dist1)] hc1 <- hclust(as.dist(my.dist1), method="average") +hc1 plot(hc1,hang=-1) + ## 2 - Paste the distance matrix in the report. Use header=T ## 3 - no supporting code @@ -48,6 +50,7 @@ plot(hc1,hang=-1) # Install if (!require("BiocManager")) install.packages("BiocManager") library(BiocManager) +if (!require("WGCNA")) BiocManager::install("WGCNA") # load WGCNA and run on the hc1 dendrogram @@ -61,7 +64,9 @@ dynamicMods = cutreeDynamic( minClusterSize = 2) names(dynamicMods) <- colnames(my.dist1) -## 5 - no supporting code +## 5 - identify clusters +dynamicMods + ## 6 - show clustered data dynamicColors = labels2colors(dynamicMods) # colors might not work @@ -91,18 +96,17 @@ a <- list() # each merged pair in a row a$merge <- rbind(c(-1, -2), # +1 (A-B) - c(1,-3) , # +2 (A-B)-C - _______ , # +3 (D-E) - _______ , # +4 ((A-B)-C)-(DE) - _______) # +5 (((A-B)-C)-(DE))-F + c(1, -4), # +2 (A-B)-D + c(2, -3)) # +3 ((A-B)-D)-C + -a$height <- c(1, 2, 1.5, 3, 4) # merge heights -a$order <- 1:6 # order of leaves -a$labels <- LETTERS[1:6] # labels of leaves as Letters +a$height <- c(0.14, 0.305, 0.51) # merge heights +a$order <- 1:4 # order of leaves +a$labels <- LETTERS[1:4] # labels of leaves as Letters class(a) <- "hclust" # force a to be hclust object # plot the tree # plot knows that a is an hclust object and plots accordingly -plot(a,hang=-1) # or use plot(as.dendrogram(a)) +plot(a) # or use plot(as.dendrogram(a)) ## 4 - Verify results @@ -121,7 +125,7 @@ test$merge test$height test$order test$labels<-LETTERS[1:4] -plot(test,hang=-1) +plot(test) #### Part D - MDS ## 1 - Show the 2D MDS @@ -134,4 +138,4 @@ plot(x,y,main="Multi-dimensional Scaling", xlab="MDS dimension-1", ylab="MDS dimension-2", pch=NA,asp=1) # pch specifies plot symbol; we want null because we are using letter next # plot the text labels instead of symbols: -text(x,y,test$labels,cex=1) \ No newline at end of file +text(x,y,test$labels,cex=1)