|
11 | 11 | #include <Rcpp.h> |
12 | 12 | #include <cli/progress.h> |
13 | 13 | #include "utils.h" |
14 | | -#include <random> |
15 | 14 |
|
16 | 15 | #define MISMATCHBAM_MODE_READ 1 |
17 | 16 | #define MISMATCHBAM_MODE_STATE 3 |
@@ -528,14 +527,6 @@ Rcpp::List read_mismatchbam_cpp(std::string inname_str, |
528 | 527 | // ... return value for mode 3 |
529 | 528 | Rcpp::NumericMatrix pair_counts; |
530 | 529 |
|
531 | | - // random number generation |
532 | | - // first generate a single random number from R |
533 | | - // to link the C++ RNG to the R session's current seed state |
534 | | - // dis() can then be used to draw uniformly distributed random numbers |
535 | | - double r_seed = R::runif(0, 1000000); |
536 | | - std::mt19937 gen((unsigned int)r_seed); |
537 | | - std::uniform_real_distribution<double> dis(0.0, 1.0); |
538 | | - |
539 | 530 | // prepare bam file for reading |
540 | 531 | if (verbose) { |
541 | 532 | snprintf(buffer, buffer_len, "opening input file {.file %s} using {%d} thread{?s}", inname, n_threads); |
@@ -614,7 +605,7 @@ Rcpp::List read_mismatchbam_cpp(std::string inname_str, |
614 | 605 | (calculate_aligned_bases(bamdata) >= minAlignedLength)) { |
615 | 606 |
|
616 | 607 | if (!(bamdata->core.flag & BAM_FPAIRED) && |
617 | | - ((n_alns_to_sample == 0) || (dis(gen) < keep_aln_fraction))) { |
| 608 | + ((n_alns_to_sample == 0) || (R::runif(0, 1) < keep_aln_fraction))) { |
618 | 609 | // single-end - process directly |
619 | 610 | success = process_mismatch_bam_record( |
620 | 611 | MISMATCHBAM_MODE_STATE, // run mode |
@@ -674,7 +665,7 @@ Rcpp::List read_mismatchbam_cpp(std::string inname_str, |
674 | 665 | // mate seen - get it from the map and process the pair |
675 | 666 | bamdata2 = curr_records_it->second; |
676 | 667 |
|
677 | | - if ((n_alns_to_sample == 0) || (dis(gen) < keep_aln_fraction)) { |
| 668 | + if ((n_alns_to_sample == 0) || (R::runif(0, 1) < keep_aln_fraction)) { |
678 | 669 | success = process_mismatch_bam_record_pair( |
679 | 670 | MISMATCHBAM_MODE_STATE, // run mode |
680 | 671 | bamdata2, // bam record |
@@ -722,7 +713,7 @@ Rcpp::List read_mismatchbam_cpp(std::string inname_str, |
722 | 713 | curr_records_it = curr_records.begin(); |
723 | 714 | bamdata2 = curr_records_it->second; |
724 | 715 |
|
725 | | - if ((n_alns_to_sample == 0) || (dis(gen) < keep_aln_fraction)) { |
| 716 | + if ((n_alns_to_sample == 0) || (R::runif(0, 1) < keep_aln_fraction)) { |
726 | 717 | success = process_mismatch_bam_record( |
727 | 718 | MISMATCHBAM_MODE_STATE, // run mode |
728 | 719 | bamdata2, // bam record |
@@ -813,7 +804,7 @@ Rcpp::List read_mismatchbam_cpp(std::string inname_str, |
813 | 804 | // read overlapping alignments using iterator |
814 | 805 | while ((c = sam_itr_next(infile, iter, bamdata)) >= 0) { |
815 | 806 | if (!(bamdata->core.flag & (BAM_FUNMAP | BAM_FSECONDARY | BAM_FSUPPLEMENTARY)) && |
816 | | - ((n_alns_to_sample == 0) || (dis(gen) < keep_aln_fraction))) { |
| 807 | + ((n_alns_to_sample == 0) || (R::runif(0, 1) < keep_aln_fraction))) { |
817 | 808 | success = process_mismatch_bam_record( |
818 | 809 | MISMATCHBAM_MODE_READ, // run mode |
819 | 810 | bamdata, // bam record |
|
0 commit comments