Chaste  Release::2018.1
CheckReadyToDivideAndPhaseIsUpdated.hpp
1 /*
2 
3 Copyright (c) 2005-2018, 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 "AbstractSimpleCellCycleModel.hpp"
42 #include "AbstractPhaseBasedCellCycleModel.hpp"
43 #include "DifferentiatedCellProliferativeType.hpp"
44 
56 void CheckReadyToDivideAndPhaseIsUpdated(AbstractPhaseBasedCellCycleModel* pModel,
57  double g1Duration,
58  double g2Duration=DBL_MAX)
59 {
60  if (g2Duration==DBL_MAX)
61  {
62  g2Duration = pModel->GetG2Duration();
63  }
64 
65  double age = pModel->GetAge();
66 
67  const double G1TOL = 1e-5; // how accurate the expected G1 duration is
68 
69  // If the G1 duration is incorrect, print out the mismatch
70  if ((pModel->GetCell()->GetCellProliferativeType()->IsType<DifferentiatedCellProliferativeType>()) &&
71  (age >= pModel->GetMDuration()) &&
72  (pModel->GetG1Duration() != DOUBLE_UNSET) &&
73  (fabs(pModel->GetG1Duration() - g1Duration) > G1TOL))
74  {
75  std::cout << "G1 duration mismatch: actual = " << pModel->GetG1Duration()
76  << ", expected = " << g1Duration
77  << std::endl;
78  }
79 
80  if (pModel->GetCell()->GetCellProliferativeType()->IsType<DifferentiatedCellProliferativeType>())
81  {
82  // If the cell is differentiated, then it must be in G0 phase and must never divide
83  TS_ASSERT_EQUALS(pModel->ReadyToDivide(), false);
84  TS_ASSERT_EQUALS(pModel->GetCurrentCellCyclePhase(), G_ZERO_PHASE);
85  }
86  else if (age < pModel->GetMDuration())
87  {
88  // If the cell in M phase, then it must not be ready to divide
89  TS_ASSERT_EQUALS(pModel->ReadyToDivide(), false);
90  TS_ASSERT_EQUALS(pModel->GetCurrentCellCyclePhase(), M_PHASE);
91  }
92  else if (age < pModel->GetMDuration() + g1Duration - G1TOL)
93  {
94  // The next cell cycle phase after M is G1; cells in G1 phase
95  // must still not be ready to divide
96  TS_ASSERT_EQUALS(pModel->ReadyToDivide(), false);
97  TS_ASSERT_EQUALS(pModel->GetCurrentCellCyclePhase(), G_ONE_PHASE);
98 
99  // If the cell is not in G1 phase when it should be, print out the mismatch
100  if (pModel->GetCurrentCellCyclePhase() != G_ONE_PHASE)
101  {
102  std::cout << "Expected G1: " << g1Duration
103  << "; actual: " << pModel->GetG1Duration()
104  << "; age = " << age
105  << "; G1-S transition = " << pModel->GetMDuration() + g1Duration
106  << std::endl;
107  }
108  }
109  else if (age < pModel->GetMDuration() + g1Duration + pModel->GetSDuration() - G1TOL)
110  {
111  // The next cell cycle phase after G1 is S; cells in S phase
112  // must still not be ready to divide
113  TS_ASSERT_EQUALS(pModel->ReadyToDivide(), false);
114  TS_ASSERT_EQUALS(pModel->GetCurrentCellCyclePhase(), S_PHASE);
115  }
116  else if (age < pModel->GetMDuration() + g1Duration + pModel->GetSDuration() + g2Duration - G1TOL)
117  {
118  // The next cell cycle phase after S is G2; cells in G2 phase
119  // must still not be ready to divide
120  TS_ASSERT_EQUALS(pModel->ReadyToDivide(), false);
121  TS_ASSERT_EQUALS(pModel->GetCurrentCellCyclePhase(), G_TWO_PHASE);
122  }
123  else
124  {
125  // Cells must be ready to divide as soon as they leave G2 phase
126  TS_ASSERT_EQUALS(pModel->ReadyToDivide(), true);
127  }
128 }
129 
140 void CheckReadyToDivideIsUpdated(AbstractSimpleCellCycleModel* pModel,
141  double cellCycleDuration)
142 {
143  double age = pModel->GetAge();
144 
145  const double CCDTOL = 1e-5; // how accurate the expected CCD duration is
146 
147  // If the CCD duration is incorrect, print out the mismatch
148  if ((pModel->GetCellCycleDuration() != DOUBLE_UNSET) &&
149  (fabs(pModel->GetCellCycleDuration() - cellCycleDuration) > CCDTOL))
150  {
151  std::cout << "CCD duration mismatch: actual = " << pModel->GetCellCycleDuration()
152  << ", expected = " << cellCycleDuration
153  << std::endl;
154  }
155 
156  // Check ReadyToDivide is updated correctly.
157  if (pModel->GetCell()->GetCellProliferativeType()->IsType<DifferentiatedCellProliferativeType>())
158  {
159  // If the cell is differentiated, then it must be in G0 phase and must never divide
160  TS_ASSERT_EQUALS(pModel->ReadyToDivide(), false);
161  }
162  else if (age < cellCycleDuration)
163  {
164  TS_ASSERT_EQUALS(pModel->ReadyToDivide(), false);
165  }
166  else
167  {
168  TS_ASSERT_EQUALS(pModel->ReadyToDivide(), true);
169  }
170 }
171 
172 
173 #endif /*CHECKREADYTODIVIDEANDPHASEISUPDATED_HPP_*/
const double DOUBLE_UNSET
Definition: Exception.hpp:56