Open-Systems-Pharmacology / PK-Sim

PK-Sim® is a comprehensive software tool for whole-body physiologically based pharmacokinetic modeling
Other
103 stars 50 forks source link

createIndividual: Age should be required for human #1453

Closed moPellowe closed 4 years ago

moPellowe commented 4 years ago

I am trying to create an individual, but the function createIndividualCharacteristics() isn't working as I expected. What do I need to do differently?

> library(ospsuite)
> simFilePath <- file.path(getwd(), paste0("Simulation 1.pkml"), fsep = .Platform$file.sep)
> sim <- loadSimulation(simFilePath)
> individual_chars <- createIndividualCharacteristics(species = Species$Human,
+                                                     population = HumanPopulation$WhiteAmerican_NHANES_1997,
+                                                     gender = Gender$Male,
+                                                     weight = 175, weightUnit = "lbs",
+                                                     height = 70, heightUnit = "in")
Error in file.exists(pathToAdd) : invalid 'file' argument
> individual_chars <- createIndividualCharacteristics(species = Species$Human, weight = 75)
Error in file.exists(pathToAdd) : invalid 'file' argument
> individual_chars <- createIndividualCharacteristics()
Error in file.exists(pathToAdd) : invalid 'file' argument
> 
msevestre commented 4 years ago

This function requires PK-Sim v9 to be installed on the system, which you do not have because it has not been released yet.

You can try to install the portable version and then specify explicitly the path of the pksim install dir

see example here https://github.com/Open-Systems-Pharmacology/OSPSuite-R/blob/develop/tests/dev/script-create-individual.R#L4

Also note that the suite only support the metric system. Weight in lbs and height in inches will throw an error

Error in file.exists(pathToAdd) : invalid 'file' argument

This is kind of surprising nonetheless. DO you hve the file.exists method available on your machine?

moPellowe commented 4 years ago

Yes, I have the file.exists method built into R.

Do you know when PK-Sim v9 will be released?

msevestre commented 4 years ago

Official v9 probably end of April. But this was before the whole world went into chaos. In the meantime, you can download the portable version and initialize the Path as I did in the example

Portable can be found here http://pk-sim-portable.open-systems-pharmacology.org/

It's a zip file. Unzip it and use this folder in the initPKSim method see https://github.com/Open-Systems-Pharmacology/OSPSuite-R/blob/develop/tests/dev/script-create-individual.R#L4

Note: If you get somekind of weird error with, please paste here. Both packages are in development and it is possible that something does not fit anymore. This will be fixed obviously in the release

msevestre commented 4 years ago

Note to self: We need to make sure we show a better error when PKsim is not found. In this case, pathToAdd is null and the function crashes.

moPellowe commented 4 years ago

I downloaded the portable version of PK-Sim and used initPKSim() to initialize the path. createIndividualCharacteristics() worked as expected. Note that the error about the incorrect units doesn't show up in createIndividualCharacteristics() but in createIndividual() when I try to create the individual with the imperial units.

After fixing the units, I tried running createIndividual() and it inconsistently shows an error when running the command. Sometimes it works, and sometimes it doesn't without any changes. What am I missing?

>     library(ospsuite)
>     ## Load simulation
>     simFilePath <- file.path(getwd(), paste0("bupropion_SR_150mg.pkml"), fsep = .Platform$file.sep)
>     sim <- loadSimulation(simFilePath)
> individual_chars <- createIndividualCharacteristics(species = Species$Human,
+ population = HumanPopulation$WhiteAmerican_NHANES_1997,
+ gender = Gender$Male,
+ weight = 60, weightUnit = "kg",
+ height = 180, heightUnit = "cm")
> individual <- createIndividual(individual_chars)
Error in rClr::clrCall(individualFactory, "CreateIndividual", individualCharacteristics$ref) : 
  Type:    PKSim.Core.Services.CannotCreateIndividualWithConstraintsException
