Skip to content

Commit

Permalink
update asym div as per conversation
Browse files Browse the repository at this point in the history
- use probabilities instead of weights
- move Asymmetric_Division into Cycle
- move xml element inside cycle
- update sample project
  • Loading branch information
drbergman committed Oct 11, 2024
1 parent f67d454 commit cf66287
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 172 deletions.
126 changes: 45 additions & 81 deletions core/PhysiCell_cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ Cell_Definition::Cell_Definition()
// are appropriately sized. Same on motiltiy.
phenotype.cell_interactions.sync_to_cell_definitions();
phenotype.cell_transformations.sync_to_cell_definitions();
phenotype.cell_asymmetric_divisions.sync_to_cell_definitions();
phenotype.cycle.asymmetric_division.sync_to_cell_definitions();
phenotype.motility.sync_to_current_microenvironment();
phenotype.mechanics.sync_to_cell_definitions();

Expand Down Expand Up @@ -2034,7 +2034,7 @@ Cell_Definition* initialize_cell_definition_from_pugixml( pugi::xml_node cd_node
pCD->phenotype.cell_transformations.transformation_rates.assign(number_of_cell_defs,0.0);

// asymmetric division
pCD->phenotype.cell_asymmetric_divisions.asymmetric_division_weights.assign(number_of_cell_defs,0.0);
pCD->phenotype.cycle.asymmetric_division.asymmetric_division_probabilities.assign(number_of_cell_defs,0.0);
}
else
{
Expand Down Expand Up @@ -2073,7 +2073,7 @@ Cell_Definition* initialize_cell_definition_from_pugixml( pugi::xml_node cd_node
// this requires that prebuild_cell_definition_index_maps was already run
pCD->phenotype.cell_interactions.sync_to_cell_definitions();
pCD->phenotype.cell_transformations.sync_to_cell_definitions();
pCD->phenotype.cell_asymmetric_divisions.sync_to_cell_definitions();
pCD->phenotype.cycle.asymmetric_division.sync_to_cell_definitions();
pCD->phenotype.mechanics.sync_to_cell_definitions();

// set the reference phenotype
Expand Down Expand Up @@ -2222,11 +2222,49 @@ Cell_Definition* initialize_cell_definition_from_pugixml( pugi::xml_node cd_node

node = node.next_sibling( "duration" );
}

}



node = cd_node.child( "phenotype" );
node = node.child( "cycle" );
node = node.child( "standard_asymmetric_division" );
if( node && node.attribute("enabled").as_bool() )
{
Asymmetric_Division *pAD = &(pCD->phenotype.cycle.asymmetric_division);

// asymmetric division rates
pugi::xml_node node_adp = node.child( "asymmetric_division_probability");
while (node_adp)
{
// get the name of the target cell type
std::string target_name = node_adp.attribute("name").value();
// now find its index
auto search = cell_definition_indices_by_name.find(target_name);
// safety first!
if( search != cell_definition_indices_by_name.end() )
{
// if the target is found, set the appropriate rate
int target_index = search->second;

double asymmetric_division_probability = xml_get_my_double_value(node_adp);
pAD->asymmetric_division_probabilities[target_index] = asymmetric_division_probability;
}
else
{
std::cout << "Error: When processing the " << pCD->name << " cell definition: " << std::endl
<< "\tCould not find cell type " << target_name << " for asymmetric division." << std::endl
<< "\tRemove this cell type from the asymmetric division probabilities!" << std::endl << std::endl;
exit(-1);
}
node_adp = node_adp.next_sibling("asymmetric_division_probability");
}
std::cout << "Asymmetric division probabilities for " << pCD->name << ": ";
for (int i = 0; i < pAD->asymmetric_division_probabilities.size(); i++)
{
std::cout << pAD->asymmetric_division_probabilities[i] << " ";
}
std::cout << std::endl;
pCD->functions.cell_division_function = standard_asymmetric_division_function;
}
}

// here's what it ***should*** do:
Expand Down Expand Up @@ -2442,45 +2480,11 @@ Cell_Definition* initialize_cell_definition_from_pugixml( pugi::xml_node cd_node
node = node.next_sibling( "duration" );
}


/*
if( node.child( "phase_durations" ) )
{ node = node.child( "phase_durations" ); }
if( node )
{
node = node.child( "duration");
while( node )
{
// which duration?
int start = node.attribute("index").as_int();
// fixed duration?
bool fixed = false;
if( node.attribute( "fixed_duration" ) )
{ fixed = node.attribute("fixed_duration").as_bool(); }
// actual value of the duration
double value = xml_get_my_double_value( node );
// set the transition rate
pCD->phenotype.cycle.data.exit_rate(start) = 1.0 / (value+1e-16);
// set it to fixed / non-fixed
pCD->phenotype.cycle.model().phase_links[start][0].fixed_duration = fixed;
node = node.next_sibling( "duration" );
}
}
*/


node = node.parent(); // phase_durations
node = node.parent(); // model
}

// node = node.parent();

model_node = model_node.next_sibling( "model" );
// death_model_index++;
}

}
Expand Down Expand Up @@ -2825,7 +2829,7 @@ Cell_Definition* initialize_cell_definition_from_pugixml( pugi::xml_node cd_node
}
std::cout << std::endl;
}
}
}

// secretion

Expand Down Expand Up @@ -3068,46 +3072,6 @@ Cell_Definition* initialize_cell_definition_from_pugixml( pugi::xml_node cd_node
}

