-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPCA
More file actions
35 lines (35 loc) · 1.92 KB
/
Copy pathPCA
File metadata and controls
35 lines (35 loc) · 1.92 KB
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
library(knitr)
library(DESeq2)
library(ggplot2)
library(magrittr)
folder <- "/media/goutham/B/Test/features"
setwd(folder)
folder <- "./"
options(stringsAsFactors = FALSE)
opts_chunk$set(echo = TRUE, message = FALSE,cache=FALSE)
readcounts <- read.table(paste0(folder, "featurecounts.txt"),
header=TRUE)
row.names(readcounts) <- gsub("-", ".", readcounts$Geneid)
readcounts <- readcounts[,-c(1:6)]
orig_names <- names(readcounts)
names(readcounts) <- c("C4_1", "C4_2", "C4_3", "C8_1", "C8_2", "C8_3", "C16_1", "C16_2", "C16_3", "Fs4_1", "Fs4_2", "Fs4_3", "Fs8_1", "Fs8_2", "Fs8_3", "Fs16_1", "Fs16_2", "Fs16_3")
pca <- prcomp(t(readcounts))
pca_results <- pca$x
pca_variance <- pca$sdev^2
pca_proportion <- pca_variance / sum(pca_variance)
plot(pca_results[, 1], pca_results[, 2], type = "n", xlab = "PC1", ylab = "PC2", ylim = c(-10, 10))
c4_colors <- c("purple", "purple", "purple") # Colors for C4_1-3
c8_colors <- c("blue", "blue", "blue") # Colors for C8_1-3
c16_colors <- c("green", "green", "green") # Colors for C16_1-3
Fs4_colors <- c("yellow", "yellow", "yellow") # Colors for Fs4_1-3
Fs8_colors <- c("orange", "orange", "orange") # Colors for Fs8_1-3
Fs16_colors <- c("red", "red", "red") # Colors for Fs16_1-3
points(pca_results[1:3, 1], pca_results[1:3, 2], pch = 16, col = c4_colors)
points(pca_results[4:6, 1], pca_results[4:6, 2], pch = 16, col = c8_colors)
points(pca_results[7:9, 1], pca_results[7:9, 2], pch = 16, col = c16_colors)
points(pca_results[10:12, 1], pca_results[10:12, 2], pch = 16, col = Fs4_colors)
points(pca_results[13:15, 1], pca_results[13:15, 2], pch = 16, col = Fs8_colors)
points(pca_results[16:18, 1], pca_results[16:18, 2], pch = 16, col = Fs16_colors)
legend_colors <- c(c4_colors, c8_colors, c16_colors, Fs4_colors, Fs8_colors, Fs16_colors)
legend_labels <- c("C4", "C8", "C16", "Fs4", "Fs8", "Fs16", sample_info$condition[7:18])
legend("bottomright", legend = legend_labels, col = legend_colors, pch = 16, bty = "n")