From 7043689b8c5602945d54f70c8a7b801bd3140d7d Mon Sep 17 00:00:00 2001 From: Adrian Cantu Date: Mon, 11 Jun 2018 22:32:54 +0000 Subject: [PATCH 01/12] a new way for m4 to pass flags to makefiles --- configure.ac | 2 + m4/ax_boost_system.m4 | 121 +++++++++++ m4/ax_pthread.m4 | 485 ++++++++++++++++++++++++++++++++++++++++++ src/Makefile.in | 22 +- 4 files changed, 627 insertions(+), 3 deletions(-) create mode 100644 m4/ax_boost_system.m4 create mode 100644 m4/ax_pthread.m4 diff --git a/configure.ac b/configure.ac index 433aaee..f5c3341 100644 --- a/configure.ac +++ b/configure.ac @@ -16,9 +16,11 @@ AC_CONFIG_HEADERS([config.h]) AC_PROG_CXX AC_PROG_INSTALL AX_BOOST_BASE([1.41], [], AC_MSG_ERROR([Could not find a useful version of boost])) +AX_BOOST_SYSTEM AX_BOOST_FILESYSTEM AX_BOOST_IOSTREAMS AX_CHECK_ZLIB +AX_PTHREAD # Checks for libraries. diff --git a/m4/ax_boost_system.m4 b/m4/ax_boost_system.m4 new file mode 100644 index 0000000..207d7be --- /dev/null +++ b/m4/ax_boost_system.m4 @@ -0,0 +1,121 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_boost_system.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_BOOST_SYSTEM +# +# DESCRIPTION +# +# Test for System library from the Boost C++ libraries. The macro requires +# a preceding call to AX_BOOST_BASE. Further documentation is available at +# . +# +# This macro calls: +# +# AC_SUBST(BOOST_SYSTEM_LIB) +# +# And sets: +# +# HAVE_BOOST_SYSTEM +# +# LICENSE +# +# Copyright (c) 2008 Thomas Porschberg +# Copyright (c) 2008 Michael Tindal +# Copyright (c) 2008 Daniel Casimiro +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 19 + +AC_DEFUN([AX_BOOST_SYSTEM], +[ + AC_ARG_WITH([boost-system], + AS_HELP_STRING([--with-boost-system@<:@=special-lib@:>@], + [use the System library from boost - it is possible to specify a certain library for the linker + e.g. --with-boost-system=boost_system-gcc-mt ]), + [ + if test "$withval" = "no"; then + want_boost="no" + elif test "$withval" = "yes"; then + want_boost="yes" + ax_boost_user_system_lib="" + else + want_boost="yes" + ax_boost_user_system_lib="$withval" + fi + ], + [want_boost="yes"] + ) + + if test "x$want_boost" = "xyes"; then + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_BUILD]) + CPPFLAGS_SAVED="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" + export CPPFLAGS + + LDFLAGS_SAVED="$LDFLAGS" + LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" + export LDFLAGS + + AC_CACHE_CHECK(whether the Boost::System library is available, + ax_cv_boost_system, + [AC_LANG_PUSH([C++]) + CXXFLAGS_SAVE=$CXXFLAGS + CXXFLAGS= + + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include ]], + [[boost::system::error_category *a = 0;]])], + ax_cv_boost_system=yes, ax_cv_boost_system=no) + CXXFLAGS=$CXXFLAGS_SAVE + AC_LANG_POP([C++]) + ]) + if test "x$ax_cv_boost_system" = "xyes"; then + AC_SUBST(BOOST_CPPFLAGS) + + AC_DEFINE(HAVE_BOOST_SYSTEM,,[define if the Boost::System library is available]) + BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'` + + LDFLAGS_SAVE=$LDFLAGS + if test "x$ax_boost_user_system_lib" = "x"; then + for libextension in `ls -r $BOOSTLIBDIR/libboost_system* 2>/dev/null | sed 's,.*/lib,,' | sed 's,\..*,,'` ; do + ax_lib=${libextension} + AC_CHECK_LIB($ax_lib, exit, + [BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break], + [link_system="no"]) + done + if test "x$link_system" != "xyes"; then + for libextension in `ls -r $BOOSTLIBDIR/boost_system* 2>/dev/null | sed 's,.*/,,' | sed -e 's,\..*,,'` ; do + ax_lib=${libextension} + AC_CHECK_LIB($ax_lib, exit, + [BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break], + [link_system="no"]) + done + fi + + else + for ax_lib in $ax_boost_user_system_lib boost_system-$ax_boost_user_system_lib; do + AC_CHECK_LIB($ax_lib, exit, + [BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break], + [link_system="no"]) + done + + fi + if test "x$ax_lib" = "x"; then + AC_MSG_ERROR(Could not find a version of the library!) + fi + if test "x$link_system" = "xno"; then + AC_MSG_ERROR(Could not link against $ax_lib !) + fi + fi + + CPPFLAGS="$CPPFLAGS_SAVED" + LDFLAGS="$LDFLAGS_SAVED" + fi +]) diff --git a/m4/ax_pthread.m4 b/m4/ax_pthread.m4 new file mode 100644 index 0000000..5fbf9fe --- /dev/null +++ b/m4/ax_pthread.m4 @@ -0,0 +1,485 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_pthread.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) +# +# DESCRIPTION +# +# This macro figures out how to build C programs using POSIX threads. It +# sets the PTHREAD_LIBS output variable to the threads library and linker +# flags, and the PTHREAD_CFLAGS output variable to any special C compiler +# flags that are needed. (The user can also force certain compiler +# flags/libs to be tested by setting these environment variables.) +# +# Also sets PTHREAD_CC to any special C compiler that is needed for +# multi-threaded programs (defaults to the value of CC otherwise). (This +# is necessary on AIX to use the special cc_r compiler alias.) +# +# NOTE: You are assumed to not only compile your program with these flags, +# but also to link with them as well. For example, you might link with +# $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS +# +# If you are only building threaded programs, you may wish to use these +# variables in your default LIBS, CFLAGS, and CC: +# +# LIBS="$PTHREAD_LIBS $LIBS" +# CFLAGS="$CFLAGS $PTHREAD_CFLAGS" +# CC="$PTHREAD_CC" +# +# In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant +# has a nonstandard name, this macro defines PTHREAD_CREATE_JOINABLE to +# that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX). +# +# Also HAVE_PTHREAD_PRIO_INHERIT is defined if pthread is found and the +# PTHREAD_PRIO_INHERIT symbol is defined when compiling with +# PTHREAD_CFLAGS. +# +# ACTION-IF-FOUND is a list of shell commands to run if a threads library +# is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it +# is not found. If ACTION-IF-FOUND is not specified, the default action +# will define HAVE_PTHREAD. +# +# Please let the authors know if this macro fails on any platform, or if +# you have any other suggestions or comments. This macro was based on work +# by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help +# from M. Frigo), as well as ac_pthread and hb_pthread macros posted by +# Alejandro Forero Cuervo to the autoconf macro repository. We are also +# grateful for the helpful feedback of numerous users. +# +# Updated for Autoconf 2.68 by Daniel Richard G. +# +# LICENSE +# +# Copyright (c) 2008 Steven G. Johnson +# Copyright (c) 2011 Daniel Richard G. +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation, either version 3 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . +# +# As a special exception, the respective Autoconf Macro's copyright owner +# gives unlimited permission to copy, distribute and modify the configure +# scripts that are the output of Autoconf when processing the Macro. You +# need not follow the terms of the GNU General Public License when using +# or distributing such scripts, even though portions of the text of the +# Macro appear in them. The GNU General Public License (GPL) does govern +# all other use of the material that constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the Autoconf +# Macro released by the Autoconf Archive. When you make and distribute a +# modified version of the Autoconf Macro, you may extend this special +# exception to the GPL to apply to your modified version as well. + +#serial 24 + +AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD]) +AC_DEFUN([AX_PTHREAD], [ +AC_REQUIRE([AC_CANONICAL_HOST]) +AC_REQUIRE([AC_PROG_CC]) +AC_REQUIRE([AC_PROG_SED]) +AC_LANG_PUSH([C]) +ax_pthread_ok=no + +# We used to check for pthread.h first, but this fails if pthread.h +# requires special compiler flags (e.g. on Tru64 or Sequent). +# It gets checked for in the link test anyway. + +# First of all, check if the user has set any of the PTHREAD_LIBS, +# etcetera environment variables, and if threads linking works using +# them: +if test "x$PTHREAD_CFLAGS$PTHREAD_LIBS" != "x"; then + ax_pthread_save_CC="$CC" + ax_pthread_save_CFLAGS="$CFLAGS" + ax_pthread_save_LIBS="$LIBS" + AS_IF([test "x$PTHREAD_CC" != "x"], [CC="$PTHREAD_CC"]) + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + LIBS="$PTHREAD_LIBS $LIBS" + AC_MSG_CHECKING([for pthread_join using $CC $PTHREAD_CFLAGS $PTHREAD_LIBS]) + AC_LINK_IFELSE([AC_LANG_CALL([], [pthread_join])], [ax_pthread_ok=yes]) + AC_MSG_RESULT([$ax_pthread_ok]) + if test "x$ax_pthread_ok" = "xno"; then + PTHREAD_LIBS="" + PTHREAD_CFLAGS="" + fi + CC="$ax_pthread_save_CC" + CFLAGS="$ax_pthread_save_CFLAGS" + LIBS="$ax_pthread_save_LIBS" +fi + +# We must check for the threads library under a number of different +# names; the ordering is very important because some systems +# (e.g. DEC) have both -lpthread and -lpthreads, where one of the +# libraries is broken (non-POSIX). + +# Create a list of thread flags to try. Items starting with a "-" are +# C compiler flags, and other items are library names, except for "none" +# which indicates that we try without any flags at all, and "pthread-config" +# which is a program returning the flags for the Pth emulation library. + +ax_pthread_flags="pthreads none -Kthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" + +# The ordering *is* (sometimes) important. Some notes on the +# individual items follow: + +# pthreads: AIX (must check this before -lpthread) +# none: in case threads are in libc; should be tried before -Kthread and +# other compiler flags to prevent continual compiler warnings +# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) +# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads), Tru64 +# (Note: HP C rejects this with "bad form for `-t' option") +# -pthreads: Solaris/gcc (Note: HP C also rejects) +# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it +# doesn't hurt to check since this sometimes defines pthreads and +# -D_REENTRANT too), HP C (must be checked before -lpthread, which +# is present but should not be used directly; and before -mthreads, +# because the compiler interprets this as "-mt" + "-hreads") +# -mthreads: Mingw32/gcc, Lynx/gcc +# pthread: Linux, etcetera +# --thread-safe: KAI C++ +# pthread-config: use pthread-config program (for GNU Pth library) + +case $host_os in + + freebsd*) + + # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) + # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) + + ax_pthread_flags="-kthread lthread $ax_pthread_flags" + ;; + + hpux*) + + # From the cc(1) man page: "[-mt] Sets various -D flags to enable + # multi-threading and also sets -lpthread." + + ax_pthread_flags="-mt -pthread pthread $ax_pthread_flags" + ;; + + openedition*) + + # IBM z/OS requires a feature-test macro to be defined in order to + # enable POSIX threads at all, so give the user a hint if this is + # not set. (We don't define these ourselves, as they can affect + # other portions of the system API in unpredictable ways.) + + AC_EGREP_CPP([AX_PTHREAD_ZOS_MISSING], + [ +# if !defined(_OPEN_THREADS) && !defined(_UNIX03_THREADS) + AX_PTHREAD_ZOS_MISSING +# endif + ], + [AC_MSG_WARN([IBM z/OS requires -D_OPEN_THREADS or -D_UNIX03_THREADS to enable pthreads support.])]) + ;; + + solaris*) + + # On Solaris (at least, for some versions), libc contains stubbed + # (non-functional) versions of the pthreads routines, so link-based + # tests will erroneously succeed. (N.B.: The stubs are missing + # pthread_cleanup_push, or rather a function called by this macro, + # so we could check for that, but who knows whether they'll stub + # that too in a future libc.) So we'll check first for the + # standard Solaris way of linking pthreads (-mt -lpthread). + + ax_pthread_flags="-mt,pthread pthread $ax_pthread_flags" + ;; +esac + +# GCC generally uses -pthread, or -pthreads on some platforms (e.g. SPARC) + +AS_IF([test "x$GCC" = "xyes"], + [ax_pthread_flags="-pthread -pthreads $ax_pthread_flags"]) + +# The presence of a feature test macro requesting re-entrant function +# definitions is, on some systems, a strong hint that pthreads support is +# correctly enabled + +case $host_os in + darwin* | hpux* | linux* | osf* | solaris*) + ax_pthread_check_macro="_REENTRANT" + ;; + + aix*) + ax_pthread_check_macro="_THREAD_SAFE" + ;; + + *) + ax_pthread_check_macro="--" + ;; +esac +AS_IF([test "x$ax_pthread_check_macro" = "x--"], + [ax_pthread_check_cond=0], + [ax_pthread_check_cond="!defined($ax_pthread_check_macro)"]) + +# Are we compiling with Clang? + +AC_CACHE_CHECK([whether $CC is Clang], + [ax_cv_PTHREAD_CLANG], + [ax_cv_PTHREAD_CLANG=no + # Note that Autoconf sets GCC=yes for Clang as well as GCC + if test "x$GCC" = "xyes"; then + AC_EGREP_CPP([AX_PTHREAD_CC_IS_CLANG], + [/* Note: Clang 2.7 lacks __clang_[a-z]+__ */ +# if defined(__clang__) && defined(__llvm__) + AX_PTHREAD_CC_IS_CLANG +# endif + ], + [ax_cv_PTHREAD_CLANG=yes]) + fi + ]) +ax_pthread_clang="$ax_cv_PTHREAD_CLANG" + +ax_pthread_clang_warning=no + +# Clang needs special handling, because older versions handle the -pthread +# option in a rather... idiosyncratic way + +if test "x$ax_pthread_clang" = "xyes"; then + + # Clang takes -pthread; it has never supported any other flag + + # (Note 1: This will need to be revisited if a system that Clang + # supports has POSIX threads in a separate library. This tends not + # to be the way of modern systems, but it's conceivable.) + + # (Note 2: On some systems, notably Darwin, -pthread is not needed + # to get POSIX threads support; the API is always present and + # active. We could reasonably leave PTHREAD_CFLAGS empty. But + # -pthread does define _REENTRANT, and while the Darwin headers + # ignore this macro, third-party headers might not.) + + PTHREAD_CFLAGS="-pthread" + PTHREAD_LIBS= + + ax_pthread_ok=yes + + # However, older versions of Clang make a point of warning the user + # that, in an invocation where only linking and no compilation is + # taking place, the -pthread option has no effect ("argument unused + # during compilation"). They expect -pthread to be passed in only + # when source code is being compiled. + # + # Problem is, this is at odds with the way Automake and most other + # C build frameworks function, which is that the same flags used in + # compilation (CFLAGS) are also used in linking. Many systems + # supported by AX_PTHREAD require exactly this for POSIX threads + # support, and in fact it is often not straightforward to specify a + # flag that is used only in the compilation phase and not in + # linking. Such a scenario is extremely rare in practice. + # + # Even though use of the -pthread flag in linking would only print + # a warning, this can be a nuisance for well-run software projects + # that build with -Werror. So if the active version of Clang has + # this misfeature, we search for an option to squash it. + + AC_CACHE_CHECK([whether Clang needs flag to prevent "argument unused" warning when linking with -pthread], + [ax_cv_PTHREAD_CLANG_NO_WARN_FLAG], + [ax_cv_PTHREAD_CLANG_NO_WARN_FLAG=unknown + # Create an alternate version of $ac_link that compiles and + # links in two steps (.c -> .o, .o -> exe) instead of one + # (.c -> exe), because the warning occurs only in the second + # step + ax_pthread_save_ac_link="$ac_link" + ax_pthread_sed='s/conftest\.\$ac_ext/conftest.$ac_objext/g' + ax_pthread_link_step=`$as_echo "$ac_link" | sed "$ax_pthread_sed"` + ax_pthread_2step_ac_link="($ac_compile) && (echo ==== >&5) && ($ax_pthread_link_step)" + ax_pthread_save_CFLAGS="$CFLAGS" + for ax_pthread_try in '' -Qunused-arguments -Wno-unused-command-line-argument unknown; do + AS_IF([test "x$ax_pthread_try" = "xunknown"], [break]) + CFLAGS="-Werror -Wunknown-warning-option $ax_pthread_try -pthread $ax_pthread_save_CFLAGS" + ac_link="$ax_pthread_save_ac_link" + AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])], + [ac_link="$ax_pthread_2step_ac_link" + AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])], + [break]) + ]) + done + ac_link="$ax_pthread_save_ac_link" + CFLAGS="$ax_pthread_save_CFLAGS" + AS_IF([test "x$ax_pthread_try" = "x"], [ax_pthread_try=no]) + ax_cv_PTHREAD_CLANG_NO_WARN_FLAG="$ax_pthread_try" + ]) + + case "$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG" in + no | unknown) ;; + *) PTHREAD_CFLAGS="$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG $PTHREAD_CFLAGS" ;; + esac + +fi # $ax_pthread_clang = yes + +if test "x$ax_pthread_ok" = "xno"; then +for ax_pthread_try_flag in $ax_pthread_flags; do + + case $ax_pthread_try_flag in + none) + AC_MSG_CHECKING([whether pthreads work without any flags]) + ;; + + -mt,pthread) + AC_MSG_CHECKING([whether pthreads work with -mt -lpthread]) + PTHREAD_CFLAGS="-mt" + PTHREAD_LIBS="-lpthread" + ;; + + -*) + AC_MSG_CHECKING([whether pthreads work with $ax_pthread_try_flag]) + PTHREAD_CFLAGS="$ax_pthread_try_flag" + ;; + + pthread-config) + AC_CHECK_PROG([ax_pthread_config], [pthread-config], [yes], [no]) + AS_IF([test "x$ax_pthread_config" = "xno"], [continue]) + PTHREAD_CFLAGS="`pthread-config --cflags`" + PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" + ;; + + *) + AC_MSG_CHECKING([for the pthreads library -l$ax_pthread_try_flag]) + PTHREAD_LIBS="-l$ax_pthread_try_flag" + ;; + esac + + ax_pthread_save_CFLAGS="$CFLAGS" + ax_pthread_save_LIBS="$LIBS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + LIBS="$PTHREAD_LIBS $LIBS" + + # Check for various functions. We must include pthread.h, + # since some functions may be macros. (On the Sequent, we + # need a special flag -Kthread to make this header compile.) + # We check for pthread_join because it is in -lpthread on IRIX + # while pthread_create is in libc. We check for pthread_attr_init + # due to DEC craziness with -lpthreads. We check for + # pthread_cleanup_push because it is one of the few pthread + # functions on Solaris that doesn't have a non-functional libc stub. + # We try pthread_create on general principles. + + AC_LINK_IFELSE([AC_LANG_PROGRAM([#include +# if $ax_pthread_check_cond +# error "$ax_pthread_check_macro must be defined" +# endif + static void routine(void *a) { a = 0; } + static void *start_routine(void *a) { return a; }], + [pthread_t th; pthread_attr_t attr; + pthread_create(&th, 0, start_routine, 0); + pthread_join(th, 0); + pthread_attr_init(&attr); + pthread_cleanup_push(routine, 0); + pthread_cleanup_pop(0) /* ; */])], + [ax_pthread_ok=yes], + []) + + CFLAGS="$ax_pthread_save_CFLAGS" + LIBS="$ax_pthread_save_LIBS" + + AC_MSG_RESULT([$ax_pthread_ok]) + AS_IF([test "x$ax_pthread_ok" = "xyes"], [break]) + + PTHREAD_LIBS="" + PTHREAD_CFLAGS="" +done +fi + +# Various other checks: +if test "x$ax_pthread_ok" = "xyes"; then + ax_pthread_save_CFLAGS="$CFLAGS" + ax_pthread_save_LIBS="$LIBS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + LIBS="$PTHREAD_LIBS $LIBS" + + # Detect AIX lossage: JOINABLE attribute is called UNDETACHED. + AC_CACHE_CHECK([for joinable pthread attribute], + [ax_cv_PTHREAD_JOINABLE_ATTR], + [ax_cv_PTHREAD_JOINABLE_ATTR=unknown + for ax_pthread_attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do + AC_LINK_IFELSE([AC_LANG_PROGRAM([#include ], + [int attr = $ax_pthread_attr; return attr /* ; */])], + [ax_cv_PTHREAD_JOINABLE_ATTR=$ax_pthread_attr; break], + []) + done + ]) + AS_IF([test "x$ax_cv_PTHREAD_JOINABLE_ATTR" != "xunknown" && \ + test "x$ax_cv_PTHREAD_JOINABLE_ATTR" != "xPTHREAD_CREATE_JOINABLE" && \ + test "x$ax_pthread_joinable_attr_defined" != "xyes"], + [AC_DEFINE_UNQUOTED([PTHREAD_CREATE_JOINABLE], + [$ax_cv_PTHREAD_JOINABLE_ATTR], + [Define to necessary symbol if this constant + uses a non-standard name on your system.]) + ax_pthread_joinable_attr_defined=yes + ]) + + AC_CACHE_CHECK([whether more special flags are required for pthreads], + [ax_cv_PTHREAD_SPECIAL_FLAGS], + [ax_cv_PTHREAD_SPECIAL_FLAGS=no + case $host_os in + solaris*) + ax_cv_PTHREAD_SPECIAL_FLAGS="-D_POSIX_PTHREAD_SEMANTICS" + ;; + esac + ]) + AS_IF([test "x$ax_cv_PTHREAD_SPECIAL_FLAGS" != "xno" && \ + test "x$ax_pthread_special_flags_added" != "xyes"], + [PTHREAD_CFLAGS="$ax_cv_PTHREAD_SPECIAL_FLAGS $PTHREAD_CFLAGS" + ax_pthread_special_flags_added=yes]) + + AC_CACHE_CHECK([for PTHREAD_PRIO_INHERIT], + [ax_cv_PTHREAD_PRIO_INHERIT], + [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]], + [[int i = PTHREAD_PRIO_INHERIT;]])], + [ax_cv_PTHREAD_PRIO_INHERIT=yes], + [ax_cv_PTHREAD_PRIO_INHERIT=no]) + ]) + AS_IF([test "x$ax_cv_PTHREAD_PRIO_INHERIT" = "xyes" && \ + test "x$ax_pthread_prio_inherit_defined" != "xyes"], + [AC_DEFINE([HAVE_PTHREAD_PRIO_INHERIT], [1], [Have PTHREAD_PRIO_INHERIT.]) + ax_pthread_prio_inherit_defined=yes + ]) + + CFLAGS="$ax_pthread_save_CFLAGS" + LIBS="$ax_pthread_save_LIBS" + + # More AIX lossage: compile with *_r variant + if test "x$GCC" != "xyes"; then + case $host_os in + aix*) + AS_CASE(["x/$CC"], + [x*/c89|x*/c89_128|x*/c99|x*/c99_128|x*/cc|x*/cc128|x*/xlc|x*/xlc_v6|x*/xlc128|x*/xlc128_v6], + [#handle absolute path differently from PATH based program lookup + AS_CASE(["x$CC"], + [x/*], + [AS_IF([AS_EXECUTABLE_P([${CC}_r])],[PTHREAD_CC="${CC}_r"])], + [AC_CHECK_PROGS([PTHREAD_CC],[${CC}_r],[$CC])])]) + ;; + esac + fi +fi + +test -n "$PTHREAD_CC" || PTHREAD_CC="$CC" + +AC_SUBST([PTHREAD_LIBS]) +AC_SUBST([PTHREAD_CFLAGS]) +AC_SUBST([PTHREAD_CC]) + +# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: +if test "x$ax_pthread_ok" = "xyes"; then + ifelse([$1],,[AC_DEFINE([HAVE_PTHREAD],[1],[Define if you have POSIX threads libraries and header files.])],[$1]) + : +else + ax_pthread_ok=no + $2 +fi +AC_LANG_POP +])dnl AX_PTHREAD diff --git a/src/Makefile.in b/src/Makefile.in index 2581d34..528e835 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -11,12 +11,28 @@ bindir = @bindir@ # VPATH-related substitution variables srcdir = @srcdir@ VPATH = @srcdir@ - -CXXFLAGS = -std=c++11 -Wall -O3 -pthread -lboost_filesystem -lboost_system -lboost_iostreams -lz +CXX=@CXX@ +CXXFLAGS=@CXXFLAGS@ @PTHREAD_CFLAGS@ +LIBS=@LIBS@ @BOOST_SYSTEM_LIB@ @BOOST_FILESYSTEM_LIB@ @BOOST_IOSTREAMS_LIB@ @PTHREAD_LIBS@ +# CXXFLAGS = -std=c++11 -Wall -O3 -pthread -lboost_filesystem -lboost_system -lboost_iostreams -lz all: prinseq++ +echo: + echo @CXX@ + echo @CXXFLAGS@ + echo @LIBS@ + echo @CPPFLAGS@ + echo @LDFLAGS@ + echo @BOOST_FILESYSTEM_LIB@ + echo @BOOST_IOSTREAMS_LIB@ + echo @BOOST_CPPFLAGS@ + echo @BOOSTLIBDIR@ + echo @BOOST_LDFLAGS@ + echo @BOOST_SYSTEM_LIB@ + echo @PTHREAD_CFLAGS@ + comp: prinseq++ time ./prinseq-lite.pl -fastq stenotrophomonas_R1.fastq -fastq2 stenotrophomonas_R2.fastq -min_len 5000 -out_good Test_good -out_bad Test_bad -no_qual_header -ns_max_n 2 -lc_method entropy -lc_threshold 50 -min_gc 40 -max_gc 60 @@ -28,7 +44,7 @@ compp: prinseq++ time -v ./prinseq++ -fastq stenotrophomonas_R1.fastq -fastq2 stenotrophomonas_R2.fastq -min_len 5 -ns_max_n 2 -out_name Test_time_ prinseq++: main.o reads.o verbose.o - $(CXX) main.o reads.o verbose.o $(CXXFLAGS) -o prinseq++ + $(CXX) main.o reads.o verbose.o $(CXXFLAGS) $(LIBS) -o prinseq++ main.o: main.cpp reads.h bloom_filter.hpp verbose.h reads.o: reads.cpp reads.h From 29e1c9a51000186c80d5da85763ce61389eaef9f Mon Sep 17 00:00:00 2001 From: Adrian Cantu Date: Tue, 12 Jun 2018 20:21:09 +0000 Subject: [PATCH 02/12] added options to name each output file independentlly --- src/main.cpp | 79 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 69 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 6c2afd8..7a6a241 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -83,6 +83,9 @@ pthread_mutex_t read_mutex4=PTHREAD_MUTEX_INITIALIZER; //derep filter int verbosity=1; std::string line; + + std::string out_good_1_name, out_good_2_name, out_single_1_name, + out_single_2_name, out_bad_1_name,out_bad_2_name; struct option longopts[] = { { "fastq" , required_argument , NULL , 1 }, @@ -115,6 +118,12 @@ pthread_mutex_t read_mutex4=PTHREAD_MUTEX_INITIALIZER; //derep filter { "version" , no_argument , &ver , 1 }, { "FASTA" , no_argument , &fasta_in, 1 }, { "VERBOSE" , required_argument , NULL , 23 }, + { "out_good" , required_argument , NULL , 24 }, + { "out_good2" , required_argument , NULL , 25 }, + { "out_single" , required_argument , NULL , 26 }, + { "out_single2" , required_argument , NULL , 27 }, + { "out_bad" , required_argument , NULL , 28 }, + { "out_bad2" , required_argument , NULL , 29 }, {0,0,0,0} }; @@ -229,6 +238,24 @@ int main (int argc, char **argv) case 23: verbosity=atoi(optarg); break; + case 24: + out_good_1_name=optarg; + break; + case 25: + out_good_2_name=optarg; + break; + case 26: + out_single_1_name=optarg; + break; + case 27: + out_single_2_name=optarg; + break; + case 28: + out_bad_1_name=optarg; + break; + case 29: + out_bad_2_name=optarg; + break; case 0: // getopt set a variable break; @@ -340,14 +367,38 @@ int main (int argc, char **argv) if (out_format == 1 ) { out_ext = "fasta";} if (out_gz == 1 ) { out_ext = out_ext + ".gz"; } - if (reverse_read_file) { - tmp_bad_out_file_R1= new std::ofstream(out_name + "_bad_out_R1." + out_ext ); - tmp_single_out_file_R1= new std::ofstream(out_name + "_single_out_R1." + out_ext ); - tmp_good_out_file_R1= new std::ofstream(out_name + "_good_out_R1." + out_ext); - tmp_bad_out_file_R2= new std::ofstream(out_name + "_bad_out_R2." + out_ext ); - tmp_single_out_file_R2= new std::ofstream(out_name + "_single_out_R2." + out_ext); - tmp_good_out_file_R2= new std::ofstream(out_name + "_good_out_R2." + out_ext); - if (out_gz) { + if (reverse_read_file) { //set output names + if (!out_bad_1_name.empty()){ + tmp_bad_out_file_R1= new std::ofstream(out_bad_1_name); + } else { + tmp_bad_out_file_R1= new std::ofstream(out_name + "_bad_out_R1." + out_ext ); + } + if (!out_single_1_name.empty()) { + tmp_single_out_file_R1= new std::ofstream(out_single_1_name); + } else { + tmp_single_out_file_R1= new std::ofstream(out_name + "_single_out_R1." + out_ext ); + } + if (!out_good_1_name.empty()) { + tmp_good_out_file_R1= new std::ofstream(out_good_1_name); + } else { + tmp_good_out_file_R1= new std::ofstream(out_name + "_good_out_R1." + out_ext); + } + if (!out_bad_2_name.empty()) { + tmp_bad_out_file_R2= new std::ofstream(out_bad_2_name); + } else { + tmp_bad_out_file_R2= new std::ofstream(out_name + "_bad_out_R2." + out_ext ); + } + if (!out_single_2_name.empty()) { + tmp_single_out_file_R2= new std::ofstream(out_single_2_name); + } else { + tmp_single_out_file_R2= new std::ofstream(out_name + "_single_out_R2." + out_ext); + } + if (!out_good_2_name.empty()) { + tmp_good_out_file_R2= new std::ofstream(out_good_2_name); + } else { + tmp_good_out_file_R2= new std::ofstream(out_name + "_good_out_R2." + out_ext); + } + if (out_gz) { //add a compressor to the output out_bad_R1_buf.push(boost::iostreams::gzip_compressor()); out_bad_R2_buf.push(boost::iostreams::gzip_compressor()); out_single_R1_buf.push(boost::iostreams::gzip_compressor()); @@ -371,8 +422,16 @@ int main (int argc, char **argv) } else { - tmp_good_out_file_R1= new std::ofstream(out_name + "_good_out." + out_ext); - tmp_bad_out_file_R1= new std::ofstream(out_name + "_bad_out." + out_ext); + if (!out_good_1_name.empty()) { + tmp_good_out_file_R1= new std::ofstream(out_good_1_name); + } else { + tmp_good_out_file_R1= new std::ofstream(out_name + "_good_out." + out_ext); + } + if (!out_bad_1_name.empty()){ + tmp_bad_out_file_R1= new std::ofstream(out_bad_1_name); + } else { + tmp_bad_out_file_R1= new std::ofstream(out_name + "_bad_out." + out_ext ); + } if (out_gz) { out_good_R1_buf.push(boost::iostreams::gzip_compressor()); out_bad_R1_buf.push(boost::iostreams::gzip_compressor()); From f450537b41975f24d7812eaedf4f5b27599015c3 Mon Sep 17 00:00:00 2001 From: Adrian Cantu Date: Tue, 12 Jun 2018 20:33:04 +0000 Subject: [PATCH 03/12] added documentation for individually renaming output files --- README.md | 9 ++++++++- README.md.in | 9 ++++++++- src/main.cpp | 6 ++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 950c8e0..a3eac58 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,14 @@ If you want to edit the source code, clone this repository. not change the header in the 1st line (@header). -out_gz - Write the output to a compressed file (WARNING this can be really SLOW) + Write the output to a compressed file (WARNING this can be really SLOW, + will be fixed in a future release) + + -out_good , -out_single , -out_bad, + -out_good2 , -out_single2, -out_bad2 + Rename the output files idividually, this overwrites the names given by + -out_name only for the selected files. File extension won't be added + automatically. (TIP: if you don't need a file, set its name to /dev/null) ***** FILTER OPTION ****** diff --git a/README.md.in b/README.md.in index ed8a5f7..cfd7bc9 100644 --- a/README.md.in +++ b/README.md.in @@ -83,7 +83,14 @@ If you want to edit the source code, clone this repository. not change the header in the 1st line (@header). -out_gz - Write the output to a compressed file (WARNING this can be really SLOW) + Write the output to a compressed file (WARNING this can be really SLOW, + will be fixed in a future release) + + -out_good , -out_single , -out_bad, + -out_good2 , -out_single2, -out_bad2 + Rename the output files idividually, this overwrites the names given by + -out_name only for the selected files. File extension won't be added + automatically. (TIP: if you don't need a file, set its name to /dev/null) ***** FILTER OPTION ****** diff --git a/src/main.cpp b/src/main.cpp index 7a6a241..fe0fec9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -668,6 +668,12 @@ reducing the use of hard drive. -out_gz Write the output to a compressed file (WARNING this can be really SLOW) + -out_good , -out_single , -out_bad, + -out_good2 , -out_single2, -out_bad2 + Rename the output files idividually, this overwrites the names given by + -out_name only for the selected files. File extension won't be added + automatically. (TIP: if you don't need a file, set its name to /dev/null) + ***** FILTER OPTION ****** -min_len From d117b6533cf0507acb3d4b0a97eedafb556742af Mon Sep 17 00:00:00 2001 From: Adrian Cantu Date: Tue, 12 Jun 2018 21:57:45 +0000 Subject: [PATCH 04/12] fixed if two output files have the same name --- src/main.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index fe0fec9..91a9b14 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -398,6 +398,37 @@ int main (int argc, char **argv) } else { tmp_good_out_file_R2= new std::ofstream(out_name + "_good_out_R2." + out_ext); } + // correct for files with same name + if (!out_bad_1_name.empty()) { + if (out_bad_1_name==out_single_1_name ) {tmp_single_out_file_R1 = tmp_bad_out_file_R1;} + if (out_bad_1_name==out_good_1_name ) {tmp_good_out_file_R1 = tmp_bad_out_file_R1;} + if (out_bad_1_name==out_bad_2_name ) {tmp_bad_out_file_R2 = tmp_bad_out_file_R1;} + if (out_bad_1_name==out_single_2_name ) {tmp_single_out_file_R2 = tmp_bad_out_file_R1;} + if (out_bad_1_name==out_good_2_name ) {tmp_good_out_file_R2 = tmp_bad_out_file_R1;} + } + + if (!out_single_1_name.empty()) { + if (out_single_1_name==out_good_1_name ) {tmp_good_out_file_R1 = tmp_single_out_file_R1;} + if (out_single_1_name==out_bad_2_name ) {tmp_bad_out_file_R2 = tmp_single_out_file_R1;} + if (out_single_1_name==out_single_2_name ) {tmp_single_out_file_R2 = tmp_single_out_file_R1;} + if (out_single_1_name==out_good_2_name ) {tmp_good_out_file_R2 = tmp_single_out_file_R1;} + } + + if (!out_good_1_name.empty()) { + if (out_good_1_name == out_bad_2_name) {tmp_bad_out_file_R2 = tmp_good_out_file_R1;} + if (out_good_1_name == out_single_2_name) {tmp_single_out_file_R2 = tmp_good_out_file_R1;} + if (out_good_1_name == out_good_2_name) {tmp_good_out_file_R2 = tmp_good_out_file_R1;} + } + + if (!out_bad_2_name.empty()) { + if (out_bad_2_name == out_single_2_name) { tmp_single_out_file_R2 = tmp_bad_out_file_R2;} + if (out_bad_2_name == out_good_2_name) { tmp_good_out_file_R2 = tmp_bad_out_file_R2;} + } + + if (!out_single_2_name.empty()) { + if (out_single_2_name == out_good_2_name) { tmp_good_out_file_R2 = tmp_single_out_file_R2;} + } + if (out_gz) { //add a compressor to the output out_bad_R1_buf.push(boost::iostreams::gzip_compressor()); out_bad_R2_buf.push(boost::iostreams::gzip_compressor()); @@ -432,6 +463,8 @@ int main (int argc, char **argv) } else { tmp_bad_out_file_R1= new std::ofstream(out_name + "_bad_out." + out_ext ); } + + if ((out_bad_1_name==out_good_1_name) && !out_good_1_name.empty() ) {tmp_bad_out_file_R1 = tmp_good_out_file_R1;} if (out_gz) { out_good_R1_buf.push(boost::iostreams::gzip_compressor()); out_bad_R1_buf.push(boost::iostreams::gzip_compressor()); From dde04402556f2ac9280f9e73575bd8647e0a5b00 Mon Sep 17 00:00:00 2001 From: Adrian Cantu Date: Thu, 14 Jun 2018 13:47:32 -0700 Subject: [PATCH 05/12] added header for accumulate --- README.md | 8 ++++---- configure.ac | 2 +- src/reads.cpp | 4 ++++ src/verbose.cpp | 6 +++++- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a3eac58..040677d 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,13 @@ PRINSEQ++ is a C++ implementation of the prinseq-lite.pl program. It can be used 4. pthread ## Download -If you are just interested in compiling and using PRINSEQ++, download the latest [version](https://github.com/Adrian-Cantu/PRINSEQ-plus-plus/releases/download/v1.1/prinseq-plus-plus-1.1.tar.gz). -You can also download the [binary](https://github.com/Adrian-Cantu/PRINSEQ-plus-plus/releases/download/v1.1/binary_prinseq-plus-plus-1.1.tar.gz). +If you are just interested in compiling and using PRINSEQ++, download the latest [version](https://github.com/Adrian-Cantu/PRINSEQ-plus-plus/releases/download/v1.2-devel/prinseq-plus-plus-1.2-devel.tar.gz). +You can also download the [binary](https://github.com/Adrian-Cantu/PRINSEQ-plus-plus/releases/download/v1.2-devel/binary_prinseq-plus-plus-1.2-devel.tar.gz). If you want to edit the source code, clone this repository. ## To install -1. tar -xvf prinseq-plus-plus-1.1.tar.gz -2. cd prinseq-plus-plus-1.1 +1. tar -xvf prinseq-plus-plus-1.2-devel.tar.gz +2. cd prinseq-plus-plus-1.2-devel 3. ./configure 4. make 5. make test diff --git a/configure.ac b/configure.ac index f5c3341..f8089ae 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ([2.69]) -AC_INIT([PRINSEQ++], [1.1], [garbanyo@gmail.com] ,[prinseq-plus-plus], [https://github.com/Adrian-Cantu/PRINSEQ-plus-plus]) +AC_INIT([PRINSEQ++], [1.2-devel], [garbanyo@gmail.com] ,[prinseq-plus-plus], [https://github.com/Adrian-Cantu/PRINSEQ-plus-plus]) ##AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([src/main.cpp]) AC_LANG([C++]) diff --git a/src/reads.cpp b/src/reads.cpp index 18a3639..9b2c858 100644 --- a/src/reads.cpp +++ b/src/reads.cpp @@ -26,7 +26,11 @@ #include "reads.h" #include #include + +#ifndef NUMERIC +#define NUMERIC #include +#endif using namespace std; diff --git a/src/verbose.cpp b/src/verbose.cpp index 56010d5..9e5900d 100644 --- a/src/verbose.cpp +++ b/src/verbose.cpp @@ -5,6 +5,10 @@ #include #endif +#ifndef NUMERIC +#define NUMERIC +#include +#endif //#include "reads.h" //#include @@ -84,4 +88,4 @@ void verbose::print(void){ std::cout << total_trim_qual_left << std::endl; std::cout << total_trim_qual_right<< std::endl; } -} \ No newline at end of file +} From 57e5ebe52408613376b154f803a2e5613950b149 Mon Sep 17 00:00:00 2001 From: Adrian Cantu Date: Thu, 28 Jun 2018 15:28:36 -0700 Subject: [PATCH 06/12] added phred64 option --- src/main.cpp | 23 +++++++++++++---------- src/reads.cpp | 22 ++++++++++++---------- src/reads.h | 7 +++---- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 91a9b14..b850850 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -81,6 +81,7 @@ pthread_mutex_t read_mutex4=PTHREAD_MUTEX_INITIALIZER; //derep filter int ver=0; int fasta_in=0; int verbosity=1; + int read_mode=33; std::string line; @@ -118,12 +119,13 @@ pthread_mutex_t read_mutex4=PTHREAD_MUTEX_INITIALIZER; //derep filter { "version" , no_argument , &ver , 1 }, { "FASTA" , no_argument , &fasta_in, 1 }, { "VERBOSE" , required_argument , NULL , 23 }, - { "out_good" , required_argument , NULL , 24 }, - { "out_good2" , required_argument , NULL , 25 }, - { "out_single" , required_argument , NULL , 26 }, - { "out_single2" , required_argument , NULL , 27 }, - { "out_bad" , required_argument , NULL , 28 }, - { "out_bad2" , required_argument , NULL , 29 }, + { "out_good" , required_argument , NULL , 24 }, + { "out_good2" , required_argument , NULL , 25 }, + { "out_single" , required_argument , NULL , 26 }, + { "out_single2" , required_argument , NULL , 27 }, + { "out_bad" , required_argument , NULL , 28 }, + { "out_bad2" , required_argument , NULL , 29 }, + { "phred64" , no_argument , &read_mode, 64}, {0,0,0,0} }; @@ -504,7 +506,7 @@ int main (int argc, char **argv) vector ttt2(threads); for (ii=0 ; ii set_outputs(*bad_out_file_R1,*single_out_file_R1,*good_out_file_R1,*bad_out_file_R2,*single_out_file_R2,*good_out_file_R2); v2[ii]-> set_out_format(out_format); ttt2[ii].read= v2[ii]; @@ -523,7 +525,7 @@ int main (int argc, char **argv) /////////////////////////////////////////// for single end } else { //////////// pthreads magic - vector v(threads,*inFile_f); + vector v(threads); vector tthreads(threads); vector ttt(threads); // declare structure for the thread @@ -532,8 +534,9 @@ int main (int argc, char **argv) for (ii=0 ; iiset_outputs(*bad_out_file_R1,*bad_out_file_R1,*good_out_file_R1); + ttt[ii].read= v[ii]; ttt[ii].filter= filter; ttt[ii].thread_id=ii; diff --git a/src/reads.cpp b/src/reads.cpp index 9b2c858..74dacca 100644 --- a/src/reads.cpp +++ b/src/reads.cpp @@ -34,7 +34,7 @@ using namespace std; -single_read::single_read(istream &is): file1(is) { +single_read::single_read(istream &is, int mode): file1(is) , qual_mode(mode) { fastq_to_fasta.assign("^@"); out_stream = new ostream(nullptr); } @@ -42,6 +42,7 @@ single_read::single_read(istream &is): file1(is) { single_read::single_read(void) : file1(cin){ // starndar input fastq_to_fasta.assign("^@"); out_stream = new ostream(nullptr); + qual_mode=33; } /** \brief Set or change inmput stream. @@ -176,7 +177,7 @@ int single_read::min_qual_score(int min_qual) { int i; if (read_status==2) {return 0;} for(i = seq_qual.size()-1; i >= 0; --i) { - score=int(seq_qual[i])-33; + score=int(seq_qual[i])-qual_mode; if (score < min_qual) { single_read::set_read_status(2); return 1; @@ -207,7 +208,7 @@ int single_read::min_qual_mean(int min_qual) { float average=0; if (read_status==2) {return 0;} for(std::string::size_type i = seq_qual.size()-1; i > 0; --i) { - score=int(seq_qual[i])-33; + score=int(seq_qual[i])-qual_mode; average= average + score; } average=average/seq_qual.size(); @@ -414,7 +415,7 @@ int single_read::trim_qual_right(string type, string rule, int step, int window_ int score; vector vals; for(int i = window.size()-1; i >= 0; --i) { - score=int(window[i])-33; + score=int(window[i])-qual_mode; vals.push_back(score); } float compare; @@ -465,7 +466,7 @@ int single_read::trim_qual_left(string type, string rule, int step, int window_s int score; vector vals; for(int i = window.size()-1; i >= 0; --i) { - score=int(window[i])-33; + score=int(window[i])-qual_mode; vals.push_back(score); } float compare; @@ -545,21 +546,22 @@ int single_read::trim_tail_right(int num) { return 0; } + ////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// - pair_read::pair_read(istream &is1, istream &is2): file1(is1),file2(is2) { + pair_read::pair_read(istream &is1, istream &is2, int mode): file1(is1),file2(is2) { - read1= new single_read(file1); - read2= new single_read(file2); + read1= new single_read(file1,mode); + read2= new single_read(file2,mode); } pair_read::pair_read(void):file1(cin),file2(cin) { - read1= new single_read(file1); - read2= new single_read(file2); + read1= new single_read(file1,33); + read2= new single_read(file2,33); } void pair_read::set_inputs(istream &read_f,istream &read_r) { diff --git a/src/reads.h b/src/reads.h index 63b0ca3..6983229 100644 --- a/src/reads.h +++ b/src/reads.h @@ -30,12 +30,11 @@ using namespace std; */ class single_read { public: - single_read(istream &is); + single_read(istream &is, int mode); single_read(void); void set_inputs(istream &is); void set_outputs(ostream& bad_out_file, ostream& single_out_file, ostream& good_out_file); int read_read(pthread_mutex_t * read_mutex, int format); - //filter int ns_max_n(int ns_max_n); // int max_n_p(int ns_max_p); @@ -59,7 +58,7 @@ class single_read { int trim_tail_right(int num); void print(int out_form); - + int qual_mode; int get_read_status(void); void set_read_status(int status); @@ -90,7 +89,7 @@ class single_read { */ class pair_read { public: - pair_read(istream &is1, istream &is2); + pair_read(istream &is1, istream &is2, int mode); pair_read(void); void set_inputs(istream &read_f,istream &read_r); int read_read(pthread_mutex_t* read_mutex_1, pthread_mutex_t* read_mutex_2,pthread_mutex_t* read_mutex3, int format); From 26475202436fffd8be279b26e19d663a67928ff8 Mon Sep 17 00:00:00 2001 From: Adrian Cantu Date: Fri, 29 Jun 2018 22:23:52 +0000 Subject: [PATCH 07/12] added U to the iupac basses --- src/reads.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reads.cpp b/src/reads.cpp index 74dacca..d8c5843 100644 --- a/src/reads.cpp +++ b/src/reads.cpp @@ -224,7 +224,7 @@ int single_read::min_qual_mean(int min_qual) { */ int single_read::noiupac() { if (read_status==2) {return 0;} - regex pattern("^[ACGTN]+$", regex::icase); + regex pattern("^[ACGTUN]+$", regex::icase); if (!regex_search(seq_seq,pattern)) { single_read::set_read_status(2); return 1; From 1af5e9dd74614aace38cb736bd5c25add9d30510 Mon Sep 17 00:00:00 2001 From: Adrian Cantu Date: Wed, 11 Jul 2018 14:08:35 +0000 Subject: [PATCH 08/12] corrected trim left and right --- src/main.cpp | 14 ++++++++++++++ src/reads.cpp | 40 +++++++++++++++++++++++++++++++++++++++- src/reads.h | 4 ++++ src/verbose.cpp | 9 ++++++++- src/verbose.h | 6 +++++- 5 files changed, 70 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b850850..efd54a2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -82,6 +82,8 @@ pthread_mutex_t read_mutex4=PTHREAD_MUTEX_INITIALIZER; //derep filter int fasta_in=0; int verbosity=1; int read_mode=33; + int trim_right; + int trim_left; std::string line; @@ -126,6 +128,8 @@ pthread_mutex_t read_mutex4=PTHREAD_MUTEX_INITIALIZER; //derep filter { "out_bad" , required_argument , NULL , 28 }, { "out_bad2" , required_argument , NULL , 29 }, { "phred64" , no_argument , &read_mode, 64}, + { "trim_right" , required_argument , NULL , 30}, + { "trim_left " , required_argument , NULL , 31}, {0,0,0,0} }; @@ -258,6 +262,12 @@ int main (int argc, char **argv) case 29: out_bad_2_name=optarg; break; + case 30: + trim_left=atoi(optarg); + break; + case 31: + trim_right=atoi(optarg); + break; case 0: // getopt set a variable break; @@ -568,6 +578,8 @@ void* do_single (void * arguments) { int id = args->thread_id; int derep_1; while( read->read_read( &read_mutex,fasta_in)) { + if (trim_left) {(*(verbose_vec->trim_left))[id] += read->trim_left(trim_left);} + if (trim_right) {(*(verbose_vec->trim_right))[id] += read->trim_right(trim_right);} if (trim_tail_left) {(*(verbose_vec->trim_tail_left))[id] += read->trim_tail_left(trim_tail_left);} if (trim_tail_right) {(*(verbose_vec->trim_tail_right))[id] += read->trim_tail_right(trim_tail_right);} if (trim_qual_right) {(*(verbose_vec->trim_qual_right))[id] += read->trim_qual_right("mean","lt",trim_qual_step,trim_qual_window,trim_qual_right_threshold);} @@ -607,6 +619,8 @@ void* do_pair (void * arguments) { int id = args->thread_id; int derep_1, derep_2; //read_rf.read1->trim_qual_right("mean","lt",5,10,30); + if (trim_left ){(*(verbose_vec->trim_left))[id] += read-> trim_left(trim_left); + if (trim_right){(*(verbose_vec->trim_right))[id] += read-> trim_right(trim_right); if (trim_tail_left) {(*(verbose_vec->trim_tail_left))[id] += read->trim_tail_left(trim_tail_left);} if (trim_tail_right) {(*(verbose_vec->trim_tail_right))[id] += read->trim_tail_right(trim_tail_right);} if (trim_qual_right) {(*(verbose_vec->trim_qual_right))[id] += read->trim_qual_right("mean","lt",trim_qual_step,trim_qual_window,trim_qual_right_threshold);} diff --git a/src/reads.cpp b/src/reads.cpp index d8c5843..70cc46f 100644 --- a/src/reads.cpp +++ b/src/reads.cpp @@ -546,6 +546,32 @@ int single_read::trim_tail_right(int num) { return 0; } +int single_read::trim_right(int num) { + if (read_status==2) { return 0;} + int temp_size = seq_seq.size(); + if (num >= temp_size) { + single_read::set_read_status(2); + return 1; + } else { + seq_seq.erase(temp_size-num,num); + seq_qual.erase(temp_size-num,num); + } + return 0; +} + +int single_read::trim_left(int num) { + if (read_status==2) { return 0;} + int temp_size = seq_seq.size(); + if (num >= temp_size) { + single_read::set_read_status(2); + return 1; + } else { + seq_seq.erase(0,num); + seq_qual.erase(0,num); + } + return 0; +} + ////////////////////////////////////////////////////////////////////////////// @@ -669,7 +695,19 @@ int pair_read::trim_tail_right(int num) { int hit = read1->trim_tail_right(num) + read2->trim_tail_right(num); pair_read::auto_set_read_status(); return hit; -} +} + +int pair_read::trim_left(int num) { + int hit = read1->trim_left(num) + read2->trim_left(num); + pair_read::auto_set_read_status(); + return hit; +} + +int pair_read::trim_right(int num) { + int hit = read1->trim_right(num) + read2->trim_right(num); + pair_read::auto_set_read_status(); + return hit; +} void pair_read::rm_header(void) { read1->rm_header(); diff --git a/src/reads.h b/src/reads.h index 6983229..228f6a5 100644 --- a/src/reads.h +++ b/src/reads.h @@ -56,6 +56,8 @@ class single_read { void rm_header(void); int trim_tail_left(int num); int trim_tail_right(int num); + int trim_left(int num); + int trim_right(int num); void print(int out_form); int qual_mode; @@ -116,6 +118,8 @@ class pair_read { void rm_header(void); int trim_tail_left(int num); int trim_tail_right(int num); + int trim_left(int num); + int trim_right(int num); single_read* read1; diff --git a/src/verbose.cpp b/src/verbose.cpp index 9e5900d..ea7bd23 100644 --- a/src/verbose.cpp +++ b/src/verbose.cpp @@ -32,6 +32,8 @@ verbose::verbose(int k, int verb) : threads(k), verbosity(verb) { trim_tail_right= new std::vector(threads,0); trim_qual_left= new std::vector(threads,0); trim_qual_right= new std::vector(threads,0); + trim_left= new std::vector(threads,0); + trim_right= new std::vector(threads,0); } void verbose::accumulate(void) { @@ -51,7 +53,8 @@ void verbose::accumulate(void) { total_trim_tail_right=std::accumulate((*trim_tail_right).begin(), (*trim_tail_right).end(), 0); total_trim_qual_left=std::accumulate((*trim_qual_left).begin(), (*trim_qual_left).end(), 0); total_trim_qual_right=std::accumulate((*trim_qual_right).begin(), (*trim_qual_right).end(), 0); - + total_trim_left=std::accumulate((*trim_left).begin(), (*trim_left).end(), 0); + total_trim_right=std::accumulate((*trim_right).begin(), (*trim_right).end(), 0); } void verbose::print(void){ @@ -71,6 +74,8 @@ void verbose::print(void){ if (total_trim_tail_right) { std::cout << total_trim_tail_right <<" reads removed by -trim_tail_right" << std::endl;} if (total_trim_qual_left) { std::cout << total_trim_qual_left <<" reads removed by -trim_qual_left" << std::endl;} if (total_trim_qual_right) { std::cout << total_trim_qual_right <<" reads removed by -trim_qual_right" << std::endl;} + if (total_trim_left) { std::cout << total_trim_left <<" reads removed by -trim_left" << std::endl;} + if (total_trim_right) { std::cout << total_trim_right <<" reads removed by -trim_right" << std::endl;} } else if (verbosity==2) { std::cout << total_min_len << std::endl; std::cout << total_max_len << std::endl; @@ -87,5 +92,7 @@ void verbose::print(void){ std::cout << total_trim_tail_right<< std::endl; std::cout << total_trim_qual_left << std::endl; std::cout << total_trim_qual_right<< std::endl; + std::cout << total_trim_left << std::endl; + std::cout << total_trim_right<< std::endl; } } diff --git a/src/verbose.h b/src/verbose.h index e52e01a..aedc576 100644 --- a/src/verbose.h +++ b/src/verbose.h @@ -42,7 +42,9 @@ class verbose { int total_trim_tail_left; int total_trim_tail_right; int total_trim_qual_left; - int total_trim_qual_right; + int total_trim_qual_right; + int total_trim_right; + int total_trim_left; std::vector* min_len; std::vector* max_len; @@ -59,6 +61,8 @@ class verbose { std::vector* trim_tail_right; std::vector* trim_qual_left; std::vector* trim_qual_right; + std::vector* trim_right; + std::vector* trim_left; int threads; int verbosity; From 10479790bd6bef90c01cefe4419fa6d11199b35b Mon Sep 17 00:00:00 2001 From: Adrian Cantu Date: Wed, 11 Jul 2018 19:24:45 -0700 Subject: [PATCH 09/12] fixed -trim_right -trim_left --- src/main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index efd54a2..6023905 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -128,8 +128,8 @@ pthread_mutex_t read_mutex4=PTHREAD_MUTEX_INITIALIZER; //derep filter { "out_bad" , required_argument , NULL , 28 }, { "out_bad2" , required_argument , NULL , 29 }, { "phred64" , no_argument , &read_mode, 64}, - { "trim_right" , required_argument , NULL , 30}, - { "trim_left " , required_argument , NULL , 31}, + { "trim_left " , required_argument , NULL , 30}, + { "trim_right" , required_argument , NULL , 31}, {0,0,0,0} }; @@ -619,8 +619,8 @@ void* do_pair (void * arguments) { int id = args->thread_id; int derep_1, derep_2; //read_rf.read1->trim_qual_right("mean","lt",5,10,30); - if (trim_left ){(*(verbose_vec->trim_left))[id] += read-> trim_left(trim_left); - if (trim_right){(*(verbose_vec->trim_right))[id] += read-> trim_right(trim_right); + if (trim_left ){(*(verbose_vec->trim_left))[id] += read-> trim_left(trim_left);} + if (trim_right){(*(verbose_vec->trim_right))[id] += read-> trim_right(trim_right);} if (trim_tail_left) {(*(verbose_vec->trim_tail_left))[id] += read->trim_tail_left(trim_tail_left);} if (trim_tail_right) {(*(verbose_vec->trim_tail_right))[id] += read->trim_tail_right(trim_tail_right);} if (trim_qual_right) {(*(verbose_vec->trim_qual_right))[id] += read->trim_qual_right("mean","lt",trim_qual_step,trim_qual_window,trim_qual_right_threshold);} From fe925118fd09caceba58e8632a7cca6d6eebc2bf Mon Sep 17 00:00:00 2001 From: Adrian Cantu Date: Wed, 11 Jul 2018 19:42:51 -0700 Subject: [PATCH 10/12] added new options to readme --- README.md.in | 11 ++++++++++- src/main.cpp | 9 +++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md.in b/README.md.in index cfd7bc9..d21095e 100644 --- a/README.md.in +++ b/README.md.in @@ -66,6 +66,9 @@ If you want to edit the source code, clone this repository. Input is in fasta format (no quality). Note that the output format is still fastq by default. Quality will be treated as 31 (A) for all bases. + -phred64 + Input quality is in phred64 format. This is for older Illumina/Solexa reads. + ***** OUTPUT OPTION ***** -out_format @@ -131,7 +134,13 @@ If you want to edit the source code, clone this repository. the 0-1 interval. (Default=0.5) ***** TRIM OPTIONS ***** - + + -trim_left + Trim bases from the left (5'->3'). + + -trim_right + Trim bases from the right (3'->5'). + -trim_tail_left Trim poly-A/T tail with a minimum length of at the 5'-end. diff --git a/src/main.cpp b/src/main.cpp index 6023905..b847eb9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -698,6 +698,9 @@ reducing the use of hard drive. -FASTA Input is in fasta format (no quality). Note that the output format is still fastq by default. Quality will be treated as 31 (A) for all bases. + + -phred64 + Input quality is in phred64 format. This is for older Illumina/Solexa reads. ***** OUTPUT OPTION ***** @@ -764,6 +767,12 @@ reducing the use of hard drive. ***** TRIM OPTIONS ***** + -trim_left + Trim bases from the left (5'->3'). + + -trim_right + Trim bases from the right (3'->5'). + -trim_tail_left Trim poly-A/T tail with a minimum length of at the 5'-end. From 1221ae8e25f6530230eb51594e57b7b5cb186002 Mon Sep 17 00:00:00 2001 From: Adrian Cantu Date: Wed, 18 Jul 2018 16:09:07 -0700 Subject: [PATCH 11/12] fixed help text for VERBOSE=2 --- README.md | 13 +++++++++++-- README.md.in | 2 +- src/main.cpp | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 040677d..74659ad 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ If you want to edit the source code, clone this repository. on the filters that removed sequences. VERBOSE=2 prints numbers for filters in order (min_len, max_len, min_cg, max_cg, min_qual_score, min_qual_mean, ns_max_n, noiupac, derep, lc_entropy, lc_dust, trim_tail_left, trim_tail_right, - trim_qual_left, trim_qual_right) to compare stats of diferent files. + trim_qual_left, trim_qual_right, trim_left, trim_right) to compare stats of diferent files. VERBOSE=0 prints nothing. (Default=1) @@ -66,6 +66,9 @@ If you want to edit the source code, clone this repository. Input is in fasta format (no quality). Note that the output format is still fastq by default. Quality will be treated as 31 (A) for all bases. + -phred64 + Input quality is in phred64 format. This is for older Illumina/Solexa reads. + ***** OUTPUT OPTION ***** -out_format @@ -131,7 +134,13 @@ If you want to edit the source code, clone this repository. the 0-1 interval. (Default=0.5) ***** TRIM OPTIONS ***** - + + -trim_left + Trim bases from the left (5'->3'). + + -trim_right + Trim bases from the right (3'->5'). + -trim_tail_left Trim poly-A/T tail with a minimum length of at the 5'-end. diff --git a/README.md.in b/README.md.in index d21095e..63657fa 100644 --- a/README.md.in +++ b/README.md.in @@ -49,7 +49,7 @@ If you want to edit the source code, clone this repository. on the filters that removed sequences. VERBOSE=2 prints numbers for filters in order (min_len, max_len, min_cg, max_cg, min_qual_score, min_qual_mean, ns_max_n, noiupac, derep, lc_entropy, lc_dust, trim_tail_left, trim_tail_right, - trim_qual_left, trim_qual_right) to compare stats of diferent files. + trim_qual_left, trim_qual_right, trim_left, trim_right) to compare stats of diferent files. VERBOSE=0 prints nothing. (Default=1) diff --git a/src/main.cpp b/src/main.cpp index b847eb9..87dd35d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -682,7 +682,7 @@ reducing the use of hard drive. on the filters that removed sequences. VERBOSE=2 prints numbers for filters in order (min_len, max_len, min_cg, max_cg, min_qual_score, min_qual_mean, ns_max_n, noiupac, derep, lc_entropy, lc_dust, trim_tail_left, trim_tail_right, - trim_qual_left, trim_qual_right) to compare stats of diferent files. + trim_qual_left, trim_qual_right, trim_left, trim_right) to compare stats of diferent files. VERBOSE=0 prints nothing. (Default=1) From cde96c30a672f6bfb896ac329e1d6b39c75c1204 Mon Sep 17 00:00:00 2001 From: Adrian Cantu Date: Wed, 18 Jul 2018 16:26:16 -0700 Subject: [PATCH 12/12] change version number and changelog --- README.md | 8 ++++---- changelog | 8 ++++++++ configure.ac | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 74659ad..7ccdfa1 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,13 @@ PRINSEQ++ is a C++ implementation of the prinseq-lite.pl program. It can be used 4. pthread ## Download -If you are just interested in compiling and using PRINSEQ++, download the latest [version](https://github.com/Adrian-Cantu/PRINSEQ-plus-plus/releases/download/v1.2-devel/prinseq-plus-plus-1.2-devel.tar.gz). -You can also download the [binary](https://github.com/Adrian-Cantu/PRINSEQ-plus-plus/releases/download/v1.2-devel/binary_prinseq-plus-plus-1.2-devel.tar.gz). +If you are just interested in compiling and using PRINSEQ++, download the latest [version](https://github.com/Adrian-Cantu/PRINSEQ-plus-plus/releases/download/v1.2/prinseq-plus-plus-1.2.tar.gz). +You can also download the [binary](https://github.com/Adrian-Cantu/PRINSEQ-plus-plus/releases/download/v1.2/binary_prinseq-plus-plus-1.2.tar.gz). If you want to edit the source code, clone this repository. ## To install -1. tar -xvf prinseq-plus-plus-1.2-devel.tar.gz -2. cd prinseq-plus-plus-1.2-devel +1. tar -xvf prinseq-plus-plus-1.2.tar.gz +2. cd prinseq-plus-plus-1.2 3. ./configure 4. make 5. make test diff --git a/changelog b/changelog index 0dec561..2153e3a 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,11 @@ +1.2 +- Added -trim_left, -trim_right to trim reads unconditionally +- Added the -phred64 option for old files +- Added -out_good , -out_single , -out_bad, -out_good2 , -out_single2, -out_bad2 + in case you want to manually name output files. unused options default to the default + filename. You can even send two output streams to the same file. +- fixed a bug were -noiupac was filtering RNA sequences. (those containing 'U') + 1.1 Added verbose options and an options to read fasta files. Speed up run time by only performing filters on good reads. diff --git a/configure.ac b/configure.ac index f8089ae..ee6c39c 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ([2.69]) -AC_INIT([PRINSEQ++], [1.2-devel], [garbanyo@gmail.com] ,[prinseq-plus-plus], [https://github.com/Adrian-Cantu/PRINSEQ-plus-plus]) +AC_INIT([PRINSEQ++], [1.2], [garbanyo@gmail.com] ,[prinseq-plus-plus], [https://github.com/Adrian-Cantu/PRINSEQ-plus-plus]) ##AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([src/main.cpp]) AC_LANG([C++])