Skip to content

Commit

Permalink
version 0.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
philipdelff authored and cran-robot committed Nov 29, 2023
1 parent 31d8d51 commit a42f9d5
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 30 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: NMsim
Type: Package
Title: Seamless 'Nonmem' Simulation Platform
Version: 0.0.5
Version: 0.0.6
Authors@R: c(person("Philip", "Delff", email = "philip@delff.dk",role = c("aut","cre")),
person("Matthew","Fidler", role = c("ctb"), email = "matt.fidler@novartis.com", comment="Co-author on NMreadCov"))
Maintainer: Philip Delff <philip@delff.dk>
Expand All @@ -17,8 +17,8 @@ BugReports: https://github.com/philipdelff/NMsim/issues
Language: en-US
URL: https://philipdelff.github.io/NMsim/
NeedsCompilation: no
Packaged: 2023-11-11 03:18:52 UTC; philipde
Packaged: 2023-11-28 17:08:37 UTC; philipde
Author: Philip Delff [aut, cre],
Matthew Fidler [ctb] (Co-author on NMreadCov)
Repository: CRAN
Date/Publication: 2023-11-11 07:03:20 UTC
Date/Publication: 2023-11-28 17:40:13 UTC
16 changes: 8 additions & 8 deletions MD5
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
80f80a8763b66ad609580ab3e4a441bf *DESCRIPTION
6343c01859d5d9119ad8bc5671cd6e28 *DESCRIPTION
1b54f9d1f7f1b5d3cc24b43761e6e90b *LICENSE
2dfb3022020fd50053ac2af4f2abddbe *NAMESPACE
54b08c5fde8128e15ecf15ddb67f3b74 *NEWS
b4a9a2f6496599b0b4f79c69e2f18378 *NEWS
ab9edb832f4f5394db40a1d39900bc6a *R/NMcreateDoses.R
81d79fa0b5359930eeb29ab75601f17d *R/NMcreateMatLines.R
9b54ad1926973ae8cda755ccb8278eba *R/NMexec.R
a2f74e642414acc0744a2f00302d0c0d *R/NMexecDirectory.R
8a40d137cc85eeafd76ece075d72b8d7 *R/NMexecDirectory.R
b5e6f443d760fd80a3345c48423e9c52 *R/NMgenPNM.R
0b82153826c79fa0622eaf658ea31010 *R/NMreadCov.R
8c46a875e27f14cf9a7eb7fe59be9874 *R/NMreadExt.R
1164a25c2ab913bdf549d1af21ddc2d3 *R/NMreadPhi.R
6dc7073222fe7bea84fa8cf009c72c29 *R/NMreplaceInits.R
b90ede35a11351ec080eac38adf61cf2 *R/NMsim.R
b24408dc9d89d947577b3e7e4b84ba9b *R/NMsim.R
73e97d663ae5eb7965c3b30b6c18faa7 *R/NMsim_VarCov.R
b279eadc10000d2e41ddd11d0bee4e81 *R/NMsim_asis.R
c209a4e65f8fde544a21ce69350eb04f *R/NMsim_default.R
f5338e5ef5d13c04eec1a19b87336777 *R/NMsim_known.R
c4a42c15e583046a0cdf83c11d993e1c *R/NMsim_known.R
c5fcc3a06f3ae11cf4146535ce158e83 *R/NMsim_typical.R
41bdb6a5b812615848a93e739bafa0eb *R/NMupdateInits.R
b2a62935425686c940e129942e00eba3 *R/addEVID2.R
5ff78774a99ef240ffcc0c02b590550a *R/addEVID2.R
cf90fd720fbe3d25d94f616feb764c3d *R/addResVar.R
ca1179f1353377c3077c25307eba1681 *R/checkTimes.R
e0818cb996859906370f76bc143bf62e *R/dt2mat.R
21405a4362ef69a4d98b600be490217e *R/dtapply.R
81947395c5ae449f58ad0b61276ad3da *R/findUpdated.R
5ac111236ed50b6c1d1ef1fbd2f62db2 *R/genPhiFile.R
0d73892a6482f6ea294f814b4364e7bc *R/genPhiFile.R
b9757c44d15df0702c8e6ae0bd5151ca *R/getSystemType.R
cc8507539ec1a557df0af3d1846a33a5 *R/inputArchive.R
8cf7e8f024fe63a2e3e4036ffa0e8673 *R/simpleCharArg.R
Expand Down Expand Up @@ -104,7 +104,7 @@ b23b9bf17b6d2d7c43ea4ed4bd248018 *man/NMreadCov.Rd
521a7c765013ae049a5032c36aae67d3 *man/NMreadExt.Rd
110fc8580de020bd0c120578ca40051c *man/NMreadPhi.Rd
ec65765f523b467907e104521acbba96 *man/NMreplaceInits.Rd
273d112fa61cf3eca47b1b586f0818d2 *man/NMsim.Rd
c5cd376bf1ccc55da4a34bfe272d610a *man/NMsim.Rd
bb63b50e8717016df83cd8913179665a *man/NMsim_VarCov.Rd
fa13000cd9814908ac0fc3dc82040d85 *man/NMsim_asis.Rd
ab5f546b765ab2ddb90a399bc642d903 *man/NMsim_default.Rd
Expand Down
13 changes: 13 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# 0.0.6
## New features