node = cd_node.child( "phenotype" );
node = node.child( "cell_asymmetric_divisions" );
if( node )
{
Cell_Asymmetric_Divisions *pCAD = &(pCD->phenotype.cell_asymmetric_divisions);

// asymmetric division rates
pugi::xml_node node_cad = node.child( "asymmetric_division_weights");
if( node_cad )
{ node_cad = node_cad.child( "asymmetric_division_weight"); }
while (node_cad)
{
// get the name of the target cell type
std::string target_name = node_cad.attribute("name").value();
// now find its index
auto search = cell_definition_indices_by_name.find(target_name);
// safety first!
if( search != cell_definition_indices_by_name.end() )
{
// if the target is found, set the appropriate rate
int target_index = search->second;

double asymmetric_division_weight = xml_get_my_double_value(node_cad);
pCAD->asymmetric_division_weights[target_index] = asymmetric_division_weight;
}
else
{
std::cout << "Error: When processing the " << pCD->name << " cell definition: " << std::endl
<< "\tCould not find cell type " << target_name << " for asymmetric division." << std::endl
<< "\tRemove this cell type from the asymmetric division weights!" << std::endl << std::endl;
exit(-1);
}
node_cad = node_cad.next_sibling("asymmetric_division_weight");
}
for (int i = 0; i < pCAD->asymmetric_division_weights.size(); i++)
{
std::cout << pCAD->asymmetric_division_weights[i] << " ";
}
std::cout << std::endl;
pCD->functions.cell_division_function = standard_asymmetric_division_function;
}

// intracellular
node = cd_node.child( "phenotype" );
Expand Down
21 changes: 10 additions & 11 deletions core/PhysiCell_phenotype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,6 @@ Phenotype& Phenotype::operator=(const Phenotype &p ) {

cell_interactions = p.cell_interactions;
cell_transformations = p.cell_transformations;
cell_asymmetric_divisions = p.cell_asymmetric_divisions;

return *this;
}
Expand Down Expand Up @@ -1359,36 +1358,36 @@ double& Cell_Transformations::transformation_rate( std::string type_name )
return transformation_rates[n];
}

Cell_Asymmetric_Divisions::Cell_Asymmetric_Divisions()
Asymmetric_Division::Asymmetric_Division()
{
asymmetric_division_weights = {0.0};
asymmetric_division_probabilities = {0.0};
}

void Cell_Asymmetric_Divisions::sync_to_cell_definitions()
void Asymmetric_Division::sync_to_cell_definitions()
{
extern std::unordered_map<std::string,int> cell_definition_indices_by_name;
int number_of_cell_defs = cell_definition_indices_by_name.size();

if( asymmetric_division_weights.size() != number_of_cell_defs )
{ asymmetric_division_weights.resize( number_of_cell_defs, 0.0); }
if( asymmetric_division_probabilities.size() != number_of_cell_defs )
{ asymmetric_division_probabilities.resize( number_of_cell_defs, 0.0); }

return;
}

double Cell_Asymmetric_Divisions::weights_total( void )
double Asymmetric_Division::probabilities_total( void )
{
double total = 0.0;
for( int i=0; i < asymmetric_division_weights.size(); i++ )
{ total += asymmetric_division_weights[i]; }
for( int i=0; i < asymmetric_division_probabilities.size(); i++ )
{ total += asymmetric_division_probabilities[i]; }
return total;
}

// ease of access
double& Cell_Asymmetric_Divisions::asymmetric_division_weight( std::string type_name )
double& Asymmetric_Division::asymmetric_division_probability( std::string type_name )
{
extern std::unordered_map<std::string,int> cell_definition_indices_by_name;
int n = cell_definition_indices_by_name[type_name];
return asymmetric_division_weights[n];
return asymmetric_division_probabilities[n];
}

// beta functionality in 1.10.3
Expand Down
37 changes: 19 additions & 18 deletions core/PhysiCell_phenotype.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,23 @@ class Cycle_Model
std::ostream& display( std::ostream& os ); // done
};

class Asymmetric_Division
{
private:
public:
// rates of asymmetric division into different cell types
std::vector<double> asymmetric_division_probabilities;

// initialization
Asymmetric_Division(); // done
void sync_to_cell_definitions(); // done

double probabilities_total();

// ease of access
double& asymmetric_division_probability( std::string type_name ); // done
};

class Cycle
{
private:
Expand All @@ -230,6 +247,8 @@ class Cycle
int& current_phase_index( void ); // done

void sync_to_cycle_model( Cycle_Model& cm ); // done

Asymmetric_Division asymmetric_division;
};

class Death_Parameters
Expand Down Expand Up @@ -718,23 +737,6 @@ class Cell_Transformations
// void perform_transformations( Cell* pCell, Phenotype& phenotype, double dt );
};

class Cell_Asymmetric_Divisions
{
private:
public:
// rates of asymmetric division into different cell types
std::vector<double> asymmetric_division_weights;

// initialization
Cell_Asymmetric_Divisions(); // done
void sync_to_cell_definitions(); // done

double weights_total();

// ease of access
double& asymmetric_division_weight( std::string type_name ); // done
};

// pre-beta functionality in 1.10.3
class Cell_Integrity
{
Expand Down Expand Up @@ -791,7 +793,6 @@ class Phenotype

Cell_Interactions cell_interactions;
Cell_Transformations cell_transformations;
Cell_Asymmetric_Divisions cell_asymmetric_divisions;

Phenotype(); // done
Phenotype(const Phenotype &p);
Expand Down
Loading

0 comments on commit cf66287

Please sign in to comment.