Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Taxonomy segfault fix #952

Merged
merged 2 commits into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.15.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
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