Message: Could not create individuals with given constraint:

Method:  Void optimizeVolumes(PKSim.Core.Model.Individual, OSPSuite.Core.Maths.Random.RandomGenerator)
Stack trace:
   at PKSim.Core.Services.CreateIndividualAlgorithm.optimizeVolumes(Individual individual, RandomGenerator randomGenerator)
   at PKSim.Core.Services.CreateIndividualAlgorithm.distributeParameterFor(Individual individual, RandomGenerator randomGenerator, Action`2 action)
   at PKSim.Core.Services.CreateIndividualAlgorithm.Optimize(Individual individual)
   at PKSim.Core.Model.IndividualFactory.CreateAndOptimizeFor(OriginData originData, Nullable`1 seed)
   at PKSim.R.Services.IndividualFactory.CreateIndividual(IndividualCharacteristics individualCharacteristics)

> individual <- createIndividual(individual_chars)
> View(individual)
> individual
$distributedParameters
$distributedParameters$paths
 [1] "Organism|Hematocrit"                                                      
 [2] "Organism|MeanBW"                                                          
 [3] "Organism|MeanHeight"                                                      
 [4] "Organism|VenousBlood|Volume"                                              
 [5] "Organism|ArterialBlood|Volume"                                            
 [6] "Organism|Bone|Specific blood flow rate"                                   
 [7] "Organism|Bone|Volume"                                                     
 [8] "Organism|Brain|Volume"                                                    
 [9] "Organism|Brain|Specific blood flow rate"                                  
