|
| 1 | +setwd('/gpfs/group/yzz2/default/legacy/group/projects/vision/snapshot18_reproduce_0_16lim_all_NB88') |
| 2 | + |
| 3 | +d=read.table('atac_20cell.index.matrix.txt', header=F, sep='\t') |
| 4 | +dis = d[,-c(1:4)] |
| 5 | +set.seed(2019) |
| 6 | +#dis = dis[sample(dim(dis)[1], 100000),] |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +IS_count_vec = c(2) |
| 11 | +IS_min_vec = c(min(table(dis[,1]))) |
| 12 | +for (i in c(2:dim(dis)[2])){ |
| 13 | +IS_mat = dis[,1:i] |
| 14 | +IS_table = apply(IS_mat, 1, function(x) paste(x, collapse='_')) |
| 15 | +IS_count = length(unique(IS_table)) |
| 16 | +IS_min = median(table(IS_table)) |
| 17 | +print(IS_count) |
| 18 | +IS_count_vec = c(IS_count_vec, IS_count) |
| 19 | +IS_min_vec = c(IS_min_vec, IS_min) |
| 20 | +} |
| 21 | + |
| 22 | +### get background |
| 23 | +num_ccREs = dim(dis)[1] |
| 24 | +set.seed(2019) |
| 25 | +IS_count_mat_shuf = c() |
| 26 | + |
| 27 | +for (j in c(1:5)){ |
| 28 | +print(j) |
| 29 | +dis_shuffle = c() |
| 30 | +for (i in c(1:dim(dis)[2])){ |
| 31 | +dis_shuffle = cbind(dis_shuffle, dis[sample(num_ccREs),i]) |
| 32 | +} |
| 33 | +IS_count_vec_shuf = c(2) |
| 34 | +IS_min_vec_shuf = c(min(table(dis[,1]))) |
| 35 | +for (i in c(2:dim(dis)[2])){ |
| 36 | +IS_mat = dis_shuffle[,1:i] |
| 37 | +IS_table = apply(IS_mat, 1, function(x) paste(x, collapse='_')) |
| 38 | +IS_count = length(unique(IS_table)) |
| 39 | +IS_min = median(table(IS_table)) |
| 40 | +print(IS_count) |
| 41 | +IS_count_vec_shuf = c(IS_count_vec_shuf, IS_count) |
| 42 | +IS_min_vec_shuf = c(IS_min_vec_shuf, IS_min) |
| 43 | +} |
| 44 | +IS_count_mat_shuf = cbind(IS_count_mat_shuf, IS_count_vec_shuf) |
| 45 | +IS_min_mat_shuf = cbind(IS_min_mat_shuf, IS_min_vec_shuf) |
| 46 | +} |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | +pdf('IS_n_vs_CT_n.pdf', width=4.5, height=4.5) |
| 52 | +par(mfrow=c(1,1)) |
| 53 | +plot(1:length(IS_count_vec), IS_count_vec, log='', ylim=c(1, max(cbind(IS_count_vec, IS_count_mat_shuf))), xlab='', ylab='') |
| 54 | +lines(1:length(IS_count_vec), IS_count_vec, lwd=1.5) |
| 55 | +points(1:length(IS_count_vec), rowMeans(IS_count_mat_shuf), col='gray') |
| 56 | +lines(1:length(IS_count_vec), rowMeans(IS_count_mat_shuf), lwd=1.5, col='gray') |
| 57 | +CI_h = rowMeans(IS_count_mat_shuf) + apply(IS_count_mat_shuf, 1, sd)/sqrt(dim(IS_count_mat_shuf)[2]) * 1.960 |
| 58 | +CI_l = rowMeans(IS_count_mat_shuf) - apply(IS_count_mat_shuf, 1, sd)/sqrt(dim(IS_count_mat_shuf)[2]) * 1.960 |
| 59 | +#lines(1:length(IS_count_vec), CI_h, lwd=1, col='gray') |
| 60 | +#lines(1:length(IS_count_vec), CI_l, lwd=1, col='gray') |
| 61 | +#plot(1:length(IS_count_vec), IS_min_vec, log='') |
| 62 | +#lines(1:length(IS_count_vec), IS_min_vec, lwd=1.5) |
| 63 | +#for (i in 1:50){ |
| 64 | +#points(1:length(IS_count_vec), IS_min_mat_shuf[,i], col='gray') |
| 65 | +#lines(1:length(IS_count_vec), IS_min_mat_shuf[,i], lwd=1.5, col='gray') |
| 66 | +#} |
| 67 | +dev.off() |
| 68 | + |
| 69 | +IS_table = apply(IS_mat, 1, function(x) paste(x, collapse='_')) |
| 70 | +IS_ccRE_count = table(IS_table) |
| 71 | + |
| 72 | +library(ggplot2) |
| 73 | +pdf('ccRE_count_hist.10k.pdf', width=3.5, height=3.) |
| 74 | +#mydata_hist = hist((IS_ccRE_count), breaks=50, xlab='', ylab='', main='') |
| 75 | +#plot(mydata_hist$count, log="y", type='h', lwd=10, lend=2) |
| 76 | +#box() |
| 77 | +IS_ccRE_count = as.data.frame(IS_ccRE_count) |
| 78 | +ggplot(as.data.frame(IS_ccRE_count), aes(x = Freq)) + geom_histogram() + scale_x_log10() + theme_bw() + theme(panel.grid.major = element_blank(), |
| 79 | +panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) |
| 80 | +dev.off() |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | + |
0 commit comments