-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDensityPlot_AllFeatures.R
184 lines (139 loc) · 8.21 KB
/
DensityPlot_AllFeatures.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
##################################################################################################
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
##################################################################################################
# Start
#"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
# Density plot script written by Dr Reza Rafiee
# Research Associate, Northern Institute for Cancer Research, Newcastle University
# This script gets a csv file including age at diagnosis and other features for plotting density plots
linear.density.plot <- function(present.score,not.present.score, condition, max.age)
{
#max(c(present.score,not.present.score)) -> max.age
score <- c(present.score,not.present.score)
cat <- rep('a',length(score))
cat[score<5] <- 'less.five'
#cat[score<5&score>=3] <- 'three.to.five'
cat[score<=max.age&score>=5] <- 'more.five'
cat <- as.factor(cat)
cat <- factor(cat,levels(cat)[c(1,3,2)])
pres.fact <- factor(c(rep("Present",length(present.score)),rep("Absent",length(not.present.score))))
counts <- table(pres.fact,cat)
plot(density(present.score)$x,density(present.score)$y*14, col = "blue", type = "l", #density(present.score)$y*13 is original, 15
ylim=c(-0.2,max(density(present.score)$y)*14), # original
#ylim=c(-0.2,4.00), # maxium Y axis (3.59) is for the Chr17q.gain
xlim=c(0,max.age), xlab = "Age (Years)",
bty="n",
xaxt='n', ann=FALSE, yaxt='n'
)
lines(density(present.score)$x,density(present.score)$y*14, col = "blue") #15
axis(1,at=c(0,max.age),pos=0, tck=c(-0.1), labels = NA,lwd=1)
axis(1,at=c(0,max.age),pos=0, tck=c(0.1), labels = NA,lwd=1)
#lines(density(present.score), col = "blue")
rug(present.score, col = "blue", side = 1, ticksize=0.2,lwd = 2)
rug(not.present.score, col = "grey", side = 1, ticksize=0.2,lwd =0.5)
abline(v=5, lty = 2)
mtext(paste("",condition), side = 2, las = 1, cex = 0.75)
}
setwd("~/")
#### density plots
# 31 March 2017
data_Infant16 <- read.csv("Under5vsOver5DensityPlots.csv", header=T) #
data <- data_Infant16
#### data stored in a list for each plot on the combined linear density plot
density.plots <- list()
###########
score <- data$Ageatdiagnosis
cat <- rep('a',length(score))
cat[score<5] <- 'less.five'
cat[score>=5] <- 'more.five'
cat <- as.factor(cat)
cat <- factor(cat,levels(cat)[c(1,3,2)])
present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$Male=="1")]
not.present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$Male=="2")]
density.plots[[1]]<-list(present.score,not.present.score)
present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$STR=="1")]
not.present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$STR=="2")]
density.plots[[2]]<-list(present.score,not.present.score)
present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$M2.=="1")]
not.present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$M2.=="2")]
density.plots[[3]]<-list(present.score,not.present.score)
present.score <- data$Ageatdiagnosis[which(data_Infant16$CLA=="1")]
not.present.score <- data$Ageatdiagnosis[which(data_Infant16$CLA=="2")]
density.plots[[4]] <- list(present.score,not.present.score)
present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$DN.MBEN=="1")]
not.present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$DN.MBEN=="2")]
density.plots[[5]] <- list(present.score,not.present.score)
present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$LCA=="1")]
not.present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$LCA=="2")]
density.plots[[6]] <- list(present.score,not.present.score)
present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$WNT=="1")]
not.present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$WNT=="2")]
density.plots[[7]] <- list(present.score,not.present.score)
present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$SHH=="1")]
not.present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$SHH=="2")]
density.plots[[8]] <- list(present.score,not.present.score)
present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$G3=="1")]
not.present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$G3=="2")]
density.plots[[9]] <- list(present.score,not.present.score)
present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$G4=="1")]
not.present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$G4=="2")]
density.plots[[10]] <- list(present.score,not.present.score)
present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$MYC.amplification=="1")]
not.present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$MYC.amplification=="2")]
density.plots[[11]] <- list(present.score,not.present.score)
present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$MYCN.amplification=="1")]
not.present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$MYCN.amplification=="2")]
density.plots[[12]] <- list(present.score,not.present.score)
present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$TP53.mutation=="1")]
not.present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$TP53.mutation=="2")]
density.plots[[13]]<-list(present.score,not.present.score)
present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$i17q=="1")]
not.present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$i17q=="2")]
density.plots[[14]]<-list(present.score,not.present.score)
# present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$Under.5=="1")] # Under 5
# not.present.score <- data_Infant16$Ageatdiagnosis[which(data_Infant16$Under.5=="2")] # more than 5 years
# density.plots[[2]] <- list(present.score,not.present.score)
names(density.plots)<-c("Male", #1
"STR", #2
"M2+", #3 max(density(present.score)$y)*13 ===> 0.9822429
#"DN/MBEN", #4 max(density(present.score)$y)*13 ===> 0.9822429
"CLA", #4
"DN/MBEN", #5
"LCA", #6
"WNT", #7
"SHH", #8
"Grp3", #9
"Grp4", #10
"MYC amplification", #11
"MYCN amplification", #12
#"Male", #13 - max(density(present.score)$y)*13 ===> 1.750508
"TP53 Mutation", #13
"iso17q") #14
names(density.plots)<- strrep(" ",1:14) #14
##save(density.plots, file="~/My Projects at NICR/2014/Infant/Our New Material/density.plots_List20Var_14Jan16.rda")
##save(density.plots, file="~/My Projects at NICR/2014/Infant/Our New Material/density.plots_List16Var_08Jan16.rda")
###pdf(file="linear.density.plot.pdf")
#load("~/My Projects at NICR/2014/Infant/Our New Material/density.plots_List16Var_08Jan16.rda")
###data <- read.csv(file = "Infant data current 0-16 DH050116_Ch17.csv")
#load("~/My Projects at NICR/2014/Infant/Our New Material/density.plots_List20Var_14Jan16.rda")
#data <- read.csv(file = "FOR DENSITY PLOT FIG 1 ONLY_DATA INFIDELITY Copy of Infant data current 0-16 DH140116.csv")
max.age <- max(data_Infant16$Ageatdiagnosis, na.rm=TRUE)
#max.age <- max(data$Ageatdiagnosis)
number.of.graphs <- 14
#number.of.graphs <- 1
#pdf(file="linear.density.plot14Jan2016_Final.pdf")
par(mfrow=c(number.of.graphs,1),mar=c(0.5,10,0.5,5)) #original: mar=c(0.5,8,0.5,5)
for(i in 1:14)
{
present.score <- as.numeric(density.plots[[i]][[1]])
present.score <- present.score[!is.na(present.score)]
not.present.score <- as.numeric(density.plots[[i]][[2]])
not.present.score <- not.present.score[!is.na(not.present.score)]
linear.density.plot(present.score ,not.present.score ,names(density.plots)[i],max.age)
}
#dev.off()
#"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
# End
##################################################################################################
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
##################################################################################################