i64 totient_with_factor(const IntPairVec& vfac) { i64 prod = 1; for(unsigned int i = 0; i < vfac.size(); ++i){ i64 px = vfac[i].first; i64 npow = vfac[i].second; prod *= (px-1); prod *= power(px, npow-1); } return prod; }
void generate_all_numbers(int num, IntPairVec& pairs, vector<int>& vn, int cpos) { if(cpos == pairs.size()){ vn.push_back(num); return; } for( int i = 0; true ; ++i ){ int n1 = num * power(pairs[cpos].first, i); if(n1 > 100000) break; generate_all_numbers(n1, pairs, vn, cpos+1); } }
int main(int argc, char* argv[]) { using namespace kmer_match; using maligner_dp::AlignmentHeader; opt::program_name = argv[0]; parse_args(argc, argv); cerr << "................................................\n" << "MALIGNER settings:\n" << "\tquery_maps_file: " << opt::query_maps_file << "\n" << "\tref_maps_file: " << opt::ref_maps_file << "\n" << "\tmax. consecutive unmatched sites: " << opt::max_unmatched_sites << "\n" << "\tmax. unmatched rate: " << opt::max_unmatched_rate << "\n" << "\trelative_error: " << opt::rel_error << "\n" << "\tabsolute_error: " << opt::min_abs_error << "\n" << "\tminimum query frags: " << opt::min_frag << "\n" << "\tmax matches per query: " << opt::max_match << "\n" << "................................................\n\n"; ErrorModel error_model(opt::rel_error, opt::min_abs_error); auto start_time = chrono::steady_clock::now(); ///////////////////////////////////////////////////////////// // Read Reference Maps MapWrapperVec ref_maps = read_ref_maps(opt::ref_maps_file, opt::ref_is_circular, opt::ref_is_bounded); // Store a vector of pointers to the underlying Maps. MapWrapperPVec p_ref_maps(ref_maps.size()); for(size_t i = 0; i < ref_maps.size(); i++) { p_ref_maps[i] = &ref_maps[i]; } // Store reference maps in an unordered map. MapDB ref_map_db; for(auto i = ref_maps.begin(); i != ref_maps.end(); i++) { ref_map_db.insert( MapDB::value_type(i->map_.name_, *i) ); } cerr << "Read " << ref_maps.size() << " reference maps.\n"; //////////////////////////////////////////////////////////////// // Build Chunk Database MapChunkDB chunkDB(p_ref_maps, opt::max_unmatched_sites); cerr << "Made MapChunkDB with " << chunkDB.map_chunks_.size() << " chunks.\n"; // Write alignment header std::cout << AlignmentHeader(); size_t aln_count = 0; size_t map_with_aln = 0; size_t counter = 0; size_t interval_report = 100; Scorer scorer(opt::query_miss_penalty, opt::ref_miss_penalty, opt::min_sd, opt::sd_rate); // Iterate through query maps file. Map query_map; MapReader query_map_reader(opt::query_maps_file); for(; query_map_reader.next(query_map); counter++) { if(counter == interval_report) { std::cerr << "."; counter = 0; } MapWrapper query = MapWrapper(std::move(query_map), false, false); if(int(query.num_frags()) < opt::min_frag) { continue; } std::cerr << "Aligning " << query.get_name() << "\n"; const FragVec& frags = query.get_frags(); // Note: We ignore boundary fragments IntPairVec bounds = error_model.compute_bounds(frags.begin() + 1, frags.end() - 1); // Determine the maximum number of unmatched sites allowed const double mur = opt::max_unmatched_rate; size_t max_unmatched = mur > 0.0 ? size_t((mur/(1-mur)) * bounds.size()) : std::numeric_limits<size_t>::max(); RefAlignmentVec ref_alns = chunkDB.get_compatible_alignments_best(bounds, max_unmatched); // std::cerr << qi->name_ << "\n"; // std::cerr << frags << "\n"; // std::cerr << "max_unmatched: " << max_unmatched << "\n"; // std::cerr << "num_frags: " << bounds.size() << "\n"; // std::cerr << "num aln: " << " " << ref_alns.size() << std::endl; // Sort the alignments in ascending order of miss_rate std::sort(ref_alns.begin(), ref_alns.end(), ReferenceAlignmentMissRateSort()); AlignmentVec alns = convert_alignments(ref_alns, query, ref_map_db, scorer); cerr << "Converted " << alns.size() << " alignments.\n"; int query_aln_count = 0; bool map_has_alignment = false; for(auto a = alns.begin(); a != alns.end(); a++) { if(query_aln_count == opt::max_match) break; const maligner_dp::Alignment& aln = *a; bool have_aln = false; if(aln.score_per_inner_chunk <= opt::max_score_per_inner_chunk) { maligner_dp::print_alignment(std::cout, aln); ++aln_count; ++query_aln_count; have_aln = true; map_has_alignment = true; } } if(map_has_alignment) { ++map_with_aln; } } cerr << "\ntotal alignments: " << aln_count << "\n"; cerr << map_with_aln << " maps with alignments.\n"; auto end_time = chrono::steady_clock::now(); cerr << chrono::duration <double, milli> (end_time - start_time).count() << " ms" << endl; std::cerr << "maligner done.\n"; return EXIT_SUCCESS; }