[10] "Organism|Fat|Volume"                                                      
[11] "Organism|Fat|Vf (lipid)"                                                  
[12] "Organism|Fat|Vf (neutral lipid)-PT"                                       
[13] "Organism|Fat|Vf (phospholipid)-PT"                                        
[14] "Organism|Fat|Fraction interstitial"                                       
[15] "Organism|Fat|Vf (water)"                                                  
[16] "Organism|Fat|Vf (water)-PT"                                               
[17] "Organism|Fat|Vf (neutral lipid)-RR"                                       
[18] "Organism|Fat|Vf (neutral lipid)-WS"                                       
[19] "Organism|Fat|Vf (neutral phospholipid)-RR"                                
[20] "Organism|Fat|Vf (neutral phospholipid, plasma)-WS"                        
[21] "Organism|Fat|Vf (extracellular water)-RR"                                 
[22] "Organism|Fat|Vf (intracellular water)-RR"                                 
[23] "Organism|Fat|Vf (water)-WS"                                               
[24] "Organism|Fat|Specific blood flow rate"                                    
[25] "Organism|Gonads|Volume"                                                   
[26] "Organism|Gonads|Specific blood flow rate"                                 
[27] "Organism|Heart|Volume"                                                    
[28] "Organism|Heart|Specific blood flow rate"                                  
[29] "Organism|Kidney|Volume"                                                   
[30] "Organism|Kidney|Age of aging onset"                                       
[31] "Organism|Kidney|Aging half-time"                                          
[32] "Organism|Kidney|GFRmat"                                                   
[33] "Organism|Kidney|Hill coefficient for aging GFR"                           
[34] "Organism|Kidney|Hill coefficient for GFR"                                 
[35] "Organism|Kidney|Maximal decreasing rate factor"                           
[36] "Organism|Kidney|TM50 for GFR"                                             
[37] "Organism|Kidney|Specific blood flow rate"                                 
[38] "Organism|Lumen|Effective surface area variability factor"                 
[39] "Organism|Lumen|Stomach|Distal radius"                                     
[40] "Organism|Lumen|Stomach|Gastric emptying time"                             
[41] "Organism|Lumen|Stomach|GET_alpha (Weibull function) variability factor"   
[42] "Organism|Lumen|Stomach|GET_beta (Weibull function) variability factor"    
[43] "Organism|Lumen|Stomach|Length"                                            
[44] "Organism|Lumen|Stomach|Proximal radius"                                   
[45] "Organism|Lumen|Duodenum|Effective surface area enhancement factor"        
[46] "Organism|Lumen|UpperJejunum|Effective surface area enhancement factor"    
[47] "Organism|Lumen|LowerJejunum|Effective surface area enhancement factor"    
[48] "Organism|Lumen|UpperIleum|Effective surface area enhancement factor"      
[49] "Organism|Lumen|LowerIleum|Effective surface area enhancement factor"      
[50] "Organism|Lumen|Caecum|Effective surface area enhancement factor"          
[51] "Organism|Lumen|ColonAscendens|Effective surface area enhancement factor"  
[52] "Organism|Lumen|ColonTransversum|Effective surface area enhancement factor"
[53] "Organism|Lumen|ColonDescendens|Effective surface area enhancement factor" 
[54] "Organism|Lumen|ColonSigmoid|Effective surface area enhancement factor"    
[55] "Organism|Lumen|Rectum|Effective surface area enhancement factor"          
[56] "Organism|Stomach|Volume"                                                  
[57] "Organism|Stomach|Specific blood flow rate"                                
[58] "Organism|SmallIntestine|Small intestinal transit time"                    
[59] "Organism|SmallIntestine|Volume"                                           
[60] "Organism|SmallIntestine|Specific blood flow rate"                         
[61] "Organism|LargeIntestine|Large intestinal transit time"                    
[62] "Organism|LargeIntestine|Volume"                                           
[63] "Organism|LargeIntestine|Specific blood flow rate"                         
[64] "Organism|Liver|Volume"                                                    
[65] "Organism|Liver|Specific blood flow rate"                                  
[66] "Organism|Lung|Volume"                                                     
[67] "Organism|Lung|Fraction vascular"                                          
[68] "Organism|Muscle|Volume"                                                   
[69] "Organism|Muscle|Vf (lipid)"                                               
[70] "Organism|Muscle|Vf (neutral lipid)-PT"                                    
[71] "Organism|Muscle|Vf (phospholipid)-PT"                                     
[72] "Organism|Muscle|Vf (protein)"                                             
[73] "Organism|Muscle|Vf (water)"                                               
[74] "Organism|Muscle|Vf (water)-PT"                                            
[75] "Organism|Muscle|Fraction interstitial"                                    
[76] "Organism|Muscle|Vf (neutral lipid)-RR"                                    
[77] "Organism|Muscle|Vf (neutral lipid)-WS"                                    
[78] "Organism|Muscle|Vf (neutral phospholipid)-RR"                             
[79] "Organism|Muscle|Vf (neutral phospholipid, plasma)-WS"                     
[80] "Organism|Muscle|Vf (extracellular water)-RR"                              
[81] "Organism|Muscle|Vf (protein)-WS"                                          
[82] "Organism|Muscle|Vf (intracellular water)-RR"                              
[83] "Organism|Muscle|Vf (water)-WS"                                            
[84] "Organism|Muscle|Specific blood flow rate"                                 
[85] "Organism|Pancreas|Volume"                                                 
[86] "Organism|Pancreas|Specific blood flow rate"                               
[87] "Organism|PortalVein|Volume"                                               
[88] "Organism|Skin|Volume"                                                     
[89] "Organism|Skin|Specific blood flow rate"                                   
[90] "Organism|Spleen|Volume"                                                   
[91] "Organism|Spleen|Specific blood flow rate"                                 

$distributedParameters$values
 [1] 4.546460e-01 8.034881e+01 1.784882e+01 1.002279e+00 4.253134e-01 2.749500e-02 1.215768e+01 1.540251e+00 5.167500e-01 1.445445e-01
