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
|
/***************************************************************************
* Copyright (C) 2018 by BUI Quang Minh *
* m.bui@anu.edu.au *
* *
* 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 "superalignmentunlinked.h"
#include "utils/timeutil.h"
/** constructor initialize from a supertree */
SuperAlignmentUnlinked::SuperAlignmentUnlinked(Params ¶ms)
: SuperAlignment()
{
readFromParams(params);
init();
}
/** constructor initialize empty alignment */
SuperAlignmentUnlinked::SuperAlignmentUnlinked()
: SuperAlignment()
{
unlinked_taxa = true;
}
void SuperAlignmentUnlinked::init(StrVector *sequence_names) {
// start original code
max_num_states = 0;
// first build taxa_index and partitions
int part, seq, npart = partitions.size();
map<string, int> name2part;
vector<Alignment*>::iterator it;
unlinked_taxa = true;
for (it = partitions.begin(); it != partitions.end(); it++) {
// Make sure that all partitions have different seq names
for (auto sit = (*it)->seq_names.begin(); sit != (*it)->seq_names.end(); sit++) {
if (name2part.find(*sit) != name2part.end()) {
unlinked_taxa = false;
break;
}
name2part[*sit] = (it) - partitions.begin();
}
}
if (!unlinked_taxa) {
// if some taxon sets are overlapping
SuperAlignment::init(sequence_names);
cout << "Linked " << seq_names.size() << " total sequences" << endl;
return;
}
for (it = partitions.begin(); it != partitions.end(); it++) {
seq_names.insert(seq_names.end(), (*it)->seq_names.begin(), (*it)->seq_names.end());
}
cout << "Unlinked " << seq_names.size() << " total sequences" << endl;
/*
taxa_index.resize(total_seqs, IntVector(npart, -1));
for (it = partitions.begin(), part = 0, seq = 0; it != partitions.end(); it++, part++) {
int part_nseq = (*it)->getNSeq();
for (int part_seq = 0; part_seq < part_nseq; part_seq++, seq++) {
taxa_index[seq][part] = part_seq;
}
}
ASSERT(seq == total_seqs);
*/
// now the patterns of sequence-genes presence/absence
buildPattern();
}
void SuperAlignmentUnlinked::buildPattern() {
if (!unlinked_taxa) {
SuperAlignment::buildPattern();
return;
}
int part, seq, npart = partitions.size();
seq_type = SEQ_BINARY;
num_states = 2; // binary type because the super alignment presents the presence/absence of taxa in the partitions
STATE_UNKNOWN = 2;
site_pattern.resize(npart, -1);
clear();
pattern_index.clear();
/*
VerboseMode save_mode = verbose_mode;
verbose_mode = min(verbose_mode, VB_MIN); // to avoid printing gappy sites in addPattern
int nseq = getNSeq();
int start_seq = 0;
resize(npart, Pattern(nseq));
for (part = 0; part < npart; part++) {
Pattern *pat = &at(part);
for (seq = 0; seq < partitions[part]->getNSeq(); seq++)
pat->at(start_seq + seq) = 1;
//addPattern(pat, part);
computeConst(*pat);
// NOT USED FOR TOPO_UNLINKED
//pattern_index[*pat] = part;
site_pattern[part] = part;
start_seq += partitions[part]->getNSeq();
}
ASSERT(start_seq == nseq);
verbose_mode = save_mode;
*/
resize(1, Pattern(getNSeq(), npart));
computeConst(at(0));
for (part = 0; part < npart; part++) {
site_pattern[part] = 0;
}
countConstSite();
// buildSeqStates();
}
void SuperAlignmentUnlinked::computeConst(Pattern &pat) {
if (!unlinked_taxa) {
SuperAlignment::computeConst(pat);
return;
}
bool is_const = (partitions.size() == 1);
bool is_invariant = (partitions.size() == 1);
bool is_informative = (partitions.size() > 1);
pat.const_char = (is_const) ? 1 : (STATE_UNKNOWN+1);
pat.num_chars = (is_const) ? 1 : 2; // number of states with >= 1 appearance
pat.flag = 0;
if (is_const) pat.flag |= PAT_CONST;
if (is_invariant) pat.flag |= PAT_INVARIANT;
if (is_informative) pat.flag |= PAT_INFORMATIVE;
}
/*
void SuperAlignmentUnlinked::buildSeqStates(bool add_unobs_const) {
if (!unlinked_taxa) {
SuperAlignment::buildSeqStates(add_unobs_const);
return;
}
seq_states.clear();
if (add_unobs_const) {
seq_states.resize(getNSeq(), IntVector({0,1}));
} else {
if (partitions.size() == 1)
seq_states.resize(getNSeq(), IntVector({1}));
else
seq_states.resize(getNSeq(), IntVector({0,1}));
}
}
*/
|