Пример #1
0
def test_variables_samples(achr: ACHRSampler) -> None:
    """Test variable samples."""
    vnames = np.array([v.name for v in achr.model.variables])
    s = achr.sample(10, fluxes=False)
    assert s.shape == (10, achr.warmup.shape[1])
    assert (s.columns == vnames).all()
    assert (achr.validate(s) == "v").all()
Пример #2
0
def test_validate_wrong_sample(achr: ACHRSampler, model: "Model") -> None:
    """Test sample correctness."""
    s = achr.sample(10)
    s["hello"] = 1

    with pytest.raises(ValueError):
        achr.validate(s)
Пример #3
0
def test_complicated_model():
    """Test a complicated model.

    Difficult model since the online mean calculation is numerically
    unstable so many samples weakly violate the equality constraints.

    """

    model = Model('flux_split')

    reaction1 = Reaction('V1')
    reaction2 = Reaction('V2')
    reaction3 = Reaction('V3')
    reaction1.bounds = (0, 6)
    reaction2.bounds = (0, 8)
    reaction3.bounds = (0, 10)

    A = Metabolite('A')

    reaction1.add_metabolites({A: -1})
    reaction2.add_metabolites({A: -1})
    reaction3.add_metabolites({A: 1})

    model.add_reactions([reaction1, reaction2, reaction3])

    optgp = OptGPSampler(model, 1, seed=42)
    achr = ACHRSampler(model, seed=42)

    optgp_samples = optgp.sample(100)
    achr_samples = achr.sample(100)

    assert any(optgp_samples.corr().abs() < 1.0)
    assert any(achr_samples.corr().abs() < 1.0)

    # > 95% are valid
    assert sum(optgp.validate(optgp_samples) == "v") > 95
    assert sum(achr.validate(achr_samples) == "v") > 95
Пример #4
0
def test_complicated_model():
    """Test a complicated model.

    Difficult model since the online mean calculation is numerically
    unstable so many samples weakly violate the equality constraints.

    """

    model = Model('flux_split')

    reaction1 = Reaction('V1')
    reaction2 = Reaction('V2')
    reaction3 = Reaction('V3')
    reaction1.bounds = (0, 6)
    reaction2.bounds = (0, 8)
    reaction3.bounds = (0, 10)

    A = Metabolite('A')

    reaction1.add_metabolites({A: -1})
    reaction2.add_metabolites({A: -1})
    reaction3.add_metabolites({A: 1})

    model.add_reactions([reaction1, reaction2, reaction3])

    optgp = OptGPSampler(model, 1, seed=42)
    achr = ACHRSampler(model, seed=42)

    optgp_samples = optgp.sample(100)
    achr_samples = achr.sample(100)

    assert any(optgp_samples.corr().abs() < 1.0)
    assert any(achr_samples.corr().abs() < 1.0)

    # > 95% are valid
    assert sum(optgp.validate(optgp_samples) == "v") > 95
    assert sum(achr.validate(achr_samples) == "v") > 95
Пример #5
0
from scipy.stats import hypergeom

modelIN = cobra.io.load_matlab_model('HumanGEMNHBESARS_cons.mat')
modelUIN = cobra.io.load_matlab_model('HumanGEMNHBEMock_cons.mat')
modelIB = cobra.io.load_matlab_model('HumanGEMBiopsySARS.mat')
modelUIB = cobra.io.load_matlab_model('HumanGEMBiopsyMock.mat')

modelIN.reactions.EX_sarscov2s.bounds = (-0.1259, 1000)
modelUIN.reactions.HMR_10024.bounds = (-0.0088, 1000)

achr_IN = ACHRSampler(modelIN, thinning=100)
achr_UIN = ACHRSampler(modelUIN, thinning=100)
achr_IB = ACHRSampler(modelIB, thinning=100)
achr_UIB = ACHRSampler(modelUIB, thinning=100)

samples_IB = achr_IB.sample(10000)
samples_UIB = achr_UIB.sample(10000)
samples_IN = achr_IN.sample(10000)
samples_UIN = achr_UIN.sample(10000)

#KS Test


def bootstrapCI(rxn):
    bsci = []
    for i in range(1000):
        bt_samp = rxn.sample(1000, replace=True)
        bsci.append(bt_samp.mean())
    ci_low = np.percentile(bsci, 2.5)
    ci_high = np.percentile(bsci, 97.5)
    if (ci_low > 0 or ci_high < 0):
Пример #6
0
def test_sampling(achr: ACHRSampler) -> None:
    """Test sampling."""
    s = achr.sample(10)
    assert all(achr.validate(s) == "v")