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
|
/***************************************************************************
* Copyright (C) 2006 by BUI Quang Minh, Steffen Klaere, Arndt von Haeseler *
* minh.bui@univie.ac.at *
* *
* This program 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. *
* *
* This program 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 this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "pdtreeset.h"
PDTreeSet::PDTreeSet()
: MTreeSet()
{
}
PDTreeSet::PDTreeSet(Params ¶ms) {
init(params);
}
void PDTreeSet::init(Params ¶ms) {
MTreeSet::init(params.user_file, params.is_rooted, params.tree_burnin, params.tree_max_count);
if (isRootedTrees()) {
params.sub_size++;
params.min_size++;
}
if (isRootedTrees() && params.root != NULL) {
outError(ERR_CONFLICT_ROOT);
}
if (params.sub_size > getNTaxa()) {
ostringstream err;
err << "Subset size k = " << params.sub_size - params.is_rooted <<
" is greater than the number of taxa = " << getNTaxa() - params.is_rooted;
outError(err.str());
}
if (isRootedTrees()) {
char *rname = (char*)ROOT_NAME;
readRootNode(rname);
}
// read the parameter file
if (params.param_file != NULL) {
readParams(params);
}
// identify the root
if (params.root != NULL)
readRootNode(params.root);
// read the initial set of taxa, incoporate info into the split system
if (params.initial_file != NULL) {
readInitialSet(params);
}
}
bool PDTreeSet::isRootedTrees() {
ASSERT(size() > 0);
return front()->rooted;
}
int PDTreeSet::getNTaxa() {
ASSERT(size() > 0);
return front()->leafNum;
}
void PDTreeSet::readRootNode(const char *root_name) {
string name = root_name;
init_taxa.push_back(name);
for (iterator it = begin(); it != end(); it++)
((PDTree*)(*it))->readRootNode(root_name);
}
void PDTreeSet::readParams(Params ¶ms) {
int ntaxa = getNTaxa() - params.is_rooted;
// read parameters from file
double scale;
StrVector tax_name;
DoubleVector ori_weight;
readWeightFile(params, ntaxa, scale, tax_name, ori_weight);
for (iterator it = begin(); it != end(); it++) {
// now convert the weights
PDTree *mytree = (PDTree*)(*it);
LeafMapName lsn;
mytree->buildLeafMapName(lsn);
DoubleVector tax_weight;
tax_weight.resize(ntaxa, 0);
for (int i = 0; i < tax_name.size(); i++) {
LeafMapName::iterator nameit = lsn.find(tax_name[i]);
if (nameit == lsn.end())
outError(ERR_NO_TAXON, tax_name[i]);
tax_weight[(*nameit).second->id] = ori_weight[i];
}
// incoporate them into the tree
mytree->incoporateParams(scale, tax_weight);
}
}
/**
read the initial set of taxa to be included into PD-tree
*/
void PDTreeSet::readInitialSet(Params ¶ms) {
int ntaxa = getNTaxa() - params.is_rooted;
StrVector tax_name;
readInitTaxaFile(params, ntaxa, tax_name);
init_taxa.insert(init_taxa.end(), tax_name.begin(), tax_name.end());
for (iterator itree = begin(); itree != end(); itree++) {
PDTree *mytree = (PDTree*)(*itree);
LeafMapName lsn;
mytree->buildLeafMapName(lsn);
for (StrVector::iterator it = tax_name.begin(); it != tax_name.end(); it++) {
LeafMapName::iterator nameit = lsn.find((*it));
if (nameit == lsn.end()) {
outError(ERR_NO_TAXON, *it);
}
mytree->initialset.push_back((*nameit).second);
}
}
}
|