示例#1
0
def test_dataset_validation():
    # make dummy datasets
    dummy3 = [1, 2, 3]
    dummy4 = [1, 2, 3, 4]

    # these should be valid
    bmds.DichotomousDataset(doses=dummy3, ns=dummy3, incidences=dummy3)
    bmds.ContinuousDataset(doses=dummy3,
                           ns=dummy3,
                           responses=dummy3,
                           stdevs=dummy3)

    # these should raise errors
    with pytest.raises(ValueError):
        # different sized lists
        bmds.DichotomousDataset(doses=dummy4, ns=dummy3, incidences=dummy3)
        bmds.ContinuousDataset(doses=dummy4,
                               ns=dummy3,
                               responses=dummy3,
                               stdevs=dummy3)

        # 2 remaining after dropping-doses
        bmds.DichotomousDataset(doses=dummy3,
                                ns=dummy3,
                                incidences=dummy3,
                                doses_dropped=1)
        bmds.ContinuousDataset(doses=dummy3,
                               ns=dummy3,
                               responses=dummy3,
                               stdevs=dummy3,
                               doses_dropped=1)
示例#2
0
def test_doses_used():
    ds5 = [1, 2, 3, 4, 5]

    ds = bmds.DichotomousDataset(ds5, ds5, ds5)
    assert ds.doses_used == 5
    ds = bmds.DichotomousDataset(ds5, ds5, ds5, doses_dropped=2)
    assert ds.doses_used == 3

    ds = bmds.ContinuousDataset(ds5, ds5, ds5, ds5)
    assert ds.doses_used == 5
    ds = bmds.ContinuousDataset(ds5, ds5, ds5, ds5, doses_dropped=2)
    assert ds.doses_used == 3
示例#3
0
    def build_session(inputs, dataset):

        bmds_version = inputs['bmds_version']
        dataset_type = inputs['dataset_type']
        models = inputs.get('models')
        bmr = inputs.get('bmr')

        # build dataset
        if dataset_type == bmds.constants.CONTINUOUS:
            dataset = bmds.ContinuousDataset(doses=dataset['doses'],
                                             ns=dataset['ns'],
                                             means=dataset['means'],
                                             stdevs=dataset['stdevs'])
        elif dataset_type == bmds.constants.CONTINUOUS_INDIVIDUAL:
            dataset = bmds.ContinuousIndividualDataset(
                doses=dataset['doses'], responses=dataset['responses'])
        else:
            dataset = bmds.DichotomousDataset(
                doses=dataset['doses'],
                ns=dataset['ns'],
                incidences=dataset['incidences'],
            )

        # build session
        session = bmds.BMDS.versions[bmds_version](dataset_type,
                                                   dataset=dataset)

        # get BMR
        global_overrides = {}
        if bmr is not None:
            global_overrides = {
                'bmr':
                bmr['value'],
                'bmr_type':
                bmds.constants.BMR_CROSSWALK[dataset_type][bmr['type']],
            }

        # Add models to session
        if models is None:
            session.add_default_models(global_overrides=global_overrides)
        else:
            for model in models:
                overrides = deepcopy(global_overrides)
                if 'settings' in model:
                    overrides.update(model['settings'])
                session.add_model(model['name'], overrides=overrides)

        return session
示例#4
0
    def build_session(inputs, dataset):

        bmds_version = inputs["bmds_version"]
        dataset_type = inputs["dataset_type"]
        models = inputs.get("models")
        bmr = inputs.get("bmr")

        # build dataset
        if dataset_type == bmds.constants.CONTINUOUS:
            dataset = bmds.ContinuousDataset(
                doses=dataset["doses"],
                ns=dataset["ns"],
                means=dataset["means"],
                stdevs=dataset["stdevs"],
            )
        elif dataset_type == bmds.constants.CONTINUOUS_INDIVIDUAL:
            dataset = bmds.ContinuousIndividualDataset(
                doses=dataset["doses"], responses=dataset["responses"])
        else:
            dataset = bmds.DichotomousDataset(doses=dataset["doses"],
                                              ns=dataset["ns"],
                                              incidences=dataset["incidences"])

        # build session
        session = bmds.BMDS.versions[bmds_version](dataset_type,
                                                   dataset=dataset)

        # get BMR
        global_overrides = {}
        if bmr is not None:
            global_overrides = {
                "bmr":
                bmr["value"],
                "bmr_type":
                bmds.constants.BMR_CROSSWALK[dataset_type][bmr["type"]],
            }

        # Add models to session
        if models is None:
            session.add_default_models(global_overrides=global_overrides)
        else:
            for model in models:
                overrides = deepcopy(global_overrides)
                if "settings" in model:
                    overrides.update(model["settings"])
                session.add_model(model["name"], overrides=overrides)

        return session
示例#5
0
def test_dfile_outputs():
    dummy4 = [1, 2, 3, 4]

    # check dichotomous
    ds = bmds.DichotomousDataset(doses=dummy4,
                                 ns=[5, 5, 5, 5],
                                 incidences=[0, 1, 2, 3],
                                 doses_dropped=1)
    dfile = ds.as_dfile()
    expected = 'Dose Incidence NEGATIVE_RESPONSE\n1.000000 0 5\n2.000000 1 4\n3.000000 2 3'  # noqa
    assert dfile == expected

    # check continuous
    ds = bmds.ContinuousDataset(doses=dummy4,
                                ns=dummy4,
                                responses=dummy4,
                                stdevs=dummy4,
                                doses_dropped=1)
    dfile = ds.as_dfile()
    expected = 'Dose NumAnimals Response Stdev\n1.000000 1 1.000000 1.000000\n2.000000 2 2.000000 2.000000\n3.000000 3 3.000000 3.000000'  # noqa
    assert dfile == expected
示例#6
0
 def get_endpoint_dataset(self):
     ds = self.endpoint.get_json(json_encode=False)
     doses = [
         dose['dose']
         for dose in ds['animal_group']['dosing_regime']['doses']
         if dose['dose_units']['id'] == self.dose_units_id
     ]
     grps = ds['groups']
     if self.endpoint.data_type == 'C':
         return bmds.ContinuousDataset(
             doses=doses,
             ns=[d['n'] for d in grps],
             means=[d['response'] for d in grps],
             stdevs=[d['stdev'] for d in grps],
         )
     else:
         return bmds.DichotomousDataset(
             doses=doses,
             ns=[d['n'] for d in grps],
             incidences=[d['incidence'] for d in grps],
         )
示例#7
0
def dataset():
    return bmds.DichotomousDataset(doses=[0, 1.96, 5.69, 29.75],
                                   ns=[75, 49, 50, 49],
                                   incidences=[5, 1, 3, 14])
示例#8
0
import bmds
from bmds.bmds3.models.dichotomous import Logistic

dataset = bmds.DichotomousDataset(doses=[0, 50, 100, 150, 200],
                                  ns=[100, 100, 100, 100, 100],
                                  incidences=[0, 5, 30, 65, 90])
model = Logistic(dataset=dataset)
result = model.execute()
print(result.dict())