00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef NCL_ASSUMPTIONSBLOCK_H
00021 #define NCL_ASSUMPTIONSBLOCK_H
00022
00023 #include <vector>
00024
00025 #include "ncl/nxsdefs.h"
00026 #include "ncl/nxsblock.h"
00027 #include "ncl/nxstreesblock.h"
00028 #include "ncl/nxscharactersblock.h"
00029 #include "ncl/nxstaxablock.h"
00030
00031 class NxsCharactersBlockAPI;
00032 class NxsTaxaBlockAPI;
00033
00034 using std::vector;
00035
00036 class NxsAssumptionsBlockAPI
00037 : public NxsBlock
00038 {
00039 public:
00040 virtual void SetCallback(NxsCharactersBlockAPI *p) = 0;
00041
00042
00043
00044 virtual void SetCharBlockPtr(NxsCharactersBlockAPI * c, NxsBlockLinkStatus s) = 0;
00045 virtual void SetTaxaBlockPtr(NxsTaxaBlockAPI *, NxsBlockLinkStatus s) = 0;
00046 virtual void SetTreesBlockPtr(NxsTreesBlockAPI *, NxsBlockLinkStatus s) = 0;
00047
00048 virtual NxsCharactersBlockAPI * GetCharBlockPtr(int *status=NULL) = 0;
00049 virtual NxsTaxaBlockAPI * GetTaxaBlockPtr(int *status=NULL) = 0;
00050 virtual NxsTreesBlockAPI * GetTreesBlockPtr(int *status=NULL) = 0;
00051
00052
00053
00054
00055
00056 virtual void AddCharPartition(const std::string & name, const NxsPartition &) = 0;
00057 virtual void AddTaxPartition(const std::string & name, const NxsPartition &) = 0;
00058 virtual void AddTreePartition(const std::string & name, const NxsPartition &) = 0;
00059 virtual void AddCodeSet(const std::string & name, const NxsPartition &, bool asterisked) = 0;
00060 virtual void AddCodonPosSet(const std::string & name, const NxsPartition &, bool asterisked) = 0;
00061
00062 virtual void FlagCharBlockAsUsed() = 0;
00063 virtual void FlagTaxaBlockAsUsed() = 0;
00064 virtual void FlagTreesBlockAsUsed() = 0;
00065
00066 virtual void ReadCharsetDef(NxsString charset_name, NxsToken &token, bool asterisked) = 0;
00067 virtual void ReadExsetDef(NxsString charset_name, NxsToken &token, bool asterisked) = 0;
00068 virtual void ReadTaxsetDef(NxsString set_name, NxsToken &token, bool asterisked) = 0;
00069 virtual void ReadTreesetDef(NxsString set_name, NxsToken &token, bool asterisked) = 0;
00070
00071 virtual NxsTransformationManager & GetNxsTransformationManagerRef() = 0;
00072 virtual NxsGeneticCodesManager & GetNxsGeneticCodesManagerRef() = 0;
00073 virtual void SetGapsAsNewstate(bool v) = 0;
00074 };
00075
00088 class NxsAssumptionsBlock
00089 : public NxsAssumptionsBlockAPI
00090 {
00091 enum NameOfAssumpBlockAsRead
00092 {
00093 UNREAD_OR_GENERATED_BLOCK,
00094 ASSUMPTIONS_BLOCK_READ,
00095 SETS_BLOCK_READ,
00096 CODONS_BLOCK_READ
00097 };
00098
00099
00100 public:
00101 NxsAssumptionsBlock(NxsTaxaBlockAPI *t);
00102 virtual ~NxsAssumptionsBlock();
00103
00104 virtual bool CanReadBlockType(const NxsToken & token);
00105
00106 void ReplaceTaxaBlockPtr(NxsTaxaBlockAPI *tb);
00107 void SetCallback(NxsCharactersBlockAPI *p);
00108
00109 int GetNumCharSets() const;
00110
00111 void GetCharSetNames(NxsStringVector &names) const;
00112 const NxsUnsignedSet *GetCharSet(NxsString nm) const;
00113
00114 int GetNumCharPartitions();
00115 void GetCharPartitionNames(vector<std::string> &names);
00116 const NxsPartition *GetCharPartition(std::string nm) const;
00117
00118 int GetNumTaxSets();
00119 void GetTaxSetNames(NxsStringVector &names);
00120 NxsUnsignedSet & GetTaxSet(NxsString nm);
00121
00122 int GetNumExSets();
00123 void GetExSetNames(NxsStringVector &names);
00124 NxsUnsignedSet & GetExSet(NxsString nm);
00125 NxsString GetDefExSetName();
00126 void ApplyExset(NxsString nm);
00127
00128 virtual void Read(NxsToken& token);
00129 virtual void Report(std::ostream& out) NCL_COULD_BE_CONST ;
00130 virtual void Reset();
00131 virtual void WriteAsNexus(std::ostream &out) const;
00132
00133
00134 virtual void HandleLinkCommand(NxsToken & );
00135 virtual void WriteLinkCommand(std::ostream &out) const;
00136
00137 virtual VecBlockPtr GetImpliedBlocks()
00138 {
00139 return GetCreatedTaxaBlocks();
00140 }
00141
00142 int GetCharLinkStatus() {return charLinkStatus;}
00143 int GetTaxaLinkStatus() {return taxaLinkStatus;}
00144 int GetTreesLinkStatus() {return treesLinkStatus;}
00145
00146 void FlagCharBlockAsUsed() {charLinkStatus |= NxsBlock::BLOCK_LINK_USED;}
00147 void FlagTaxaBlockAsUsed() {taxaLinkStatus |= NxsBlock::BLOCK_LINK_USED;}
00148 void FlagTreesBlockAsUsed() {treesLinkStatus |= NxsBlock::BLOCK_LINK_USED;}
00149
00150 void SetCharLinkStatus(NxsBlockLinkStatus s);
00151 void SetTaxaLinkStatus(NxsBlockLinkStatus s);
00152 void SetTreesLinkStatus(NxsBlockLinkStatus s);
00153
00154 void SetCharBlockPtr(NxsCharactersBlockAPI * c, NxsBlockLinkStatus s);
00155 void SetTaxaBlockPtr(NxsTaxaBlockAPI *, NxsBlockLinkStatus s);
00156 void SetTreesBlockPtr(NxsTreesBlockAPI *, NxsBlockLinkStatus s);
00157 NxsCharactersBlockAPI * GetCharBlockPtr(int *status=NULL);
00158 NxsTaxaBlockAPI * GetTaxaBlockPtr(int *status=NULL);
00159 NxsTreesBlockAPI * GetTreesBlockPtr(int *status=NULL);
00160
00161 NxsTransformationManager & GetNxsTransformationManagerRef()
00162 {
00163 return transfMgr;
00164 }
00165 NxsGeneticCodesManager & GetNxsGeneticCodesManagerRef()
00166 {
00167 return codesMgr;
00168 }
00169 virtual void AddCharPartition(const std::string & name, const NxsPartition &);
00170 virtual void AddTaxPartition(const std::string & name, const NxsPartition &);
00171 virtual void AddTreePartition(const std::string & name, const NxsPartition &);
00172 virtual void AddCodeSet(const std::string & name, const NxsPartition &, bool asterisked);
00173 virtual void AddCodonPosSet(const std::string & name, const NxsPartition &, bool asterisked);
00174
00175
00176
00177
00178 NxsAssumptionsBlock &operator=(const NxsAssumptionsBlock &other)
00179 {
00180 CopyBaseBlockContents(static_cast<const NxsBlock &>(other));
00181 CopyAssumptionsContents(other);
00182 return *this;
00183 }
00184
00185
00186
00187
00188
00189
00190
00191 virtual void CopyAssumptionsContents(const NxsAssumptionsBlock &other)
00192 {
00193 taxa = other.taxa;
00194 charBlockPtr = other.charBlockPtr;
00195 treesBlockPtr = other.treesBlockPtr;
00196 charsets = other.charsets;
00197 taxsets = other.taxsets;
00198 treesets = other.treesets;
00199 exsets = other.exsets;
00200 charPartitions = other.charPartitions;
00201 taxPartitions = other.taxPartitions;
00202 treePartitions = other.treePartitions;
00203 def_exset = other.def_exset;
00204 charLinkStatus = other.charLinkStatus;
00205 taxaLinkStatus = other.taxaLinkStatus;
00206 treesLinkStatus = other.treesLinkStatus;
00207 passedRefOfOwnedBlock = true;
00208 readAs = other.readAs;
00209 transfMgr = other.transfMgr;
00210 codesMgr = other.codesMgr;
00211 createdSubBlocks = other.createdSubBlocks;
00212 polyTCountValue = other.polyTCountValue;
00213 gapsAsNewstate = other.gapsAsNewstate;
00214 codonPosSets = other.codonPosSets;
00215 def_codonPosSet = other.def_codonPosSet;
00216 codeSets = other.codeSets;
00217 def_codeSet = other.def_codeSet;
00218 }
00219
00220 virtual NxsAssumptionsBlock * Clone() const
00221 {
00222 NxsAssumptionsBlock * a = new NxsAssumptionsBlock(taxa);
00223 *a = *this;
00224 return a;
00225 }
00226 virtual void SetGapsAsNewstate(bool v)
00227 {
00228 gapsAsNewstate = v;
00229 }
00230
00231
00232 protected:
00233 typedef std::vector<NxsAssumptionsBlockAPI *> VecAssumpBlockPtr;
00234
00235 virtual void ReadCharsetDef(NxsString charset_name, NxsToken &token, bool asterisked);
00236 virtual void ReadExsetDef(NxsString charset_name, NxsToken &token, bool asterisked);
00237 virtual void ReadTreesetDef(NxsString set_name, NxsToken &token, bool asterisked);
00238 virtual void ReadTaxsetDef(NxsString set_name, NxsToken &token, bool asterisked);
00239
00240
00241 VecBlockPtr GetCreatedTaxaBlocks();
00242 virtual unsigned TaxonLabelToNumber(NxsString s) const;
00243
00244 void HandleCharPartition(NxsToken& token);
00245 void HandleCharSet(NxsToken& token);
00246 void HandleCodeSet(NxsToken& token);
00247 void HandleCodonPosSet(NxsToken& token);
00248 void HandleExSet(NxsToken& token);
00249 void HandleOptions(NxsToken & token);
00250 void HandleTaxPartition(NxsToken& token);
00251 void HandleTaxSet(NxsToken& token);
00252 void HandleTreePartition(NxsToken& token);
00253 void HandleTreeSet(NxsToken& token);
00254 void HandleTypeSet(NxsToken& token);
00255 void HandleUserType(NxsToken& token);
00256 void HandleWeightSet(NxsToken& token);
00257
00258 void WriteCharSet(std::ostream &out) const
00259 {
00260 NxsWriteSetCommand("CHARSET", charsets, out);
00261 }
00262 void WriteCharPartition(std::ostream &out) const
00263 {
00264 NxsWritePartitionCommand("CharPartition", charPartitions, out);
00265 }
00266 void WriteExSet(std::ostream &out) const
00267 {
00268 NxsWriteSetCommand("EXSET", exsets, out, def_exset.c_str());
00269 }
00270 void WriteOptions(std::ostream &out) const;
00271 void WriteTaxPartition(std::ostream &out) const
00272 {
00273 NxsWritePartitionCommand("TaxPartition", taxPartitions, out);
00274 }
00275 void WriteTaxSet(std::ostream &out) const
00276 {
00277 NxsWriteSetCommand("TAXSET", taxsets, out);
00278 }
00279 void WriteTreePartition(std::ostream &out) const
00280 {
00281 NxsWritePartitionCommand("TreePartition", treePartitions, out);
00282 }
00283 void WriteTreeSet(std::ostream &out) const
00284 {
00285 NxsWriteSetCommand("TREESET", treesets, out);
00286 }
00287 void WriteCodeSet(std::ostream &out) const
00288 {
00289 NxsWritePartitionCommand("CodeSet", codeSets, out, def_codeSet.c_str());
00290 }
00291 void WriteCodonPosSet(std::ostream &out) const
00292 {
00293 NxsWritePartitionCommand("CodonPosSet", codonPosSets, out, def_codonPosSet.c_str());
00294 }
00295 NameOfAssumpBlockAsRead GetIDOfBlockTypeIDFromParse() const
00296 {
00297 return readAs;
00298 }
00299 private:
00300 NxsAssumptionsBlockAPI *GetAssumptionsBlockForCharTitle(const char *title, NxsToken &token, const char *cmd);
00301 NxsAssumptionsBlockAPI *GetAssumptionsBlockForTaxaTitle(const char *title, NxsToken &token, const char *cmd);
00302 NxsAssumptionsBlockAPI *GetAssumptionsBlockForTreesTitle(const char *title, NxsToken &token, const char *cmd);
00303
00304 NxsAssumptionsBlockAPI *GetAssumptionsBlockForCharBlock(NxsCharactersBlockAPI *, NxsBlockLinkStatus, NxsToken &token);
00305 NxsAssumptionsBlockAPI *GetAssumptionsBlockForTaxaBlock(NxsTaxaBlockAPI *, NxsBlockLinkStatus, NxsToken &token);
00306 NxsAssumptionsBlockAPI *GetAssumptionsBlockForTreesBlock(NxsTreesBlockAPI *, NxsBlockLinkStatus, NxsToken &token);
00307
00308 NxsAssumptionsBlockAPI *CreateNewAssumptionsBlock(NxsToken &token);
00309 NxsAssumptionsBlockAPI *DealWithPossibleParensInCharDependentCmd(NxsToken &token, const char *cmd, const std::vector<std::string> *unsupported = NULL, bool * isVect = false);
00310 bool HasAssumptionsBlockCommands() const;
00311 bool HasSetsBlockCommands() const;
00312 bool HasCodonsBlockCommands() const;
00313
00314
00315 NxsTaxaBlockAPI *taxa;
00316 NxsCharactersBlockAPI *charBlockPtr;
00317 NxsTreesBlockAPI *treesBlockPtr;
00318
00319
00320
00321 NxsUnsignedSetMap charsets;
00322 NxsUnsignedSetMap taxsets;
00323 NxsUnsignedSetMap treesets;
00324 NxsUnsignedSetMap exsets;
00325
00326 NxsPartitionsByName charPartitions;
00327 NxsPartitionsByName taxPartitions;
00328 NxsPartitionsByName treePartitions;
00329
00330 NxsString def_exset;
00331
00332 NxsPartitionsByName codonPosSets;
00333 NxsString def_codonPosSet;
00334 NxsPartitionsByName codeSets;
00335 NxsString def_codeSet;
00336
00337 int charLinkStatus;
00338 int taxaLinkStatus;
00339 int treesLinkStatus;
00340 bool passedRefOfOwnedBlock;
00341 NameOfAssumpBlockAsRead readAs;
00342 NxsTransformationManager transfMgr;
00343 NxsGeneticCodesManager codesMgr;
00344
00345 std::vector<NxsAssumptionsBlockAPI *> createdSubBlocks;
00346 enum PolyTCountValue
00347 {
00348 POLY_T_COUNT_UNKNOWN,
00349 POLY_T_COUNT_MIN,
00350 POLY_T_COUNT_MAX
00351 };
00352 PolyTCountValue polyTCountValue;
00353 bool gapsAsNewstate;
00354
00355 friend class NxsAssumptionsBlockFactory;
00356 friend class PublicNexusReader;
00357 };
00358
00359 class NxsAssumptionsBlockFactory
00360 :public NxsBlockFactory
00361 {
00362 public:
00363 virtual NxsAssumptionsBlock * GetBlockReaderForID(const std::string & id, NxsReader *reader, NxsToken *token);
00364 };
00365
00366 typedef NxsAssumptionsBlock AssumptionsBlock;
00367
00368 #endif
00369