Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install pytest pytest-cov python-libsbml
- name: Tnstall biocrnpyler
- name: Install biocrnpyler
run: pip install -e .
- name: Test biocrnpyler
run: pytest --cov biocrnpyler
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/test_chemicalReactionNetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def test_initial_condition_vector(self):
def test_get_all_species_containing(self):
# test that the species arument must be Species object
with self.assertRaisesRegex(
ValueError, 'species argument must be an instance of Species!'
ValueError, 'species argument must be an instance of Species'
):
self.crn.get_all_species_containing(species=self.species_list)

Expand Down
1 change: 0 additions & 1 deletion Tests/Unit/test_compartment.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ def test_compartment_setter(self):
s1 = Species('S1', compartment=comp1)
mixture_1 = Mixture(species=[s1])
crn_1 = mixture_1.compile_crn()
crn_1.write_sbml_file('test_compartment_setter_1.xml')
# change compartment
s1.compartment = comp2
mixture_2 = Mixture(species=[s1])
Expand Down
6 changes: 5 additions & 1 deletion Tests/Unit/test_component_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ def test_enzyme():
products = 'P1'
enzyme = 'E1'

e = Enzyme(enzyme=enzyme, substrates=substrates, products=products)
e = Enzyme(
enzyme=enzyme, substrates=substrates, products=products,
)
e.default_mechanism=None # override failsafe

assert any([s.name == 'S1' for s in e.substrates])
assert any([p.name == 'P1' for p in e.products])
assert enzyme == e.enzyme.name
Expand Down
5 changes: 5 additions & 0 deletions Tests/Unit/test_component_membrane.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def test_DiffusibleMolecule():

assert dm.get_species().name == 'DP'

