Coder Social home page Coder Social logo

modelbuilder's Introduction

badge1 badge2 badge3 badge4 badge5 badge6

logo

Pharmpy is an open-source software package for pharmacometric modeling. It has functionality ranging from reading and manipulating model files and datasets to full tools where subsequent results are collected and presented.

Features include:

  • A model abstraction which splits a model into core components which Pharmpy understands and can manipulate: parameters, random variables, statements (including ODE system), dataset, and execution steps
  • An abstraction for modelfit results which splits a parsed results into core components: e.g. OFV, parameter estimates, relative standard errors (RSEs), residuals, predictions
  • Functions for manipulation of models and datasets in the modeling-module: e.g. change structural model, add time-after-dose column, deidentify dataset
  • Tools to aid model development in the tools-module: execution of models within Python/R scripts, automatic development of models (e.g. AMD, IIVSearch, RUVSearch), comparison of estimation methods
  • Support for multiple estimation tools: parse NONMEM models, execute NONMEM, nlmixr2, and rxODE2 models, run all Pharmpy tools with NONMEM and some with nlmixr2

For more comprehensive information and documentation, see: https://pharmpy.github.io

Pharmpy can be used as a regular Python package, in R via the pharmr package, or via its built in command line interface.

Getting started

The sections below are intended as first steps, please check our website website for more comprehensive documentation, such as user guides and API references.

Installation

For installation in R, see pharmr.

Install the latest stable version from PyPI:

pip install pharmpy-core # or 'pip3 install' if that is your default python3 pip

Python Example

>>> from pharmpy.modeling import read_model
>>> from pharmpy.tools import load_example_modelfit_results
>>> model = load_example_model("pheno")
>>> model.parameters
            value  lower upper    fix
POP_CL   0.004693   0.00     ∞  False
POP_VC   1.009160   0.00     ∞  False
COVAPGR  0.100000  -0.99     ∞  False
IIV_CL   0.030963   0.00     ∞  False
IIV_VC   0.031128   0.00     ∞  False
SIGMA    0.013086   0.00     ∞  False
>>> res = load_example_modelfit_results("pheno")
>>> res.parameter_estimates
POP_CL     0.004696
POP_VC     0.984258
COVAPGR    0.158920
IIV_CL     0.029351
IIV_VC     0.027906
SIGMA      0.013241
Name: estimates, dtype: float64
>>>

CLI Example

# Get help
pharmpy -h

# Remove first ID from dataset and save new model using new dataset
pharmpy data filter run1.mod 'ID!=1'

# Run tool for selecting IIV structure
pharmpy run iivsearch run1.mod

Contact

This is the team behind Pharmpy

Please ask a question in an issue or contact one of the maintainers if you have any questions.

Contributing

If you interested in contributing to Pharmpy, you can find more information under Contribute.

modelbuilder's People

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

davsjob vrognas

modelbuilder's Issues

Move callbacks to different files.

Move callbacks to separate files corresponding to each tab, then import from there into app.py
Will improve maintaining , debugging and readability.

Uploading dataset

Hi!
Looked around a little and noticed that uploaded datasets are required to be in the repo folder and will give an error message otherwise. Could be nice to allow other paths as well

Remove the "Model statements" button

We should move the "Model statements" button. If possible the functionality could be replacing the generic code view, but it seems as if the text renderer is buggy. If not possible simply remove the button.

Change the top label

Currently it says "PLACEHOLDER Pharmpy GUI Navbar", but since we don't have a navbar yet perhaps it should simply say "Pharmpy model builder"

Crash when switching to the "Parameter Variability" tab

The app gives an error when directly switching to the "Parameter Variability" tab

Traceback (most recent call last):
  File "/home/rikard/devel/modelbuilder/app.py", line 440, in render_iiv_iov_data
    occ_opts = globals()["model"].datainfo.typeix["idv"].names + globals()["model"].datainfo.typeix["unknown"].names
  File "/home/rikard/devel/modelbuilder_venv/lib/python3.10/site-packages/pharmpy/model/datainfo.py", line 1008, in __getitem__
    raise IndexError(f"No columns of type {i} available")
