Cell.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "Cell.hpp"
00037
00050 struct null_deleter
00051 {
00053 void operator()(void const *) const
00054 {
00055 }
00056 };
00057
00058 Cell::Cell(boost::shared_ptr<AbstractCellProperty> pMutationState,
00059 AbstractCellCycleModel* pCellCycleModel,
00060 bool archiving,
00061 CellPropertyCollection cellPropertyCollection)
00062 : mCanDivide(false),
00063 mCellPropertyCollection(cellPropertyCollection),
00064 mpCellCycleModel(pCellCycleModel),
00065 mDeathTime(DBL_MAX),
00066 mStartOfApoptosisTime(DBL_MAX),
00067 mApoptosisTime(0.25),
00068 mUndergoingApoptosis(false),
00069 mIsDead(false),
00070 mIsLogged(false)
00071 {
00072 if (SimulationTime::Instance()->IsStartTimeSetUp()==false)
00073 {
00074 EXCEPTION("Cell is setting up a cell-cycle model but SimulationTime has not been set up");
00075 }
00076
00077 if (pCellCycleModel == NULL)
00078 {
00079 EXCEPTION("Cell-cycle model is null");
00080 }
00081
00082 mpCellCycleModel->SetCell(CellPtr(this, null_deleter()));
00083
00084 if (!mCellPropertyCollection.HasPropertyType<CellId>())
00085 {
00086
00087 MAKE_PTR(CellId, p_cell_id);
00088 p_cell_id->AssignCellId();
00089 mCellPropertyCollection.AddProperty(p_cell_id);
00090 }
00091
00092 if (!pMutationState->IsSubType<AbstractCellMutationState>())
00093 {
00094 EXCEPTION("Attempting to create cell with a cell mutation state that is not a subtype of AbstractCellMutationState");
00095 }
00096
00097 if (!mCellPropertyCollection.HasProperty(pMutationState))
00098 {
00099 mCellPropertyCollection.AddProperty(pMutationState);
00100 }
00101
00102 if (!mCellPropertyCollection.HasPropertyType<CellData>())
00103 {
00104
00105 MAKE_PTR(CellData, p_cell_data);
00106 mCellPropertyCollection.AddProperty(p_cell_data);
00107 }
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 if (!mCellPropertyCollection.HasPropertyType<AbstractCellProliferativeType>())
00118 {
00119 mCellPropertyCollection.AddProperty(CellPropertyRegistry::Instance()->Get<DefaultCellProliferativeType>());
00120 }
00121
00122 if (!archiving)
00123 {
00124
00125 for (CellPropertyCollection::Iterator property_iter = mCellPropertyCollection.Begin();
00126 property_iter != mCellPropertyCollection.End();
00127 ++property_iter)
00128 {
00129 (*property_iter)->IncrementCellCount();
00130 }
00131 }
00132 }
00133
00134 Cell::~Cell()
00135 {
00136 if (!mIsDead)
00137 {
00138 Kill();
00139 }
00140 delete mpCellCycleModel;
00141 }
00142
00143 void Cell::SetCellProliferativeType(boost::shared_ptr<AbstractCellProperty> pProliferativeType)
00144 {
00145 if (!pProliferativeType->IsSubType<AbstractCellProliferativeType>())
00146 {
00147 EXCEPTION("Attempting to give cell a cell proliferative type that is not a subtype of AbstractCellProliferativeType");
00148 }
00149
00150 boost::shared_ptr<AbstractCellProliferativeType> p_old_proliferative_type = GetCellProliferativeType();
00151
00152 p_old_proliferative_type->DecrementCellCount();
00153 mCellPropertyCollection.RemoveProperty(p_old_proliferative_type);
00154
00155 AddCellProperty(pProliferativeType);
00156 }
00157
00158 boost::shared_ptr<AbstractCellProliferativeType> Cell::GetCellProliferativeType() const
00159 {
00160 CellPropertyCollection proliferative_type_collection = mCellPropertyCollection.GetPropertiesType<AbstractCellProliferativeType>();
00161
00162
00163
00164
00165
00166
00167
00168 assert(proliferative_type_collection.GetSize() == 1);
00169
00170 return boost::static_pointer_cast<AbstractCellProliferativeType>(proliferative_type_collection.GetProperty());
00171 }
00172
00173 void Cell::SetCellCycleModel(AbstractCellCycleModel* pCellCycleModel)
00174 {
00175 if (mpCellCycleModel != pCellCycleModel)
00176 {
00177 delete mpCellCycleModel;
00178 }
00179 mpCellCycleModel = pCellCycleModel;
00180 mpCellCycleModel->SetCell(CellPtr(this, null_deleter()));
00181 }
00182
00183 AbstractCellCycleModel* Cell::GetCellCycleModel() const
00184 {
00185 return mpCellCycleModel;
00186 }
00187
00188 void Cell::InitialiseCellCycleModel()
00189 {
00190 mpCellCycleModel->Initialise();
00191 }
00192
00193 double Cell::GetAge() const
00194 {
00195 return mpCellCycleModel->GetAge();
00196 }
00197
00198 double Cell::GetBirthTime() const
00199 {
00200 return mpCellCycleModel->GetBirthTime();
00201 }
00202
00203 void Cell::SetBirthTime(double birthTime)
00204 {
00205 mpCellCycleModel->SetBirthTime(birthTime);
00206 }
00207
00208 void Cell::SetMutationState(boost::shared_ptr<AbstractCellProperty> pMutationState)
00209 {
00210 if (!pMutationState->IsSubType<AbstractCellMutationState>())
00211 {
00212 EXCEPTION("Attempting to give cell a cell mutation state that is not a subtype of AbstractCellMutationState");
00213 }
00214
00215 boost::shared_ptr<AbstractCellMutationState> p_old_mutation_state = GetMutationState();
00216 p_old_mutation_state->DecrementCellCount();
00217 mCellPropertyCollection.RemoveProperty(p_old_mutation_state);
00218
00219 AddCellProperty(pMutationState);
00220 }
00221
00222 boost::shared_ptr<AbstractCellMutationState> Cell::GetMutationState() const
00223 {
00224 CellPropertyCollection mutation_state_collection = mCellPropertyCollection.GetPropertiesType<AbstractCellMutationState>();
00225
00226
00227
00228
00229
00230
00231
00232 assert(mutation_state_collection.GetSize() == 1);
00233
00234 return boost::static_pointer_cast<AbstractCellMutationState>(mutation_state_collection.GetProperty());
00235 }
00236
00237 boost::shared_ptr<CellData> Cell::GetCellData() const
00238 {
00239 CellPropertyCollection cell_data_collection = mCellPropertyCollection.GetPropertiesType<CellData>();
00240
00241
00242
00243
00244
00245 assert(cell_data_collection.GetSize() <= 1);
00246
00247 return boost::static_pointer_cast<CellData>(cell_data_collection.GetProperty());
00248 }
00249
00250 CellPropertyCollection& Cell::rGetCellPropertyCollection()
00251 {
00252 return mCellPropertyCollection;
00253 }
00254
00255 const CellPropertyCollection& Cell::rGetCellPropertyCollection() const
00256 {
00257 return mCellPropertyCollection;
00258 }
00259
00260 void Cell::AddCellProperty(const boost::shared_ptr<AbstractCellProperty>& rProperty)
00261 {
00262
00263 if (!mCellPropertyCollection.HasProperty(rProperty))
00264 {
00265 mCellPropertyCollection.AddProperty(rProperty);
00266 rProperty->IncrementCellCount();
00267 }
00268 }
00269
00270 void Cell::SetLogged()
00271 {
00272 mIsLogged = true;
00273 }
00274
00275 bool Cell::IsLogged()
00276 {
00277 return mIsLogged;
00278 }
00279
00280 void Cell::StartApoptosis(bool setDeathTime)
00281 {
00282 assert(!IsDead());
00283
00284 if (mUndergoingApoptosis)
00285 {
00286 EXCEPTION("StartApoptosis() called when already undergoing apoptosis");
00287 }
00288 mUndergoingApoptosis = true;
00289 mStartOfApoptosisTime = SimulationTime::Instance()->GetTime();
00290 if (setDeathTime)
00291 {
00292 mDeathTime = mStartOfApoptosisTime + mApoptosisTime;
00293 }
00294 else
00295 {
00296 mDeathTime = DBL_MAX;
00297 }
00298 AddCellProperty(mCellPropertyCollection.GetCellPropertyRegistry()->Get<ApoptoticCellProperty>());
00299 }
00300
00301 bool Cell::HasApoptosisBegun() const
00302 {
00303 return mUndergoingApoptosis;
00304 }
00305
00306 double Cell::GetStartOfApoptosisTime() const
00307 {
00308 return mStartOfApoptosisTime;
00309 }
00310
00311 double Cell::GetApoptosisTime() const
00312 {
00313 return mApoptosisTime;
00314 }
00315
00316 void Cell::SetApoptosisTime(double apoptosisTime)
00317 {
00318 assert(apoptosisTime > 0.0);
00319 mApoptosisTime = apoptosisTime;
00320 }
00321
00322 double Cell::GetTimeUntilDeath() const
00323 {
00324 if (!mUndergoingApoptosis || mDeathTime==DBL_MAX)
00325 {
00326 EXCEPTION("Shouldn't be checking time until apoptosis as it isn't set");
00327 }
00328
00329 return mDeathTime - SimulationTime::Instance()->GetTime();
00330 }
00331
00332 bool Cell::IsDead()
00333 {
00334 if (mUndergoingApoptosis && !mIsDead)
00335 {
00336 double sloppy_death_time = mDeathTime - DBL_EPSILON * mApoptosisTime;
00337 if (SimulationTime::Instance()->GetTime() >= sloppy_death_time )
00338 {
00339 this->Kill();
00340 }
00341 }
00342 return mIsDead;
00343 }
00344
00345 void Cell::Kill()
00346 {
00347
00348 for (CellPropertyCollection::Iterator property_iter = mCellPropertyCollection.Begin();
00349 property_iter != mCellPropertyCollection.End();
00350 ++property_iter)
00351 {
00352 (*property_iter)->DecrementCellCount();
00353 }
00354 mIsDead = true;
00355 }
00356
00357 void Cell::SetAncestor(boost::shared_ptr<AbstractCellProperty> pCellAncestor)
00358 {
00359 if (!pCellAncestor->IsSubType<CellAncestor>())
00360 {
00361 EXCEPTION("Attempting to give cell a cell ancestor which is not a CellAncestor");
00362 }
00363
00364
00365 CellPropertyCollection ancestor_collection = mCellPropertyCollection.GetPropertiesType<CellAncestor>();
00366 if (ancestor_collection.GetSize() == 0)
00367 {
00368 AddCellProperty(pCellAncestor);
00369 }
00370 else
00371 {
00372
00373 RemoveCellProperty<CellAncestor>();
00374 AddCellProperty(pCellAncestor);
00375 }
00376 }
00377
00378 unsigned Cell::GetAncestor() const
00379 {
00380 CellPropertyCollection ancestor_collection = mCellPropertyCollection.GetPropertiesType<CellAncestor>();
00381
00382 assert(ancestor_collection.GetSize() <= 1);
00383 if (ancestor_collection.GetSize() == 0)
00384 {
00385 return UNSIGNED_UNSET;
00386 }
00387
00388 boost::shared_ptr<CellAncestor> p_ancestor = boost::static_pointer_cast<CellAncestor>(ancestor_collection.GetProperty());
00389
00390 return p_ancestor->GetAncestor();
00391 }
00392
00393 unsigned Cell::GetCellId() const
00394 {
00395 CellPropertyCollection cell_id_collection = mCellPropertyCollection.GetPropertiesType<CellId>();
00396
00397 assert(cell_id_collection.GetSize() == 1);
00398
00399 boost::shared_ptr<CellId> p_cell_id = boost::static_pointer_cast<CellId>(cell_id_collection.GetProperty());
00400
00401 return p_cell_id->GetCellId();
00402 }
00403
00404 bool Cell::ReadyToDivide()
00405 {
00406 assert(!IsDead());
00407 if (mUndergoingApoptosis || HasCellProperty<ApoptoticCellProperty>())
00408 {
00409 return false;
00410 }
00411
00412 mCanDivide = mpCellCycleModel->ReadyToDivide();
00413
00414 return mCanDivide;
00415 }
00416
00417 CellPtr Cell::Divide()
00418 {
00419
00420 assert(!IsDead());
00421 assert(mCanDivide);
00422 mCanDivide = false;
00423
00424
00425 mpCellCycleModel->ResetForDivision();
00426
00427
00428 CellPropertyCollection daughter_property_collection = mCellPropertyCollection;
00429
00430
00431 daughter_property_collection.RemoveProperty<CellId>();
00432
00433
00434 assert(daughter_property_collection.HasPropertyType<CellData>());
00435
00436
00437 boost::shared_ptr<CellData> p_cell_data = GetCellData();
00438 daughter_property_collection.RemoveProperty(p_cell_data);
00439
00440
00441 MAKE_PTR_ARGS(CellData, p_daughter_cell_data, (*p_cell_data));
00442 daughter_property_collection.AddProperty(p_daughter_cell_data);
00443
00444
00445 CellPtr p_new_cell(new Cell(GetMutationState(), mpCellCycleModel->CreateCellCycleModel(), false, daughter_property_collection));
00446
00447
00448 p_new_cell->GetCellCycleModel()->InitialiseDaughterCell();
00449
00450
00451 p_new_cell->SetApoptosisTime(mApoptosisTime);
00452
00453 return p_new_cell;
00454 }