-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompartment_hiC.r
68 lines (47 loc) · 1.78 KB
/
compartment_hiC.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
## Author: Qi Yu
## Contact: [email protected]
library("lattice")
library("reshape2")
library(RColorBrewer)
library(gridExtra)
library(reshape2)
#Plot heat map
defplot<-function(file,name=NA,chr=NA){
matrix1<-read.table(file,header=FALSE)
names(matrix1)<-c("x","y","z")
png(paste(chr,"_",name,"log.png",sep=""),width=900, height=900, res=200)
myplot<-levelplot(log(z) ~ x*y, data=matrix1, xlab="X" , col.regions = heat.colors(100)[length(heat.colors(100)):1] , main=paste(name,chr))
print(myplot)
dev.off()
return(matrix1)
}
pachy<-defplot("prelep_allValidPairs_homologous.hic_chr1_100000.out",name="Prelep_B6_B6",chr="chr1")
#secondway
name="prelep"
chr="chr1"
data<- as.matrix(read.table("prelep_highres_allValidPairs_G1_1_1.hic_chr1_100000.out_matrix.txt", header=FALSE, sep = "\t",
#row.names = 1,
as.is=TRUE))
png(paste(chr,name,"_matrix100kb.png",sep=""),width=1200, height=1200, res=200)
image(x=1:1924, y=1:1924, z=log(data),
#zlim=c(-1,1),
col=colorRampPalette(c("red","yellow","white"))(256), useRaster=TRUE)
dev.off()
#calculate pearson correaltion and plot
cm <- cor(data)
png(paste(chr,name,"_corr100kb.png",sep=""),width=1200, height=1200, res=200)
image(x=1:1924, y=1:1924, z=cm,
#zlim=c(-1,1),
col=colorRampPalette(c("red", "white","blue"))(256), useRaster=TRUE)
dev.off()
#subtract first compartment
png(paste(chr,name,"_ppc1_100kb.png",sep=""),width=1200, height=800, res=200)
cm[is.na(cm)] <- 0
princp = princomp(cm)
plot(princp$loadings[,1],type='l')
dev.off()
#subtract second compartment
png(paste(chr,name,"_pc2_100kb.png",sep=""),width=1200, height=800, res=200)
plot(princp$loadings[,2],type='l')
dev.off()
#######################################################################################