Skip to content

Commit

Permalink
Merge pull request #953 from benjjneb/taxonomy-segfault-fix
Browse files Browse the repository at this point in the history
Taxonomy segfault fix
  • Loading branch information
benjjneb authored Feb 21, 2020
2 parents 5890e28 + 712ff92 commit 9a9336e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Description: The dada2 package infers exact amplicon sequence variants (ASVs) fr
removing substitution and chimera errors. Taxonomic classification is available
via a native implementation of the RDP naive Bayesian classifier, and species-level
assignment to 16S rRNA gene fragments by exact matching.
Version: 1.14.0
Date: 2019-04-22
Version: 1.15.1
Date: 2020-02-19
Maintainer: Benjamin Callahan <[email protected]>
Author: Benjamin Callahan <[email protected]>, Paul McMurdie, Susan Holmes
License: LGPL-3
Expand Down
2 changes: 1 addition & 1 deletion R/misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ bs1ham <- function(dd, ham=1) {

#' @keywords internal
getSRR <- Vectorize(function(run, outdir="sra", verbose=TRUE, ...) {
if(!grepl("^SRR[0-9]{6+}$", run)) stop("Requires SRA Run accessions in format: SRR1234567")
if(!grepl("^SRR[0-9]{6,}$", run)) stop("Requires SRA Run accessions in format: SRR1234567")
if(!dir.exists(outdir)) dir.create(outdir)
loc <- paste0("ftp-trace.ncbi.nlm.nih.gov/sra/sra-instant/reads/ByRun/sra/SRR/",
substr(run, 1, 6), "/", run, "/")
Expand Down
8 changes: 7 additions & 1 deletion src/taxonomy.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "dada.h"
#include <Rcpp.h>
#include <RcppParallel.h>
#include <random>

using namespace Rcpp;

// Gets kmer index
Expand Down Expand Up @@ -70,6 +72,9 @@ int get_best_genus(int *karray, double *out_logp, unsigned int arraylen, unsigne
double p, logp, max_logp = 1.0; // Init value to be replaced on first iteration
double rv; // Dummy random variable
unsigned int nmax=0; // Number of times the current max logp has been seen
std::random_device rd; //Will be used to obtain a seed for the random number engine
std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd()
std::uniform_real_distribution<> cunif(0.0, 1.0);

for(g=0;g<ngenus;g++) {
genus_kv = &genus_kmers[g*n_kmers];
Expand Down Expand Up @@ -97,7 +102,8 @@ int get_best_genus(int *karray, double *out_logp, unsigned int arraylen, unsigne
nmax=1;
} else if (max_logp == logp) { // With uniform prob, store if equal to current max
nmax++;
rv = (double) Rcpp::runif(1)[0];
rv = (double) cunif(gen);
///! rv = (double) Rcpp::runif(1)[0];
if(rv < 1.0/nmax) {
max_g = g;
}
Expand Down

0 comments on commit 9a9336e

Please sign in to comment.