1 // $Id: gc_structures.h,v 1.37 2012/02/23 19:55:26 jmcgill Exp $
2 
3 /*
4   Copyright 2002  Mary Kuhner, Jon Yamato, and Joseph Felsenstein
5 
6   This software is distributed free of charge for non-commercial use
7   and is copyrighted.  Of course, we do not guarantee that the software
8   works, and are not responsible for any damage you may cause or have.
9 */
10 
11 #ifndef GC_STRUCTURES_H
12 #define GC_STRUCTURES_H
13 
14 #include "gc_dictionary.h"
15 #include "gc_file_info.h"
16 #include "gc_locus.h"
17 #include "gc_migration.h"
18 #include "gc_panel.h"
19 #include "gc_parent.h"
20 #include "gc_phase_info.h"
21 #include "gc_population.h"
22 #include "gc_structure_maps.h"
23 #include "gc_region.h"
24 #include "gc_trait.h"
25 #include "wx/string.h"
26 #include <set>
27 #include <map>
28 #include <vector>
29 
30 class gcTraitAllele;
31 
32 class gcNameSet : public gcDictionary
33 {
34   protected:
35     virtual const wxString &    infoString() const;
36   public:
37     gcNameSet();
38     virtual ~gcNameSet();
39 };
40 
41 class gcTraitNameSet : public gcDictionary
42 {
43   protected:
44     virtual const wxString &    infoString() const;
45   public:
46     gcTraitNameSet();
47     virtual ~gcTraitNameSet();
48 };
49 
50 class GCStructures
51 {
52   private:
53     const GCDataStore * m_dataStoreP;
54     gcNameSet           m_names;
55     gcTraitNameSet      m_traitNames;
56     gcBlockSetMap       m_blocks;
57     gcRegionMap         m_regions;
58     gcLocusMap          m_loci;
59     gcPanelMap          m_panels;
60     gcParentMap         m_parents;
61     gcPopMap            m_pops;
62     gcTraitMap          m_traitClasses;
63     gcAlleleMap         m_alleles;
64     gcPhenoMap          m_phenotypes;
65     gcFileMap           m_files;
66     gcMigrationMap      m_migrations;
67 
68     gcDisplayOrder      m_popDisplay;
69     gcDisplayOrder      m_regionDisplay;
70 
71     bool                m_divergenceState;
72     bool                m_panelsState;
73     bool                m_divMigMatrixDefined;
74     bool                m_migMatrixDefined;
75 
76 
77   protected:
78     bool                HaveBlocksForRegion(size_t regionId) const;
79     bool                HaveBlocksForLocus(size_t locusId) const;
80     bool                HaveBlocksForPop(size_t popId) const;
81     bool                IsBlessedRegion(size_t locusId) const;
82     bool                IsBlessedLocus(size_t locusId) const;
83     bool                IsBlessedPop(size_t popId) const;
84 
85   public:
86     GCStructures(const GCDataStore *);
87     ~GCStructures();
88 
89     bool AnyZeroes() const;
90 
91     void AssignBlockToPop(size_t blockId, size_t popId);
92     void AssignBlockToLocus(size_t blockId, size_t locusId);
93 
94     void AssignBlock(size_t blockId, size_t popId, size_t locusId);
95     void AssignLocus(size_t locusId, size_t regionId);
96     void AssignTrait(size_t traitId, size_t regionId);
97 
98     void AssignAllele(gcTraitAllele &, gcTraitInfo &);
99     void AssignLocus(gcLocus &, gcRegion &);
100     void AssignPhenotype(gcPhenotype &, gcTraitInfo &);
101     void AssignTrait(gcTraitInfo &, gcRegion &);
102 
103     void RemoveBlockAssignment(size_t blockId);
104 
105     void DebugDump(wxString prefix=wxEmptyString) const;
106 
107     bool GetDivergenceState();
108     bool GetDivergenceState() const;
109     void SetDivergenceState(bool state);
110 
111     bool GetPanelsState();
112     bool GetPanelsState() const;
113     void SetPanelsState(bool state);
114 
115     bool GetDivMigMatrixDefined();
116     bool GetDivMigMatrixDefined() const;
117     void SetDivMigMatrixDefined(bool state);
118 
119     bool GetMigMatrixDefined();
120     bool GetMigMatrixDefined() const;
121     void SetMigMatrixDefined(bool state);
122 
123     gcIdSet     GetBlockIds(size_t popId, size_t locusId) const;
124     gcIdSet     GetBlocksForLocus(size_t locusId) const;
125 
126     gcIdSet GetPanelIdsForRegions(gcIdSet regionIds) const;
127 
128     gcDisplayOrder  GetDisplayableLocusIds() const;
129     gcDisplayOrder  GetDisplayablePopIds() const;
130     gcDisplayOrder  GetDisplayableRegionIds() const;
131     gcDisplayOrder  GetParentIds() const;
132 
133     objVector   GetDisplayableRegions() ;
134     objVector   GetDisplayableLoci() ;
135     objVector   GetDisplayableLociFor(size_t regionId) ;
136     objVector   GetDisplayablePops() ;
137     objVector   GetParents() ;
138 
139     constObjVector  GetConstDisplayableRegions()   const;
140     constObjVector  GetConstDisplayableLoci()     const;
141 
142 #if 0  // Potentially DEAD CODE (bobgian, Feb 2010)
143     constObjVector  GetConstDisplayableLociFor(size_t regionId) const ;
144 #endif
145 
146     constObjVector  GetConstDisplayableLociInMapOrderFor(size_t regionId) const ;
147     constObjVector  GetConstDisplayableLinkedLociInMapOrderFor(size_t regionId) const ;
148     constObjVector  GetConstDisplayablePops()  const;
149     constObjVector  GetConstParents()  const;
150 
151     constObjVector  GetConstTraits() const;
152 
153     gcIdVec         GetLocusIdsForRegionByCreation(size_t regionId) const;
154     gcIdVec         GetLocusIdsForRegionByMapPosition(size_t regionId) const;
155 
156     gcTraitAllele &     GetAllele(size_t id);
157     gcRegion &          GetRegion(size_t id);
158     gcLocus &           GetLocus(size_t id);
159     gcPhenotype &       GetPhenotype(size_t id);
160     gcPopulation &      GetPop(size_t id);
161     gcTraitInfo &       GetTrait(size_t id);
162     gcPanel &           GetPanel(size_t id);
163     gcParent &          GetParent(size_t id);
164     gcMigration &       GetMigration(size_t id);
165 
166     const gcTraitAllele &   GetAllele(size_t id) const;
167     const gcRegion &        GetRegion(size_t id) const;
168     const gcLocus &         GetLocus(size_t id) const;
169     const gcPhenotype &     GetPhenotype(size_t id) const;
170     const gcPopulation &    GetPop(size_t id) const;
171     const gcTraitInfo &     GetTrait(size_t id) const;
172     const gcPanel &         GetPanel(size_t id) const;
173     const gcPanel &         GetPanel(size_t regionId, size_t popId) const;
174     const gcParent &        GetParent(size_t id) const;
175     const gcMigration &     GetMigration(size_t id) const;
176     const gcMigration &     GetMigration(size_t fromId, size_t toId) const;
177 
178     gcTraitAllele &             GetAllele(gcTraitInfo&,wxString name);
179     gcTraitAllele &             GetAllele(wxString name);
180     gcRegion &                  GetRegion(wxString name);
181     gcLocus &                   GetLocus(gcRegion&,wxString name);
182     gcLocus &                   GetLocus(wxString name);
183     gcPhenotype &               GetPhenotype(wxString name);
184     gcPopulation &              GetPop(wxString name);
185     gcTraitInfo &               GetTrait(wxString name);
186     gcPanel &                   GetPanel(wxString name);
187     gcPanel &                   GetPanel(size_t regionId, size_t popId);
188     gcParent &                  GetParent(wxString name);
189     gcMigration &               GetMigration(wxString name);
190     gcMigration &               GetMigration(size_t fromId, size_t toId);
191 
192     const gcTraitAllele &       GetAllele(wxString name) const;
193     const gcRegion &            GetRegion(wxString name) const;
194     const gcLocus &             GetLocus(wxString name) const;
195     const gcPhenotype &         GetPhenotype(wxString name) const;
196     const gcPopulation &        GetPop(wxString name) const;
197     const gcTraitInfo &         GetTrait(wxString name) const;
198     const gcPanel &             GetPanel(wxString name) const;
199     const gcParent &            GetParent(wxString name) const;
200 
201     bool  HasParents() const;
202     bool  HasPanel(size_t regionId, size_t popId) const;
203     bool  HasBlock(size_t locusId, size_t popId) const;
204     bool  HasMigration(size_t fromId, size_t toId) const;
205 
206     const GCPopMatcher &        GetPopMatcher(const GCFile&) const;
207     const GCLocusMatcher &      GetLocusMatcher(const GCFile&) const;
208     void                        SetPopMatcher(const GCFile&, const GCPopMatcher &);
209     void                        SetLocusMatcher(const GCFile&, const GCLocusMatcher &);
210 
211     const gcPhenoMap &          GetPhenotypeMap() const;
212 
213     bool            HasAllele(wxString name) const;
214     bool            HasLocus(wxString name) const;
215     bool            HasPop(wxString name) const;
216     bool            HasRegion(wxString name) const;
217     bool            HasTrait(wxString name) const;
218     bool            HasPanel(wxString name) const;
219     bool            HasMigration(wxString name) const;
220 
221     long GetPopDisplayIndexOf(size_t popId) const;
222     long GetLocusDisplayIndexOf(size_t locusId) const;
223 
224     size_t          GetPopForBlock(size_t blockId) const;
225     size_t          GetLocusForBlock(size_t blockId) const;
226 
227     gcTraitAllele & FetchOrMakeAllele(gcTraitInfo&, wxString name);
228     gcLocus &       FetchOrMakeLocus(gcRegion&, wxString name, const gcCreationInfo&);
229     //gcPhenotype &   FetchOrMakePhenotype();
230     gcPanel &       FetchOrMakePanel(wxString name);
231     gcPopulation &  FetchOrMakePop(wxString name);
232     gcRegion &      FetchOrMakeRegion(wxString name);
233     gcTraitInfo &   FetchOrMakeTrait(wxString name);
234 
235     gcTraitAllele & MakeAllele(wxString name);
236     gcRegion &      MakeRegion(wxString name=wxEmptyString,bool blessed=false);
237     gcLocus &       MakeLocus(size_t regionId, wxString name, bool blessed, const gcCreationInfo&);
238     gcLocus &       MakeLocus(gcRegion &, wxString name, bool blessed, const gcCreationInfo&);
239     gcPhenotype &   MakePhenotype(wxString name=wxEmptyString);
240     gcPopulation &  MakePop(wxString name=wxEmptyString, bool blessed=false);
241     gcTraitInfo &   MakeTrait(wxString name);
242     gcPanel &       MakePanel(wxString name, bool blessed, size_t m_regionId, size_t m_popId);
243     gcParent &      MakeParent(wxString name);
244     gcMigration &   MakeMigration(bool blessed, size_t m_fromId, size_t m_toId);
245 
246     gcPanel & CreatePanel(size_t m_regionId, size_t m_popId);
247 
248     void Rename(GCQuantum & object, wxString newName);
249 
250     bool RegionHasAnyLinkedLoci(size_t regionId) const;
251     bool RegionHasAnyUnLinkedLoci(size_t regionId) const;
252 
253     void FragmentRegion(size_t regionId);
254     void LocusToOwnRegion(size_t locusId);
255 
256     void MergeLoci(gcIdVec locusIds);
257     void MergePops(gcIdVec popIds);
258     void MergeRegions(gcIdVec regionIds);
259     //void MergePanels(gcIdVec panelIds);
260 
261     void RemoveBlocks(gcIdSet blockIds);
262     void RemoveBlocksForLocus(size_t locusId);
263     void RemoveBlocksForPop(size_t popId);
264     void RemoveRegion(gcRegion & region);
265     void RemoveLocus(gcLocus & locus);
266     void RemovePop(gcPopulation & pop);
267     void RemoveRegions(objVector regions);
268     void RemoveLoci(objVector loci);
269     void RemovePops(objVector pops);
270     void RemoveFile(size_t fileId);
271     void RemovePanel(size_t regionId, size_t popId);
272     void RemoveParent(size_t parentId);
273     void RemoveParents();
274     void RemoveMigration(size_t fromId, size_t toId);
275 
276     bool    GetFileSelection(size_t fileId) const;
277     void    SetFileSelection(size_t fileId, bool selected);
278     size_t  SelectedFileCount() const;
279     void    AllFileSelectionsTo(bool selectValue);
280 
281     void AddFile(const GCFile &);
282     bool HasUnparsedFiles() const;
283 
284     void SetParse(const GCParse & parse);
285     void UnsetParse(const GCParse & parse);
286 
287     bool            HasParse(const GCFile &) const;
288     const GCParse & GetParse(const GCFile &) const;
289     const GCParse & GetParse(size_t fileId ) const;
290 
291     void    SetHapFileAdjacent( size_t fileId, size_t numHaps);
292     bool    HasHapFileAdjacent(size_t fileId) const;
293     size_t  GetHapFileAdjacent(size_t fileId) const;
294     void    UnsetHapFileAdjacent(size_t fileId);
295 
296     bool    HasGenoFile(size_t fileId) const;
297     void    UnsetGenoFile(size_t fileId);
298 
299     void    VerifyLocusSeparations(const gcRegion&) const;    // throws if not separated
300 
301     int GetPopCount();
302     int GetPopCount() const;
303 
304     int GetParentCount();
305     int GetParentCount() const;
306 
307     bool IsPop(size_t id);
308     bool IsPop(size_t id) const;
309     bool IsPop(wxString name);
310     bool IsPop(wxString name) const;
311 
312     bool IsParent(size_t id);
313     bool IsParent(size_t id) const;
314 
315     int GetUnusedPopCount();
316     int GetUnusedPopCount() const;
317 
318     int GetUnusedParentCount();
319     int GetUnusedParentCount() const;
320 
321     void ClearPopDisplayOrder();
322 
323     size_t FindTopParent();
324 
325     void MakeMigrationMatrix();
326 };
327 
328 #endif  // GC_STRUCTURES_H
329 
330 //____________________________________________________________________________________
331