12 #ifndef PS_CANDIDATE_HXX
13 #define PS_CANDIDATE_HXX
22 #ifndef _GLIBCXX_CLIMITS
34 return &(*c1) < &(*c2);
64 passes_left = MAX_PASSES;
68 one_false_IDs_matches = 0;
75 static const unsigned int MAX_PASSES = 3;
85 PS_BitMap_Counted *
map;
96 return one_false_IDs->size();
106 if (map->getCountFor(id1) == _max_id+1)
continue;
107 if (id1 < _min_sets_id) _min_sets_id = id1;
108 if (id1 > _max_sets_id) _max_sets_id = id1;
109 map->getFalseIndicesFor(id1, falseIndices);
110 while ((*(falseIndices.begin()) < id1) &&
111 !falseIndices.empty()) falseIndices.erase(*falseIndices.begin());
112 if (falseIndices.empty())
continue;
113 if (*falseIndices.begin() < _min_sets_id) _min_sets_id = *falseIndices.begin();
114 if (*falseIndices.rbegin() > _max_sets_id) _max_sets_id = *falseIndices.rbegin();
116 false_IDs += falseIndices.size();
117 if (falseIndices.size() == 1) {
118 one_false_IDs->insert(
ID2IDPair(id1, *falseIndices.begin()));
122 return one_false_IDs->size();
126 unsigned long matches = 0;
129 p != one_false_IDs->end();
131 if (_path.find(p->first) == path_end) {
132 if (_path.find(p->second) != path_end) ++matches;
135 if (_path.find(p->second) == path_end) ++matches;
154 (child != children.end()) && (found == children.end());
156 if (child->second->node == _ps_node) found = child;
158 return found != children.end();
162 if (node.
isNull())
return false;
163 if (_ps_node == node) {
177 if (found == children.end()) {
179 children[_gain] = new_child;
182 else if (_distance < found->second->distance) {
183 children.erase(_gain);
185 children[_gain] = new_child;
192 const unsigned long _one_false_IDs_matches,
193 const float _filling_level,
197 if (children.empty()) {
200 new_child->depth = depth+1;
201 new_child->filling_level = _filling_level;
202 if (_filling_level >= 100.0) new_child->passes_left = 0;
203 children[0] = new_child;
204 one_false_IDs_matches = _one_false_IDs_matches;
208 if (_one_false_IDs_matches < one_false_IDs_matches)
return false;
210 if ((_one_false_IDs_matches == one_false_IDs_matches) &&
211 (_gain <= children[0]->gain))
return false;
215 new_child->depth = depth+1;
216 new_child->filling_level = _filling_level;
217 if (_filling_level >= 100.0) new_child->passes_left = 0;
218 children[0] = new_child;
219 one_false_IDs_matches = _one_false_IDs_matches;
224 if (children.empty())
return;
226 unsigned long best_gain = children.rbegin()->first;
227 unsigned long worst_gain = children.begin()->first;
228 unsigned long middle_gain = (best_gain + worst_gain) >> 1;
230 if (middle_child == children.end()) {
231 middle_child = children.lower_bound(middle_gain);
232 middle_gain = middle_child->first;
236 if (_filling_level < 50.0) {
237 if (children.size() <= 3)
return;
241 if (to_delete != children.end()) {
242 children.erase(to_delete);
243 to_delete = children.end();
245 if ((c->first != worst_gain) &&
246 (c->first != middle_gain) &&
247 (c->first != best_gain)) {
252 else if (_filling_level < 75.0) {
253 if (children.size() <= 2)
return;
257 if (to_delete != children.end()) {
258 children.erase(to_delete);
259 to_delete = children.end();
261 if ((c->first != middle_gain) &&
262 (c->first != best_gain)) {
268 if (children.size() <= 1)
return;
272 if (to_delete != children.end()) {
273 children.erase(to_delete);
274 to_delete = children.end();
276 if (c->first != best_gain) {
281 if (to_delete != children.end()) {
282 children.erase(to_delete);
283 to_delete = children.end();
288 const unsigned long _depth = 0,
289 const bool _descend =
true)
const {
290 for (
unsigned long i = 0; i < _depth; ++i) {
295 for (
unsigned long i = 0; i < _depth; ++i) {
298 printf(
"[%p] depth (%lu) no node\n",
this, _depth);
301 for (
unsigned long i = 0; i < _depth; ++i) {
304 printf(
"[%p] depth (%lu) node (%p) no probes\n",
this, _depth, &(*node));
310 for (
unsigned long i = 0; i < _depth; ++i) {
313 printf(
"[%p] depth (%lu) node (%p) matches (%zu) %u %u\n",
317 ((*probe)->quality > 0) ? path.size() : _species_count - path.size(),
319 (*probe)->GC_content);
326 child != children.rend();
328 child->second->printProbes(_species_count, _depth+1);
334 void print (
const unsigned long _depth = 0,
335 const bool _print_one_false_IDs =
false,
336 const bool _descend =
true)
const {
337 for (
unsigned long i = 0; i < _depth; ++i) {
340 printf(
"[%p] passes left (%u) filling level (%.5f) distance (%6.2f) gain (%6lu) depth (%3lu) path length (%4zu) ",
349 printf(
"node (undefined) children (%2zu) ", children.size());
352 printf(
"node (%p) children (%2zu) ", &(*node), children.size());
354 printf(
"(%4lu %4zu)/%lu", one_false_IDs_matches, (one_false_IDs) ? one_false_IDs->size() : 0, false_IDs);
355 if (_print_one_false_IDs) {
357 for (
unsigned long i = 0; i < _depth; ++i) {
360 printf(
" one_false_IDs : ");
363 p != one_false_IDs->end();
365 printf(
"(%i %i) ", p->first, p->second);
372 printf(
"\n");
fflush(stdout);
375 child != children.rend();
377 child->second->print(_depth+1);
383 const unsigned long _bits_in_map) {
393 count = one_false_IDs->size();
396 p != one_false_IDs->end();
416 count = children.size();
419 child != children.end();
421 child->second->save(_file, _bits_in_map);
426 const unsigned long _bits_in_map,
436 filling_level = (float)(_bits_in_map - false_IDs) / _bits_in_map * 100.0;
442 for (; count > 0; --count) {
445 one_false_IDs->insert(
ID2IDPair(id1, id2));
451 if (count) node = _root_node;
452 for (; count > 0; --count) {
459 for (; count > 0; --count) {
461 new_child->depth = depth+1;
462 new_child->parent =
this;
463 new_child->load(_file, _bits_in_map, _root_node);
464 children[new_child->gain] = new_child;
471 distance = _distance;
476 one_false_IDs =
NULp;
477 one_false_IDs_matches = 0;
483 if (one_false_IDs)
delete one_false_IDs;
491 #error ps_candidate.hxx included twice
492 #endif // PS_CANDIDATE_HXX
void put_ulong(unsigned long int _ul)
set< ID2IndexSetPair > ID2IndexSetSet
PS_CandidateSet::iterator PS_CandidateSetIter
std::set< SpeciesID > IDSet
PS_CandidateSet::const_reverse_iterator PS_CandidateSetCRIter
bool alreadyUsedNode(const PS_NodePtr &_ps_node) const
void printProbes(const SpeciesID _species_count, const unsigned long _depth=0, const bool _descend=true) const
PS_CandidateSet::const_iterator PS_CandidateSetCIter
PS_Candidate * PS_CandidatePtr
PS_ProbeSet::const_iterator PS_ProbeSetCIter
size_t countProbes() const
bool isNull() const
test if SmartPtr is NULp
PS_ProbeSetCIter getProbesBegin() const
void setNull()
set SmartPtr to NULp
void put_uint(unsigned int _ui)
bool operator()(const PS_CandidateSPtr &c1, const PS_CandidateSPtr &c2) const
PS_ProbeSetCIter getProbesEnd() const
map< unsigned long, PS_CandidateSPtr > PS_CandidateByGainMap
void get_uint(unsigned int &_ui)
ID2IndexSetSet::const_iterator ID2IndexSetSetCIter
ID2IndexSetSet::reverse_iterator ID2IndexSetSetRIter
set< PS_CandidateSPtr, cmp_candidates > PS_CandidateSet
SmartPtr< PS_Candidate > PS_CandidateSPtr
PS_CandidateByGainMap::iterator PS_CandidateByGainMapIter
unsigned long one_false_IDs_matches
PS_CandidateByGainMap children
PS_CandidateSet::reverse_iterator PS_CandidateSetRIter
unsigned long initFalseIDs(const SpeciesID _min_id, const SpeciesID _max_id, SpeciesID &_min_sets_id, SpeciesID &_max_sets_id)
std::set< ID2IDPair > ID2IDSet
PS_CandidateByGainMap::reverse_iterator PS_CandidateByGainMapRIter
ID2IDSet::const_iterator ID2IDSetCIter
unsigned long matchPathOnOneFalseIDs(IDSet &_path)
PS_Candidate(float _distance)
void reduceChildren(const float _filling_level)
int addChild(unsigned long _distance, unsigned long _gain, const PS_NodePtr &_node, IDSet &_path)
bool hasChild(PS_NodePtr _ps_node) const
bool updateBestChild(const unsigned long _gain, const unsigned long _one_false_IDs_matches, const float _filling_level, const PS_NodePtr &_node, IDSet &_path)
void get_ulong(unsigned long int &_ul)
PS_CandidateByGainMap::const_reverse_iterator PS_CandidateByGainMapCRIter
void load(PS_FileBuffer *_file, const unsigned long _bits_in_map, const PS_NodePtr &_root_node)
pair< bool, PS_NodePtr > getChild(SpeciesID id)
ID2IndexSetSet::iterator ID2IndexSetSetIter
PS_CandidateByGainMap::const_iterator PS_CandidateByGainMapCIter
void print(const unsigned long _depth=0, const bool _print_one_false_IDs=false, const bool _descend=true) const
ID2IndexSetSet::const_reverse_iterator ID2IndexSetSetCRIter
pair< SpeciesID, PS_BitSet::IndexSet > ID2IndexSetPair
std::pair< SpeciesID, SpeciesID > ID2IDPair
void save(PS_FileBuffer *_file, const unsigned long _bits_in_map)
IDSet::const_iterator IDSetCIter