-
Notifications
You must be signed in to change notification settings - Fork 1
/
chrView.R
116 lines (92 loc) · 3.1 KB
/
chrView.R
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#chrView plot
chrvwlist=read.table("chrView_list.txt",sep='\t', stringsAsFactors=FALSE)
n_rain=nrow(chrvwlist)
cl <- rainbow(n_rain)
viewfile1=read.table(chrvwlist[1,2],sep='\t',header=T)
y_cg=max(viewfile1$meanCG)*1.5*100
y_chg=max(viewfile1$meanCHG)*1.5*100
y_chh=max(viewfile1$meanCHH)*1.5*100
#CG
outfile=paste("./chrView_CG.png",sep="")
bitmap(outfile,type="png16m",height=2,width=8,res=400)
plot(NA,ylab='CG methylation levels (%)',xlab="Chromosome",col='white',pch=19,type='p',cex.main = 1,frame = FALSE,ylim=c(0,100),xlim=c(0,nrow(viewfile1)),xaxt="n",cex=1.5)
for (i in 1:nrow(chrvwlist)){
name=chrvwlist[i,1]
file=chrvwlist[i,2]
viewfile=read.table(file,sep='\t',header=T)
chr=unique(viewfile$chromosome)
for (j in chr){
sub=viewfile[viewfile$chromosome==j,]
lines(sub$Position,sub$meanCG*100,lwd=0.5,col= cl[i])
#last row
abline(v=sub[nrow(sub),1]+0.5,col="grey",lwd=0.5)
#label
labsite=sub[as.integer(nrow(sub)/2),1]
lab=sub$chromosome[1]
sta_p=sub[1,1]
end_p=sub[(nrow(sub)),1]
axis(1,at=labsite ,label=lab,tick=F)
axis(1,at=sta_p ,label=FALSE)
axis(1,at=end_p ,label=FALSE)
xx<-c(sta_p,end_p)
axis(1,at=xx,labels=F)
}
}
legend("topright", legend = t(chrvwlist[1]), col = t(cl), lwd = 1,cex = 0.5)
dev.off()
#CHG
outfile=paste("./chrView_CHG.png",sep="")
bitmap(outfile,type="png16m",height=2,width=8,res=400)
plot(NA,ylab='CHG methylation levels (%)',xlab="Chromosome",col='white',pch=19,type='p',cex.main = 1,frame = FALSE,ylim=c(0,y_chg),xlim=c(0,nrow(viewfile1)),xaxt="n",cex=1.5)
for (i in 1:nrow(chrvwlist)){
name=chrvwlist[i,1]
file=chrvwlist[i,2]
viewfile=read.table(file,sep='\t',header=T)
chr=unique(viewfile$chromosome)
for (j in chr){
sub=viewfile[viewfile$chromosome==j,]
lines(sub$Position,sub$meanCHG*100,lwd=0.5,col= cl[i])
#last row
abline(v=sub[nrow(sub),1]+0.5,col="grey",lwd=0.5)
#label
labsite=sub[as.integer(nrow(sub)/2),1]
lab=sub$chromosome[1]
sta_p=sub[1,1]
end_p=sub[(nrow(sub)),1]
axis(1,at=labsite ,label=lab,tick=F)
axis(1,at=sta_p ,label=FALSE)
axis(1,at=end_p ,label=FALSE)
xx<-c(sta_p,end_p)
axis(1,at=xx,labels=F)
}
}
legend("topright", legend = t(chrvwlist[1]), col = t(cl), lwd = 1,cex = 0.5)
dev.off()
#CHH
outfile=paste("./chrView_CHH.png",sep="")
bitmap(outfile,type="png16m",height=2,width=8,res=400)
plot(NA,ylab='CHH methylation levels (%)',xlab="Chromosome",col='white',pch=19,type='p',cex.main = 1,frame = FALSE,ylim=c(0,y_chh),xlim=c(0,nrow(viewfile1)),xaxt="n",cex=1.5)
for (i in 1:nrow(chrvwlist)){
name=chrvwlist[i,1]
file=chrvwlist[i,2]
viewfile=read.table(file,sep='\t',header=T)
chr=unique(viewfile$chromosome)
for (j in chr){
sub=viewfile[viewfile$chromosome==j,]
lines(sub$Position,sub$meanCHH*100,lwd=0.5,col= cl[i])
#last row
abline(v=sub[nrow(sub),1]+0.5,col="grey",lwd=0.5)
#label
labsite=sub[as.integer(nrow(sub)/2),1]
lab=sub$chromosome[1]
sta_p=sub[1,1]
end_p=sub[(nrow(sub)),1]
axis(1,at=labsite ,label=lab,tick=F)
axis(1,at=sta_p ,label=FALSE)
axis(1,at=end_p ,label=FALSE)
xx<-c(sta_p,end_p)
axis(1,at=xx,labels=F)
}
}
legend("topright", legend = t(chrvwlist[1]), col = t(cl), lwd = 1,cex = 0.5)
dev.off()