// [[Rcpp::export]] LogicalVector sequenceChecker_cpp(CharacterMatrix x){ int nc = x.ncol() ; CharacterVector ns(x.nrow()); CharacterVector Ns(x.nrow()); std::fill(ns.begin(), ns.end(), "n"); std::fill(Ns.begin(), Ns.end(), "N"); LogicalVector out(nc); for(int i=0; i < nc; i++){ out[i] = is_false(any(x(_,i) == Ns)) && is_false(any(x(_,i) == ns)) && unique(x(_,i)).size() != 1; } return out; }
// [[Rcpp::export]] std::string runit_CharacterMatrix_column( CharacterMatrix m){ CharacterMatrix::Column col = m.column(0) ; std::string res( std::accumulate( col.begin(), col.end(), std::string() ) ) ; return res ; }
// [[Rcpp::export]] std::string runit_CharacterMatrix_row( CharacterMatrix m ){ CharacterMatrix::Row first_row = m.row(0) ; std::string res( std::accumulate( first_row.begin(), first_row.end(), std::string() ) ) ; return res ; }
// [[Rcpp::export]] double obsHet(CharacterMatrix in_mat) { //CharacterVector new_mat = in_mat(_,1) ; int n = in_mat.nrow() ; double total = 0 ; double ns = 0 ; for(int i = 0; i < n; i++){ CharacterVector tst = in_mat(i,_) ; LogicalVector id = is_na(tst) ; if(tst[0] != tst[1]){ total += 1 ; } if(!id[0]) { ns += 1 ; } } return total/ns ; }
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(); }