Last active
May 18, 2022 17:02
-
-
Save mbk0asis/f3f9714a48654117df5491a6858b330c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#################################################################### | |
# Load a count data | |
countsTable <- read.csv("counts.csv",row.names=1, header=T) | |
head(countsTable) | |
dim(countsTable) | |
#################################################################### | |
# run DESeq2 | |
conds<- factor(c(rep("SETDB1_High",20),rep("SETDB1_Low",20))) | |
coldat=DataFrame(conds=factor(conds)) | |
dds <- DESeqDataSetFromMatrix(cnts_noZero, colData=coldat, design = ~ conds) | |
dds <- DESeq(dds, fitType = "mean") | |
#################################################################### | |
# plots for PCA results | |
rld <- rlogTransformation(dds,fitType = "mean") | |
# automatic 'pcaplot' function | |
#pcaplot(rld,intgroup=c("conds"),ntop=500, text_labels=F, title="PCA",pcX=1,pcY=2,point_size=3,ellipse=F) | |
# manual plotting | |
pca <- prcomp(t(assay(rld))) | |
percentVar <- pca$sdev^2/sum(pca$sdev^2) | |
df <- data.frame(PC1 = pca$x[, 1], PC2 = pca$x[, 2], group = conds, t(setdb1)) | |
colnames(df) <-c("PC1","PC2","conds","Setdb1") | |
tiff("PCAplot.tif",units = "px",width = 400, height = 300) | |
ggplot(data = df, aes_string(x = "PC1", y = "PC2", size="Setdb1", color="Setdb1")) + | |
geom_point(alpha=.8) + theme_bw() + | |
xlab(paste0("PC1: ", round(percentVar[1] * 100), "% variance")) + | |
ylab(paste0("PC2: ", round(percentVar[2] * 100), "% variance")) + | |
scale_colour_gradient2(midpoint=40,low="green",mid="grey60",high="red", space = "Lab", na.value = "grey50", guide = "colourbar") | |
dev.off() | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment