-
Notifications
You must be signed in to change notification settings - Fork 0
/
fig2c.R
executable file
·112 lines (90 loc) · 3.39 KB
/
fig2c.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
library(data.table)
library(ggplot2)
library(grid)
library(gridExtra)
library(ggpubr)
library(ggplotify)
data <- read.csv("/Users/mar/BIO/PROJECTS/APOBEC/NONBDNA/Denek3/united_X0.txt",sep='\t',header = TRUE)
data <- data.table(data)
setnames(data,c("cancer","structure","isAPOBEC","sample","trgIn","cntIn","trgOut","cntOut","trgOutOld","cntOutOld","sign"))
data[sign < 5 | sign > 95, signBinary:=1]
data[is.na(signBinary), signBinary := 0]
data$signBinary <- as.factor(data$signBinary)
data[, ratio := log((cntIn/trgIn)/(cntOut/trgOut))]
activity <- read.csv("/Users/mar/BIO/PROJECTS/PCAWG_APOBEC/PCAWG_enrichment_6cancers.txt",sep='\t',header=FALSE,strip.white =TRUE)
activity <- data.table(activity)
setnames(activity,c("project","sample","enrichment"))
data <- merge(data,activity,by="sample",all.x = TRUE)
data[, densityIn := cntIn / trgIn]
data[, densityOut := cntOut / trgOut]
data[, densRatio := densityIn/densityOut]
data[enrichment >= 2.0 & structure == "dr", min(densityIn/densityOut)]
nonAnonS <- copy(data)
nonAnonS <- nonAnonS[isAPOBEC==0]
nonAnonS[,trg := trgOut]
nonAnonS[,cnt := cntOut]
nonAnonS[,type := "nonAnonS"]
nonAinS <- copy(data)
nonAinS <- nonAinS[isAPOBEC==0]
nonAinS[,trg := trgIn]
nonAinS[,cnt := cntIn]
nonAinS[,type := "nonAinS"]
isAnonS <- copy(data)
isAnonS <- isAnonS[isAPOBEC==1]
isAnonS[,trg := trgOut]
isAnonS[,cnt := cntOut]
isAnonS[,type := "isAnonS"]
isAinS <- copy(data)
isAinS <- isAinS[isAPOBEC==1]
isAinS[,trg := trgIn]
isAinS[,cnt := cntIn]
isAinS[,type := "isAinS"]
dt <- rbind(nonAnonS,nonAinS,isAnonS,isAinS)
structures <- unique(data$structure)
cancers <- unique(data$cancer)
plots <- list()
dt <- dt[!is.na(enrichment)]
i <- 1
for(s in structures)
{
for(c in cancers)
{
dt2 <- dt[cancer==c & structure == s]
dt2[,sampleEnrich := paste0(sample,'__',round(enrichment,2))]
sampleLevels <- unique(dt2[order(enrichment),sampleEnrich])
dt2$sampleEnrich <- factor(dt2$sampleEnrich,levels=sampleLevels)
dt2$enrichment <- as.factor(as.character(round(dt2$enrichment,2)))
p <- ggplot(dt2,aes(x=enrichment,y=cnt/trg,fill=type)) + geom_bar(stat="identity",position="dodge") +
theme(panel.background = element_blank(),
axis.text.x = element_text(size=8),
axis.title = element_blank(),
axis.line = element_line(color="black"),
legend.position = "none") +
scale_fill_manual(values=c(rgb(203,73,123,maxColorValue = 255),
rgb(161,201,171,maxColorValue = 255),
rgb(242,234,102,maxColorValue = 255),
rgb(139,197,229,maxColorValue = 255)))
if(c %in% c("BLCA","CESC"))
wd <- 150
else if(c == "BRCA")
wd <- 450
else if(c == "HNSC")
wd <- 300
else if(c == "LUAD")
wd <- 250
else if(c == "LUSC")
wd <- 300
else
wd <- 150
ggsave(paste0("/Users/mar/BIO/PROJECTS/APOBEC/NONBDNA/pics/fig2/c/",s,"_",c,"_.tiff"),plot=p,width=wd,height=50,units="mm",dpi=300)
plots[[i]] <- as.grob(p)
i <- i + 1
}
}
#lay <- rbind(c(1,2),
# c(3,4),
# c(5,6),
# c(7,8),
# c(9,10))
#plts <- marrangeGrob(grobs=plots, nrow=5, ncol=1, top=NULL)
#ggexport(plts,filename="/Users/mar/BIO/PROJECTS/APOBEC/NONBDNA/Denek2/resultsNEWmy.pdf")