-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_loops_size_hichiper_original.r
137 lines (113 loc) · 4.46 KB
/
plot_loops_size_hichiper_original.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
## Author: Qi Yu
## Contact: [email protected]
library(ggplot2)
library(wesanderson)
args<-(commandArgs(TRUE))
library(tidyr)
library(tibble)
library(reshape2)
#filename = args[1]
#title = args[2]
readfile<-function(filename,title=NA){
homo<-read.table(filename)
homo<-homo[c(2,5,7)]
names(homo)<-c("start","count","end")
homo$distance<-abs(homo$end-homo$start)/1000
d <- homo$distance
cs <- sum(homo$count)
#100k to 2000k
intvals <- 1:40
props <- sapply(intvals, function(i){
sum(homo$count[(d <= i * 100) & (d > (i-1) * 100)])/cs
})
v <- as.character(c(1,100*intvals)); lv <- length(v)
colnm <- paste0(c(paste0(v[-1*lv], "-",v[-1])[-lv]), "kb")
names(props) <- colnm
propdf <- melt(props)
propdf$type<-title
propdf <- rownames_to_column(propdf, var="Bin")
return(propdf)
}#end of function readfile
table<-readfile("/home/qiyu/data/hiC/hichipper_lep_analysis/190110_9018_1_CGTACG_GC_121718_HiChip_B6_4C_H3K4me3.intra.loop_counts.bedpe_merge_at_B6_wt_DMC1_peaks_no_blacklist.bed","4C_1HT")
table2<-readfile("/home/qiyu/data/hiC/hichipper_lep_analysis/190110_9018_1_CGATGT_GC_121718_HiChip_B6_Lep_H3K4me3.intra.loop_counts.bedpe_merge_at_B6_wt_DMC1_peaks_no_blacklist.bed","Lep_1HT")
# table<-table[which(table$distance<2000),]
# table2<-table2[which(table2$distance<2000),]
#
# new<-table(cut(table$distance, seq(0, 2000, by=100), include.lowest=TRUE))
# new2<-table(cut(table2$distance, seq(0, 2000, by=100), include.lowest=TRUE))
#
# tablea<-split(table, cut(table$distance, seq(0, 2000, by=100), include.lowest=TRUE))
# tableb<-split(table2, cut(table2$distance, seq(0, 2000, by=100), include.lowest=TRUE))
#
# Dummy calls to remove note
Sample <- ""
Bin <- ""
Value <- ""
intvals <- 1:40
v <- as.character(c(1,100*intvals)); lv <- length(v)
propdf <- rbind(table,table2)
colnm <- paste0(c(paste0(v[-1*lv], "-",v[-1])[-lv]), "kb")
propdf$Bin<-factor(propdf$Bin,levels=colnm,ordered=TRUE)
propdf<-propdf[order(propdf$Bin),]
p1 <- ggplot(propdf, aes(x=Bin, y=value, group=type, color=type)) + geom_line(size=2) +
theme_bw()+
theme(axis.text.x = element_text(hjust=1, angle = 45),
text = element_text(size=25),
legend.title=element_blank()) +
labs(title = "Proportional PET counts per distance",
x = "Binned Loop Distance", y = "Proportional Pet Counts") +
annotation_logticks(sides="l")+
scale_y_log10()
ggsave(plot=p1,filename="intra_noself_1HT_4Mb_4C_Lep.png",height=7,width=14,dpi=200)
#new2$type<-factor(new2$type,levels=c("PreL_Boris","P_Boris","P_CTCF","Z_Boris","Z_CTCF","P_Boris_DSB","P_CTCF_DSB"))
options(scipen=10000)
new4<-new2[which(new2$distance<1000),]
d2<-ggplot(new4,aes(x=distance,fill=type))+
#geom_density(linesize=2)+
geom_histogram(color="black")+
facet_wrap( ~ type, ncol=1)+
#facet_grid(type ~ .)+
#geom_freqpoly()+
#geom_density(size=1.5)+
#scale_fill_manual(values=c(rev(wes_palette("Rushmore",5)),"blue","purple"),name="")+
theme_bw()+
xlab("loop Length (kb)")+
#scale_y_log10()+
annotation_logticks(sides="b")+
theme(text = element_text(size=25),legend.title=element_blank(),legend.justification=c(1,01))
#scale_x_log10()+scale_y_log10()+
ggsave(plot=d2,filename="1HT_intra_noself_4C_Lep.png",height=7,width=10,dpi=200)
d2<-ggplot(new2,aes(x=count,color=type))+
#geom_density(linesize=2)+
stat_ecdf(size=2)+
facet_wrap( ~ type, ncol=1)+
#facet_grid(type ~ .)+
#geom_freqpoly()+
#geom_density(size=1.5)+
#scale_fill_manual(values=c(rev(wes_palette("Rushmore",5)),"blue","purple"),name="")+
theme_bw()+
xlab("PET")+
scale_x_log10()+
scale_y_log10()+
annotation_logticks(sides="lb")+
theme(text = element_text(size=25),legend.title=element_blank(),legend.justification=c(1,01))
#scale_x_log10()+scale_y_log10()+
ggsave(plot=d2,filename="PET_count_noself_4C_Lep.png",height=7,width=10,dpi=200)
new3<-new4[which(new4$count>4),]
d2<-ggplot(new3,aes(x=distance,fill=type))+
#geom_density(linesize=2)+
geom_histogram(color="black")+
facet_wrap( ~ type, ncol=1)+
ggtitle(">=5")+
#facet_grid(type ~ .)+
#geom_freqpoly()+
#geom_density(size=1.5)+
#scale_fill_manual(values=c(rev(wes_palette("Rushmore",5)),"blue","purple"),name="")+
theme_bw()+
xlab("loop Length (kb)")+
#scale_x_log10()+
annotation_logticks(sides="b")+
theme(text = element_text(size=25),legend.title=element_blank(),legend.justification=c(1,01))
#scale_x_log10()+scale_y_log10()+
#scale_x_log10()+scale_y_log10()+
ggsave(plot=d2,filename="1HT_intra_noself_4C_Lep_5_a.png",height=7,width=10,dpi=200)