00001 #ifndef Pedigree_INCLUDED
00002 #define Pedigree_INCLUDED
00003
00004 #include <iostream>
00005 #include "Individual.h"
00006 #include "NuclearFamily.h"
00007 #include "DataTable.h"
00008 #include "DataColumn.h"
00009 #include "Data.h"
00010 #include "DescentTree.h"
00011 #include "LabelSet.h"
00012 #include "Exception.h"
00013 #include "utility.h"
00014 #include "Grid.h"
00015
00016
00020
00021 struct compareIndividual{
00022 bool operator()(Individual* i1,Individual* i2) const{
00023 return i1->getId() < i2->getId();
00024 }
00025 };
00026
00027 struct compareNuclearFamily{
00028 bool operator()(NuclearFamily* n1,NuclearFamily* n2) const{
00029 if(n1->getFather()->getId() != n2->getFather()->getId())
00030 return n1->getFather()->getId() < n2->getFather()->getId();
00031 return n1->getMother()->getId() < n2->getMother()->getId();
00032 }
00033 };
00034
00035 class Pedigree{
00036 public:
00037
00038
00039 Pedigree(){ _dtsHaveConsanguinity=false; }
00040 Pedigree(const std::string id, const unsigned tableId) : _id(id),_tableId(tableId),_dtsHaveConsanguinity(false) { }
00041 ~Pedigree();
00042
00043 void set(const std::string id, const unsigned tableId) { _id = id; _tableId = tableId; }
00044 std::string getId() const { return _id; }
00045 unsigned getTableId() const { return _tableId; }
00046 void addIndividual(const std::string ind,std::string mother,std::string father, std::string gender, int rowIndex, int tableIndex,const DataTable& pedigreeTable );
00047
00048 void setCoreOptionalFields(const DataTable* pedigreeTable);
00049 void determineFoundingGroups();
00050 void establishIndividualConnections();
00051
00052
00053 void checkForAncestorDescendantAnomoly(Individual *ancestor);
00054 void clearVisitCounts();
00055
00056 void checkParentChildDOB();
00057 void computePedigreeWidth(const std::string& sortField,bool dobSortOrder);
00058 void draw(const LabelSet* labelSet);
00059
00060 void display() const;
00061 static void setDrawingFileExtension(const std::string& ext);
00062
00063 private:
00064
00065 std::string _id;
00066 unsigned _tableId;
00067 bool _dtsHaveConsanguinity;
00068
00069 std::set<Individual*,compareIndividual> _individuals;
00070 std::set<NuclearFamily*,compareNuclearFamily> _nuclearFamilies;
00071 std::vector<NuclearFamily*> _nfOfOrdinaryFounders;
00072 std::vector<DescentTree*> _descentTrees;
00073 std::map<std::string, std::vector<Individual*> > _twinMarkers;
00074 std::set<std::string> _consangPairIds;
00075 Grid<int,Individual* > _individualGrid;
00076
00077
00078 std::vector<Individual *> _anomolous;
00079
00080 void _setIndividualTwinField(const DataColumn * twinDataColumn,char type);
00081 void _assignChildrenDescentTree(Individual* individual,unsigned descentTreeId);
00082 void _assignDescentTrees();
00083 void _addDescentTree(unsigned id) ;
00084 void _addDescentTreesConnectedTo(unsigned dtIndex,std::deque<DescentTree*>& orderedDescentTrees,bool left);
00085 void _sortAndCalculateDescentTreeWidth();
00086 void _checkParentsGender(Individual* individual);
00087 void _checkMarkedTwinsDOB();
00088 void _calculateWidth(Individual* individual,bool classicalOrder,unsigned descentTreeIndex);
00089 void _populateIndividualGrid();
00090 void _sortNuclearFamilies(bool consanguinousFlag);
00091 void _sortIndividualNuclearFamilies();
00092 void _sortNuclearFamiliesBasedOnDataField(const std::string& name,bool dobSortOrder);
00093 void _addNuclearFamily(Individual* mother,Individual* father);
00094 void _establishNuclearFamilies();
00095 void _determineConnectorIndividuals();
00096 void _reorderDescentTreesBasedOnExternalConnections();
00097 void determineConnectorIndividualsOld();
00098 void _setLeftShiftConnectionFlags();
00099
00100
00101
00102 void _markConnectorIndividuals(Individual* individual,unsigned& loopNumber);
00103 void _markLeftLoopFlags(Individual* individual,unsigned loopNumber);
00104 void _markRightLoopFlags(Individual* individual,unsigned loopNumber);
00105 void _markLeftExternalConnectionFlags(Individual* individual,unsigned connectionNumber);
00106 void _markRightExternalConnectionFlags(Individual* individual,unsigned connectionNumber);
00107 void _markExternalConnectionFlags();
00108 void _markConsanguinousIndividuals();
00109 void _markConsanguinousFlags(Individual* individual,unsigned& loopNumber);
00110
00111
00112 void _drawConsanguinousConnectors(DrawingCanvas& dc);
00113 void _drawConsanguinityLetter(Individual* mother,Individual* father,unsigned int &uniqueId,double iconInterval,double iconDiameter, std::map<std::string,std::string>& individualConsanguinityLetter,DrawingCanvas& dc,double multipleSpouseOffset=0,bool leftConnector=false);
00114 void _drawHorizontalConnectorLine(double y,double x1,double x2,bool isConsanguinous,DrawingCanvas& dc);
00115 void _drawVerticalConnectorLine(double startY,double endY,double startX,double endX,bool isConsanguinous,DrawingCanvas& dc,double multipleSpouseOffset=0.0,bool singleChild=false);
00116 void _getSpouses(std::set<Individual*,compareIndividual>& foundingGroup,Individual* individual) ;
00117
00118 bool _hasIndividualAtPosition(Individual* start,Individual* end);
00119 void _sortSibsBasedOnExternalConnections(const std::vector<Individual*>& sibs,std::vector<Individual*>& sortedSibs);
00120
00121 void _sortSibsBasedOnConsanguinousConnections(const std::vector<Individual*>& sibs,std::vector<Individual*>& sortedSibs);
00122
00123 unsigned _getPrimaryDescentTreeIndex(std::set<unsigned>& dt,Individual* individual,bool increment);
00124
00125 };
00126
00127 #endif // Pedigree_INCLUDED
00128