-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDMRannotation - calcs.r
136 lines (125 loc) · 4.94 KB
/
DMRannotation - calcs.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
136
#gen <- readRDS("matrixReloaded.data")
dmr <- readRDS("allDMR.data")
stages <- c("2-8 cells", "Intermediate", "Spat")
A <- B <- C <- NULL
Agenes <- Bgenes <- Cgenes <- NULL
################################################################################
message("Scanning A...")
subdmr <- subset(dmr, Stage == "2-8 cells")
# For each of the three DMR comparisons (subset):
for (j in 1:nrow(subdmr))
{
# Identify which scaffold and extract the map table:
smap <- gen[[ which(names(gen) == subdmr$Item[j]) ]]$map
# DMR start and stop:
dmrstart <- subdmr$Start[j]
dmrstop <- subdmr$Stop[j]
# For each feature having a start/stop included in the DMR:
readstart <- dmrstart < smap$Stop
readstart <- min(which(readstart))
readstop <- dmrstop > smap$Start
readstop <- max(which(readstop))
if (readstop < readstart)
{ A <- c(A, "OUT") } else {
# Check if the length of the selection is zero:
if (!is.infinite(readstart) & !is.infinite(readstop)) {
# Save that feature on a vector:
A <- c(A, as.character(smap[readstart:readstop, ]$Feature))
# Extract the gene IDs for those positions:
Agenes <- c(Agenes, smap[readstart:readstop, ]$Annot)
}
}
}
greppata <- grep("LTR|LINE|DNA|RC", A)
A[greppata] <- "TE"
greppata <- grep("similarity|Repeat", A)
A[greppata] <- "REP"
A <- A[ A != "mRNA" ]
################################################################################
message("Scanning B...")
subdmr <- subset(dmr, Stage == "Intermediate")
# For each of the three DMR comparisons (subset):
for (j in 1:nrow(subdmr))
{
# Identify which scaffold and extract the map table:
smap <- gen[[ which(names(gen) == subdmr$Item[j]) ]]$map
# DMR start and stop:
dmrstart <- subdmr$Start[j]
dmrstop <- subdmr$Stop[j]
# For each feature having a start/stop included in the DMR:
readstart <- dmrstart < smap$Stop
readstart <- min(which(readstart))
readstop <- dmrstop > smap$Start
readstop <- max(which(readstop))
if (readstop < readstart)
{ B <- c(B, "OUT") } else {
# Check if the length of the selection is zero:
if (!is.infinite(readstart) & !is.infinite(readstop)) {
# Save that feature on a vector:
B <- c(B, as.character(smap[readstart:readstop, ]$Feature))
# Extract the gene IDs for those positions:
Bgenes <- c(Bgenes, smap[readstart:readstop, ]$Annot)
}
}
}
greppata <- grep("LTR|LINE|DNA|RC", B)
B[greppata] <- "TE"
greppata <- grep("similarity|Repeat", B)
B[greppata] <- "REP"
B <- B[ B != "mRNA" ]
################################################################################
message("Scanning C...")
subdmr <- subset(dmr, Stage == "Spat")
# For each of the three DMR comparisons (subset):
for (j in 1:nrow(subdmr))
{
# Identify which scaffold and extract the map table:
smap <- gen[[ which(names(gen) == subdmr$Item[j]) ]]$map
# DMR start and stop:
dmrstart <- subdmr$Start[j]
dmrstop <- subdmr$Stop[j]
# For each feature having a start/stop included in the DMR:
readstart <- dmrstart < smap$Stop
readstart <- min(which(readstart))
readstop <- dmrstop > smap$Start
readstop <- max(which(readstop))
if (readstop < readstart)
{ C <- c(C, "OUT") } else {
# Check if the length of the selection is zero:
if (!is.infinite(readstart) & !is.infinite(readstop)) {
# Save that feature on a vector:
C <- c(C, as.character(smap[readstart:readstop, ]$Feature))
# Extract the gene IDs for those positions:
Cgenes <- c(Cgenes, smap[readstart:readstop, ]$Annot)
}
}
}
greppata <- grep("LTR|LINE|DNA|RC", C)
C[greppata] <- "TE"
greppata <- grep("similarity|Repeat", C)
C[greppata] <- "REP"
C <- C[ C != "mRNA" ]
################################################################################
full <- c(34987154,181064503,25674748,21879155,24463465,233068965)
full <- matrix(nrow = 6, ncol = 1, data = full)
rownames(full) <- c("CDS","intrn","promoter","REP","TE","OUT")
full <- full/sum(full)*100
################################################################################
ds <- data.frame(Counts = c(table(A), table(B), table(C), full),
Feature = c(names(table(A)), names(table(B)),
names(table(C)), rownames(full)),
Comp = c(rep("S",6),rep("I",5),rep("M",6),rep("genome",6)) )
# This re-ordering was changed to take into account that S-I-M are not in the
# alphabetical order:
#ds <- rbind(ds, c(0, "promoter", "I"))
#ds <- ds[order(ds$Comp), ]
ds <- rbind(ds[1:7, ], c(0, "OUT", "I"), ds[8:nrow(ds), ])
ds$Counts <- as.numeric(ds$Counts)
# By comparison, percentage of its maximum:
ds[1:6 , 1] <- with(ds[1:6 , ], Counts/sum(Counts)*100)
ds[7:12 , 1] <- with(ds[7:12 , ], Counts/sum(Counts)*100)
ds[13:18, 1] <- with(ds[13:18, ], Counts/sum(Counts)*100)
# This line added because levels are reordered alphabetically by default:
#levels(ds$Comp) <- unique(as.character(ds$Comp))
ds <- round(xtabs(ds), 3)
write.table(ds, "DMRannotation.csv", sep = ";", dec = ",")