Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

Individual.h

Go to the documentation of this file.
00001 
00002 //
00003 // This file is part of the MADELINE 2 program 
00004 // written by Edward H. Trager, Ritu Khanna, and Adrian Marrs
00005 // Copyright (c) 2005 by the
00006 // Regents of the University of Michigan.
00007 // All Rights Reserved.
00008 // 
00009 // The latest version of this program is available from:
00010 // 
00011 //   http://eyegene.ophthy.med.umich.edu/madeline/
00012 //   
00013 // Released under the GNU General Public License.
00014 // A copy of the GPL is included in the distribution
00015 // package of this software, or see:
00016 // 
00017 //   http://www.gnu.org/copyleft/
00018 //   
00019 // ... for licensing details.
00020 // 
00022 //
00023 // 2005.08.31.ET
00024 //
00025 
00026 //
00027 // Individual.h
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         // "less" function for comparing Individuals based on id:
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         // Inherent attributes -- These are normally derived directly from
00080         // reading a database table:
00081         // 
00082         String   _id;         // individual's ID - never missing
00083         String   _motherId;   // mother's ID - can be missing if father is also missing
00084         String   _fatherId;   // father's ID - can be missing if mother is also missing
00085         Gender   _gender;     // male, female, or missing
00086         
00087         // Attributes not present in FieldLabels:
00088         Date*       _dob;         // date of birth
00089         Date*       _dod;         // date of death
00090         Affected*   _affected;    // affection status
00091         LivingDead* _deceased;    // deceased or alive - defaults to missing
00092         Proband*    _proband;     // true for the proband only, else false; no need for missing
00093         Consultand* _consultand;  // true if a consultand, else false.
00094         Carrier*    _carrier;     // true if a carrier, else false.
00095         RelationshipEnded* _relationshipEnded; // true if relationship ended (divorced,separated,reason unknown) - requires that a mated pair are *both* so marked for display ...
00096         Sterility*         _sterility;         // 2009.05.19.ET ADDENDUM
00097         Infertility*       _infertility;       // 2009.05.19.ET ADDENDUM
00098         Twin        _twinMarker;  // stores the marker of monozygotic or dizygotic twin 
00099         Sampled*    _sampled;     // individual is sampled or not
00100         
00101         Individual *_father;  // Pointer to the father -- defaults to NULL (0)
00102         Individual *_mother;  // Pointer to the mother -- defaults to NULL (0)
00103         
00104         Individual *_adoptedComplement; // Pointer to adopted complement -- defaults to NULL (0);
00105         
00106         //
00107         // Constructed attributes:
00108         //
00109         bool     _isVirtual;             // true only for "virtual" individuals created by Madeline
00110         bool     _isUnconnected;         // true if the person remains unattached
00111         bool     _isConsanguinous;       // true if consanguinously mated
00112         bool     _hasExternalConnection; // true if the individual has a spouse from a different descent tree   
00113         unsigned _birthOrder;            // set when dob is present
00114         
00115         // Determined attributes:
00116         bool     _isOriginalFounder;
00117         bool     _isOrdinaryFounder;
00118         
00119         //
00120         // Drawing attributes:
00121         //
00122         unsigned _leftWidth;
00123         unsigned _rightWidth;
00124         unsigned _totalWidth;
00125         double   _x;              // drawing x position 
00126         double   _y;              // drawing y position
00127         bool     _hasBeenVisited; // true if the individual has been visited
00128         int      _visitCount;     // counter for times visited
00129         bool     _hasBeenDrawn;   // true if the individual has been drawn
00130         
00131         // Loop flags:
00132         unsigned _leftSideOfLoop;
00133         unsigned _rightSideOfLoop;
00134         
00135         // ExternalConnection flags:
00136         unsigned _leftSideOfExternalConnection;
00137         unsigned _rightSideOfExternalConnection;
00138         
00139         // Spouse Connector flag:
00140         bool _leftSpouseConnector;
00141         
00142         struct compareData{
00143                 bool operator()(Data* a, Data* b) const{
00144                         return *a < *b;
00145                 }
00146         };
00147         
00148         // Containers that establish individual connections:
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         // Link with the DataTable
00157         int _rowIndex;
00158         int _tableIndex;
00159         const DataTable *_pedigreeTable;
00160         
00161         static bool _sampledColumnPresent;
00162         
00163         //
00164         // Flags for special types of individuals:
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         // Constructors:
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         // Static Methods:
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         // Setters:
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         // 2009.05....ET Newly added columns:
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         // Set drawing attributes:
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         // By default the spouse connector is drawn on the right
00237         // In exceptional cases like consanguinity if the male of the pair
00238         // is on the left then the connector on the female is drawn on the left
00239         void setLeftSpouseConnector(bool value){ _leftSpouseConnector = value; }
00240         
00241         
00242         //
00243         // Getters:
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         // Getters that return Boolean:
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         // For these, if the pointer is NULL, then we have no information, so return false
00262         // Else, if the pointer is not NULL, then getBoolean() returns the state information:
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         // 2009.05.11.ET Addendum:
00269         bool     relationshipHasEnded(void){ if(_relationshipEnded == 0) return false; return _relationshipEnded->getBoolean(); }
00270         // 2009.05.19.ET Addenda:
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         // 2009.05.11.ET Addendum:
00277         // get RelationshipEnded type:
00278         //
00279         RelationshipEnded::TYPE getRelationshipEndedType(void) const {if(_relationshipEnded == 0) return RelationshipEnded::RELATIONSHIP_ENDED_MISSING_TYPE; return _relationshipEnded->getType(); }
00280         // 2009.05.19.ET Addenda:
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         // More getters:
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         // Get drawing attributes:
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         // Getters of Individual connections:
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         // Methods that access the underlying pedigree Data Table:
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         // Other Methods:
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         // Debug:
00352         void displayChildren();
00353         void displaySpouses();
00354         void displayNuclearFamilies();
00355         void display();
00356         
00357         //
00358         // "get" functions for determining special categories of individuals:
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         // getDataTable:
00369         //
00370         const DataTable * getDataTable(void) const { return _pedigreeTable; }
00371         
00372         //
00373         // 2011.03.17.ET Addendum:
00374         //
00375         int getVisitCount()          { return _visitCount; }
00376         void resetVisitCount()       { _visitCount = 0;    }
00377         void incrementVisitCount()   { _visitCount++;      }
00378         
00379 };
00380 
00381 #endif

Generated on Fri Nov 18 16:24:39 2011 for MADELINE by  doxygen 1.4.4