Chaste  Release::3.4
CheckReadyToDivideAndPhaseIsUpdated.hpp
1 /*
2 
3 Copyright (c) 2005-2016, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
14  * Redistributions of source code must retain the above copyright notice,
15  this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the above copyright notice,
17  this list of conditions and the following disclaimer in the documentation
18  and/or other materials provided with the distribution.
19  * Neither the name of the University of Oxford nor the names of its
20  contributors may be used to endorse or promote products derived from this
21  software without specific prior written permission.
22 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 */
35 
36 #ifndef CHECKREADYTODIVIDEANDPHASEISUPDATED_HPP_
37 #define CHECKREADYTODIVIDEANDPHASEISUPDATED_HPP_
38 
39 #include <cxxtest/TestSuite.h>
40 #include <cmath>
41 #include "AbstractCellCycleModel.hpp"
42 #include "DifferentiatedCellProliferativeType.hpp"
43 
55 void CheckReadyToDivideAndPhaseIsUpdated(AbstractCellCycleModel* pModel,
56  double g1Duration,
57  double g2Duration=DBL_MAX)
58 {
59  if (g2Duration==DBL_MAX)
60  {
61  g2Duration = pModel->GetG2Duration();
62  }
63 
64  double age = pModel->GetAge();
65 
66  const double G1TOL = 1e-5; // how accurate the expected G1 duration is
67 
68  // If the G1 duration is incorrect, print out the mismatch
69  if ((pModel->GetCell()->GetCellProliferativeType()->IsType<DifferentiatedCellProliferativeType>()) &&
70  (age >= pModel->GetMDuration()) &&
71  (pModel->GetG1Duration() != DOUBLE_UNSET) &&
72  (fabs(pModel->GetG1Duration() - g1Duration) > G1TOL))
73  {
74  std::cout << "G1 duration mismatch: actual = " << pModel->GetG1Duration()
75  << ", expected = " << g1Duration
76  << std::endl;
77  }
78 
79  if (pModel->GetCell()->GetCellProliferativeType()->IsType<DifferentiatedCellProliferativeType>())
80  {
81  // If the cell is differentiated, then it must be in G0 phase and must never divide
82  TS_ASSERT_EQUALS(pModel->ReadyToDivide(), false);
83  TS_ASSERT_EQUALS(pModel->GetCurrentCellCyclePhase(), G_ZERO_PHASE);
84  }
85  else if (age < pModel->GetMDuration())
86  {
87  // If the cell in M phase, then it must not be ready to divide
88  TS_ASSERT_EQUALS(pModel->ReadyToDivide(), false);
89  TS_ASSERT_EQUALS(pModel->GetCurrentCellCyclePhase(), M_PHASE);
90  }
91  else if (age < pModel->GetMDuration() + g1Duration - G1TOL)
92  {
93  // The next cell cycle phase after M is G1; cells in G1 phase
94  // must still not be ready to divide
95  TS_ASSERT_EQUALS(pModel->ReadyToDivide(), false);
96  TS_ASSERT_EQUALS(pModel->GetCurrentCellCyclePhase(), G_ONE_PHASE);
97 
98  // If the cell is not in G1 phase when it should be, print out the mismatch
99  if (pModel->GetCurrentCellCyclePhase() != G_ONE_PHASE)
100  {
101  std::cout << "Expected G1: " << g1Duration
102  << "; actual: " << pModel->GetG1Duration()
103  << "; age = " << age
104  << "; G1-S transition = " << pModel->GetMDuration() + g1Duration
105  << std::endl;
106  }
107  }
108  else if (age < pModel->GetMDuration() + g1Duration + pModel->GetSDuration() - G1TOL)
109  {
110  // The next cell cycle phase after G1 is S; cells in S phase
111  // must still not be ready to divide
112  TS_ASSERT_EQUALS(pModel->ReadyToDivide(), false);
113  TS_ASSERT_EQUALS(pModel->GetCurrentCellCyclePhase(), S_PHASE);
114  }
115  else if (age < pModel->GetMDuration() + g1Duration + pModel->GetSDuration() + g2Duration - G1TOL)
116  {
117  // The next cell cycle phase after S is G2; cells in G2 phase
118  // must still not be ready to divide
119  TS_ASSERT_EQUALS(pModel->ReadyToDivide(), false);
120  TS_ASSERT_EQUALS(pModel->GetCurrentCellCyclePhase(), G_TWO_PHASE);
121  }
122  else
123  {
124  // Cells must be ready to divide as soon as they leave G2 phase
125  TS_ASSERT_EQUALS(pModel->ReadyToDivide(), true);
126  }
127 }
128 
129 #endif /*CHECKREADYTODIVIDEANDPHASEISUPDATED_HPP_*/
const double DOUBLE_UNSET
Definition: Exception.hpp:56
CellCyclePhase GetCurrentCellCyclePhase()