Chaste Release::3.1
CheckReadyToDivideAndPhaseIsUpdated.hpp
00001 /*
00002 
00003 Copyright (c) 2005-2012, University of Oxford.
00004 All rights reserved.
00005 
00006 University of Oxford means the Chancellor, Masters and Scholars of the
00007 University of Oxford, having an administrative office at Wellington
00008 Square, Oxford OX1 2JD, UK.
00009 
00010 This file is part of Chaste.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019  * Neither the name of the University of Oxford nor the names of its
00020    contributors may be used to endorse or promote products derived from this
00021    software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 
00034 */
00035 
00036 #ifndef CHECKREADYTODIVIDEANDPHASEISUPDATED_HPP_
00037 #define CHECKREADYTODIVIDEANDPHASEISUPDATED_HPP_
00038 
00039 #include <cxxtest/TestSuite.h>
00040 #include <cmath>
00041 #include "AbstractCellCycleModel.hpp"
00042 
00054 void CheckReadyToDivideAndPhaseIsUpdated(AbstractCellCycleModel* pModel,
00055                                          double g1Duration,
00056                                          double g2Duration=DBL_MAX)
00057 {
00058     if (g2Duration==DBL_MAX)
00059     {
00060         g2Duration = pModel->GetG2Duration();
00061     }
00062 
00063     double age = pModel->GetAge();
00064 
00065     const double G1TOL = 1e-5; // how accurate the expected G1 duration is
00066 
00067     // If the G1 duration is incorrect, print out the mismatch
00068     if ((pModel->GetCell()->GetCellProliferativeType() != DIFFERENTIATED) &&
00069         (age >= pModel->GetMDuration()) &&
00070         (pModel->GetG1Duration() != DOUBLE_UNSET) &&
00071         (fabs(pModel->GetG1Duration() - g1Duration) > G1TOL))
00072     {
00073         std::cout << "G1 duration mismatch: actual = " << pModel->GetG1Duration()
00074                   << ", expected = " << g1Duration
00075                   << std::endl;
00076     }
00077 
00078     if (pModel->GetCell()->GetCellProliferativeType()==DIFFERENTIATED)
00079     {
00080         // If the cell is differentiated, then it must be in G0 phase and must never divide
00081         TS_ASSERT_EQUALS(pModel->ReadyToDivide(), false);
00082         TS_ASSERT_EQUALS(pModel->GetCurrentCellCyclePhase(), G_ZERO_PHASE);
00083     }
00084     else if (age < pModel->GetMDuration())
00085     {
00086         // If the cell in M phase, then it must not be ready to divide
00087         TS_ASSERT_EQUALS(pModel->ReadyToDivide(), false);
00088         TS_ASSERT_EQUALS(pModel->GetCurrentCellCyclePhase(), M_PHASE);
00089     }
00090     else if (age < pModel->GetMDuration() + g1Duration - G1TOL)
00091     {
00092         // The next cell cycle phase after M is G1; cells in G1 phase
00093         // must still not be ready to divide
00094         TS_ASSERT_EQUALS(pModel->ReadyToDivide(), false);
00095         TS_ASSERT_EQUALS(pModel->GetCurrentCellCyclePhase(), G_ONE_PHASE);
00096 
00097         // If the cell is not in G1 phase when it should be, print out the mismatch
00098         if (pModel->GetCurrentCellCyclePhase() != G_ONE_PHASE)
00099         {
00100             std::cout << "Expected G1: " << g1Duration
00101                       << "; actual: " << pModel->GetG1Duration()
00102                       << "; age = " << age
00103                       << "; G1-S transition = " << pModel->GetMDuration() + g1Duration
00104                       << std::endl;
00105         }
00106     }
00107     else if (age < pModel->GetMDuration() + g1Duration + pModel->GetSDuration() - G1TOL)
00108     {
00109         // The next cell cycle phase after G1 is S; cells in S phase
00110         // must still not be ready to divide
00111         TS_ASSERT_EQUALS(pModel->ReadyToDivide(), false);
00112         TS_ASSERT_EQUALS(pModel->GetCurrentCellCyclePhase(), S_PHASE);
00113     }
00114     else if (age < pModel->GetMDuration() + g1Duration + pModel->GetSDuration() + g2Duration  - G1TOL)
00115     {
00116         // The next cell cycle phase after S is G2; cells in G2 phase
00117         // must still not be ready to divide
00118         TS_ASSERT_EQUALS(pModel->ReadyToDivide(), false);
00119         TS_ASSERT_EQUALS(pModel->GetCurrentCellCyclePhase(), G_TWO_PHASE);
00120     }
00121     else
00122     {
00123         // Cells must be ready to divide as soon as they leave G2 phase
00124         TS_ASSERT_EQUALS(pModel->ReadyToDivide(), true);
00125     }
00126 }
00127 
00128 #endif /*CHECKREADYTODIVIDEANDPHASEISUPDATED_HPP_*/