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 #include "Cell.hpp"
00030 #include "ApoptoticCellProperty.hpp"
00031
00032 unsigned Cell::mMaxCellId = 0;
00033
00046 struct null_deleter
00047 {
00049 void operator()(void const *) const
00050 {
00051 }
00052 };
00053
00054 Cell::Cell(boost::shared_ptr<AbstractCellProperty> pMutationState,
00055 AbstractCellCycleModel* pCellCycleModel,
00056 bool archiving,
00057 CellPropertyCollection cellPropertyCollection)
00058 : mCanDivide(false),
00059 mCellPropertyCollection(cellPropertyCollection),
00060 mpCellCycleModel(pCellCycleModel),
00061 mAncestor(UNSIGNED_UNSET),
00062 mDeathTime(DBL_MAX),
00063 mStartOfApoptosisTime(DBL_MAX),
00064 mApoptosisTime(0.25),
00065 mUndergoingApoptosis(false),
00066 mIsDead(false),
00067 mIsLogged(false)
00068 {
00069 if (SimulationTime::Instance()->IsStartTimeSetUp()==false)
00070 {
00071 EXCEPTION("Cell is setting up a cell-cycle model but SimulationTime has not been set up");
00072 }
00073
00074 if (pCellCycleModel == NULL)
00075 {
00076 EXCEPTION("Cell-cycle model is null");
00077 }
00078
00079 mpCellCycleModel->SetCell(CellPtr(this, null_deleter()));
00080
00081
00082 mCellId = ++ mMaxCellId -1;
00083
00084 if (!pMutationState->IsSubType<AbstractCellMutationState>())
00085 {
00086 EXCEPTION("Attempting to create cell with a cell mutation state is not a subtype of AbstractCellMutationState");
00087 }
00088
00089 if (!mCellPropertyCollection.HasProperty(pMutationState))
00090 {
00091 mCellPropertyCollection.AddProperty(pMutationState);
00092 }
00093
00094 if (!archiving)
00095 {
00096
00097 for (CellPropertyCollection::Iterator property_iter = mCellPropertyCollection.Begin();
00098 property_iter != mCellPropertyCollection.End();
00099 ++property_iter)
00100 {
00101 (*property_iter)->IncrementCellCount();
00102 }
00103 }
00104 }
00105
00106 Cell::~Cell()
00107 {
00108 if (!mIsDead)
00109 {
00110 Kill();
00111 }
00112 delete mpCellCycleModel;
00113 }
00114
00115 void Cell::SetCellCycleModel(AbstractCellCycleModel* pCellCycleModel)
00116 {
00117 if (mpCellCycleModel != pCellCycleModel)
00118 {
00119 delete mpCellCycleModel;
00120 }
00121 mpCellCycleModel = pCellCycleModel;
00122 mpCellCycleModel->SetCell(CellPtr(this, null_deleter()));
00123 }
00124
00125 AbstractCellCycleModel* Cell::GetCellCycleModel() const
00126 {
00127 return mpCellCycleModel;
00128 }
00129
00130 void Cell::InitialiseCellCycleModel()
00131 {
00132 mpCellCycleModel->Initialise();
00133 }
00134
00135 double Cell::GetAge() const
00136 {
00137 return mpCellCycleModel->GetAge();
00138 }
00139
00140 double Cell::GetBirthTime() const
00141 {
00142 return mpCellCycleModel->GetBirthTime();
00143 }
00144
00145 void Cell::SetBirthTime(double birthTime)
00146 {
00147 mpCellCycleModel->SetBirthTime(birthTime);
00148 }
00149
00150 void Cell::SetMutationState(boost::shared_ptr<AbstractCellProperty> pMutationState)
00151 {
00152 if (!pMutationState->IsSubType<AbstractCellMutationState>())
00153 {
00154 EXCEPTION("Attempting to give cell a cell mutation state is not a subtype of AbstractCellMutationState");
00155 }
00156
00157 boost::shared_ptr<AbstractCellMutationState> p_old_mutation_state = GetMutationState();
00158 p_old_mutation_state->DecrementCellCount();
00159 mCellPropertyCollection.RemoveProperty(p_old_mutation_state);
00160
00161 AddCellProperty(pMutationState);
00162 }
00163
00164 boost::shared_ptr<AbstractCellMutationState> Cell::GetMutationState() const
00165 {
00166 CellPropertyCollection mutation_state_collection = mCellPropertyCollection.GetPropertiesType<AbstractCellMutationState>();
00167
00168
00169
00170
00171
00172
00173
00174 assert(mutation_state_collection.GetSize() == 1);
00175
00176 return boost::static_pointer_cast<AbstractCellMutationState>(mutation_state_collection.GetProperty());
00177 }
00178
00179 CellPropertyCollection& Cell::rGetCellPropertyCollection()
00180 {
00181 return mCellPropertyCollection;
00182 }
00183
00184 const CellPropertyCollection& Cell::rGetCellPropertyCollection() const
00185 {
00186 return mCellPropertyCollection;
00187 }
00188
00189 void Cell::AddCellProperty(const boost::shared_ptr<AbstractCellProperty>& rProperty)
00190 {
00191
00192 if (!mCellPropertyCollection.HasProperty(rProperty))
00193 {
00194 mCellPropertyCollection.AddProperty(rProperty);
00195 rProperty->IncrementCellCount();
00196 }
00197 }
00198
00199 void Cell::SetLogged()
00200 {
00201 mIsLogged = true;
00202 }
00203
00204 bool Cell::IsLogged()
00205 {
00206 return mIsLogged;
00207 }
00208
00209 void Cell::StartApoptosis(bool setDeathTime)
00210 {
00211 assert(!IsDead());
00212
00213 if (mUndergoingApoptosis)
00214 {
00215 EXCEPTION("StartApoptosis() called when already undergoing apoptosis");
00216 }
00217 mUndergoingApoptosis = true;
00218 mStartOfApoptosisTime = SimulationTime::Instance()->GetTime();
00219 if (setDeathTime)
00220 {
00221 mDeathTime = mStartOfApoptosisTime + mApoptosisTime;
00222 }
00223 else
00224 {
00225 mDeathTime = DBL_MAX;
00226 }
00227 AddCellProperty(mCellPropertyCollection.GetCellPropertyRegistry()->Get<ApoptoticCellProperty>());
00228 }
00229
00230 bool Cell::HasApoptosisBegun() const
00231 {
00232 return mUndergoingApoptosis;
00233 }
00234
00235 double Cell::GetStartOfApoptosisTime() const
00236 {
00237 return mStartOfApoptosisTime;
00238 }
00239
00240 double Cell::GetApoptosisTime() const
00241 {
00242 return mApoptosisTime;
00243 }
00244
00245 void Cell::SetApoptosisTime(double apoptosisTime)
00246 {
00247 assert(apoptosisTime > 0.0);
00248 mApoptosisTime = apoptosisTime;
00249 }
00250
00251 double Cell::GetTimeUntilDeath() const
00252 {
00253 if (!mUndergoingApoptosis || mDeathTime==DBL_MAX)
00254 {
00255 EXCEPTION("Shouldn't be checking time until apoptosis as it isn't set");
00256 }
00257
00258 return mDeathTime - SimulationTime::Instance()->GetTime();
00259 }
00260
00261 bool Cell::IsDead()
00262 {
00263 if (mUndergoingApoptosis && !mIsDead)
00264 {
00265 if (SimulationTime::Instance()->GetTime() >= mDeathTime)
00266 {
00267 this->Kill();
00268 }
00269 }
00270 return mIsDead;
00271 }
00272
00273 void Cell::Kill()
00274 {
00275
00276 for (CellPropertyCollection::Iterator property_iter = mCellPropertyCollection.Begin();
00277 property_iter != mCellPropertyCollection.End();
00278 ++property_iter)
00279 {
00280 (*property_iter)->DecrementCellCount();
00281 }
00282 mIsDead = true;
00283 }
00284
00285 void Cell::SetAncestor(unsigned ancestorIndex)
00286 {
00287 mAncestor = ancestorIndex;
00288 }
00289
00290 unsigned Cell::GetAncestor() const
00291 {
00292 return mAncestor;
00293 }
00294
00295 unsigned Cell::GetCellId() const
00296 {
00297 return mCellId;
00298 }
00299
00300 void Cell::ResetMaxCellId()
00301 {
00302 mMaxCellId = 0;
00303 }
00304
00305 bool Cell::ReadyToDivide()
00306 {
00307 assert(!IsDead());
00308 if (mUndergoingApoptosis || HasCellProperty<ApoptoticCellProperty>())
00309 {
00310 return false;
00311 }
00312
00313 mCanDivide = mpCellCycleModel->ReadyToDivide();
00314
00315 return mCanDivide;
00316 }
00317
00318 CellPtr Cell::Divide()
00319 {
00320
00321 assert(!IsDead());
00322 assert(mCanDivide);
00323 mCanDivide = false;
00324
00325
00326 mpCellCycleModel->ResetForDivision();
00327
00328
00329 CellPtr p_new_cell(new Cell(GetMutationState(), mpCellCycleModel->CreateCellCycleModel(), false, mCellPropertyCollection));
00330
00331
00332 p_new_cell->GetCellCycleModel()->InitialiseDaughterCell();
00333 p_new_cell->SetAncestor(GetAncestor());
00334
00335 return p_new_cell;
00336 }