* Support for parallelization of simulations added when using PSN. It
used to be possible to run multiple simulations simultaneously in
separate threads. Now single simulation runs can be parallelized on
`sge` type clusters (using `qsub`). See arguments `sge` and `nc`.

## Bugfixes

* A simple mistake would create problems in `genPhiFile()` when having
more than 10 ETAs in a model. Now fixed.

# 0.0.5
## New features

Expand Down
4 changes: 3 additions & 1 deletion R/NMexecDirectory.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ NMexecDirectory <- function(file.mod,path.nonmem,files.needed,dir.data=".."){
file.copy(extr.data$path.csv,dir.tmp)
### modify .mod to use local copy of input data. Notice the newfile
### arg to NMwriteSection creating file.mod.tmp.

sec.data.new <- paste("$DATA",sub(extr.data$string,basename(extr.data$path.csv),extr.data$DATA,fixed=TRUE))
} else {
### This works with NMsim but not with estimation.
### This works with NMsim but not with estimation.

sec.data.new <- sub(extr.data$string,file.path(dir.data,basename(extr.data$path.csv)),extr.data$DATA,fixed=TRUE)
### this is a different interpretation of dir.data - ie. the relative change of path. It does not work.
## sec.data.new <- sub(extr.data$string,file.path(dir.data,extr.data$path.csv),extr.data$DATA,fixed=TRUE)
Expand Down
23 changes: 15 additions & 8 deletions R/NMsim.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@
##' @param col.row Only used if data is not supplied (which is most
##' likely for simulations for VPCs) A column name to use for a
##' row identifier. If none is supplied,
##' \code{NMdataConf()[['col.row']]} will be used. If the column already exists in the data set, it will be used as is, if not it will be added.
##' \code{NMdataConf()[['col.row']]} will be used. If the column
##' already exists in the data set, it will be used as is, if not
##' it will be added.
##' @param method.execute Specify how to call Nonmem. Options are
##' "psn" (PSN's execute), "nmsim" (an internal method similar to
##' PSN's execute), and "direct" (just run Nonmem directly and
Expand All @@ -94,6 +96,8 @@
##' is in the system search path. So as long as you know where
##' your Nonmem executable is, "nmsim" is recommended. The default
##' is "nmsim" if path.nonmem is specified, and "psn" if not.
##' @param nc Number of cores used in parallelization. This is so far
##' only supported with \code{method.execute="psn"}.
##' @param method.update.inits The initial estimates must be updated
##' from the estimated model before running the simulation. NMsim
##' supports two ways of doing this: "psn" which uses PSN's
Expand Down Expand Up @@ -226,7 +230,8 @@ NMsim <- function(file.mod,data,dir.sims, name.sim,
table.options,
text.sim="",
method.sim=NMsim_default,
execute=TRUE,sge=FALSE,transform=NULL,
execute=TRUE,sge=FALSE,
nc=1,transform=NULL,
method.execute,method.update.inits,create.dir=TRUE,dir.psn,
list.sections,sim.dir.from.scratch=TRUE,
col.row,
Expand Down Expand Up @@ -425,6 +430,7 @@ NMsim <- function(file.mod,data,dir.sims, name.sim,
text.sim=text.sim,
execute=execute,
sge=sge
,nc=nc
## ,modelname=modelname
,transform=transform
,method.sim=method.sim
Expand Down Expand Up @@ -527,7 +533,7 @@ NMsim <- function(file.mod,data,dir.sims, name.sim,
col.row <- NMdata:::NMdataDecideOption("col.row",col.row)
if(!col.row %in% colnames(data)){
data[,(col.row):=.I]
message(paste0("Row counter was added in column",col.row,". Use this to merge output and input data."))
message(paste0("Row counter was added in column ",col.row,". Use this to merge output and input data."))
}
args.NMscanData.default$merge.by.row <- TRUE
args.NMscanData.default$col.row <- col.row
Expand Down Expand Up @@ -568,7 +574,7 @@ NMsim <- function(file.mod,data,dir.sims, name.sim,

dt.models[,
{
cmd.update <- sprintf("%s --output_model=\"%s\" \"%s\"",normalizePath(cmd.update.inits),fn.sim.tmp,normalizePath(file.mod))
cmd.update <- sprintf("%s --output_model=\"%s\" \"%s\"",normalizePath(cmd.update.inits,mustWork=FALSE),fn.sim.tmp,normalizePath(file.mod))
### would be better to write to another location than next to estimation model
## cmd.update <- sprintf("%s --output_model=%s %s",cmd.update.inits,file.path(".",fn.sim.tmp),file.mod)

Expand Down Expand Up @@ -602,10 +608,11 @@ NMsim <- function(file.mod,data,dir.sims, name.sim,
dt.models[,{

nmtext <- NMwriteData(data,file=path.data,quiet=TRUE,args.NMgenText=list(dir.data="."),script=script)
## input
NMdata:::NMwriteSectionOne(file0=path.sim,list.sections = nmtext["INPUT"],backup=FALSE,quiet=TRUE)
## data

## input
NMdata:::NMwriteSectionOne(file0=path.sim,list.sections = nmtext["INPUT"],backup=FALSE,quiet=TRUE)
if(rewrite.data.section){
## data
NMdata:::NMwriteSectionOne(file0=path.sim,list.sections = nmtext["DATA"],backup=FALSE,quiet=TRUE)
} else {
## replace data file only
Expand Down Expand Up @@ -819,7 +826,7 @@ NMsim <- function(file.mod,data,dir.sims, name.sim,
unlink(path.sim.lst)

}
NMexec(files=path.sim,sge=sge,nc=1,wait=wait,args.psn.execute=args.psn.execute,nmquiet=nmquiet,method.execute=method.execute,path.nonmem=path.nonmem,dir.psn=dir.psn,files.needed=files.needed.n,input.archive=input.archive,system.type=system.type)
NMexec(files=path.sim,sge=sge,nc=nc,wait=wait,args.psn.execute=args.psn.execute,nmquiet=nmquiet,method.execute=method.execute,path.nonmem=path.nonmem,dir.psn=dir.psn,files.needed=files.needed.n,input.archive=input.archive,system.type=system.type)

if(wait){
args.NMscanData <- c(args.NMscanData,args.NMscanData.default)
Expand Down
10 changes: 5 additions & 5 deletions R/NMsim_known.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


NMsim_known <- function(file.sim,file.mod,data.sim,file.phi,return.text=FALSE){

#### Section start: Dummy variables, only not to get NOTE's in pacakge checks ####

. <- NULL
Expand Down Expand Up @@ -96,11 +96,11 @@ NMsim_known <- function(file.sim,file.mod,data.sim,file.phi,return.text=FALSE){
}


###### using the last table found in .phi to generate lines for a new .phi file. Reading this should be done with NMreadPhi.
###### using the last table found in .phi to generate lines for a new .phi file.
phi.lines <- data.table(text=readLines(file.phi))
phi.lines[,n:=.I]
## Accepting E and R which can be in numbers (R?)
phi.lines[,is.data:=!grepl("[a-zABCDFGHIJKLMNOPQSTUVWXYZ]",x=text)]
phi.lines[,is.data:=!grepl("[abcdfghijklmnopqrstuvwxyzABCDFGHIJKLMNOPQSTUVWXYZ]",x=text)]
phi.lines[is.data==TRUE,textmod:=gsub(" +"," ",text)]
phi.lines[is.data==TRUE,textmod:=gsub("^ +","",textmod)]
phi.lines[is.data==TRUE,ID:=strsplit(textmod,split=" ")[[1]][2],by=.(n)]
Expand All @@ -111,12 +111,12 @@ NMsim_known <- function(file.sim,file.mod,data.sim,file.phi,return.text=FALSE){
phi.lines[,TABLE.NO:=cumsum(tableStart)]
phi.lines <- phi.lines[TABLE.NO==max(TABLE.NO)]

phi.use <- mergeCheck(dt.id.order[,.(ID)],phi.lines[,.(ID,text)],by=cc(ID),all.x=TRUE)
phi.use <- mergeCheck(dt.id.order[,.(ID)],phi.lines[,.(ID,text)],by=cc(ID),all.x=TRUE,quiet=TRUE)


### Error if subjects in data are not found in phi
if(phi.use[,any(is.na(text))]){
message("IDs not found in nonmem results (phi file):", paste(phi.use[is.na(text),ID],collapse=", "))
message("IDs not found in nonmem results (phi file): ", paste(phi.use[is.na(text),ID],collapse=", "))
phi.use <- phi.use[!is.na(text)]
}
phi.use <- rbind(phi.lines[is.data==FALSE,.(text)],phi.use,fill=TRUE)
Expand Down
4 changes: 2 additions & 2 deletions R/addEVID2.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@


addEVID2 <- function(doses,time.sim,CMT,as.fun){

#### Section start: Dummy variables, only not to get NOTE's in pacakge checks ####

EVID <- NULL
Expand Down Expand Up @@ -91,7 +91,7 @@ addEVID2 <- function(doses,time.sim,CMT,as.fun){
CMT <- as.data.table(CMT)
}


dt.obs <- dt.obs[,setdiff(colnames(dt.obs),colnames(CMT)),with=FALSE]
dt.obs <- egdt(dt.obs,CMT,quiet=TRUE)


Expand Down
10 changes: 8 additions & 2 deletions R/genPhiFile.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
##' @import data.table
##' @export



genPhiFile <- function(data,file){
## if(missing(file)) file <- NULL


name.eta.phi <- NULL
name.tab <- NULL
SUBJECT_NO <- NULL

Expand All @@ -25,11 +29,13 @@ genPhiFile <- function(data,file){
dt.names <- data.table(
name.tab = cnames.covs[grepl(pattern="ET[A]*[1-9][0-9]*",cnames.covs)]
)
dt.names[,I:=sub("ET[A]([1-9][0-9]*)","\\1",name.tab) |> as.numeric()]
dt.names[,I:=sub("ET[A]*([1-9][0-9]*)","\\1",name.tab) |> as.numeric()]
dt.names[,name.eta.phi:=sprintf("ETA(%s)",I)]
setorder(dt.names,I)


dt.etas <- dt.covs[,c("ID",dt.names$name.tab),with=FALSE]
setnames(dt.etas,dt.names$name.tab,dt.names$name.eta.phi)
dt.etas[,SUBJECT_NO:=.I]
setcolorder(dt.etas,"SUBJECT_NO")

Expand Down
8 changes: 7 additions & 1 deletion man/NMsim.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a42f9d5

Please sign in to comment.