Skip to content

Instantly share code, notes, and snippets.

@mbk0asis
Last active September 7, 2016 00:30
Show Gist options
  • Save mbk0asis/419c62de32005bb9290724a4206a89fe to your computer and use it in GitHub Desktop.
Save mbk0asis/419c62de32005bb9290724a4206a89fe to your computer and use it in GitHub Desktop.
R code used to analyse Endoplasmic Reticulum genes
cntNorm_ER <- read.csv("/home/bio1/00-NGS/RNAseq/single_ICM_TE/DESeq/cntNorm_ER.csv",row.names = 1)
head(cntNorm_ER)
colnames(cntNorm_ER)=c("ii1","ii2","ii3","ii4","ii5","ii6","ii7",
"ii8","ii9","ii10","ii11","ii12","ii13","ii14",
"ii15","ii16","ii17","ii18","ii19","ii20","ii21",
"ti1","ti2","ti3","ti4","ti5","ti6","ti7",
"ti8","ti9","ti10","ti11","ti12","ti13","ti14",
"ti15","ti16","ti17","ti18","ti19","ti20","ti21",
"in1","in2","in3","in4","in5","in6","in7",
"in8","in9","in10","in11","in12","in13","in14","in15",
"tn1","tn2","tn3","tn4","tn5","tn6","tn7",
"tn8","tn9","tn10","tn11","tn12","tn13","tn14","tn15")
ii.idx=1:21
ti.idx=22:42
in.idx=43:57
tn.idx=58:72
ii.col=rep("cyan",21)
ti.col=rep("darkblue",21)
in.col=rep("hotpink",15)
tn.col=rep("darkred",15)
cn_er<- as.matrix(cntNorm_ER)
rel = log2(1+cn_er[, c(ii.idx,in.idx)])-log2(rowMeans(1+cn_er[, ti.idx]))
rel = log2(1+cn_er[, 1:72])-log2(rowMeans(1+cn_er[, ii.idx]))
my_palette <- colorRampPalette(c("blue", "black", "yellow"))
breaks = unique(c(seq(-4,-2,length=75),
seq(-2,2,length=75),
seq(2,4,length=75)))
sampleTree = hclust(dist(rel), method="complete")
library('dendextend')
library(RColorBrewer)
dend <- as.dendrogram(sampleTree)
d2=color_branches(d1,h=35,groupLabels = T) # auto-coloring 5 clusters of branches.
plot(d2)
#abline(h=35,col="red")
clust=cutree(sampleTree,h=35)
clust=cutreeStatic(sampleTree, cutHeight = 35, minSize = 1)
table(clust)
rc <- cbind(rel,clust)
colourCount = length(unique(rc.order[clust,]))
getPalette = colorRampPalette(brewer.pal(9, "Set1"))
heatmap.2(rc[, 1:72],trace="none",col=my_palette,density="none",breaks = breaks,
main="ER",cexRow = 1,
Rowv = F,Colv = T, dendrogram="none", #hclustfun = function(x) hclust(x,method = 'complete'),
key.title="Pearson",key.xlab = NULL,key.ylab = NULL,
ColSideColors=c(rep("cyan",21),rep("darkblue",21),rep("hotpink",15),rep("darkred",15)),
RowSideColors=getPalette(22))
library(WGCNA)
keepSamples=(clust==1)
rel.select=rel[keepSamples,]
#head(rel.select)
heatmap.2(rel.select,trace="none",col=my_palette,density="none",breaks = breaks,
main="ER",cexRow = 1,margins=c(5,10),
Rowv = F,Colv = F, dendrogram="none", hclustfun = function(x) hclust(x,method = 'complete'),
key.title="Pearson",key.xlab = NULL,key.ylab = NULL,
ColSideColors=c(ii.col,ti.col,in.col,tn.col))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment