Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Membrane components, mechanism, and examples #286

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
90 changes: 90 additions & 0 deletions Tests/Unit/test_component_membrane.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Copyright (c) 2020, Build-A-Cell. All rights reserved.
# See LICENSE file in the project root directory for details.

from biocrnpyler import DiffusibleMolecule, IntegralMembraneProtein, MembraneChannel, MembranePump, MembraneSensor
import pytest

def test_DiffusibleMolecule():
diffusion_molecule = 'DP'

dm = DiffusibleMolecule(substrate=diffusion_molecule)
assert diffusion_molecule == dm.substrate.name
assert diffusion_molecule== dm.product.name

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

with pytest.raises(KeyError, match='Unable to find mechanism of type diffusion in Component'):
dm.update_species()

with pytest.raises(KeyError, match='Unable to find mechanism of type diffusion in Component'):
dm.update_reactions()

def test_IntegralMembraneProtein():
membrane_protein = 'MP1'
products = 'P1'

imp = IntegralMembraneProtein(membrane_protein=membrane_protein, product=products)
assert membrane_protein == imp.membrane_protein.name
assert products== imp.product.name

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

with pytest.raises(KeyError, match='Unable to find mechanism of type membrane_insertion in Component'):
imp.update_species()

with pytest.raises(KeyError, match='Unable to find mechanism of type membrane_insertion in Component'):
imp.update_reactions()

def test_MembraneChannel():
integral_membrane_protein = 'IMP1'
substrates = 'S1'

mc = MembraneChannel(integral_membrane_protein, substrate=substrates)
assert integral_membrane_protein == mc.integral_membrane_protein.name
assert substrates == mc.substrate.name
assert substrates == mc.product.name

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

with pytest.raises(KeyError, match='Unable to find mechanism of type transport in Component'):
mc.update_species()

with pytest.raises(KeyError, match='Unable to find mechanism of type transport in Component'):
mc.update_reactions()

def test_MembranePump():
membrane_pump = 'MPump1'
substrates = 'S1'

mp = MembranePump(membrane_pump, substrate=substrates)
assert membrane_pump == mp.membrane_pump.name
assert substrates == mp.substrate.name
assert substrates == mp.product.name

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

with pytest.raises(KeyError, match='Unable to find mechanism of type transport in Component'):
mp.update_species()

with pytest.raises(KeyError, match='Unable to find mechanism of type transport in Component'):
mp.update_reactions()

def test_MembraneSensor():
membrane_sensor = 'MSensor1'
response_protein = 'RP1'
assigned_substrate = 'Sub_A1'
signal_substrate = 'Sub_S1'

ms = MembraneSensor(membrane_sensor, response_protein=response_protein,
assigned_substrate=assigned_substrate, signal_substrate=signal_substrate)
assert response_protein == ms.response_protein.name
assert assigned_substrate == ms.assigned_substrate.name
assert signal_substrate == ms.signal_substrate.name

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

with pytest.raises(KeyError, match='Unable to find mechanism of type membrane_sensor in Component'):
ms.update_species()

with pytest.raises(KeyError, match='Unable to find mechanism of type membrane_sensor in Component'):
ms.update_reactions()
48 changes: 48 additions & 0 deletions Tests/Unit/test_membrane_signaling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

# Copyright (c) 2020, Build-A-Cell. All rights reserved.
# See LICENSE file in the project root directory for details.

from biocrnpyler import Species, Complex

#Test Membrane Transport Mechanisms
from biocrnpyler import Membrane_Signaling_Pathway_MM

class test_membrane_signaling_MM():
tcs = Membrane_Signaling_Pathway_MM()
MSP = Species("MSP1")
MSP.ATP=2
RP = Species("RP1")
sub_assign = Species("S1")
sub_signal = Species("S2")
energy = Species("E1")
waste = Species("W1")
c1 = Complex([sub_signal, MSP])
c2 = Complex([MSP.ATP*[energy], c1])
c3 = Complex([c1, MSP.ATP*[waste], sub_assign])
c4 = Complex([c1, sub_assign])
c5 = Complex([c4, RP])
c6 = Complex([c1, RP, sub_assign])
c7 = Complex([RP, sub_assign])

