File: split.h

package info (click to toggle)
iqtree 1.6.12%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 12,140 kB
  • sloc: cpp: 111,752; ansic: 53,619; python: 242; sh: 195; makefile: 52
file content (301 lines) | stat: -rw-r--r-- 6,825 bytes parent folder | download | duplicates (3)
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
/***************************************************************************
 *   Copyright (C) 2009-2015 by                                            *
 *   BUI Quang Minh <minh.bui@univie.ac.at>                                *
 *   Lam-Tung Nguyen <nltung@gmail.com>                                    *
 *                                                                         *
 *                                                                         *
 *   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.             *
 ***************************************************************************/
#ifndef SPLIT_H
#define SPLIT_H

#include <vector>
#include <string>
#include "utils/tools.h"
#include "nclextra/msplitsblock.h"

using namespace std;


const int UINT_BITS = sizeof(UINT) * 8;
const int BITS_DIV = (sizeof(int) == 2) ? 4 : ((sizeof(int)==4) ? 5 : 6);
const int BITS_MODULO = UINT_BITS-1;

/**
Defining a split, also a set of taxa.

@author BUI Quang Minh, Steffen Klaere, Arndt von Haeseler
*/
class Split : public vector<UINT>
{
public:

	friend class MSplitsBlock;
	friend class SplitGraph;
	friend class PDNetwork;
	friend class CircularNetwork;
	friend class PDTree;
    friend class MTreeSet;

	/**
		empty constructor
	*/
    Split();

	/**
		constructor
		@param antaxa number of taxa
		@param aweight weight of split
	*/
	Split(int antaxa, double aweight = 0.0);


	/**
		constructor copy from another split
		@param sp split to be copied from
	*/
	Split(const Split &sp);

	/**
		construct the split from a taxa list
		@param antaxa number of taxa
		@param aweight weight of split
		@param taxa_list list of taxa in one side of split
	*/
    Split(int antaxa, double aweight, vector<int> taxa_list);

	/**
		print infos of split graph
		@param out the output stream
	*/	
	void report(ostream &out);

	/**
		destructor
	*/
    ~Split();

	/**
		get number of taxa
		@return number of taxa
	*/
	inline int getNTaxa() const {
		return ntaxa;
	}

	/**
		get number of taxa being in the split
		@return number of taxa
	*/
	int countTaxa() const;

	/**
		copy from another split
	*/
	//void copy(Split &sp); 

	/**
		set number of taxa
		@param antaxa number of taxa
	*/
	void setNTaxa(int antaxa);

	/**
		get the first taxon in the set
		@return the first taxon or -1 if empty
	*/
	int firstTaxon();

	/**
		@return TRUE if the set is empty
	*/
	bool isEmpty();

	/**
		get weight
		@return weight
	*/
	inline double getWeight() const {
		return weight;
	}

	/**
		set weight
		@param aweight the new weight
	*/
	inline void setWeight(double aweight) {
		weight = aweight;
	}

	/**
		check whether the split should be inverted (number of taxa > ntaxa / 2)
		@return TRUE yes, should be inverted
	*/
	bool shouldInvert();

	/**
		invert the split (0->1, 1->0)
	*/
	void invert();

	/**
		@param sp the other split
		@return true if this split is compatible with sp
	*/
	bool compatible(Split &sp);

	/**	
		@param taxa_set set of taxa
		@return true if this split is preserved in the set taxa_set
	*/
	bool preserved(Split &taxa_set);

	/**
		if the split is trivial (contains 1 taxon in 1 side), return the taxon id, 
		otherwise return -1
		@return the taxon id if the split is trivial 
	*/
	int trivial();

	/**
		add a taxon into the split
		@param tax_id id of taxon from 0..ntaxa-1
	*/
	void addTaxon(int tax_id); 

	/**
		remove a taxon from the split
		@param tax_id id of taxon from 0..ntaxa-1
	*/
	void removeTaxon(int tax_id); 

	/**
		@param tax_id id of taxon from 0..ntaxa-1
		@return true if tax_id is in the set
	*/
	bool containTaxon(int tax_id); 

	/**
		@param tax_id vector of id of taxa from 0..ntaxa-1
		@return true if SOME taxon in tax_id is in the set
	*/
	bool containAny(IntVector &tax_id); 

	/**
		@param tax_id vector of id of taxa from 0..ntaxa-1
		@return true if ALL taxa in tax_id is in the set
	*/
	bool containAll(IntVector &tax_id); 

	/**
		get the list of taxa contained in split
		@param invec (OUT) taxa in this side of split
	*/
	void getTaxaList(vector<int> &invec);

	/**
		get the list of taxa contained in split and not contained in split
		@param invec (OUT) taxa in this side of split
		@param outvec (OUT) taxa on the other side
	*/
	void getTaxaList(vector<int> &invec, vector<int> &outvec);

	/**
	 *  Test whether the current split is smaller than \a sp
	 *  @param sp the other split to compare
	 *  @return true if the current split contains less taxa than \a sp
	 */
    bool operator<(const Split &sp) const;

	/**
		compare two split, do not compare the weight
		@param sp the target split
		@return TRUE if equal, FALSE otherwise
	*/
	bool operator==(const Split &sp) const;

	/**
		add all taxa from another split into this split (union)
		@param sp a split
	*/
	Split &operator+=(Split &sp);

	/**
		get the intersection with another split
		@param sp a split
	*/
	Split &operator*=(Split &sp);

	/**
		get the set difference with another split
		@param sp a split
	*/
	Split &operator-=(Split &sp);

	/**
		@return TRUE if there is overlapped taxon with sp, FALSE otherwise
		@param sp a split
	*/
	bool overlap(Split &sp);

	/**
		assignment
		@param sp a split
	*/
	Split &operator= (const Split &sp);

	/**
		subset operator
		@param sp a split
		@return TRUE of this set is a subset of sp
	*/
	bool subsetOf (Split &sp);


	/**
		randomize the set of a specific size
		@param size number of taxa in the resulting set
	*/
	void randomize(int size);

	Split *extractSubSplit(Split &taxa_mask);

	string &getName() { return name; }

protected:
	/**
		number of taxa
	*/
	int ntaxa; 

	/**
		weight of split
	*/
	double weight;
    
    /** 2018-08-23: split name */
    string name;

};

inline int splitweightcmp(const Split* a, const Split* b)
{
	return (a->getWeight() > b->getWeight());
}

typedef Split TaxaSet;

#endif