-
Notifications
You must be signed in to change notification settings - Fork 1
/
SendTrialDomains.R
418 lines (403 loc) · 13.7 KB
/
SendTrialDomains.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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
# These functions work together with the SendDataFactory
# convert ISO duration to days
DUR_to_days <- function(duration) {
DUR_to_seconds(duration)/(24*3600)
}
isControl <- function(theGroup) {
# return if this group has control in its name
grepl(toupper("control"),toupper(theGroup))
}
getTrialSetInfoCount <- function(theGroup) {
# return number of trial set information rows per set
iCount <- 10
if (!isControl(theGroup)) {iCount <- iCount -1}
iCount
}
trialSetInfo <- function(iParam,whichColumn,theArm,theSetName,theGroup,isTK,numMales,numFemales,DoseFromFile) {
txcodes <- c(
"ARMCD",
"SPGRPCD",
"GRPLBL",
"SETLBL",
"TRTDOS",
"TRTDOSU",
"TCNTRL",
"TKDESC",
"PLANMSUB",
"PLANFSUB")
txnames <- c(
"Arm Code",
"Sponsor-Defined Group Code",
"Group Label",
"Set Label",
"Dose Level",
"Dose Units",
"Control Type",
"Toxicokinetic Description",
"Planned Number of Male Subjects",
"Planned Number of Female Subjects")
# skip control parameter if not a control group
if (!isControl(theGroup)&&iParam>=7) { iParam <- iParam+1}
# return values for parameters
if (whichColumn==1) { # code
txcodes[iParam]
} else if (whichColumn==2) { # name
txnames[iParam]
} else { # value
if (iParam==1) {theArm}
else if (iParam==2) {theArm}
else if (iParam==3) {unique(taOut$ARM)[theArm]}
else if (iParam==4) {theSetName}
# assumes males and females same dose level
else if (iParam==5) {DoseFromFile$Male.dose.level[theArm]}
else if (iParam==6) {as.character(DoseFromFile$Male.dose.units[theArm])}
else if (iParam==7) { # control type
theGroup }
else if (iParam==8) {
if (isTK) { "TK"
} else {"NONTK"}
}
else if (iParam==9) {
numMales}
else {numFemales }
} # end of value else
}
#
setTSFile <- function(input) {
# create data frame based on structure
aDomain <- "TS"
theColumns <- dfSENDIG[dfSENDIG$Domain==aDomain,]$Column
theLabels <- dfSENDIG[dfSENDIG$Domain==aDomain,]$Label
tsOut <<- setNames(data.frame(matrix(ncol = length(theColumns), nrow = 1)),
theColumns
)
aRow <- 1
if (!is.null(input$testArticle)) {
tsOut[aRow,] <<- list(input$studyName,
aDomain,
aRow,
"",
"TRT",
"Investigational Therapy or Treatment",
input$testArticle,
"")
aRow <- aRow + 1
}
if (!is.null(input$species)) {
tsOut[aRow,] <<- list(input$studyName,
aDomain,
aRow,
"",
"SPECIES",
"Species",
input$species,
"")
aRow <- aRow + 1
}
if (!is.null(input$studyType)) {
tsOut[aRow,] <<- list(input$studyName,
aDomain,
aRow,
"",
"SSTYP",
"Study Type",
input$studyType,
"")
aRow <- aRow + 1
}
if (!is.null(input$CTSelection)) {
tsOut[aRow,] <<- list(input$studyName,
aDomain,
aRow,
"",
"SNDCTVER",
"SEND Controlled Terminology Version",
paste("SEND Terminology",input$CTSelection),
"")
aRow <- aRow + 1
}
if (!is.null(input$SENDVersion)) {
tsOut[aRow,] <<- list(input$studyName,
aDomain,
aRow,
"",
"SNDIGVER",
"SEND Implementation Guide Version",
str_to_upper(paste("SEND Implementation Guide Version",input$SENDVersion)),
"")
aRow <- aRow + 1
}
if (!is.null(input$strain)) {
tsOut[aRow,] <<- list(input$studyName,
aDomain,
aRow,
"",
"STRAIN",
"Strain/Substrain",
input$strain,
"")
aRow <- aRow + 1
}
# calculate animals per group
animalsCount <- length(input$sex)*length(input$treatment)*(as.integer(input$TKanimalsPerGroup)+as.integer(input$animalsPerGroup))
printDebug(paste("Total number of animals",length(input$sex),length(input$treatment),as.integer(input$TKanimalsPerGroup),as.integer(input$animalsPerGroup)))
tsOut[aRow,] <<- list(input$studyName,
aDomain,
aRow,
"",
"SPLANSUB",
"Planned Number of Subjects",
animalsCount,
"")
aRow <- aRow + 1
if (!is.null(input$sex)) {
if (length(input$sex)==2) {
theSEXPOP <- "BOTH"
}
else {
theSEXPOP <- input$sex[1]
}
tsOut[aRow,] <<- list(input$studyName,
aDomain,
aRow,
"",
"SEXPOP",
"Sex of Participants",
theSEXPOP,
"")
aRow <- aRow + 1
}
# Add in the other TS values
for(index in 1:nrow(TSFromFile)) {
tsOut[aRow,] <<- list(input$studyName,
aDomain,
aRow,
"",
as.character(TSFromFile$TSPARMCD[index]),
as.character(TSFromFile$TSPARM[index]),
as.character(TSFromFile$TSVAL[index]),
"")
aRow <- aRow + 1
}
# fix to numeric the sequence
tsOut$TSSEQ <<- as.numeric(tsOut$TSSEQ)
# set labels for each field
index <- 1
for (aColumn in theColumns) {
Hmisc::label(tsOut[[index]]) <<- theLabels[index]
index <- index + 1
}
tsOut <<- tsOut[, checkCore(tsOut)]
printDebug(" TS domain made: ")
printDebug(tsOut)
# add to set of data
addToSet("TS","TRIAL SUMMARY","tsOut")
}
setTEFile <- function(input) {
# create data frame based on structure
aDomain <- "TE"
theColumns <- dfSENDIG[dfSENDIG$Domain==aDomain,]$Column
theLabels <- dfSENDIG[dfSENDIG$Domain==aDomain,]$Label
tOut <<- setNames(data.frame(matrix(ncol = length(theColumns), nrow = 1)),
theColumns
)
aRow <- 1
# create element for pretreatment
if ("Pre-treatment" %in% input$elementOptions ) {
tOut[aRow,] <<- list(input$studyName,
aDomain,
"SCRN",
"Screen",
"Start of Pretreatment",
# FIXME - make lenth of pretreatment variable
paste(1,"week after start of Element"),
paste("P",7,"D",sep=""))
aRow <- aRow + 1
}
# create element for dosing phases
iCount <- 1
for (iDose in input$treatment) {
# read duration from DOSDUR in tsOUT
duration <- tsOut[tsOut$TSPARMCD=="DOSDUR","TSVAL"]
iDays <- DUR_to_days(duration)
tOut[aRow,] <<- list(input$studyName,
aDomain,
paste("TRT0",iCount,sep=""),
iDose,
paste("Start of",iDose),
paste(iDays,"days after start of Element"),
duration
)
iCount <- iCount + 1
aRow <- aRow + 1
}
if ("Recovery" %in% input$elementOptions ) {
tOut[aRow,] <<- list(input$studyName,
aDomain,
"RECOVERY",
"Recovery period",
"Start of Recovery period",
# FIXME - make lenth of recovery variable
paste(7,"days after start of Element"),
paste("P",7,"D",sep=""))
aRow <- aRow + 1
}
# save final
tOut <<- setSENDNumeric(tOut)
# set labels for each field
index <- 1
for (aColumn in theColumns) {
Hmisc::label(tOut[[index]]) <<- theLabels[index]
index <- index + 1
}
teOut <<- tOut[, checkCore(tOut)]
# add to set of data
addToSet("TE","TRIAL ELEMENTS","teOut")
}
setTAFile <- function(input) {
# create data frame based on structure
aDomain <- "TA"
theColumns <- dfSENDIG[dfSENDIG$Domain==aDomain,]$Column
theLabels <- dfSENDIG[dfSENDIG$Domain==aDomain,]$Label
tOut <<- setNames(data.frame(matrix(ncol = length(theColumns), nrow = 1)),
theColumns
)
# assume 1 arm per dose group, first one is control
nArm <- 1
aRow <- 1
for (iDose in input$treatment) {
# within the arm, add treatment row if existing
anElement <- 1
armName <- iDose
screenElement <- 0
isRecovery <- FALSE
if ("Recovery" %in% input$elementOptions ) {isRecovery<-TRUE}
if (nArm == 1) { armName <- "Control"}
if ("Pre-treatment" %in% input$elementOptions ) {
tOut[aRow,] <<- list(input$studyName,
aDomain,
nArm,
armName,
anElement,
teOut$ETCD[1],
teOut$ELEMENT[1],
paste("Randomized to Group",nArm),
"","Screen"
)
aRow <- aRow + 1
screenElement <- 1
anElement <- anElement + 1
}
TaBranch <- ""
if (isRecovery) TaBranch <- "Start of Recovery"
# within the arm, add the matching treatment row
tOut[aRow,] <<- list(input$studyName,
aDomain,
nArm,
armName,
anElement,
teOut$ETCD[nArm+screenElement],
teOut$ELEMENT[nArm+screenElement],
TaBranch,
"","Treatment"
)
aRow <- aRow + 1
anElement <- anElement + 1
if ("Recovery" %in% input$elementOptions ) {
tOut[aRow,] <<- list(input$studyName,
aDomain,
as.character(nArm),
armName,
anElement,
teOut$ETCD[nrow(teOut)],
teOut$ELEMENT[nrow(teOut)],
"",
"","Recovery"
)
aRow <- aRow + 1
anElement <- anElement + 1
} # recovery need check
nArm <- nArm+1
} # treatment count loop
# save final
tOut <<- setSENDNumeric(tOut)
# set labels for each field
index <- 1
for (aColumn in theColumns) {
Hmisc::label(tOut[[index]]) <<- theLabels[index]
index <- index + 1
}
taOut <<- tOut[, checkCore(tOut)]
# add to set of data
addToSet("TA","TRIAL ARMS","taOut")
}
setTXFile <- function(input) {
# create data frame based on structure
aDomain <- "TX"
theColumns <- dfSENDIG[dfSENDIG$Domain==aDomain,]$Column
theLabels <- dfSENDIG[dfSENDIG$Domain==aDomain,]$Label
tOut <<- setNames(data.frame(matrix(ncol = length(theColumns), nrow = 1)),
theColumns
)
# assume 1 set per dosage group, double if TK
nSet <- 1
nArm <- 1
aRow <- 1
# assume for now no spare animals, and have males and females
numGroups <- length(unique(taOut$ARM))
numMales <- as.integer(input$animalsPerGroup)
numFemales <- as.integer(input$animalsPerGroup)
numMalesTK <- as.integer(input$TKanimalsPerGroup)
numFemalesTK <- as.integer(input$TKanimalsPerGroup)
for (theGroup in input$treatment) {
# within the arm, add treatment row if existing
hasTK <- FALSE
if (as.integer(input$TKanimalsPerGroup)>0 ) {hasTK<-TRUE}
# within the set, add the matching treatment rows
theArm <- unique(taOut$ARM)[nArm]
name <- theArm
if (hasTK) { name <- paste(theArm,", Non-TK",sep="") }
# non TK first
for (iLoop in 1:getTrialSetInfoCount(theGroup)) {
tOut[aRow,] <<- list(input$studyName,
aDomain,
as.character(nSet),
name,
aRow,
trialSetInfo(iLoop,1,nArm,name,theGroup,FALSE,numMales,numFemales,DoseFromFile),
trialSetInfo(iLoop,2,nArm,name,theGroup,FALSE,numMales,numFemales,DoseFromFile),
trialSetInfo(iLoop,3,nArm,name,theGroup,FALSE,numMales,numFemales,DoseFromFile)
)
aRow <- aRow + 1
} # iLoop
nSet <- nSet+1
if (hasTK) {
name <- paste(theArm,", TK",sep="")
for (iLoop in 1:getTrialSetInfoCount(theGroup)) {
tOut[aRow,] <<- list(input$studyName,
aDomain,
as.character(nSet),
name,
aRow,
trialSetInfo(iLoop,1,nArm,name,theGroup,TRUE,numMalesTK,numFemalesTK,DoseFromFile),
trialSetInfo(iLoop,2,nArm,name,theGroup,TRUE,numMalesTK,numFemalesTK,DoseFromFile),
trialSetInfo(iLoop,3,nArm,name,theGroup,TRUE,numMalesTK,numFemalesTK,DoseFromFile)
)
aRow <- aRow + 1
} # iLoop
nSet <- nSet+1
} # hasTK
nArm <- nArm+1
} # treatment count loop
# save final
tOut <<- setSENDNumeric(tOut)
# set labels for each field
index <- 1
for (aColumn in theColumns) {
Hmisc::label(tOut[[index]]) <<- theLabels[index]
index <- index + 1
}
txOut <<- tOut[, checkCore(tOut)]
# add to set of data
addToSet("TX","TRIAL SETS","txOut")
}