IndexError: No columns of type idv available

During handling of the above exception, another exception occurred:

IndexError: No columns of type unknown available

Crash when directly switching to MM elimination

Directly switching to MM elimination after starting the app causes a crash.

I think this is actually a bug in Pharmpy:

Traceback (most recent call last):
  File "/home/rikard/devel/modelbuilder/app.py", line 174, in update_abs_elim
    "MM": set_michaelis_menten_elimination(globals()["model"]),
  File "/home/rikard/devel/modelbuilder_venv/lib/python3.10/site-packages/pharmpy/modeling/odes.py", line 573, in set_michaelis_menten_elimination
    model = _do_michaelis_menten_elimination(model)
  File "/home/rikard/devel/modelbuilder_venv/lib/python3.10/site-packages/pharmpy/modeling/odes.py", line 645, in _do_michaelis_menten_elimination
    km_init, clmm_init = _get_mm_inits(model, numer, combined)
  File "/home/rikard/devel/modelbuilder_venv/lib/python3.10/site-packages/pharmpy/modeling/odes.py", line 753, in _get_mm_inits
    dv_max = get_observations(model).max()
  File "/home/rikard/devel/modelbuilder_venv/lib/python3.10/site-packages/pharmpy/modeling/data.py", line 257, in get_observations
    idcol = model.datainfo.id_column.name
  File "/home/rikard/devel/modelbuilder_venv/lib/python3.10/site-packages/pharmpy/model/datainfo.py", line 738, in id_column
    return self.typeix['id'][0]
  File "/home/rikard/devel/modelbuilder_venv/lib/python3.10/site-packages/pharmpy/model/datainfo.py", line 1008, in __getitem__
    raise IndexError(f"No columns of type {i} available")
IndexError: No columns of type id available

Length of peripheral/transit input boxes are too wide

It feels like the width of the numeric input boxes is too wide in comparison to the rest of the buttons in the same column and also given the small amount of text they will contain. Perhaps they could be made less wide

Constantly switching the name of the browser tab

When running the app the tab in the browser will be constantly toggling between being named "Pharmpy GUI" and "Updating...". I am using Firefox. In chrome it doesn't switch back and forth but is stable on "Pharmpy GUI"

Hard to distinguish between labels and buttons

For example after starting the app: "Model Type" and "Model format" are labels and "Write model" and "Choose dataset" are buttons, but they look exactly the same (perhaps the font is slightly different). I think it should be possible to know what is clickable just by looking.

Generate R/Python code

In the same way we can generate e.g. NONMEM code, there should be a tab for R/Python code generation.

Change from generic model to nonmem model does not work

When changing from generic model format to nonmem model format after having changed the iiv of some parameters the code is not nonmem code anymore:

