AbstractCellPopulation.hpp
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
00029 #ifndef ABSTRACTCELLPOPULATION_HPP_
00030 #define ABSTRACTCELLPOPULATION_HPP_
00031
00032 #include "Cell.hpp"
00033 #include "OutputFileHandler.hpp"
00034
00035 #include <list>
00036 #include <map>
00037 #include <vector>
00038 #include <boost/shared_ptr.hpp>
00039
00040 #include "ChasteSerialization.hpp"
00041 #include "ClassIsAbstract.hpp"
00042 #include <boost/serialization/vector.hpp>
00043 #include <boost/serialization/list.hpp>
00044 #include <boost/serialization/map.hpp>
00045 #include <boost/serialization/shared_ptr.hpp>
00046
00047 #include "Node.hpp"
00048 #include "CellPropertyRegistry.hpp"
00049 #include "Identifiable.hpp"
00050
00051
00052 #include "WildTypeCellMutationState.hpp"
00053 #include "ApcOneHitCellMutationState.hpp"
00054 #include "ApcTwoHitCellMutationState.hpp"
00055 #include "BetaCateninOneHitCellMutationState.hpp"
00056 #include "ApoptoticCellProperty.hpp"
00057 #include "CellLabel.hpp"
00058
00065 template<unsigned DIM>
00066 class AbstractCellPopulation : public Identifiable
00067 {
00068 private:
00070 friend class boost::serialization::access;
00077 template<class Archive>
00078 void serialize(Archive & archive, const unsigned int version)
00079 {
00080 archive & mCells;
00081 archive & mLocationCellMap;
00082 archive & mCellLocationMap;
00083 archive & mCellProliferativeTypeCount;
00084 archive & mCellCyclePhaseCount;
00085 archive & mpCellPropertyRegistry;
00086 archive & mOutputCellIdData;
00087 archive & mOutputCellMutationStates;
00088 archive & mOutputCellAncestors;
00089 archive & mOutputCellProliferativeTypes;
00090 archive & mOutputCellVariables;
00091 archive & mOutputCellCyclePhases;
00092 archive & mOutputCellAges;
00093 archive & mOutputCellVolumes;
00094 }
00095
00096 protected:
00097
00099 std::list<CellPtr> mCells;
00100
00102 std::map<unsigned, CellPtr> mLocationCellMap;
00103
00105 std::map<Cell*, unsigned> mCellLocationMap;
00106
00108 std::vector<unsigned> mCellProliferativeTypeCount;
00109
00111 std::vector<unsigned> mCellCyclePhaseCount;
00112
00114 c_vector<double, DIM> mCentroid;
00115
00117 out_stream mpVizNodesFile;
00118
00120 out_stream mpVizCellProliferativeTypesFile;
00121
00123 out_stream mpVizCellProliferativePhasesFile;
00124
00126 out_stream mpCellMutationStatesFile;
00127
00129 out_stream mpVizCellAncestorsFile;
00130
00132 out_stream mpCellProliferativeTypesFile;
00133
00135 out_stream mpCellCyclePhasesFile;
00136
00138 out_stream mpCellVariablesFile;
00139
00141 out_stream mpCellAgesFile;
00142
00144 out_stream mpCellIdFile;
00145
00147 out_stream mpCellVolumesFile;
00148
00150 out_stream mpVizBoundaryNodesFile;
00151
00153 std::string mDirPath;
00154
00156 out_stream mpVtkMetaFile;
00157
00159 boost::shared_ptr<CellPropertyRegistry> mpCellPropertyRegistry;
00160
00162 bool mOutputCellIdData;
00163
00165 bool mOutputCellMutationStates;
00166
00168 bool mOutputCellAncestors;
00169
00171 bool mOutputCellProliferativeTypes;
00172
00174 bool mOutputCellVariables;
00175
00177 bool mOutputCellCyclePhases;
00178
00180 bool mOutputCellAges;
00181
00183 bool mOutputCellVolumes;
00184
00191 virtual void Validate()=0;
00192
00199 virtual void WriteVtkResultsToFile()=0;
00200
00206 AbstractCellPopulation()
00207 {
00208 }
00209
00210 public:
00211
00222 AbstractCellPopulation(std::vector<CellPtr>& rCells,
00223 const std::vector<unsigned> locationIndices=std::vector<unsigned>());
00224
00228 virtual ~AbstractCellPopulation();
00229
00233 void InitialiseCells();
00234
00238 std::list<CellPtr>& rGetCells();
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 void SetNode(unsigned nodeIndex, ChastePoint<DIM>& rNewLocation)=0;
00280
00291 virtual bool IsCellAssociatedWithADeletedLocation(CellPtr pCell)=0;
00292
00308 virtual CellPtr AddCell(CellPtr pNewCell, const c_vector<double,DIM>& rCellDivisionVector, CellPtr pParentCell=CellPtr())=0;
00309
00310 class Iterator;
00311
00320 virtual unsigned RemoveDeadCells()=0;
00321
00328 virtual void Update(bool hasHadBirthsOrDeaths=true)=0;
00329
00339 std::vector<unsigned> GetCellMutationStateCount();
00340
00349 const std::vector<unsigned>& rGetCellProliferativeTypeCount() const;
00350
00361 const std::vector<unsigned>& rGetCellCyclePhaseCount() const;
00362
00366 unsigned GetNumRealCells();
00367
00372 void SetCellAncestorsToLocationIndices();
00373
00377 void WriteCellIdDataToFile();
00378
00385 std::set<unsigned> GetCellAncestors();
00386
00397 CellPtr GetCellUsingLocationIndex(unsigned index);
00398
00409 unsigned GetLocationIndexUsingCell(CellPtr pCell);
00410
00414 boost::shared_ptr<CellPropertyRegistry> GetCellPropertyRegistry();
00415
00420 void SetDefaultMutationStateOrdering();
00421
00431 virtual double GetWidth(const unsigned& rDimension)=0;
00432
00442 virtual std::set<unsigned> GetNeighbouringNodeIndices(unsigned index)=0;
00443
00447 c_vector<double, DIM> GetCentroidOfCellPopulation();
00448
00455 virtual void CreateOutputFiles(const std::string& rDirectory,
00456 bool cleanOutputDirectory);
00457
00461 virtual void WriteResultsToFiles();
00462
00466 virtual void WriteTimeAndNodeResultsToFiles();
00467
00471 virtual void GenerateCellResultsAndWriteToFiles()=0;
00472
00480 virtual void GenerateCellResults(unsigned locationIndex,
00481 std::vector<unsigned>& rCellProliferativeTypeCounter,
00482 std::vector<unsigned>& rCellCyclePhaseCounter);
00483
00489 virtual void WriteCellVolumeResultsToFile()=0;
00490
00497 void WriteCellResultsToFiles(std::vector<unsigned>& rCellProliferativeTypeCounter,
00498 std::vector<unsigned>& rCellCyclePhaseCounter);
00499
00503 virtual void CloseOutputFiles();
00504
00510 void OutputCellPopulationInfo(out_stream& rParamsFile);
00511
00520 virtual void OutputCellPopulationParameters(out_stream& rParamsFile)=0;
00521
00525 bool GetOutputCellIdData();
00526
00530 bool GetOutputCellMutationStates();
00531
00535 bool GetOutputCellAncestors();
00536
00540 bool GetOutputCellProliferativeTypes();
00541
00545 bool GetOutputCellVariables();
00546
00550 bool GetOutputCellCyclePhases();
00551
00555 bool GetOutputCellAges();
00556
00560 bool GetOutputCellVolumes();
00561
00567 void SetOutputCellIdData(bool outputCellIdData);
00568
00574 void SetOutputCellMutationStates(bool outputCellMutationStates);
00575
00581 void SetOutputCellAncestors(bool outputCellAncestors);
00582
00588 void SetOutputCellProliferativeTypes(bool outputCellProliferativeTypes);
00589
00595 void SetOutputCellVariables(bool outputCellVariables);
00596
00602 void SetOutputCellCyclePhases(bool outputCellCyclePhases);
00603
00609 void SetOutputCellAges(bool outputCellAges);
00610
00616 void SetOutputCellVolumes(bool outputCellVolumes);
00617
00622 c_vector<double,DIM> GetSizeOfCellPopulation();
00623
00630 class Iterator
00631 {
00632 public:
00633
00637 inline CellPtr operator*();
00638
00643 inline CellPtr operator->();
00644
00650 inline bool operator!=(const AbstractCellPopulation<DIM>::Iterator& rOther);
00651
00655 inline Iterator& operator++();
00656
00663 Iterator(AbstractCellPopulation& rCellPopulation, std::list<CellPtr>::iterator cellIter);
00664
00668 virtual ~Iterator()
00669 {}
00670
00671 private:
00672
00679 virtual inline bool IsRealCell();
00680
00684 inline bool IsAtEnd();
00685
00687 AbstractCellPopulation& mrCellPopulation;
00688
00690 std::list<CellPtr>::iterator mCellIter;
00691 };
00692
00696 Iterator Begin();
00697
00701 Iterator End();
00702
00703 };
00704
00705 enum cell_colours
00706 {
00707 STEM_COLOUR,
00708 TRANSIT_COLOUR,
00709 DIFFERENTIATED_COLOUR,
00710 EARLY_CANCER_COLOUR,
00711 LATE_CANCER_COLOUR,
00712 LABELLED_COLOUR,
00713 APOPTOSIS_COLOUR,
00714 INVISIBLE_COLOUR
00715 };
00716
00717 TEMPLATED_CLASS_IS_ABSTRACT_1_UNSIGNED(AbstractCellPopulation)
00718
00719
00720
00722
00723 template<unsigned DIM>
00724 CellPtr AbstractCellPopulation<DIM>::Iterator::operator*()
00725 {
00726 assert(!IsAtEnd());
00727 return *mCellIter;
00728 }
00729
00730 template<unsigned DIM>
00731 CellPtr AbstractCellPopulation<DIM>::Iterator::operator->()
00732 {
00733 assert(!IsAtEnd());
00734 return *mCellIter;
00735 }
00736
00737 template<unsigned DIM>
00738 bool AbstractCellPopulation<DIM>::Iterator::operator!=(const AbstractCellPopulation<DIM>::Iterator& rOther)
00739 {
00740 return mCellIter != rOther.mCellIter;
00741 }
00742
00743 template<unsigned DIM>
00744 typename AbstractCellPopulation<DIM>::Iterator& AbstractCellPopulation<DIM>::Iterator::operator++()
00745 {
00746 do
00747 {
00748 ++mCellIter;
00749 }
00750 while (!IsAtEnd() && !IsRealCell());
00751
00752 return (*this);
00753 }
00754
00755 template<unsigned DIM>
00756 bool AbstractCellPopulation<DIM>::Iterator::IsRealCell()
00757 {
00758 return !( mrCellPopulation.IsCellAssociatedWithADeletedLocation(*mCellIter) || (*this)->IsDead() );
00759 }
00760
00761 template<unsigned DIM>
00762 bool AbstractCellPopulation<DIM>::Iterator::IsAtEnd()
00763 {
00764 return mCellIter == mrCellPopulation.rGetCells().end();
00765 }
00766
00767 template<unsigned DIM>
00768 AbstractCellPopulation<DIM>::Iterator::Iterator(AbstractCellPopulation& rCellPopulation, std::list<CellPtr>::iterator cellIter)
00769 : mrCellPopulation(rCellPopulation),
00770 mCellIter(cellIter)
00771 {
00772
00773 if (mrCellPopulation.rGetCells().empty())
00774 {
00775 mCellIter = mrCellPopulation.rGetCells().end();
00776 }
00777 else
00778 {
00779
00780 if (mCellIter == mrCellPopulation.rGetCells().begin() && !IsRealCell())
00781 {
00782 ++(*this);
00783 }
00784 }
00785 }
00786
00787 template<unsigned DIM>
00788 typename AbstractCellPopulation<DIM>::Iterator AbstractCellPopulation<DIM>::Begin()
00789 {
00790 return Iterator(*this, this->mCells.begin());
00791 }
00792
00793 template<unsigned DIM>
00794 typename AbstractCellPopulation<DIM>::Iterator AbstractCellPopulation<DIM>::End()
00795 {
00796 return Iterator(*this, this->mCells.end());
00797 }
00798
00799
00800 #endif