int main(int argc, char** argv) { int size = -1; std::string filterString; int verbosityLevel = 1; int cliqueLimit = -1; lemon::ArgParser ap(argc, argv); ap.boolOption("-version", "Show version number") .refOption("v", "Verbosity level (default: 1)", verbosityLevel) .refOption("s", "Maximal clique size (default: -1 (maximum))", size) .refOption("f", "Filter (default : \"\")", filterString) .refOption("l", "Clique limit (default : -1 (unlimited))", cliqueLimit) .other("input", "Input file"); ap.parse(); g_verbosity = static_cast<VerbosityLevel>(verbosityLevel); if (ap.given("-version")) { std::cout << "Version number: " << SPRUCE_VERSION << std::endl; return 0; } if (ap.files().size() == 0) { std::cerr << "Error: missing input file" << std::endl; return 1; } const std::string& inputFilename(ap.files()[0]); std::ifstream inFile(inputFilename.c_str()); if (!inFile.good()) { std::cerr << "Unable to open '" << inputFilename << "' for reading" << std::endl; return 1; } IntPairSet filter; IntSet whiteList; if (!filterString.empty()) { StringVector s; boost::split(s, filterString, boost::is_any_of(";")); for (const std::string& str : s) { StringVector ss; boost::split(ss, str, boost::is_any_of(",")); filter.insert(std::make_pair(boost::lexical_cast<int>(ss[0]), boost::lexical_cast<int>(ss[1]))); } } CharacterMatrix M; try { inFile >> M; } catch (std::runtime_error& e) { std::cerr << "File: '" << ap.files()[0].c_str() << "'. " << e.what() << std::endl; return 1; } M.init(); M.applyHeuristic(); CompatibilityGraph G(M); G.setCliqueLimit(cliqueLimit); G.init(filter, size); G.write(std::cout); return 0; }
void enumerate(int limit, int timeLimit, int threads, int state_tree_limit, std::ifstream& inFile, const std::string& intervalFile, int lowerbound, bool monoclonal, const std::string& purityString, bool writeCliqueFile, bool readCliqueFile, const std::string& cliqueFile, int offset, const IntSet& whiteList, SolutionSet& sols) { CharacterMatrix M; try { g_lineNumber = 0; inFile >> M; } catch (std::runtime_error& e) { std::cerr << "Character matrix file. " << e.what() << std::endl; exit(1); } if (!intervalFile.empty()) { std::ifstream inFile2(intervalFile.c_str()); if (inFile2.good()) { try { M.setIntervals(inFile2); } catch (std::runtime_error& e) { std::cerr << "Interval file. " << e.what() << std::endl; exit(1); } } } StlDoubleVector purityValues; if (purityString != "" && !parse_purity_vector(purityString, M.m(), purityValues)) { return; } // if (monoclonal && purityString == "") // { // std::cerr << "Expected purity values" << std::endl; // return; // } if (g_verbosity >= VERBOSE_ESSENTIAL) { std::cerr << "Intializing copy-state matrix ..." << std::endl; } M.init(); if (monoclonal) { M.applyHeuristic(); } CompatibilityGraph* pComp = NULL; if (!readCliqueFile) { if (g_verbosity >= VERBOSE_ESSENTIAL) { std::cerr << std::endl << "Initializing compatibility graph ..." << std::endl; } pComp = new CompatibilityGraph(M); pComp->init(IntPairSet(), -1); } else { std::ifstream inFile(cliqueFile); pComp = new CompatibilityGraph(M); pComp->init(inFile); } if (writeCliqueFile) { std::ofstream outFile(cliqueFile); if (outFile.good()) { pComp->write(outFile); } } NoisyCnaEnumerate alg(M, purityValues, *pComp, lowerbound); alg.init(state_tree_limit); alg.enumerate(limit, timeLimit, threads, state_tree_limit, monoclonal, offset, whiteList); sols = alg.sols(); delete pComp; if (g_verbosity >= VERBOSE_ESSENTIAL) { std::cerr << "Generated " << sols.solutionCount() << " solutions" << std::endl; } inFile.close(); }