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 #ifndef ABSTRACTCELLPOPULATION_HPP_
00029 #define ABSTRACTCELLPOPULATION_HPP_
00030
00031 #include "Cell.hpp"
00032 #include "OutputFileHandler.hpp"
00033
00034 #include <list>
00035 #include <map>
00036 #include <vector>
00037 #include <boost/shared_ptr.hpp>
00038
00039 #include "ChasteSerialization.hpp"
00040 #include "ClassIsAbstract.hpp"
00041 #include <boost/serialization/vector.hpp>
00042 #include <boost/serialization/list.hpp>
00043 #include <boost/serialization/map.hpp>
00044 #include <boost/serialization/shared_ptr.hpp>
00045
00046 #include "Node.hpp"
00047 #include "CellPropertyRegistry.hpp"
00048 #include "Identifiable.hpp"
00049
00050
00051 #include "WildTypeCellMutationState.hpp"
00052 #include "ApcOneHitCellMutationState.hpp"
00053 #include "ApcTwoHitCellMutationState.hpp"
00054 #include "BetaCateninOneHitCellMutationState.hpp"
00055 #include "ApoptoticCellProperty.hpp"
00056 #include "CellLabel.hpp"
00057
00064 template<unsigned DIM>
00065 class AbstractCellPopulation : public Identifiable
00066 {
00067 private:
00069 friend class boost::serialization::access;
00076 template<class Archive>
00077 void serialize(Archive & archive, const unsigned int version)
00078 {
00079 archive & mCells;
00080 archive & mLocationCellMap;
00081 archive & mCellLocationMap;
00082 archive & mCellProliferativeTypeCount;
00083 archive & mCellCyclePhaseCount;
00084 archive & mCellPopulationContainsMesh;
00085 archive & mpCellPropertyRegistry;
00086 archive & mDampingConstantNormal;
00087 archive & mDampingConstantMutant;
00088 archive & mOutputCellIdData;
00089 archive & mOutputCellMutationStates;
00090 archive & mOutputCellAncestors;
00091 archive & mOutputCellProliferativeTypes;
00092 archive & mOutputCellVariables;
00093 archive & mOutputCellCyclePhases;
00094 archive & mOutputCellAges;
00095 archive & mOutputCellVolumes;
00096 }
00097
00098 protected:
00099
00101 std::list<CellPtr> mCells;
00102
00104 std::map<unsigned, CellPtr> mLocationCellMap;
00105
00107 std::map<Cell*, unsigned> mCellLocationMap;
00108
00110 std::vector<unsigned> mCellProliferativeTypeCount;
00111
00113 std::vector<unsigned> mCellCyclePhaseCount;
00114
00116 out_stream mpVizNodesFile;
00117
00119 out_stream mpVizCellProliferativeTypesFile;
00120
00122 out_stream mpCellMutationStatesFile;
00123
00125 out_stream mpVizCellAncestorsFile;
00126
00128 out_stream mpCellProliferativeTypesFile;
00129
00131 out_stream mpCellCyclePhasesFile;
00132
00134 out_stream mpCellVariablesFile;
00135
00137 out_stream mpCellAgesFile;
00138
00140 out_stream mpCellIdFile;
00141
00143 out_stream mpVizBoundaryNodesFile;
00144
00146 bool mCellPopulationContainsMesh;
00147
00149 boost::shared_ptr<CellPropertyRegistry> mpCellPropertyRegistry;
00150
00157 double mDampingConstantNormal;
00158
00162 double mDampingConstantMutant;
00163
00165 bool mOutputCellIdData;
00166
00168 bool mOutputCellMutationStates;
00169
00171 bool mOutputCellAncestors;
00172
00174 bool mOutputCellProliferativeTypes;
00175
00177 bool mOutputCellVariables;
00178
00180 bool mOutputCellCyclePhases;
00181
00183 bool mOutputCellAges;
00184
00186 bool mOutputCellVolumes;
00187
00194 virtual void Validate()=0;
00195
00201 AbstractCellPopulation()
00202 {
00203 }
00204
00205 public:
00206
00217 AbstractCellPopulation(std::vector<CellPtr>& rCells,
00218 const std::vector<unsigned> locationIndices=std::vector<unsigned>());
00219
00223 virtual ~AbstractCellPopulation();
00224
00228 void InitialiseCells();
00229
00233 std::list<CellPtr>& rGetCells();
00234
00238 bool IsMeshBasedCellPopulation();
00239
00246 virtual unsigned GetNumNodes()=0;
00247
00257 virtual c_vector<double, DIM> GetLocationOfCellCentre(CellPtr pCell)=0;
00258
00268 virtual Node<DIM>* GetNode(unsigned index)=0;
00269
00279 virtual unsigned AddNode(Node<DIM>* pNewNode)=0;
00280
00290 virtual void SetNode(unsigned nodeIndex, ChastePoint<DIM>& rNewLocation)=0;
00291
00302 virtual bool IsCellAssociatedWithADeletedLocation(CellPtr pCell)=0;
00303
00315 virtual void UpdateNodeLocations(const std::vector< c_vector<double, DIM> >& rNodeForces, double dt)=0;
00316
00326 virtual double GetDampingConstant(unsigned nodeIndex)=0;
00327
00343 virtual CellPtr AddCell(CellPtr pNewCell, const c_vector<double,DIM>& rCellDivisionVector, CellPtr pParentCell=CellPtr())=0;
00344
00345 class Iterator;
00346
00355 virtual unsigned RemoveDeadCells()=0;
00356
00363 virtual void Update(bool hasHadBirthsOrDeaths=true)=0;
00364
00374 std::vector<unsigned> GetCellMutationStateCount();
00375
00384 const std::vector<unsigned>& rGetCellProliferativeTypeCount() const;
00385
00396 const std::vector<unsigned>& rGetCellCyclePhaseCount() const;
00397
00401 unsigned GetNumRealCells();
00402
00407 void SetCellAncestorsToLocationIndices();
00408
00412 void WriteCellIdDataToFile();
00413
00420 std::set<unsigned> GetCellAncestors();
00421
00432 CellPtr GetCellUsingLocationIndex(unsigned index);
00433
00444 unsigned GetLocationIndexUsingCell(CellPtr pCell);
00445
00449 boost::shared_ptr<CellPropertyRegistry> GetCellPropertyRegistry();
00450
00455 void SetDefaultMutationStateOrdering();
00456
00465 virtual double GetWidth(const unsigned& rDimension)=0;
00466
00473 virtual void CreateOutputFiles(const std::string& rDirectory,
00474 bool cleanOutputDirectory);
00475
00479 virtual void WriteResultsToFiles();
00480
00484 virtual void WriteTimeAndNodeResultsToFiles();
00485
00489 virtual void GenerateCellResultsAndWriteToFiles()=0;
00490
00498 virtual void GenerateCellResults(unsigned locationIndex,
00499 std::vector<unsigned>& rCellProliferativeTypeCounter,
00500 std::vector<unsigned>& rCellCyclePhaseCounter);
00501
00508 void WriteCellResultsToFiles(std::vector<unsigned>& rCellProliferativeTypeCounter,
00509 std::vector<unsigned>& rCellCyclePhaseCounter);
00510
00514 virtual void CloseOutputFiles();
00515
00521 void OutputCellPopulationInfo(out_stream& rParamsFile);
00522
00531 virtual void OutputCellPopulationParameters(out_stream& rParamsFile)=0;
00532
00536 double GetDampingConstantNormal();
00540 double GetDampingConstantMutant();
00541
00545 bool GetOutputCellIdData();
00546
00550 bool GetOutputCellMutationStates();
00551
00555 bool GetOutputCellAncestors();
00556
00560 bool GetOutputCellProliferativeTypes();
00561
00565 bool GetOutputCellVariables();
00566
00570 bool GetOutputCellCyclePhases();
00571
00575 bool GetOutputCellAges();
00576
00580 bool GetOutputCellVolumes();
00581
00587 void SetDampingConstantNormal(double dampingConstantNormal);
00588
00594 void SetDampingConstantMutant(double dampingConstantMutant);
00595
00601 void SetOutputCellIdData(bool outputCellIdData);
00602
00608 void SetOutputCellMutationStates(bool outputCellMutationStates);
00609
00615 void SetOutputCellAncestors(bool outputCellAncestors);
00616
00622 void SetOutputCellProliferativeTypes(bool outputCellProliferativeTypes);
00623
00629 void SetOutputCellVariables(bool outputCellVariables);
00630
00636 void SetOutputCellCyclePhases(bool outputCellCyclePhases);
00637
00643 void SetOutputCellAges(bool outputCellAges);
00644
00650 void SetOutputCellVolumes(bool outputCellVolumes);
00651
00658 class Iterator
00659 {
00660 public:
00661
00665 inline CellPtr operator*();
00666
00671 inline CellPtr operator->();
00672
00678 inline bool operator!=(const AbstractCellPopulation<DIM>::Iterator& rOther);
00679
00683 inline Iterator& operator++();
00684
00691 Iterator(AbstractCellPopulation& rCellPopulation, std::list<CellPtr>::iterator cellIter);
00692
00696 virtual ~Iterator()
00697 {}
00698
00699 private:
00700
00707 virtual inline bool IsRealCell();
00708
00712 inline bool IsAtEnd();
00713
00715 AbstractCellPopulation& mrCellPopulation;
00716
00718 std::list<CellPtr>::iterator mCellIter;
00719 };
00720
00724 Iterator Begin();
00725
00729 Iterator End();
00730
00731 };
00732
00733 enum cell_colours
00734 {
00735 STEM_COLOUR,
00736 TRANSIT_COLOUR,
00737 DIFFERENTIATED_COLOUR,
00738 EARLY_CANCER_COLOUR,
00739 LATE_CANCER_COLOUR,
00740 LABELLED_COLOUR,
00741 APOPTOSIS_COLOUR,
00742 INVISIBLE_COLOUR
00743 };
00744
00745 TEMPLATED_CLASS_IS_ABSTRACT_1_UNSIGNED(AbstractCellPopulation)
00746
00747
00748
00750
00751 template<unsigned DIM>
00752 CellPtr AbstractCellPopulation<DIM>::Iterator::operator*()
00753 {
00754 assert(!IsAtEnd());
00755 return *mCellIter;
00756 }
00757
00758 template<unsigned DIM>
00759 CellPtr AbstractCellPopulation<DIM>::Iterator::operator->()
00760 {
00761 assert(!IsAtEnd());
00762 return *mCellIter;
00763 }
00764
00765 template<unsigned DIM>
00766 bool AbstractCellPopulation<DIM>::Iterator::operator!=(const AbstractCellPopulation<DIM>::Iterator& rOther)
00767 {
00768 return mCellIter != rOther.mCellIter;
00769 }
00770
00771 template<unsigned DIM>
00772 typename AbstractCellPopulation<DIM>::Iterator& AbstractCellPopulation<DIM>::Iterator::operator++()
00773 {
00774 do
00775 {
00776 ++mCellIter;
00777 }
00778 while (!IsAtEnd() && !IsRealCell());
00779
00780 return (*this);
00781 }
00782
00783 template<unsigned DIM>
00784 bool AbstractCellPopulation<DIM>::Iterator::IsRealCell()
00785 {
00786 return !( mrCellPopulation.IsCellAssociatedWithADeletedLocation(*mCellIter) || (*this)->IsDead() );
00787 }
00788
00789 template<unsigned DIM>
00790 bool AbstractCellPopulation<DIM>::Iterator::IsAtEnd()
00791 {
00792 return mCellIter == mrCellPopulation.rGetCells().end();
00793 }
00794
00795 template<unsigned DIM>
00796 AbstractCellPopulation<DIM>::Iterator::Iterator(AbstractCellPopulation& rCellPopulation, std::list<CellPtr>::iterator cellIter)
00797 : mrCellPopulation(rCellPopulation),
00798 mCellIter(cellIter)
00799 {
00800
00801 if (mrCellPopulation.rGetCells().empty())
00802 {
00803 mCellIter = mrCellPopulation.rGetCells().end();
00804 }
00805 else
00806 {
00807
00808 if (mCellIter == mrCellPopulation.rGetCells().begin() && !IsRealCell())
00809 {
00810 ++(*this);
00811 }
00812 }
00813 }
00814
00815 template<unsigned DIM>
00816 typename AbstractCellPopulation<DIM>::Iterator AbstractCellPopulation<DIM>::Begin()
00817 {
00818 return Iterator(*this, this->mCells.begin());
00819 }
00820
00821 template<unsigned DIM>
00822 typename AbstractCellPopulation<DIM>::Iterator AbstractCellPopulation<DIM>::End()
00823 {
00824 return Iterator(*this, this->mCells.end());
00825 }
00826
00827
00828 #endif