├── .gitattributes ├── .github └── workflows │ └── cmake-multi-platform.yml ├── .gitignore ├── .travis.yml ├── CMakeLists.txt ├── LICENSE.txt ├── README.md ├── cmake-modules ├── FindGSL.cmake └── FindLIBQES.cmake ├── docs ├── .gitignore ├── CMakeLists.txt ├── Makefile ├── algorithm.rst ├── conf.py ├── gitversion.py ├── index.rst ├── tutorial.rst ├── usage.rst └── usage.txt ├── src ├── CMakeLists.txt ├── axe.c ├── axe.h ├── axe_config.h.in ├── datrie │ ├── alpha-map-private.h │ ├── alpha-map.c │ ├── alpha-map.h │ ├── darray.c │ ├── darray.h │ ├── dstring-private.h │ ├── dstring.c │ ├── dstring.h │ ├── tail.c │ ├── tail.h │ ├── trie-private.h │ ├── trie-string.c │ ├── trie-string.h │ ├── trie.c │ ├── trie.h │ ├── triedefs.h │ └── typedefs.h ├── gsl │ ├── combination.c │ ├── error.c │ ├── gsl_combination.h │ ├── gsl_errno.h │ ├── gsl_message.h │ ├── init.c │ ├── message.c │ ├── stream.c │ └── strerror.c ├── libqes │ ├── .gitignore │ ├── .gitmodules │ ├── .travis.yml │ ├── AUTHORS │ ├── CMakeLists.txt │ ├── LICENSE │ ├── README.md │ ├── TODO.md │ ├── cmake-modules │ │ ├── CodeCoverage.cmake │ │ ├── FindLIBQES.cmake │ │ ├── GetGitRevisionDescription.cmake │ │ ├── GetGitRevisionDescription.cmake.in │ │ └── GitSemVer.cmake │ ├── src │ │ ├── CMakeLists.txt │ │ ├── crc.c │ │ ├── crc.h │ │ ├── qes.h │ │ ├── qes_compat.c │ │ ├── qes_compat.h │ │ ├── qes_config.h.in │ │ ├── qes_file.c │ │ ├── qes_file.h │ │ ├── qes_libgnu.c │ │ ├── qes_libgnu.h │ │ ├── qes_log.c │ │ ├── qes_log.h │ │ ├── qes_match.c │ │ ├── qes_match.h │ │ ├── qes_seq.c │ │ ├── qes_seq.h │ │ ├── qes_seqfile.c │ │ ├── qes_seqfile.h │ │ ├── qes_sequtil.c │ │ ├── qes_sequtil.h │ │ ├── qes_str.c │ │ ├── qes_str.h │ │ ├── qes_util.c │ │ └── qes_util.h │ ├── test │ │ ├── CMakeLists.txt │ │ ├── benchmarks.c │ │ ├── data │ │ │ ├── bad_diff_lens.fastq │ │ │ ├── bad_nohdr.fastq │ │ │ ├── bad_noqual.fastq │ │ │ ├── bad_noqualhdrchr.fastq │ │ │ ├── bad_noqualhdreol.fastq │ │ │ ├── empty.fastq │ │ │ ├── empty.txt │ │ │ ├── loremipsum.txt │ │ │ ├── loremipsum.txt.gz │ │ │ ├── nocomment.fasta │ │ │ ├── random.bin │ │ │ ├── test.fasta │ │ │ ├── test.fastq │ │ │ ├── test.fastq.bz2 │ │ │ ├── test.fastq.gz │ │ │ ├── test_large.fasta.gz │ │ │ └── truth │ │ │ │ ├── log_test.txt │ │ │ │ ├── qes_seq_print.fa │ │ │ │ └── qes_seq_print.fq │ │ ├── helpers.c │ │ ├── helpers.h │ │ ├── kseq.h │ │ ├── kseqcat.c │ │ ├── logdemo.c │ │ ├── qes_seqcat.c │ │ ├── qes_seqprint.c │ │ ├── test.c │ │ ├── test_file.c │ │ ├── test_helpers.c │ │ ├── test_log.c │ │ ├── test_match.c │ │ ├── test_seq.c │ │ ├── test_seqcats.sh │ │ ├── test_seqfile.c │ │ ├── test_sequtil.c │ │ ├── test_util.c │ │ ├── testdata.c │ │ ├── testdata.h │ │ ├── tests.h │ │ └── tinytest │ │ │ ├── tinytest.c │ │ │ ├── tinytest.h │ │ │ └── tinytest_macros.h │ └── util │ │ ├── make_codon_list.py │ │ └── make_codon_map.py └── main.c ├── tests ├── CMakeLists.txt ├── axe_cli_tests.py ├── data │ ├── fake.barcodes │ ├── fake_0mm_R1.fq.gz │ ├── fake_1mm_R1.fq.gz │ ├── fake_2mm_R1.fq.gz │ ├── gbs.barcodes │ ├── gbs_R1.fastq.gz │ ├── gbs_R2.fastq.gz │ ├── gbs_se.barcodes │ ├── pare.barcodes │ ├── pare.fq.gz │ └── pare_full.fq.gz ├── test.c ├── test_libaxe.c ├── tests.h └── tinytest │ ├── .gitignore │ ├── Makefile │ ├── README │ ├── TODO │ ├── tinytest.c │ ├── tinytest.h │ ├── tinytest_demo.c │ └── tinytest_macros.h └── utils ├── hbb_script.sh └── static_build.sh /.gitattributes: -------------------------------------------------------------------------------- 1 | docs/gitversion.py export-subst 2 | -------------------------------------------------------------------------------- /.github/workflows/cmake-multi-platform.yml: -------------------------------------------------------------------------------- 1 | # This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform. 2 | # See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml 3 | name: CMake on multiple platforms 4 | 5 | on: 6 | push: 7 | branches: [ "master" ] 8 | pull_request: 9 | branches: [ "master" ] 10 | 11 | jobs: 12 | build: 13 | runs-on: ${{ matrix.os }} 14 | 15 | strategy: 16 | # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. 17 | fail-fast: false 18 | 19 | # Set up a matrix to run the following 3 configurations: 20 | # 1. 21 | # 2. 22 | # 3. 23 | # 24 | # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. 25 | matrix: 26 | os: [ubuntu-latest, windows-latest] 27 | build_type: [Release] 28 | c_compiler: [gcc, clang, cl] 29 | include: 30 | - os: windows-latest 31 | c_compiler: cl 32 | cpp_compiler: cl 33 | - os: ubuntu-latest 34 | c_compiler: gcc 35 | cpp_compiler: g++ 36 | - os: ubuntu-latest 37 | c_compiler: clang 38 | cpp_compiler: clang++ 39 | exclude: 40 | - os: windows-latest 41 | c_compiler: gcc 42 | - os: windows-latest 43 | c_compiler: clang 44 | - os: ubuntu-latest 45 | c_compiler: cl 46 | 47 | steps: 48 | - uses: actions/checkout@v4 49 | 50 | - name: Set reusable strings 51 | # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. 52 | id: strings 53 | shell: bash 54 | run: | 55 | echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" 56 | 57 | - name: Configure CMake 58 | # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. 59 | # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type 60 | run: > 61 | cmake -B ${{ steps.strings.outputs.build-output-dir }} 62 | -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} 63 | -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} 64 | -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} 65 | -S ${{ github.workspace }} 66 | 67 | - name: Build 68 | # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). 69 | run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} 70 | 71 | - name: Test 72 | working-directory: ${{ steps.strings.outputs.build-output-dir }} 73 | # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). 74 | # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail 75 | run: ctest --build-config ${{ matrix.build_type }} 76 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Editor temp files 2 | *.swp 3 | *.bak 4 | *~ 5 | 6 | # compiled 7 | build 8 | *.pyc 9 | *.o 10 | *.a 11 | *.so 12 | tags 13 | version 14 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | sudo: required 4 | dist: trusty 5 | 6 | env: 7 | - BUILD_TYPE=Release 8 | - BUILD_TYPE=Debug 9 | 10 | compiler: 11 | - clang 12 | - gcc 13 | 14 | notifications: 15 | email: 16 | - kdmfoss@gmail.com 17 | 18 | install: 19 | - sudo apt-get install zlib1g-dev libgsl0-dev 20 | - mkdir build 21 | - mkdir target 22 | 23 | script: 24 | - cd build 25 | - cmake .. -DCMAKE_INSTALL_PREFIX=../target -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DZLIB_ROOT=$HOME 26 | - make 27 | - ctest --verbose 28 | - make install 29 | - test -f ../target/bin/axe-demux 30 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 3.5...3.31) 2 | PROJECT(axe C) 3 | 4 | LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake-modules") 5 | 6 | # Cmake options 7 | SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 8 | SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 9 | SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 10 | ENABLE_TESTING() 11 | 12 | IF (NOT CMAKE_BUILD_TYPE) 13 | SET(CMAKE_BUILD_TYPE Release) 14 | ENDIF() 15 | 16 | IF (NOT AXE_VERSION) 17 | # git describe as versioning 18 | EXECUTE_PROCESS(COMMAND git describe 19 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 20 | OUTPUT_VARIABLE AXE_VERSION 21 | OUTPUT_STRIP_TRAILING_WHITESPACE) 22 | ENDIF() 23 | 24 | MESSAGE(STATUS "${CMAKE_BUILD_TYPE} build of axe version: ${AXE_VERSION}") 25 | 26 | ############################### 27 | ## Find Packages and Headers ## 28 | ############################### 29 | 30 | FIND_PACKAGE(ZLIB 1.2.5 REQUIRED) 31 | 32 | FIND_PACKAGE(GSL) 33 | 34 | IF (GSL_FOUND) 35 | SET(AXE_DEP_INCLUDES ${GSL_INCLUDE_DIRS}) 36 | SET(AXE_DEP_LIBS ${GSL_LIBRARIES}) 37 | ENDIF() 38 | 39 | 40 | ########################## 41 | ## Set Compiler Options ## 42 | ########################## 43 | 44 | # Set CFLAGS 45 | SET(AXEWRN "${AXEWRN} -fstack-protector-all -Wstack-protector") 46 | SET(AXEWRN "${AXEWRN} -Wall -Wextra -Wpedantic") 47 | 48 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11") 49 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${AXEWRN}") 50 | 51 | INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src 52 | ${PROJECT_SOURCE_DIR}/src/datrie 53 | ${PROJECT_SOURCE_DIR}/src/libqes/src 54 | ${PROJECT_SOURCE_DIR}/src/gsl) 55 | LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/lib) 56 | 57 | INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}) 58 | 59 | CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/src/axe_config.h.in 60 | ${CMAKE_BINARY_DIR}/axe_config.h) 61 | 62 | SET(LIBQES_AS_SUBMODULE True) # stop libqes installing itself 63 | ADD_SUBDIRECTORY(src/libqes) 64 | ADD_SUBDIRECTORY(docs) 65 | ADD_SUBDIRECTORY(tests) 66 | ADD_SUBDIRECTORY(src) 67 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | AXE 2 | === 3 | 4 | > De-multiplex NGS reads using trie data structures. It's fast, and made of tries! 5 | 6 | 7 | 8 | [![DOI](https://zenodo.org/badge/6357/kdmurray91/axe.svg)](https://zenodo.org/badge/latestdoi/6357/kdmurray91/axe) 9 | [![Documentation Status](https://readthedocs.org/projects/axe-demultiplexer/badge/?version=latest)](https://readthedocs.org/projects/axe-demultiplexer/?badge=latest) 10 | [![Join the chat at https://gitter.im/axe-demultipexer/Lobby](https://badges.gitter.im/axe-demultipexer/Lobby.svg)](https://gitter.im/axe-demultipexer/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 11 | 12 | 13 | AXE very rapidly selects the optimal index present in a sequence read, even 14 | in the presence of sequencing errors. The algorithm is able to handle 15 | combinatorial indexing, indexes of differing length, and several mismatches 16 | per index. Benchmarking results indicate far improved accuracy and speed over 17 | existing de-multiplexers. Unscientific trials show AXE processes more than 18 | 500,000 reads per second. 19 | 20 | 21 | Quick Start 22 | ----------- 23 | 24 | ### `conda` 25 | 26 | [![](https://img.shields.io/badge/Anaconda.org-0.3.3-blue.svg?style=flat-square)](https://anaconda.org/kdm801/axe-demultiplexer/) 27 | 28 | ``` 29 | mamba install -c kdm801 axe-demultiplexer 30 | ``` 31 | 32 | 33 | ### From source 34 | 35 | To install on UNIX-like systems (Mac, Linux), get the dependencies (zlib and cmake, see below), and: 36 | 37 | git clone --recursive https://github.com/kdmurray91/axe.git axe 38 | cd axe 39 | cmake . 40 | sudo make install 41 | 42 | A tutorial on the usage of Axe is available at , along with full documentation and a basic description of the algorithm. 43 | 44 | Important Note 45 | -------------- 46 | 47 | **For arcane reasons, the name of the ``axe`` binary changed to ``axe-demux`` 48 | with version 0.3.0. Apologies for the inconvenience, this was required to 49 | make ``axe`` installable in Debian and its derivatives. Command-line usage 50 | did not change.** 51 | 52 | 53 | Installation: 54 | ------------- 55 | 56 | Currently, only recent GNU/Linux systems are officially supported. All code and 57 | the build system is portable, so compilation and use on other systems should be 58 | possible, I just don't have machines available to test. Please report any 59 | installation issues on any system as GitHub bugs and I'll do my best to sort 60 | them out. 61 | 62 | 63 | To install to a prefix, as you would with `./configure --prefix` with the 64 | autotools build system, please use the following cmake command in place of the 65 | one above: 66 | 67 | cmake -DCMAKE_INSTALL_PREFIX=/path/to/your/prefix .. 68 | 69 | e.g.: 70 | 71 | cmake -DCMAKE_INSTALL_PREFIX=$HOME .. 72 | 73 | For me, using `~/` as the prefix will install `axe` under `/home/kevin/bin` on 74 | GNU/Linux, and (if I had one) `/Users/kevin/bin` on Mac OSX.It's also wise to 75 | use `make install` not `sudo make install` when installing to a home directory. 76 | 77 | ### Dependencies: 78 | 79 | - cmake. This is installable via `sudo apt-get install cmake` on Debian based 80 | systems, or `brew install cmake` using homebrew on OS X. 81 | - zlib version >= 1.2.5. On Debian, use the package `zlib1g-dev`. 82 | - libqes, tinytest, libgsl and libdatrie (bundled in source, if you used 83 | `git clone --recursive` or an installation tarball. Otherwise, run 84 | `git submodule update --init`). 85 | 86 | You'll possibly need to install zlib to your chosen prefix (e.g. `~/`) on 87 | supercomputers, which often have very old versions of zlib. To do so: 88 | 89 | wget http://zlib.net/zlib-1.2.8.tar.gz 90 | tar xvf zlib-1.2.8.tar.gz 91 | cd zlib-1.2.8 92 | ./configure --prefix= # e.g. --prefix=$HOME 93 | make && make install 94 | 95 | And then, use the following cmake command, assuming your prefix is `~/`: 96 | 97 | cmake -DCMAKE_INSTALL_PREFIX=$HOME -DZLIB_ROOT=$HOME .. 98 | 99 | 100 | Publication 101 | ----------- 102 | 103 | We have a paper describing AXE published in Bioinformatics https://academic.oup.com/bioinformatics/article/34/22/3924/5026649 104 | A [PDF is available](https://raw.githubusercontent.com/kdm9/axe-paper/master/oxford-final/axe-formatted.pdf?token=GHSAT0AAAAAABVH27O27FSFX47CB5FAUFZ6YV5NNQA) 105 | 106 | Versioning 107 | ---------- 108 | 109 | We use Semantic Versioning. See [semver.org](http://semver.org) 110 | 111 | LICENSE 112 | ------- 113 | 114 | The source of axe itself, namely `src/axe*.[ch]` and `tests/*.[ch]`, is 115 | Copyright 2014-2015 Kevin Murray. All axe source code is licensed under the GNU 116 | GPL version 3 or greater, a copy of which is included with this source as 117 | `LICENCE.txt` 118 | 119 | The source of `tinytest`, located in `tests/tinytest`, is Copyright 2009-2012 120 | Nick Matthewson; `tinytest` is distributed under the 3-clause BSD license. 121 | `tinytest` is hosted at [Nick's github page](https://github.com/nmathewson/tinytest). 122 | 123 | The source of `libgsl`, located in `src/gsl`, is Copyright (C) 1996, 1997, 124 | 1998, 1999, 2000, 2007 Gerard Jungman and Brian Gough. It is licensed under the 125 | GNU General Public License, vesion 3 or greater. 126 | 127 | The source of `libdatrie`, located in `src/datrie`, is Copyright 2006 Theppitak 128 | Karoonboonyanan, and is licensed under the GNU LGPL version 2.1 per 129 | `src/datrie/COPYING`. `libdatrie` is hosted at Theppitak Karoonboonyanan's 130 | website, [here](http://linux.thai.net/~thep/datrie/datrie.html). 131 | -------------------------------------------------------------------------------- /cmake-modules/FindGSL.cmake: -------------------------------------------------------------------------------- 1 | # Try to find gnu scientific library GSL 2 | # See 3 | # http://www.gnu.org/software/gsl/ and 4 | # http://gnuwin32.sourceforge.net/packages/gsl.htm 5 | # 6 | # Based on a script of Felix Woelk and Jan Woetzel 7 | # (www.mip.informatik.uni-kiel.de) 8 | # 9 | # It defines the following variables: 10 | # GSL_FOUND - system has GSL lib 11 | # GSL_INCLUDE_DIRS - where to find headers 12 | # GSL_LIBRARIES - full path to the libraries 13 | # GSL_LIBRARY_DIRS, the directory where the PLplot library is found. 14 | 15 | # CMAKE_GSL_CXX_FLAGS = Unix compiler flags for GSL, essentially "`gsl-config --cxxflags`" 16 | # GSL_LINK_DIRECTORIES = link directories, useful for rpath on Unix 17 | # GSL_EXE_LINKER_FLAGS = rpath on Unix 18 | 19 | set( GSL_FOUND OFF ) 20 | set( GSL_CBLAS_FOUND OFF ) 21 | 22 | # Windows, but not for Cygwin and MSys where gsl-config is available 23 | if( WIN32 AND NOT CYGWIN AND NOT MSYS ) 24 | # look for headers 25 | find_path( GSL_INCLUDE_DIR 26 | NAMES gsl/gsl_cdf.h gsl/gsl_randist.h 27 | ) 28 | if( GSL_INCLUDE_DIR ) 29 | # look for gsl library 30 | find_library( GSL_LIBRARY 31 | NAMES gsl 32 | ) 33 | if( GSL_LIBRARY ) 34 | set( GSL_INCLUDE_DIRS ${GSL_INCLUDE_DIR} ) 35 | get_filename_component( GSL_LIBRARY_DIRS ${GSL_LIBRARY} PATH ) 36 | set( GSL_FOUND ON ) 37 | endif( GSL_LIBRARY ) 38 | 39 | # look for gsl cblas library 40 | find_library( GSL_CBLAS_LIBRARY 41 | NAMES gslcblas 42 | ) 43 | if( GSL_CBLAS_LIBRARY ) 44 | set( GSL_CBLAS_FOUND ON ) 45 | endif( GSL_CBLAS_LIBRARY ) 46 | 47 | set( GSL_LIBRARIES ${GSL_LIBRARY} ${GSL_CBLAS_LIBRARY} ) 48 | endif( GSL_INCLUDE_DIR ) 49 | 50 | mark_as_advanced( 51 | GSL_INCLUDE_DIR 52 | GSL_LIBRARY 53 | GSL_CBLAS_LIBRARY 54 | ) 55 | else( WIN32 AND NOT CYGWIN AND NOT MSYS ) 56 | if( UNIX OR MSYS ) 57 | find_program( GSL_CONFIG_EXECUTABLE gsl-config 58 | /usr/bin/ 59 | /usr/local/bin 60 | ) 61 | 62 | if( GSL_CONFIG_EXECUTABLE ) 63 | set( GSL_FOUND ON ) 64 | 65 | # run the gsl-config program to get cxxflags 66 | execute_process( 67 | COMMAND sh "${GSL_CONFIG_EXECUTABLE}" --cflags 68 | OUTPUT_VARIABLE GSL_CFLAGS 69 | RESULT_VARIABLE RET 70 | ERROR_QUIET 71 | ) 72 | if( RET EQUAL 0 ) 73 | string( STRIP "${GSL_CFLAGS}" GSL_CFLAGS ) 74 | separate_arguments( GSL_CFLAGS ) 75 | 76 | # parse definitions from cflags; drop -D* from CFLAGS 77 | string( REGEX MATCHALL "-D[^;]+" 78 | GSL_DEFINITIONS "${GSL_CFLAGS}" ) 79 | string( REGEX REPLACE "-D[^;]+;" "" 80 | GSL_CFLAGS "${GSL_CFLAGS}" ) 81 | 82 | # parse include dirs from cflags; drop -I prefix 83 | string( REGEX MATCHALL "-I[^;]+" 84 | GSL_INCLUDE_DIRS "${GSL_CFLAGS}" ) 85 | string( REPLACE "-I" "" 86 | GSL_INCLUDE_DIRS "${GSL_INCLUDE_DIRS}") 87 | string( REGEX REPLACE "-I[^;]+;" "" 88 | GSL_CFLAGS "${GSL_CFLAGS}") 89 | else( RET EQUAL 0 ) 90 | set( GSL_FOUND FALSE ) 91 | endif( RET EQUAL 0 ) 92 | 93 | # run the gsl-config program to get the libs 94 | execute_process( 95 | COMMAND sh "${GSL_CONFIG_EXECUTABLE}" --libs 96 | OUTPUT_VARIABLE GSL_LIBRARIES 97 | RESULT_VARIABLE RET 98 | ERROR_QUIET 99 | ) 100 | if( RET EQUAL 0 ) 101 | string(STRIP "${GSL_LIBRARIES}" GSL_LIBRARIES ) 102 | separate_arguments( GSL_LIBRARIES ) 103 | 104 | # extract linkdirs (-L) for rpath (i.e., LINK_DIRECTORIES) 105 | string( REGEX MATCHALL "-L[^;]+" 106 | GSL_LIBRARY_DIRS "${GSL_LIBRARIES}" ) 107 | string( REPLACE "-L" "" 108 | GSL_LIBRARY_DIRS "${GSL_LIBRARY_DIRS}" ) 109 | else( RET EQUAL 0 ) 110 | set( GSL_FOUND FALSE ) 111 | endif( RET EQUAL 0 ) 112 | 113 | MARK_AS_ADVANCED( 114 | GSL_CFLAGS 115 | ) 116 | else( GSL_CONFIG_EXECUTABLE ) 117 | message( STATUS "FindGSL: gsl-config not found.") 118 | endif( GSL_CONFIG_EXECUTABLE ) 119 | endif( UNIX OR MSYS ) 120 | endif( WIN32 AND NOT CYGWIN AND NOT MSYS ) 121 | 122 | if( GSL_FOUND ) 123 | if( NOT GSL_FIND_QUIETLY ) 124 | message( STATUS "FindGSL: Found both GSL headers and library" ) 125 | endif( NOT GSL_FIND_QUIETLY ) 126 | else( GSL_FOUND ) 127 | if( GSL_FIND_REQUIRED ) 128 | message( FATAL_ERROR "FindGSL: Could not find GSL headers or library" ) 129 | endif( GSL_FIND_REQUIRED ) 130 | endif( GSL_FOUND ) 131 | -------------------------------------------------------------------------------- /cmake-modules/FindLIBQES.cmake: -------------------------------------------------------------------------------- 1 | # - Find libqes 2 | # Find the native libqes includes and library. 3 | # Once done this will define 4 | # 5 | # LIBQES_INCLUDE_DIRS - where to find qes.h, etc. 6 | # LIBQES_LIBRARIES - List of libraries when using libqes. 7 | # LIBQES_FOUND - True if libqes found. 8 | # 9 | # LIBQES_VERSION_STRING - The version of libqes found (x.y.z) 10 | # LIBQES_VERSION_MAJOR - The major version of libqes 11 | # LIBQES_VERSION_MINOR - The minor version of libqes 12 | # LIBQES_VERSION_PATCH - The patch version of libqes 13 | # LIBQES_VERSION_PREREL - The pre-release version of libqes 14 | # LIBQES_VERSION_GIT - The git version of libqes 15 | # 16 | # An includer may set LIBQES_ROOT to a libqes installation root to tell 17 | # this module where to look. 18 | 19 | #============================================================================= 20 | # Copyright 2014 Kevin Murray. Adapted from FindZLIB.cmake 21 | # 22 | # Distributed under the OSI-approved BSD License (the "License"); 23 | # see accompanying file Copyright.txt for details. 24 | # 25 | # This software is distributed WITHOUT ANY WARRANTY; without even the 26 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 27 | # See the License for more information. 28 | #============================================================================= 29 | # (To distribute this file outside of CMake, substitute the full 30 | # License text for the above reference.) 31 | 32 | set(_LIBQES_SEARCHES) 33 | 34 | # Search LIBQES_ROOT first if it is set. 35 | if(LIBQES_ROOT) 36 | set(_LIBQES_SEARCH_ROOT PATHS ${LIBQES_ROOT} NO_DEFAULT_PATH) 37 | list(APPEND _LIBQES_SEARCHES _LIBQES_SEARCH_ROOT) 38 | endif() 39 | 40 | # Normal search. 41 | set(_LIBQES_SEARCH_NORMAL 42 | PATHS "$ENV{PROGRAMFILES}/libqes" 43 | ) 44 | list(APPEND _LIBQES_SEARCHES _LIBQES_SEARCH_NORMAL) 45 | 46 | # Try each search configuration. 47 | foreach(search ${_LIBQES_SEARCHES}) 48 | find_path(LIBQES_INCLUDE_DIR NAMES qes.h ${${search}} PATH_SUFFIXES include) 49 | find_library(LIBQES_LIBRARY NAMES qes ${${search}} PATH_SUFFIXES lib) 50 | endforeach() 51 | 52 | mark_as_advanced(LIBQES_LIBRARY LIBQES_INCLUDE_DIR) 53 | # Handle version. Again, flogged from zlib 54 | if(LIBQES_INCLUDE_DIR AND EXISTS "${LIBQES_INCLUDE_DIR}/qes_config.h") 55 | file(STRINGS "${LIBQES_INCLUDE_DIR}/qes_config.h" LIBQES_H REGEX "^#define LIBQES_VERSION \"[^\"]*\"") 56 | 57 | string(REGEX REPLACE "^.*LIBQES_VERSION \"[Vv]?([0-9]+).*$" "\\1" LIBQES_VERSION_MAJOR "${LIBQES_H}") 58 | string(REGEX REPLACE "^.*LIBQES_VERSION \"[Vv]?[0-9]+\\.([0-9]+).*$" "\\1" LIBQES_VERSION_MINOR "${LIBQES_H}") 59 | string(REGEX REPLACE "^.*LIBQES_VERSION \"[Vv]?[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" LIBQES_VERSION_PATCH "${LIBQES_H}") 60 | set(LIBQES_VERSION_STRING "${LIBQES_VERSION_MAJOR}.${LIBQES_VERSION_MINOR}.${LIBQES_VERSION_PATCH}") 61 | 62 | # only append a EXTRA version if it exists: 63 | set(LIBQES_VERSION_EXTRA "") 64 | if( "${LIBQES_H}" MATCHES "^.*LIBQES_VERSION \"[Vv]?[0-9]+\\.[0-9]+\\.[0-9]+(.+)\\+git.*$") 65 | set(LIBQES_VERSION_PREREL "${CMAKE_MATCH_1}") 66 | endif() 67 | if( "${LIBQES_H}" MATCHES "^.*LIBQES_VERSION \"[Vv]?[0-9]+\\.[0-9]+\\.[0-9]+.*\\+git\\.(.+)$") 68 | set(LIBQES_VERSION_git "${CMAKE_MATCH_1}") 69 | endif() 70 | set(LIBQES_VERSION_STRING "${LIBQES_VERSION_STRING}${LIBQES_VERSION_PREREL}") 71 | endif() 72 | 73 | # handle the QUIETLY and REQUIRED arguments and set LIBQES_FOUND to TRUE if 74 | # all listed variables are TRUE 75 | include(FindPackageHandleStandardArgs) 76 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBQES REQUIRED_VARS LIBQES_LIBRARY LIBQES_INCLUDE_DIR 77 | VERSION_VAR LIBQES_VERSION_STRING) 78 | 79 | if(LIBQES_FOUND) 80 | set(LIBQES_INCLUDE_DIRS ${LIBQES_INCLUDE_DIR}) 81 | set(LIBQES_LIBRARIES ${LIBQES_LIBRARY}) 82 | endif() 83 | 84 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | .build 2 | -------------------------------------------------------------------------------- /docs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FIND_PROGRAM(SPHINXBUILD sphinx-build) 2 | IF(SPHINXBUILD) 3 | SET(ALLSPHINXOPTS -q -D latex_paper_size=a4) 4 | ADD_CUSTOM_TARGET(doc_html 5 | COMMAND ${SPHINXBUILD} -b html ${ALLSPHINXOPTS} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_BINARY_DIR}/doc/html 6 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 7 | ) 8 | ADD_CUSTOM_TARGET(doc_onehtml 9 | COMMAND ${SPHINXBUILD} -b singlehtml ${ALLSPHINXOPTS} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_BINARY_DIR}/doc/single 10 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 11 | ) 12 | ADD_CUSTOM_TARGET(doc_man 13 | COMMAND ${SPHINXBUILD} -b man ${ALLSPHINXOPTS} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_BINARY_DIR}/doc/man 14 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 15 | ) 16 | ADD_CUSTOM_TARGET(doc_clean 17 | COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_BINARY_DIR}/doc" 18 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 19 | ) 20 | ADD_CUSTOM_TARGET(doc ALL DEPENDS doc_man doc_html doc_onehtml) 21 | INSTALL(FILES ${CMAKE_BINARY_DIR}/doc/man/axe.1 DESTINATION "share/man/man1" RENAME "axe-demux.1") 22 | SET_DIRECTORY_PROPERTIES(PROPERTY ADDITIONAL_MAKE_CLEAN_FILES doc/) 23 | ELSE() 24 | MESSAGE(WARNING "Cannot build documenation, sphinx isn't installed") 25 | ENDIF() 26 | 27 | -------------------------------------------------------------------------------- /docs/algorithm.rst: -------------------------------------------------------------------------------- 1 | ************************ 2 | Axe's matching algorithm 3 | ************************ 4 | 5 | Axe uses an algorithm based on longest-prefix-in-trie matching to match a 6 | variable length from the start of each read against a set of 'mutated' 7 | indexes. 8 | 9 | Hamming distance matching 10 | ------------------------- 11 | 12 | While for most applications in high-throughput sequencing hamming distances are 13 | a frowned-upon metric, it is typical for HTS read indexes to be designed to 14 | tolerate a certain level of hamming mismatches. Given these sequences are short 15 | and typically occur at the 5' end of reads, insertions and deletions rarely 16 | need be considered, and the increased rate of assignment of reads with many 17 | errors is offset by the risk of falsely assigning indexes to an incorrect 18 | sample. In any case, reads with more than 1-2 sequencing errors in their first 19 | several bases are likely to be poor quality, and will simply be filtered out 20 | during downstream quality control. 21 | 22 | Hamming mismatch tries 23 | ---------------------- 24 | 25 | Typically, reads are matched to a set of indexes by calculating the hamming 26 | distance between the index, and the first :math:`l` bases of a read for a 27 | index of length :math:`l`. The "correct" index is then selected by 28 | recording either the index with the lowest hamming distance to the read 29 | (competitive matching) or by simply accepting the first index with a hamming 30 | distance below a certain threshold. These approaches are both very 31 | computationally expensive, and can have lower accuracy than the algorithm I 32 | propose. Additionally, implementations of these methods rarely handle indexes 33 | of differing length and combinatorial indexing well, if at all. 34 | 35 | Central to Axe's algorithm is the concept of hamming-mismatch tries. A trie is 36 | a N-ary tree for an N letter alphabet. In the case of high-throughput 37 | sequencing reads, we have the alphabet ``AGCT``, corresponding to the four 38 | nucleotides of DNA, plus ``N``, used to represent ambiguous base calls. Instead 39 | of matching each index to each read, we pre-calculate all allowable sequences 40 | at each mismatch level, and store these in level-wise tries. For example, to 41 | match to a hamming distance of 2, we create three tries: One containing all 42 | indexes, verbatim, and two tries where every sequence within a hamming 43 | distance of 1 and 2 of each index respectively. Hereafter, these tries are 44 | referred to as the 0, 1 and 2-mm tries, for a hamming distance (mismatch) of 45 | 0, 1 and 2. Then, we find the longest prefix in each sequence read in the 0mm 46 | trie. If this prefix is not a valid leaf in the 0mm trie, we find the longest 47 | prefix in the 1mm trie, and so on for all tries in ascending order. If no 48 | prefix of the read is a complete sequence in any trie, the read is assigned to 49 | an "non-indexed" output file. 50 | 51 | This algorithm ensures optimal index matching in many ways, but is also 52 | extremely fast. In situations with indexes of differing length, we ensure that 53 | the *longest* acceptable index at a given hamming distance is chosen; 54 | assuming that sequence is random after the index, the probability of false 55 | assignments using this method is low. We also ensure that short perfect matches 56 | are preferred to longer inexact matches, as we firstly only consider indexes 57 | with no error, then 1 error, and so on. This ensures that reads with indexes 58 | that are followed by random sequence that happens to inexactly match a longer 59 | index in the set are not falsely assigned to this longer index. 60 | 61 | The speed of this algorithm is largely due to the constant time matching 62 | algorithm with respect to the number of indexes to match. The time taken to 63 | match each read is proportional instead to the length of the indexes, as for a 64 | index of length :math:`l`, at most :math:`l + 1` trie level descents are 65 | required to find an entry in the trie. As this length is more-or-less constant 66 | and small, the overall complexity of axe's algorithm is :math:`O(n)` for 67 | :math:`n` reads, as opposed to :math:`O(nm)` for :math:`n` reads and :math:`m` 68 | indexes as is typical for traditional matching algorithms 69 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. axe documentation master file, created by 2 | sphinx-quickstart on Fri Jul 25 09:16:47 2014. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to axe's documentation! 7 | =============================== 8 | 9 | Axe is a read de-multiplexer, useful in situations where sequence reads contain 10 | the indexes that uniquely distinguish samples. Axe uses a rapid and accurate 11 | algorithm based on hamming mismatch tries to competitively match the prefix of 12 | a sequencing read against a set of indexes. Axe supports combinatorial 13 | indexing schemes. 14 | 15 | Contents: 16 | 17 | .. toctree:: 18 | :maxdepth: 1 19 | 20 | tutorial 21 | usage 22 | algorithm 23 | 24 | 25 | 26 | 27 | Indices and tables 28 | ================== 29 | 30 | * :ref:`genindex` 31 | -------------------------------------------------------------------------------- /docs/tutorial.rst: -------------------------------------------------------------------------------- 1 | ************ 2 | Axe Tutorial 3 | ************ 4 | 5 | In this tutorial, we'll use Axe to demultiplex some paired-end, 6 | combinatorially-index Genotyping-by-Sequencing reads. The data for this 7 | tutorial is available from figshare: 8 | https://figshare.com/articles/axe-tutorial_tar/6143720 . 9 | 10 | Axe should be run as the initial step of any analysis: don't use sequence QC 11 | tools like AdapterRemoval or Trimmomatic before using axe, as indexes may be 12 | trimmed away, or pairing information removed. 13 | 14 | Step 0: Download the trial data 15 | ------------------------------- 16 | 17 | This will download the trial data, and extract it on the fly: 18 | 19 | .. code-block:: bash 20 | 21 | curl -LS https://ndownloader.figshare.com/files/11094782 | tar xv 22 | 23 | Step 1: prepare a key file 24 | -------------------------- 25 | 26 | The key file associates index sequences with sample names. A key file can be 27 | prepared in a spreadsheet editor, like LibreOffice Calc, or Excel. The format 28 | is quite strict, and is described in detail in the online usage documentation. 29 | 30 | Let's now inspect the keyfile I have provided for the tutorial. 31 | 32 | .. code-block:: bash 33 | 34 | head axe-keyfile.tsv 35 | 36 | 37 | Step 2: Demultiplex with Axe 38 | ---------------------------- 39 | 40 | 41 | In this step, we will demultiplex our interleaved input file to per-sample 42 | interleaved output files. To see a full range of Axe's options, please run 43 | ``axe-demux -h``, or inspect the online usage documentation. 44 | 45 | First, let's inspect the input. 46 | 47 | .. code-block:: bash 48 | 49 | zcat axe-tutorial.fastq.gz | head -n 8 50 | 51 | Then, we need to ensure that axe has somewhere to put the demultiplexed reads. 52 | Axe outputs one file (or more, depending on pairing) per sample. Axe does so by 53 | appending the sample name to some prefix (as given by the ``-I``, ``-F``, 54 | and/or ``-R`` options). If this prefix is a directory, then sample fastq files 55 | will be created in that sub-directory, but the directory must exist. Let's make 56 | an output directory: 57 | 58 | .. code-block:: bash 59 | 60 | mkdir -p output 61 | 62 | Now, let's demultiplex the reads! 63 | 64 | .. code-block:: bash 65 | 66 | axe-demux -i axe-tutorial.fastq.gz -I output/ \ 67 | -c -b axe-keyfile.tsv -t demux-stats.tsv -z 1 68 | 69 | The command above demultiplexes reads from ``axe-tutorial.fastq.gz`` into 70 | separate files under ``output``, based on the combinatorial (``-c``) 71 | sample-to-index-sequence mapping described in ``axe-keyfile.tsv``, and saves a 72 | file of statistics as ``demux-stats.tsv``. Note that we have enabled 73 | compression of output files using the ``-z`` option, in case you don't have 74 | much disk space available. This will make Axe slightly slower. 75 | -------------------------------------------------------------------------------- /docs/usage.rst: -------------------------------------------------------------------------------- 1 | ********* 2 | Axe Usage 3 | ********* 4 | 5 | .. note:: 6 | For arcane reasons, the name of the ``axe`` binary changed to ``axe-demux`` 7 | with version 0.3.0. Apologies for the inconvenience, this was required to 8 | make ``axe`` installable in Debian and its derivatives. Command-line usage 9 | did not change. 10 | 11 | Axe has several usage modes. The primary distinction is between the two 12 | alternate indexing schemes, single and combinatorial indexing. Single index 13 | matching is used when only the first read contains index sequences. 14 | Combinatorial indexing is used when both reads in a read pair contain 15 | independent (typically different) index sequences. 16 | 17 | For concise reference, the command-line usage of ``axe-demux`` is reproduced 18 | below: 19 | 20 | .. literalinclude:: usage.txt 21 | :language: text 22 | 23 | Inputs and Outputs 24 | ------------------ 25 | 26 | Regardless of read mode, three input and output schemes are supported: 27 | single-end reads, paired reads (separate R1 and R2 files) and interleaved 28 | paired reads (one file, with R1 and R2 as consecutive reads). If single end 29 | reads are inputted, they must be output as single end reads. If either paired or 30 | interleaved paired reads are read, they can be output as either paired reads or 31 | interleaved paired reads. This applies to both successfully de-multiplexed reads 32 | and reads that could not be de-multiplexed. 33 | 34 | The ``-z`` flag can be used to specify that outputs should be compressed using 35 | gzip compression. The ``-z`` flag takes an integer argument between 0 (the 36 | default) and 9, where 0 indicates plain text output (``gzopen`` mode "wT"), and 37 | 1-9 indicate that the respective compression level should be used, where 1 is 38 | fastest and 9 is most compact. 39 | 40 | The output flags should be prefixes that are used to generate the output file 41 | name based on the index's (or index pair's) ID. The names are generated as: 42 | ``prefix`` + ``_`` + ``index ID`` + ``_`` + ``read number`` + ``.extension``. 43 | The output file for reads that could not be demultiplexed is ``prefix`` + ``_`` 44 | + ``unknown`` + ``_`` + ``read number`` + ``.extension``. The read number is 45 | omitted unless the paired read file scheme is used, and is "il" for interleaved 46 | output. The extension is "fastq"; ".gz" is appended to the extension if the 47 | ``-z`` flag is used. 48 | 49 | The corresponding CLI flags are: 50 | - ``-f`` and ``-F``: Single end or paired R1 file input and output 51 | respectively. 52 | - ``-r`` and ``-R``: Paired R2 file input and output. 53 | - ``-i`` and ``-I``: Interleaved paired input and output. 54 | 55 | The index file 56 | ---------------- 57 | 58 | The index file is a tab-separated file with an optional header. It is 59 | mandatory, and is always supplied using the ``-b`` command line flag. The exact 60 | format is dependent on indexing mode, and is described further in the sections 61 | below. If a header is present, the header line must start with either 62 | `Barcode` or ``index``, or it will be interpreted as a index line, leading 63 | to a parsing error. Any line starting with ';' or '#' is ignored, allowing 64 | comments to be added in line with indexes. Please ensure that the software 65 | used to produce the index uses ASCII encoding, and does not insert a 66 | Byte-order Mark (BoM) as many text editors can silently use Unicode-based 67 | encoding schemes. I recommend the use of 68 | `LibreOffice Calc `_ (part of a free and open source 69 | office suite) to generate index tables; Microsoft Excel can also be used. 70 | 71 | Mismatch level selection 72 | ------------------------ 73 | 74 | Independent of index mode, the ``-m`` flag is used to select the maximum 75 | allowable hamming distance between a read's prefix and a index to be 76 | considered as a match. As "mutated" indexes must be unique, a hamming distance 77 | of one is the default as typically indexes are designed to differ by a hamming 78 | distance of at least two. Optionally, (using the ``-p`` flag), axe will allow 79 | selective mismatch levels, where, if clashes are observed, the index will 80 | only be matched exactly. This allows one to process datasets with indexes that 81 | don't have a sufficiently high distance between them. 82 | 83 | Single index mode 84 | ------------------- 85 | 86 | Single index mode is the default mode of operation. Barcodes are matched 87 | against read one (hereafter the forward read), and the index is trimmed from 88 | only the forward read, unless the ``-2`` command line flag is given, in which 89 | case a prefix the same length as the matched index is also trimmed from the 90 | second or reverse read. Note that sequence of this second read is not checked 91 | before trimming. 92 | 93 | In single index mode, the index file has two columns: ``Barcode`` and 94 | ``ID``. 95 | 96 | Combinatorial index mode 97 | -------------------------- 98 | 99 | Combinatorial index mode is activated by giving the ``-c`` flag on the 100 | command line. Forward read indexes are matched against the forward read, and 101 | reverse read indexes are matched against the reverse read. The optimal 102 | indexes are selected independently, and the index pair is selected from 103 | these two indexes. The respective indexes are trimmed from both reads; the 104 | ``-2`` command line flag has no effect in combinatorial index mode. 105 | 106 | In combinatorial index mode, the index file has three columns: 107 | ``Barcode1``, ``Barcode2`` and ``ID``. Individual indexes can occur many times 108 | within the forward and reverse indexes, but index pairs must be unique 109 | combinations. 110 | 111 | The Demultiplexing Statistics File 112 | ---------------------------------- 113 | 114 | The ``-t`` option allows the output of per-sample read counts to a 115 | tab-separated file. The file will have a header describing its format, and 116 | includes a line for reads which could not be demultiplexed. 117 | -------------------------------------------------------------------------------- /docs/usage.txt: -------------------------------------------------------------------------------- 1 | USAGE: 2 | axe-demux [-mzc2pt] -b (-f [-r] | -i) (-F [-R] | -I) 3 | axe-demux -h 4 | axe-demux -v 5 | 6 | OPTIONS: 7 | -m, --mismatch Maximum hamming distance mismatch. [int, default 1] 8 | -z, --ziplevel Gzip compression level, or 0 for plain text [int, default 0] 9 | -c, --combinatorial Use combinatorial barcode matching. [flag, default OFF] 10 | -p, --permissive Don't error on barcode mismatch confict, matching only 11 | exactly for conficting barcodes. [flag, default OFF] 12 | -2, --trim-r2 Trim barcode from R2 read as well as R1. [flag, default OFF] 13 | -b, --barcodes Barcode file. See --help for example. [file] 14 | -f, --fwd-in Input forward read. [file] 15 | -F, --fwd-out Output forward read prefix. [file prefix or existing directory] 16 | -r, --rev-in Input reverse read. [file] 17 | -R, --rev-out Output reverse read prefix. [file prefix or existing directory] 18 | -i, --ilfq-in Input interleaved paired reads. [file] 19 | -I, --ilfq-out Output interleaved paired reads prefix. [file prefix or existing directory] 20 | -t, --table-file Output a summary table of demultiplexing statistics to file. [file] 21 | -h, --help Print this usage plus additional help. 22 | -V, --version Print version string. 23 | -v, --verbose Be more verbose. Additive, -vv is more vebose than -v. 24 | -q, --quiet Be very quiet. 25 | 26 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2015 Kevin Murray 2 | # 3 | # This program is free software: you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation, either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program. If not, see . 15 | 16 | # Axe library (libaxe.a) 17 | FILE(GLOB DATRIE_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/datrie/*.c) 18 | FILE(GLOB GSL_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/gsl/*.c) 19 | SET(AXELIB_SRCS ${DATRIE_SRCS} axe.c) 20 | 21 | IF (NOT GSL_FOUND) 22 | MESSAGE(STATUS "Using bundled GSL sources") 23 | SET(AXELIB_SRCS ${AXELIB_SRCS} ${GSL_SRCS}) 24 | ENDIF() 25 | 26 | ADD_LIBRARY(axelib STATIC ${AXELIB_SRCS}) 27 | TARGET_LINK_LIBRARIES(axelib qes_static ${AXE_DEP_LIBS}) 28 | SET_TARGET_PROPERTIES(axelib PROPERTIES OUTPUT_NAME axe) 29 | 30 | # Executable 31 | ADD_EXECUTABLE(axe-demux main.c) 32 | TARGET_LINK_LIBRARIES(axe-demux ${AXE_DEPENDS_LIBS} axelib) 33 | INSTALL(TARGETS axe-demux DESTINATION "bin") 34 | -------------------------------------------------------------------------------- /src/axe_config.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================ 3 | * 4 | * Filename: axe_config.h.in 5 | * Description: Pull in build system definitions 6 | * Copyright: 2014-2016 Kevin Murray 7 | * License: GNU GPL v3+ 8 | * 9 | * This program is free software: you can redistribute it and/or modify it 10 | * under the terms of the GNU General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 17 | * more details. 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * this program. If not, see . 21 | * 22 | * ============================================================================ 23 | */ 24 | 25 | #ifndef AXE_CONFIG_H 26 | #define AXE_CONFIG_H 27 | 28 | #define _GNU_SOURCE 29 | 30 | #define AXE_VERSION "${AXE_VERSION}" 31 | 32 | #endif /* AXE_CONFIG_H */ 33 | -------------------------------------------------------------------------------- /src/datrie/alpha-map-private.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* 3 | * libdatrie - Double-Array Trie Library 4 | * Copyright (C) 2006 Theppitak Karoonboonyanan 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | /* 22 | * alpha-map-private.h - private APIs for alpha-map 23 | * Created: 2008-12-04 24 | * Author: Theppitak Karoonboonyanan 25 | */ 26 | 27 | #ifndef __ALPHA_MAP_PRIVATE_H 28 | #define __ALPHA_MAP_PRIVATE_H 29 | 30 | #include 31 | #include "alpha-map.h" 32 | 33 | TrieIndex alpha_map_char_to_trie (const AlphaMap *alpha_map, 34 | AlphaChar ac); 35 | 36 | AlphaChar alpha_map_trie_to_char (const AlphaMap *alpha_map, 37 | TrieChar tc); 38 | 39 | TrieChar * alpha_map_char_to_trie_str (const AlphaMap *alpha_map, 40 | const AlphaChar *str); 41 | 42 | AlphaChar * alpha_map_trie_to_char_str (const AlphaMap *alpha_map, 43 | const TrieChar *str); 44 | 45 | 46 | #endif /* __ALPHA_MAP_PRIVATE_H */ 47 | 48 | 49 | /* 50 | vi:ts=4:ai:expandtab 51 | */ 52 | 53 | -------------------------------------------------------------------------------- /src/datrie/alpha-map.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* 3 | * libdatrie - Double-Array Trie Library 4 | * Copyright (C) 2006 Theppitak Karoonboonyanan 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | /* 22 | * alpha-map.h - map between character codes and trie alphabet 23 | * Created: 2006-08-19 24 | * Author: Theppitak Karoonboonyanan 25 | */ 26 | 27 | #ifndef __ALPHA_MAP_H 28 | #define __ALPHA_MAP_H 29 | 30 | #include 31 | 32 | #include "typedefs.h" 33 | #include "triedefs.h" 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | /** 40 | * @file alpha-map.h 41 | * @brief AlphaMap data type and functions 42 | * 43 | * AlphaMap is a mapping between AlphaChar and TrieChar. AlphaChar is the 44 | * alphabet character used in words of a target language, while TrieChar 45 | * is a small integer with packed range of values and is actually used in 46 | * trie state transition calculations. 47 | * 48 | * Since double-array trie relies on sparse state transition table, 49 | * a small set of input characters can make the table small, i.e. with 50 | * small number of columns. But in real life, alphabet characters can be 51 | * of non-continuous range of values. The unused slots between them can 52 | * waste the space in the table, and can increase the chance of unused 53 | * array cells. 54 | * 55 | * AlphaMap is thus defined for mapping between non-continuous ranges of 56 | * values of AlphaChar and packed and continuous range of Triechar. 57 | * 58 | * In this implementation, TrieChar is defined as a single-byte integer, 59 | * which means the largest AlphaChar set that is supported is of 255 60 | * values, as the special value of 0 is reserved for null-termination code. 61 | */ 62 | 63 | /** 64 | * @brief AlphaMap data type 65 | */ 66 | typedef struct _AlphaMap AlphaMap; 67 | 68 | AlphaMap * alpha_map_new (void); 69 | 70 | AlphaMap * alpha_map_clone (const AlphaMap *a_map); 71 | 72 | void alpha_map_free (AlphaMap *alpha_map); 73 | 74 | int alpha_map_add_range (AlphaMap *alpha_map, 75 | AlphaChar begin, 76 | AlphaChar end); 77 | 78 | int alpha_char_strlen (const AlphaChar *str); 79 | int alpha_char_strcmp (const AlphaChar *str1, const AlphaChar *str2); 80 | 81 | #ifdef __cplusplus 82 | } 83 | #endif 84 | 85 | #endif /* __ALPHA_MAP_H */ 86 | 87 | 88 | /* 89 | vi:ts=4:ai:expandtab 90 | */ 91 | -------------------------------------------------------------------------------- /src/datrie/darray.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* 3 | * libdatrie - Double-Array Trie Library 4 | * Copyright (C) 2006 Theppitak Karoonboonyanan 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | /* 22 | * darray.h - Double-array trie structure 23 | * Created: 2006-08-11 24 | * Author: Theppitak Karoonboonyanan 25 | */ 26 | 27 | #ifndef __DARRAY_H 28 | #define __DARRAY_H 29 | 30 | #include "triedefs.h" 31 | #include "trie-string.h" 32 | 33 | /** 34 | * @file darray.h 35 | * @brief Double-array trie structure 36 | */ 37 | 38 | /** 39 | * @brief Symbol set structure type 40 | */ 41 | typedef struct _Symbols Symbols; 42 | 43 | Symbols * symbols_new (void); 44 | void symbols_free (Symbols *syms); 45 | void symbols_add (Symbols *syms, TrieChar c); 46 | int symbols_num (const Symbols *syms); 47 | TrieChar symbols_get (const Symbols *syms, int index); 48 | 49 | /** 50 | * @brief Double-array structure type 51 | */ 52 | typedef struct _DArray DArray; 53 | 54 | 55 | DArray * da_new (void); 56 | 57 | void da_free (DArray *d); 58 | 59 | TrieIndex da_get_root (const DArray *d); 60 | 61 | 62 | TrieIndex da_get_base (const DArray *d, TrieIndex s); 63 | 64 | TrieIndex da_get_check (const DArray *d, TrieIndex s); 65 | 66 | 67 | void da_set_base (DArray *d, TrieIndex s, TrieIndex val); 68 | 69 | void da_set_check (DArray *d, TrieIndex s, TrieIndex val); 70 | 71 | bool da_walk (const DArray *d, TrieIndex *s, TrieChar c); 72 | 73 | Symbols * da_output_symbols (const DArray *d, TrieIndex s); 74 | 75 | /** 76 | * @brief Test walkability in double-array structure 77 | * 78 | * @param d : the double-array structure 79 | * @param s : current state 80 | * @param c : the input character 81 | * 82 | * @return boolean indicating walkability 83 | * 84 | * Test if there is a transition from state @a s with input character @a c. 85 | */ 86 | /* 87 | bool da_is_walkable (DArray *d, TrieIndex s, TrieChar c); 88 | */ 89 | #define da_is_walkable(d,s,c) \ 90 | (da_get_check ((d), da_get_base ((d), (s)) + (c)) == (s)) 91 | 92 | TrieIndex da_insert_branch (DArray *d, TrieIndex s, TrieChar c); 93 | 94 | void da_prune (DArray *d, TrieIndex s); 95 | 96 | void da_prune_upto (DArray *d, TrieIndex p, TrieIndex s); 97 | 98 | TrieIndex da_first_separate (DArray *d, TrieIndex root, TrieString *keybuff); 99 | 100 | TrieIndex da_next_separate (DArray *d, 101 | TrieIndex root, 102 | TrieIndex sep, 103 | TrieString *keybuff); 104 | 105 | #endif /* __DARRAY_H */ 106 | 107 | /* 108 | vi:ts=4:ai:expandtab 109 | */ 110 | -------------------------------------------------------------------------------- /src/datrie/dstring-private.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* 3 | * libdatrie - Double-Array Trie Library 4 | * Copyright (C) 2006 Theppitak Karoonboonyanan 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | /* 22 | * dstring-private.h - Dynamic string type 23 | * Created: 2012-08-02 24 | * Author: Theppitak Karoonboonyanan 25 | */ 26 | 27 | #ifndef __DSTRING_PRIVATE_H 28 | #define __DSTRING_PRIVATE_H 29 | 30 | #include "typedefs.h" 31 | 32 | 33 | struct _DString { 34 | int char_size; 35 | int str_len; 36 | int alloc_size; 37 | void * val; 38 | }; 39 | 40 | 41 | #endif /* __DSTRING_PRIVATE_H */ 42 | 43 | /* 44 | vi:ts=4:ai:expandtab 45 | */ 46 | -------------------------------------------------------------------------------- /src/datrie/dstring.c: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* 3 | * libdatrie - Double-Array Trie Library 4 | * Copyright (C) 2006 Theppitak Karoonboonyanan 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | /* 22 | * dstring.c - Dynamic string type 23 | * Created: 2012-08-01 24 | * Author: Theppitak Karoonboonyanan 25 | */ 26 | 27 | #include "dstring.h" 28 | #include "dstring-private.h" 29 | 30 | #include "trie-private.h" 31 | #include 32 | #include 33 | 34 | 35 | DString * 36 | dstring_new (int char_size, int n_elm) 37 | { 38 | DString *ds; 39 | 40 | ds = (DString *) malloc (sizeof (DString)); 41 | if (!ds) 42 | return NULL; 43 | 44 | ds->alloc_size = char_size * n_elm; 45 | ds->val = malloc (ds->alloc_size); 46 | if (!ds->val) { 47 | free (ds); 48 | return NULL; 49 | } 50 | 51 | ds->char_size = char_size; 52 | ds->str_len = 0; 53 | 54 | return ds; 55 | } 56 | 57 | void 58 | dstring_free (DString *ds) 59 | { 60 | free (ds->val); 61 | free (ds); 62 | } 63 | 64 | int 65 | dstring_length (const DString *ds) 66 | { 67 | return ds->str_len; 68 | } 69 | 70 | const void * 71 | dstring_get_val (const DString *ds) 72 | { 73 | return ds->val; 74 | } 75 | 76 | void * 77 | dstring_get_val_rw (DString *ds) 78 | { 79 | return ds->val; 80 | } 81 | 82 | void 83 | dstring_clear (DString *ds) 84 | { 85 | ds->str_len = 0; 86 | } 87 | 88 | static bool 89 | dstring_ensure_space (DString *ds, int size) 90 | { 91 | if (ds->alloc_size < size) { 92 | int re_size = MAX_VAL (ds->alloc_size * 2, size); 93 | void *re_ptr = realloc (ds->val, re_size); 94 | if (!re_ptr) 95 | return false; 96 | ds->val = re_ptr; 97 | ds->alloc_size = re_size; 98 | } 99 | 100 | return true; 101 | } 102 | 103 | bool 104 | dstring_copy (DString *dst, const DString *src) 105 | { 106 | if (!dstring_ensure_space (dst, (src->str_len + 1) * src->char_size)) 107 | return false; 108 | 109 | memcpy (dst->val, src->val, (src->str_len + 1) * src->char_size); 110 | 111 | dst->char_size = src->char_size; 112 | dst->str_len = src->str_len; 113 | 114 | return true; 115 | } 116 | 117 | bool 118 | dstring_append (DString *dst, const DString *src) 119 | { 120 | if (dst->char_size != src->char_size) 121 | return false; 122 | 123 | if (!dstring_ensure_space (dst, (dst->str_len + src->str_len + 1) 124 | * dst->char_size)) 125 | { 126 | return false; 127 | } 128 | 129 | memcpy ((char *)dst->val + (dst->char_size * dst->str_len), src->val, 130 | (src->str_len + 1) * dst->char_size); 131 | 132 | dst->str_len += src->str_len; 133 | 134 | return true; 135 | } 136 | 137 | bool 138 | dstring_append_string (DString *ds, const void *data, int len) 139 | { 140 | if (!dstring_ensure_space (ds, (ds->str_len + len + 1) * ds->char_size)) 141 | return false; 142 | 143 | memcpy ((char *)ds->val + (ds->char_size * ds->str_len), data, 144 | ds->char_size * len); 145 | 146 | ds->str_len += len; 147 | 148 | return true; 149 | } 150 | 151 | bool 152 | dstring_append_char (DString *ds, const void *data) 153 | { 154 | if (!dstring_ensure_space (ds, (ds->str_len + 2) * ds->char_size)) 155 | return false; 156 | 157 | memcpy ((char *)ds->val + (ds->char_size * ds->str_len), data, 158 | ds->char_size); 159 | 160 | ds->str_len++; 161 | 162 | return true; 163 | } 164 | 165 | bool 166 | dstring_terminate (DString *ds) 167 | { 168 | if (!dstring_ensure_space (ds, (ds->str_len + 2) * ds->char_size)) 169 | return false; 170 | 171 | memset ((char *)ds->val + (ds->char_size * ds->str_len), 0, ds->char_size); 172 | 173 | return true; 174 | } 175 | 176 | bool 177 | dstring_cut_last (DString *ds) 178 | { 179 | if (0 == ds->str_len) 180 | return false; 181 | 182 | ds->str_len--; 183 | 184 | return true; 185 | } 186 | 187 | /* 188 | vi:ts=4:ai:expandtab 189 | */ 190 | -------------------------------------------------------------------------------- /src/datrie/dstring.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* 3 | * libdatrie - Double-Array Trie Library 4 | * Copyright (C) 2006 Theppitak Karoonboonyanan 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | /* 22 | * dstring.h - Dynamic string type 23 | * Created: 2012-08-01 24 | * Author: Theppitak Karoonboonyanan 25 | */ 26 | 27 | #ifndef __DSTRING_H 28 | #define __DSTRING_H 29 | 30 | #include "typedefs.h" 31 | 32 | typedef struct _DString DString; 33 | 34 | DString * dstring_new (int char_size, int n_elm); 35 | 36 | void dstring_free (DString *ds); 37 | 38 | int dstring_length (const DString *ds); 39 | 40 | const void * dstring_get_val (const DString *ds); 41 | 42 | void * dstring_get_val_rw (DString *ds); 43 | 44 | void dstring_clear (DString *ds); 45 | 46 | bool dstring_copy (DString *dst, const DString *src); 47 | 48 | bool dstring_append (DString *dst, const DString *src); 49 | 50 | bool dstring_append_string (DString *ds, const void *data, int len); 51 | 52 | bool dstring_append_char (DString *ds, const void *data); 53 | 54 | bool dstring_terminate (DString *ds); 55 | 56 | bool dstring_cut_last (DString *ds); 57 | 58 | #endif /* __DSTRING_H */ 59 | 60 | /* 61 | vi:ts=4:ai:expandtab 62 | */ 63 | -------------------------------------------------------------------------------- /src/datrie/tail.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* 3 | * libdatrie - Double-Array Trie Library 4 | * Copyright (C) 2006 Theppitak Karoonboonyanan 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | /* 22 | * tail.h - trie tail for keeping suffixes 23 | * Created: 2006-08-12 24 | * Author: Theppitak Karoonboonyanan 25 | */ 26 | 27 | #ifndef __TAIL_H 28 | #define __TAIL_H 29 | 30 | #include "triedefs.h" 31 | 32 | /** 33 | * @file tail.h 34 | * @brief trie tail for keeping suffixes 35 | */ 36 | 37 | /** 38 | * @brief Double-array structure type 39 | */ 40 | typedef struct _Tail Tail; 41 | 42 | Tail * tail_new (void); 43 | 44 | void tail_free (Tail *t); 45 | 46 | 47 | const TrieChar * tail_get_suffix (const Tail *t, TrieIndex index); 48 | 49 | bool tail_set_suffix (Tail *t, TrieIndex index, const TrieChar *suffix); 50 | 51 | TrieIndex tail_add_suffix (Tail *t, const TrieChar *suffix); 52 | 53 | TrieData tail_get_data (const Tail *t, TrieIndex index); 54 | 55 | bool tail_set_data (Tail *t, TrieIndex index, TrieData data); 56 | 57 | void tail_delete (Tail *t, TrieIndex index); 58 | 59 | int tail_walk_str (const Tail *t, 60 | TrieIndex s, 61 | short *suffix_idx, 62 | const TrieChar *str, 63 | int len); 64 | 65 | bool tail_walk_char (const Tail *t, 66 | TrieIndex s, 67 | short *suffix_idx, 68 | TrieChar c); 69 | 70 | /** 71 | * @brief Test walkability in tail with a character 72 | * 73 | * @param t : the tail data 74 | * @param s : the tail data index 75 | * @param suffix_idx : current character index in suffix 76 | * @param c : the character to test walkability 77 | * 78 | * @return boolean indicating walkability 79 | * 80 | * Test if the character @a c can be used to walk from given character 81 | * position @a suffix_idx of entry @a s of the tail data @a t. 82 | */ 83 | /* 84 | bool tail_is_walkable_char (Tail *t, 85 | TrieIndex s, 86 | short suffix_idx, 87 | const TrieChar c); 88 | */ 89 | #define tail_is_walkable_char(t,s,suffix_idx,c) \ 90 | (tail_get_suffix ((t), (s)) [suffix_idx] == (c)) 91 | 92 | #endif /* __TAIL_H */ 93 | 94 | /* 95 | vi:ts=4:ai:expandtab 96 | */ 97 | -------------------------------------------------------------------------------- /src/datrie/trie-private.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* 3 | * libdatrie - Double-Array Trie Library 4 | * Copyright (C) 2006 Theppitak Karoonboonyanan 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | /* 22 | * trie-private.h - Private utilities for trie implementation 23 | * Created: 2007-08-25 24 | * Author: Theppitak Karoonboonyanan 25 | */ 26 | 27 | #ifndef __TRIE_PRIVATE_H 28 | #define __TRIE_PRIVATE_H 29 | 30 | #include 31 | 32 | /** 33 | * @file trie-private.h 34 | * @brief Private utilities for trie implementation 35 | */ 36 | 37 | /** 38 | * @brief Minimum value macro 39 | */ 40 | #define MIN_VAL(a,b) ((a)<(b)?(a):(b)) 41 | /** 42 | * @brief Maximum value macro 43 | */ 44 | #define MAX_VAL(a,b) ((a)>(b)?(a):(b)) 45 | 46 | #endif /* __TRIE_PRIVATE_H */ 47 | 48 | /* 49 | vi:ts=4:ai:expandtab 50 | */ 51 | -------------------------------------------------------------------------------- /src/datrie/trie-string.c: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* 3 | * libdatrie - Double-Array Trie Library 4 | * Copyright (C) 2006 Theppitak Karoonboonyanan 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | /* 22 | * trie-string.c - Dynamic string type for Trie alphabets 23 | * Created: 2012-08-02 24 | * Author: Theppitak Karoonboonyanan 25 | */ 26 | 27 | #include "trie-string.h" 28 | #include "dstring-private.h" 29 | #include "triedefs.h" 30 | 31 | #include 32 | 33 | 34 | struct _TrieString { 35 | DString ds; 36 | }; 37 | 38 | 39 | TrieString * 40 | trie_string_new (int n_elm) 41 | { 42 | return (TrieString *) dstring_new (sizeof (TrieChar), n_elm); 43 | } 44 | 45 | void 46 | trie_string_free (TrieString *ts) 47 | { 48 | dstring_free ((DString *)ts); 49 | } 50 | 51 | int 52 | trie_string_length (const TrieString *ts) 53 | { 54 | return dstring_length ((DString *)ts); 55 | } 56 | 57 | const void * 58 | trie_string_get_val (const TrieString *ts) 59 | { 60 | return dstring_get_val ((DString *)ts); 61 | } 62 | 63 | void * 64 | trie_string_get_val_rw (TrieString *ts) 65 | { 66 | return dstring_get_val_rw ((DString *)ts); 67 | } 68 | 69 | void 70 | trie_string_clear (TrieString *ts) 71 | { 72 | dstring_clear ((DString *)ts); 73 | } 74 | 75 | bool 76 | trie_string_copy (TrieString *dst, const TrieString *src) 77 | { 78 | return dstring_copy ((DString *)dst, (const DString *)src); 79 | } 80 | 81 | bool 82 | trie_string_append (TrieString *dst, const TrieString *src) 83 | { 84 | return dstring_append ((DString *)dst, (const DString *)src); 85 | } 86 | 87 | bool 88 | trie_string_append_string (TrieString *ts, const TrieChar *str) 89 | { 90 | return dstring_append_string ((DString *)ts, 91 | str, strlen ((const char *)str)); 92 | } 93 | 94 | bool 95 | trie_string_append_char (TrieString *ts, TrieChar tc) 96 | { 97 | return dstring_append_char ((DString *)ts, &tc); 98 | } 99 | 100 | bool 101 | trie_string_terminate (TrieString *ts) 102 | { 103 | return dstring_terminate ((DString *)ts); 104 | } 105 | 106 | bool 107 | trie_string_cut_last (TrieString *ts) 108 | { 109 | return dstring_cut_last ((DString *)ts); 110 | } 111 | 112 | /* 113 | vi:ts=4:ai:expandtab 114 | */ 115 | -------------------------------------------------------------------------------- /src/datrie/trie-string.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* 3 | * libdatrie - Double-Array Trie Library 4 | * Copyright (C) 2006 Theppitak Karoonboonyanan 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | /* 22 | * trie-string.h - Dynamic string type for Trie alphabets 23 | * Created: 2012-08-02 24 | * Author: Theppitak Karoonboonyanan 25 | */ 26 | 27 | #ifndef __TRIE_STRING_H 28 | #define __TRIE_STRING_H 29 | 30 | #include "dstring.h" 31 | #include "triedefs.h" 32 | 33 | typedef struct _TrieString TrieString; 34 | 35 | TrieString * trie_string_new (int n_elm); 36 | 37 | void trie_string_free (TrieString *ts); 38 | 39 | int trie_string_length (const TrieString *ts); 40 | 41 | const void * trie_string_get_val (const TrieString *ts); 42 | 43 | void * trie_string_get_val_rw (TrieString *ts); 44 | 45 | void trie_string_clear (TrieString *ts); 46 | 47 | bool trie_string_copy (TrieString *dst, const TrieString *src); 48 | 49 | bool trie_string_append (TrieString *dst, const TrieString *src); 50 | 51 | bool trie_string_append_string (TrieString *ts, const TrieChar *str); 52 | 53 | bool trie_string_append_char (TrieString *ts, TrieChar tc); 54 | 55 | bool trie_string_terminate (TrieString *ts); 56 | 57 | bool trie_string_cut_last (TrieString *ts); 58 | 59 | 60 | #endif /* __TRIE_STRING_H */ 61 | 62 | /* 63 | vi:ts=4:ai:expandtab 64 | */ 65 | 66 | -------------------------------------------------------------------------------- /src/datrie/triedefs.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* 3 | * libdatrie - Double-Array Trie Library 4 | * Copyright (C) 2006 Theppitak Karoonboonyanan 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | /* 22 | * triedefs.h - General typedefs for trie 23 | * Created: 2006-08-11 24 | * Author: Theppitak Karoonboonyanan 25 | */ 26 | 27 | #ifndef __TRIEDEFS_H 28 | #define __TRIEDEFS_H 29 | 30 | #include 31 | #include 32 | 33 | /** 34 | * @file triedefs.h 35 | * @brief General typedefs for trie 36 | */ 37 | 38 | /** 39 | * @brief Alphabet character type for use as input/output strings of trie keys 40 | */ 41 | typedef char AlphaChar; 42 | 43 | /** 44 | * @brief Error value for alphabet character 45 | */ 46 | #define ALPHA_CHAR_ERROR (~(AlphaChar)0) 47 | 48 | /** 49 | * @brief Raw character type mapped into packed set from AlphaChar, 50 | * for use in actual trie transition calculations 51 | */ 52 | typedef uint8_t TrieChar; 53 | /** 54 | * @brief Trie terminator character 55 | */ 56 | #define TRIE_CHAR_TERM ((TrieChar) 0) 57 | #define TRIE_CHAR_MAX UINT8_MAX 58 | 59 | /** 60 | * @brief Type of index into Trie double-array and tail structures 61 | */ 62 | typedef int32_t TrieIndex; 63 | /** 64 | * @brief Trie error index 65 | */ 66 | #define TRIE_INDEX_ERROR ((TrieIndex) 0) 67 | /** 68 | * @brief Maximum trie index value 69 | */ 70 | #define TRIE_INDEX_MAX INT32_MAX 71 | 72 | /** 73 | * @brief Type of value associated to trie entries 74 | */ 75 | typedef intptr_t TrieData; 76 | /** 77 | * @brief Trie error data 78 | */ 79 | #define TRIE_DATA_ERROR ((TrieData) -1) 80 | 81 | #endif /* __TRIEDEFS_H */ 82 | 83 | /* 84 | vi:ts=4:ai:expandtab 85 | */ 86 | -------------------------------------------------------------------------------- /src/datrie/typedefs.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* 3 | * libdatrie - Double-Array Trie Library 4 | * Copyright (C) 2006 Theppitak Karoonboonyanan 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | /* 22 | * typedefs.h - general types 23 | * Created : 11 Aug 2006 24 | * Author : Theppitak Karoonboonyanan 25 | */ 26 | 27 | #ifndef __TYPEDEFS_H 28 | #define __TYPEDEFS_H 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | typedef uint8_t byte; 35 | typedef uint16_t word; 36 | typedef uint32_t dword; 37 | 38 | 39 | #endif /* __TYPEDEFS_H */ 40 | 41 | /* 42 | vi:ts=4:ai:expandtab 43 | */ 44 | -------------------------------------------------------------------------------- /src/gsl/combination.c: -------------------------------------------------------------------------------- 1 | /* combination/combination.c 2 | * based on permutation/permutation.c by Brian Gough 3 | * 4 | * Copyright (C) 2001 Szymon Jaroszewicz 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or (at 9 | * your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | 21 | #include "gsl_errno.h" 22 | #include "gsl_combination.h" 23 | 24 | size_t 25 | gsl_combination_n (const gsl_combination * c) 26 | { 27 | return c->n ; 28 | } 29 | 30 | size_t 31 | gsl_combination_k (const gsl_combination * c) 32 | { 33 | return c->k ; 34 | } 35 | 36 | size_t * 37 | gsl_combination_data (const gsl_combination * c) 38 | { 39 | return c->data ; 40 | } 41 | 42 | int 43 | gsl_combination_valid (gsl_combination * c) 44 | { 45 | const size_t n = c->n ; 46 | const size_t k = c->k ; 47 | 48 | size_t i, j ; 49 | 50 | if( k > n ) 51 | { 52 | GSL_ERROR("combination has k greater than n", GSL_FAILURE) ; 53 | } 54 | for (i = 0; i < k; i++) 55 | { 56 | const size_t ci = c->data[i]; 57 | 58 | if (ci >= n) 59 | { 60 | GSL_ERROR("combination index outside range", GSL_FAILURE) ; 61 | } 62 | 63 | for (j = 0; j < i; j++) 64 | { 65 | if (c->data[j] == ci) 66 | { 67 | GSL_ERROR("duplicate combination index", GSL_FAILURE) ; 68 | } 69 | if (c->data[j] > ci) 70 | { 71 | GSL_ERROR("combination indices not in increasing order", 72 | GSL_FAILURE) ; 73 | } 74 | } 75 | } 76 | 77 | return GSL_SUCCESS; 78 | } 79 | 80 | 81 | int 82 | gsl_combination_next (gsl_combination * c) 83 | { 84 | /* Replaces c with the next combination (in the standard lexicographical 85 | * ordering). Returns GSL_FAILURE if there is no next combination. 86 | */ 87 | const size_t n = c->n; 88 | const size_t k = c->k; 89 | size_t *data = c->data; 90 | size_t i; 91 | 92 | if(k == 0) 93 | { 94 | return GSL_FAILURE; 95 | } 96 | i = k - 1; 97 | 98 | while(i > 0 && data[i] == n - k + i) 99 | { 100 | i--; 101 | } 102 | if(i == 0 && data[i] == n - k) 103 | { 104 | return GSL_FAILURE; 105 | } 106 | data[i]++; 107 | for(; i < k - 1; i++) 108 | { 109 | data[i + 1] = data[i] + 1; 110 | } 111 | return GSL_SUCCESS; 112 | } 113 | 114 | int 115 | gsl_combination_prev (gsl_combination * c) 116 | { 117 | /* Replaces c with the previous combination (in the standard 118 | * lexicographical ordering). Returns GSL_FAILURE if there is no 119 | * previous combination. 120 | */ 121 | const size_t n = c->n; 122 | const size_t k = c->k; 123 | size_t *data = c->data; 124 | size_t i; 125 | 126 | if(k == 0) 127 | { 128 | return GSL_FAILURE; 129 | } 130 | i = k - 1; 131 | 132 | while(i > 0 && data[i] == data[i-1] + 1) 133 | { 134 | i--; 135 | } 136 | if(i == 0 && data[i] == 0) 137 | { 138 | return GSL_FAILURE; 139 | } 140 | data[i++]--; 141 | for(; i < k; i++) 142 | { 143 | data[i] = n - k + i; 144 | } 145 | return GSL_SUCCESS; 146 | } 147 | 148 | int 149 | gsl_combination_memcpy (gsl_combination * dest, const gsl_combination * src) 150 | { 151 | const size_t src_n = src->n; 152 | const size_t src_k = src->k; 153 | const size_t dest_n = dest->n; 154 | const size_t dest_k = dest->k; 155 | 156 | if (src_n != dest_n || src_k != dest_k) 157 | { 158 | GSL_ERROR ("combination lengths are not equal", GSL_EBADLEN); 159 | } 160 | 161 | { 162 | size_t j; 163 | 164 | for (j = 0; j < src_k; j++) 165 | { 166 | dest->data[j] = src->data[j]; 167 | } 168 | } 169 | 170 | return GSL_SUCCESS; 171 | } 172 | -------------------------------------------------------------------------------- /src/gsl/error.c: -------------------------------------------------------------------------------- 1 | /* err/error.c 2 | * 3 | * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 3 of the License, or (at 8 | * your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "gsl_errno.h" 25 | #include "gsl_message.h" 26 | 27 | gsl_error_handler_t * gsl_error_handler = NULL; 28 | 29 | static void no_error_handler (const char *reason, const char *file, int line, int gsl_errno); 30 | 31 | void 32 | gsl_error (const char * reason, const char * file, int line, int gsl_errno) 33 | { 34 | if (gsl_error_handler) 35 | { 36 | (*gsl_error_handler) (reason, file, line, gsl_errno); 37 | return ; 38 | } 39 | 40 | gsl_stream_printf ("ERROR", file, line, reason); 41 | 42 | fflush (stdout); 43 | fprintf (stderr, "Default GSL error handler invoked.\n"); 44 | fflush (stderr); 45 | 46 | abort (); 47 | } 48 | 49 | gsl_error_handler_t * 50 | gsl_set_error_handler (gsl_error_handler_t * new_handler) 51 | { 52 | gsl_error_handler_t * previous_handler = gsl_error_handler; 53 | gsl_error_handler = new_handler; 54 | return previous_handler; 55 | } 56 | 57 | 58 | gsl_error_handler_t * 59 | gsl_set_error_handler_off (void) 60 | { 61 | gsl_error_handler_t * previous_handler = gsl_error_handler; 62 | gsl_error_handler = no_error_handler; 63 | return previous_handler; 64 | } 65 | 66 | static void 67 | no_error_handler (const char *reason, const char *file, int line, int gsl_errno) 68 | { 69 | /* do nothing */ 70 | (void) reason; 71 | (void) file; 72 | (void) line; 73 | (void) gsl_errno; 74 | return; 75 | } 76 | 77 | 78 | -------------------------------------------------------------------------------- /src/gsl/gsl_combination.h: -------------------------------------------------------------------------------- 1 | /* combination/gsl_combination.h 2 | * based on permutation/gsl_permutation.h by Brian Gough 3 | * 4 | * Copyright (C) 2001 Szymon Jaroszewicz 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or (at 9 | * your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | 21 | #ifndef __GSL_COMBINATION_H__ 22 | #define __GSL_COMBINATION_H__ 23 | 24 | #include 25 | #include "gsl_errno.h" 26 | 27 | #undef __BEGIN_DECLS 28 | #undef __END_DECLS 29 | #ifdef __cplusplus 30 | # define __BEGIN_DECLS extern "C" { 31 | # define __END_DECLS } 32 | #else 33 | # define __BEGIN_DECLS /* empty */ 34 | # define __END_DECLS /* empty */ 35 | #endif 36 | 37 | __BEGIN_DECLS 38 | 39 | struct gsl_combination_struct 40 | { 41 | size_t n; 42 | size_t k; 43 | size_t *data; 44 | }; 45 | 46 | typedef struct gsl_combination_struct gsl_combination; 47 | 48 | gsl_combination *gsl_combination_alloc (const size_t n, const size_t k); 49 | gsl_combination *gsl_combination_calloc (const size_t n, const size_t k); 50 | void gsl_combination_init_first (gsl_combination * c); 51 | void gsl_combination_init_last (gsl_combination * c); 52 | void gsl_combination_free (gsl_combination * c); 53 | int gsl_combination_memcpy (gsl_combination * dest, const gsl_combination * src); 54 | 55 | int gsl_combination_fread (FILE * stream, gsl_combination * c); 56 | int gsl_combination_fwrite (FILE * stream, const gsl_combination * c); 57 | int gsl_combination_fscanf (FILE * stream, gsl_combination * c); 58 | int gsl_combination_fprintf (FILE * stream, const gsl_combination * c, const char *format); 59 | 60 | size_t gsl_combination_n (const gsl_combination * c); 61 | size_t gsl_combination_k (const gsl_combination * c); 62 | size_t * gsl_combination_data (const gsl_combination * c); 63 | 64 | int gsl_combination_valid (gsl_combination * c); 65 | int gsl_combination_next (gsl_combination * c); 66 | int gsl_combination_prev (gsl_combination * c); 67 | 68 | static inline size_t 69 | gsl_combination_get (const gsl_combination * c, const size_t i) 70 | { 71 | return c->data[i]; 72 | } 73 | 74 | __END_DECLS 75 | 76 | #endif /* __GSL_COMBINATION_H__ */ 77 | -------------------------------------------------------------------------------- /src/gsl/gsl_message.h: -------------------------------------------------------------------------------- 1 | /* err/gsl_message.h 2 | * 3 | * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 3 of the License, or (at 8 | * your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef __GSL_MESSAGE_H__ 21 | #define __GSL_MESSAGE_H__ 22 | 23 | #undef __BEGIN_DECLS 24 | #undef __END_DECLS 25 | #ifdef __cplusplus 26 | # define __BEGIN_DECLS extern "C" { 27 | # define __END_DECLS } 28 | #else 29 | # define __BEGIN_DECLS /* empty */ 30 | # define __END_DECLS /* empty */ 31 | #endif 32 | 33 | __BEGIN_DECLS 34 | 35 | /* Provide a general messaging service for client use. Messages can 36 | * be selectively turned off at compile time by defining an 37 | * appropriate message mask. Client code which uses the GSL_MESSAGE() 38 | * macro must provide a mask which is or'ed with the GSL_MESSAGE_MASK. 39 | * 40 | * The messaging service can be completely turned off 41 | * by defining GSL_MESSAGING_OFF. */ 42 | 43 | void gsl_message(const char * message, const char * file, int line, 44 | unsigned int mask); 45 | 46 | #ifndef GSL_MESSAGE_MASK 47 | #define GSL_MESSAGE_MASK 0xffffffffu /* default all messages allowed */ 48 | #endif 49 | 50 | extern unsigned int gsl_message_mask ; 51 | 52 | /* Provide some symolic masks for client ease of use. */ 53 | 54 | enum { 55 | GSL_MESSAGE_MASK_A = 1, 56 | GSL_MESSAGE_MASK_B = 2, 57 | GSL_MESSAGE_MASK_C = 4, 58 | GSL_MESSAGE_MASK_D = 8, 59 | GSL_MESSAGE_MASK_E = 16, 60 | GSL_MESSAGE_MASK_F = 32, 61 | GSL_MESSAGE_MASK_G = 64, 62 | GSL_MESSAGE_MASK_H = 128 63 | } ; 64 | 65 | #ifdef GSL_MESSAGING_OFF /* throw away messages */ 66 | #define GSL_MESSAGE(message, mask) do { } while(0) 67 | #else /* output all messages */ 68 | #define GSL_MESSAGE(message, mask) \ 69 | do { \ 70 | if (mask & GSL_MESSAGE_MASK) \ 71 | gsl_message (message, __FILE__, __LINE__, mask) ; \ 72 | } while (0) 73 | #endif 74 | 75 | __END_DECLS 76 | 77 | #endif /* __GSL_MESSAGE_H__ */ 78 | 79 | 80 | -------------------------------------------------------------------------------- /src/gsl/init.c: -------------------------------------------------------------------------------- 1 | /* combination/init.c 2 | * based on permutation/init.c by Brian Gough 3 | * 4 | * Copyright (C) 2001 Szymon Jaroszewicz 5 | * Copyright (C) 2009 Brian Gough 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or (at 10 | * your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | */ 21 | 22 | #include 23 | #include "gsl_errno.h" 24 | #include "gsl_combination.h" 25 | 26 | gsl_combination * 27 | gsl_combination_alloc (const size_t n, const size_t k) 28 | { 29 | gsl_combination * c; 30 | 31 | if (n == 0) 32 | { 33 | GSL_ERROR_VAL ("combination parameter n must be positive integer", 34 | GSL_EDOM, 0); 35 | } 36 | if (k > n) 37 | { 38 | GSL_ERROR_VAL ("combination length k must be an integer less than or equal to n", 39 | GSL_EDOM, 0); 40 | } 41 | c = (gsl_combination *) malloc (sizeof (gsl_combination)); 42 | 43 | if (c == 0) 44 | { 45 | GSL_ERROR_VAL ("failed to allocate space for combination struct", 46 | GSL_ENOMEM, 0); 47 | } 48 | 49 | if (k > 0) 50 | { 51 | c->data = (size_t *) malloc (k * sizeof (size_t)); 52 | 53 | if (c->data == 0) 54 | { 55 | free (c); /* exception in constructor, avoid memory leak */ 56 | 57 | GSL_ERROR_VAL ("failed to allocate space for combination data", 58 | GSL_ENOMEM, 0); 59 | } 60 | } 61 | else 62 | { 63 | c->data = 0; 64 | } 65 | 66 | c->n = n; 67 | c->k = k; 68 | 69 | return c; 70 | } 71 | 72 | gsl_combination * 73 | gsl_combination_calloc (const size_t n, const size_t k) 74 | { 75 | size_t i; 76 | 77 | gsl_combination * c = gsl_combination_alloc (n, k); 78 | 79 | if (c == 0) 80 | return 0; 81 | 82 | /* initialize combination to identity */ 83 | 84 | for (i = 0; i < k; i++) 85 | { 86 | c->data[i] = i; 87 | } 88 | 89 | return c; 90 | } 91 | 92 | void 93 | gsl_combination_init_first (gsl_combination * c) 94 | { 95 | const size_t k = c->k ; 96 | size_t i; 97 | 98 | /* initialize combination to identity */ 99 | 100 | for (i = 0; i < k; i++) 101 | { 102 | c->data[i] = i; 103 | } 104 | } 105 | 106 | void 107 | gsl_combination_init_last (gsl_combination * c) 108 | { 109 | const size_t k = c->k ; 110 | size_t i; 111 | size_t n = c->n; 112 | 113 | /* initialize combination to identity */ 114 | 115 | for (i = 0; i < k; i++) 116 | { 117 | c->data[i] = n - k + i; 118 | } 119 | } 120 | 121 | void 122 | gsl_combination_free (gsl_combination * c) 123 | { 124 | if (c == NULL) return; 125 | if (c->k > 0) free (c->data); 126 | free (c); 127 | } 128 | -------------------------------------------------------------------------------- /src/gsl/message.c: -------------------------------------------------------------------------------- 1 | /* err/message.c 2 | * 3 | * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 3 of the License, or (at 8 | * your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "gsl_errno.h" 25 | #include "gsl_message.h" 26 | 27 | unsigned int gsl_message_mask = GSL_MESSAGE_MASK; 28 | 29 | void 30 | gsl_message (const char * reason, const char * file, int line, 31 | unsigned int mask) 32 | { 33 | if (mask & gsl_message_mask) 34 | { 35 | gsl_stream_printf ("MESSAGE", file, line, reason); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/gsl/stream.c: -------------------------------------------------------------------------------- 1 | /* err/stream.c 2 | * 3 | * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 3 of the License, or (at 8 | * your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "gsl_errno.h" 25 | #include "gsl_message.h" 26 | 27 | FILE * gsl_stream = NULL ; 28 | gsl_stream_handler_t * gsl_stream_handler = NULL; 29 | 30 | void 31 | gsl_stream_printf (const char *label, const char *file, int line, 32 | const char *reason) 33 | { 34 | if (gsl_stream == NULL) 35 | { 36 | gsl_stream = stderr; 37 | } 38 | if (gsl_stream_handler) 39 | { 40 | (*gsl_stream_handler) (label, file, line, reason); 41 | return; 42 | } 43 | fprintf (gsl_stream, "gsl: %s:%d: %s: %s\n", file, line, label, reason); 44 | 45 | } 46 | 47 | gsl_stream_handler_t * 48 | gsl_set_stream_handler (gsl_stream_handler_t * new_handler) 49 | { 50 | gsl_stream_handler_t * previous_handler = gsl_stream_handler; 51 | gsl_stream_handler = new_handler; 52 | return previous_handler; 53 | } 54 | 55 | FILE * 56 | gsl_set_stream (FILE * new_stream) 57 | { 58 | FILE * previous_stream; 59 | if (gsl_stream == NULL) { 60 | gsl_stream = stderr; 61 | } 62 | previous_stream = gsl_stream; 63 | gsl_stream = new_stream; 64 | return previous_stream; 65 | } 66 | -------------------------------------------------------------------------------- /src/gsl/strerror.c: -------------------------------------------------------------------------------- 1 | /* err/strerror.c 2 | * 3 | * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 3 of the License, or (at 8 | * your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "gsl_errno.h" 21 | 22 | const char * 23 | gsl_strerror (const int gsl_errno) 24 | { 25 | switch (gsl_errno) 26 | { 27 | case GSL_SUCCESS: 28 | return "success" ; 29 | case GSL_FAILURE: 30 | return "failure" ; 31 | case GSL_CONTINUE: 32 | return "the iteration has not converged yet"; 33 | case GSL_EDOM: 34 | return "input domain error" ; 35 | case GSL_ERANGE: 36 | return "output range error" ; 37 | case GSL_EFAULT: 38 | return "invalid pointer" ; 39 | case GSL_EINVAL: 40 | return "invalid argument supplied by user" ; 41 | case GSL_EFAILED: 42 | return "generic failure" ; 43 | case GSL_EFACTOR: 44 | return "factorization failed" ; 45 | case GSL_ESANITY: 46 | return "sanity check failed - shouldn't happen" ; 47 | case GSL_ENOMEM: 48 | return "malloc failed" ; 49 | case GSL_EBADFUNC: 50 | return "problem with user-supplied function"; 51 | case GSL_ERUNAWAY: 52 | return "iterative process is out of control"; 53 | case GSL_EMAXITER: 54 | return "exceeded max number of iterations" ; 55 | case GSL_EZERODIV: 56 | return "tried to divide by zero" ; 57 | case GSL_EBADTOL: 58 | return "specified tolerance is invalid or theoretically unattainable" ; 59 | case GSL_ETOL: 60 | return "failed to reach the specified tolerance" ; 61 | case GSL_EUNDRFLW: 62 | return "underflow" ; 63 | case GSL_EOVRFLW: 64 | return "overflow" ; 65 | case GSL_ELOSS: 66 | return "loss of accuracy" ; 67 | case GSL_EROUND: 68 | return "roundoff error" ; 69 | case GSL_EBADLEN: 70 | return "matrix/vector sizes are not conformant" ; 71 | case GSL_ENOTSQR: 72 | return "matrix not square" ; 73 | case GSL_ESING: 74 | return "singularity or extremely bad function behavior detected" ; 75 | case GSL_EDIVERGE: 76 | return "integral or series is divergent" ; 77 | case GSL_EUNSUP: 78 | return "the required feature is not supported by this hardware platform"; 79 | case GSL_EUNIMPL: 80 | return "the requested feature is not (yet) implemented"; 81 | case GSL_ECACHE: 82 | return "cache limit exceeded"; 83 | case GSL_ETABLE: 84 | return "table limit exceeded"; 85 | case GSL_ENOPROG: 86 | return "iteration is not making progress towards solution"; 87 | case GSL_ENOPROGJ: 88 | return "jacobian evaluations are not improving the solution"; 89 | case GSL_ETOLF: 90 | return "cannot reach the specified tolerance in F"; 91 | case GSL_ETOLX: 92 | return "cannot reach the specified tolerance in X"; 93 | case GSL_ETOLG: 94 | return "cannot reach the specified tolerance in gradient"; 95 | case GSL_EOF: 96 | return "end of file"; 97 | default: 98 | return "unknown error code" ; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/libqes/.gitignore: -------------------------------------------------------------------------------- 1 | # Editor temp files 2 | *.swp 3 | *.bak 4 | *~ 5 | 6 | # compiled 7 | build 8 | *.o 9 | *.a 10 | *.so 11 | tags 12 | version 13 | -------------------------------------------------------------------------------- /src/libqes/.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kdm9/axe/c8a636fd11d394034776bda45a5f0ef9b6e80046/src/libqes/.gitmodules -------------------------------------------------------------------------------- /src/libqes/.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | sudo: required 4 | dist: trusty 5 | 6 | env: 7 | - BUILD_TYPE=Release 8 | - BUILD_TYPE=Debug 9 | - BUILD_TYPE=Coverage 10 | 11 | compiler: 12 | - clang 13 | - gcc 14 | 15 | notifications: 16 | email: 17 | - kdmfoss@gmail.com 18 | 19 | install: 20 | - sudo apt-get install lcov python-pip zlib1g-dev 21 | - sudo pip install cpp-coveralls 22 | - mkdir build 23 | - mkdir target 24 | - cd build 25 | 26 | script: 27 | - cmake .. -DCMAKE_INSTALL_PREFIX=../target -DCMAKE_BUILD_TYPE=$BUILD_TYPE 28 | - make 29 | - ctest --verbose 30 | - make install 31 | - test -f ../target/include/qes.h 32 | 33 | after_success: 34 | - cd .. 35 | - if [ "$BUILD_TYPE" == "Coverage" ] ; then coveralls -e target -e test -e util -e zlib -E '.*\.h' -e build/CMakeFiles; fi 36 | -------------------------------------------------------------------------------- /src/libqes/AUTHORS: -------------------------------------------------------------------------------- 1 | Kevin Murray 2 | -------------------------------------------------------------------------------- /src/libqes/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 3.5...3.31) 2 | PROJECT(libqes C) 3 | 4 | # Append cmake-modules to module path 5 | SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} 6 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules") 7 | 8 | 9 | IF (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/version") 10 | FILE(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/version" LIBQES_VERSION) 11 | ELSE() 12 | # git describe as versioning 13 | EXECUTE_PROCESS(COMMAND git describe 14 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 15 | OUTPUT_VARIABLE LIBQES_VERSION 16 | OUTPUT_STRIP_TRAILING_WHITESPACE) 17 | ENDIF() 18 | 19 | ############################# 20 | ## Setup CMAKE Environment ## 21 | ############################# 22 | 23 | # Set this before you include libqes as a CMake subproject, so that we know not 24 | # to add cmake to the install rule 25 | IF (LIBQES_AS_SUBMODULE) 26 | SET(LIBQES_DONT_INSTALL True) 27 | ELSE() 28 | SET(LIBQES_DONT_INSTALL False) 29 | ENDIF() 30 | 31 | OPTION(NO_OPENMP "Disable OpenMP" False) 32 | OPTION(NO_ZLIB "Disable zlib" False) 33 | # Shortcut to enable dev compile options 34 | OPTION(DEV "Enable developer warnings") 35 | IF (DEV) 36 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize=leak -fsanitize=undefined") 37 | SET(CMAKE_BUILD_TYPE Coverage) 38 | ENDIF() 39 | 40 | IF (NOT CMAKE_BUILD_TYPE) 41 | SET(CMAKE_BUILD_TYPE Release) 42 | ENDIF() 43 | 44 | MESSAGE(STATUS "${CMAKE_BUILD_TYPE} build of ${PROJECT_NAME} version: ${LIBQES_VERSION}") 45 | 46 | # Set output directories 47 | SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 48 | SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 49 | SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 50 | 51 | # Include coverage module IFF out build type is Coverage to avoid bailing out 52 | # with unmet dependencies on Release builds, i.e. other peoples' computers 53 | IF (CMAKE_BUILD_TYPE STREQUAL "Coverage") 54 | INCLUDE(CodeCoverage) 55 | ENDIF() 56 | 57 | # Testing 58 | ENABLE_TESTING() 59 | 60 | # Packaging 61 | SET(CPACK_GENERATOR "TGZ;TBZ2") 62 | INCLUDE(CPack) 63 | 64 | ########################## 65 | ## Set Compiler Options ## 66 | ########################## 67 | 68 | 69 | SET(WARN_FLAGS "${WARN_FLAGS} -Wall -Wextra -Wpedantic") 70 | 71 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -D_GNU_SOURCE ${WARN_FLAGS}") 72 | 73 | SET(CMAKE_C_FLAGS_DEBUG "-ggdb") 74 | SET(CMAKE_C_FLAGS_RELEASE "-O3") 75 | 76 | 77 | ############################### 78 | ## Find Packages and Headers ## 79 | ############################### 80 | 81 | # Header/symbols 82 | INCLUDE(CheckSymbolExists) 83 | INCLUDE(CheckFunctionExists) 84 | INCLUDE(CheckLibraryExists) 85 | INCLUDE(CheckIncludeFiles) 86 | 87 | CHECK_SYMBOL_EXISTS(vasprintf stdio.h VASPRINTF_FOUND) 88 | CHECK_SYMBOL_EXISTS(asprintf stdio.h ASPRINTF_FOUND) 89 | CHECK_SYMBOL_EXISTS(getline stdio.h GETLINE_FOUND) 90 | CHECK_SYMBOL_EXISTS(strndup string.h STRNDUP_FOUND) 91 | 92 | IF (NOT ${NO_ZLIB}) 93 | FIND_PACKAGE(ZLIB 1.2.5 REQUIRED) 94 | CHECK_LIBRARY_EXISTS(${ZLIB_LIBRARIES} gzbuffer "" GZBUFFER_FOUND) 95 | ELSE() 96 | SET(ZLIB_FOUND FALSE) 97 | SET(GZBUFFER_FOUND FALSE) 98 | SET(ZLIB_C_FLAGS "") 99 | SET(ZLIB_LIBRARIES "") 100 | SET(ZLIB_INCLUDE_DIRS "") 101 | MESSAGE(STATUS "Building without zlib") 102 | ENDIF() 103 | 104 | IF (NOT ${NO_OPENMP}) 105 | FIND_PACKAGE(OpenMP) 106 | ELSE() 107 | SET(OPENMP_FOUND FALSE) 108 | SET(OpenMP_C_FLAGS "") 109 | MESSAGE(STATUS "Building without OpenMP") 110 | ENDIF() 111 | 112 | # Set dependency flags appropriately 113 | SET(LIBQES_DEPENDS_LIBS 114 | ${LIBQES_DEPENDS_LIBS} 115 | ${ZLIB_LIBRARIES}) 116 | SET(LIBQES_DEPENDS_INCLUDE_DIRS 117 | ${LIBQES_DEPENDS_INCLUDE_DIRS} 118 | ${ZLIB_INCLUDE_DIRS}) 119 | SET(LIBQES_DEPENDS_CFLAGS 120 | ${LIBQES_DEPENDS_CFLAGS} 121 | ${ZLIB_CFLAGS} 122 | ${OpenMP_C_FLAGS}) 123 | 124 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBQES_DEPENDS_CFLAGS}") 125 | 126 | 127 | ##################### 128 | ## Set CMake Paths ## 129 | ##################### 130 | 131 | # Set include dirs 132 | INCLUDE_DIRECTORIES( 133 | ${CMAKE_BINARY_DIR} 134 | ${CMAKE_CURRENT_SOURCE_DIR}/src 135 | ${CMAKE_CURRENT_SOURCE_DIR}/test 136 | ${CMAKE_CURRENT_SOURCE_DIR}/test/tinytest 137 | ${LIBQES_DEPENDS_INCLUDE_DIRS} 138 | ) 139 | 140 | # Set link dirs 141 | LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/lib) 142 | 143 | # Traverse to library source and tests 144 | ADD_SUBDIRECTORY(src) 145 | if (NOT LIBQES_AS_SUBMODULE) 146 | ADD_SUBDIRECTORY(test) 147 | endif() 148 | -------------------------------------------------------------------------------- /src/libqes/README.md: -------------------------------------------------------------------------------- 1 | libqes 2 | ====== 3 | 4 | A C library for various bioinformatics-y tasks. Proper docs will come in time. 5 | For now, we have reasonable test coverage under `./test/` that demonstrate the 6 | API. 7 | 8 | ###Tests: 9 | 10 | | Jenkins GNU/Linux | [![Build Status](http://biojenkins.anu.edu.au/job/libqes/badge/icon)](http://biojenkins.anu.edu.au/job/libqes/) | 11 | | ----------------- | --- | 12 | | Jenkins MinGW | [![Build Status](http://biojenkins.anu.edu.au/job/libqes-mingw/badge/icon)](http://biojenkins.anu.edu.au/job/libqes-mingw/) | 13 | | TravisCI | [![Build Status](https://travis-ci.org/kdmurray91/libqes.svg?branch=dev)](https://travis-ci.org/kdmurray91/libqes) | 14 | | Test Coverage | [![Coverage Status](https://img.shields.io/coveralls/kdmurray91/libqes.svg)](https://coveralls.io/r/kdmurray91/libqes?branch=master) | 15 | 16 | 17 | License 18 | ======= 19 | 20 | ![GPL logo](http://www.gnu.org/graphics/gplv3-127x51.png) 21 | 22 | All libqes source code is licensed under the GNU Public License version 3, or a 23 | later version at your preference. For license text, see `./gpl-3.0.txt` or 24 | [the GNU website here](http://www.gnu.org/licenses/gpl-3.0.html). 25 | 26 | The source of `tinytest`, located in `tests/tinytest`, is Copyright 2009-2012 27 | Nick Matthewson; `tinytest` is distributed under the 3-clause BSD license. 28 | `tinytest` is hosted at 29 | [Nick's github page](https://github.com/nmathewson/tinytest). 30 | 31 | `src/crc.[ch]` are from gnulib, and are licensed under the LGPL. 32 | -------------------------------------------------------------------------------- /src/libqes/TODO.md: -------------------------------------------------------------------------------- 1 | KDM Todos: 2 | --------- 3 | 4 | Error handling: 5 | 6 | - write tests 7 | 8 | qes_seq: 9 | 10 | - split qes_seq_print into separate functions for FASTQ and FASTA. Also maybe 11 | allow line wrapping for FASTA. 12 | -------------------------------------------------------------------------------- /src/libqes/cmake-modules/CodeCoverage.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # 2012-01-31, Lars Bilke 3 | # - Enable Code Coverage 4 | # 5 | # 2013-09-17, Joakim Söderberg 6 | # - Added support for Clang. 7 | # - Some additional usage instructions. 8 | # 9 | # USAGE: 10 | # 1. Copy this file into your cmake modules path. 11 | # 12 | # 2. Add the following line to your CMakeLists.txt: 13 | # INCLUDE(CodeCoverage) 14 | # 15 | # 3. Set compiler flags to turn off optimization and enable coverage: 16 | # SET(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage") 17 | # SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage") 18 | # 19 | # 3. Use the function SETUP_TARGET_FOR_COVERAGE to create a custom make target 20 | # which runs your test executable and produces a lcov code coverage report: 21 | # Example: 22 | # SETUP_TARGET_FOR_COVERAGE( 23 | # my_coverage_target # Name for custom target. 24 | # test_driver # Name of the test driver executable that runs the tests. 25 | # # NOTE! This should always have a ZERO as exit code 26 | # # otherwise the coverage generation will not complete. 27 | # coverage # Name of output directory. 28 | # ) 29 | # 30 | # 4. Build a Debug build: 31 | # cmake -DCMAKE_BUILD_TYPE=Debug .. 32 | # make 33 | # make my_coverage_target 34 | # 35 | # 36 | 37 | # Check prereqs 38 | FIND_PROGRAM( GCOV_PATH gcov ) 39 | FIND_PROGRAM( LCOV_PATH lcov ) 40 | FIND_PROGRAM( GENHTML_PATH genhtml ) 41 | FIND_PROGRAM( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/tests) 42 | 43 | 44 | 45 | SET(CMAKE_CXX_FLAGS_COVERAGE 46 | "${CMAKE_CXX_FLAGS_DEBUG} -g -O0 --coverage -fprofile-arcs -ftest-coverage" 47 | CACHE STRING "Flags used by the C++ compiler during coverage builds." 48 | FORCE) 49 | SET(CMAKE_C_FLAGS_COVERAGE 50 | "${CMAKE_C_FLAGS_DEBUG} -g -O0 --coverage -fprofile-arcs -ftest-coverage" 51 | CACHE STRING "Flags used by the C compiler during coverage builds." 52 | FORCE) 53 | SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE 54 | "" 55 | CACHE STRING "Flags used for linking binaries during coverage builds." 56 | FORCE) 57 | SET(CMAKE_SHARED_LINKER_FLAGS_COVERAGE 58 | "" 59 | CACHE STRING "Flags used by the shared libraries linker during coverage builds." 60 | FORCE) 61 | MARK_AS_ADVANCED( 62 | CMAKE_CXX_FLAGS_COVERAGE 63 | CMAKE_C_FLAGS_COVERAGE 64 | CMAKE_EXE_LINKER_FLAGS_COVERAGE 65 | CMAKE_SHARED_LINKER_FLAGS_COVERAGE ) 66 | 67 | IF(NOT GCOV_PATH) 68 | MESSAGE(FATAL_ERROR "gcov not found! Aborting...") 69 | ENDIF() # NOT GCOV_PATH 70 | 71 | IF(NOT CMAKE_COMPILER_IS_GNUCC AND NOT CMAKE_COMPILER_IS_GNUCXX) 72 | # Clang version 3.0.0 and greater now supports gcov as well. 73 | MESSAGE(WARNING "Compiler is not GNU gcc! Clang Version 3.0.0 and greater supports gcov as well, but older versions don't.") 74 | 75 | IF(NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" AND NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") 76 | MESSAGE(FATAL_ERROR "Compiler is not GNU gcc! Aborting...") 77 | ENDIF() 78 | ENDIF() # NOT CMAKE_COMPILER_IS_GNUCXX 79 | 80 | 81 | 82 | # Param _targetname The name of new the custom make target 83 | # Param _testrunner The name of the target which runs the tests. 84 | # MUST return ZERO always, even on errors. 85 | # If not, no coverage report will be created! 86 | # Param _outputname lcov output is generated as _outputname.info 87 | # HTML report is generated in _outputname/index.html 88 | # Optional fourth parameter is passed as arguments to _testrunner 89 | # Pass them in list form, e.g.: "-j;2" for -j 2 90 | FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname _coverdir) 91 | 92 | IF(NOT LCOV_PATH) 93 | MESSAGE(FATAL_ERROR "lcov not found! Aborting...") 94 | ENDIF() # NOT LCOV_PATH 95 | 96 | IF(NOT GENHTML_PATH) 97 | MESSAGE(FATAL_ERROR "genhtml not found! Aborting...") 98 | ENDIF() # NOT GENHTML_PATH 99 | 100 | # Setup target 101 | ADD_CUSTOM_TARGET(${_targetname} 102 | 103 | # Cleanup lcov 104 | ${LCOV_PATH} --rc lcov_branch_coverage=1 --directory ${_coverdir} --zerocounters 105 | 106 | # Run tests 107 | COMMAND ${_testrunner} ${ARGV4} 108 | 109 | # Capturing lcov counters and generating report 110 | COMMAND ${LCOV_PATH} --rc lcov_branch_coverage=1 --directory ${_coverdir} --capture --output-file ${_outputname}.info 111 | COMMAND ${GENHTML_PATH} --branch-coverage -o ${_outputname} ${_outputname}.info 112 | COMMAND ${CMAKE_COMMAND} -E remove ${_outputname}.info 113 | 114 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 115 | COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report." 116 | ) 117 | 118 | # Show info where to find the report 119 | ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD 120 | COMMAND ; 121 | COMMENT "Open ./${_outputname}/index.html in your browser to view the coverage report." 122 | ) 123 | 124 | ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE 125 | 126 | # Param _targetname The name of new the custom make target 127 | # Param _testrunner The name of the target which runs the tests 128 | # Param _outputname cobertura output is generated as _outputname.xml 129 | # Optional fourth parameter is passed as arguments to _testrunner 130 | # Pass them in list form, e.g.: "-j;2" for -j 2 131 | FUNCTION(SETUP_TARGET_FOR_COVERAGE_COBERTURA _targetname _testrunner _outputname) 132 | 133 | IF(NOT PYTHON_EXECUTABLE) 134 | MESSAGE(FATAL_ERROR "Python not found! Aborting...") 135 | ENDIF() # NOT PYTHON_EXECUTABLE 136 | 137 | IF(NOT GCOVR_PATH) 138 | MESSAGE(FATAL_ERROR "gcovr not found! Aborting...") 139 | ENDIF() # NOT GCOVR_PATH 140 | 141 | ADD_CUSTOM_TARGET(${_targetname} 142 | 143 | # Run tests 144 | ${_testrunner} ${ARGV3} 145 | 146 | # Running gcovr 147 | COMMAND ${GCOVR_PATH} -x -r ${CMAKE_SOURCE_DIR} -e '${CMAKE_SOURCE_DIR}/tests/' -o ${_outputname}.xml 148 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 149 | COMMENT "Running gcovr to produce Cobertura code coverage report." 150 | ) 151 | 152 | # Show info where to find the report 153 | ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD 154 | COMMAND ; 155 | COMMENT "Cobertura code coverage report saved in ${_outputname}.xml." 156 | ) 157 | 158 | ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE_COBERTURA 159 | -------------------------------------------------------------------------------- /src/libqes/cmake-modules/FindLIBQES.cmake: -------------------------------------------------------------------------------- 1 | # - Find libqes 2 | # Find the native libqes includes and library. 3 | # Once done this will define 4 | # 5 | # LIBQES_INCLUDE_DIRS - where to find qes.h, etc. 6 | # LIBQES_LIBRARIES - List of libraries when using libqes. 7 | # LIBQES_FOUND - True if libqes found. 8 | # 9 | # LIBQES_VERSION_STRING - The version of libqes found (x.y.z) 10 | # LIBQES_VERSION_MAJOR - The major version of libqes 11 | # LIBQES_VERSION_MINOR - The minor version of libqes 12 | # LIBQES_VERSION_PATCH - The patch version of libqes 13 | # LIBQES_VERSION_PREREL - The pre-release version of libqes 14 | # LIBQES_VERSION_GIT - The git version of libqes 15 | # 16 | # An includer may set LIBQES_ROOT to a libqes installation root to tell 17 | # this module where to look. 18 | 19 | # ============================================================================= 20 | # Copyright 2014 Kevin Murray. Adapted from FindZLIB.cmake 21 | # Licensed under the 3-clause BSD license 22 | # 23 | # Redistribution and use in source and binary forms, with or without 24 | # modification, are permitted provided that the following conditions 25 | # are met: 26 | # 1. Redistributions of source code must retain the above copyright 27 | # notice, this list of conditions and the following disclaimer. 28 | # 2. Redistributions in binary form must reproduce the above copyright 29 | # notice, this list of conditions and the following disclaimer in the 30 | # documentation and/or other materials provided with the distribution. 31 | # 3. Neither the name of the University nor the names of its contributors 32 | # may be used to endorse or promote products derived from this software 33 | # without specific prior written permission. 34 | # 35 | # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 36 | # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 37 | # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 38 | # REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 39 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 40 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 41 | # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 42 | # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 43 | # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 44 | # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 45 | 46 | set(_LIBQES_SEARCHES) 47 | 48 | # Search LIBQES_ROOT first if it is set. 49 | if(LIBQES_ROOT) 50 | set(_LIBQES_SEARCH_ROOT PATHS ${LIBQES_ROOT} NO_DEFAULT_PATH) 51 | list(APPEND _LIBQES_SEARCHES _LIBQES_SEARCH_ROOT) 52 | endif() 53 | 54 | # Normal search. 55 | set(_LIBQES_SEARCH_NORMAL 56 | PATHS "$ENV{PROGRAMFILES}/libqes" 57 | ) 58 | list(APPEND _LIBQES_SEARCHES _LIBQES_SEARCH_NORMAL) 59 | 60 | # Try each search configuration. 61 | foreach(search ${_LIBQES_SEARCHES}) 62 | find_path(LIBQES_INCLUDE_DIR NAMES qes.h ${${search}} PATH_SUFFIXES include) 63 | find_library(LIBQES_LIBRARY NAMES qes ${${search}} PATH_SUFFIXES lib) 64 | endforeach() 65 | 66 | mark_as_advanced(LIBQES_LIBRARY LIBQES_INCLUDE_DIR) 67 | # Handle version. Again, flogged from zlib 68 | if(LIBQES_INCLUDE_DIR AND EXISTS "${LIBQES_INCLUDE_DIR}/qes_config.h") 69 | file(STRINGS "${LIBQES_INCLUDE_DIR}/qes_config.h" LIBQES_H REGEX "^#define LIBQES_VERSION \"[^\"]*\"") 70 | 71 | string(REGEX REPLACE "^.*LIBQES_VERSION \"[Vv]?([0-9]+).*$" "\\1" LIBQES_VERSION_MAJOR "${LIBQES_H}") 72 | string(REGEX REPLACE "^.*LIBQES_VERSION \"[Vv]?[0-9]+\\.([0-9]+).*$" "\\1" LIBQES_VERSION_MINOR "${LIBQES_H}") 73 | string(REGEX REPLACE "^.*LIBQES_VERSION \"[Vv]?[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" LIBQES_VERSION_PATCH "${LIBQES_H}") 74 | set(LIBQES_VERSION_STRING "${LIBQES_VERSION_MAJOR}.${LIBQES_VERSION_MINOR}.${LIBQES_VERSION_PATCH}") 75 | 76 | # only append a EXTRA version if it exists: 77 | set(LIBQES_VERSION_EXTRA "") 78 | if( "${LIBQES_H}" MATCHES "^.*LIBQES_VERSION \"[Vv]?[0-9]+\\.[0-9]+\\.[0-9]+(.+)\\+git.*$") 79 | set(LIBQES_VERSION_PREREL "${CMAKE_MATCH_1}") 80 | endif() 81 | if( "${LIBQES_H}" MATCHES "^.*LIBQES_VERSION \"[Vv]?[0-9]+\\.[0-9]+\\.[0-9]+.*\\+git\\.(.+)$") 82 | set(LIBQES_VERSION_git "${CMAKE_MATCH_1}") 83 | endif() 84 | set(LIBQES_VERSION_STRING "${LIBQES_VERSION_STRING}${LIBQES_VERSION_PREREL}") 85 | endif() 86 | 87 | # handle the QUIETLY and REQUIRED arguments and set LIBQES_FOUND to TRUE if 88 | # all listed variables are TRUE 89 | include(FindPackageHandleStandardArgs) 90 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBQES REQUIRED_VARS LIBQES_LIBRARY LIBQES_INCLUDE_DIR 91 | VERSION_VAR LIBQES_VERSION_STRING) 92 | 93 | if(LIBQES_FOUND) 94 | set(LIBQES_INCLUDE_DIRS ${LIBQES_INCLUDE_DIR}) 95 | set(LIBQES_LIBRARIES ${LIBQES_LIBRARY}) 96 | endif() 97 | 98 | -------------------------------------------------------------------------------- /src/libqes/cmake-modules/GetGitRevisionDescription.cmake: -------------------------------------------------------------------------------- 1 | # - Returns a version string from Git 2 | # 3 | # These functions force a re-configure on each git commit so that you can 4 | # trust the values of the variables in your build system. 5 | # 6 | # get_git_head_revision( [ ...]) 7 | # 8 | # Returns the refspec and sha hash of the current head revision 9 | # 10 | # git_describe( [ ...]) 11 | # 12 | # Returns the results of git describe on the source tree, and adjusting 13 | # the output so that it tests false if an error occurs. 14 | # 15 | # git_get_exact_tag( [ ...]) 16 | # 17 | # Returns the results of git describe --exact-match on the source tree, 18 | # and adjusting the output so that it tests false if there was no exact 19 | # matching tag. 20 | # 21 | # Requires CMake 2.6 or newer (uses the 'function' command) 22 | # 23 | # Original Author: 24 | # 2009-2010 Ryan Pavlik 25 | # http://academic.cleardefinition.com 26 | # Iowa State University HCI Graduate Program/VRAC 27 | # 28 | # Copyright Iowa State University 2009-2010. 29 | # Distributed under the Boost Software License, Version 1.0. 30 | # (See accompanying file LICENSE_1_0.txt or copy at 31 | # http://www.boost.org/LICENSE_1_0.txt) 32 | 33 | if(__get_git_revision_description) 34 | return() 35 | endif() 36 | set(__get_git_revision_description YES) 37 | 38 | # We must run the following at "include" time, not at function call time, 39 | # to find the path to this module rather than the path to a calling list file 40 | get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH) 41 | 42 | function(get_git_head_revision _refspecvar _hashvar) 43 | set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") 44 | set(GIT_DIR "${GIT_PARENT_DIR}/.git") 45 | while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories 46 | set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}") 47 | get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH) 48 | if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT) 49 | # We have reached the root directory, we are not in git 50 | set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE) 51 | set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE) 52 | return() 53 | endif() 54 | set(GIT_DIR "${GIT_PARENT_DIR}/.git") 55 | endwhile() 56 | # check if this is a submodule 57 | if(NOT IS_DIRECTORY ${GIT_DIR}) 58 | file(READ ${GIT_DIR} submodule) 59 | string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule}) 60 | get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH) 61 | get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE) 62 | endif() 63 | set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data") 64 | if(NOT EXISTS "${GIT_DATA}") 65 | file(MAKE_DIRECTORY "${GIT_DATA}") 66 | endif() 67 | 68 | if(NOT EXISTS "${GIT_DIR}/HEAD") 69 | return() 70 | endif() 71 | set(HEAD_FILE "${GIT_DATA}/HEAD") 72 | configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY) 73 | 74 | configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in" 75 | "${GIT_DATA}/grabRef.cmake" 76 | @ONLY) 77 | include("${GIT_DATA}/grabRef.cmake") 78 | 79 | set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE) 80 | set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE) 81 | endfunction() 82 | 83 | function(git_describe _var) 84 | if(NOT GIT_FOUND) 85 | find_package(Git QUIET) 86 | endif() 87 | get_git_head_revision(refspec hash) 88 | if(NOT GIT_FOUND) 89 | set(${_var} "GIT-NOTFOUND" PARENT_SCOPE) 90 | return() 91 | endif() 92 | if(NOT hash) 93 | set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE) 94 | return() 95 | endif() 96 | 97 | # TODO sanitize 98 | #if((${ARGN}" MATCHES "&&") OR 99 | # (ARGN MATCHES "||") OR 100 | # (ARGN MATCHES "\\;")) 101 | # message("Please report the following error to the project!") 102 | # message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}") 103 | #endif() 104 | 105 | #message(STATUS "Arguments to execute_process: ${ARGN}") 106 | 107 | execute_process(COMMAND 108 | "${GIT_EXECUTABLE}" 109 | describe 110 | ${hash} 111 | ${ARGN} 112 | WORKING_DIRECTORY 113 | "${CMAKE_SOURCE_DIR}" 114 | RESULT_VARIABLE 115 | res 116 | OUTPUT_VARIABLE 117 | out 118 | ERROR_QUIET 119 | OUTPUT_STRIP_TRAILING_WHITESPACE) 120 | if(NOT res EQUAL 0) 121 | set(out "${out}-${res}-NOTFOUND") 122 | endif() 123 | 124 | set(${_var} "${out}" PARENT_SCOPE) 125 | endfunction() 126 | 127 | function(git_get_exact_tag _var) 128 | git_describe(out --exact-match ${ARGN}) 129 | set(${_var} "${out}" PARENT_SCOPE) 130 | endfunction() 131 | -------------------------------------------------------------------------------- /src/libqes/cmake-modules/GetGitRevisionDescription.cmake.in: -------------------------------------------------------------------------------- 1 | # 2 | # Internal file for GetGitRevisionDescription.cmake 3 | # 4 | # Requires CMake 2.6 or newer (uses the 'function' command) 5 | # 6 | # Original Author: 7 | # 2009-2010 Ryan Pavlik 8 | # http://academic.cleardefinition.com 9 | # Iowa State University HCI Graduate Program/VRAC 10 | # 11 | # Copyright Iowa State University 2009-2010. 12 | # Distributed under the Boost Software License, Version 1.0. 13 | # (See accompanying file LICENSE_1_0.txt or copy at 14 | # http://www.boost.org/LICENSE_1_0.txt) 15 | 16 | set(HEAD_HASH) 17 | 18 | file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024) 19 | 20 | string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS) 21 | if(HEAD_CONTENTS MATCHES "ref") 22 | # named branch 23 | string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}") 24 | if(EXISTS "@GIT_DIR@/${HEAD_REF}") 25 | configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY) 26 | elseif(EXISTS "@GIT_DIR@/logs/${HEAD_REF}") 27 | configure_file("@GIT_DIR@/logs/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY) 28 | set(HEAD_HASH "${HEAD_REF}") 29 | endif() 30 | else() 31 | # detached HEAD 32 | configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY) 33 | endif() 34 | 35 | if(NOT HEAD_HASH) 36 | file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024) 37 | string(STRIP "${HEAD_HASH}" HEAD_HASH) 38 | endif() 39 | -------------------------------------------------------------------------------- /src/libqes/cmake-modules/GitSemVer.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014-2015 Kevin Murray 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining 4 | # a copy of this software and associated documentation files (the 5 | # "Software"), to deal in the Software without restriction, including 6 | # without limitation the rights to use, copy, modify, merge, publish, 7 | # distribute, sublicense, and/or sell copies of the Software, and to 8 | # permit persons to whom the Software is furnished to do so, subject to 9 | # the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be 12 | # included in all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 18 | # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 19 | # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | INCLUDE(GetGitRevisionDescription) 24 | 25 | function(GetGitSemVer _var) 26 | get_git_head_revision(rev hash) 27 | git_get_exact_tag(tag) 28 | 29 | IF(NOT "${tag}" MATCHES "^-") 30 | SET(vers "${tag}") 31 | ELSE() 32 | git_describe(gitdesc "--always") 33 | if("${gitdesc}" MATCHES "^.+-.+-.+$") 34 | STRING (REGEX REPLACE "-" " " gdlist ${gitdesc}) 35 | SEPARATE_ARGUMENTS(gdlist) 36 | LIST(GET gdlist 0 tag) 37 | LIST(GET gdlist 1 cmts_since_tag) 38 | SET(vers "${tag}-${cmts_since_tag}-dirty") 39 | ELSE() 40 | SET(vers "dirty") 41 | ENDIF() 42 | ENDIF() 43 | 44 | IF (NOT "${hash}" STREQUAL "") 45 | STRING(SUBSTRING ${hash} 0 7 hash) 46 | set(vers "${vers}+git=${hash}") 47 | ENDIF() 48 | set(${_var} ${vers} PARENT_SCOPE) 49 | endfunction() 50 | -------------------------------------------------------------------------------- /src/libqes/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB LIBQES_SOURCES qes_*.c) 2 | 3 | # Targets 4 | if(LIBQES_DONT_INSTALL) 5 | ADD_LIBRARY(qes_static STATIC EXCLUDE_FROM_ALL ${LIBQES_SOURCES}) 6 | ADD_LIBRARY(qes SHARED EXCLUDE_FROM_ALL ${LIBQES_SOURCES}) 7 | else() 8 | ADD_LIBRARY(qes_static STATIC ${LIBQES_SOURCES}) 9 | ADD_LIBRARY(qes SHARED ${LIBQES_SOURCES}) 10 | endif() 11 | 12 | 13 | SET_TARGET_PROPERTIES(qes_static PROPERTIES OUTPUT_NAME qes) 14 | TARGET_LINK_LIBRARIES(qes_static ${LIBQES_DEPENDS_LIBS}) 15 | target_include_directories(qes_static PUBLIC ${LIBQES_DEPENDS_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}) 16 | 17 | SET_TARGET_PROPERTIES(qes PROPERTIES SONAME_VERSION 0 VERSION 0) 18 | TARGET_LINK_LIBRARIES(qes ${LIBQES_DEPENDS_LIBS}) 19 | target_include_directories(qes PUBLIC ${LIBQES_DEPENDS_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}) 20 | 21 | CONFIGURE_FILE(qes_config.h.in ${CMAKE_BINARY_DIR}/qes_config.h) 22 | FILE(GLOB LIBQES_HEADERS ${CMAKE_SOURCE_DIR}/src/*.h ${CMAKE_BINARY_DIR}/qes_config.h) 23 | 24 | IF (NOT LIBQES_DONT_INSTALL) 25 | INSTALL(FILES ${LIBQES_HEADERS} DESTINATION "include") 26 | INSTALL(TARGETS qes qes_static DESTINATION "lib") 27 | ENDIF() 28 | -------------------------------------------------------------------------------- /src/libqes/src/crc.c: -------------------------------------------------------------------------------- 1 | /* crc.c -- cyclic redundancy checks 2 | Copyright (C) 2005-2006, 2009-2014 Free Software Foundation, Inc. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation; either version 3, or (at your option) 7 | any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . */ 16 | 17 | /* Written by Simon Josefsson. */ 18 | 19 | #include "crc.h" 20 | 21 | /* Table of CRCs of all 8-bit messages. Generated by running code 22 | from RFC 1952 modified to print out the table. */ 23 | static const uint32_t crc32_table[256] = { 24 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 25 | 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 26 | 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, 27 | 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 28 | 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 29 | 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 30 | 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, 31 | 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 32 | 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 33 | 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 34 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, 35 | 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, 36 | 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 37 | 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 38 | 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, 39 | 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 40 | 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 41 | 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 42 | 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 43 | 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, 44 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 45 | 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 46 | 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, 47 | 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 48 | 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 49 | 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 50 | 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, 51 | 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 52 | 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 53 | 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 54 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, 55 | 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 56 | 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 57 | 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 58 | 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, 59 | 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 60 | 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 61 | 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 62 | 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 63 | 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 64 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 65 | 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 66 | 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d 67 | }; 68 | 69 | /* 70 | * The following function was extracted from RFC 1952 by Simon 71 | * Josefsson. It was modified to avoid initial and final XOR, to use 72 | * size_t for the buffer length, and to use the const keyword. 73 | */ 74 | uint32_t 75 | crc32_update_no_xor (uint32_t crc, const char *buf, size_t len) 76 | { 77 | size_t n; 78 | 79 | for (n = 0; n < len; n++) 80 | crc = crc32_table[(crc ^ buf[n]) & 0xff] ^ (crc >> 8); 81 | 82 | return crc; 83 | } 84 | 85 | uint32_t 86 | crc32_no_xor (const char *buf, size_t len) 87 | { 88 | return crc32_update_no_xor (0L, buf, len); 89 | } 90 | 91 | uint32_t 92 | crc32_update (uint32_t crc, const char *buf, size_t len) 93 | { 94 | return crc32_update_no_xor (crc ^ 0xffffffff, buf, len) ^ 0xffffffff; 95 | } 96 | 97 | uint32_t 98 | crc32 (const char *buf, size_t len) 99 | { 100 | return crc32_update (0L, buf, len); 101 | } 102 | -------------------------------------------------------------------------------- /src/libqes/src/crc.h: -------------------------------------------------------------------------------- 1 | /* crc.h -- cyclic redundancy checks 2 | Copyright (C) 2005, 2009-2014 Free Software Foundation, Inc. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation; either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . */ 16 | 17 | /* Written by Simon Josefsson. */ 18 | 19 | #ifndef CRC_H 20 | # define CRC_H 1 21 | 22 | #include 23 | #include 24 | 25 | /* Compute CRC-32 value of LEN bytes long BUF, and return it. */ 26 | uint32_t crc32 (const char *buf, size_t len); 27 | 28 | /* Incrementally update CRC-32 value CRC using LEN bytes long BUF. In 29 | the first call, use 0 as the value for CRC. Return the updated 30 | CRC-32 value. */ 31 | uint32_t crc32_update (uint32_t crc, const char *buf, size_t len); 32 | 33 | /* Compute modified-CRC-32 value of LEN bytes long BUF, and return it. 34 | The "modification" is to avoid the initial and final XOR operation. 35 | Due to historic implementation errors, this variant is sometimes 36 | used (i.e., in RFC 3961). */ 37 | uint32_t crc32_no_xor (const char *buf, size_t len); 38 | 39 | /* Incrementally update modified-CRC-32 value CRC using LEN bytes long 40 | BUF. In the first call, use 0 as the value for CRC. Return the 41 | updated modified-CRC-32 value. The "modification" is to avoid the 42 | initial and final XOR operation. Due to historic implementation 43 | errors, this variant is sometimes used (i.e., in RFC 3961). */ 44 | uint32_t crc32_update_no_xor (uint32_t crc, const char *buf, size_t len); 45 | 46 | #endif /* CRC_H */ 47 | -------------------------------------------------------------------------------- /src/libqes/src/qes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Kevin Murray 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | /* 18 | * ========================================================================== 19 | * 20 | * Filename: qes.h 21 | * 22 | * Description: Some common sequence analysis stuff 23 | * License: GPLv3+ 24 | * Author: Kevin Murray, spam@kdmurray.id.au 25 | * 26 | * =========================================================================== 27 | */ 28 | 29 | #ifndef LIBQES_H 30 | #define LIBQES_H 31 | 32 | 33 | /* ##### HEADER FILE INCLUDES ########################################## */ 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #endif /* LIBQES_H */ 43 | -------------------------------------------------------------------------------- /src/libqes/src/qes_compat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Kevin Murray 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | /* 18 | * ============================================================================ 19 | * 20 | * Filename: qes_compat.c 21 | * 22 | * Description: Compatibility helpers for cross-platformness 23 | * License: GPLv3+ 24 | * Author: Kevin Murray, spam@kdmurray.id.au 25 | * 26 | * ============================================================================ 27 | */ 28 | 29 | #include "qes_compat.h" 30 | 31 | 32 | #ifndef STRNDUP_FOUND 33 | char * 34 | strndup(const char *s, size_t n) 35 | { 36 | char *dest = malloc(n+1); 37 | if (dest == NULL) return NULL; 38 | strncpy(dest, s, n); 39 | dest[n] = '\0'; 40 | return dest; 41 | } 42 | #endif 43 | 44 | #ifndef VASPRINTF_FOUND 45 | int vasprintf(char **ret, const char *format, va_list args) 46 | { 47 | va_list copy; 48 | int count; 49 | va_copy(copy, args); 50 | 51 | *ret = NULL; 52 | 53 | count = vsnprintf(NULL, 0, format, args); 54 | if (count >= 0) { 55 | char *buffer = malloc(count + 1); 56 | if (buffer == NULL) { 57 | count = -1; 58 | } else if ((count = vsnprintf(buffer, count + 1, format, copy)) < 0) { 59 | free(buffer); 60 | } 61 | else { 62 | *ret = buffer; 63 | } 64 | } 65 | va_end(copy); 66 | 67 | return count; 68 | } 69 | #endif 70 | 71 | #ifndef ASPRINTF_FOUND 72 | int asprintf(char **ret, const char *format, ...) 73 | { 74 | va_list args; 75 | int count; 76 | 77 | va_start(args, format); 78 | count = vasprintf(ret, format, args); 79 | va_end(args); 80 | return(count); 81 | } 82 | #endif 83 | -------------------------------------------------------------------------------- /src/libqes/src/qes_compat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Kevin Murray 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | /* 18 | * ============================================================================ 19 | * 20 | * Filename: qes_compat.h 21 | * 22 | * Description: Compatibility helpers for cross-platformness 23 | * License: GPLv3+ 24 | * Author: Kevin Murray, spam@kdmurray.id.au 25 | * 26 | * ============================================================================ 27 | */ 28 | 29 | #include "qes_config.h" 30 | #include 31 | #include 32 | #include 33 | 34 | 35 | #ifndef STRNDUP_FOUND 36 | char *strndup(const char *s, size_t n); 37 | #endif 38 | 39 | #ifndef VASPRINTF_FOUND 40 | int vasprintf(char **ret, const char *format, va_list args); 41 | #endif 42 | 43 | #ifndef ASPRINTF_FOUND 44 | int asprintf(char **ret, const char *format, ...); 45 | #endif 46 | -------------------------------------------------------------------------------- /src/libqes/src/qes_config.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Kevin Murray 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | /* 18 | * ============================================================================ 19 | * 20 | * Filename: qes_config.h.in 21 | * 22 | * Description: Define various things from CMake. 23 | * 24 | * Created: 15/08/14 12:09:59 25 | * License: GPLv3+ 26 | * Compiler: gcc, clang 27 | * 28 | * Author: Kevin Murray, spam@kdmurray.id.au 29 | * 30 | * ============================================================================ 31 | */ 32 | 33 | #ifndef QES_CONFIG_H 34 | #define QES_CONFIG_H 35 | 36 | #define LIBQES_VERSION "${LIBQES_VERSION}" 37 | #cmakedefine GETLINE_FOUND 38 | #cmakedefine STRNDUP_FOUND 39 | #cmakedefine ZLIB_FOUND 40 | #cmakedefine GZBUFFER_FOUND 41 | #cmakedefine OPENMP_FOUND 42 | #cmakedefine ASPRINTF_FOUND 43 | #cmakedefine VASPRINTF_FOUND 44 | 45 | /* Definitions to make changing fp type easy */ 46 | #ifdef ZLIB_FOUND 47 | # include 48 | # define QES_ZTYPE gzFile 49 | # define QES_ZOPEN gzopen 50 | # define QES_ZDOPEN gzdopen 51 | # define QES_ZCLOSE gzclose 52 | # define QES_ZREAD gzread 53 | # define QES_ZWRITE gzwrite 54 | # define QES_ZFLUSH(fp) gzflush(fp, Z_SYNC_FLUSH) 55 | # define QES_ZFPRINTF gzprintf 56 | # define QES_ZFPUTS gzputs 57 | # define QES_ZFPUTC gzputc 58 | # define QES_ZFGETS gzgets 59 | # define QES_ZFGETC gzgetc 60 | # define QES_ZFUNGETC gzungetc 61 | # define QES_ZERR gzerror 62 | # define QES_ZEOF gzeof 63 | #ifdef GZBUFFER_FOUND 64 | # define QES_ZBUFFER gzbuffer 65 | #endif 66 | # define QES_ZSEEK gzseek 67 | # define QES_ZTELL gztell 68 | # define QES_ZREWIND gzrewind 69 | #else 70 | # define QES_ZTYPE FILE* 71 | # define QES_ZOPEN fopen 72 | # define QES_ZCLOSE fclose 73 | # define QES_ZDOPEN fdopen 74 | # define QES_ZCLOSE fclose 75 | # define QES_ZREAD(fp, buf, ln) fread(buf, 1, ln, fp) 76 | # define QES_ZWRITE(fp, buf, ln) fwrite(buf, 1, ln, fp) 77 | # define QES_ZFLUSH fflush 78 | # define QES_ZFPRINTF fprintf 79 | # define QES_ZFPUTS(fp, s) fputs(s, fp) 80 | # define QES_ZFPUTC(fp, c) fputc(c, fp) 81 | # define QES_ZFGETS(fp, s, l) fgets(s, l, fp) 82 | # define QES_ZFGETC fgetc 83 | # define QES_ZFUNGETC fungetc 84 | # define QES_ZERR ferror 85 | # define QES_ZEOF feof 86 | # define QES_ZBUFFER(fp, sz) setvbuf(fp, NULL, _IOFBF, sz) 87 | # define QES_ZSEEK fseek 88 | # define QES_ZTELL ftell 89 | # define QES_ZREWIND rewind 90 | #endif 91 | 92 | #endif /* QES_CONFIG_H */ 93 | -------------------------------------------------------------------------------- /src/libqes/src/qes_libgnu.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Kevin Murray 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | /* 18 | * ============================================================================ 19 | * 20 | * Filename: qes_libgnu.c 21 | * Description: Functions required from gnulib 22 | * License: GPLv3+ 23 | * Author: Kevin Murray, spam@kdmurray.id.au 24 | * 25 | * ============================================================================ 26 | */ 27 | 28 | #include "qes_libgnu.h" 29 | 30 | #ifndef ZLIB_FOUND 31 | # include "crc.c" 32 | #endif 33 | -------------------------------------------------------------------------------- /src/libqes/src/qes_libgnu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Kevin Murray 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | /* 18 | * ============================================================================ 19 | * 20 | * Filename: qes_libgnu.h 21 | * Description: Functions required from gnulib 22 | * License: GPLv3+ 23 | * Author: Kevin Murray, spam@kdmurray.id.au 24 | * 25 | * ============================================================================ 26 | */ 27 | 28 | #ifndef QES_LIBGNU_H 29 | #define QES_LIBGNU_H 30 | 31 | #include "qes_config.h" 32 | 33 | /* This file and qes_libgnu.c are designed to allow us to keep the sources of 34 | * the gnulib functions intact and in their original separate form. */ 35 | 36 | #ifndef ZLIB_FOUND 37 | # include "crc.h" 38 | #else 39 | # include 40 | /* Cast is to avoid a difference in signed-ness in the two implementations. */ 41 | # define crc32_update(c, b, l) crc32(c, (const unsigned char *)b, l) 42 | #endif 43 | 44 | #endif /* QES_LIBGNU_H */ 45 | -------------------------------------------------------------------------------- /src/libqes/src/qes_match.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Kevin Murray 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | /* 18 | * ============================================================================ 19 | * 20 | * Filename: qes_match.c 21 | * 22 | * Description: Sequence matching and finding functions used in 23 | * bioinformatic tasks 24 | * License: GPLv3+ 25 | * Author: Kevin Murray, spam@kdmurray.id.au 26 | * 27 | * ============================================================================ 28 | */ 29 | 30 | #include "qes_match.h" 31 | 32 | 33 | inline int_fast32_t 34 | qes_match_hamming (const char *seq1, const char *seq2, size_t len) 35 | { 36 | int_fast32_t mismatches = 0; 37 | size_t iii = 0; 38 | 39 | /* Error out on bad arguments */ 40 | if (seq1 == NULL || seq2 == NULL) { 41 | return -1; 42 | } 43 | /* If we've been given a length of 0, we make it up ourselves */ 44 | if (len == 0) { 45 | size_t len2 = strlen(seq2); 46 | len = strlen(seq1); 47 | /* Max of len & len2 */ 48 | if (len > len2) { 49 | len = len2; 50 | } 51 | } 52 | /* Count mismatches. See comment on analogous loop in qes_match_hamming_max 53 | * for an explanation. */ 54 | while(iii < len) { 55 | if (seq2[iii] != seq1[iii]) { 56 | mismatches++; 57 | } 58 | iii++; 59 | } 60 | return mismatches; 61 | } 62 | 63 | 64 | inline int_fast32_t 65 | qes_match_hamming_max(const char *seq1, const char *seq2, size_t len, 66 | int_fast32_t max) 67 | { 68 | int_fast32_t mismatches = 0; 69 | size_t iii = 0; 70 | 71 | /* Error out on bad arguments */ 72 | if (seq1 == NULL || seq2 == NULL || max < 0) { 73 | return -1; 74 | } 75 | /* If we've been given a length of 0, we make it up ourselves */ 76 | if (len == 0) { 77 | size_t len2 = strlen(seq2); 78 | len = strlen(seq1); 79 | /* Max of len & len2 */ 80 | if (len > len2) { 81 | len = len2; 82 | } 83 | } 84 | /* We obediently go until ``len``, assuming whoever gave us ``len`` knew 85 | WTF they were doing. This makes things a bit faster, since these 86 | functions are expected to be very much inner-loop. */ 87 | while(iii < len) { 88 | /* Find mismatch count */ 89 | if (seq2[iii] != seq1[iii]) { 90 | mismatches++; 91 | } 92 | iii++; 93 | if (mismatches > max) { 94 | /* Bail out if we're over max, always cap at max + 1 */ 95 | return max + 1; 96 | } 97 | } 98 | return mismatches; 99 | } 100 | -------------------------------------------------------------------------------- /src/libqes/src/qes_match.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Kevin Murray 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | /* 18 | * ============================================================================ 19 | * 20 | * Filename: qes_match.h 21 | * 22 | * Description: Sequence matching and finding functions used in 23 | * bioinformatic tasks 24 | * License: GPLv3+ 25 | * Author: Kevin Murray, spam@kdmurray.id.au 26 | * 27 | * ============================================================================ 28 | */ 29 | 30 | #ifndef QES_MATCH_H 31 | #define QES_MATCH_H 32 | 33 | #include 34 | 35 | 36 | /*=== FUNCTION ============================================================* 37 | Name: qes_match_hamming 38 | Parameters: const char *seq1, *seq2: Two strings to compare. 39 | size_t len: Compare ``len`` chars. If 0, guess length with 40 | strlen (may be unsafe). 41 | Description: Find the hamming distance between two strings. The strings are 42 | matched until the length of the smallest string. 43 | Returns: The hamming distance between ``seq1`` and ``seq2``, or -1 on 44 | error. 45 | *===========================================================================*/ 46 | extern int_fast32_t qes_match_hamming(const char *seq1, const char *seq2, size_t len); 47 | 48 | 49 | /*=== FUNCTION ============================================================* 50 | Name: qes_match_hamming_max 51 | Parameters: const char *seq1, *seq2: Two strings to compare. 52 | size_t len: Compare ``len`` chars. If 0, guess length with 53 | strlen (may be unsafe). 54 | int_fast32_t max: Stop counting at ``max``, return ``max + 1``. 55 | Description: Find the hamming distance between two strings. The strings are 56 | matched until the length of the smallest string, or ``len`` 57 | charachers, or until the maximum hamming distance (``max``) is 58 | reached. 59 | Returns: The hamming distance between ``seq1`` and ``seq2``, or 60 | ``max + 1`` if the hamming distance exceeds ``max``, or -1 on 61 | error. 62 | *===========================================================================*/ 63 | extern int_fast32_t qes_match_hamming_max(const char *seq1, const char *seq2, size_t len, 64 | int_fast32_t max); 65 | 66 | #endif /* QES_MATCH_H */ 67 | -------------------------------------------------------------------------------- /src/libqes/src/qes_sequtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Kevin Murray 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | /* 18 | * ============================================================================ 19 | * 20 | * Filename: qes_sequtil.h 21 | * 22 | * Description: Sequence utility functions 23 | * License: GPLv3+ 24 | * Author: Kevin Murray, spam@kdmurray.id.au 25 | * 26 | * ============================================================================ 27 | */ 28 | 29 | #ifndef QES_SEQUTIL_H 30 | #define QES_SEQUTIL_H 31 | 32 | #include 33 | 34 | 35 | extern int qes_sequtil_translate_codon(const char *codon); 36 | extern char *qes_sequtil_revcomp(const char *seq, size_t len); 37 | extern void qes_sequtil_revcomp_inplace(char *seq, size_t len); 38 | 39 | #endif /* QES_SEQUTIL_H */ 40 | -------------------------------------------------------------------------------- /src/libqes/src/qes_str.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Kevin Murray 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | /* 18 | * ============================================================================ 19 | * 20 | * Filename: qes_str.c 21 | * 22 | * Description: String handling functions 23 | * License: GPLv3+ 24 | * Author: Kevin Murray, spam@kdmurray.id.au 25 | * 26 | * ============================================================================ 27 | */ 28 | 29 | #include "qes_str.h" 30 | 31 | 32 | void 33 | qes_str_print (const struct qes_str *str, FILE *stream) 34 | { 35 | if (qes_str_ok(str)) { 36 | fwrite(str->str, 1, str->len, stream); 37 | } 38 | } 39 | 40 | void 41 | qes_str_destroy_cp (struct qes_str *str) 42 | { 43 | if (str != NULL) qes_free(str->str); 44 | } 45 | 46 | void 47 | qes_str_destroy (struct qes_str *str) 48 | { 49 | qes_str_destroy_cp(str); 50 | qes_free(str); 51 | } 52 | 53 | -------------------------------------------------------------------------------- /src/libqes/src/qes_util.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Kevin Murray 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | /* 18 | * ============================================================================ 19 | * 20 | * Filename: qes_util.c 21 | * 22 | * Description: Wrappers around std library functions 23 | * License: GPLv3+ 24 | * Author: Kevin Murray, spam@kdmurray.id.au 25 | * 26 | * ============================================================================ 27 | */ 28 | 29 | #include "qes_util.h" 30 | 31 | 32 | /* Pull LIBQES_VERSION in from qes_config.h */ 33 | const char *libqes_version = LIBQES_VERSION; 34 | 35 | /* Valid non-function to pass to libqes functions */ 36 | void 37 | errnil (QES_ERRFN_ARGS) 38 | { 39 | (void) (msg); 40 | (void) (file); 41 | (void) (line); 42 | } 43 | 44 | /* Function to pass to libqes functions which prints out errors to stderr */ 45 | void 46 | errprint (QES_ERRFN_ARGS) 47 | { 48 | char msg_fmt[1<<8] = ""; 49 | va_list args; 50 | if (msg == NULL) { 51 | msg = "GENERIC ERROR WITH NO MESSAGE"; 52 | } 53 | va_start (args, line); 54 | vsnprintf(msg_fmt, 1<<8, msg, args); 55 | va_end (args); 56 | fprintf(stderr, "[%s: %d]: %s\n", file, line, msg_fmt); 57 | } 58 | 59 | /* Function to pass to libqes functions which prints out errors to stderr and 60 | calls `exit(EXIT_FAILURE)` */ 61 | void 62 | errprintexit (QES_ERRFN_ARGS) 63 | { 64 | char msg_fmt[1<<8] = ""; 65 | va_list args; 66 | if (msg == NULL) { 67 | msg = "GENERIC ERROR WITH NO MESSAGE"; 68 | } 69 | va_start (args, line); 70 | vsnprintf(msg_fmt, 1<<8, msg, args); 71 | va_end (args); 72 | fprintf(stderr, "[%s: %d]: %s\n", file, line, msg_fmt); 73 | QES_EXIT_FN(EXIT_FAILURE); 74 | } 75 | 76 | -------------------------------------------------------------------------------- /src/libqes/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## Compile tests, & set up coverage 2 | SET(COMMON_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/helpers.c) 3 | FILE(GLOB TEST_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/test*.c) 4 | SET(TEST_SRCS ${COMMON_SRCS} ${TEST_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/tinytest/tinytest.c) 5 | ADD_EXECUTABLE(test_libqes ${TEST_SRCS}) 6 | TARGET_LINK_LIBRARIES(test_libqes qes ${LIBQES_DEPENDS_LIBS}) 7 | IF (CMAKE_BUILD_TYPE STREQUAL "Coverage") 8 | SETUP_TARGET_FOR_COVERAGE(coverage test_libqes coverage src) 9 | ENDIF() 10 | ADD_TEST(NAME run_test_libqes 11 | COMMAND ${CMAKE_BINARY_DIR}/bin/test_libqes ${CMAKE_BINARY_DIR}) 12 | 13 | ADD_EXECUTABLE(qes_seqcat ${CMAKE_CURRENT_SOURCE_DIR}/qes_seqcat.c) 14 | TARGET_LINK_LIBRARIES(qes_seqcat qes ${LIBQES_DEPENDS_LIBS}) 15 | 16 | ADD_EXECUTABLE(qes_seqprint ${CMAKE_CURRENT_SOURCE_DIR}/qes_seqprint.c) 17 | TARGET_LINK_LIBRARIES(qes_seqprint qes ${LIBQES_DEPENDS_LIBS}) 18 | 19 | ADD_EXECUTABLE(kseqcat ${CMAKE_CURRENT_SOURCE_DIR}/kseqcat.c) 20 | TARGET_LINK_LIBRARIES(kseqcat qes ${LIBQES_DEPENDS_LIBS}) 21 | 22 | # Demos 23 | ADD_EXECUTABLE(log_demo ${CMAKE_CURRENT_SOURCE_DIR}/logdemo.c) 24 | TARGET_LINK_LIBRARIES(log_demo qes ${LIBQES_DEPENDS_LIBS}) 25 | ADD_TEST(NAME run_log_demo 26 | COMMAND ${CMAKE_BINARY_DIR}/bin/log_demo) 27 | 28 | # Benchmarking: 29 | ADD_EXECUTABLE(bench_libqes ${CMAKE_CURRENT_SOURCE_DIR}/benchmarks.c ${COMMON_SRCS}) 30 | TARGET_LINK_LIBRARIES(bench_libqes qes ${LIBQES_DEPENDS_LIBS}) 31 | ADD_TEST(NAME run_bench_libqes 32 | COMMAND ${CMAKE_BINARY_DIR}/bin/bench_libqes 33 | ${CMAKE_BINARY_DIR}/data/test.fastq 34 | 50 35 | qes_seqfile_write 36 | kseq_parse_fq 37 | gnu_getline 38 | qes_seqfile_parse_fq 39 | qes_file_readline_realloc) 40 | 41 | # Copy test files over to bin dir 42 | ADD_CUSTOM_COMMAND(TARGET test_libqes 43 | COMMAND ${CMAKE_COMMAND} -E copy_directory 44 | ${CMAKE_CURRENT_SOURCE_DIR}/data 45 | ${CMAKE_BINARY_DIR}/data) 46 | -------------------------------------------------------------------------------- /src/libqes/test/data/bad_diff_lens.fastq: -------------------------------------------------------------------------------- 1 | @HWI-ST960:105:D10GVACXX:2:1101:1151:2158 1:N:0: bcd:RPI9 seq:CACGATCAGATC 2 | CACGATCAGATCAANGACATTGAATCTATATGT 3 | + 4 | JJJJJIJHIJCC#4ADFFHHHGHJJJJIJJJ 5 | -------------------------------------------------------------------------------- /src/libqes/test/data/bad_nohdr.fastq: -------------------------------------------------------------------------------- 1 | CACGATCAGATCAANGACATTGAATCTATATGT 2 | + 3 | JJJJJJJIJHIJCC#4ADFFHHHGHJJJJIJJJ 4 | -------------------------------------------------------------------------------- /src/libqes/test/data/bad_noqual.fastq: -------------------------------------------------------------------------------- 1 | @HWI-ST960:105:D10GVACXX:2:1101:1151:2158 1:N:0: bcd:RPI9 seq:CACGATCAGATC 2 | CACGATCAGATCAANGACATTGAATCTATATGT 3 | + 4 | -------------------------------------------------------------------------------- /src/libqes/test/data/bad_noqualhdrchr.fastq: -------------------------------------------------------------------------------- 1 | @HWI-ST960:105:D10GVACXX:2:1101:1151:2158 1:N:0: bcd:RPI9 seq:CACGATCAGATC 2 | CACGATCAGATCAANGACATTGAATCTATATGT 3 | 4 | CACGATCAGATCAANGACATTGAATCTATATGT 5 | -------------------------------------------------------------------------------- /src/libqes/test/data/bad_noqualhdreol.fastq: -------------------------------------------------------------------------------- 1 | @HWI-ST960:105:D10GVACXX:2:1101:1151:2158 1:N:0: bcd:RPI9 seq:CACGATCAGATC 2 | CACGATCAGATCAANGACATTGAATCTATATGT 3 | +HWI-BLERG -------------------------------------------------------------------------------- /src/libqes/test/data/empty.fastq: -------------------------------------------------------------------------------- 1 | @ -------------------------------------------------------------------------------- /src/libqes/test/data/empty.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kdm9/axe/c8a636fd11d394034776bda45a5f0ef9b6e80046/src/libqes/test/data/empty.txt -------------------------------------------------------------------------------- /src/libqes/test/data/loremipsum.txt: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ornare tortor et 2 | rhoncus iaculis. Sed suscipit, arcu nec elementum vestibulum, tortor tortor 3 | dictum dui, eu sodales magna orci eu libero. Cras commodo, ligula tempor auctor 4 | vulputate, eros urna gravida eros, eget congue leo quam quis mi. Curabitur 5 | luctus augue nibh, eget vehicula augue commodo eget. Donec condimentum molestie 6 | adipiscing. In non purus lacus. Nam nec mollis mauris. Donec rhoncus, diam sit 7 | amet rhoncus viverra, lectus risus tincidunt ipsum, in dignissim justo purus 8 | eget enim. Fusce congue nulla egestas est auctor faucibus. Integer feugiat 9 | molestie leo, a interdum neque pretium nec. Etiam sit amet nibh leo. 10 | 11 | End of lorem ipsum. 12 | -------------------------------------------------------------------------------- /src/libqes/test/data/loremipsum.txt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kdm9/axe/c8a636fd11d394034776bda45a5f0ef9b6e80046/src/libqes/test/data/loremipsum.txt.gz -------------------------------------------------------------------------------- /src/libqes/test/data/nocomment.fasta: -------------------------------------------------------------------------------- 1 | >HWI-ST960:105:D10GVACXX:2:1101:1122:2186 2 | CACACTTGAA 3 | TCCAGTTTAA 4 | AGTTAACTCA 5 | TTG 6 | -------------------------------------------------------------------------------- /src/libqes/test/data/random.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kdm9/axe/c8a636fd11d394034776bda45a5f0ef9b6e80046/src/libqes/test/data/random.bin -------------------------------------------------------------------------------- /src/libqes/test/data/test.fastq.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kdm9/axe/c8a636fd11d394034776bda45a5f0ef9b6e80046/src/libqes/test/data/test.fastq.bz2 -------------------------------------------------------------------------------- /src/libqes/test/data/test.fastq.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kdm9/axe/c8a636fd11d394034776bda45a5f0ef9b6e80046/src/libqes/test/data/test.fastq.gz -------------------------------------------------------------------------------- /src/libqes/test/data/test_large.fasta.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kdm9/axe/c8a636fd11d394034776bda45a5f0ef9b6e80046/src/libqes/test/data/test_large.fasta.gz -------------------------------------------------------------------------------- /src/libqes/test/data/truth/log_test.txt: -------------------------------------------------------------------------------- 1 | Hello World 2 | Hello World 3 | -------------------------------------------------------------------------------- /src/libqes/test/data/truth/qes_seq_print.fa: -------------------------------------------------------------------------------- 1 | >TEST Comment 1 2 | AGCT 3 | -------------------------------------------------------------------------------- /src/libqes/test/data/truth/qes_seq_print.fq: -------------------------------------------------------------------------------- 1 | @TEST Comment 1 2 | AGCT 3 | + 4 | IIII 5 | -------------------------------------------------------------------------------- /src/libqes/test/helpers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Kevin Murray 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | /* 18 | * ============================================================================ 19 | * 20 | * Filename: helpers.h 21 | * 22 | * Description: Helpers for tests 23 | * License: GPLv3+ 24 | * Author: Kevin Murray, spam@kdmurray.id.au 25 | * 26 | * ============================================================================ 27 | */ 28 | 29 | #ifndef HELPERS_H 30 | #define HELPERS_H 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #ifndef _WIN32 43 | # include 44 | #endif 45 | 46 | #include 47 | 48 | 49 | extern char *data_prefix; 50 | char *find_data_file(const char * filepath); 51 | char *get_writable_file(void); 52 | void clean_writable_file(char *filepath); 53 | char *crc32_file(const char *filepath); 54 | int filecmp(const char *file1, const char *file2); 55 | 56 | #endif /* HELPERS_H */ 57 | -------------------------------------------------------------------------------- /src/libqes/test/kseqcat.c: -------------------------------------------------------------------------------- 1 | #include "qes_config.h" 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | #include "kseq.h" 8 | 9 | #ifdef ZLIB_FOUND 10 | # include 11 | KSEQ_INIT(gzFile, gzread) 12 | #else 13 | # include 14 | # include 15 | KSEQ_INIT(int, read) 16 | #endif 17 | 18 | int main(int argc, char *argv[]) 19 | { 20 | if (argc < 2) return 1; 21 | const char *fname = argv[1]; 22 | gzFile fp = gzopen(fname, "r"); 23 | kseq_t *kseq = kseq_init(fp); 24 | ssize_t res = 0; 25 | while((res = kseq_read(kseq)) > 0) { 26 | if (kseq->qual.l < 1) { 27 | // fasta 28 | printf(">%s %s\n", kseq->name.s, kseq->comment.s); 29 | puts(kseq->seq.s); 30 | } else { 31 | // fastq 32 | printf("@%s %s\n", kseq->name.s, kseq->comment.s); 33 | puts(kseq->seq.s); 34 | puts("+"); 35 | puts(kseq->qual.s); 36 | } 37 | } 38 | kseq_destroy(kseq); 39 | gzclose(fp); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /src/libqes/test/logdemo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Kevin Murray 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | /* 18 | * ============================================================================ 19 | * 20 | * Filename: logdemo.c 21 | * Description: Demontrate libqes logging 22 | * License: GPLv3+ 23 | * Author: Kevin Murray, spam@kdmurray.id.au 24 | * 25 | * ============================================================================ 26 | */ 27 | 28 | #include 29 | 30 | int 31 | main (int argc, char *argv[]) 32 | { 33 | struct qes_logger *logger = qes_logger_create(); 34 | 35 | (void) argc; 36 | (void) argv; 37 | 38 | qes_logger_init(logger, "Test Logger", QES_LOG_DEBUG); 39 | qes_logger_add_destination_formatted(logger, stdout, QES_LOG_DEBUG, 40 | &qes_log_formatter_pretty); 41 | 42 | qes_log_message_debug(logger, "Debug message, nice and quiet\n"); 43 | qes_log_message_info(logger, "Informative message, clearer\n"); 44 | qes_log_message_warning(logger, "Warning message, pay attention!\n"); 45 | qes_log_message_error(logger, "Error message, something's gone wrong\n"); 46 | qes_log_message_fatal(logger, "Fatal message, I'm leaving now\n"); 47 | 48 | qes_logger_destroy(logger); 49 | return EXIT_SUCCESS; 50 | } 51 | -------------------------------------------------------------------------------- /src/libqes/test/qes_seqcat.c: -------------------------------------------------------------------------------- 1 | #include "qes_config.h" 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | if (argc < 2) return 1; 10 | const char *fname = argv[1]; 11 | struct qes_seq *seq = qes_seq_create(); 12 | struct qes_seqfile *sf = qes_seqfile_create(fname, "r"); 13 | ssize_t res = 0; 14 | while((res = qes_seqfile_read(sf, seq)) > 0) { 15 | if (seq->qual.len < 1) { 16 | // fasta 17 | printf(">%s %s\n", seq->name.str, seq->comment.str); 18 | puts(seq->seq.str); 19 | } else { 20 | // fastq 21 | printf("@%s %s\n", seq->name.str, seq->comment.str); 22 | puts(seq->seq.str); 23 | puts("+"); 24 | puts(seq->qual.str); 25 | } 26 | } 27 | qes_seqfile_destroy(sf); 28 | qes_seq_destroy(seq); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /src/libqes/test/qes_seqprint.c: -------------------------------------------------------------------------------- 1 | #include "qes_config.h" 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | if (argc < 2) return 1; 10 | const char *fname = argv[1]; 11 | struct qes_seq *seq = qes_seq_create(); 12 | struct qes_seqfile *sf = qes_seqfile_create(fname, "r"); 13 | ssize_t res = 0; 14 | while((res = qes_seqfile_read(sf, seq)) > 0) { 15 | int fasta = seq->qual.len < 1; 16 | qes_seq_print(seq, stdout, fasta, 0); 17 | } 18 | qes_seqfile_destroy(sf); 19 | qes_seq_destroy(seq); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /src/libqes/test/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Kevin Murray 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | /* 18 | * ============================================================================ 19 | * 20 | * Filename: test.c 21 | * 22 | * Description: Tests for libqes 23 | * License: GPLv3+ 24 | * Author: Kevin Murray, spam@kdmurray.id.au 25 | * 26 | * ============================================================================ 27 | */ 28 | 29 | #include "tests.h" 30 | 31 | 32 | struct testgroup_t libqes_tests[] = { 33 | {"qes/util/", qes_util_tests}, 34 | {"qes/match/", qes_match_tests}, 35 | {"qes/file/", qes_file_tests}, 36 | {"qes/seqfile/", qes_seqfile_tests}, 37 | {"qes/seq/", qes_seq_tests}, 38 | {"qes/log/", qes_log_tests}, 39 | {"qes/sequtil/", qes_sequtil_tests}, 40 | {"testdata/", data_tests}, 41 | {"testhelpers/", helper_tests}, 42 | END_OF_GROUPS 43 | }; 44 | 45 | 46 | /* 47 | * === FUNCTION ============================================================= 48 | * Name: main 49 | * Description: Run all tests 50 | * ============================================================================ 51 | */ 52 | 53 | int 54 | main (int argc, const char *argv[]) 55 | { 56 | int res; 57 | int our_argc = argc; 58 | const char **our_argv = argv; 59 | 60 | data_prefix = NULL; 61 | if (argc>1) { 62 | data_prefix = strdup(argv[1]); 63 | our_argc -= 1; 64 | our_argv += 1; 65 | } 66 | if (data_prefix == NULL) { 67 | data_prefix = strdup("."); 68 | assert(data_prefix != NULL); 69 | } 70 | if (access(data_prefix, W_OK | X_OK | R_OK) != 0) { 71 | fprintf(stderr, "ERROR: Could not access data prefix dir '%s'\n", 72 | data_prefix); 73 | fprintf(stderr, "Usage: test_libqes []\n"); 74 | free(data_prefix); 75 | exit(EXIT_FAILURE); 76 | } 77 | res = tinytest_main(our_argc, our_argv, libqes_tests); 78 | free(data_prefix); 79 | return res; 80 | } 81 | -------------------------------------------------------------------------------- /src/libqes/test/test_helpers.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Kevin Murray 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | /* 18 | * ============================================================================ 19 | * 20 | * Filename: test_helpers.c 21 | * 22 | * Description: Tests of test/helpers.c 23 | * License: GPLv3+ 24 | * Author: Kevin Murray, spam@kdmurray.id.au 25 | * 26 | * ============================================================================ 27 | */ 28 | 29 | #include "tests.h" 30 | 31 | 32 | static void 33 | test_crc32_file(void *data) 34 | { 35 | char *crc = NULL; 36 | char *fname = NULL; 37 | 38 | (void) data; 39 | fname = find_data_file("loremipsum.txt"); 40 | crc = crc32_file(fname); 41 | tt_str_op(crc, ==, "9f20f7ec"); 42 | end: 43 | free(fname); 44 | free(crc); 45 | } 46 | 47 | static void 48 | test_filecmp(void *data) 49 | { 50 | char *fname1 = NULL; 51 | char *fname2 = NULL; 52 | 53 | (void) data; 54 | fname1 = find_data_file("loremipsum.txt"); 55 | fname2 = find_data_file("loremipsum.txt.gz"); 56 | tt_int_op(filecmp(fname1, fname1), ==, 0); 57 | tt_int_op(filecmp(fname1, fname2), ==, 1); 58 | tt_int_op(filecmp(NULL, fname2), ==, -1); 59 | tt_int_op(filecmp("/does/not/exist/", fname2), ==, -1); 60 | 61 | end: 62 | free(fname1); 63 | free(fname2); 64 | } 65 | 66 | struct testcase_t helper_tests[] = { 67 | { "crc32_file", test_crc32_file, 0, NULL, NULL}, 68 | { "filecmp", test_filecmp, 0, NULL, NULL}, 69 | END_OF_TESTCASES 70 | }; 71 | -------------------------------------------------------------------------------- /src/libqes/test/test_match.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Kevin Murray 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | /* 18 | * ============================================================================ 19 | * 20 | * Filename: test_match.c 21 | * 22 | * Description: Test qes_match functions 23 | * License: GPLv3+ 24 | * Author: Kevin Murray, spam@kdmurray.id.au 25 | * 26 | * ============================================================================ 27 | */ 28 | 29 | #include "tests.h" 30 | #include 31 | #include 32 | 33 | 34 | static void 35 | test_qes_hamming (void *p) 36 | { 37 | (void) (p); 38 | /* Simple stuff */ 39 | tt_int_op(qes_match_hamming("ACTTG", "ACTTG", 5), ==, 0); 40 | tt_int_op(qes_match_hamming("ACTTG", "ACTGG", 5), ==, 1); 41 | /* Different lengths */ 42 | tt_int_op(qes_match_hamming("ACTTGA", "ACTTG", 5), ==, 0); 43 | tt_int_op(qes_match_hamming("ACTTG", "ACTTGA", 5), ==, 0); 44 | tt_int_op(qes_match_hamming("ACTTG", "ACTGGA", 5), ==, 1); 45 | tt_int_op(qes_match_hamming("ACTTG", "ACTGGA", 6), ==, 2); 46 | tt_int_op(qes_match_hamming("ACTTG", "ACTTGA", 6), ==, 1); 47 | /* Make it guess lengths */ 48 | tt_int_op(qes_match_hamming("ACTTG", "ACTTG", 0), ==, 0); 49 | tt_int_op(qes_match_hamming("ACATG", "ACTTG", 0), ==, 1); 50 | tt_int_op(qes_match_hamming("ACTTG", "ACTTGT", 0), ==, 0); 51 | tt_int_op(qes_match_hamming("ACATG", "ACTTGT", 0), ==, 1); 52 | tt_int_op(qes_match_hamming("ACTTGT", "ACTTG", 0), ==, 0); 53 | /* Give it hell */ 54 | tt_int_op(qes_match_hamming("ACTTG", NULL, 0), ==, -1); 55 | tt_int_op(qes_match_hamming(NULL, "ACTTG", 0), ==, -1); 56 | tt_int_op(qes_match_hamming(NULL, NULL, 0), ==, -1); 57 | end: 58 | ; 59 | } 60 | 61 | 62 | static void 63 | test_qes_hamming_max (void *p) 64 | { 65 | 66 | (void) (p); 67 | /* Same tests as per hamming, max is INT_MAX */ 68 | /* Simple stuff */ 69 | tt_int_op(qes_match_hamming_max("ACTTG", "ACTTG", 5, INT_MAX), ==, 0); 70 | tt_int_op(qes_match_hamming_max("ACTTG", "ACTGG", 5, INT_MAX), ==, 1); 71 | /* Different lengths */ 72 | tt_int_op(qes_match_hamming_max("ACTTGA", "ACTTG", 5, INT_MAX), ==, 0); 73 | tt_int_op(qes_match_hamming_max("ACTTG", "ACTTGA", 5, INT_MAX), ==, 0); 74 | tt_int_op(qes_match_hamming_max("ACTTG", "ACTGGA", 5, INT_MAX), ==, 1); 75 | tt_int_op(qes_match_hamming_max("ACTTG", "ACTGGA", 6, INT_MAX), ==, 2); 76 | tt_int_op(qes_match_hamming_max("ACTTG", "ACTTGA", 6, INT_MAX), ==, 1); 77 | /* Make it guess lengths */ 78 | tt_int_op(qes_match_hamming_max("ACTTG", "ACTTG", 0, INT_MAX), ==, 0); 79 | tt_int_op(qes_match_hamming_max("ACATG", "ACTTG", 0, INT_MAX), ==, 1); 80 | tt_int_op(qes_match_hamming_max("ACTTG", "ACTTGT", 0, INT_MAX), ==, 0); 81 | tt_int_op(qes_match_hamming_max("ACATG", "ACTTGT", 0, INT_MAX), ==, 1); 82 | tt_int_op(qes_match_hamming_max("ACTTGT", "ACTTG", 0, INT_MAX), ==, 0); 83 | /* Test it bails out when over ``max`` */ 84 | tt_int_op(qes_match_hamming_max("ACTTG", "ACTGG", 5, 1), ==, 1); 85 | tt_int_op(qes_match_hamming_max("ACTTG", "ACTGG", 5, 0), ==, 1); 86 | tt_int_op(qes_match_hamming_max("ACTTG", "ACTGA", 5, 0), ==, 1); 87 | tt_int_op(qes_match_hamming_max("ACTTG", "ACTGA", 5, 1), ==, 2); 88 | tt_int_op(qes_match_hamming_max("ACTTG", "ACTGA", 5, 2), ==, 2); 89 | /* Give it hell */ 90 | tt_int_op(qes_match_hamming_max("ACTTG", NULL, 0, INT_MAX), ==, -1); 91 | tt_int_op(qes_match_hamming_max(NULL, "ACTTG", 0, INT_MAX), ==, -1); 92 | tt_int_op(qes_match_hamming_max(NULL, NULL, 0, INT_MAX), ==, -1); 93 | tt_int_op(qes_match_hamming_max("ACTTG", "ACTTG", 0, -1), ==, -1); 94 | tt_int_op(qes_match_hamming_max("ACTTG", NULL, 0, -1), ==, -1); 95 | tt_int_op(qes_match_hamming_max(NULL, "ACTTG", 0, -1), ==, -1); 96 | tt_int_op(qes_match_hamming_max(NULL, NULL, 0, -1), ==, -1); 97 | end: 98 | ; 99 | } 100 | 101 | struct testcase_t qes_match_tests[] = { 102 | { "qes_match_hamming", test_qes_hamming, 0, NULL, NULL}, 103 | { "qes_match_hamming_max", test_qes_hamming_max, 0, NULL, NULL}, 104 | END_OF_TESTCASES 105 | }; 106 | -------------------------------------------------------------------------------- /src/libqes/test/test_seqcats.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ $# -lt 1 ] 4 | then 5 | files=("data/test.fasta") 6 | else 7 | files=( "$@" ) 8 | fi 9 | 10 | for file in "${files[@]}" 11 | do 12 | kseq_m5=$(bin/kseqcat $file | md5sum | awk '{print $1}') 13 | qseq_m5=$(bin/qes_seqcat $file | md5sum | awk '{print $1}') 14 | kprint_m5=$(bin/kseqcat $file | seqtk seq -l 79 | md5sum | awk '{print $1}') 15 | qprint_m5=$(bin/qes_seqprint $file | md5sum | awk '{print $1}') 16 | 17 | if [ "$kseq_m5" != "$qseq_m5" ] 18 | then 19 | echo "TEST (seq) FAILED: $file" 20 | echo " kseq: $kseq_m5" 21 | echo " qes: $qseq_m5" 22 | else 23 | echo "TEST (seq) PASSED: $file" 24 | fi 25 | 26 | if [ "$kprint_m5" != "$qprint_m5" ] 27 | then 28 | echo "TEST (print) FAILED: $file" 29 | echo " kseq: $kprint_m5" 30 | echo " qes: $qprint_m5" 31 | else 32 | echo "TEST (print) PASSED: $file" 33 | fi 34 | done 35 | -------------------------------------------------------------------------------- /src/libqes/test/test_sequtil.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Kevin Murray 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | /* 18 | * ============================================================================ 19 | * 20 | * Filename: test_sequtil.c 21 | * 22 | * Description: Tests for the sequtil module 23 | * License: GPLv3+ 24 | * Author: Kevin Murray, spam@kdmurray.id.au 25 | * 26 | * ============================================================================ 27 | */ 28 | 29 | #include "tests.h" 30 | #include 31 | 32 | 33 | static void 34 | test_qes_sequtil_translate_codon (void *ptr) 35 | { 36 | size_t iii; 37 | size_t jjj; 38 | char *cdn = NULL; 39 | char aa = 0; 40 | 41 | (void) ptr; 42 | for (iii = 0; iii < n_codons; iii++) { 43 | aa = qes_sequtil_translate_codon(codon_list[iii]); 44 | tt_assert_op_type(aa, ==, aa_list[iii], char, "%c"); 45 | } 46 | tt_int_op(qes_sequtil_translate_codon("XACACA"), ==, -1); 47 | tt_int_op(qes_sequtil_translate_codon("A"), ==, -1); 48 | tt_int_op(qes_sequtil_translate_codon(NULL), ==, -1); 49 | /* Try with mutations */ 50 | for (iii = 0; iii < n_codons; iii++) { 51 | for (jjj = 0; jjj < 3; jjj++) { 52 | cdn = strdup(codon_list[iii]); 53 | cdn[jjj] = 'N'; 54 | aa = qes_sequtil_translate_codon(cdn); 55 | tt_assert_op_type(aa, ==, 'X', char, "%c"); 56 | free(cdn); 57 | cdn = NULL; 58 | } 59 | } 60 | end: 61 | if (cdn != NULL) free(cdn); 62 | } 63 | 64 | struct testcase_t qes_sequtil_tests[] = { 65 | { "qes_sequtil_translate_codon", test_qes_sequtil_translate_codon, 0, NULL, NULL}, 66 | END_OF_TESTCASES 67 | }; 68 | -------------------------------------------------------------------------------- /src/libqes/test/test_util.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Kevin Murray 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | /* 18 | * ============================================================================ 19 | * 20 | * Filename: test_util.c 21 | * 22 | * Description: Test qes_util.c 23 | * License: GPLv3+ 24 | * Author: Kevin Murray, spam@kdmurray.id.au 25 | * 26 | * ============================================================================ 27 | */ 28 | 29 | #include "tests.h" 30 | #include 31 | 32 | 33 | /* Actual tests */ 34 | static void 35 | test_qes_calloc(void *ptr) 36 | { 37 | void *res = NULL; 38 | const size_t bufsize = 1<<10; 39 | unsigned char *zeros[1<<10]; 40 | 41 | (void) ptr; 42 | memset(zeros, 0, bufsize); 43 | /* This should work, and the buffer should be zero throughout */ 44 | res = qes_calloc(1, 1); 45 | tt_ptr_op(res, !=, NULL); 46 | tt_int_op(memcmp(res, zeros, 1), ==, 0); 47 | free(res); 48 | res = NULL; 49 | end: 50 | if (res != NULL) free(res); 51 | } 52 | 53 | static void 54 | test_qes_malloc(void *ptr) 55 | { 56 | void *res = NULL; 57 | 58 | (void) ptr; 59 | res = qes_malloc(1); 60 | tt_ptr_op(res, !=, NULL); 61 | free(res); 62 | res = NULL; 63 | end: 64 | if (res != NULL) free(res); 65 | } 66 | 67 | static void 68 | test_qes_realloc(void *ptr) 69 | { 70 | char *res = NULL; 71 | const char *str = "test"; 72 | char *dat = strdup(str); 73 | 74 | (void) ptr; 75 | /* Test resizing buffer */ 76 | res = qes_realloc(dat, 10); 77 | dat = NULL; 78 | tt_ptr_op(res, !=, NULL); 79 | tt_int_op(memcmp(res, str, 5), ==, 0); 80 | free(res); 81 | res = NULL; 82 | end: 83 | if (res != NULL) free(res); 84 | if (dat != NULL) free(dat); 85 | } 86 | 87 | static void 88 | test_qes_free(void *ptr) 89 | { 90 | char *dat = strdup("test"); 91 | 92 | (void) ptr; 93 | /* Test freeing buffer */ 94 | tt_ptr_op(dat, !=, NULL); 95 | qes_free(dat); 96 | tt_ptr_op(dat, ==, NULL); 97 | /* This free(NULL) should not fail */ 98 | qes_free(dat); 99 | tt_ptr_op(dat, ==, NULL); 100 | end: 101 | if (dat != NULL) free(dat); 102 | } 103 | 104 | static void 105 | test_qes_roundup32 (void *ptr) 106 | { 107 | int32_t val = 3; 108 | uint32_t uval = (1u<<31) - 1; 109 | 110 | (void) ptr; 111 | /* Signed */ 112 | tt_int_op(qes_roundup32(val), ==, 4); 113 | val++; 114 | tt_int_op(qes_roundup32(val), ==, 8); 115 | val = 8; 116 | tt_int_op(qes_roundup32(val), ==, 16); 117 | val = 262143; 118 | tt_int_op(qes_roundup32(val), ==, 262144); 119 | /* Unsigned */ 120 | tt_int_op(qes_roundup32(uval), ==, 1u<<31); 121 | uval++; 122 | tt_int_op(qes_roundup32(uval), ==, 0); 123 | end: 124 | ; 125 | } 126 | 127 | static void 128 | test_qes_roundup64 (void *ptr) 129 | { 130 | int64_t val = 3; 131 | uint64_t uval = (1llu<<63) - 1; 132 | 133 | (void) ptr; 134 | /* Signed */ 135 | tt_int_op(qes_roundup64(val), ==, 4); 136 | val = 4; 137 | tt_int_op(qes_roundup64(val), ==, 8); 138 | val = 8; 139 | tt_int_op(qes_roundup64(val), ==, 16); 140 | val = 262143llu; 141 | tt_int_op(qes_roundup64(val), ==, 262144); 142 | /* Unsigned */ 143 | tt_assert(qes_roundup64(uval) == 1llu<<63); 144 | uval = 1llu<<62; 145 | tt_assert(qes_roundup64(uval) == 1llu<<63); 146 | uval = 63llu; 147 | tt_assert(qes_roundup64(uval) - 2 == 62llu); 148 | end: 149 | ; 150 | } 151 | 152 | 153 | struct testcase_t qes_util_tests[] = { 154 | { "qes_calloc", test_qes_calloc, 0, NULL, NULL}, 155 | { "qes_malloc", test_qes_malloc, 0, NULL, NULL}, 156 | { "qes_realloc", test_qes_realloc, 0, NULL, NULL}, 157 | { "qes_free", test_qes_free, 0, NULL, NULL}, 158 | { "qes_roundup32", test_qes_roundup32, 0, NULL, NULL}, 159 | { "qes_roundup64", test_qes_roundup64, 0, NULL, NULL}, 160 | END_OF_TESTCASES 161 | }; 162 | -------------------------------------------------------------------------------- /src/libqes/test/testdata.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Kevin Murray 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | /* 18 | * ============================================================================ 19 | * 20 | * Filename: testdata.h 21 | * 22 | * Description: Data for tests 23 | * License: GPLv3+ 24 | * Author: Kevin Murray, spam@kdmurray.id.au 25 | * 26 | * ============================================================================ 27 | */ 28 | 29 | #ifndef TESTDATA_H 30 | #define TESTDATA_H 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #ifndef _WIN32 40 | #include 41 | #endif 42 | #include 43 | #include 44 | 45 | /* TinyTest */ 46 | #include "tinytest.h" 47 | #include "tinytest_macros.h" 48 | #include "testdata.h" 49 | #include "helpers.h" 50 | 51 | 52 | extern const size_t n_loremipsum_lines; 53 | extern const size_t loremipsum_fsize; 54 | extern const size_t loremipsum_line_lens[]; 55 | extern const char *loremipsum_lines[]; 56 | extern const char *first_fastq_read[]; 57 | extern const size_t first_fastq_len; 58 | extern struct testcase_t data_tests[]; 59 | extern const size_t n_codons; 60 | extern const char *codon_list[]; 61 | extern const char aa_list[]; 62 | 63 | void test_data_files (void *ptr); 64 | 65 | #endif /* TESTDATA_H */ 66 | -------------------------------------------------------------------------------- /src/libqes/test/tests.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================ 3 | * 4 | * Filename: tests.h 5 | * 6 | * Description: Tests for libqes 7 | * License: GPLv3+ 8 | * Author: Kevin Murray, spam@kdmurray.id.au 9 | * 10 | * ============================================================================ 11 | */ 12 | 13 | #ifndef TESTS_H 14 | #define TESTS_H 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #ifndef _WIN32 24 | #include 25 | #endif 26 | #include 27 | #include 28 | 29 | /* TinyTest */ 30 | #include "tinytest.h" 31 | #include "tinytest_macros.h" 32 | #include "testdata.h" 33 | #include "helpers.h" 34 | 35 | #define QES_DEFAULT_ERR_FN errnil 36 | #define QES_EXIT_FN (void) 37 | #include 38 | 39 | 40 | /* test_util tests */ 41 | extern struct testcase_t qes_util_tests[]; 42 | /* test_match tests */ 43 | extern struct testcase_t qes_match_tests[]; 44 | /* test_qes_file tests */ 45 | extern struct testcase_t qes_file_tests[]; 46 | /* test_seqfile tests */ 47 | extern struct testcase_t qes_seqfile_tests[]; 48 | /* test_seq tests */ 49 | extern struct testcase_t qes_seq_tests[]; 50 | /* test_sequtil tests */ 51 | extern struct testcase_t qes_sequtil_tests[]; 52 | /* test_log tests */ 53 | extern struct testcase_t qes_log_tests[]; 54 | /* test_helpers tests */ 55 | extern struct testcase_t helper_tests[]; 56 | 57 | #endif /* TESTS_H */ 58 | -------------------------------------------------------------------------------- /src/libqes/test/tinytest/tinytest.h: -------------------------------------------------------------------------------- 1 | /* tinytest.h -- Copyright 2009-2012 Nick Mathewson 2 | * 3 | * Redistribution and use in source and binary forms, with or without 4 | * modification, are permitted provided that the following conditions 5 | * are met: 6 | * 1. Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * 2. Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * 3. The name of the author may not be used to endorse or promote products 12 | * derived from this software without specific prior written permission. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef TINYTEST_H_INCLUDED_ 27 | #define TINYTEST_H_INCLUDED_ 28 | 29 | /** Flag for a test that needs to run in a subprocess. */ 30 | #define TT_FORK (1<<0) 31 | /** Runtime flag for a test we've decided to skip. */ 32 | #define TT_SKIP (1<<1) 33 | /** Internal runtime flag for a test we've decided to run. */ 34 | #define TT_ENABLED_ (1<<2) 35 | /** Flag for a test that's off by default. */ 36 | #define TT_OFF_BY_DEFAULT (1<<3) 37 | /** If you add your own flags, make them start at this point. */ 38 | #define TT_FIRST_USER_FLAG (1<<4) 39 | 40 | typedef void (*testcase_fn)(void *); 41 | 42 | struct testcase_t; 43 | 44 | /** Functions to initialize/teardown a structure for a testcase. */ 45 | struct testcase_setup_t { 46 | /** Return a new structure for use by a given testcase. */ 47 | void *(*setup_fn)(const struct testcase_t *); 48 | /** Clean/free a structure from setup_fn. Return 1 if ok, 0 on err. */ 49 | int (*cleanup_fn)(const struct testcase_t *, void *); 50 | }; 51 | 52 | /** A single test-case that you can run. */ 53 | struct testcase_t { 54 | const char *name; /**< An identifier for this case. */ 55 | testcase_fn fn; /**< The function to run to implement this case. */ 56 | unsigned long flags; /**< Bitfield of TT_* flags. */ 57 | const struct testcase_setup_t *setup; /**< Optional setup/cleanup fns*/ 58 | void *setup_data; /**< Extra data usable by setup function */ 59 | }; 60 | #define END_OF_TESTCASES { NULL, NULL, 0, NULL, NULL } 61 | 62 | /** A group of tests that are selectable together. */ 63 | struct testgroup_t { 64 | const char *prefix; /**< Prefix to prepend to testnames. */ 65 | struct testcase_t *cases; /** Array, ending with END_OF_TESTCASES */ 66 | }; 67 | #define END_OF_GROUPS { NULL, NULL} 68 | 69 | struct testlist_alias_t { 70 | const char *name; 71 | const char **tests; 72 | }; 73 | #define END_OF_ALIASES { NULL, NULL } 74 | 75 | /** Implementation: called from a test to indicate failure, before logging. */ 76 | void tinytest_set_test_failed_(void); 77 | /** Implementation: called from a test to indicate that we're skipping. */ 78 | void tinytest_set_test_skipped_(void); 79 | /** Implementation: return 0 for quiet, 1 for normal, 2 for loud. */ 80 | int tinytest_get_verbosity_(void); 81 | /** Implementation: Set a flag on tests matching a name; returns number 82 | * of tests that matched. */ 83 | int tinytest_set_flag_(struct testgroup_t *, const char *, int set, unsigned long); 84 | /** Implementation: Put a chunk of memory into hex. */ 85 | char *tinytest_format_hex_(const void *, unsigned long); 86 | 87 | /** Set all tests in 'groups' matching the name 'named' to be skipped. */ 88 | #define tinytest_skip(groups, named) \ 89 | tinytest_set_flag_(groups, named, 1, TT_SKIP) 90 | 91 | /** Run a single testcase in a single group. */ 92 | int testcase_run_one(const struct testgroup_t *,const struct testcase_t *); 93 | 94 | void tinytest_set_aliases(const struct testlist_alias_t *aliases); 95 | 96 | /** Run a set of testcases from an END_OF_GROUPS-terminated array of groups, 97 | as selected from the command line. */ 98 | int tinytest_main(int argc, const char **argv, struct testgroup_t *groups); 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /src/libqes/util/make_codon_list.py: -------------------------------------------------------------------------------- 1 | from Bio.Data import CodonTable 2 | 3 | nts = "ACGTU" 4 | codons = [] 5 | aas = [] 6 | codon_tab = CodonTable.generic_by_name["Standard"].forward_table 7 | for a in nts: 8 | for b in nts: 9 | for c in nts: 10 | codon = "".join((a,b,c)) 11 | try: 12 | aa = codon_tab[codon.replace("U", "T")] 13 | except KeyError: 14 | aa = "*" 15 | codons.append(codon) 16 | aas.append(aa) 17 | n = 0 18 | print "const size_t n_codons = %s;" % len(codons) 19 | print 20 | print "const char *codon_list[] = {" , 21 | for cdn in codons: 22 | if n % 5 == 0: 23 | print "\n ", 24 | print '"%s", ' % cdn, 25 | n += 1 26 | print 27 | print "};" 28 | n = 0 29 | print 30 | print "const char aa_list[] = {", 31 | for aa in aas: 32 | if n % 5 == 0: 33 | print "\n ", 34 | print "'%s', " % aa, 35 | n += 1 36 | print 37 | print "};" 38 | print 39 | -------------------------------------------------------------------------------- /src/libqes/util/make_codon_map.py: -------------------------------------------------------------------------------- 1 | from Bio.Data import CodonTable 2 | 3 | nts = "ACGTU" 4 | 5 | codon_tab = CodonTable.generic_by_name["Standard"].forward_table 6 | print "char\ntranslate_codon(char *codon)\n{" 7 | for a in nts: 8 | print " else if (codon[0] == '%s') {" % a 9 | for b in nts: 10 | print " else if (codon[1] == '%s') {" % b 11 | for c in nts: 12 | print " else if (codon[2] == '%s')" % c , 13 | codon = "".join((a,b,c)) 14 | try: 15 | aa = codon_tab[codon] 16 | except KeyError: 17 | aa = "*" 18 | print "return '%s'" % aa 19 | print " }" 20 | print " }" 21 | print "}" 22 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/tinytest) 2 | 3 | ADD_EXECUTABLE(test_axe test.c ${CMAKE_CURRENT_SOURCE_DIR}/tinytest/tinytest.c test_libaxe.c) 4 | TARGET_LINK_LIBRARIES(test_axe ${AXE_DEPENDS_LIBRARIES} axelib qes_static) 5 | 6 | # Copy test files over to bin dir & make output 7 | ADD_CUSTOM_TARGET(setup_tests ALL 8 | COMMAND ${CMAKE_COMMAND} -E copy_directory 9 | ${CMAKE_CURRENT_SOURCE_DIR}/data 10 | ${CMAKE_BINARY_DIR}/data 11 | COMMAND ${CMAKE_COMMAND} -E copy 12 | ${CMAKE_CURRENT_SOURCE_DIR}/axe_cli_tests.py 13 | ${CMAKE_BINARY_DIR}/bin 14 | COMMAND ${CMAKE_COMMAND} -E make_directory 15 | ${CMAKE_BINARY_DIR}/out) 16 | ADD_DEPENDENCIES(test_axe setup_tests) 17 | 18 | ADD_TEST(NAME "UnitTests" COMMAND test_axe) 19 | SET(COVERAGE_CMD test_axe) 20 | SET(COVERAGE_OUT "${CMAKE_BINARY_DIR}/coverage_html") 21 | 22 | ADD_TEST(NAME "IntegrationTests" COMMAND python 23 | ${CMAKE_BINARY_DIR}/bin/axe_cli_tests.py 24 | ${CMAKE_BINARY_DIR}) 25 | 26 | IF (CMAKE_BUILD_TYPE STREQUAL "Coverage") 27 | FIND_PROGRAM( GCOV_PATH gcov ) 28 | FIND_PROGRAM( LCOV_PATH lcov ) 29 | FIND_PROGRAM( GENHTML_PATH genhtml ) 30 | FIND_PROGRAM( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/tests) 31 | 32 | SET(CMAKE_C_FLAGS_COVERAGE 33 | "${CMAKE_C_FLAGS_DEBUG} -g -O0 --coverage -fprofile-arcs -ftest-coverage" 34 | CACHE STRING "Flags used by the C compiler during coverage builds." 35 | FORCE) 36 | SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE 37 | "" 38 | CACHE STRING "Flags used for linking binaries during coverage builds." 39 | FORCE) 40 | SET(CMAKE_SHARED_LINKER_FLAGS_COVERAGE 41 | "" 42 | CACHE STRING "Flags used by the shared libraries linker during coverage builds." 43 | FORCE) 44 | MARK_AS_ADVANCED( 45 | CMAKE_C_FLAGS_COVERAGE 46 | CMAKE_EXE_LINKER_FLAGS_COVERAGE 47 | CMAKE_SHARED_LINKER_FLAGS_COVERAGE ) 48 | 49 | IF(NOT GCOV_PATH) 50 | MESSAGE(FATAL_ERROR "gcov not found! Aborting...") 51 | ENDIF() # NOT GCOV_PATH 52 | IF(NOT LCOV_PATH) 53 | MESSAGE(FATAL_ERROR "lcov not found! Aborting...") 54 | ENDIF() # NOT LCOV_PATH 55 | IF(NOT GENHTML_PATH) 56 | MESSAGE(FATAL_ERROR "genhtml not found! Aborting...") 57 | ENDIF() # NOT GENHTML_PATH 58 | IF(NOT CMAKE_COMPILER_IS_GNUCC AND NOT CMAKE_COMPILER_IS_GNUCXX) 59 | # Clang version 3.0.0 and greater now supports gcov as well. 60 | MESSAGE(WARNING "Compiler is not GNU gcc! Clang Version 3.0.0 and greater supports gcov as well, but older versions don't.") 61 | IF(NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" AND NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") 62 | MESSAGE(FATAL_ERROR "Compiler is not GNU gcc! Aborting...") 63 | ENDIF() 64 | ENDIF() # NOT CMAKE_COMPILER_IS_GNUCXX 65 | 66 | # Setup target 67 | ADD_CUSTOM_TARGET(coverage 68 | # Cleanup lcov 69 | COMMAND ${LCOV_PATH} --rc lcov_branch_coverage=1 --directory ${CMAKE_BINARY_DIR}/src --zerocounters 70 | 71 | # Run tests 72 | COMMAND ${COVERAGE_CMD} 73 | 74 | # Capturing lcov counters and generating report 75 | COMMAND ${LCOV_PATH} --rc lcov_branch_coverage=1 --directory ${CMAKE_BINARY_DIR}/src --capture --output-file ${COVERAGE_OUT}.info 76 | COMMAND ${LCOV_PATH} --rc lcov_branch_coverage=1 --output-file ${COVERAGE_OUT}.info --remove ${COVERAGE_OUT}.info src/libqes/* 77 | COMMAND ${LCOV_PATH} --rc lcov_branch_coverage=1 --output-file ${COVERAGE_OUT}.info --remove ${COVERAGE_OUT}.info src/datrie/* 78 | COMMAND ${GENHTML_PATH} --branch-coverage -o ${COVERAGE_OUT} ${COVERAGE_OUT}.info 79 | COMMAND ${CMAKE_COMMAND} -E remove ${COVERAGE_OUT}.info 80 | 81 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 82 | COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report." 83 | ) 84 | 85 | # Show info where to find the report 86 | ADD_CUSTOM_COMMAND(TARGET coverage POST_BUILD 87 | COMMAND ; 88 | COMMENT "Open ${COVERAGE_OUT}/index.html in your browser to view the coverage report." 89 | ) 90 | 91 | ENDIF() # build type coverage 92 | -------------------------------------------------------------------------------- /tests/data/fake.barcodes: -------------------------------------------------------------------------------- 1 | Barcode ID 2 | ATCACG 1 3 | CGATGT 2 4 | -------------------------------------------------------------------------------- /tests/data/fake_0mm_R1.fq.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kdm9/axe/c8a636fd11d394034776bda45a5f0ef9b6e80046/tests/data/fake_0mm_R1.fq.gz -------------------------------------------------------------------------------- /tests/data/fake_1mm_R1.fq.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kdm9/axe/c8a636fd11d394034776bda45a5f0ef9b6e80046/tests/data/fake_1mm_R1.fq.gz -------------------------------------------------------------------------------- /tests/data/fake_2mm_R1.fq.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kdm9/axe/c8a636fd11d394034776bda45a5f0ef9b6e80046/tests/data/fake_2mm_R1.fq.gz -------------------------------------------------------------------------------- /tests/data/gbs.barcodes: -------------------------------------------------------------------------------- 1 | Barcode1 Barcode2 ID 2 | CTCGTGCAG CGAGTGCAG A1 3 | TGCATGCAG TGCATGCAG A2 4 | ACTATGCAG TAGTTGCAG A3 5 | CAGATGCAG TCTGTGCAG A4 6 | AACTTGCAG AGTTTGCAG A5 7 | GCGTTGCAG ACGCTGCAG A6 8 | CGATTGCAG ATCGTGCAG A7 9 | GTAATGCAG TTACTGCAG A8 10 | AGGGTGCAG CCCTTGCAG A9 11 | GATGTGCAG CATCTGCAG A10 12 | TCAGTGCAG CTGATGCAG A11 13 | TGCGATGCAG TCGCATGCAG A12 14 | CGCTTTGCAG AAGCGTGCAG B1 15 | TCACGTGCAG CGTGATGCAG B2 16 | CTAGGTGCAG CCTAGTGCAG B3 17 | ACAAATGCAG TTTGTTGCAG B4 18 | TTCTGTGCAG CAGAATGCAG B5 19 | AGCCGTGCAG CGGCTTGCAG B6 20 | GTATTTGCAG AATACTGCAG B7 21 | CTGTATGCAG TACAGTGCAG B8 22 | ACCGTTGCAG ACGGTTGCAG B9 23 | GCTTATGCAG TAAGCTGCAG B10 24 | GGTGTTGCAG ACACCTGCAG B11 25 | AGGATTGCAG ATCCTTGCAG B12 26 | ATTGATGCAG TCAATTGCAG C1 27 | CATCTTGCAG AGATGTGCAG C2 28 | CCTAGTGCAG CTAGGTGCAG C3 29 | GAGGATGCAG TCCTCTGCAG C4 30 | GGAAGTGCAG CTTCCTGCAG C5 31 | GTCAATGCAG TTGACTGCAG C6 32 | TAATATGCAG TATTATGCAG C7 33 | TACATTGCAG ATGTATGCAG C8 34 | TCGTTTGCAG AACGATGCAG C9 35 | GGTTGTTGCAG ACAACCTGCAG C10 36 | CCAGCTTGCAG AGCTGGTGCAG C11 37 | TTCAGATGCAG TCTGAATGCAG C12 38 | TAGGAATGCAG TTCCTATGCAG D1 39 | GCTCTATGCAG TAGAGCTGCAG D2 40 | CCACAATGCAG TTGTGGTGCAG D3 41 | CTTCCATGCAG TGGAAGTGCAG D4 42 | GAGATATGCAG TATCTCTGCAG D5 43 | ATGCCTTGCAG AGGCATTGCAG D6 44 | AGTGGATGCAG TCCACTTGCAG D7 45 | ACCTAATGCAG TTAGGTTGCAG D8 46 | ATATGTTGCAG ACATATTGCAG D9 47 | ATCGTATGCAG TACGATTGCAG D10 48 | CATCGTTGCAG ACGATGTGCAG D11 49 | CGCGGTTGCAG ACCGCGTGCAG D12 50 | CTATTATGCAG TAATAGTGCAG E1 51 | GCCAGTTGCAG ACTGGCTGCAG E2 52 | GGAAGATGCAG TCTTCCTGCAG E3 53 | GTACTTTGCAG AAGTACTGCAG E4 54 | GTTGAATGCAG TTCAACTGCAG E5 55 | TAACGATGCAG TCGTTATGCAG E6 56 | TGGCTATGCAG TAGCCATGCAG E7 57 | TATTTTTTGCAG AAAAATATGCAG E8 58 | CTTGCTTTGCAG AAGCAAGTGCAG E9 59 | ATGAAAGTGCAG CTTTCATTGCAG E10 60 | AAAAGTTTGCAG AACTTTTTGCAG E11 61 | GAATTCATGCAG TGAATTCTGCAG E12 62 | GAACTTGTGCAG CAAGTTCTGCAG F1 63 | GGACCTATGCAG TAGGTCCTGCAG F2 64 | GTCGATTTGCAG AATCGACTGCAG F3 65 | AACGCCTTGCAG AGGCGTTTGCAG F4 66 | AATATGGTGCAG CCATATTTGCAG F5 67 | ACGTGTTTGCAG AACACGTTGCAG F6 68 | ATTAATTTGCAG AATTAATTGCAG F7 69 | ATTGGATTGCAG ATCCAATTGCAG F8 70 | CATAAGTTGCAG ACTTATGTGCAG F9 71 | CGCTGATTGCAG ATCAGCGTGCAG F10 72 | CGGTAGATGCAG TCTACCGTGCAG F11 73 | CTACGGATGCAG TCCGTAGTGCAG F12 74 | GCGGAATTGCAG ATTCCGCTGCAG G1 75 | TAGCGGATGCAG TCCGCTATGCAG G2 76 | TCGAAGATGCAG TCTTCGATGCAG G3 77 | TCTGTGATGCAG TCACAGATGCAG G4 78 | TGCTGGATGCAG TCCAGCATGCAG G5 79 | ACGACTAGTGCAG CTAGTCGTTGCAG G6 80 | TAGCATGGTGCAG CCATGCTATGCAG G7 81 | TAGGCCATTGCAG ATGGCCTATGCAG G8 82 | TGCAAGGATGCAG TCCTTGCATGCAG G9 83 | TGGTACGTTGCAG ACGTACCATGCAG G10 84 | TCTCAGTGTGCAG CACTGAGATGCAG G11 85 | CCGGATATTGCAG ATATCCGGTGCAG G12 86 | CGCCTTATTGCAG ATAAGGCGTGCAG H1 87 | AACCGAGATGCAG TCTCGGTTTGCAG H2 88 | ACAGGGAATGCAG TTCCCTGTTGCAG H3 89 | ACGTGGTATGCAG TACCACGTTGCAG H4 90 | CCATGGGTTGCAG ACCCATGGTGCAG H5 91 | CGCGGAGATGCAG TCTCCGCGTGCAG H6 92 | CGTGTGGTTGCAG ACCACACGTGCAG H7 93 | GCTGTGGATGCAG TCCACAGCTGCAG H8 94 | GGATTGGTTGCAG ACCAATCCTGCAG H9 95 | GTGAGGGTTGCAG ACCCTCACTGCAG H10 96 | TATCGGGATGCAG TCCCGATATGCAG H11 97 | TTCCTGGATGCAG TCCAGGAATGCAG H12 98 | -------------------------------------------------------------------------------- /tests/data/gbs_R1.fastq.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kdm9/axe/c8a636fd11d394034776bda45a5f0ef9b6e80046/tests/data/gbs_R1.fastq.gz -------------------------------------------------------------------------------- /tests/data/gbs_R2.fastq.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kdm9/axe/c8a636fd11d394034776bda45a5f0ef9b6e80046/tests/data/gbs_R2.fastq.gz -------------------------------------------------------------------------------- /tests/data/gbs_se.barcodes: -------------------------------------------------------------------------------- 1 | Barcode1 ID 2 | CTCGTGCAG A1 3 | TGCATGCAG A2 4 | ACTATGCAG A3 5 | CAGATGCAG A4 6 | AACTTGCAG A5 7 | GCGTTGCAG A6 8 | CGATTGCAG A7 9 | GTAATGCAG A8 10 | AGGGTGCAG A9 11 | GATGTGCAG A10 12 | TCAGTGCAG A11 13 | TGCGATGCAG A12 14 | CGCTTTGCAG B1 15 | TCACGTGCAG B2 16 | CTAGGTGCAG B3 17 | ACAAATGCAG B4 18 | TTCTGTGCAG B5 19 | AGCCGTGCAG B6 20 | GTATTTGCAG B7 21 | CTGTATGCAG B8 22 | ACCGTTGCAG B9 23 | GCTTATGCAG B10 24 | GGTGTTGCAG B11 25 | AGGATTGCAG B12 26 | ATTGATGCAG C1 27 | CATCTTGCAG C2 28 | CCTAGTGCAG C3 29 | GAGGATGCAG C4 30 | GGAAGTGCAG C5 31 | GTCAATGCAG C6 32 | TAATATGCAG C7 33 | TACATTGCAG C8 34 | TCGTTTGCAG C9 35 | GGTTGTTGCAG C10 36 | CCAGCTTGCAG C11 37 | TTCAGATGCAG C12 38 | TAGGAATGCAG D1 39 | GCTCTATGCAG D2 40 | CCACAATGCAG D3 41 | CTTCCATGCAG D4 42 | GAGATATGCAG D5 43 | ATGCCTTGCAG D6 44 | AGTGGATGCAG D7 45 | ACCTAATGCAG D8 46 | ATATGTTGCAG D9 47 | ATCGTATGCAG D10 48 | CATCGTTGCAG D11 49 | CGCGGTTGCAG D12 50 | CTATTATGCAG E1 51 | GCCAGTTGCAG E2 52 | GGAAGATGCAG E3 53 | GTACTTTGCAG E4 54 | GTTGAATGCAG E5 55 | TAACGATGCAG E6 56 | TGGCTATGCAG E7 57 | TATTTTTTGCAG E8 58 | CTTGCTTTGCAG E9 59 | ATGAAAGTGCAG E10 60 | AAAAGTTTGCAG E11 61 | GAATTCATGCAG E12 62 | GAACTTGTGCAG F1 63 | GGACCTATGCAG F2 64 | GTCGATTTGCAG F3 65 | AACGCCTTGCAG F4 66 | AATATGGTGCAG F5 67 | ACGTGTTTGCAG F6 68 | ATTAATTTGCAG F7 69 | ATTGGATTGCAG F8 70 | CATAAGTTGCAG F9 71 | CGCTGATTGCAG F10 72 | CGGTAGATGCAG F11 73 | CTACGGATGCAG F12 74 | GCGGAATTGCAG G1 75 | TAGCGGATGCAG G2 76 | TCGAAGATGCAG G3 77 | TCTGTGATGCAG G4 78 | TGCTGGATGCAG G5 79 | ACGACTAGTGCAG G6 80 | TAGCATGGTGCAG G7 81 | TAGGCCATTGCAG G8 82 | TGCAAGGATGCAG G9 83 | TGGTACGTTGCAG G10 84 | TCTCAGTGTGCAG G11 85 | CCGGATATTGCAG G12 86 | CGCCTTATTGCAG H1 87 | AACCGAGATGCAG H2 88 | ACAGGGAATGCAG H3 89 | ACGTGGTATGCAG H4 90 | CCATGGGTTGCAG H5 91 | CGCGGAGATGCAG H6 92 | CGTGTGGTTGCAG H7 93 | GCTGTGGATGCAG H8 94 | GGATTGGTTGCAG H9 95 | GTGAGGGTTGCAG H10 96 | TATCGGGATGCAG H11 97 | TTCCTGGATGCAG H12 98 | -------------------------------------------------------------------------------- /tests/data/pare.barcodes: -------------------------------------------------------------------------------- 1 | Barcode ID 2 | ATCACG 1 3 | CGATGT 2 4 | TTAGGC 3 5 | TGACCA 4 6 | ACAGTG 5 7 | GCCAAT 6 8 | CAGATC 7 9 | ACTTGA 8 10 | GATCAG 9 11 | -------------------------------------------------------------------------------- /tests/data/pare.fq.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kdm9/axe/c8a636fd11d394034776bda45a5f0ef9b6e80046/tests/data/pare.fq.gz -------------------------------------------------------------------------------- /tests/data/pare_full.fq.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kdm9/axe/c8a636fd11d394034776bda45a5f0ef9b6e80046/tests/data/pare_full.fq.gz -------------------------------------------------------------------------------- /tests/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================ 3 | * 4 | * Filename: test.c 5 | * 6 | * Description: Tests for axe 7 | * 8 | * Version: 1.0 9 | * Created: 20/06/14 17:14:55 10 | * Revision: none 11 | * License: GPLv3+ 12 | * Compiler: gcc, clang 13 | * 14 | * Author: Kevin Murray, spam@kdmurray.id.au 15 | * 16 | * ============================================================================ 17 | */ 18 | #include "tests.h" 19 | #include 20 | 21 | 22 | struct testgroup_t axe_tests[] = { 23 | {"libaxe/", core_tests}, 24 | END_OF_GROUPS 25 | }; 26 | 27 | 28 | /* 29 | * === FUNCTION ============================================================= 30 | * Name: main 31 | * Description: Run all tests 32 | * ============================================================================ 33 | */ 34 | 35 | int 36 | main (int argc, const char *argv[]) 37 | { 38 | int res; 39 | int our_argc = argc; 40 | const char **our_argv = argv; 41 | char *data_prefix; 42 | 43 | data_prefix = NULL; 44 | if (argc>1) { 45 | data_prefix = strdup(argv[1]); 46 | our_argc -= 1; 47 | our_argv += 1; 48 | } else { 49 | data_prefix = strdup("."); 50 | } 51 | assert(data_prefix != NULL); 52 | if (access(data_prefix, W_OK | X_OK | R_OK) != 0) { 53 | fprintf(stderr, "Could not access data prefix dir '%s'\n", data_prefix); 54 | free(data_prefix); 55 | exit(EXIT_FAILURE); 56 | } 57 | res = tinytest_main(our_argc, our_argv, axe_tests); 58 | free(data_prefix); 59 | return res; 60 | } 61 | -------------------------------------------------------------------------------- /tests/test_libaxe.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================ 3 | * 4 | * Filename: test_libaxe.c 5 | * 6 | * Description: Tests of core functionality 7 | * 8 | * Version: 1.0 9 | * Created: 22/06/14 13:23:46 10 | * Revision: none 11 | * License: GPLv3+ 12 | * Compiler: gcc, clang 13 | * 14 | * Author: Kevin Murray, spam@kdmurray.id.au 15 | * 16 | * ============================================================================ 17 | */ 18 | 19 | #include "tests.h" 20 | 21 | static void 22 | test_product (void *ptr) 23 | { 24 | const uint64_t len = 4; 25 | const uint64_t elem = 2; 26 | uintptr_t choices[] = {0,0}; 27 | /* Truth from python's itertools.product */ 28 | uintptr_t truth[][2] = { 29 | {0, 0}, {0, 1}, {0, 2}, {0, 3}, 30 | {1, 0}, {1, 1}, {1, 2}, {1, 3}, 31 | {2, 0}, {2, 1}, {2, 2}, {2, 3}, 32 | {3, 0}, {3, 1}, {3, 2}, {3, 3}, }; 33 | int ret = 0; 34 | int count = 0; 35 | size_t iii = 0; 36 | 37 | (void)ptr; 38 | while ((ret = product(len, elem, choices, !ret)) == 1) { 39 | 40 | for (iii = 0; iii < elem; iii++) { 41 | tt_int_op(choices[iii], ==, truth[count][iii]); 42 | } 43 | count++; 44 | } 45 | tt_int_op(ret, ==, 0); 46 | tt_int_op(count, ==, 16); 47 | end: 48 | ; 49 | } 50 | 51 | static void 52 | test_hamming_mutate (void *ptr) 53 | { 54 | char **mutated = NULL; 55 | size_t count = 0; 56 | size_t iii = 0; 57 | const char *str = "AAAA"; 58 | const char *truth[] = { 59 | "AAAA", "ACAA", "AGAA", "ATAA", "CAAA", "CCAA", "CGAA", "CTAA", "GAAA", 60 | "GCAA", "GGAA", "GTAA", "TAAA", "TCAA", "TGAA", "TTAA", "AAAA", "AACA", 61 | "AAGA", "AATA", "CAAA", "CACA", "CAGA", "CATA", "GAAA", "GACA", "GAGA", 62 | "GATA", "TAAA", "TACA", "TAGA", "TATA", "AAAA", "AAAC", "AAAG", "AAAT", 63 | "CAAA", "CAAC", "CAAG", "CAAT", "GAAA", "GAAC", "GAAG", "GAAT", "TAAA", 64 | "TAAC", "TAAG", "TAAT", "AAAA", "AACA", "AAGA", "AATA", "ACAA", "ACCA", 65 | "ACGA", "ACTA", "AGAA", "AGCA", "AGGA", "AGTA", "ATAA", "ATCA", "ATGA", 66 | "ATTA", "AAAA", "AAAC", "AAAG", "AAAT", "ACAA", "ACAC", "ACAG", "ACAT", 67 | "AGAA", "AGAC", "AGAG", "AGAT", "ATAA", "ATAC", "ATAG", "ATAT", "AAAA", 68 | "AAAC", "AAAG", "AAAT", "AACA", "AACC", "AACG", "AACT", "AAGA", "AAGC", 69 | "AAGG", "AAGT", "AATA", "AATC", "AATG", "AATT", }; 70 | 71 | (void) ptr; 72 | mutated = hamming_mutate_dna(&count, str, strlen(str), 2, 1); 73 | tt_ptr_op(mutated, !=, NULL); 74 | tt_int_op(count, ==, 96); 75 | for (iii = 0; iii < count; iii++) { 76 | tt_ptr_op(mutated[iii], !=, NULL); 77 | tt_str_op(mutated[iii], ==, truth[iii]); 78 | } 79 | 80 | end: 81 | if (mutated != NULL) { 82 | for (iii = 0; iii < count; iii++) { 83 | if (mutated[iii] != NULL) { 84 | free(mutated[iii]); 85 | } 86 | } 87 | free(mutated); 88 | } 89 | } 90 | 91 | struct testcase_t core_tests[] = { 92 | { "product", test_product, 0, NULL, NULL}, 93 | { "hamming_mutate", test_hamming_mutate, 0, NULL, NULL}, 94 | END_OF_TESTCASES 95 | }; 96 | -------------------------------------------------------------------------------- /tests/tests.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================ 3 | * 4 | * Filename: tests.h 5 | * 6 | * Description: All tests for axe, and all common includes. 7 | * 8 | * Version: 1.0 9 | * Created: 20/06/14 17:16:52 10 | * Revision: none 11 | * License: GPLv3+ 12 | * Compiler: gcc, clang 13 | * 14 | * Author: Kevin Murray, spam@kdmurray.id.au 15 | * 16 | * ============================================================================ 17 | */ 18 | 19 | #ifndef AXE_TESTS_H 20 | #define AXE_TESTS_H 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #ifndef _WIN32 30 | #include 31 | #endif 32 | 33 | #include 34 | #include 35 | 36 | /* TinyTest */ 37 | #include "tinytest/tinytest.h" 38 | #include "tinytest/tinytest_macros.h" 39 | 40 | #include 41 | 42 | #include "axe.h" 43 | 44 | 45 | /* Core tests */ 46 | extern struct testcase_t core_tests[]; 47 | #endif /* ifndef AXE_TESTS_H */ 48 | -------------------------------------------------------------------------------- /tests/tinytest/.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.o 3 | \#*\# 4 | .\#* 5 | 6 | /tt-demo 7 | /tt-demo.exe 8 | -------------------------------------------------------------------------------- /tests/tinytest/Makefile: -------------------------------------------------------------------------------- 1 | VERSION=1.0.1 2 | 3 | all: tt-demo 4 | 5 | .c.o: 6 | gcc -Wall -g -O2 -c $< 7 | 8 | tinytest.o: tinytest.h 9 | 10 | tinytest_demo.o: tinytest_macros.h tinytest.h 11 | 12 | OBJS=tinytest.o tinytest_demo.o 13 | 14 | tt-demo: $(OBJS) 15 | gcc -Wall -g -O2 $(OBJS) -o tt-demo 16 | 17 | lines: 18 | wc -l tinytest.c tinytest_macros.h tinytest.h 19 | 20 | clean: 21 | rm -f *.o *~ tt-demo 22 | 23 | DISTFILES=tinytest.c tinytest_demo.c tinytest.h tinytest_macros.h Makefile \ 24 | README 25 | 26 | dist: 27 | rm -rf tinytest-$(VERSION) 28 | mkdir tinytest-$(VERSION) 29 | cp $(DISTFILES) tinytest-$(VERSION) 30 | tar cf - tinytest-$(VERSION) | gzip -c -9 > tinytest-$(VERSION).tar.gz 31 | -------------------------------------------------------------------------------- /tests/tinytest/README: -------------------------------------------------------------------------------- 1 | Tinytest is a tiny little test framework written in C by Nick Mathewson. 2 | 3 | It is distributed under the 3-clause BSD license. You can use it in 4 | your own programs so long as you follow the license's conditions. 5 | 6 | It's been tested on Windows, Mac, and many of the free Unixes. 7 | 8 | It knows how to fork before running certain tests, and it makes 9 | text-mode output in a format I like. 10 | 11 | For info on how to use it, check out tinytest_demo.c. 12 | 13 | You can get the latest version using Git, by pulling from 14 | git://github.com/nmathewson/tinytest.git 15 | 16 | Patches are welcome. Patches that turn this from tinytest to hugetest 17 | will not be applied. If you want a huge test framework, use CUnit. 18 | 19 | -------------------------------------------------------------------------------- /tests/tinytest/TODO: -------------------------------------------------------------------------------- 1 | Things to do to tinytest 2 | 3 | o Replace the license with something recognizeable 4 | o Test forking on win32. 5 | o Write minimalist libevent-legacy thing. 6 | o port libevent tests; move libevent test main into a new regress_main 7 | o allow per-group forks. 8 | o See where we're at. 9 | 10 | - Allow groups to nest, perhaps. 11 | - Port Tor to use tinytest 12 | - Warn when running multiple tests with --no-fork 13 | -------------------------------------------------------------------------------- /tests/tinytest/tinytest.h: -------------------------------------------------------------------------------- 1 | /* tinytest.h -- Copyright 2009-2012 Nick Mathewson 2 | * 3 | * Redistribution and use in source and binary forms, with or without 4 | * modification, are permitted provided that the following conditions 5 | * are met: 6 | * 1. Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * 2. Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * 3. The name of the author may not be used to endorse or promote products 12 | * derived from this software without specific prior written permission. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef TINYTEST_H_INCLUDED_ 27 | #define TINYTEST_H_INCLUDED_ 28 | 29 | /** Flag for a test that needs to run in a subprocess. */ 30 | #define TT_FORK (1<<0) 31 | /** Runtime flag for a test we've decided to skip. */ 32 | #define TT_SKIP (1<<1) 33 | /** Internal runtime flag for a test we've decided to run. */ 34 | #define TT_ENABLED_ (1<<2) 35 | /** Flag for a test that's off by default. */ 36 | #define TT_OFF_BY_DEFAULT (1<<3) 37 | /** If you add your own flags, make them start at this point. */ 38 | #define TT_FIRST_USER_FLAG (1<<4) 39 | 40 | typedef void (*testcase_fn)(void *); 41 | 42 | struct testcase_t; 43 | 44 | /** Functions to initialize/teardown a structure for a testcase. */ 45 | struct testcase_setup_t { 46 | /** Return a new structure for use by a given testcase. */ 47 | void *(*setup_fn)(const struct testcase_t *); 48 | /** Clean/free a structure from setup_fn. Return 1 if ok, 0 on err. */ 49 | int (*cleanup_fn)(const struct testcase_t *, void *); 50 | }; 51 | 52 | /** A single test-case that you can run. */ 53 | struct testcase_t { 54 | const char *name; /**< An identifier for this case. */ 55 | testcase_fn fn; /**< The function to run to implement this case. */ 56 | unsigned long flags; /**< Bitfield of TT_* flags. */ 57 | const struct testcase_setup_t *setup; /**< Optional setup/cleanup fns*/ 58 | void *setup_data; /**< Extra data usable by setup function */ 59 | }; 60 | #define END_OF_TESTCASES { NULL, NULL, 0, NULL, NULL } 61 | 62 | /** A group of tests that are selectable together. */ 63 | struct testgroup_t { 64 | const char *prefix; /**< Prefix to prepend to testnames. */ 65 | struct testcase_t *cases; /** Array, ending with END_OF_TESTCASES */ 66 | }; 67 | #define END_OF_GROUPS { NULL, NULL} 68 | 69 | struct testlist_alias_t { 70 | const char *name; 71 | const char **tests; 72 | }; 73 | #define END_OF_ALIASES { NULL, NULL } 74 | 75 | /** Implementation: called from a test to indicate failure, before logging. */ 76 | void tinytest_set_test_failed_(void); 77 | /** Implementation: called from a test to indicate that we're skipping. */ 78 | void tinytest_set_test_skipped_(void); 79 | /** Implementation: return 0 for quiet, 1 for normal, 2 for loud. */ 80 | int tinytest_get_verbosity_(void); 81 | /** Implementation: Set a flag on tests matching a name; returns number 82 | * of tests that matched. */ 83 | int tinytest_set_flag_(struct testgroup_t *, const char *, int set, unsigned long); 84 | /** Implementation: Put a chunk of memory into hex. */ 85 | char *tinytest_format_hex_(const void *, unsigned long); 86 | 87 | /** Set all tests in 'groups' matching the name 'named' to be skipped. */ 88 | #define tinytest_skip(groups, named) \ 89 | tinytest_set_flag_(groups, named, 1, TT_SKIP) 90 | 91 | /** Run a single testcase in a single group. */ 92 | int testcase_run_one(const struct testgroup_t *,const struct testcase_t *); 93 | 94 | void tinytest_set_aliases(const struct testlist_alias_t *aliases); 95 | 96 | /** Run a set of testcases from an END_OF_GROUPS-terminated array of groups, 97 | as selected from the command line. */ 98 | int tinytest_main(int argc, const char **argv, struct testgroup_t *groups); 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /utils/hbb_script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | source /hbb_exe/activate 4 | set -x 5 | 6 | prefix=/io/axe_${AXE_VERSION}_amd64 7 | rm -rf $prefix 8 | mkdir -p $prefix 9 | trap "chown $HBBUID:$HBBUID -R $prefix" EXIT 10 | 11 | # Clone to builddir 12 | builddir=$(mktemp -d) 13 | cd $builddir 14 | tar xvf /io/axe_${AXE_VERSION}.tar --strip-components=1 15 | 16 | rm -rf build 17 | mkdir build 18 | cd build 19 | 20 | cmake .. \ 21 | -DAXE_VERSION=${AXE_VERSION} \ 22 | -DCMAKE_INSTALL_PREFIX=$prefix 23 | make -j4 VERBOSE=1 24 | make test 25 | make install 26 | -------------------------------------------------------------------------------- /utils/static_build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | version=$(git describe --always --match '[[:digit:]]*') 5 | 6 | srcdir=$PWD 7 | wkdir=$(mktemp -d) 8 | 9 | trap "rm -rf $wkdir" EXIT 10 | 11 | set -x 12 | 13 | git stash -u 14 | tar cvf $wkdir/axe_${version}.tar . 15 | git stash pop 16 | 17 | cd $wkdir 18 | 19 | docker run \ 20 | -v $wkdir:/io \ 21 | -v $srcdir/utils/hbb_script.sh:/hbb_script.sh:ro \ 22 | -e AXE_VERSION=${version} \ 23 | -e HBBUID=$(id -u) \ 24 | kdmurray91/kdm-hbb-64 \ 25 | bash /hbb_script.sh 26 | 27 | 28 | tar cvzf $srcdir/axe_${version}_amd64.tar.gz axe_${version}_amd64 29 | --------------------------------------------------------------------------------