00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef Individual_INCLUDED
00030 #define Individual_INCLUDED
00031
00032 #include "String.h"
00033 #include "Gender.h"
00034 #include "Date.h"
00035 #include "Affected.h"
00036 #include "Twin.h"
00037 #include "LivingDead.h"
00038 #include "Proband.h"
00039 #include "DataTable.h"
00040 #include "Sampled.h"
00041 #include "Consultand.h"
00042 #include "Carrier.h"
00043 #include "RelationshipEnded.h"
00044 #include "Infertility.h"
00045 #include "Sterility.h"
00046
00047 #include <set>
00048 #include <vector>
00049 #include <map>
00050 #include <deque>
00051
00052
00053 class NuclearFamily;
00054
00055 class Individual{
00056
00057 private:
00058
00059 inline void _init(void);
00060 void _checkForSpecialIndividualTypes(void);
00061 void _rearrangeMultipleSpouses(std::deque<Individual*>& initial,std::deque<Individual*>& left,std::deque<Individual*>& right,std::deque<Individual*>& result);
00062
00063 public:
00064
00065
00066
00067 struct compareIndividual
00068 {
00069 bool operator()(Individual* i1, Individual* i2) const
00070 {
00071 return i1->getId().get().compare(i2->getId().get()) < 0;
00072 }
00073 };
00074
00075
00076 private:
00077
00078
00079
00080
00081
00082 String _id;
00083 String _motherId;
00084 String _fatherId;
00085 Gender _gender;
00086
00087
00088 Date* _dob;
00089 Date* _dod;
00090 Affected* _affected;
00091 LivingDead* _deceased;
00092 Proband* _proband;
00093 Consultand* _consultand;
00094 Carrier* _carrier;
00095 RelationshipEnded* _relationshipEnded;
00096 Sterility* _sterility;
00097 Infertility* _infertility;
00098 Twin _twinMarker;
00099 Sampled* _sampled;
00100
00101 Individual *_father;
00102 Individual *_mother;
00103
00104 Individual *_adoptedComplement;
00105
00106
00107
00108
00109 bool _isVirtual;
00110 bool _isUnconnected;
00111 bool _isConsanguinous;
00112 bool _hasExternalConnection;
00113 unsigned _birthOrder;
00114
00115
00116 bool _isOriginalFounder;
00117 bool _isOrdinaryFounder;
00118
00119
00120
00121
00122 unsigned _leftWidth;
00123 unsigned _rightWidth;
00124 unsigned _totalWidth;
00125 double _x;
00126 double _y;
00127 bool _hasBeenVisited;
00128 int _visitCount;
00129 bool _hasBeenDrawn;
00130
00131
00132 unsigned _leftSideOfLoop;
00133 unsigned _rightSideOfLoop;
00134
00135
00136 unsigned _leftSideOfExternalConnection;
00137 unsigned _rightSideOfExternalConnection;
00138
00139
00140 bool _leftSpouseConnector;
00141
00142 struct compareData{
00143 bool operator()(Data* a, Data* b) const{
00144 return *a < *b;
00145 }
00146 };
00147
00148
00149 std::set<Individual *,compareIndividual> _spouses;
00150 std::set<Individual *,compareIndividual> _children;
00151
00152 std::map<std::string, std::vector<Individual*> > _childrenIdsSortedByExternalConnections;
00153 std::set<unsigned> _descentTrees;
00154 std::vector<NuclearFamily*> _nuclearFamilies;
00155
00156
00157 int _rowIndex;
00158 int _tableIndex;
00159 const DataTable *_pedigreeTable;
00160
00161 static bool _sampledColumnPresent;
00162
00163
00164
00165
00166 bool _individualIndicatingNoOffspring;
00167 bool _individualIndicatingNonFertility;
00168 bool _individualIndicatingTerminatedPregnancy;
00169 bool _individualAdoptedOut;
00170 bool _individualAdoptedIn;
00171 bool _isSpecial;
00172
00173 public:
00174
00175
00176
00177
00178 Individual();
00179 Individual(const std::string & id);
00180 Individual(const std::string & id, int rowIndex, int tableIndex);
00181 Individual(const std::string & id, const std::string & motherId, const std::string & fatherId, const std::string &gender);
00182 Individual(const std::string & id, const std::string & motherId, const std::string & fatherId, const std::string & gender,int rowIndex,int tableIndex);
00183
00184
00185
00186
00187 static std::string getRandomId();
00188 static void groupIndividualsBasedOn(bool consanguinousLoop,const std::vector<Individual*>& individuals,std::deque<Individual*>& initial,std::deque<Individual*>& left,std::deque<Individual*>& right,bool unique=false);
00189 static std::vector<Individual*> sortIndividualsBasedOnDataField(const std::string& name,const std::vector<Individual*>& individuals,bool dobSortOrder);
00190 static void setSampledColumnPresent();
00191 static bool getSampledColumnPresent();
00192
00193
00194
00195
00196 void setOrdinaryFounder(bool value) { _isOrdinaryFounder = value; }
00197 void setOriginalFounder(bool value) { _isOriginalFounder = value; }
00198 void setExternalConnection(bool value) { _hasExternalConnection = value; }
00199 void setIsUnconnected(bool value) { _isUnconnected = value; }
00200 void setIsConsanguinous(bool value) { _isConsanguinous = value; }
00201 void setMother(Individual* mother) { _mother = mother; }
00202 void setFather(Individual* father) { _father = father; }
00203 void setAdoptedComplement(Individual* adoptedComplement) { _adoptedComplement = adoptedComplement; }
00204 void setDOB(Date* dob) { _dob = dob; }
00205 void setAffectionStatus(Affected* affected) { _affected = affected; }
00206 void setProbandStatus(Proband* proband) { _proband = proband; }
00207 void setDeceasedStatus(LivingDead* deceased) { _deceased = deceased; }
00208 void setVirtualIndividual(bool value){ _isVirtual = value; }
00209 void setMotherId(std::string motherId){ _motherId = motherId; }
00210 void setFatherId(std::string fatherId){ _fatherId = fatherId; }
00211 void setTwin(std::string marker,Twin::TWIN_TYPE type) { _twinMarker.set(marker,type); }
00212 void setGender(std::string gender) { _gender.set(gender); }
00213 void setSampled(Sampled* sampled){ _sampled=sampled; }
00214 void setConsultandStatus(Consultand* consultand){ _consultand=consultand; }
00215 void setCarrierStatus(Carrier* carrier){ _carrier=carrier; }
00216
00217 void setRelationshipEndedStatus(RelationshipEnded* relationshipEnded){ _relationshipEnded=relationshipEnded; }
00218 void setInfertilityStatus (Infertility* infertility ){ _infertility =infertility; }
00219 void setSterilityStatus (Sterility* sterility ){ _sterility =sterility; }
00220
00221 void setBirthOrder(unsigned birthOrder){ _birthOrder = birthOrder; }
00222
00223
00224 void setLeftWidth(unsigned leftWidth){ _leftWidth = leftWidth; }
00225 void setRightWidth(unsigned rightWidth){ _rightWidth = rightWidth; }
00226 void setTotalWidth(unsigned totalWidth) { _totalWidth = totalWidth; }
00227 void setX(double x) { _x = x; }
00228 void setY(double y) { _y = y; }
00229 void setLeftSideOfLoop(unsigned loopNumber){ _leftSideOfLoop = loopNumber; }
00230 void setRightSideOfLoop(unsigned loopNumber){ _rightSideOfLoop = loopNumber; }
00231 void setLeftSideOfExternalConnection(unsigned connectionNumber) { _leftSideOfExternalConnection = connectionNumber; }
00232 void setRightSideOfExternalConnection(unsigned connectionNumber) { _rightSideOfExternalConnection = connectionNumber; }
00233 void setHasBeenDrawn() { _hasBeenDrawn = true; }
00234 void setVisited(bool value) { _hasBeenVisited = value; }
00235
00236
00237
00238
00239 void setLeftSpouseConnector(bool value){ _leftSpouseConnector = value; }
00240
00241
00242
00243
00244
00245 String getId( void ) { return _id; }
00246 String getMotherId( void ) { return _motherId; }
00247 String getFatherId( void ) { return _fatherId; }
00248 Gender getGender(void) { return _gender; }
00249 Date* getDOB(void) { return _dob; }
00250
00251
00252
00253
00254 bool isOrdinaryFounder(void) { return _isOrdinaryFounder; }
00255 bool isOriginalFounder(void) { return _isOriginalFounder; }
00256 bool isVirtual(void) { return _isVirtual; }
00257 bool hasExternalConnection(void) { return _hasExternalConnection; }
00258 bool hasBeenVisited(void) { return _hasBeenVisited; }
00259 bool hasBeenDrawn(void) { return _hasBeenDrawn; }
00260 bool isConsanguinous(void) { return _isConsanguinous; }
00261
00262
00263 bool isAffected(void) { if(_affected == 0) return false; return _affected->getBoolean(); }
00264 bool isSampled(void) { if(_sampled == 0) return false; return _sampled->getBoolean(); }
00265 bool isProband(void) { if(_proband == 0) return false; return _proband->getBoolean(); }
00266 bool isConsultand(void) { if(_consultand == 0) return false; return _consultand->getBoolean(); }
00267 bool isCarrier(void) { if(_carrier == 0) return false; return _carrier->getBoolean(); }
00268
00269 bool relationshipHasEnded(void){ if(_relationshipEnded == 0) return false; return _relationshipEnded->getBoolean(); }
00270
00271 bool isInfertile(void){ if(_infertility == 0) return false; return _infertility->getBoolean(); }
00272 bool isSterile(void) { if(_sterility == 0) return false; return _sterility->getBoolean(); }
00273
00274 bool isDeceased(void) { if(_deceased == 0) return false; return _deceased->getBoolean(); }
00275
00276
00277
00278
00279 RelationshipEnded::TYPE getRelationshipEndedType(void) const {if(_relationshipEnded == 0) return RelationshipEnded::RELATIONSHIP_ENDED_MISSING_TYPE; return _relationshipEnded->getType(); }
00280
00281 Infertility::TYPE getInfertilityType(void) const {if(_infertility == 0) return Infertility::UNKNOWN_INFERTILITY_TYPE; return _infertility->getType(); }
00282 Sterility::TYPE getSterilityType(void) const {if(_sterility == 0) return Sterility::UNKNOWN_STERILITY_TYPE; return _sterility->getType(); }
00283 std::string getInfertilityLabel(void) const {if(_infertility == 0) return std::string("."); return _infertility->get(); }
00284 std::string getSterilityLabel(void) const {if(_sterility == 0) return std::string("."); return _sterility->get(); }
00285
00286
00287
00288
00289
00290 unsigned getBirthOrder(void) { return _birthOrder; }
00291 unsigned getRowIndex(void) { return _rowIndex; }
00292 Individual* getFather(void) { return _father; }
00293 Individual* getMother(void) { return _mother; }
00294 Individual* getAdoptedComplement(void) { return _adoptedComplement; }
00295 Individual* getFirstSpouse(void);
00296 Twin getTwinMarker(void) { return _twinMarker; }
00297 unsigned getNumberOfSpouses(void) { return _spouses.size(); }
00298 unsigned getNumberOfChildren(void) { return _children.size(); }
00299 unsigned getNumberOfDescentTrees(void) { return _descentTrees.size(); }
00300 unsigned getNumberOfNuclearFamilies(void) { return _nuclearFamilies.size(); }
00301 NuclearFamily* getNuclearFamily(unsigned index);
00302 std::set<unsigned> getDescentTrees(void) { return _descentTrees; }
00303
00304
00305 unsigned getLeftWidth(void) { return _leftWidth; }
00306 unsigned getRightWidth(void) { return _rightWidth; }
00307 unsigned getTotalWidth(void) { return _totalWidth; }
00308 double getX(void) { return _x; }
00309 double getY(void) { return _y; }
00310 unsigned getLeftSideOfLoop(void) { return _leftSideOfLoop; }
00311 unsigned getRightSideOfLoop(void) { return _rightSideOfLoop; }
00312 unsigned getLeftSideOfExternalConnection(void) { return _leftSideOfExternalConnection; }
00313 unsigned getRightSideOfExternalConnection(void) { return _rightSideOfExternalConnection; }
00314 unsigned getLeftFlag(bool consanguinousLoop);
00315 unsigned getRightFlag(bool consanguinousLoop);
00316 bool getLeftSpouseConnector(void) { return _leftSpouseConnector; }
00317
00318
00319 std::vector<std::string> getChildrenIds(Individual* spouse);
00320
00321 const std::set<Individual*,compareIndividual> *const getSpouses(void) const;
00322 const std::set<Individual*,compareIndividual> *const getChildren(void) const;
00323
00324 void getChildrenWithSpouse(Individual* spouse,std::vector<Individual*>& children);
00325 void getChildrenSortedByExternalConnections(Individual* spouse,std::vector<Individual*>& children);
00326
00327
00328 void setPedigreeDataTable(const DataTable *pedigreeTable){
00329 _pedigreeTable = pedigreeTable;
00330 }
00331
00332 Data* getData(const std::string label){
00333 if(_tableIndex != -1 && _rowIndex != -1){
00334 if(_pedigreeTable->columnExists(label.c_str())){
00335 return _pedigreeTable->getDataAtIndex(label,_rowIndex);
00336 }
00337 }
00338
00339 Data* temp = new String(".");
00340 return temp;
00341 }
00342
00343
00344 void sortSpouses(bool externalFlag=false);
00345 void addSpouse(Individual* spouse);
00346 void addChild(Individual* child) { _children.insert(child); }
00347 void addDescentTree(unsigned descentTreeId) { _descentTrees.insert(descentTreeId); }
00348 void addNuclearFamily(NuclearFamily* nuclearFamily){ _nuclearFamilies.push_back(nuclearFamily); }
00349 void setChildrenIdsSortedByExternalConnections(std::string parentPair,std::vector<Individual*> children);
00350
00351
00352 void displayChildren();
00353 void displaySpouses();
00354 void displayNuclearFamilies();
00355 void display();
00356
00357
00358
00359
00360 inline bool isIndividualIndicatingNoOffspring(void){ return _individualIndicatingNoOffspring; }
00361 inline bool isIndividualIndicatingNonFertility(void){ return _individualIndicatingNonFertility; }
00362 inline bool isIndividualIndicatingTerminatedPregnancy(void){ return _individualIndicatingTerminatedPregnancy; }
00363 inline bool isIndividualAdoptedIn(void){ return _individualAdoptedIn; }
00364 inline bool isIndividualAdoptedOut(void){ return _individualAdoptedOut; }
00365 inline bool isSpecial(void){ return _isSpecial; }
00366
00367
00368
00369
00370 const DataTable * getDataTable(void) const { return _pedigreeTable; }
00371
00372
00373
00374
00375 int getVisitCount() { return _visitCount; }
00376 void resetVisitCount() { _visitCount = 0; }
00377 void incrementVisitCount() { _visitCount++; }
00378
00379 };
00380
00381 #endif