From 28e3c8f732906b290a809f81a032601612049b5d Mon Sep 17 00:00:00 2001 From: wandai330 Date: Thu, 15 Jun 2017 16:21:16 -0400 Subject: [PATCH 1/3] Fix int type overflow Minimal changes made to fix a couple of total numbers as uint64_t to hold numbers larger than 2 billion --- clipper/Makefile | 8 ++++++-- clipper/fastq-multx.cpp | 10 +++++----- clipper/fastq-stats.cpp | 5 ++++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/clipper/Makefile b/clipper/Makefile index dad4a7f..8e40bf1 100644 --- a/clipper/Makefile +++ b/clipper/Makefile @@ -5,6 +5,7 @@ CC=g++ PREFIX?=/usr BINDIR?=$(PREFIX)/bin CFLAGS?=-O3 -I. +CXXFLAGS=-std=c++0x $(CFLAGS) # for debugging: # CFLAGS?=-g -I. @@ -70,7 +71,7 @@ $(PKG).${VER}-${REL}.tar.gz: $(PKG).tar.gz sparsehash: sparsehash-2.0.3 cd sparsehash-2.0.3; ./configure; make - mkdir sparsehash + mkdir -p sparsehash cp -r sparsehash-2.0.3/src/sparsehash/* sparsehash/ # why the libbam.a doesn't work? not sure... *.o works @@ -94,8 +95,11 @@ else $(CC) $(CFLAGS) fastq-lib.cpp tidx/tidx-lib.cpp -o $@ $< -lgsl -lgslcblas endif +fastq-multx: fastq-multx.cpp fastq-lib.cpp sparsehash + $(CC) $(CXXFLAGS) fastq-multx.cpp fastq-lib.cpp -o $@ + fastq-stats: fastq-stats.cpp fastq-lib.cpp gcModel.cpp sparsehash - $(CC) $(CFLAGS) fastq-lib.cpp gcModel.cpp -o $@ $< + $(CC) $(CXXFLAGS) fastq-lib.cpp gcModel.cpp -o $@ $< bam-filter: bam-filter.cpp $(CC) $(CFLAGS) fastq-lib.cpp -o $@ $< -lbamtools diff --git a/clipper/fastq-multx.cpp b/clipper/fastq-multx.cpp index 6a195ec..35aeec5 100644 --- a/clipper/fastq-multx.cpp +++ b/clipper/fastq-multx.cpp @@ -25,7 +25,7 @@ THE SOFTWARE. See "void usage" below for usage. */ - +#include #include "fastq-lib.h" #define MAX_BARCODE_NUM 6000 @@ -43,7 +43,7 @@ struct bc { char *out[6]; // one output per input FILE *fout[6]; bool gzout[6]; - int cnt; // count found + uint64_t cnt; // count found bool shifted; // count found in 1-shifted position char * dual; // is this a dual-indexed barcode? if so, this points to the second index. int dual_n; // length of dual @@ -1072,9 +1072,9 @@ int main (int argc, char **argv) { int j; printf("Id\tCount\tFile(s)\n"); - int tot=0; + uint64_t tot=0; for (i=0;i<=bcnt;++i) { - printf("%s\t%d", bc[i].id.s, bc[i].cnt); + printf("%s\t%" PRIu64, bc[i].id.s, bc[i].cnt); tot+=bc[i].cnt; for (j=0;j #include +#include void usage( FILE * f ) { fprintf( f, @@ -153,7 +154,7 @@ int window = 2000000; int cyclemax = 35; int gcCyclemax = 100; // to compare with fastqc, seq is rounded to nearest 100 to reduce # of gc models; for < 200 length, this is teh same as max=100 float gcSum; -int gcTotal; +uint64_t gcTotal; int show_max = 10; bool debug = 0; @@ -565,6 +566,8 @@ int main( int argc, char**argv ) { if(gc) { // put these where they belong + if (debug) + printf("gcTotal\t%" PRIu64 "\tgcSum\t%f\n\n", gcTotal, gcSum); printf("pct-gc cycle-max\t%d\n", gcCyclemax); printf("pct-gc mean\t%.2f\n", 100.0 * gcSum / gcTotal); } From dabfc9cb3ccc5355b1e6a196c01bbfd3e69902b7 Mon Sep 17 00:00:00 2001 From: wandai330 Date: Tue, 20 Jun 2017 16:45:32 -0400 Subject: [PATCH 2/3] Some int type variable overflow The maximal number of int type is 2,147,483,648. But now some number could be 5 billion or bigger. Changed those variables to type uint64_t --- clipper/fastq-multx.cpp | 6 +++--- clipper/fastq-stats.cpp | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/clipper/fastq-multx.cpp b/clipper/fastq-multx.cpp index 35aeec5..daf28e1 100644 --- a/clipper/fastq-multx.cpp +++ b/clipper/fastq-multx.cpp @@ -25,7 +25,7 @@ THE SOFTWARE. See "void usage" below for usage. */ -#include + #include "fastq-lib.h" #define MAX_BARCODE_NUM 6000 @@ -1074,7 +1074,7 @@ int main (int argc, char **argv) { printf("Id\tCount\tFile(s)\n"); uint64_t tot=0; for (i=0;i<=bcnt;++i) { - printf("%s\t%" PRIu64, bc[i].id.s, bc[i].cnt); + printf("%s\t%lu", bc[i].id.s, bc[i].cnt); tot+=bc[i].cnt; for (j=0;j #include -#include void usage( FILE * f ) { fprintf( f, @@ -567,7 +566,7 @@ int main( int argc, char**argv ) { if(gc) { // put these where they belong if (debug) - printf("gcTotal\t%" PRIu64 "\tgcSum\t%f\n\n", gcTotal, gcSum); + printf("gcTotal\t%lu\tgcSum\t%f\n\n", gcTotal, gcSum); printf("pct-gc cycle-max\t%d\n", gcCyclemax); printf("pct-gc mean\t%.2f\n", 100.0 * gcSum / gcTotal); } From 12ce1041bf5c0dd73c3482f6d820aff91f44265a Mon Sep 17 00:00:00 2001 From: wandai330 Date: Tue, 20 Jun 2017 16:49:16 -0400 Subject: [PATCH 3/3] Rollback makefile no c++0x flag --- clipper/Makefile | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/clipper/Makefile b/clipper/Makefile index 8e40bf1..dad4a7f 100644 --- a/clipper/Makefile +++ b/clipper/Makefile @@ -5,7 +5,6 @@ CC=g++ PREFIX?=/usr BINDIR?=$(PREFIX)/bin CFLAGS?=-O3 -I. -CXXFLAGS=-std=c++0x $(CFLAGS) # for debugging: # CFLAGS?=-g -I. @@ -71,7 +70,7 @@ $(PKG).${VER}-${REL}.tar.gz: $(PKG).tar.gz sparsehash: sparsehash-2.0.3 cd sparsehash-2.0.3; ./configure; make - mkdir -p sparsehash + mkdir sparsehash cp -r sparsehash-2.0.3/src/sparsehash/* sparsehash/ # why the libbam.a doesn't work? not sure... *.o works @@ -95,11 +94,8 @@ else $(CC) $(CFLAGS) fastq-lib.cpp tidx/tidx-lib.cpp -o $@ $< -lgsl -lgslcblas endif -fastq-multx: fastq-multx.cpp fastq-lib.cpp sparsehash - $(CC) $(CXXFLAGS) fastq-multx.cpp fastq-lib.cpp -o $@ - fastq-stats: fastq-stats.cpp fastq-lib.cpp gcModel.cpp sparsehash - $(CC) $(CXXFLAGS) fastq-lib.cpp gcModel.cpp -o $@ $< + $(CC) $(CFLAGS) fastq-lib.cpp gcModel.cpp -o $@ $< bam-filter: bam-filter.cpp $(CC) $(CFLAGS) fastq-lib.cpp -o $@ $< -lbamtools