/usr/include/ncl/nxsunalignedblock.h is in libncl-dev 2.1.18+dfsg-2build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | // Copyright (C) 2007 Paul O. Lewis
//
// This file is part of NCL (Nexus Class Library) version 2.0.
//
// NCL is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// NCL is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with NCL; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
#ifndef NCL_NXSUNALIGNEDBLOCK_H
#define NCL_NXSUNALIGNEDBLOCK_H
#include "ncl/nxsdefs.h"
#include "ncl/nxstaxablock.h"
#include "ncl/nxscharactersblock.h"
//@POL Note: This file is not yet ready for use (Paul Lewis, 19-May-2007)
class NxsTaxaBlockAPI;
/*!
This class handles reading and storage for the NEXUS block UNALIGNED. It overrides the member functions Read and
Reset, which are abstract virtual functions in the base class NxsBlock.
>
Below is a table showing the correspondence between the elements of an UNALIGNED block in a NEXUS file and the
variables and member functions of the NxsUnalignedBlock class that can be used to access each piece of information
stored. Items in parenthesis should be viewed as "see also" items.
>
NEXUS Command Data Member
Command Atribute Member Functions
---------------------------------------------------------------------
DIMENSIONS NEWTAXA newtaxa
NTAX ntax GetNTax
FORMAT DATATYPE datatype GetDataType
RESPECTCASE respectingCase IsRespectCase
MISSING missing GetMissingSymbol
SYMBOLS symbols GetSymbols
EQUATE equates GetEquateKey
GetEquateValue
GetNumEquates
(NO)LABELS labels IsLabels
TAXLABELS taxonLabels GetTaxonLabels
MATRIX matrix GetState
GetInternalRepresentation
GetNumStates
GetNumMatrixRows
IsPolymorphic
>
*/
class NxsUnalignedBlock
: public NxsBlock, public NxsTaxaBlockSurrogate
{
public:
class NxsX_NoDataForTaxon
{
public:
NxsX_NoDataForTaxon(unsigned i) : taxon_index(i) {}
unsigned taxon_index;
}; /* thrown if a function is called with an index to a taxon for which no data is stored */
NxsUnalignedBlock(NxsTaxaBlockAPI * tb);
virtual ~NxsUnalignedBlock();
void ShowStateLabels(std::ostream & out, NxsDiscreteDatum s);
NxsCharactersBlock::DataTypesEnum GetDataType() const ;
NxsCharactersBlock::DataTypesEnum GetOriginalDataType() const ;
const NxsDiscreteStateRow * GetDiscreteMatrixRow(unsigned taxInd) const
{
if (taxInd >= uMatrix.size())
return NULL;
return &uMatrix[taxInd];
}
NxsDiscreteStateRow GetInternalRepresentation(unsigned i, unsigned j);
unsigned GetNTaxWithData();
unsigned GetNTaxTotal();
unsigned GetNTaxTotal() const;
unsigned GetNumEquates();
unsigned GetNumMatrixRows();
unsigned GetNumStates(unsigned i, unsigned j);
unsigned NumCharsForTaxon(unsigned i);
char GetMissingSymbol();
bool IsLabels();
bool IsMissingState(unsigned i, unsigned j);
bool IsPolymorphic(unsigned i, unsigned j);
bool IsRespectCase();
unsigned GetStateSymbolIndex(unsigned i, unsigned j, unsigned k = 0); // added by mth for standard data types
const char * GetSymbols();
virtual void DebugShowMatrix(std::ostream & out, const char * marginText = NULL) NCL_COULD_BE_CONST ; /*v2.1to2.2 1 */
virtual void Report(std::ostream & out) NCL_COULD_BE_CONST ; /*v2.1to2.2 1 */
virtual void Reset();
void SetNexus(NxsReader *nxsptr)
{
NxsBlock::SetNexus(nxsptr);
NxsTaxaBlockSurrogate::SetNexusReader(nxsptr);
}
virtual const std::string & GetBlockName() const
{
return NCL_BLOCKTYPE_ATTR_NAME;
}
void WriteAsNexus(std::ostream & out) const;
void WriteFormatCommand(std::ostream & out) const;
void WriteMatrixCommand(std::ostream & out) const;
const char * GetDatatypeName() const
{
return NxsCharactersBlock::GetNameOfDatatype(datatype);
}
virtual VecBlockPtr GetImpliedBlocks()
{
return GetCreatedTaxaBlocks();
}
/*only used it the linkAPI is enabled*/
virtual void HandleLinkCommand(NxsToken & token)
{
HandleLinkTaxaCommand(token);
}
virtual void WriteLinkCommand(std::ostream &out) const
{
WriteLinkTaxaCommand(out);
}
/*---------------------------------------------------------------------------------------
| Results in aliasing of the taxa, assumptionsBlock blocks!
*/
NxsUnalignedBlock & operator=(const NxsUnalignedBlock &other)
{
Reset();
CopyBaseBlockContents(static_cast<const NxsBlock &>(other));
CopyTaxaBlockSurrogateContents(other);
CopyUnalignedBlockContents(other);
return *this;
}
/*---------------------------------------------------------------------------------------
| Results in aliasing of the taxa, assumptionsBlock blocks!
*/
virtual void CopyUnalignedBlockContents(const NxsUnalignedBlock &other)
{
nChar = other.nChar;
nTaxWithData = other.nTaxWithData;
matchchar = other.matchchar;
respectingCase = other.respectingCase;
transposing = other.transposing;
labels = other.labels;
missing = other.missing;
gap = other.gap;
symbols = other.symbols;
equates = other.equates;
mapper = other.mapper;
uMatrix = other.uMatrix;
datatype = other.datatype;
statesFormat = other.statesFormat;
}
virtual NxsUnalignedBlock * Clone() const
{
NxsUnalignedBlock * a = new NxsUnalignedBlock(taxa);
*a = *this;
return a;
}
bool SwapEquivalentTaxaBlock(NxsTaxaBlockAPI * tb)
{
return SurrogateSwapEquivalentTaxaBlock(tb);
}
std::string GetMatrixRowAsStr(const unsigned rowIndex) const;
protected:
bool IsInSymbols(char ch);
void HandleDimensions(NxsToken & token);
void HandleEndblock(NxsToken & token);
virtual void HandleFormat(NxsToken & token);
virtual void HandleMatrix(NxsToken & token);
virtual bool HandleNextState(NxsToken & token, unsigned taxInd, unsigned charInd, NxsDiscreteStateRow & new_row, const NxsString &);
virtual void Read(NxsToken & token);
void ResetSymbols();
std::string FormatState(NxsDiscreteDatum x) const;
void WriteStatesForMatrixRow(std::ostream &out, unsigned currTaxonIndex) const;
unsigned nChar; /* number of columns in matrix */
unsigned nTaxWithData; /* number of non empty rows in the matrix*/
char matchchar; /* match symbol to use in matrix */
bool respectingCase; /* if true, RESPECTCASE keyword specified in FORMAT command */
bool transposing; /* indicates matrix will be in transposed format */
bool labels; /* indicates whether or not labels will appear on left side of matrix */
char missing; /* missing data symbol */
char gap; /* gap symbol, will often be \0, but can be - */
std::string symbols; /* list of valid character state symbols */
std::map<char, NxsString> equates; /* list of associations defined by EQUATE attribute of FORMAT command */
NxsDiscreteDatatypeMapper mapper;
NxsDiscreteStateMatrix uMatrix; /* storage for unaligned data */
private:
NxsCharactersBlock::DataTypesEnum datatype; /* flag variable (see datatypes enum) */
NxsCharactersBlock::DataTypesEnum originalDatatype; /* flag variable (see datatypes enum) */
NxsCharactersBlock::StatesFormatEnum statesFormat;
NxsDiscreteStateCell GetStateIndex(unsigned i, unsigned j, unsigned k);
void ResetDatatypeMapper();
bool TaxonIndHasData(const unsigned ind) const;
friend class PublicNexusReader;
friend class MultiFormatReader;
};
class NxsUnalignedBlockFactory
:public NxsBlockFactory
{
public:
virtual NxsUnalignedBlock *GetBlockReaderForID(const std::string & NCL_BLOCKTYPE_ATTR_NAME, NxsReader *reader, NxsToken *token);
};
/*!
Returns datatype listed in the CHARACTERS block.
The original datatype can differ from the current datatype if the symbols list of a built in type was augmented
(thus converting it to standard).
*/
inline NxsCharactersBlock::DataTypesEnum NxsUnalignedBlock::GetOriginalDataType() const
{
return originalDatatype;
}
/*!
Returns value of `datatype' as an unsigned integer. If you want the name of the datatype, you should call
NxsUnalignedBlock::GetDatatypeName instead.
*/
inline NxsCharactersBlock::DataTypesEnum NxsUnalignedBlock::GetDataType() const
{
return datatype;
}
/*!
Returns the missing data symbol currently in effect. If no missing data symbol specified, returns '\0'.
*/
inline char NxsUnalignedBlock::GetMissingSymbol()
{
return missing;
}
/*!
Returns the number of taxa that have data (or will have data according to the Dimensions command, if the matrix
has not been read.
*/
inline unsigned NxsUnalignedBlock::GetNTaxWithData()
{
return nTaxWithData;
}
/*!
Returns the number of taxa in the taxa block associated with the unaligned block.
*/
inline unsigned NxsUnalignedBlock::GetNTaxTotal()
{
return (unsigned)uMatrix.size();
}
/*!
Returns the number of taxa in the taxa block associated with the unaligned block.
*/
inline unsigned NxsUnalignedBlock::GetNTaxTotal() const
{
return (unsigned)uMatrix.size();
}
/*!
Returns the number of stored equate associations.
*/
inline unsigned NxsUnalignedBlock::GetNumEquates()
{
return (unsigned)equates.size();
}
/*!
Returns the number of actual rows in `matrix'. This number is equal to `ntax', and hence this function is identical
to GetNTax. Note that `ntax' can be smaller than `ntaxTotal' since the user did not have to provide data for all
taxa specified in the TAXA block.
*/
inline unsigned NxsUnalignedBlock::GetNumMatrixRows()
{
return (unsigned)uMatrix.size();
}
/*!
Returns data member `symbols'. Warning: returned value may be NULL.
*/
inline const char * NxsUnalignedBlock::GetSymbols()
{
return symbols.c_str();
}
/*!
Returns true if LABELS was specified in the FORMAT command, false otherwise.
*/
inline bool NxsUnalignedBlock::IsLabels()
{
return labels;
}
/*!
Returns true if RESPECTCASE was specified in the FORMAT command, false otherwise.
*/
inline bool NxsUnalignedBlock::IsRespectCase()
{
return respectingCase;
}
#endif
|