Skip to content

Commit

Permalink
minor code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
eagmon committed Oct 15, 2023
1 parent daf1f40 commit 208a109
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 19 deletions.
6 changes: 5 additions & 1 deletion tumor_tcell/composites/dendritic_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,13 @@ def generate_topology(self, config):
# tests
def test_dendritic_agent(
total_time=1000,
agent_ids=['0'],
agent_ids=None,
agent_timeline=None,
initial_agent_state='PD1n',
):
"""run a test on dendritic cell agents"""
if agent_ids is None:
agent_ids = ['0']
composite = Composite()
for agent_id in agent_ids:
parameters = {'agent_id': agent_id}
Expand Down Expand Up @@ -191,6 +194,7 @@ def test_dendritic_agent(


def run_agent(out_dir='out'):
"""run one agent and plot results"""
agent_ids = ['0', '1']
agent_timeline = []
data = test_dendritic_agent(
Expand Down
7 changes: 6 additions & 1 deletion tumor_tcell/composites/t_cell_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,13 @@ def generate_topology(self, config):
# tests
def test_tcell_agent(
total_time=1000,
agent_ids=['0'],
agent_ids=None,
agent_timeline=None,
initial_agent_state='PD1n',
):
"""run a test on t cell agents"""
if agent_ids is None:
agent_ids = ['0']
composite = Composite()
for agent_id in agent_ids:
parameters = {
Expand Down Expand Up @@ -217,7 +220,9 @@ def test_tcell_agent(

return output


def run_agent(out_dir='out'):
"""run one agent and plot results"""
agent_ids = ['0', '1']
agent_timeline = [
(500, {
Expand Down
6 changes: 5 additions & 1 deletion tumor_tcell/composites/tumor_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,13 @@ def generate_topology(self, config):
# tests
def test_tumor_agent(
total_time=1000,
agent_ids=['0'],
agent_ids=None,
agent_timeline=None,
initial_agent_state='PDL1n',
):
"""run a test on tumor agents"""
if agent_ids is None:
agent_ids = ['0']
composite = Composite()
for agent_id in agent_ids:
parameters = {
Expand Down Expand Up @@ -217,6 +220,7 @@ def test_tumor_agent(


def run_agent(out_dir='out'):
"""run one agent and plot results"""
agent_ids = ['0', '1']
agent_timeline = []
data = test_tumor_agent(
Expand Down
7 changes: 1 addition & 6 deletions tumor_tcell/processes/dendritic_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from vivarium.library.units import units
from vivarium.processes.timeline import TimelineProcess

from tumor_tcell.processes.fields import DIFFUSION_RATES # , CONCENTRATION_UNIT
from tumor_tcell.processes.fields import DIFFUSION_RATES
from tumor_tcell.processes.tumor import get_probability_timestep

TIMESTEP = 60 # seconds
Expand Down Expand Up @@ -102,11 +102,6 @@ def ports_schema(self):
'cell_state_count': {
'_default': 0,
'_updater': 'accumulate'}, # counts how many total cell in a given time. Might not be needed.
# 'lymph_node_timer': {
# # counts how long in lymph node, high value increases chance of migration back to tumor
# '_default': 0, # TODO -- does the LN time this, or do the cells?
# '_emit': True,
# '_updater': 'accumulate'},
},
'boundary': {
'cell_type': {
Expand Down
2 changes: 1 addition & 1 deletion tumor_tcell/processes/lymph_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from vivarium.core.process import Process
from vivarium.core.engine import pp, Engine
from tumor_tcell.processes.t_cell import get_probability_timestep, TIMESTEP
from vivarium.library.units import remove_units
from tumor_tcell.library.location import random_location, DEFAULT_BOUNDS
from tumor_tcell.processes.local_field import LENGTH_UNIT
from tumor_tcell.processes.neighbors import DEFAULT_MASS_UNIT, DEFAULT_VELOCITY_UNIT
Expand Down Expand Up @@ -258,6 +257,7 @@ def next_update(self, timestep, states):


def test_lymph_node():
"""run a test for moving cells between the lymph node and tumor environment"""
simtime = 1000000
init_state = {
'cells': {
Expand Down
27 changes: 18 additions & 9 deletions tumor_tcell/processes/neighbors.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
# directories
from tumor_tcell import PROCESS_OUT_DIR


NAME = 'neighbors'
DEFAULT_MASS_UNIT = units.ng
DEFAULT_VELOCITY_UNIT = units.um / units.s
Expand All @@ -56,22 +55,26 @@ def daughter_locations(mother_location, state):
mother_y = mother_location[1]
locations = []
for daughter in range(2):
location = [mother_x + random.gauss(0, 0.1)*mother_diameter, mother_y + random.gauss(0, 0.1)*mother_diameter]
location = [mother_x + random.gauss(0, 0.1) * mother_diameter,
mother_y + random.gauss(0, 0.1) * mother_diameter]
locations.append(location)
return locations


def sphere_volume_from_diameter(diameter):
"""Given a diameter for a sphere, return the volume"""
radius = diameter / 2
volume = 4 / 3 * (PI * radius**3)
volume = 4 / 3 * (PI * radius ** 3)
return volume


def make_random_position(bounds):
"""Return a random position with the [x, y] bounds"""
return [
np.random.uniform(0, bound.magnitude) * bound.units
for bound in bounds]


def add_to_dict(dict, added):
for k, v in added.items():
if k in dict:
Expand All @@ -80,6 +83,7 @@ def add_to_dict(dict, added):
dict[k] = v
return dict


def remove_from_dict(dict, removed):
for k, v in removed.items():
if k in dict:
Expand Down Expand Up @@ -145,7 +149,7 @@ def __init__(self, parameters=None):
'bounds': [
b.to(self.length_unit).magnitude
for b in parameters['bounds']],
'physics_dt': min(timestep/10, 0.1)}
'physics_dt': min(timestep / 10, 0.1)}
self.physics = Pymunk(multibody_config)

# interactive plot for visualization
Expand Down Expand Up @@ -271,7 +275,8 @@ def bodies_remove_units(self, bodies):
"""
for bodies_id, specs in bodies.items():
# convert location
bodies[bodies_id]['boundary']['location'] = [loc.to(self.length_unit).magnitude for loc in specs['boundary']['location']]
bodies[bodies_id]['boundary']['location'] = [loc.to(self.length_unit).magnitude for loc in
specs['boundary']['location']]
# convert diameter
bodies[bodies_id]['boundary']['diameter'] = specs['boundary']['diameter'].to(self.length_unit).magnitude
# convert mass
Expand Down Expand Up @@ -359,16 +364,18 @@ def animate_frame(self, cells):

xl = self.remove_length_units(bounds[0])
yl = self.remove_length_units(bounds[1])
plt.xlim([-xl, 2*xl])
plt.ylim([-yl, 2*yl])
plt.xlim([-xl, 2 * xl])
plt.ylim([-yl, 2 * yl])
plt.draw()
plt.pause(0.01)


# configs
DEFAULT_DIAMETER = 7.5 * DEFAULT_LENGTH_UNIT


def single_cell_config(config):
"""return config dict for a single cell"""
# cell dimensions
diameter = DEFAULT_DIAMETER
volume = sphere_volume_from_diameter(diameter)
Expand Down Expand Up @@ -402,6 +409,7 @@ def cell_body_config(config):
class InvokeUpdate(object):
def __init__(self, update):
self.update = update

def get(self, timeout=0):
return self.update

Expand All @@ -411,6 +419,7 @@ def get(self, timeout=0):
'bounds': DEFAULT_BOUNDS,
'cell_ids': ['1', '2']}))


def test_growth_division(config=default_gd_config, settings={}):
initial_cells_state = config['cells']

Expand All @@ -426,7 +435,7 @@ def test_growth_division(config=default_gd_config, settings={}):
'diameter': {
'_updater': 'set',
'_divider': 'split'},
}})
}})
experiment.state._apply_subschemas()

# get initial cell state
Expand Down Expand Up @@ -489,6 +498,7 @@ def test_growth_division(config=default_gd_config, settings={}):
experiment.end()
return experiment.emitter.get_data()


def multibody_neighbors_workflow(
config={}, out_dir='out', filename='neighbors'):
n_cells = 2
Expand All @@ -514,7 +524,6 @@ def multibody_neighbors_workflow(
gd_data = test_growth_division(gd_config, settings)



if __name__ == '__main__':
out_dir = os.path.join(PROCESS_OUT_DIR, NAME)
if not os.path.exists(out_dir):
Expand Down

0 comments on commit 208a109

Please sign in to comment.