void NxsTransposeCompressedMatrix( const std::vector<NxsCharacterPattern> & compressedTransposedMatrix, ScopedTwoDMatrix<NxsCDiscreteStateSet> & destination, std::vector<unsigned> * patternCounts, std::vector<double> * patternWeights) { const unsigned npatterns = (unsigned const)compressedTransposedMatrix.size(); if (npatterns == 0) { destination.Initialize(0, 0); return; } const unsigned ntaxa = (unsigned const)compressedTransposedMatrix[0].stateCodes.size(); destination.Initialize(ntaxa, npatterns); NxsCDiscreteStateSet ** matrix = destination.GetAlias(); /** taxa x characters matrix of indices of state sets */ if (patternCounts) patternCounts->resize(npatterns); if (patternWeights) patternWeights->resize(npatterns); for (unsigned p = 0; p < npatterns; ++p) { const NxsCharacterPattern & pattern = compressedTransposedMatrix[p]; const std::vector<NxsCDiscreteState_t> & states = pattern.stateCodes; for (unsigned t = 0; t < ntaxa; ++t) matrix[t][p] = states[t]; if (patternCounts) (*patternCounts)[p] = pattern.count; if (patternWeights) (*patternWeights)[p] = pattern.sumOfPatternWeights; } }
int processContent(PublicNexusReader & nexusReader, const char *gFilename, std::ostream *os, INIReader & iniReader) { BlockReaderList blocks = nexusReader.GetUsedBlocksInOrder(); if (blocks.size() == 0) { cerr << "Error:\n No understandable content was found.\n"; exit(1); } const unsigned numTaxaBlocks = nexusReader.GetNumTaxaBlocks(); if (numTaxaBlocks != 1) { std::cerr << "Expecting a file with exactly 1 TAXA block, but found " << numTaxaBlocks << " in the file " << gFilename << ".\n"; return 2; } NxsTaxaBlock * taxaBlock = nexusReader.GetTaxaBlock(0); const unsigned nCharBlocks = nexusReader.GetNumCharactersBlocks(taxaBlock); if (nCharBlocks != 1) { std::cerr << "Expecting a file with exactly 1 CHARACTERS/DATA block, but found " << nCharBlocks << " in the file " << gFilename << ".\n"; return 3; } const unsigned nTreesBlocks = nexusReader.GetNumTreesBlocks(taxaBlock); if (nTreesBlocks != 1) { std::cerr << "Expecting a file with exactly 1 TREES block, but found " << nTreesBlocks << " in the file " << gFilename << ".\n"; return 3; } const NxsCharactersBlock * charBlock = nexusReader.GetCharactersBlock(taxaBlock, 0); std::vector<const NxsDiscreteDatatypeMapper *> mappers = charBlock->GetAllDatatypeMappers(); if (mappers.size() != 1) { std::cerr << "Expecting an unmixed characters block, but found a matrix with datatype = mixed or a datatype with augmented symbols\n"; return 4; } const NxsDiscreteDatatypeMapper * dm = mappers[0]; ScopedTwoDMatrix<NxsCDiscreteStateSet> compressedMatrix; std::vector<unsigned> patternCounts; std::vector<double> patternWeights; bool hasWeights = true; std::vector<NxsCharacterPattern> compressedTransposedMatrix; std::vector<std::set<unsigned> > compressedIndexToOriginal; std::vector<int> originalIndexToCompressed; if (true) { if (true) { NxsCXXDiscreteMatrix cxxMat(*charBlock, false, 0L, false); hasWeights = cxxMat.hasWeights(); NxsCompressDiscreteMatrix(cxxMat, compressedTransposedMatrix, &originalIndexToCompressed, &compressedIndexToOriginal); } std::vector<double> * wtsPtr = (hasWeights ? &patternWeights : 0L); NxsTransposeCompressedMatrix(compressedTransposedMatrix, compressedMatrix, &patternCounts, wtsPtr); patternWeights.clear(); for (auto i : patternCounts) { patternWeights.push_back(double(i)); } } _DEBUG_VEC(patternWeights); NxsCDiscreteStateSet ** matrixAlias = compressedMatrix.GetAlias(); const unsigned ntaxTotal = charBlock->GetNTaxTotal(); const NxsTreesBlock * treesBlock = nexusReader.GetTreesBlock(taxaBlock, 0); //mt::ModelDescription md(mt::ModelDescription::VAR_ONLY_NO_MISSING_ASC_BIAS); //@TODO should be run-time setting mt::ModelDescription md(mt::ModelDescription::NO_ASC_BIAS); //@TODO should be run-time setting mt::NCL2MT ncl2mt; for (unsigned nti = 0; nti < treesBlock->GetNumTrees(); ++nti) { const NxsSimpleTree nst(treesBlock->GetFullTreeDescription(nti), 1, 0.1, true); ncl2mt.processTree(os, ntaxTotal, charBlock, dm, (const NxsCDiscreteStateSet **) matrixAlias, patternWeights, originalIndexToCompressed, nst, md, iniReader); } return 0; }