// This is the main search algorithm for the (D)ERPA. std::vector< double > solve_region( const MatrixFactory &mf, const interval_t ®ion, const std::vector< double > lower_vals, const std::vector< double > upper_vals, double epsilon ) { // Determine # solutions int num_solutions = get_num_solutions( lower_vals, region.lower(), upper_vals, region.upper() ); // If no solutions, return empty. if ( 0 == num_solutions ) { return std::vector< double >(); } // If the interval has no width, but has solutions, return the value. if ( std::abs( region.upper() - region.lower() ) < epsilon ) { return std::vector< double >( 1, region.lower() ); } // If 1 solution, root_find. if ( 1 == num_solutions ) { std::vector< double > temp( 1, root_find_solution( mf, region, lower_vals, upper_vals, epsilon ) ); return temp; } // If > 1 solution, sub-divide region. double center = boost::numeric::median( region ); std::vector< double > center_vals = util::sorted_eigenvalues( mf.build( center ) ); std::vector< double > solutions = solve_region( mf, interval_t( region.lower(), center ), lower_vals, center_vals, epsilon ); { std::vector< double > upper_solutions = solve_region( mf, interval_t( center, region.upper() ), center_vals, upper_vals, epsilon ); solutions.insert( solutions.end(), upper_solutions.begin(), upper_solutions.end() ); } return solutions; }
interval_map_t makeIntervalMap (DataFrame incl) { CharacterVector incl_chroms = incl["chrom"] ; IntegerVector incl_starts = incl["start"] ; IntegerVector incl_ends = incl["end"] ; int nr = incl.nrows() ; interval_map_t interval_map ; for(int i=0; i<nr; ++i) { std::string chrom = as<std::string>(incl_chroms[i]) ; if (!interval_map.count(chrom)) interval_map[chrom] = intervalVector() ; interval_map[chrom].push_back(interval_t(incl_starts[i], incl_ends[i], i)) ; } return interval_map ; }