How to know cell types

Hi,
how can I loop through different cells created after using divide() and know the cell types (mother or daughter). For example, differentiate and count the mother and daughter cells after some simulation time step, so that at nth time of division, after reaching around 200 cells, I can stop the cell division.
Thanks,
Swarnika

1 Like

Hi, just to clarify: Swarnika is asking how one can loop through all cells at each simulation step, and check if the cell belongs to a certain cell type or not. If so, a counter is increased. Cheers

1 Like

well, if that’s the case then, Swarnika you can create a “new” Agent class (that inherits BiodynaMo’s corresponding class) which has as member object an integer variable - you could use it as an indicator of the cell phenotype.

wrt the division aspect, you could also add an extra integer counter (that increments every time a cell multiplies) - this would mean you’d need to create a virtual function (that employs DivisiionEvent class) so that it updates this counter :wink:

cheers

1 Like

Thank you VasVav. Please, if you could also share a sample code for the same.

Also, I would like to share a code snippet from the Demo in BioDynamo Tutorials (from soma_clustering->validation_criterion.h) which can be of use to loop through all cells and extract the cell types:

rm->ForEachAgent([&](Agent* agent) {
if (auto* cell = dynamic_cast<MyCell*>(agent)) {
const auto& pos = cell->GetPosition();
auto type = cell->GetCellType();

  if ((fabs(pos[0] - 0.5) < sub_vol_max) &&
      (fabs(pos[1] - 0.5) < sub_vol_max) &&
      (fabs(pos[2] - 0.5) < sub_vol_max)) {
    pos_sub_vol[num_cells_sub_vol][0] = pos[0];
    pos_sub_vol[num_cells_sub_vol][1] = pos[1];
    pos_sub_vol[num_cells_sub_vol][2] = pos[2];
    types_sub_vol[num_cells_sub_vol] = type;
    num_cells_sub_vol++;
  }
}

});

Thanks

1 Like

hi @Swarnika, and my sincere apologies for the ultra slow response…

here is a code you could use to do the job (havent 100% tested if it compiles ok) :wink:

class MyCell : public neuroscience::NeuronSoma {
BDM_AGENT_HEADER(MyCell, neuroscience::NeuronSoma, 1);
//
public:
  MyCell () {}
  explicit MyCell (size_t pheno, const Double3& xyz) :
    neuroscience::NeuronSoma(xyz), phenotype_(pheno) {}
  //
  void Initialize (const NewAgentEvent& event) override {
    neuroscience::NeuronSoma::Initialize(event);
    // if cell divides then attributes have to be initialized
    if (auto* mother = dynamic_cast<InVitroNeuro_Cell*>(event.existing_agent))
    {
      if (event.GetUid() == bdm::CellDivisionEvent::kUid) {
        phenotype_ = mother->GetPhenotype();
      } else {
        bdm::Log::Fatal(std::string(__FILE__),"error @line "+std::to_string(__LINE__));
      }
    }
  }
  //
  void SetPhenotype (int p) { phenotype_ = p; }
  int GetPhenotype () const { return phenotype_; }
//
private:
  // index to designate the cell phenotype
  size_t phenotype_ = 0;  
};

please have a look and let me know what you think :slight_smile:

Hi @VasVav, Thanks for sharing.