dm.default_mechanism = None # override failsafe
with pytest.raises(
KeyError,
match='Unable to find mechanism of type diffusion in Component',
Expand All @@ -46,6 +47,7 @@ def test_IntegralMembraneProtein():

assert imp.get_species().name == 'MP1'

imp.default_mechanism = None # override failsafe
with pytest.raises(
KeyError,
match='Unable to find mechanism of type membrane_insertion in Component',
Expand All @@ -70,6 +72,7 @@ def test_MembraneChannel():

assert mc.get_species().name == 'IMP1'

mc.default_mechanism = None # override failsafe
with pytest.raises(
KeyError,
match='Unable to find mechanism of type transport in Component',
Expand All @@ -94,6 +97,7 @@ def test_MembranePump():

assert mp.get_species().name == 'MPump1'

mp.default_mechanism = None # override failsafe
with pytest.raises(
KeyError,
match='Unable to find mechanism of type transport in Component',
Expand Down Expand Up @@ -125,6 +129,7 @@ def test_MembraneSensor():

assert ms.get_species().name == 'MSensor1'

ms.default_mechanism = None # override failsafe
with pytest.raises(
KeyError,
match='Unable to find mechanism of type membrane_sensor in Component',
Expand Down
43 changes: 27 additions & 16 deletions Tests/Unit/test_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ def test_find_parameter(self):
)


def test_findpath():
def test_findpath(tmp_path):
import os
import platform

Expand All @@ -530,21 +530,32 @@ def test_findpath():
bcp.find_file_in_bcp_path('mechanisms/txtl_parameters.tsv')
)

# Make sure we can find files in current directory
assert bcp.find_file_in_bcp_path('__testfile__.tsv') is None
open('__testfile__.tsv', 'w')
assert os.path.exists(bcp.find_file_in_bcp_path('__testfile__.tsv'))
os.remove('__testfile__.tsv')

# Make sure we can find files in the path
open('../__testfile__.tsv', 'w')
assert bcp.find_file_in_bcp_path('__testfile__.tsv') is None
if platform.system() == 'Windows':
os.environ['BCP_PATH'] = '/tmp;.;..'
else:
os.environ['BCP_PATH'] = '/tmp:.:..'
assert os.path.exists(bcp.find_file_in_bcp_path('__testfile__.tsv'))
os.remove('../__testfile__.tsv')
prev_cwd = os.getcwd()
prev_bcp_path = os.environ.get('BCP_PATH')
child_dir = tmp_path / 'child'
child_dir.mkdir()
os.chdir(child_dir)
try:
# Make sure we can find files in current directory
assert bcp.find_file_in_bcp_path('__testfile__.tsv') is None
(child_dir / '__testfile__.tsv').write_text('')
assert os.path.exists(bcp.find_file_in_bcp_path('__testfile__.tsv'))
os.remove(child_dir / '__testfile__.tsv')

# Make sure we can find files in the path
(tmp_path / '__testfile__.tsv').write_text('')
assert bcp.find_file_in_bcp_path('__testfile__.tsv') is None
if platform.system() == 'Windows':
os.environ['BCP_PATH'] = f'/tmp;.;{tmp_path}'
else:
os.environ['BCP_PATH'] = f'/tmp:.:{tmp_path}'
assert os.path.exists(bcp.find_file_in_bcp_path('__testfile__.tsv'))
finally:
os.chdir(prev_cwd)
if prev_bcp_path is None:
os.environ.pop('BCP_PATH', None)
else:
os.environ['BCP_PATH'] = prev_bcp_path


def test_parameter_ordering():
Expand Down
37 changes: 32 additions & 5 deletions Tests/Unit/test_sbml.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,36 @@ def test_generate_sbml_model():
assert validate_sbml(document) == 0


def test_generate_sbml_model_writes_units_from_biocrnpyler():
compartment = Compartment('cell', size=1, unit='uL')
s1 = Species('S1', compartment=compartment)
s2 = Species('S2', compartment=compartment)
kf = ParameterEntry('k', 0.1, unit='/sec')
x0 = ParameterEntry('S1_0', 1.0, unit='uM')
rxn = Reaction.from_massaction(inputs=[s1], outputs=[s2], k_forward=kf)
crn = ChemicalReactionNetwork(
species=[s1, s2],
reactions=[rxn],
initial_concentration_dict={s1: x0},
)

document, model = crn.generate_sbml_model()
assert validate_sbml(document) == 0

sbml_compartment = model.getCompartment('cell')
assert sbml_compartment.getUnits() == 'uL'

sbml_species = model.getSpecies(0)
assert sbml_species.getSubstanceUnits() == 'pmol'
assert sbml_species.getInitialConcentration() == 1.0

sbml_parameter = model.getListOfParameters()[0]
assert sbml_parameter.getUnits() == 'per_sec'

unit_defs = {ud.getId() for ud in model.getListOfUnitDefinitions()}
assert {'uL', 'pmol', 'per_sec'}.issubset(unit_defs)


def test_generate_sbml_model_parameter_names():
s1 = Species('S1')
s2 = Species('S2')
Expand Down Expand Up @@ -518,11 +548,8 @@ def check(value, message):
global_param = _create_global_parameter(
model, 'k_global', value=10, p_unit=24
)
with pytest.warns(
Warning,
match="The string identifier for the unit 1_s is not supported by "
"BioCRNpyler. Add this to the dictionary in biocrnpyler/units.py "
"if you want this unit",
with pytest.raises(
ValueError, match="Unsupported SBML unit '1_s'"
):
global_param = _create_global_parameter(
model, 'k_global', value=10, p_unit='1_s'
Expand Down
6 changes: 6 additions & 0 deletions biocrnpyler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@

# All utilities
from .utils import *
from .utils.plotting import (
plot_all_species_containing as plot_all_species_containing,
)
from .utils.plotting import (
plot_gene_expression_data as plot_gene_expression_data,
)

try:
from ._version import version as __version__
Expand Down
29 changes: 26 additions & 3 deletions biocrnpyler/components/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from ..core.component import Component
from ..core.reaction import Reaction
from ..core.species import Complex, Species
from ..mechanisms.binding import One_Step_Binding
from ..mechanisms.enzyme import MichaelisMenten
from ..mechanisms.metabolite import OneStepPathway


class DNA(Component):
Expand Down Expand Up @@ -402,7 +405,17 @@ def __init__(
else:
self.products.append(self.set_species(p))

Component.__init__(self=self, name=name, **kwargs)
if precursors is not None or products is not None:
default_mechanism = OneStepPathway()
else:
default_mechanism = None

Component.__init__(
self=self,
name=name,
default_mechanism=default_mechanism,
**kwargs,
)

def get_species(self) -> Species:
"""Get the metabolite species.
Expand Down Expand Up @@ -602,7 +615,12 @@ def __init__(
if name is None:
name = self.species.name

Component.__init__(self=self, name=name, **kwargs)
Component.__init__(
self=self,
name=name,
default_mechanism=One_Step_Binding(),
**kwargs,
)

def get_species(self) -> List[Species]:
"""Get the complex species.
Expand Down Expand Up @@ -773,7 +791,12 @@ def __init__(
self.substrates = substrates
self.products = products

Component.__init__(self=self, name=self.enzyme.name, **kwargs)
Component.__init__(
self=self,
name=self.enzyme.name,
default_mechanism=MichaelisMenten(),
**kwargs,
)

@property
def substrates(self) -> List:
Expand Down
8 changes: 6 additions & 2 deletions biocrnpyler/components/combinatorial_conformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,12 @@ def __init__(

if name is None:
name = str(self.internal_polymer.name)
Component.__init__(self, name=name, **kwargs)
self.add_mechanism(One_Step_Reversible_Conformation_Change())
Component.__init__(
self,
name=name,
default_mechanism=One_Step_Reversible_Conformation_Change(),
**kwargs,
)

# Helper function to assert the correct class type
def _assert_conformation(self, states, input_name='states'):
Expand Down
Loading