[11] 8.000000e-01 7.900000e-01 2.000000e-03 1.600000e-01 1.500000e-01 1.800000e-01 8.530000e-01 9.200000e-01 1.600000e-03 2.024000e-03
[21] 1.350000e-01 9.000000e-03 3.000000e-02 2.184000e-02 4.052231e-02 8.060000e-02 4.360839e-01 6.233500e-01 4.845142e-01 3.000000e+01
[31] 5.400000e+01 1.170400e-01 1.500000e+00 1.500000e+01 0.000000e+00 4.440000e+01 3.027050e+00 1.000000e+00 5.000000e-01 1.500000e+01
[41] 1.000000e+00 1.000000e+00 2.000000e+00 5.000000e-01 2.926883e+02 4.479877e+02 3.729358e+02 2.607527e+02 1.465650e+02 1.800000e+00
[51] 2.500000e+00 2.500000e+00 2.500000e+00 2.500000e+00 3.560000e+00 1.901288e-01 3.861000e-01 1.260000e+02 7.283717e-01 8.976500e-01
[61] 2.652000e+03 4.411236e-01 6.305000e-01 2.380525e+00 1.794000e-01 1.426892e+00 5.800000e-01 3.383189e+01 1.300000e-02 2.380000e-02
[71] 7.200000e-03 1.770000e-01 8.110000e-01 7.600000e-01 1.600000e-01 2.200000e-02 4.900000e-03 7.800000e-03 4.200000e-03 7.900000e-02
[81] 1.900000e-01 6.660000e-01 7.600000e-01 3.419000e-02 2.132154e-01 3.419000e-01 1.060477e+00 3.298858e+00 8.645000e-02 3.256408e-01
[91] 8.011250e-01

$derivedParameters
$derivedParameters$paths
 [1] "Organism|Weight"                                                 "Organism|BMI"                                                   
 [3] "Organism|BSA"                                                    "Organism|Age"                                                   
 [5] "Organism|Gestational age"                                        "Organism|Height"                                                
 [7] "Organism|Ontogeny factor (albumin)"                              "Organism|Ontogeny factor (alpha1-acid glycoprotein)"            
 [9] "Organism|Bone|Blood flow rate"                                   "Organism|Brain|Blood flow rate"                                 
[11] "Organism|Fat|Fraction intracellular"                             "Organism|Fat|Blood flow rate"                                   
[13] "Organism|Gonads|Blood flow rate"                                 "Organism|Heart|Blood flow rate"                                 
[15] "Organism|Kidney|GFR (specific)"                                  "Organism|Kidney|Blood flow rate"                                
[17] "Organism|Stomach|Blood flow rate"                                "Organism|SmallIntestine|Blood flow rate"                        
[19] "Organism|SmallIntestine|Mucosa|Duodenum|Volume"                  "Organism|SmallIntestine|Mucosa|Duodenum|Blood flow rate"        
[21] "Organism|SmallIntestine|Mucosa|UpperJejunum|Volume"              "Organism|SmallIntestine|Mucosa|UpperJejunum|Blood flow rate"    
[23] "Organism|SmallIntestine|Mucosa|LowerJejunum|Volume"              "Organism|SmallIntestine|Mucosa|LowerJejunum|Blood flow rate"    
[25] "Organism|SmallIntestine|Mucosa|UpperIleum|Volume"                "Organism|SmallIntestine|Mucosa|UpperIleum|Blood flow rate"      
[27] "Organism|SmallIntestine|Mucosa|LowerIleum|Volume"                "Organism|SmallIntestine|Mucosa|LowerIleum|Blood flow rate"      
[29] "Organism|LargeIntestine|Blood flow rate"                         "Organism|LargeIntestine|Mucosa|Caecum|Volume"                   
[31] "Organism|LargeIntestine|Mucosa|Caecum|Blood flow rate"           "Organism|LargeIntestine|Mucosa|ColonAscendens|Volume"           
[33] "Organism|LargeIntestine|Mucosa|ColonAscendens|Blood flow rate"   "Organism|LargeIntestine|Mucosa|ColonTransversum|Volume"         
[35] "Organism|LargeIntestine|Mucosa|ColonTransversum|Blood flow rate" "Organism|LargeIntestine|Mucosa|ColonDescendens|Volume"          
[37] "Organism|LargeIntestine|Mucosa|ColonDescendens|Blood flow rate"  "Organism|LargeIntestine|Mucosa|ColonSigmoid|Volume"             
[39] "Organism|LargeIntestine|Mucosa|ColonSigmoid|Blood flow rate"     "Organism|LargeIntestine|Mucosa|Rectum|Volume"                   
[41] "Organism|LargeIntestine|Mucosa|Rectum|Blood flow rate"           "Organism|Liver|Blood flow rate"                                 
[43] "Organism|Liver|Periportal|Volume"                                "Organism|Liver|Periportal|Blood flow rate"                      
[45] "Organism|Liver|Pericentral|Volume"                               "Organism|Liver|Pericentral|Blood flow rate"                     
[47] "Organism|Lung|Blood flow rate"                                   "Organism|Muscle|Fraction intracellular"                         
[49] "Organism|Muscle|Blood flow rate"                                 "Organism|Pancreas|Blood flow rate"                              
[51] "Organism|PortalVein|Blood flow rate"                             "Organism|Skin|Blood flow rate"                                  
[53] "Organism|Spleen|Blood flow rate"                                 "Organism|Saliva|Volume"                                         

