-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadingData.R
executable file
·325 lines (223 loc) · 12.2 KB
/
ReadingData.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#Function for reading the data and put it in a form of list
options(warn=-1)
ReadingData<- function(MainData_file,PathologyData_file){
source("Read_Entry_Function.R")
source("Pathology_Read_Entry_Function.R")
source("ChangeDosesToNum_Fun.R" )
source("AdjDoseFun_int.R")
library(tidyverse)
#Read the dataset
MainData=read.delim(MainData_file,sep = " ", dec = ".",header = TRUE, stringsAsFactors = FALSE)
#Delete any whitespaces in the beginning and end of the entries
MainData=apply(MainData,2,trimws)
MainData=as.data.frame(MainData,stringsAsFactors = FALSE)
#Create the names of the new extended datasets
Extract_Columns=colnames(MainData)[c(15,16,18:20,22,25,27)]
Dataset_Names=paste(Extract_Columns,rep("Dataset",length((Extract_Columns))),sep="_")
rm(Extract_Columns)
#Initialise the Datasets
for (i in 1:length(Dataset_Names)) {
if (!(Dataset_Names[i] %in% c("macroscopic_Dataset","organ_weight_Dataset"))) {
df=data.frame(identifier=character(),
study_id=character(),
species=character(),
type=character(),
duration=character(),
dose=character(),
dose_interval=character(),
severity=character(),
description=character(),
adversity=character(),
reversibility=character(),
extra_info=character(),
stringsAsFactors = FALSE)
assign(Dataset_Names[i],df)
rm(df)
} else {
df=data.frame(identifier=character(),
study_id=character(),
species=character(),
type=character(),
duration=character(),
dose=character(),
dose_interval=character(),
severity=character(),
description=character(),
target=character(),
adversity=character(),
reversibility=character(),
extra_info=character(),
stringsAsFactors = FALSE)
assign(Dataset_Names[i],df)
rm(df)
}
}
rm(Dataset_Names)
# Fill the Datasets
for (i in 1:length(MainData$identifier)) {
#Extra Info needed by the read.entry function
RO=MainData$identifier[i]
StudyId=MainData$study_id[i]
Species=MainData$species[i]
type=MainData$type[i]
Duration=as.character(MainData$duration[i])
Dose=as.character(MainData$dose[i])
Dose_interv=MainData$dose_interval[i]
#Append the body_weight_Dataset
if (grepl("ayes",MainData$body_weight[i])) {
body_weight_Dataset=rbind(body_weight_Dataset,
read.entry(MainData$body_weight[i], RO, StudyId, Species, type ,Duration, Dose, Dose_interv))
MainData$body_weight[i]="ayes"
}else{
if (grepl("yes",MainData$body_weight[i])) {
body_weight_Dataset=rbind(body_weight_Dataset,
read.entry(MainData$body_weight[i], RO, StudyId, Species, type, Duration, Dose, Dose_interv))
MainData$body_weight[i]="yes"
}
}
#Append the body_weight_gain_Dataset
if (grepl("ayes",MainData$body_weight_gain[i])) {
body_weight_gain_Dataset=rbind(body_weight_gain_Dataset,
read.entry(MainData$body_weight_gain[i], RO, StudyId, Species, type, Duration, Dose, Dose_interv))
MainData$body_weight_gain[i]="ayes"
}else{
if (grepl("yes",MainData$body_weight_gain[i])) {
body_weight_gain_Dataset=rbind(body_weight_gain_Dataset,
read.entry(MainData$body_weight_gain[i], RO, StudyId, Species, type, Duration, Dose, Dose_interv))
MainData$body_weight_gain[i]="yes"
}
}
#Append the git_clinical_signs_Dataset
if (grepl("ayes",MainData$git_clinical_signs[i])) {
git_clinical_signs_Dataset=rbind(git_clinical_signs_Dataset,
read.entry(MainData$git_clinical_signs[i], RO, StudyId, Species, type, Duration, Dose, Dose_interv))
MainData$git_clinical_signs[i]="ayes"
}else{
if (grepl("yes",MainData$git_clinical_signs[i])) {
git_clinical_signs_Dataset=rbind(git_clinical_signs_Dataset,
read.entry(MainData$git_clinical_signs[i], RO, StudyId, Species, type, Duration, Dose, Dose_interv))
MainData$git_clinical_signs[i]="yes"
}
}
#Append the neurological_clinical_signs_Dataset
if (grepl("ayes",MainData$neurological_clinical_signs[i])) {
neurological_clinical_signs_Dataset=rbind(neurological_clinical_signs_Dataset,
read.entry(MainData$neurological_clinical_signs[i], RO, StudyId, Species, type, Duration, Dose, Dose_interv))
MainData$neurological_clinical_signs[i]="ayes"
}else{
if (grepl("yes",MainData$neurological_clinical_signs[i])) {
neurological_clinical_signs_Dataset=rbind(neurological_clinical_signs_Dataset,
read.entry(MainData$neurological_clinical_signs[i], RO, StudyId, Species, type, Duration, Dose, Dose_interv))
MainData$neurological_clinical_signs[i]="yes"
}
}
#Append the other_clinical_signs_Dataset
if (grepl("ayes",MainData$other_clinical_signs[i])) {
other_clinical_signs_Dataset=rbind(other_clinical_signs_Dataset,
read.entry(MainData$other_clinical_signs[i], RO, StudyId, Species, type, Duration, Dose, Dose_interv))
MainData$other_clinical_signs[i]="ayes"
}else{
if (grepl("yes",MainData$other_clinical_signs[i])) {
other_clinical_signs_Dataset=rbind(other_clinical_signs_Dataset,
read.entry(MainData$other_clinical_signs[i], RO, StudyId, Species, type, Duration, Dose, Dose_interv))
MainData$other_clinical_signs[i]="yes"
}
}
#Append the cardiovascular_effects dataset
if (grepl("ayes",MainData$cardiovascular_effects[i])) {
cardiovascular_effects_Dataset=rbind(cardiovascular_effects_Dataset,
read.entry(MainData$cardiovascular_effects[i], RO, StudyId, Species, type, Duration, Dose, Dose_interv))
MainData$cardiovascular_effects[i]="ayes"
}else{
if (grepl("yes",MainData$cardiovascular_effects[i])) {
cardiovascular_effects_Dataset=rbind(cardiovascular_effects_Dataset,
read.entry(MainData$cardiovascular_effects[i], RO, StudyId, Species, type, Duration, Dose, Dose_interv))
MainData$cardiovascular_effects[i]="yes"
}
}
#Append the macroscopic_Dataset
#If there exists one finding that is adverse, in the main Dataset you will have "ayes"
if (grepl("ayes",MainData$macroscopic[i])) {
macroscopic_Dataset=rbind(macroscopic_Dataset,
read.entry(MainData$macroscopic[i], RO, StudyId, Species, type, Duration, Dose, Dose_interv,target=MainData$macroscopic_target[i]))
MainData$macroscopic[i]="ayes"
}else{
if (grepl("yes",MainData$macroscopic[i])) {
macroscopic_Dataset=rbind(macroscopic_Dataset,
read.entry(MainData$macroscopic[i], RO, StudyId, Species, type, Duration, Dose, Dose_interv,target=MainData$macroscopic_target[i]))
MainData$macroscopic[i]="yes"
}
}
#Append the organ_weight_Dataset
#If there exists one finding that is adverse, in the main Dataset you will have "ayes"
if (grepl("ayes",MainData$organ_weight[i])) {
organ_weight_Dataset=rbind(organ_weight_Dataset,
read.entry(MainData$organ_weight[i], RO, StudyId, Species, type, Duration, Dose, Dose_interv,target=MainData$organ_weight_target[i]))
MainData$organ_weight[i]="ayes"
}else{
if (grepl("yes",MainData$organ_weight[i])) {
organ_weight_Dataset=rbind(organ_weight_Dataset,
read.entry(MainData$organ_weight[i], RO, StudyId, Species, type, Duration, Dose, Dose_interv,target=MainData$organ_weight_target[i]))
MainData$organ_weight[i]="yes"
}
}
}
#Drop the targets from the main dataset
drops=c("macroscopic_target","organ_weight_target")
MainData=MainData[,!(names(MainData) %in% drops)]
##################################################################################################################################################
# Read Pathology Dataset
PathologyData=read.delim(PathologyData_file,sep = " ", dec = ".",header = TRUE, stringsAsFactors = FALSE)
#Delete any whitespaces in the beginning and end of the entries
PathologyData=apply(PathologyData,2,trimws)
PathologyData=as.data.frame(PathologyData,stringsAsFactors = FALSE)
#Adding type
PathologyData=PathologyData %>% add_column(type=MainData$type[match(PathologyData$study_id,MainData$study_id)],.before="duration")
#Replace NA in the recovery column with na
PathologyData$reversible=replace_na(PathologyData$reversible,"na")
#Initialise the dataset
pathology_Dataset=data.frame(identifier=character(),
study_id=character(),
species=character(),
type=character(),
duration=character(),
dose=character(),
dose_interval=character(),
severity=character(),
description=character(),
target=character(),
adversity=character(),
reversibility=character(),
extra_info=character(),
stringsAsFactors = FALSE)
for (i in 1:length(PathologyData$study_id)) {
pathology_Dataset=rbind(pathology_Dataset,
read.pathology.entry(PathologyData[i,]))
}
rm(PathologyData)
#################################################################################################################################################
#Define the data list
Data=list(MainData,body_weight_Dataset,body_weight_gain_Dataset,neurological_clinical_signs_Dataset,
git_clinical_signs_Dataset,other_clinical_signs_Dataset,macroscopic_Dataset,organ_weight_Dataset,cardiovascular_effects_Dataset, pathology_Dataset)
names(Data)=c("MainData","body_weight_Dataset","body_weight_gain_Dataset","neurological_clinical_signs_Dataset",
"git_clinical_signs_Dataset","other_clinical_signs_Dataset","macroscopic_Dataset","organ_weight_Dataset","cardiovascular_effects_Dataset","pathology_Dataset")
###################################################################################################################################################
# Define the category that each study belongs to. Possible values are (short, middle, long)
for (key in names(Data)) {
Data[[key]]$duration = as.numeric(Data[[key]]$duration)
Data[[key]] = Data[[key]] %>% mutate(group=cut(duration, breaks=c(0,7,17,60), labels=c("short","middle","long")))
}
#Remove the studies of the RNA molecules
for (key in names(Data)) {
Data[[key]] = Data[[key]] %>% filter(type!="rm")
}
#Create the Adjusted_Doses column:
for (key in names(Data)) {
#Make them numerical, solve complex doses and different doses for males/females
Data[[key]]=ChangeDose_Fun(Data[[key]])
#Adjust for dose interval, find the equivalent dose if the dose_interval= day
Data[[key]]=AdjDose_intervalFun(Data[[key]])
}
##################################################################################################################################################
return(Data)
}