Code:2019-9-23-1: Difference between revisions

From ZhangLabWiki
Jump to navigation Jump to search
>Shicheng
No edit summary
>Shicheng
No edit summary
Line 1: Line 1:
<nowiki>
#######################################################################################################################
#######################################################################################################################
###  Title : Heatmap plot based on raw methylation signals which shared with high GSI MHL regions
###  Title : Heatmap plot based on raw methylation signals which shared with high GSI MHL regions
###  Author: Shicheng Guo, Ph.D. Email: Shicheng.Guo@hotmail.com  
###  Author: Shicheng Guo, Ph.D. Email: Shicheng.Guo@hotmail.com  
###  Time :  Sep/23/2015  
###  Time :  Sep/23/2015  
###  New: Extract the methylation signals with MethylFreq2Matrix.pl
###  New: Extract the methylation signals with MethylFreq2Matrix.pl
#######################################################################################################################
#######################################################################################################################
data<-read.table("MethylMatrix.Filelist.txt.freq",row.names=1,head=T,sep="\t",as.is=T,check.names=F)
data<-read.table("MethylMatrix.Filelist.txt.freq",row.names=1,head=T,sep="\t",as.is=T,check.names=F)
s1<-grep("KZ",colnames(data))
s1<-grep("KZ",colnames(data))
s2<-grep("STL",colnames(data))
s2<-grep("STL",colnames(data))
length(s1)
length(s1)
length(s2)
length(s2)
newdata=data[,c(s1,s2)]
newdata=data[,c(s1,s2)]
dim(na.omit(newdata))
dim(na.omit(newdata))
newdata<-RawNARemove(newdata)
newdata<-RawNARemove(newdata)
library("impute")
library("impute")
newdata<-impute.knn(data.matrix(newdata))$data
newdata<-impute.knn(data.matrix(newdata))$data
newdata[1:3,1:3]
newdata[1:3,1:3]
saminfo<-read.table("saminfo.txt",head=F,sep="\t",as.is=T)
saminfo<-read.table("saminfo.txt",head=F,sep="\t",as.is=T)
colnames(newdata)=saminfo[match(colnames(newdata),saminfo[,1]),2]
colnames(newdata)=saminfo[match(colnames(newdata),saminfo[,1]),2]
newdata<-newdata[,order(colnames(newdata))]
newdata<-newdata[,order(colnames(newdata))]
save(newdata,file="Raw.methy.GSI.RData")
# source("http://www.bioconductor.org/biocLite.R")
save(newdata,file="Raw.methy.GSI.RData")
# biocLite("grDevices")
# biocLite("gplots")
# source("http://www.bioconductor.org/biocLite.R")
library("grDevices")
# biocLite("grDevices")
library("gplots")
# biocLite("gplots")
pdf("Figure-20-raw-signal.pdf")
col=colorRampPalette(c("yellow", "blue"))(20)  
library("grDevices")
heatmap.2(newdata,col=col,trace="none",density.info="none",Colv=F,Rowv=F,key=NA,keysize=1,cexCol=0.8,labRow=NA)
library("gplots")
dev.off()
pdf("Figure-20-raw-signal.pdf")
newdata<-newdata[match(corsort(rownames(newdata)),rownames(newdata)),]
col=colorRampPalette(c("yellow", "blue"))(20)  
corsort<-function(cor){
heatmap.2(newdata,col=col,trace="none",density.info="none",Colv=F,Rowv=F,key=NA,keysize=1,cexCol=0.8,labRow=NA)
  a<-unlist(lapply(strsplit(as.character(cor),split=c(":")),function(x) x))
dev.off()
  bed<-matrix(a,ncol=2,byrow=T)
newdata<-newdata[match(corsort(rownames(newdata)),rownames(newdata)),]
  bed<-bed[order(bed[,1],as.numeric(bed[,2])),]
  cor<-apply(bed,1,function(x){paste(unlist(strsplit(x,"\t"))[1],":",unlist(strsplit(x,"\t"))[2],sep="")})
  return(cor)
corsort<-function(cor){
}
  a<-unlist(lapply(strsplit(as.character(cor),split=c(":")),function(x) x))
</nowiki>
  bed<-matrix(a,ncol=2,byrow=T)
  bed<-bed[order(bed[,1],as.numeric(bed[,2])),]
  cor<-apply(bed,1,function(x){paste(unlist(strsplit(x,"\t"))[1],":",unlist(strsplit(x,"\t"))[2],sep="")})
  return(cor)
}

Revision as of 22:29, 23 September 2015

####################################################################################################################### ### Title : Heatmap plot based on raw methylation signals which shared with high GSI MHL regions ### Author: Shicheng Guo, Ph.D. Email: Shicheng.Guo@hotmail.com ### Time : Sep/23/2015 ### New: Extract the methylation signals with MethylFreq2Matrix.pl #######################################################################################################################

data<-read.table("MethylMatrix.Filelist.txt.freq",row.names=1,head=T,sep="\t",as.is=T,check.names=F) s1<-grep("KZ",colnames(data)) s2<-grep("STL",colnames(data)) length(s1) length(s2) newdata=data[,c(s1,s2)] dim(na.omit(newdata)) newdata<-RawNARemove(newdata) library("impute") newdata<-impute.knn(data.matrix(newdata))$data newdata[1:3,1:3] saminfo<-read.table("saminfo.txt",head=F,sep="\t",as.is=T) colnames(newdata)=saminfo[match(colnames(newdata),saminfo[,1]),2] newdata<-newdata[,order(colnames(newdata))]

save(newdata,file="Raw.methy.GSI.RData")

# source("http://www.bioconductor.org/biocLite.R") # biocLite("grDevices") # biocLite("gplots")

library("grDevices") library("gplots") pdf("Figure-20-raw-signal.pdf") col=colorRampPalette(c("yellow", "blue"))(20) heatmap.2(newdata,col=col,trace="none",density.info="none",Colv=F,Rowv=F,key=NA,keysize=1,cexCol=0.8,labRow=NA) dev.off() newdata<-newdata[match(corsort(rownames(newdata)),rownames(newdata)),]


corsort<-function(cor){ a<-unlist(lapply(strsplit(as.character(cor),split=c(":")),function(x) x)) bed<-matrix(a,ncol=2,byrow=T) bed<-bed[order(bed[,1],as.numeric(bed[,2])),] cor<-apply(bed,1,function(x){paste(unlist(strsplit(x,"\t"))[1],":",unlist(strsplit(x,"\t"))[2],sep="")}) return(cor) }