00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef gnodestuff_h
00023 #define gnodestuff_h
00024 #include <ext/hash_map>
00025 #include <map>
00026 #include <set>
00027 #include "geneticdist.h"
00028 #include "exception.h"
00029 #include "safe_vectors.h"
00030
00031
00032 namespace matvec {
00033 class Population;
00034 class GNodeSet;
00035 class CutSet;
00036 class GNodeList;
00037 class GNode {
00038 public:
00039 GNode(void);
00040 static GNodeList* gNodeListPtr;
00041 bool sampled;
00042 unsigned weight;
00043 set< GNodeSet*> SetofGNsts;
00044 CutSet* generatedSet;
00045 CutSet* myOldGNodeProbs;
00046 unsigned peelorder;
00047 unsigned id;
00048 unsigned connectFlag;
00049 unsigned numberOfCuts;
00050 float getCutsetMagnitude(void);
00051 void updateMysets(void);
00052 CutSet* makeNeighSet(void);
00053 CutSet calcBCutSetForPrevGNode(CutSet* FCutSetPrevGNode);
00054 CutSet calcMyBCutSet(void);
00055 void peel(void);
00056 void reComputeGNode();
00057 void reverseSampleGNode();
00058 void sampleGNode();
00059 void release(void);
00060 bool isMyNeighbor(GNode* refGNode);
00061 SafeSTLVector<int> sampledStateCount;
00062 virtual unsigned getState(void){
00063 throw exception("GNode::getState(): called for virtual function");
00064 };
00065 virtual unsigned getOldState(void){
00066 throw exception("GNode::getOldState(): called for virtual function");
00067 };
00068 virtual unsigned getAcceptedAlleleState(void){
00069 throw exception("GNode::getAcceptedAlleleState(): called for virtual function");
00070 };
00071 virtual unsigned getMyAlleleState(void){
00072 throw exception("GNode::getmState(): called for virtual function");
00073 };
00074 virtual unsigned getMyAlleleOrigin(void){
00075 throw exception("GNode::getmState(): called for virtual function");
00076 };
00077 virtual unsigned getAcceptedMatState(void){
00078 throw exception("GNode::getAcceptedMatState(): called for virtual function");
00079 };
00080 virtual unsigned getAcceptedPatState(void){
00081 throw exception("GNode::getAcceptedPatState(): called for virtual function");
00082 };
00083 virtual unsigned getmState(void){
00084 throw exception("GNode::getmState(): called for virtual function");
00085 };
00086 virtual unsigned getpState(void){
00087 throw exception("GNode::getpState(): called for virtual function");
00088 };
00089 virtual unsigned getWeight(void){
00090 throw exception("GNode::getWeight(): called for virtual function");
00091 };
00092 virtual bool incr(){
00093 throw exception("GNode::incr(): called for virtual function");
00094 };
00095 virtual void reset(int i){
00096 throw exception("GNode::reset(int i): called for virtual function");
00097 };
00098 virtual void resetAndSwitch(int i){
00099 throw exception("GNode::resetAndSwitch(int i): called for virtual function");
00100 };
00101 virtual ~GNode(void) {release();}
00102 };
00103
00104
00105
00106
00107
00108 class GNodeSet:public set<GNode*>{
00109 public:
00110 GNodeSet(void);
00111 unsigned connectFlag;
00112 unsigned numberOfCuts;
00113 static GeneticDist *prior;
00114 static unsigned currentLocus;
00115 bool incr(void);
00116 void reset(void);
00117 void attachMeToMyGnodes(void);
00118 void display(void);
00119 virtual double getValue(void){
00120 throw exception("GNodeSet::getValue(void): call for virtual function");
00121 };
00122 virtual double getTargetValue(void){
00123 throw exception("GNodeSet::getTargetValue(void): call for virtual function");
00124 };
00125 virtual double getOldValue(void){
00126 throw exception("GNodeSet::getOldValue(void): call for virtual function");
00127 };
00128 virtual ~GNodeSet(void) {;}
00129 };
00130
00131
00132
00133
00134
00135 struct compareGNodesWeight: public binary_function<GNode*,GNode*,bool>{
00136 bool operator()(GNode* a,GNode* b){
00137 unsigned aw = a->sampled ? 1 : a->getWeight();
00138 unsigned bw = b->sampled ? 1 : b->getWeight();
00139 return aw>bw;
00140 }
00141 };
00142
00143
00144
00145
00146 struct compareGNodesPeelId: public binary_function<GNode*,GNode*,bool>{
00147 bool operator()(GNode* a,GNode* b){
00148 return a->peelorder<b->peelorder;
00149 }
00150 };
00151
00152
00153
00154
00155 struct GNode_info {
00156 GNode* pointerToGNode;
00157 unsigned dist;
00158 };
00159
00160
00161
00162
00163 class InvalidSample{};
00164
00165 class GNodeList:public SafeSTLVector<GNode*> {
00166 public:
00167
00168 static double logTarget;
00169 static double logProposal;
00170 static double logOldProposal;
00171 static Population *popPtr;
00172 float sum;
00173 unsigned lastmember;
00174 Matrix<int> distanceMat;
00175 bool distanceMatDone;
00176 SafeSTLVector<GNode*> cutGNodesVector;
00177 set<GNode*> loopSetGNodes;
00178 GNodeList(void){distanceMatDone = false;};
00179 void inputGNodeSets(char* fname);
00180 void displayGNodeSets();
00181 void getPeelOrder(char* fname);
00182 void fill(unsigned n);
00183 void makealleleGNodeSets(char* infile,char* outfile);
00184 void makegenotGNodeSets(char* infile,char* outfile);
00185
00186 unsigned maxDist;
00187 GNode* sampleGNodePtr;
00188 GNode* containerGNode;
00189 set< GNodeSet*> completeSetofGNsts;
00190 set< CutSet*> completeSetofCutSets;
00191 GNodeList::iterator searchStart;
00192 GNodeList::iterator cutGNode;
00193 GNode* peelAndCut(unsigned maxCutSetSize);
00194 GNode* peelAndCutFast(void);
00195 void peelCutAndCompute(unsigned maxCutSetSize, unsigned startBlock,unsigned stopBlock,unsigned sizeBlock);
00196 void peelCutAndSample(unsigned maxCutSetSize, unsigned startBlock,unsigned stopBlock,unsigned sizeBlock);
00197 void peelCutAndSample(unsigned maxCutSetSize);
00198 void peelOrderCutAndSample(unsigned maxCutSetSize,unsigned startBlock,unsigned stopBlock,unsigned sizeBlock);
00199 void peelOrderCutAndSample(unsigned maxCutSetSize);
00200 void clearGNodeListForNextLocus(void);
00201 void reinitGNodeList(void);
00202 void releaseGNsts(void);
00203 void releaseCutSets(void);
00204 void resetGNodeList(void);
00205 void setGNodeSampleFlags(unsigned startBlock, unsigned stopBlock, unsigned sizeBlock);
00206 void setGNodeSampleFlags(void);
00207 void findLoopAndCut();
00208 GNodeList::iterator getMinWeightGNode(void);
00209 set< GNodeSet*>::iterator getCutGNodeSet(GNodeList::iterator cutGNode);
00210 void propagateFlags(unsigned lowFlag, unsigned highFlag);
00211 void resetConnectFlags(void);
00212 GNode_info choosenGNodeInfo;
00213 GNodeList isolatePureLoop(GNodeList::iterator loopCloser);
00214 void cutLoop(GNodeList::iterator cutGNode, set< GNodeSet*>::iterator cutGNodeSet);
00215 void checkSample(void);
00216 void calculateTargetProb(void);
00217 string howToSample;
00218 void makeDistanceMatrix(void);
00219 void calcDistancefrom(GNode* refGNode);
00220 GNode* findSampleGNode(void);
00221 };
00222
00223
00224
00225
00226
00227
00228 }
00229 #endif