Skip to content

Commit

Permalink
clean up cell process files
Browse files Browse the repository at this point in the history
  • Loading branch information
eagmon committed Oct 16, 2023
1 parent 208a109 commit 2e92f91
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 181 deletions.
58 changes: 23 additions & 35 deletions tumor_tcell/processes/dendritic_cell.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
==============
======================
Dendritic Cell Process
==============
======================
"""

import random
Expand All @@ -27,7 +27,11 @@ class DendriticCellProcess(Process):
"""DendriticCellProcess
References:
*
* Morefield, 2005
* Lammermann, 2008
* Naik, 2008
* Yang, 2006
* Apetoh, 2007
"""
defaults = {
'time_step': TIMESTEP,
Expand Down Expand Up @@ -67,9 +71,9 @@ def __init__(self, parameters=None):
diffusion_radius = diffusion_area ** 0.5
sphere_radius = self.parameters['diameter'] / 2 + diffusion_radius
external_tumor_debris_available_volume = 4 / 3 * self.parameters['pi'] * sphere_radius ** 3
self.molar_available_tumor_debris = (self.parameters['external_concentration_unit'] * \
external_tumor_debris_available_volume * self.parameters['nAvagadro'] / \
self.parameters['tumor_debris_MW']).to('count').magnitude
self.molar_available_tumor_debris = (self.parameters['external_concentration_unit'] *
external_tumor_debris_available_volume * self.parameters['nAvagadro'] /
self.parameters['tumor_debris_MW']).to('count').magnitude

def initial_state(self, config=None):
return {
Expand All @@ -82,7 +86,7 @@ def ports_schema(self):
'death': {
'_default': False,
'_emit': True,
'_updater': 'set'}, # nice to have. Need mechanism that turns death on. Low probability threshold?
'_updater': 'set'},
'divide': {
'_default': False,
'_updater': 'set'},
Expand All @@ -91,23 +95,20 @@ def ports_schema(self):
'_updater': 'accumulate'}}, # used to count number of divisions over time.
'internal': {
'cell_state': {
'_default': 'inactive',
'_default': 'inactive', # either 'activate' or 'inactive'
'_emit': True,
'_updater': 'set',
}, # either 'activate' or 'inactive'
'_updater': 'set'},
'tumor_debris': {
'_default': 0,
'_updater': 'accumulate',
'_emit': True},
'cell_state_count': {
'_default': 0,
'_updater': 'accumulate'}, # counts how many total cell in a given time. Might not be needed.
},
'_default': 0, # counts how many total cell in a given time. Might not be needed.
'_updater': 'accumulate'}},
'boundary': {
'cell_type': {
'_value': 'dendritic',
'_emit': True, },
# Might be needed for neighbors, but really for the experimenters to quantify
'mass': {
'_value': self.parameters['mass']},
'diameter': {
Expand All @@ -118,37 +119,26 @@ def ports_schema(self):
'external': {
'tumor_debris': {
'_default': 0.0, # TODO: units.ng / units.mL
'_emit': True
},
# 'lymph_node': { # this is True when in the lymph node, begins counter for how long.
# '_default': False
# },
},
'_emit': True}},
'exchange': {
'tumor_debris': {
'_default': 0,
'_updater': 'accumulate',
'_divider': 'split',
},
},
},
'neighbors': { # this is only for presenting in the lymph node, not in the tumor "arena"
'_divider': 'split'}}},
'neighbors': {
'present': {
'PDL1': {
'_default': 0,
'_updater': 'set'},
'MHCI': {
'_default': 0, # high level for activation, should come from environment
'_default': 0,
'_updater': 'set',
'_emit': True}},
'accept': {
'PD1': {'_default': 0},
'TCR': {
'_default': 0,
'_emit': True
}
}
}}
'_emit': True}}}}

def next_update(self, timestep, states):
cell_state = states['internal']['cell_state']
Expand Down Expand Up @@ -184,7 +174,7 @@ def next_update(self, timestep, states):
'PDL1n_divide_count': PDL1n_divide_count
}}

## Build up an update
# Build up an update
update = {
'internal': {},
'boundary': {},
Expand All @@ -208,10 +198,8 @@ def next_update(self, timestep, states):
tumor_debris_uptake = min(
int(self.parameters['tumor_debris_uptake'] * timestep),
int(available_tumor_debris_counts)) # TODO -- check this
update['boundary'].update(
{'exchange': {'tumor_debris': -tumor_debris_uptake}})
update['internal'].update({
'tumor_debris': tumor_debris_uptake})
update['boundary'].update({'exchange': {'tumor_debris': -tumor_debris_uptake}})
update['internal'].update({'tumor_debris': tumor_debris_uptake})

if new_cell_state == 'active':
PDL1 = self.parameters['PDL1p_PDL1_equilibrium']
Expand Down
84 changes: 38 additions & 46 deletions tumor_tcell/processes/lymph_node.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
"""
Lymph Node Environment Process
===========================
Lymph Node Transfer Process
===========================
This process moves cell agents between the tumor micro-environment and the lymph nodes (LN), and mediates interactions
between T cells and dendritic cells in the LN
"""

import math
Expand Down Expand Up @@ -31,15 +36,14 @@ def probability_of_occurrence_within_interval(interval_duration, expected_time):
within the time interval.
"""
lambda_ = interval_duration / expected_time
P_0 = math.exp(-lambda_)
P_at_least_one = 1 - P_0
return P_at_least_one
p_0 = math.exp(-lambda_)
p_at_least_one = 1 - p_0
return p_at_least_one