c_fake = Species("C")

#Test Update Species
assert len(tcs.update_species(MSP, RP, sub_assign, sub_signal, energy, waste)) == 13
assert c1 in tcs.update_species(MSP, RP, sub_assign, sub_signal, energy, waste)
assert c2 in tcs.update_species(MSP, RP, sub_assign, sub_signal, energy, waste)
assert c3 in tcs.update_species(MSP, RP, sub_assign, sub_signal, energy, waste)
assert c4 in tcs.update_species(MSP, RP, sub_assign, sub_signal, energy, waste)
assert c5 in tcs.update_species(MSP, RP, sub_assign, sub_signal, energy, waste)
assert c6 in tcs.update_species(MSP, RP, sub_assign, sub_signal, energy, waste)
assert c7 in tcs.update_species(MSP, RP, sub_assign, sub_signal, energy, waste)

assert c_fake in tcs.update_species(MSP, RP, sub_assign, sub_signal, energy, waste, complex = c_fake)

#Test Update Reactions
assert len(tcs.update_reactions(MSP, RP, sub_assign, sub_signal, energy, waste, kb1 = 2e-3, ku1 = 2e-10,
kb2 = 2e-3, ku2 = 2e-10, k_hydro = 1e-1, ku3 = 2e-1, kb4 = 2e-3, ku4 = 2e-10,
k_phosph = 1e-1, ku5 = 2e-1,ku6 = 2e-10)) == 8

assert len(tcs.update_reactions(MSP, RP, sub_assign, sub_signal, energy, waste, kb1 = 2e-3, ku1 = 2e-10,
kb2 = 2e-3, ku2 = 2e-10, k_hydro = 1e-1, ku3 = 2e-1, kb4 = 2e-3, ku4 = 2e-10,
k_phosph = 1e-1, ku5 = 2e-1,ku6 = 2e-10, complex_species = c_fake,)) == 8
101 changes: 101 additions & 0 deletions Tests/Unit/test_transport.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@

# Copyright (c) 2020, Build-A-Cell. All rights reserved.
# See LICENSE file in the project root directory for details.

from biocrnpyler import Species, Complex

#Test Membrane Transport Mechanisms
from biocrnpyler import Simple_Diffusion, Membrane_Protein_Integration, Simple_Transport, Facilitated_Transport_MM, Primary_Active_Transport_MM

class test_simple_diffusion():
sd = Simple_Diffusion()
substrate = Species("DMi")
product = Species("DMo")
c_fake = Species("C")
#Test Update Species
assert len(sd.update_species(substrate, product))==2
assert substrate in sd.update_species(substrate, product)
assert product in sd.update_species(substrate, product)

#Test Update Reactions
assert len(sd.update_reactions(substrate, product, k_diff = 1.0,)) == 1
assert len(sd.update_reactions(substrate, product, k_diff = 1.0, complex_species = c_fake,)) == 1

class test_membrane_integration():
mpi = Membrane_Protein_Integration()
MP = Species("MP1")
MP.size=2
IMP = Species("IMP1")
c1 = Complex([MP]*MP.size)
c_fake = Species("C")

#Test Update Species
assert len(mpi.update_species(MP, IMP)) == 4
assert c1 in mpi.update_species(MP, IMP)
assert c_fake in mpi.update_species(MP, IMP, complex = c_fake)

#Test Update Reactions
assert len(mpi.update_reactions(MP, IMP, kb1 = 1.0, ku1 = 1.0, kb2 = 1.0, ku2 = 1.0, kcat = 1.0, kex = 1.0)) == 2
assert len(mpi.update_reactions(MP, IMP, kb1 = 1.0, ku1 = 1.0, kb2 = 1.0, ku2 = 1.0, kcat = 1.0, kex = 1.0, complex_species = c_fake,)) == 2

class test_simple_transport():
st = Simple_Transport()
MC = Species("MC1")
MC.attributes=['Passive']
substrate = Species("S1")
product = Species("P1")

#Test Update Species
assert len(st.update_species(MC, substrate, product)) == 3

#Test Update Reactions
assert len(st.update_reactions(MC, substrate, product, k_channel = 1.0)) == 1