$derivedParameters$values
 [1] 6.012832e+01 1.855812e-01 1.733937e+02 3.000000e+01 4.000000e+01 1.800000e+01 1.000000e+00 1.000000e+00 3.342755e-01 7.959249e-01
[11] 8.220000e-01 3.156852e-03 3.266099e-03 2.718329e-01 2.660000e-01 1.466649e+00 7.340875e-02 6.538229e-01 1.647577e-02 4.560415e-02
[21] 4.715478e-02 1.073904e-01 3.484530e-02 1.073904e-01 3.067902e-02 1.149911e-01 1.477138e-02 1.149911e-01 2.781284e-01 7.099495e-03
[31] 1.766936e-02 1.301574e-02 3.239292e-02 2.964351e-02 6.675082e-02 1.482175e-02 5.006312e-02 1.786551e-02 2.816050e-02 7.278540e-03
[41] 1.147280e-02 4.270662e-01 2.380525e+00 4.270662e-01 0.000000e+00 4.270662e-01 6.083207e+00 8.150000e-01 1.156712e+00 7.289836e-02
[51] 1.339137e+00 2.851863e-01 2.608790e-01 4.942053e-03

>
msevestre commented 4 years ago

The same issue is in PKSim you are using the NHANES white American population image

60kg for 180cm seems to be outside of the range supported by NHANES What age are you using? Isn't it required?

msevestre commented 4 years ago

And the fact that it works sometimes is probably because this data set is probably at the EDGE of the distribution. We throw some random values at the beginning of the algorithm in order to optimize the individual. Depending on the generated values, the algo seems to succeed or fail. Interesting

moPellowe commented 4 years ago

Age isn't required. The default value is NULL in the documentation, so I'm not sure what value the algorithm is using for age if it is using it all.

I guess I should choose better values for weight and height next time I'm testing. :) Thanks.

msevestre commented 4 years ago

I don't think AGE optional makes sense. (at least not for human species) It probably uses the default AGE but this is confusing. Also the error message should be the same one as in PKSim. For some reason, it seems to be truncated...

moPellowe commented 4 years ago

For my use case, I am trying to recreate a human population used in a study. I have each individual's height and weight. However, for age, I only have the age range (e.g. 30-50 yrs), so I'd have to randomly choose an age within the range anyway for each individual. For adults, are there many parameters that are dependent on age?

moPellowe commented 4 years ago

Never mind. You're right. I'll explicitly set the individual's age.