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 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720
|
/*==========================================================================
DFI - The Deferred Frequency Index
http://www.seqan.de/projects/dfi.html
============================================================================
This is an application of the DFI algorithm in
"Efficient string mining under constraints via the deferred frequency index"
============================================================================
Copyright (C) 2008 by David Weese and Marcel H. Schulz
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 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
Lesser General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
==========================================================================*/
#include <seqan/misc/misc_cmdparser.h>
#include <seqan/index.h>
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
using namespace seqan;
#define DEBUG_ENTROPY
static const double DFI_EPSILON = 0.0000001;
//////////////////////////////////////////////////////////////////////////////
// predicates for the Frequent Pattern Mining Problem
// minimal frequency predicate
struct PredMinFreq
{
String<unsigned> minFreq;
template <typename TDataSet>
PredMinFreq(String<unsigned> _minFreq, TDataSet const &):
minFreq(_minFreq) {}
inline bool operator()(_DFIEntry const &entry) const {
for (unsigned i = 0; i < length(entry.freq); ++i)
if (entry.freq[i] < minFreq[i])
return false;
return true;
}
};
// maximal frequency predicate
struct PredMaxFreq
{
String<unsigned> maxFreq;
template <typename TDataSet>
PredMaxFreq(String<unsigned> _maxFreq, TDataSet const &):
maxFreq(_maxFreq) {}
inline bool operator()(_DFIEntry const &entry) const {
for (unsigned i = 0; i < length(entry.freq); ++i)
if (entry.freq[i] > maxFreq[i])
return false;
return true;
}
};
//////////////////////////////////////////////////////////////////////////////
// predicates for the Emerging Substring Mining Problem
// minimal support predicate for D0
struct PredMinSupp
{
unsigned minFreq;
template <typename TDataSet>
PredMinSupp(double _minSupp, TDataSet const &ds)
{
// emerging substring mode
if (_minSupp * ds[1] < 1.0) {
cerr << "Support must be at least 1/|db_1|... exit!" << endl;
exit(1);
}
// adapt parameters from support to frequency
minFreq = (unsigned) ceil(_minSupp * (double)ds[1] - DFI_EPSILON);
}
inline bool operator()(_DFIEntry const &entry) const {
return entry.freq[0] >= minFreq;
}
};
// minimal growth predicate from D1->D0
struct PredEmerging
{
double growthRate;
template <typename TDataSet>
PredEmerging(double _growthRate, TDataSet const &ds) {
growthRate = _growthRate * ((double) ds[1] / (double) (ds[2] - ds[1]) - DFI_EPSILON);
}
// HINT: here growthRate is frequency-related, not support-related
inline bool operator()(_DFIEntry const &entry) const {
return (double)entry.freq[0] >= (double)entry.freq[1] * growthRate;
}
};
//////////////////////////////////////////////////////////////////////////////
// predicates for the Maximum Entropy Mining Problem
// minimal support predicate for at least one dataset
struct PredMinAllSupp
{
String<unsigned> minFreq;
template <typename TDataSet>
PredMinAllSupp(double _minSupp, TDataSet const &ds)
{
resize(minFreq, length(ds) - 1, Exact());
// adapt parameters from support to frequency
for (unsigned i = 1; i < length(ds); ++i)
minFreq[i - 1] = (unsigned) ceil(_minSupp * (double)(ds[i] - ds[i - 1]) - DFI_EPSILON);
}
inline bool operator()(_DFIEntry const &entry) const {
for (unsigned i = 0; i < length(entry.freq); ++i)
if (entry.freq[i] >= minFreq[i])
return true;
return false;
}
};
// maximum entropy predicate
struct PredEntropy
{
double maxEntropy;
template <typename TDataSet>
PredEntropy(double _maxEntropy, TDataSet const &):
maxEntropy(_maxEntropy + DFI_EPSILON) {}
static inline double
getEntropy(_DFIEntry const &entry)
{
int sum = 0;
double H = 0;
for (unsigned i = 0; i < length(entry.freq); ++i)
sum += entry.freq[i];
double lSum = log((double)sum); // sum cannot be zero
for (unsigned i = 0; i < length(entry.freq); ++i)
if (entry.freq[i])
{
double freq = entry.freq[i];
H += freq * (log(freq) - lSum);
}
H /= -sum * log((double)length(entry.freq)); // normalize by datasets (divide by log m)
return H;
}
inline bool operator()(_DFIEntry const &entry) const
{
return getEntropy(entry) <= maxEntropy;
}
};
//////////////////////////////////////////////////////////////////////////////
// Load multi-Fasta files
//
// seq ........ StringSet containing all sequences
// fileName ... array of database file names
// fileCount .. number of databases
// ds ......... seq[ds[i]],seq[ds[i]+1],...,seq[ds[i+1]-1] are the seqs. of database i
//
template <typename TSequences, typename TFileNames, typename TDatasets>
bool loadDatasets(
TSequences &seq,
TFileNames const &fileNames,
TDatasets &ds)
{
// count sequences
resize(ds, length(fileNames) + 1);
unsigned seqCount = 0;
for(unsigned s = 0; s < length(fileNames); ++s)
{
ds[s] = seqCount;
ifstream file;
file.open(toCString(fileNames[s]), ios_base::in | ios_base::binary);
if (!file.is_open()) return false;
while (!_streamEOF(file)) {
goNext(file, Fasta());
++seqCount;
}
}
ds[length(fileNames)] = seqCount;
// import sequences
resize(seq, seqCount);
for(unsigned i = 0, s = 0; s < length(fileNames); ++s) // for each database
{
ifstream file;
file.open(toCString(fileNames[s]), ios_base::in | ios_base::binary);
if (!file.is_open()) return false;
for(; (i < seqCount) && !_streamEOF(file); ++i) // and each sequence
read(file, seq[i], Fasta()); // read sequence
file.close();
}
return (seqCount > 0);
}
template <typename TSize>
struct SubstringEntry
{
Pair<unsigned> lPos;
unsigned len, freqSum;
Pair<TSize> range;
};
template <typename TSubstringEntry>
struct LessSubstringEnd : public binary_function<TSubstringEntry, TSubstringEntry, bool >
{
inline bool operator() (TSubstringEntry const &a, TSubstringEntry const &b) const
{
// sequence number
if (a.lPos.i1 < b.lPos.i1) return true;
if (a.lPos.i1 > b.lPos.i1) return false;
// end position
unsigned x = a.lPos.i2 + a.len;
unsigned y = b.lPos.i2 + b.len;
if (x < y) return true;
if (x > y) return false;
x = a.range.i2 - a.range.i1;
y = b.range.i2 - b.range.i1;
if (x < y) return true;
if (x > y) return false;
return a.len > b.len;
}
};
template <typename TSubstringEntry>
struct LessRange : public binary_function<TSubstringEntry, TSubstringEntry, bool >
{
inline bool operator() (TSubstringEntry const &a, TSubstringEntry const &b) const
{
// left border
if (a.range.i1 < b.range.i1) return true;
if (a.range.i1 > b.range.i1) return false;
// right border
if (a.range.i2 < b.range.i2) return true;
if (a.range.i2 > b.range.i2) return false;
return a.len > b.len;
}
};
template <typename TSubstringEntry>
struct LessLex : public binary_function<TSubstringEntry, TSubstringEntry, bool >
{
inline bool operator() (TSubstringEntry const &a, TSubstringEntry const &b) const
{
if (a.range.i1 < b.range.i1) return true;
if (a.range.i1 > b.range.i1) return false;
return a.len < b.len;
}
};
template <typename TMatchString>
inline void compactMatches(TMatchString &matches)
{
typedef typename Iterator<TMatchString, Standard>::Type TIter;
TIter src = begin(matches, Standard());
TIter dst = src;
TIter srcEnd = end(matches, Standard());
unsigned lastSeq = ~0;
unsigned lastPos = 0;
unsigned lastRange = 0;
if (src == srcEnd) return;
for (; src != srcEnd; ++src)
{
if ((*src).len == ~0u)
{
*dst = *src;
++dst;
continue;
}
if (((*src).lPos.i1 == lastSeq) && ((*src).lPos.i2 + (*src).len == lastPos) && ((*src).range.i2 - (*src).range.i1 == lastRange))
continue;
lastSeq = (*src).lPos.i1;
lastPos = (*src).lPos.i2 + (*src).len;
lastRange = (*src).range.i2 - (*src).range.i1;
*dst = *src;
++dst;
}
resize(matches, dst - begin(matches, Standard()));
}
template <typename TMatchString>
inline void compactSameParentFreqMatches(TMatchString &matches)
{
typedef typename Iterator<TMatchString, Standard>::Type TIter;
TIter src = begin(matches, Standard());
TIter dst = src;
TIter srcEnd = end(matches, Standard());
unsigned r1 = ~0;
unsigned r2 = ~0;
if (src == srcEnd) return;
for (; src != srcEnd; ++src)
{
if (((*src).range.i1 == r1) && ((*src).range.i2 == r2))
continue;
r1 = (*src).range.i1;
r2 = (*src).range.i2;
if ((*src).len != ~0u)
{
*dst = *src;
++dst;
}
}
resize(matches, dst - begin(matches, Standard()));
}
template <typename TMatchString, typename TIndex, typename TDBLookup, typename TSeen, typename TEntry>
inline void compactSameSuffLinkFreqMatches(TMatchString &matches, TIndex const &index, TDBLookup const &dbLookup, TSeen &seen, TEntry &entry)
{
typedef typename Iterator<TMatchString, Standard>::Type TIter;
typedef typename Fibre<TIndex, Fibre_SA>::Type TSA;
typedef typename Iterator<TSA, Standard>::Type TSAIter;
TIter src = begin(matches, Standard());
TIter dst = src;
TIter srcEnd = end(matches, Standard());
unsigned lastSeq = ~0;
unsigned lastPos = 0;
unsigned lastFreqSum = ~0;
for (; src != srcEnd; ++src)
{
// count frequencies (debug)
TSAIter oc = begin(indexSA(index), Standard()) + (*src).range.i1;
TSAIter ocEnd = begin(indexSA(index), Standard()) + (*src).range.i2;
arrayFill(begin(seen, Standard()), end(seen, Standard()), false);
arrayFill(begin(entry.freq, Standard()), end(entry.freq, Standard()), 0);
unsigned freqSum = 0;
for (; oc != ocEnd; ++oc)
{
unsigned seqNo = getSeqNo(*oc, stringSetLimits(index));
if (!seen[seqNo])
{
seen[seqNo] = true;
++entry.freq[dbLookup[seqNo]];
++freqSum;
}
}
if (((*src).lPos.i1 == lastSeq) && ((*src).lPos.i2 + (*src).len == lastPos) && (lastFreqSum == freqSum))
continue;
lastSeq = (*src).lPos.i1;
lastPos = (*src).lPos.i2 + (*src).len;
lastFreqSum = freqSum;
*dst = *src;
++dst;
}
resize(matches, dst - begin(matches, Standard()));
}
//////////////////////////////////////////////////////////////////////////////
// Create DFI and output substrings within constraints band
//
// TPred .......... frequency predicate
// TPredHull ...... monotonic hull of the predicate above
// TAlphabet ...... sequence alphabet (Dna, Dna5, AminoAcid, char, ...)
//
// fileName ....... array of database file names
// paramPred ... .. parameter for the frequency predicate
// paramPredHull .. parameter for the monotonic hull
//
template <
typename TPredHull,
typename TPred,
typename TAlphabet,
typename TParamPredHull,
typename TParamPred,
typename TFileNames
>
int runDFI(
TFileNames const &fileNames,
TParamPredHull paramPredHull,
TParamPred paramPred,
bool maximal)
{
typedef String<TAlphabet, Alloc<> > TString;
typedef StringSet<TString> TStringSet;
typedef Index<TStringSet, Index_Wotd<
WotdDFI<TPredHull, TPred> > > TIndex;
typedef Iter<TIndex, VSTree<TopDown<ParentLinks<> > > > TIter;
typedef SubstringEntry<typename Size<TIndex>::Type> TSubstringEntry;
String<unsigned> ds;
TStringSet mySet;
if (!loadDatasets(mySet, fileNames, ds)) {
cerr << "Database read error... exit!" << endl;
return 1;
}
// for(unsigned j=1;j<length(ds);++j)
// cout<<"dataset "<<j<<':'<<ds[j]-ds[j-1]<<endl;
TPred pred(paramPred, ds);
TPredHull predHull(paramPredHull, ds);
TIndex index(mySet, predHull, pred);
Pair<unsigned> lPos;
String<TSubstringEntry> matches;
// set index partition of sequences into datasets
index.ds = ds;
// database lookup table
typedef typename Fibre<TIndex, Fibre_SA>::Type TSA;
typedef typename Iterator<TSA, Standard>::Type TSAIter;
String<unsigned> dbLookup;
String<bool> seen;
_DFIEntry entry;
resize(dbLookup, length(mySet));
resize(seen, length(mySet));
resize(entry.freq, length(ds) - 1);
for (unsigned d = 0, i = 0; i < length(mySet); ++i)
{
while (ds[d + 1] == i) ++d;
dbLookup[i] = d;
}
#ifdef DEBUG_ENTROPY
PredEntropy entrp(0, mySet);
unsigned freqSumLast = ~0;
#endif
TIter it(index);
goBegin(it);
if (maximal)
{
for (unsigned m = 0; !atEnd(it); goNext(it), ++m)
{
resize(matches, m + 1, Generous());
posLocalize(matches[m].lPos, getOccurrence(it), stringSetLimits(container(it)));
matches[m].range = range(it);
matches[m].len = repLength(it);
if (dirAt(value(it).node, index) & TIndex::DFI_PARENT_FREQ)
{
++m;
resize(matches, m + 1, Generous());
matches[m].lPos.i1 = 0;
matches[m].lPos.i2 = 0;
matches[m].range = range(index, nodeUp(it));
matches[m].len = ~0u;
}
}
sort(begin(matches, Standard()), end(matches, Standard()), LessSubstringEnd<TSubstringEntry>());
compactMatches(matches);
sort(begin(matches, Standard()), end(matches, Standard()), LessRange<TSubstringEntry>());
compactSameParentFreqMatches(matches);
sort(begin(matches, Standard()), end(matches, Standard()), LessSubstringEnd<TSubstringEntry>());
compactSameSuffLinkFreqMatches(matches, index, dbLookup, seen, entry);
sort(begin(matches, Standard()), end(matches, Standard()), LessLex<TSubstringEntry>());
typedef typename Iterator<String<TSubstringEntry>, Standard>::Type TMatchIter;
TMatchIter mit = begin(matches, Standard());
TMatchIter mitEnd = end(matches, Standard());
for (; mit != mitEnd; ++mit)
{
#ifdef DEBUG_ENTROPY
// count frequencies (debug)
TSAIter oc = begin(indexSA(index), Standard()) + (*mit).range.i1;
TSAIter ocEnd = begin(indexSA(index), Standard()) + (*mit).range.i2;
arrayFill(begin(seen, Standard()), end(seen, Standard()), false);
arrayFill(begin(entry.freq, Standard()), end(entry.freq, Standard()), 0);
unsigned freqSum = 0;
for (; oc != ocEnd; ++oc)
{
unsigned seqNo = getSeqNo(*oc, stringSetLimits(index));
if (!seen[seqNo])
{
seen[seqNo] = true;
++entry.freq[dbLookup[seqNo]];
++freqSum;
}
}
double H = entrp.getEntropy(entry);
if (H <= 0.0) H = 0.0;
// if (freqSum != freqSumLast)
#endif
{
#ifdef DEBUG_ENTROPY
cout << left << setw(14) << H << "[";
for (unsigned i = 0; i < length(entry.freq); ++i)
cout << right << setw(6) << entry.freq[i];
cout << "] \"";
#endif
cout << infix(
mySet[getSeqNo((*mit).lPos)],
getSeqOffset((*mit).lPos),
getSeqOffset((*mit).lPos) + (*mit).len);
#ifdef DEBUG_ENTROPY
cout << "\"";
freqSumLast = freqSum;
#endif
cout << endl;
}
}
}
else
{
for (; !atEnd(it); goNext(it))
{
posLocalize(lPos, getOccurrence(it), stringSetLimits(container(it)));
unsigned len = repLength(it);
for(unsigned l = parentRepLength(it) + 1; l <= len; ++l)
{
#ifdef DEBUG_ENTROPY
// count frequencies (debug)
typedef typename Infix< typename Fibre<TIndex, Fibre_SA>::Type const >::Type TOccs;
typedef typename Iterator<TOccs, Standard>::Type TOccIter;
TOccs occs = getOccurrences(it);
TOccIter oc = begin(occs, Standard()), ocEnd = end(occs, Standard());
arrayFill(begin(seen, Standard()), end(seen, Standard()), false);
arrayFill(begin(entry.freq, Standard()), end(entry.freq, Standard()), 0);
for (; oc != ocEnd; ++oc)
{
unsigned seqNo = getSeqNo(*oc, stringSetLimits(index));
if (!seen[seqNo])
{
seen[seqNo] = true;
++entry.freq[dbLookup[seqNo]];
}
}
double H = entrp.getEntropy(entry);
if (H <= 0.0) H = 0.0;
cout << left << setw(14) << H << "[";
for (unsigned i = 0; i < length(entry.freq); ++i)
cout << right << setw(6) << entry.freq[i];
cout << "] \"";
#endif
cout << infix(
mySet[getSeqNo(lPos)],
getSeqOffset(lPos),
getSeqOffset(lPos) + l);
#ifdef DEBUG_ENTROPY
cout << "\"";
#endif
cout << endl;
}
}
}
return 0;
}
int main(int argc, const char *argv[])
{
int optionAlphabet = 0; // 0..char, 1..protein, 2..dna
int optionPredicate = -1; // 0..minmax, 1..growth, 2..entropy
String<unsigned> optionMinFreq;
String<unsigned> optionMaxFreq;
double optionMinSupp = 0;
double optionGrowthRate = 0;
double optionEntropy = 0;
bool optionMaximal = false;
CommandLineParser parser;
string rev = "$Revision: 4670 $";
addVersionLine(parser, "DFI version 2.0 20090715 [" + rev.substr(11, 4) + "]");
//////////////////////////////////////////////////////////////////////////////
// Define options
addTitleLine(parser, "**************************************************************");
addTitleLine(parser, "*** DFI - The Deferred Frequency Index ***");
addTitleLine(parser, "*** (c) Copyright 2009 by David Weese and Marcel H. Schulz ***");
addTitleLine(parser, "**************************************************************");
addUsageLine(parser, "[OPTION]... --minmax <min_1> <max_1> <database 1> ... --minmax <min_m> <max_m> <database m>");
addUsageLine(parser, "[OPTION]... --growth <rho_s> <rho_g> <database 1> <database 2>");
addUsageLine(parser, "[OPTION]... --entropy <rho_s> <alpha> <database 1> <database 2> ... <database m>");
addOption(parser, CommandLineOption("f", "minmax", 2, "solve Frequent Pattern Mining Problem", OptionType::Int | OptionType::Label | OptionType::List));
addOption(parser, CommandLineOption("g", "growth", 2, "solve Emerging Substring Mining Problem", OptionType::Double | OptionType::Label));
addOption(parser, CommandLineOption("e", "entropy", 2, "solve Entropy Mining Problem", OptionType::Double | OptionType::Label));
addHelpLine(parser, "");
addOption(parser, CommandLineOption("p", "protein", "use AminoAcid alphabet (for proteomes)", OptionType::Boolean));
addOption(parser, CommandLineOption("d", "dna", "use DNA alphabet (for genomes)", OptionType::Boolean));
addOption(parser, CommandLineOption("m", "maximal", "output only left and right maximal substrings", OptionType::Boolean));
addHelpLine(parser, "The default is byte alphabet");
if (argc == 1)
{
shortHelp(parser, cerr); // print short help and exit
return 0;
}
bool stop = !parse(parser, argc, argv, cerr);
//////////////////////////////////////////////////////////////////////////////
// Extract options
getOptionValueLong(parser, "maximal", optionMaximal);
if (isSetLong(parser, "protein")) optionAlphabet = 1;
if (isSetLong(parser, "dna")) optionAlphabet = 2;
if (isSetLong(parser, "help") || isSetLong(parser, "version")) return 0; // print help or version and exit
//////////////////////////////////////////////////////////////////////////////
// Check options
if (isSetLong(parser, "minmax"))
{
optionPredicate = 0;
unsigned cons = length(getOptionValuesLong(parser, "minmax")) / 2;
resize(optionMinFreq, cons);
resize(optionMaxFreq, cons);
for (unsigned d = 0; d < cons; ++d)
{
getOptionValueLong(parser, "minmax", 2*d, optionMinFreq[d]);
getOptionValueLong(parser, "minmax", 2*d+1, optionMaxFreq[d]);
if ((optionMinFreq[d] < 1) && (stop = true))
cerr << "Minimum frequency threshold must be at least 1." << endl;
if ((optionMaxFreq[d] < 1) && (stop = true))
cerr << "Maximum frequency threshold must be greater than 0." << endl;
}
if ((argumentCount(parser) < cons) && (stop = true))
cerr << "Please specify " << cons << " databases." << endl;
if ((argumentCount(parser) > cons) && (stop = true))
cerr << "Please specify " << argumentCount(parser) << " min/max constraints." << endl;
}
if (isSetLong(parser, "growth"))
{
optionPredicate = 1;
getOptionValueLong(parser, "growth", 0, optionMinSupp);
getOptionValueLong(parser, "growth", 1, optionGrowthRate);
if ((optionMinSupp <= 0.0 || optionMinSupp > 1.0) && (stop = true))
cerr << "Support threshold must be greater than 0 and less than or equal to 1." << endl;
if ((optionGrowthRate < 1.0) && (stop = true))
cerr << "Growth rate must not be less than 1." << endl;
if ((argumentCount(parser) != 2) && (stop = true))
cerr << "Please specify 2 databases." << endl;
}
if (isSetLong(parser, "entropy"))
{
optionPredicate = 2;
getOptionValueLong(parser, "entropy", 0, optionMinSupp);
getOptionValueLong(parser, "entropy", 1, optionEntropy);
if ((optionMinSupp <= 0.0 || optionMinSupp > 1.0) && (stop = true))
cerr << "Support threshold must be greater than 0 and less than or equal to 1." << endl;
if ((optionEntropy <= 0.0 || optionEntropy > 1.0) && (stop = true))
cerr << "Entropy must not be grater than 0 and less or equal to 1." << endl;
if ((argumentCount(parser) < 2) && (stop = true))
cerr << "Please specify at least 2 databases." << endl;
}
if (stop)
{
cerr << "Exiting ..." << endl;
return -1;
}
switch (optionPredicate)
{
case 0:
switch (optionAlphabet)
{
case 0: return runDFI<PredMinFreq, PredMaxFreq, unsigned char> (getArgumentValues(parser), optionMinFreq, optionMaxFreq, optionMaximal);
case 1: return runDFI<PredMinFreq, PredMaxFreq, AminoAcid> (getArgumentValues(parser), optionMinFreq, optionMaxFreq, optionMaximal);
case 2: return runDFI<PredMinFreq, PredMaxFreq, Dna> (getArgumentValues(parser), optionMinFreq, optionMaxFreq, optionMaximal);
}
case 1:
switch (optionAlphabet)
{
case 0: return runDFI<PredMinSupp, PredEmerging, unsigned char> (getArgumentValues(parser), optionMinSupp, optionGrowthRate, optionMaximal);
case 1: return runDFI<PredMinSupp, PredEmerging, AminoAcid> (getArgumentValues(parser), optionMinSupp, optionGrowthRate, optionMaximal);
case 2: return runDFI<PredMinSupp, PredEmerging, Dna> (getArgumentValues(parser), optionMinSupp, optionGrowthRate, optionMaximal);
}
case 2:
switch (optionAlphabet)
{
case 0: return runDFI<PredMinAllSupp, PredEntropy, unsigned char> (getArgumentValues(parser), optionMinSupp, optionEntropy, optionMaximal);
case 1: return runDFI<PredMinAllSupp, PredEntropy, AminoAcid> (getArgumentValues(parser), optionMinSupp, optionEntropy, optionMaximal);
case 2: return runDFI<PredMinAllSupp, PredEntropy, Dna> (getArgumentValues(parser), optionMinSupp, optionEntropy, optionMaximal);
}
}
cerr << "Please choose a mining problem." << endl;
cerr << "Exiting ..." << endl;
return -1;
}
|