17 #include <sys/times.h>
36 void PS_debug_print_path() {
37 printf(
"__PATH %3zu :",
__PATH->size());
40 if (c % 20 == 0) printf(
"\n");
46 void PS_debug_print_inverse_path() {
50 if (c % 20 == 0) printf(
"\n");
69 printf(
"%s", __NODES_LEFT);
70 for (
int i = 0; i < 60; ++i) printf(
"\b");
77 for (
SpeciesID i = (_parent_ID < __MIN_ID) ? __MIN_ID : _parent_ID+1; i <
id; ++i) {
104 inverse_path_ID = *it_inverse_path;
106 __MAP->setTrue(path_ID, inverse_path_ID);
107 __MAP->setTrue(inverse_path_ID, path_ID);
111 for (inverse_path_ID =
id+1; inverse_path_ID <
__MAX_ID; ++inverse_path_ID) {
112 __MAP->setTrue(path_ID, inverse_path_ID);
113 __MAP->setTrue(inverse_path_ID, path_ID);
138 inverse_path_ID = *it_inverse_path;
139 smaller_ID = (path_ID < inverse_path_ID) ? path_ID : inverse_path_ID;
140 bigger_ID = (path_ID > inverse_path_ID) ? path_ID : inverse_path_ID;
142 if (
__MAP->get(smaller_ID, bigger_ID)) {
143 __MAP->setTrue(bigger_ID, smaller_ID);
146 __MAP->setTrue(smaller_ID, bigger_ID);
151 for (inverse_path_ID =
id+1; inverse_path_ID <
__MAX_ID; ++inverse_path_ID) {
152 smaller_ID = (path_ID < inverse_path_ID) ? path_ID : inverse_path_ID;
153 bigger_ID = (path_ID > inverse_path_ID) ? path_ID : inverse_path_ID;
155 if (
__MAP->get(smaller_ID, bigger_ID)) {
156 __MAP->setTrue(bigger_ID, smaller_ID);
159 __MAP->setTrue(smaller_ID, bigger_ID);
174 __NODES_LEFT[_depth] =
'0'+c;
177 __NODES_LEFT[_depth] =
'+';
182 if (_depth < 60) __NODES_LEFT[_depth] =
' ';
203 struct tms before_first_level_node;
209 __NODES_LEFT[0] =
'+';
211 if ((c < 50) || (c % 100 == 0)) {
212 times(&before_first_level_node);
213 printf(
"PS_detect_weak_differences_stepdown( %i ) : %i. of %zu ", i->first, c+1, _root_node->
countChildren());
fflush(stdout);
216 if ((c < 50) || (c % 100 == 0)) {
243 if ((
id >= __ONEMATCH_MIN_ID) && has_probes) {
244 for (
ID2IDSetCIter pair=_pairs.begin(); pair != _pairs.end(); ++pair) {
248 if (found_first ^ found_second) {
249 printf(
"found path for (%i,%i) at %p ", pair->first, pair->second, &(*_ps_node));
253 bool scanMinMax = (pair->first ==
__ONEMATCH_MIN_ID) || (pair->second == __ONEMATCH_MAX_ID);
258 __ONEMATCH_MAX_ID = -1;
259 for (
ID2IDSetCIter p=_pairs.begin(); p != _pairs.end(); ++p) {
260 if (p->first < __ONEMATCH_MIN_ID) __ONEMATCH_MIN_ID = p->first;
261 if (p->second > __ONEMATCH_MAX_ID) __ONEMATCH_MAX_ID = p->second;
263 printf(
" new MIN,MAX (%d,%d)", __ONEMATCH_MIN_ID, __ONEMATCH_MAX_ID);
275 if ((
id < __ONEMATCH_MAX_ID) || (! has_probes)) {
293 printf(
"\n\n----------------- bitmap ---------------\n\n");
303 for (
SpeciesID id2 = __MIN_ID; id2 <= id1; ++id2) {
304 smaller_id = (id1 < id2) ? id1 : id2;
305 bigger_id = (id1 < id2) ? id2 : id1;
306 bit1 =
__MAP->get(smaller_id, bigger_id);
307 bit2 =
__MAP->get(bigger_id, smaller_id);
311 oneMatch.insert(
ID2IDPair(smaller_id, bigger_id));
312 if (smaller_id < __ONEMATCH_MIN_ID) __ONEMATCH_MIN_ID = smaller_id;
313 if (bigger_id > __ONEMATCH_MAX_ID) __ONEMATCH_MAX_ID = bigger_id;
316 if (id1 != id2) noMatch.insert(
ID2IDPair(smaller_id, bigger_id));
320 printf(
"(enter to continue)\n");
322 printf(
"\n\n----------------- no matches ---------------\n\n");
323 if (!_result_filename) {
324 for (
ID2IDSetCIter i = noMatch.begin(); i != noMatch.end(); ++i) {
325 printf(
"%6i %6i\n", i->first, i->second);
328 printf(
"%zu no matches\n(enter to continue)\n", noMatch.size());
330 printf(
"\n\n----------------- one match ---------------\n\n");
331 if (!_result_filename) {
332 for (
ID2IDSetCIter i = oneMatch.begin(); i != oneMatch.end(); ++i) {
333 printf(
"%6i %6i\n", i->first, i->second);
336 printf(
"%zu one matches\n(enter to continue)\n", oneMatch.size());
346 if ((c < 50) || (c % 100 == 0)) printf(
"PS_find_probes_for_pairs( %i ) : %i of %zu\n", i->first, c+1, _root_node->
countChildren());
355 printf(
"\nPair (%i,%i) Setsize (%zu)", i->first.first, i->first.second, i->second.size());
359 path_id != i->second.end();
361 current_node = current_node->
getChild(*path_id).second;
362 if (c2 % 10 == 0) printf(
"\n");
363 printf(
"%6i%s ", *path_id, (current_node->hasProbes()) ? ((current_node->hasInverseProbes()) ?
"*" :
"+") :
"-");
365 printf(
"\nFinal Node : %p ", &(*current_node));
366 current_node->printOnlyMe();
373 if (!oneMatch.empty()) {
374 printf(
"did not find a path for these :\n");
375 for (
ID2IDSetCIter i = oneMatch.begin(); i != oneMatch.end(); ++i) {
376 printf(
"%6i %6i\n", i->first, i->second);
382 PS_BitMap_Counted *preset =
new PS_BitMap_Counted(
false, __MAX_ID+1);
384 for (
ID2IDSetCIter pair=noMatch.begin(); pair != noMatch.end(); ++pair) {
385 preset->setTrue(pair->second, pair->first);
395 if (
id == next_path_id) {
397 next_path_id = (path_iter == i->second.end()) ? -1 : *path_iter;
401 for (
IDSetCIter path_id = i->second.begin(); path_id != i->second.end(); ++path_id) {
402 if (
id == *path_id)
continue;
404 preset->setTrue(
id, *path_id);
407 preset->setTrue(*path_id,
id);
412 preset->recalcCounters();
413 if (!_result_filename) preset->print(stdout);
417 if (_result_filename) {
420 printf(
"saving no matches to %s...\n", _result_filename);
421 result_file->
put_long(noMatch.size());
422 for (
ID2IDSetCIter i = noMatch.begin(); i != noMatch.end(); ++i) {
423 result_file->
put_int(i->first);
424 result_file->
put_int(i->second);
427 printf(
"saving one matches to %s...\n", _result_filename);
430 result_file->
put_int(i->first.first);
431 result_file->
put_int(i->first.second);
432 result_file->
put_long(i->second.size());
433 for (
IDSetCIter path_id=i->second.begin(); path_id != i->second.end(); ++path_id) {
434 result_file->
put_int(*path_id);
438 printf(
"saving preset bitmap to %s...\n", _result_filename);
439 preset->save(result_file);
450 int main(
int argc,
char *argv[]) {
454 printf(
"Missing argument\n Usage %s <database name> [[-]bitmap filename] [+result filename]\n ", argv[0]);
455 printf(
"if bitmap filename begins with '-' it is loaded, else its created\n ");
456 printf(
"result filename MUST be preceded by '+'\n");
460 const char *input_DB_name = argv[1];
461 const char *bitmap_filename =
NULp;
462 const char *result_filename =
NULp;
465 if (argv[2][0] ==
'+') {
466 result_filename = argv[2]+1;
469 bitmap_filename = argv[2];
473 if (argv[3][0] ==
'+') {
474 result_filename = argv[3]+1;
477 bitmap_filename = argv[3];
483 printf(
"Opening probe-set-database '%s'..\n", input_DB_name);
484 PS_Database *db =
new PS_Database(input_DB_name, PS_Database::READONLY);
486 __MAX_ID = db->getMaxID();
487 __MIN_ID = db->getMinID();
490 __MAP =
new PS_BitMap_Fast(
false, __MAX_ID+1);
491 if (!bitmap_filename || (bitmap_filename[0] !=
'-')) {
492 printf(
"detecting..\n");
fflush(stdout);
493 __NODES_LEFT = (
char*)malloc(61);
494 memset(__NODES_LEFT,
' ', 60);
495 __NODES_LEFT[60] =
'\x00';
498 if (bitmap_filename) {
499 printf(
"saving bitmap to file %s\n", bitmap_filename);
501 __MAP->save(mapfile);
505 else if (bitmap_filename) {
506 printf(
"loading bitmap from file %s\n", bitmap_filename+1);
508 __MAP->load(mapfile);
511 printf(
"(enter to continue)\n");
518 printf(
"removing database from memory\n");
520 printf(
"(enter to continue)\n");
static const bool READONLY
std::map< ID2IDPair, IDSet > IDID2IDSetMap
IDVector::const_iterator IDVectorCIter
PS_NodeMapIterator getChildrenBegin()
IDID2IDSetMap::const_iterator IDID2IDSetMapCIter
static SpeciesID __MIN_ID
std::set< SpeciesID > IDSet
static void PS_detect_weak_differences(const PS_NodePtr &_root_node)
void put_long(long int _l)
IDID2NodeMap::const_iterator IDID2NodeMapCIter
size_t countChildren() const
static void PS_detect_weak_differences_stepdown(const PS_NodePtr &_ps_node, const SpeciesID _parent_ID, const long _depth)
static IDVector * __INVERSE_PATH
static unsigned long int __COUNT_SET_OPS
PS_NodeMap::const_iterator PS_NodeMapConstIterator
static SpeciesID __MAX_ID
static SpeciesID __ONEMATCH_MAX_ID
PS_NodeMapIterator getChildrenEnd()
static SpeciesID __ONEMATCH_MIN_ID
static PS_BitMap_Fast * __MAP
IDID2NodeMap::iterator IDID2NodeMapIter
bool hasInverseProbes() const
GB_write_int const char GB_write_autoconv_string WRITE_SKELETON(write_pointer, GBDATA *,"%p", GB_write_pointer) char *AW_awa if)(!gb_var) return strdup("")
std::set< ID2IDPair > ID2IDSet
ID2IDSet::const_iterator ID2IDSetCIter
map< ID2IDPair, PS_NodePtr > IDID2NodeMap
static char * __NODES_LEFT
int main(int argc, char *argv[])
void PS_find_probes_for_pairs(const PS_NodePtr &_ps_node, ID2IDSet &_pairs)
static unsigned long int __COUNT_SET_OPS2
std::vector< SpeciesID > IDVector
pair< bool, PS_NodePtr > getChild(SpeciesID id)
bool hasPositiveProbes() const
static void PS_print_and_evaluate_map(const PS_NodePtr &_root_node, const char *_result_filename)
std::pair< SpeciesID, SpeciesID > ID2IDPair
static const bool WRITEONLY
static IDID2IDSetMap * __PAIR2PATH
IDSet::const_iterator IDSetCIter