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 #include "TissueCell.hpp"
00029
00030 unsigned TissueCell::mMaxCellId = 0;
00031
00032
00033 TissueCell::TissueCell(CellType cellType,
00034 CellMutationState mutationState,
00035 AbstractCellCycleModel* pCellCycleModel,
00036 bool archiving)
00037 : mCanDivide(false),
00038 mCellType(cellType),
00039 mMutationState(mutationState),
00040 mpCellCycleModel(pCellCycleModel),
00041 mAncestor(UNSIGNED_UNSET),
00042 mDeathTime(DBL_MAX),
00043 mStartOfApoptosisTime(DBL_MAX),
00044 mUndergoingApoptosis(false),
00045 mIsDead(false),
00046 mIsLogged(false)
00047 {
00048 if (SimulationTime::Instance()->IsStartTimeSetUp()==false)
00049 {
00050 EXCEPTION("TissueCell is setting up a cell cycle model but SimulationTime has not been set up");
00051 }
00052
00053 if (pCellCycleModel==NULL)
00054 {
00055 EXCEPTION("Cell cycle model is null");
00056 }
00057
00058 mpCellCycleModel->SetCell(this);
00059
00060
00061 mCellId = ++ mMaxCellId -1;
00062 }
00063
00064
00065 void TissueCell::CommonCopy(const TissueCell& rOtherCell)
00066 {
00067
00068 mCanDivide = rOtherCell.mCanDivide;
00069
00070
00071 mCellType = rOtherCell.mCellType;
00072 mMutationState = rOtherCell.mMutationState;
00073 mUndergoingApoptosis = rOtherCell.mUndergoingApoptosis;
00074 mIsDead = rOtherCell.mIsDead;
00075 mDeathTime = rOtherCell.mDeathTime;
00076 mStartOfApoptosisTime = rOtherCell.mStartOfApoptosisTime;
00077 mIsLogged = rOtherCell.mIsLogged;
00078 mAncestor = rOtherCell.mAncestor;
00079 mCellId = rOtherCell.mCellId;
00080
00081
00082
00083 mpCellCycleModel = rOtherCell.mpCellCycleModel->CreateCellCycleModel();
00084
00085 mpCellCycleModel->SetCell(this);
00086 }
00087
00088
00089 TissueCell::TissueCell(const TissueCell& rOtherCell)
00090 {
00091 CommonCopy(rOtherCell);
00092 }
00093
00094
00095 TissueCell& TissueCell::operator=(const TissueCell& rOtherCell)
00096 {
00097
00098 AbstractCellCycleModel *p_temp_model = mpCellCycleModel;
00099 CommonCopy(rOtherCell);
00100
00101 delete p_temp_model;
00102 return *this;
00103 }
00104
00105
00106 TissueCell::~TissueCell()
00107 {
00108 delete mpCellCycleModel;
00109 }
00110
00111
00112 void TissueCell::SetCellCycleModel(AbstractCellCycleModel* pCellCycleModel)
00113 {
00114 if (mpCellCycleModel != pCellCycleModel)
00115 {
00116 delete mpCellCycleModel;
00117 }
00118 mpCellCycleModel = pCellCycleModel;
00119 mpCellCycleModel->SetCell(this);
00120 }
00121
00122
00123 AbstractCellCycleModel* TissueCell::GetCellCycleModel() const
00124 {
00125 return mpCellCycleModel;
00126 }
00127
00128
00129 void TissueCell::InitialiseCellCycleModel()
00130 {
00131 mpCellCycleModel->Initialise();
00132 }
00133
00134
00135 double TissueCell::GetAge() const
00136 {
00137 return mpCellCycleModel->GetAge();
00138 }
00139
00140
00141 double TissueCell::GetBirthTime() const
00142 {
00143 return mpCellCycleModel->GetBirthTime();
00144 }
00145
00146
00147 void TissueCell::SetBirthTime(double birthTime)
00148 {
00149 mpCellCycleModel->SetBirthTime(birthTime);
00150 }
00151
00152
00153 void TissueCell::SetCellType(CellType cellType)
00154 {
00155 mCellType = cellType;
00156 }
00157
00158
00159 CellType TissueCell::GetCellType() const
00160 {
00161 return mCellType;
00162 }
00163
00164
00165 void TissueCell::SetMutationState(CellMutationState mutationState)
00166 {
00167 mMutationState = mutationState;
00168 }
00169
00170
00171 CellMutationState TissueCell::GetMutationState() const
00172 {
00173 return mMutationState;
00174 }
00175
00176
00177 void TissueCell::SetLogged()
00178 {
00179 mIsLogged = true;
00180 }
00181
00182
00183 bool TissueCell::IsLogged()
00184 {
00185 return mIsLogged;
00186 }
00187
00188
00189 void TissueCell::StartApoptosis(bool setDeathTime)
00190 {
00191 assert(!IsDead());
00192
00193 if (mUndergoingApoptosis)
00194 {
00195 EXCEPTION("StartApoptosis() called when already undergoing apoptosis");
00196 }
00197 mUndergoingApoptosis = true;
00198 mStartOfApoptosisTime = SimulationTime::Instance()->GetTime();
00199 if (setDeathTime)
00200 {
00201 mDeathTime = mStartOfApoptosisTime + TissueConfig::Instance()->GetApoptosisTime();
00202 }
00203 else
00204 {
00205 mDeathTime = DBL_MAX;
00206 }
00207
00208 mCellType = APOPTOTIC;
00209 }
00210
00211
00212 bool TissueCell::HasApoptosisBegun() const
00213 {
00214 return mUndergoingApoptosis;
00215 }
00216
00217 double TissueCell::GetStartOfApoptosisTime() const
00218 {
00219 return mStartOfApoptosisTime;
00220 }
00221
00222 double TissueCell::TimeUntilDeath() const
00223 {
00224 if (!mUndergoingApoptosis || mDeathTime==DBL_MAX)
00225 {
00226 EXCEPTION("Shouldn't be checking time until apoptosis as it isn't set");
00227 }
00228
00229 return mDeathTime - SimulationTime::Instance()->GetTime();
00230 }
00231
00232
00233 bool TissueCell::IsDead()
00234 {
00235 if (mUndergoingApoptosis)
00236 {
00237 if (SimulationTime::Instance()->GetTime() >= mDeathTime)
00238 {
00239 this->Kill();
00240 }
00241 }
00242 return mIsDead;
00243 }
00244
00245
00246 void TissueCell::Kill()
00247 {
00248 mIsDead = true;
00249 }
00250
00251 void TissueCell::SetAncestor(unsigned ancestorIndex)
00252 {
00253 mAncestor = ancestorIndex;
00254 }
00255
00256 unsigned TissueCell::GetAncestor() const
00257 {
00258 return mAncestor;
00259 }
00260
00261 unsigned TissueCell::GetCellId() const
00262 {
00263 return mCellId;
00264 }
00265
00266 void TissueCell::ResetMaxCellId()
00267 {
00268 mMaxCellId = 0;
00269 }
00270
00271 bool TissueCell::ReadyToDivide()
00272 {
00273 assert(!IsDead());
00274 if (mUndergoingApoptosis || mCellType==APOPTOTIC)
00275 {
00276 return false;
00277 }
00278
00279 mCanDivide = mpCellCycleModel->ReadyToDivide();
00280
00281 return mCanDivide;
00282 }
00283
00284
00285 TissueCell TissueCell::Divide()
00286 {
00287
00288 assert(!IsDead());
00289 assert(mCanDivide);
00290 mCanDivide = false;
00291
00292
00293 mpCellCycleModel->ResetForDivision();
00294
00295
00296 TissueCell new_cell = TissueCell(mCellType, mMutationState,
00297 mpCellCycleModel->CreateCellCycleModel());
00298
00299
00300 new_cell.GetCellCycleModel()->InitialiseDaughterCell();
00301 new_cell.SetAncestor(GetAncestor());
00302
00303 return new_cell;
00304 }