The nonmem code looks as follows:
{"parameters": {"parameters": [{"name": "POP_CL", "init": 0.01, "lower": 0, "upper": null, "fix": false}, {"name": "POP_VC", "init": 1, "lower": 0, "upper": null, "fix": false}, {"name": "IIV_CL", "init": 0.1, "lower": null, "upper": null, "fix": false}, {"name": "IIV_VC", "init": 0.1, "lower": null, "upper": null, "fix": false}, {"name": "IIV_CL_IIV_CL", "init": 0.01, "lower": -Infinity, "upper": Infinity, "fix": false}, {"name": "sigma", "init": 0.09, "lower": -Infinity, "upper": Infinity, "fix": false}]}, "random_variables": {"dists": [{"class": "JointNormalDistribution", "names": ["ETA_CL", "ETA_VC"], "level": "IIV", "mean": "MutableDenseMatrix([[Integer(0)], [Integer(0)]])", "variance": "MutableDenseMatrix([[Symbol('IIV_CL'), Symbol('IIV_CL_IIV_CL')], [Symbol('IIV_CL_IIV_CL'), Symbol('IIV_VC')]])"}, {"class": "NormalDistribution", "name": "epsilon_p", "level": "RUV", "mean": "Integer(0)", "variance": "Symbol('sigma')"}], "eta_levels": {"levels": [{"name": "IIV", "reference": true, "group": "ID"}, {"name": "IOV", "reference": false, "group": "OCC"}]}, "epsilon_levels": {"levels": [{"name": "RUV", "reference": true, "group": null}]}}, "statements": {"statements": [{"class": "Assignment", "symbol": "Symbol('CL')", "expression": "Mul(Symbol('POP_CL'), exp(Symbol('ETA_CL')))"}, {"class": "Assignment", "symbol": "Symbol('VC')", "expression": "Mul(Symbol('POP_VC'), exp(Symbol('ETA_VC')))"}, {"class": "CompartmentalSystem", "compartments": [{"class": "Output"}, {"class": "Compartment", "name": "CENTRAL", "amount": "Symbol('A_CENTRAL')", "dose": {"class": "Bolus", "amount": "Symbol('AMT')", "admid": 1}, "input": "Integer(0)", "lag_time": "Integer(0)", "bioavailability": "Integer(1)"}], "rates": [[1, 0, "Mul(Symbol('CL'), Pow(Symbol('VC'), Integer(-1)))"]], "t": "Symbol('t')"}, {"class": "Assignment", "symbol": "Symbol('IPRED')", "expression": "Mul(Symbol('A_CENTRAL'), Pow(Symbol('VC'), Integer(-1)))"}, {"class": "Assignment", "symbol": "Symbol('IPREDADJ')", "expression": "Piecewise(ExprCondPair(Float('2.2250000000000002e-16', precision=53), Equality(Symbol('IPRED'), Integer(0))), ExprCondPair(Symbol('IPRED'), true))"}, {"class": "Assignment", "symbol": "Symbol('IPREDADJ1')", "expression": "Piecewise(ExprCondPair(Float('2.2250000000000002e-16', precision=53), Equality(Symbol('IPRED'), Integer(0))), ExprCondPair(Symbol('IPRED'), true))"}, {"class": "Assignment", "symbol": "Symbol('Y')", "expression": "Add(Symbol('IPRED'), Mul(Symbol('IPREDADJ1'), Symbol('epsilon_p')))"}]}, "estimation_steps": {"steps": [{"method": "FOCE", "interaction": true, "cov": null, "evaluation": false, "maximum_evaluations": 99999, "laplace": false, "isample": null, "niter": null, "auto": null, "keep_every_nth_iter": null, "solver": null, "solver_rtol": null, "solver_atol": null, "tool_options": {}}]}, "datainfo": {"columns": [{"name": "ID", "type": "id", "scale": "nominal", "continuous": false, "categories": null, "unit": "1", "datatype": "int32", "drop": false, "descriptor": null}, {"name": "TIME", "type": "idv", "scale": "ratio", "continuous": true, "categories": null, "unit": "1", "datatype": "float64", "drop": false, "descriptor": null}, {"name": "DV", "type": "dv", "scale": "ratio", "continuous": true, "categories": null, "unit": "1", "datatype": "float64", "drop": false, "descriptor": null}, {"name": "AMT", "type": "dose", "scale": "ratio", "continuous": true, "categories": null, "unit": "1", "datatype": "float64", "drop": false, "descriptor": null}, {"name": "DVID", "type": "unknown", "scale": "ratio", "continuous": true, "categories": null, "unit": "1", "datatype": "float64", "drop": false, "descriptor": null}], "path": null, "separator": "\\s+"}, "value_type": "PREDICTION", "dependent_variables": {"Y": 1}, "observation_transformation": {"Symbol('Y')": "Symbol('Y')"}, "initial_individual_estimates": null, "__magic__": "Pharmpy Model", "__version__": "0.99.0"}

Cannot create population parameter

After creating a parameter it will is added to the parameter list and a THETA value is added to the nonmem code. But when switching to another tab the parameter is vanishing.

Choose Dataset needs polish

Currently this selector is confusing. The "editable" option seems too low level. The "dataset path" has some strange default value.

Remove the "Example type" selector

Currently "PK" is the only "Model type" that can be selected so keep the radio button with only one selection, but "Example type" should be removed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.