This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumber_of_eRNA.R
71 lines (62 loc) · 2.65 KB
/
Number_of_eRNA.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
setwd("~/Documents/IFN_enhancer/")
library(GenomicRanges)
library(GenomicFeatures)
library(gplots)
library(rtracklayer)
###################################################
### Load Data
###################################################
load(file = "~/Documents/eRNA/link/UCSC/hg18_refseq.RData")
# extend all the genes by 10kb downstream
x <- read.table("R/Data/chromInfo.txt", header = F)
chr.ends <- x[, 2] - 1
names(chr.ends) <- x[, 1]
gene.ext <- gene
extend <- 10^4
upstream <- 10^3
lab <- which(strand(gene.ext) == "+")
end(gene.ext[lab]) <- apply(rbind(end(gene.ext[lab]) + extend, chr.ends[as.character(seqnames(gene.ext[lab]))]), 2, min)
start(gene.ext[lab]) <- apply(rbind(start(gene.ext[lab]) - upstream, rep(1, length(lab))), 2, max)
lab <- which(strand(gene.ext) == "-")
start(gene.ext[lab]) <- apply(rbind(start(gene.ext[lab]) - extend, rep(1, length(lab))), 2, max)
end(gene.ext[lab]) <- apply(rbind(end(gene.ext[lab]) + upstream, chr.ends[as.character(seqnames(gene.ext[lab]))]), 2, min)
load(file = "~/Documents/eRNA/link/UCSC/H3K27ac_GM.RData")
load(file = "~/Documents/eRNA/link/UCSC/H3K4me1_GM.RData")
###################################################
### Number of new eRNAs
###################################################
lab <- paste("GM", c("0h", "30min", "1h", "2h", "4h", "6h", "9h", "12h", "18h", "24h", "48h", "72h"), sep = "")
load("R/Data/HOMER_GM0h.RData")
gm_0h <- txn
newer_eRNA <- function(homer_file) { # Enhancers even without markers before treatment
load(file = homer_file)
# Intergenic only
hits <- findOverlaps(txn, gene.ext, ignore.strand = T)
ta <- txn[-unique(queryHits(hits))]
# non-overlap with enhancer markers
markers <- c(k4me1, k27ac)
ta <- ta[ta %outside% markers, ]
# Remove pre-existing eRNA
hits <- findOverlaps(ta, gm_0h, ignore.strand = T)
tb <- ta[-unique(queryHits(hits))]
print(c("Enhancers without neither marker nor eRNA:", length(tb)))
return(tb)
}
new_eRNA <- function(homer_file) { # Enhancers with markers but no eRNA before treatment
load(file = homer_file)
# Intergenic only
hits <- findOverlaps(txn, gene.ext, ignore.strand = T)
ta <- txn[-unique(queryHits(hits))]
# Remove pre-existing enhancer
markers <- c(k4me1, k27ac)
# tb <- ta[ta %outside% markers, ]
ta <- ta[ta %over% markers, ] # All expressed enhancers with markers
# Remove pre-existing eRNA
hits <- findOverlaps(ta, gm_0h, ignore.strand = T)
tb <- ta[-unique(queryHits(hits))] # Newly activated enhancers
print(c("Enhancers with marker:", length(ta)))
print(c("Enhancers with marker but no eRNA:", length(tb)))
return(tb)
}
ea <- new_eRNA("R/Data/HOMER_meta_GM.RData")
eb <- newer_eRNA("R/Data/HOMER_meta_GM.RData")