-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge_erData_with_predictionData.R
executable file
·46 lines (30 loc) · 1.25 KB
/
merge_erData_with_predictionData.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
args<-commandArgs(TRUE) # 1st = ML output folder, 2nd = erPath
library(tidyverse)
library(stringr)
library(rtracklayer)
options(stringsAsFactors=F)
path = args[1]
erPath = args[2]
if(!dir.exists(paste(path, "/PredictionMerge", sep=""))){
system(paste("mkdir -m a=rwx ",path, "/PredictionMerge", sep=""))
}
# new output path
out.path = paste(path, "/PredictionMerge", sep="")
tissues = c(
"GCB1", "GCB2"
)
for(tissue in tissues){
print(tissue)
#ER data
er = read.table(paste(erPath, "/", tissue, ".txt", sep=""), header=T, sep="\t")
## prediction data
pred = read.table(paste(path, "/Prediction/", tissue,".pred.txt", sep=""), header=TRUE)
data = left_join(pred, er, by = c("id" = "ER_id"))
saveRDS(data, file = paste(out.path, "/", tissue, "_mergedData.rds", sep=""))
# saving data as a bed format
bed = data %>%
mutate(score = 0, bed_strand = ".", thickstart = start, thickend = end, color = ifelse(predicted.prob>0.60, "0,175,187", "231,184,0")) %>%
dplyr::select(seqnames, start, end, id, score, bed_strand, thickstart, thickend, color)
write.table(bed, file = paste(out.path, "/", tissue, ".bed", sep=""), row.names=FALSE, col.names = FALSE, quote = FALSE, sep="\t")
rm(pred, data)
}