00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef NCL_NXSUNALIGNEDBLOCK_H
00021 #define NCL_NXSUNALIGNEDBLOCK_H
00022
00023 #include "ncl/nxsdefs.h"
00024 #include "ncl/nxstaxablock.h"
00025 #include "ncl/nxscharactersblock.h"
00026
00027
00028 class NxsTaxaBlockAPI;
00029
00068 class NxsUnalignedBlock
00069 : public NxsBlock, public NxsTaxaBlockSurrogate
00070 {
00071 public:
00072
00073 class NxsX_NoDataForTaxon
00074 {
00075 public:
00076 NxsX_NoDataForTaxon(unsigned i) : taxon_index(i) {}
00077 unsigned taxon_index;
00078 };
00079
00080 NxsUnalignedBlock(NxsTaxaBlockAPI * tb);
00081 virtual ~NxsUnalignedBlock();
00082
00083 void ShowStateLabels(std::ostream & out, NxsDiscreteDatum s);
00084 NxsCharactersBlock::DataTypesEnum GetDataType() const ;
00085 NxsCharactersBlock::DataTypesEnum GetOriginalDataType() const ;
00086 const NxsDiscreteStateRow * GetDiscreteMatrixRow(unsigned taxInd) const
00087 {
00088 if (taxInd >= uMatrix.size())
00089 return NULL;
00090 return &uMatrix[taxInd];
00091 }
00092 NxsDiscreteStateRow GetInternalRepresentation(unsigned i, unsigned j);
00093 unsigned GetNTaxWithData();
00094 unsigned GetNTaxTotal();
00095 unsigned GetNTaxTotal() const;
00096 unsigned GetNumEquates();
00097 unsigned GetNumMatrixRows();
00098 unsigned GetNumStates(unsigned i, unsigned j);
00099 unsigned NumCharsForTaxon(unsigned i);
00100 char GetMissingSymbol();
00101 bool IsLabels();
00102 bool IsMissingState(unsigned i, unsigned j);
00103 bool IsPolymorphic(unsigned i, unsigned j);
00104 bool IsRespectCase();
00105 unsigned GetStateSymbolIndex(unsigned i, unsigned j, unsigned k = 0);
00106 const char * GetSymbols();
00107 virtual void DebugShowMatrix(std::ostream & out, const char * marginText = NULL) NCL_COULD_BE_CONST ;
00108 virtual void Report(std::ostream & out) NCL_COULD_BE_CONST ;
00109 virtual void Reset();
00110 void SetNexus(NxsReader *nxsptr)
00111 {
00112 NxsBlock::SetNexus(nxsptr);
00113 NxsTaxaBlockSurrogate::SetNexusReader(nxsptr);
00114 }
00115 virtual const std::string & GetBlockName() const
00116 {
00117 return id;
00118 }
00119
00120 void WriteAsNexus(std::ostream & out) const;
00121 void WriteFormatCommand(std::ostream & out) const;
00122 void WriteMatrixCommand(std::ostream & out) const;
00123 const char * GetDatatypeName() const
00124 {
00125 return NxsCharactersBlock::GetNameOfDatatype(datatype);
00126 }
00127
00128 virtual VecBlockPtr GetImpliedBlocks()
00129 {
00130 return GetCreatedTaxaBlocks();
00131 }
00132
00133
00134 virtual void HandleLinkCommand(NxsToken & token)
00135 {
00136 HandleLinkTaxaCommand(token);
00137 }
00138 virtual void WriteLinkCommand(std::ostream &out) const
00139 {
00140 WriteLinkTaxaCommand(out);
00141 }
00142
00143
00144
00145
00146 NxsUnalignedBlock & operator=(const NxsUnalignedBlock &other)
00147 {
00148 Reset();
00149 CopyBaseBlockContents(static_cast<const NxsBlock &>(other));
00150 CopyTaxaBlockSurrogateContents(other);
00151 CopyUnalignedBlockContents(other);
00152 return *this;
00153 }
00154
00155
00156
00157
00158 virtual void CopyUnalignedBlockContents(const NxsUnalignedBlock &other)
00159 {
00160 nChar = other.nChar;
00161 nTaxWithData = other.nTaxWithData;
00162 matchchar = other.matchchar;
00163 respectingCase = other.respectingCase;
00164 transposing = other.transposing;
00165 labels = other.labels;
00166 missing = other.missing;
00167 symbols = other.symbols;
00168 equates = other.equates;
00169 mapper = other.mapper;
00170 uMatrix = other.uMatrix;
00171 datatype = other.datatype;
00172 statesFormat = other.statesFormat;
00173 }
00174
00175 virtual NxsUnalignedBlock * Clone() const
00176 {
00177 NxsUnalignedBlock * a = new NxsUnalignedBlock(taxa);
00178 *a = *this;
00179 return a;
00180 }
00181 bool SwapEquivalentTaxaBlock(NxsTaxaBlockAPI * tb)
00182 {
00183 return SurrogateSwapEquivalentTaxaBlock(tb);
00184 }
00185
00186 protected:
00187 bool IsInSymbols(char ch);
00188 void HandleDimensions(NxsToken & token);
00189 void HandleEndblock(NxsToken & token);
00190 virtual void HandleFormat(NxsToken & token);
00191 virtual void HandleMatrix(NxsToken & token);
00192 virtual bool HandleNextState(NxsToken & token, unsigned taxInd, unsigned charInd, NxsDiscreteStateRow & new_row, const NxsString &);
00193 virtual void Read(NxsToken & token);
00194 void ResetSymbols();
00195 std::string FormatState(NxsDiscreteDatum x) const;
00196
00197 void WriteStatesForMatrixRow(std::ostream &out, unsigned currTaxonIndex) const;
00198
00199 unsigned nChar;
00200 unsigned nTaxWithData;
00201
00202 char matchchar;
00203 bool respectingCase;
00204 bool transposing;
00205 bool labels;
00206
00207 char missing;
00208
00209 std::string symbols;
00210 std::map<char, NxsString> equates;
00211
00212 NxsDiscreteDatatypeMapper mapper;
00213 NxsDiscreteStateMatrix uMatrix;
00214
00215 private:
00216 NxsCharactersBlock::DataTypesEnum datatype;
00217 NxsCharactersBlock::DataTypesEnum originalDatatype;
00218 NxsCharactersBlock::StatesFormatEnum statesFormat;
00219
00220 NxsDiscreteStateCell GetStateIndex(unsigned i, unsigned j, unsigned k);
00221 void ResetDatatypeMapper();
00222 bool TaxonIndHasData(const unsigned ind) const;
00223 friend class PublicNexusReader;
00224 friend class MultiFormatReader;
00225 };
00226
00227 class NxsUnalignedBlockFactory
00228 :public NxsBlockFactory
00229 {
00230 public:
00231 virtual NxsUnalignedBlock *GetBlockReaderForID(const std::string & id, NxsReader *reader, NxsToken *token);
00232 };
00233
00239 inline NxsCharactersBlock::DataTypesEnum NxsUnalignedBlock::GetOriginalDataType() const
00240 {
00241 return originalDatatype;
00242 }
00243
00244
00249 inline NxsCharactersBlock::DataTypesEnum NxsUnalignedBlock::GetDataType() const
00250 {
00251 return datatype;
00252 }
00253
00254
00258 inline char NxsUnalignedBlock::GetMissingSymbol()
00259 {
00260 return missing;
00261 }
00262
00267 inline unsigned NxsUnalignedBlock::GetNTaxWithData()
00268 {
00269 return nTaxWithData;
00270 }
00271
00275 inline unsigned NxsUnalignedBlock::GetNTaxTotal()
00276 {
00277 return (unsigned)uMatrix.size();
00278 }
00279
00283 inline unsigned NxsUnalignedBlock::GetNTaxTotal() const
00284 {
00285 return (unsigned)uMatrix.size();
00286 }
00287
00291 inline unsigned NxsUnalignedBlock::GetNumEquates()
00292 {
00293 return (unsigned)equates.size();
00294 }
00295
00301 inline unsigned NxsUnalignedBlock::GetNumMatrixRows()
00302 {
00303 return (unsigned)uMatrix.size();
00304 }
00305
00309 inline const char * NxsUnalignedBlock::GetSymbols()
00310 {
00311 return symbols.c_str();
00312 }
00313
00317 inline bool NxsUnalignedBlock::IsLabels()
00318 {
00319 return labels;
00320 }
00321
00325 inline bool NxsUnalignedBlock::IsRespectCase()
00326 {
00327 return respectingCase;
00328 }
00329
00330 #endif