Cell.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2010
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
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), // Has to be set by a SetAncestor() call (usually from CellPopulation)
00062       mDeathTime(DBL_MAX), // This has to be initialised for archiving
00063       mStartOfApoptosisTime(DBL_MAX),
00064       mApoptosisTime(0.25), // cell takes 15 min to fully undergo apoptosis
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     // Set cell identifier
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         // Increment cell count for each cell property in mCellPropertyCollection
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 
00169     assert(mutation_state_collection.GetSize() == 1);
00170 
00171     return boost::static_pointer_cast<AbstractCellMutationState>(mutation_state_collection.GetProperty());
00172 }
00173 
00174 CellPropertyCollection& Cell::rGetCellPropertyCollection()
00175 {
00176     return mCellPropertyCollection;
00177 }
00178 
00179 const CellPropertyCollection& Cell::rGetCellPropertyCollection() const
00180 {
00181     return mCellPropertyCollection;
00182 }
00183 
00184 void Cell::AddCellProperty(const boost::shared_ptr<AbstractCellProperty>& rProperty)
00185 {
00187     if (!mCellPropertyCollection.HasProperty(rProperty))
00188     {
00189         mCellPropertyCollection.AddProperty(rProperty);
00190         rProperty->IncrementCellCount();
00191     }
00192 }
00193 
00194 void Cell::SetLogged()
00195 {
00196     mIsLogged = true;
00197 }
00198 
00199 bool Cell::IsLogged()
00200 {
00201     return mIsLogged;
00202 }
00203 
00204 void Cell::StartApoptosis(bool setDeathTime)
00205 {
00206     assert(!IsDead());
00207 
00208     if (mUndergoingApoptosis)
00209     {
00210         EXCEPTION("StartApoptosis() called when already undergoing apoptosis");
00211     }
00212     mUndergoingApoptosis = true;
00213     mStartOfApoptosisTime = SimulationTime::Instance()->GetTime();
00214     if (setDeathTime)
00215     {
00216         mDeathTime = mStartOfApoptosisTime + mApoptosisTime;
00217     }
00218     else
00219     {
00220         mDeathTime = DBL_MAX;
00221     }
00222     AddCellProperty(mCellPropertyCollection.GetCellPropertyRegistry()->Get<ApoptoticCellProperty>());
00223 }
00224 
00225 bool Cell::HasApoptosisBegun() const
00226 {
00227     return mUndergoingApoptosis;
00228 }
00229 
00230 double Cell::GetStartOfApoptosisTime() const
00231 {
00232     return mStartOfApoptosisTime;
00233 }
00234 
00235 double Cell::GetApoptosisTime() const
00236 {
00237     return mApoptosisTime;
00238 }
00239 
00240 void Cell::SetApoptosisTime(double apoptosisTime)
00241 {
00242     assert(apoptosisTime > 0.0);
00243     mApoptosisTime = apoptosisTime;
00244 }
00245 
00246 double Cell::GetTimeUntilDeath() const
00247 {
00248     if (!mUndergoingApoptosis || mDeathTime==DBL_MAX)
00249     {
00250         EXCEPTION("Shouldn't be checking time until apoptosis as it isn't set");
00251     }
00252 
00253     return mDeathTime - SimulationTime::Instance()->GetTime();
00254 }
00255 
00256 bool Cell::IsDead()
00257 {
00258     if (mUndergoingApoptosis && !mIsDead)
00259     {
00260         if (SimulationTime::Instance()->GetTime() >= mDeathTime)
00261         {
00262             this->Kill();
00263         }
00264     }
00265     return mIsDead;
00266 }
00267 
00268 void Cell::Kill()
00269 {
00270     // Decrement cell count for each cell property in mCellPropertyCollection
00271     for (CellPropertyCollection::Iterator property_iter = mCellPropertyCollection.Begin();
00272          property_iter != mCellPropertyCollection.End();
00273          ++property_iter)
00274     {
00275         (*property_iter)->DecrementCellCount();
00276     }
00277     mIsDead = true;
00278 }
00279 
00280 void Cell::SetAncestor(unsigned ancestorIndex)
00281 {
00282     mAncestor = ancestorIndex;
00283 }
00284 
00285 unsigned Cell::GetAncestor() const
00286 {
00287     return mAncestor;
00288 }
00289 
00290 unsigned Cell::GetCellId() const
00291 {
00292     return mCellId;
00293 }
00294 
00295 void Cell::ResetMaxCellId()
00296 {
00297     mMaxCellId = 0;
00298 }
00299 
00300 bool Cell::ReadyToDivide()
00301 {
00302     assert(!IsDead());
00303     if (mUndergoingApoptosis || HasCellProperty<ApoptoticCellProperty>())
00304     {
00305         return false;
00306     }
00307 
00308     mCanDivide = mpCellCycleModel->ReadyToDivide();
00309 
00310     return mCanDivide;
00311 }
00312 
00313 CellPtr Cell::Divide()
00314 {
00315     // Check we're allowed to divide
00316     assert(!IsDead());
00317     assert(mCanDivide);
00318     mCanDivide = false;
00319 
00320     // Reset properties of parent cell
00321     mpCellCycleModel->ResetForDivision();
00322 
00323     // Create daughter cell
00324     CellPtr p_new_cell(new Cell(GetMutationState(), mpCellCycleModel->CreateCellCycleModel(), false, mCellPropertyCollection));
00325 
00326     // Initialise properties of daughter cell
00327     p_new_cell->GetCellCycleModel()->InitialiseDaughterCell();
00328     p_new_cell->SetAncestor(GetAncestor());
00329 
00330     return p_new_cell;
00331 }

Generated on Mon Nov 1 12:35:16 2010 for Chaste by  doxygen 1.5.5