class LymphNode(Process):
"""Enable exchange of Dendritic cells between location,
interaction of T cells and Dendritic cells,
and T cells leaving to the environment
"""Enable exchange of Dendritic cells between locations, interaction of T cells and Dendritic cells, and T cells
leaving to the tumor micro-environment
"""
defaults = {
'time_step': TIMESTEP,
Expand All @@ -62,7 +66,7 @@ class LymphNode(Process):
'expected_interaction_duration': 28800, # 28800 8*60*60 t cells interact with dendritic cells for approximately \
# 8 hours (Itano, 2003)
'expected_delay_before_migration': 43200, # 43200 12*60*60. t cells wait approx 12 hours after interaction is \
# complete before starting migration (Itano, 2003);(Bousso, 2008)
# complete before starting migration (Itano, 2003); (Bousso, 2008)
}

def __init__(self, parameters=None):
Expand All @@ -84,39 +88,33 @@ def ports_schema(self):
'cell_state': {
'_default': 'inactive',
'_updater': 'set',
'_emit': True,}},
'_emit': True}},
'boundary': {
# cell_type must be either 'tumor', 't_cell', or 'dendritic'
'cell_type': {'_default': DEFAULT_CELL_TYPE,
'_emit': True,},
'cell_type': {'_default': DEFAULT_CELL_TYPE, # must be either 'tumor', 't_cell', or 'dendritic'
'_emit': True},
'diameter': {'_default': 1.0 * LENGTH_UNIT,
'_emit': True,},
'_emit': True},
'mass': {'_default': 1.0 * DEFAULT_MASS_UNIT,
'_emit': True,},
'_emit': True},
'velocity': {'_default': 0.0 * DEFAULT_VELOCITY_UNIT,
'_emit': True,},
'_emit': True},
'location': {
'_default': [0.5 * bound for bound in self.parameters['tumor_env_bounds']],
'_updater': 'set',
'_emit': True,
},
'_emit': True},
'external': {'IFNg': {'_default': 0.0,
'_emit': True,},
'tumor_debris': {'_default': 0.0,
'_emit': True,},}, # TODO -- this should not be required here
'death': {'_default': False,
'_emit': True,} # TODO -- this should not be required here
},
'_emit': True},
'tumor_debris': {'_default': 0.0, # TODO -- this should not be required here
'_emit': True}},
'death': {'_default': False, # TODO -- this should not be required here
'_emit': True}},
# initialize the schema for neighbors so cells will have it when moving back to tumor
'neighbors': {
'present': {'*': {'_default': 0.0, '_emit': True,}},
'accept': {'*': {'_default': 0.0, '_emit': True,}},
'transfer': {'*': {'_default': 0.0, '_emit': True,}},
'receive': {'*': {'_default': 0.0, '_emit': True,}}
}
}
}
}
'present': {'*': {'_default': 0.0, '_emit': True}},
'accept': {'*': {'_default': 0.0, '_emit': True}},
'transfer': {'*': {'_default': 0.0, '_emit': True}},
'receive': {'*': {'_default': 0.0, '_emit': True}}}}}}

return {
'cells': agents_schema,
'lymph_node': agents_schema,
Expand Down Expand Up @@ -152,7 +150,7 @@ def next_update(self, timestep, states):

if cell_type == 't-cell' and dendritic_cells_present:
if cell_state == 'interacting':
# interact with dendritic cells for 8 hours, then 12 hour delay before migrating to tumor
# interact with dendritic cells for 8 hours, then 12-hour delay before migrating to tumor
prob_interaction_completion = probability_of_occurrence_within_interval(
timestep, self.parameters['expected_interaction_duration'])
if random.uniform(0, 1) < prob_interaction_completion:
Expand All @@ -168,26 +166,22 @@ def next_update(self, timestep, states):
if random.uniform(0, 1) < prob_migration:
if '_move' not in lymph_node_update:
lymph_node_update['_move'] = []
# specs['internal']['cell_state'] = 'PD1n' # TODO -- get this state passed to cell
# begin transit from lymph node
lymph_node_update['_move'].append({
'source': (cell_id,),
'target': ('in_transit', 'agents',),
'update': {'internal': {'cell_state': 'PD1n'}}
})
'update': {'internal': {'cell_state': 'PD1n'}}})

else:
# Calculate probability of finding/initializing interaction with dendritic cells
# TODO -- this should depend on dendritic cell being present. Not interacting alone
prob_interaction = get_probability_timestep( # TODO -- ERAN -- why not probability_of_occurrence_within_interval?
prob_interaction = get_probability_timestep( # TODO -- ERAN -- why not probability_of_occurrence_within_interval?
self.parameters['tcell_find_dendritic_time'],
14400, # 14400 6 hours (6*60*60 seconds)
timestep) #(Itano, 2003)
timestep) # (Itano, 2003)
if random.uniform(0, 1) < prob_interaction:
# this t-cell is now interacting
lymph_node_update[cell_id] = {
'internal': {'cell_state': 'interacting'}
}
lymph_node_update[cell_id] = {'internal': {'cell_state': 'interacting'}}

#####################
# tumor environment #
Expand Down Expand Up @@ -227,8 +221,8 @@ def next_update(self, timestep, states):
# arrive at lymph node
in_transit_update['_move'].append({
'source': (cell_id,),
'target': ('lymph_node', 'agents',),
})
'target': ('lymph_node', 'agents',)})

if cell_type == 't-cell':
# tcells move from in_transit to tumor
prob_arrival = probability_of_occurrence_within_interval(
Expand All @@ -245,14 +239,12 @@ def next_update(self, timestep, states):
in_transit_update['_move'].append({
'source': (cell_id,),
'target': ('cells', 'agents'),
'update': {'boundary': {'location': location}}
})
'update': {'boundary': {'location': location}}})

return {
'cells': {'agents': cells_update},
'lymph_node': {'agents': lymph_node_update},
'in_transit': {'agents': in_transit_update},
}
'in_transit': {'agents': in_transit_update}}



Expand Down
Loading

0 comments on commit 2e92f91

Please sign in to comment.