コード例 #1
0
ファイル: fbc1.py プロジェクト: g-simmons/sbmlutils
def create(tmp: bool = False) -> None:
    """Create model."""
    create_model(
        modules=["sbmlutils.examples.fbc1"],
        output_dir=EXAMPLE_RESULTS_DIR,
        tmp=tmp,
    )
コード例 #2
0
ファイル: factory.py プロジェクト: g-simmons/sbmlutils
def create(tmp: bool = False) -> None:
    """Create model."""
    create_model(
        modules=["sbmlutils.examples.dallaman.model"],
        output_dir=Path(__file__).parent / "results",
        tmp=tmp,
        units_consistency=False,
    )
コード例 #3
0
def create(tmp: bool = False) -> None:
    """Create model."""
    create_model(
        modules=["sbmlutils.examples.distrib_distributions"],
        output_dir=EXAMPLE_RESULTS_DIR,
        tmp=tmp,
        units_consistency=False,
    )
コード例 #4
0
def test_sbml_level_version(level: int, version: int, tmp_path: Path) -> None:
    """Test that the various levels and versions of SBML can be generated."""
    md = {
        "mid": "level_version",
        "compartments": [Compartment(sid="C", value=1.0)],
        "species": [
            Species(
                sid="S1",
                initialConcentration=10.0,
                compartment="C",
                hasOnlySubstanceUnits=False,
                boundaryCondition=True,
            )
        ],
        "parameters": [Parameter(sid="k1", value=1.0)],
        "reactions": [
            Reaction(sid="R1", equation="S1 ->", formula=("k1 * S1 * sin(time)", "-"))
        ],
    }

    results = create_model(
        modules=md,
        output_dir=tmp_path,
        tmp=False,
        units_consistency=False,
        sbml_level=level,
        sbml_version=version,
    )
    doc = read_sbml(source=results.sbml_path, validate=False)
    assert level == doc.getLevel()
    assert version == doc.getVersion()
コード例 #5
0
def test_model_annotation(tmp_path: Path) -> None:
    """Create minimal model and check that annotation is written correctly."""
    model_dict = {
        "mid":
        "example_annotation",
        "compartments": [
            Compartment(
                sid="C",
                value=1.0,
                sboTerm=SBO_PHYSICAL_COMPARTMENT,
                annotations=[
                    (BQB.IS, "chebi/CHEBI:28061"),  # alpha-D-galactose
                ],
            )
        ],
    }
    results = create_model(model_dict,
                           output_dir=tmp_path,
                           filename="annotation1.xml")
    # check annotations
    doc: libsbml.SBMLDocument = read_sbml(source=results.sbml_path)
    model: libsbml.Model = doc.getModel()
    compartment: libsbml.Compartment = model.getCompartment(0)
    assert compartment

    cvterms: libsbml.CVTermList = compartment.getCVTerms()
    assert len(cvterms) == 1

    cv: libsbml.CVTerm = cvterms[0]
    assert cv.getNumResources() == 1
コード例 #6
0
ファイル: factory.py プロジェクト: g-simmons/sbmlutils
def create(tmp: bool = False) -> None:
    """Create model."""
    output_dir = Path(__file__).parent
    create_model(
        modules=["sbmlutils.examples.demo.model"],
        output_dir=output_dir / "results",
        annotations=output_dir / "demo_annotations.xlsx",
        tmp=tmp,
    )

    # without annotations
    create_model(
        modules=["sbmlutils.examples.demo.model"],
        output_dir=output_dir / "results",
        mid="{}_{}_{}".format(model.mid, model.version, "no_annotations"),
        tmp=tmp,
    )
コード例 #7
0
ファイル: factory.py プロジェクト: g-simmons/sbmlutils
def create(tmp: bool = False) -> FactoryResult:
    """Create model."""
    models_dir = Path(__file__).parent
    return create_model(
        modules=["sbmlutils.examples.tiny_model.model"],
        output_dir=models_dir / "results",
        annotations=models_dir / "annotations.xlsx",
        tmp=tmp,
    )
コード例 #8
0
def create(tmp: bool = False) -> None:
    """Create example setting boundaryCondition."""

    m1 = {
        "mid":
        "m1_boundary_condition",
        "compartments": [Compartment(sid="C", value=1.0)],
        "species": [
            Species(
                sid="S1",
                initialConcentration=10.0,
                compartment="C",
                hasOnlySubstanceUnits=False,
                boundaryCondition=True,
            )
        ],
        "parameters": [Parameter(sid="k1", value=1.0)],
        "reactions": [
            Reaction(sid="R1",
                     equation="S1 ->",
                     formula=("k1 * S1 * sin(time)", None))
        ],
        "assignments": [],
    }

    m2 = m1.copy()
    m2["mid"] = "m2_boundary_condition"
    m2["assignments"] = [AssignmentRule("S1", 20.0)]

    for d in [m1, m2]:
        create_model(
            modules=d,
            output_dir=EXAMPLE_RESULTS_DIR,
            tmp=tmp,
            units_consistency=False,
        )
コード例 #9
0
def test_model_units_metre(unit: UnitType, tmp_path: Path) -> None:
    """Test that length can be set with metre and meter."""
    md = {
        "mid": "example_model",
        "model_units": ModelUnits(length=unit, ),
    }
    results = create_model(
        modules=md,
        output_dir=tmp_path,
        tmp=False,
        sbml_level=3,
        sbml_version=1,
        validate=False,
    )
    val_results = validate_sbml(source=results.sbml_path)
    assert val_results.all_count == 0
コード例 #10
0
ファイル: test_factory.py プロジェクト: g-simmons/sbmlutils
def test_compartment_value(
    value: Any, constant: bool, expected: Dict, tmp_path: Path
) -> None:
    m1 = {
        "mid": "compartment_value",
        "compartments": [Compartment(sid="C", value=value, constant=constant)],
    }

    result = create_model(
        modules=m1,
        output_dir=tmp_path,
        units_consistency=False,
    )

    doc = read_sbml(source=result.sbml_path)
    model = doc.getModel()  # type: libsbml.Model
    assert model.getNumCompartments() == expected["compartments"]
    assert model.getNumInitialAssignments() == expected["initial_assignments"]
    assert model.getNumRules() == expected["rules"]