class test_facilitated_transport_MM():
ft = Facilitated_Transport_MM()
MC = Species("MC1")
MC.attributes=['Importer']
substrate = Species("S1")
product = Species("P1")
c1 = Complex([substrate, MC])
c2 = Complex([product, MC])
c_fake = Species("C")

#Test Update Species
assert len(ft.update_species(MC, substrate, product)) == 5
assert c1 in ft.update_species(MC, substrate, product)
assert c2 in ft.update_species(MC, substrate, product)
assert c_fake in ft.update_species(MC, substrate, product, complex = c_fake)

#Test Update Reactions
assert len(ft.update_reactions(MC, substrate, product, k1 = 1.0, ku1 = 1.0, ku2 = 1.0, k_trnsp = 1.0)) == 4
assert len(ft.update_reactions(MC, substrate, product, k1 = 1.0, ku1 = 1.0, ku2 = 1.0, k_trnsp = 1.0, complex_species = c_fake,)) == 4

class test_active_transport_MM():
pat = Primary_Active_Transport_MM()
MP = Species("MC1")
MP.ATP=2
MP.attributes=['Exporter']
substrate = Species("S1")
product = Species("P1")
energy = Species("E1")
waste = Species("W1")
c1 = Complex([substrate, MP])
c2 = Complex([product, MP])
c3 = Complex([MP.ATP*[energy], c1])
c4 = Complex([MP.ATP*[waste], c2])

c_fake = Species("C")

#Test Update Species
assert len(pat.update_species(MP, substrate, product, energy, waste)) == 9
assert c1 in pat.update_species(MP, substrate, product, energy, waste)
assert c2 in pat.update_species(MP, substrate, product, energy, waste)
assert c3 in pat.update_species(MP, substrate, product, energy, waste)
assert c4 in pat.update_species(MP, substrate, product, energy, waste)

assert c_fake in pat.update_species(MP, substrate, product, energy, waste, complex = c_fake)

#Test Update Reactions
assert len(pat.update_reactions(MP, substrate, product, energy, waste, k1 = 1.0, ku1 = 1.0, k2 = 1.0, ku2 = 1.0, k_trnsp = 1.0, ku3= 1.0, ku4= 1.0)) == 7
assert len(pat.update_reactions(MP, substrate, product, energy, waste, k1 = 1.0, ku1 = 1.0, k2 = 1.0, ku2 = 1.0, k_trnsp = 1.0, ku3= 1.0, ku4= 1.0, complex_species = c_fake,)) == 7
3 changes: 3 additions & 0 deletions biocrnpyler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from .integrase_enumerator import *
from .components_combinatorial_complex import *
from .components_combinatorial_conformation import *
from .components_membrane import *

from .global_mechanism import *
from .mechanism import *
Expand All @@ -25,6 +26,8 @@
from .mechanisms_enzyme import *
from .mechanisms_txtl import *
from .mechanisms_integrase import *
from .mechanisms_transport import *
from .mechanisms_signaling import *
# Core classes
from .mixture import *
from .mixtures_cell import *
Expand Down
9 changes: 6 additions & 3 deletions biocrnpyler/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,25 @@ def get_species(self) -> None:
"""
return None
@classmethod
def set_species(self, species: Union[Species, str], material_type=None, attributes=None) -> Species:
def set_species(self, species: Union[Species, str],
material_type=None, compartment=None,
attributes=None) -> Species:
"""Helper function that allows species to be set from strings, species, or Components

:param species: Species, str, Component
:param material_type:
:param compartment:
:param attributes:
:return: Species
"""
if isinstance(species, Species):
return species
elif isinstance(species, str):
return Species(name=species, material_type=material_type, attributes=attributes)
return Species(name=species, material_type=material_type, compartment=compartment, attributes=attributes)
elif isinstance(species, Component) and species.get_species() is not None:
return species.get_species()
elif isinstance(species, list):
return [self.set_species(s, material_type = material_type, attributes = attributes) for s in species]
return [self.set_species(s, material_type = material_type, compartment=compartment, attributes = attributes) for s in species]
else:
raise ValueError(f"Invalid Species: string, chemical_reaction_network.Species or Component with implemented .get_species() required as input. Recieved {species}")

Expand Down
Loading
Loading