Skip to content

Commit

Permalink
Merge pull request #203 from voutcn/refactor
Browse files Browse the repository at this point in the history
v1.2.1
  • Loading branch information
voutcn committed Mar 31, 2019
2 parents d4ad0ff + b790190 commit 99bae17
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 1,649 deletions.
11 changes: 9 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ language: python
python:
- "2.7"
- "3.4"
script: git submodule update --init && mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Debug -DCOVERAGE=ON && make -j2 simple_test
script:
- mkdir build
- cd build && cmake .. -DCMAKE_BUILD_TYPE=Debug -DCOVERAGE=ON
- make -j2 simple_test
- sudo make install
- megahit --test
- megahit --test --kmin-1pass
- megahit --test --no-hw-accel
after_success:
# Create lcov report
- lcov --capture --directory . --output-file coverage.info
- lcov --remove coverage.info '/usr/*' --output-file coverage.info # filter system-files
- lcov --remove coverage.info '*xxhash/*' --output-file coverage.info # filter xxhash-files
- lcov --remove coverage.info '*xxHash/*' --output-file coverage.info # filter xxhash-files
- lcov --remove coverage.info '*sparsepp/*' --output-file coverage.info # filter sparsepp-files
- lcov --list coverage.info # debug info
# Uploading report to CodeCov
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### 1.2.1-beta / 2019-03-30 PST
- Added `--no-hw-accel` option for users whose CPUs do not support BMI2/POPCNT
- Added `--test` option for testing
- Compilable with CMake 2.8 and g++4.8

### 1.2.0-beta / 2019-03-24 PST

Heavily refactored the whole project:
Expand Down
54 changes: 33 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
cmake_minimum_required(VERSION 2.8)
project(megahit)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_STANDARD 11)

option(USE_POPCNT "Use popcnt hardware instructions" ON)
option(USE_BMI2 "Use bmi2 hardware instructions" ON)
if (CMAKE_VERSION VERSION_LESS "3.1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else ()
set(CMAKE_CXX_STANDARD 11)
endif ()

option(COVERAGE "Generate coverage report" OFF)
option(STATIC_BUILD "Build static executation" OFF)

include_directories(src)
include_directories(src/sparsepp)
Expand All @@ -27,38 +31,47 @@ LIST(APPEND OTHER_SOURCE
src/sequence_manager.cpp
)

if (STATIC_BUILD)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
endif (STATIC_BUILD)

find_package(ZLIB REQUIRED)
find_package(OpenMP REQUIRED)

#set(STATIC_LIBS -lz -ldl -lpthread -lgomp -static-libstdc++ -static-libgcc -static)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DXXH_INLINE_ALL -D__STDC_FORMAT_MACROS")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unused-function")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprefetch-loop-arrays -funroll-loops")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__XFILE__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'")


if (USE_POPCNT)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mpopcnt")
endif (USE_POPCNT)

if (USE_BMI2)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mbmi2 -DUSE_BMI2")
endif (USE_BMI2)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${ZLIB_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")

if (COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
endif(COVERAGE)
set(COV_PY "coverage run")
endif (COVERAGE)

set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "-g -ggdb -O1")


message(STATUS "Build type: ${CMAKE_BUILD_TYPE}: ${CMAKE_CXX_FLAGS}")

add_executable(megahit_core ${OTHER_SOURCE} ${ASMBL_SOURCE} ${IDBA_SOURCE} ${SDBG_SOURCE} ${LCASM_SOURCE}
${CX1_SOURCE} ${TOOLKIT_SOURCE})
target_link_libraries(megahit_core ${ZLIB_LIBRARIES} ${OpenMP_CXX_LIBRARIES})
add_executable(megahit_core_no_hw_accel ${OTHER_SOURCE} ${ASMBL_SOURCE} ${IDBA_SOURCE} ${SDBG_SOURCE} ${LCASM_SOURCE}
${CX1_SOURCE} ${TOOLKIT_SOURCE})
set_target_properties(megahit_core PROPERTIES COMPILE_FLAGS "-mbmi2 -DUSE_BMI2 -mpopcnt")

if (STATIC_BUILD)
# TODO too dirty
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -static")
set_target_properties(megahit_core megahit_core_no_hw_accel PROPERTIES LINK_SEARCH_START_STATIC ON)
set_target_properties(megahit_core megahit_core_no_hw_accel PROPERTIES LINK_SEARCH_END_STATIC ON)
endif (STATIC_BUILD)

target_link_libraries(megahit_core ${ZLIB_LIBRARIES})
target_link_libraries(megahit_core_no_hw_accel ${ZLIB_LIBRARIES})

add_custom_target(
megahit
Expand All @@ -69,15 +82,14 @@ set(TEST_DATA ${CMAKE_SOURCE_DIR}/test_data)

add_custom_target(
simple_test
COMMAND rm -rf megahit_out*
COMMAND ./megahit --12 ${TEST_DATA}/r1.il.fa.gz,${TEST_DATA}/r2.il.fa.bz2 -1 ${TEST_DATA}/r3_1.fa -2 ${TEST_DATA}/r3_2.fa -r ${TEST_DATA}/r4.fa -o megahit_out1 -t 2 --keep-tmp-files
COMMAND rm -rf megahit_out*
COMMAND ./megahit --12 ${TEST_DATA}/r1.il.fa.gz,${TEST_DATA}/r2.il.fa.bz2 -1 ${TEST_DATA}/r3_1.fa -2 ${TEST_DATA}/r3_2.fa -r ${TEST_DATA}/r4.fa -o megahit_out2 -t 2 --keep-tmp-files --kmin-1pass
COMMAND ./megahit --test -t 2 --keep-tmp-files
COMMAND ./megahit --test -t 2 --keep-tmp-files --no-hw-accel
COMMAND ./megahit --test -t 2 --keep-tmp-files --kmin-1pass
)

add_dependencies(megahit megahit_core)
add_dependencies(megahit megahit_core megahit_core_no_hw_accel)
add_dependencies(simple_test megahit)

install(TARGETS megahit_core DESTINATION bin)
install(TARGETS megahit_core megahit_core_no_hw_accel DESTINATION bin)
install(PROGRAMS src/megahit DESTINATION bin)
install(DIRECTORY test_data DESTINATION share/${PROJECT_NAME})
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ WORKDIR build
RUN cmake -DCMAKE_BUILD_TYPE=Release ..
RUN make -j4
RUN make install
RUN megahit --test --no-hw-accel
RUN megahit --test --no-hw-accel --kmin-1pass
12 changes: 0 additions & 12 deletions DockerfileNoBMI2

This file was deleted.

85 changes: 32 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,97 +1,76 @@
MEGAHIT
=======

[![BioConda Install](https://img.shields.io/conda/dn/bioconda/megahit.svg?style=flag&label=BioConda%20install)](https://anaconda.org/bioconda/megahit)
[![Build Status](https://travis-ci.org/voutcn/megahit.svg?branch=master)](https://travis-ci.org/voutcn/megahit)
[![codecov](https://codecov.io/gh/voutcn/megahit/branch/master/graph/badge.svg)](https://codecov.io/gh/voutcn/megahit)
[![BioConda Install](https://img.shields.io/conda/dn/bioconda/megahit.svg?style=flag&label=BioConda%20install)](https://anaconda.org/bioconda/megahit) [![Build Status](https://travis-ci.org/voutcn/megahit.svg?branch=master)](https://travis-ci.org/voutcn/megahit) [![codecov](https://codecov.io/gh/voutcn/megahit/branch/master/graph/badge.svg)](https://codecov.io/gh/voutcn/megahit)

MEGAHIT is an ultra-fast and memory-efficient NGS assembler. It is optimized for metagenomes, but also works well on generic single genome assembly (small or mammalian size) and single-cell assembly.

*News*
*News: try v1.2.x!*
------

MEGAHIT v1.2.0-beta is released. Main changes include
MEGAHIT v1.2.x (beta) is released. Compared to v1.1.x, its changes include

- faster and more memory-efficient than before, by using [BMI2 instructions](https://en.wikipedia.org/wiki/Bit_Manipulation_Instruction_Sets), [sparsepp](https://github.com/greg7mdp/sparsepp) and [xxhash](https://github.com/Cyan4973/xxHash)
- refactored with C++11 features
- use CMake to build the project
- removal of GPU support

It is highly recommended to use v1.2.0-beta. Past versions can be found at the [release](https://github.com/voutcn/megahit/releases) page.
Please follow the instructions in [Getting Started](#gst) to try this new version.
Past versions can be found at the [release](https://github.com/voutcn/megahit/releases) page.

Getting Started
<a name="gst"></a>Getting Started
---------------

### Run with docker (recommended)
### Running with Linux binaries or docker images (recommended)

``` bash
# in the directory with your input reads
docker run -v $(pwd):/workspace -w /workspace --user $(id -u):$(id -g) vout/megahit \
megahit -1 YOUR_PE_READ_1.gz -2 YOUR_PE_READ_2.fq.gz -o YOUR_OUTPUT_DIR
``` sh
https://github.com/voutcn/megahit/releases/download/v1.2.1-beta/MEGAHIT-1.2.1-beta-Linux-static.tar.gz
tar zvxf MEGAHIT-1.2.1-beta-Linux-static
cd MEGAHIT-1.2.1-beta-Linux-static/bin/
./megahit --test # run on a toy dataset
./megahit -1 YOUR_PE_READ_1.gz -2 YOUR_PE_READ_2.fq.gz -o YOUR_OUTPUT_DIR
```

If your CPU does not support BMI2 or POPCNT instructions (typically you will see exit code -4), please use the docker images from `vout/megahit-no-popcnt-bmi2`. i.e.
If your CPU does not support BMI2 and/or POPCNT, you may see "exit code -4". In this case, run MEGAHIT with `--no-hw-accel` option.

``` bash
You can also run MEGAHIT with its docker images.

``` sh
# in the directory with your input reads
docker run -v $(pwd):/workspace -w /workspace --user $(id -u):$(id -g) vout/megahit-no-popcnt-bmi2 \
docker run -v $(pwd):/workspace -w /workspace --user $(id -u):$(id -g) vout/megahit \
megahit -1 YOUR_PE_READ_1.gz -2 YOUR_PE_READ_2.fq.gz -o YOUR_OUTPUT_DIR
```

### Build from source
### Building from source

#### Prerequisites

- For building: zlib, cmake, gcc/g++ &gt;= 5
- For building: zlib, cmake &gt;= 2.8, g++ &gt;= 4.8.4
- For running: gzip and bzip2

#### Build and test

1. Obtain the source code

``` bash
git clone https://github.com/voutcn/megahit.git
cd megahit
git submodule update --init
```

2. Create the build directory

``` bash
mkdir build && cd build
```

3. Run cmake

``` bash
cmake -DCMAKE_BUILD_TYPE=release ..
```

If your CPU does not support BMI2 instructions (uncommon), run the following command instead

cmake -DUSE_BMI2=OFF -DCMAKE_BUILD_TYPE=release ..

4. Compile & test

``` bash
make -j4
make simple_test # will test MEGAHIT with a toy dataset
```

If you need to install Megahit to your PATH, run `make install` in the build directory.
``` sh
git clone https://github.com/voutcn/megahit.git
cd megahit
git submodule update --init
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release # add -DCMAKE_INSTALL_PREFIX=YOUR_PREFIX if needed
make -j4
make simple_test # will test MEGAHIT with a toy dataset
# make install if needed
```

Usage
-----

To run MEGAHIT with default parameters:

``` bash
``` sh
megahit -1 YOUR_PE_READ_1.fq.gz -2 YOUR_PE_READ_2.fq.gz -r YOUR_SE_READ.fq.gz -o YOUR_OUTPUT_DIR
```

If you did not install Megahit to your PATH, just run Megahit with full-path, e.g.

``` bash
``` sh
/PATH/TO/MEGAHIT/build/megahit
```

Expand Down
3 changes: 2 additions & 1 deletion src/assembly/low_depth_remover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ bool RemoveLocalLowDepth(UnitigGraph &graph, double min_depth, uint32_t max_len,
bool permanent_rm, uint32_t *num_removed) {
bool is_changed = false;
bool need_refresh = false;
auto &removed = *num_removed;
uint32_t removed = 0;

#pragma omp parallel for reduction(+: removed)
for (UnitigGraph::size_type i = 0; i < graph.size(); ++i) {
Expand Down Expand Up @@ -79,6 +79,7 @@ bool RemoveLocalLowDepth(UnitigGraph &graph, double min_depth, uint32_t max_len,
bool set_changed = !permanent_rm;
graph.Refresh(set_changed);
}
*num_removed = removed;
return is_changed;
}

Expand Down
2 changes: 1 addition & 1 deletion src/definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <stdint.h>

#ifndef PACKAGE_VERSION
#define PACKAGE_VERSION "v1.2.0-beta"
#define PACKAGE_VERSION "v1.2.1-beta"
#endif

#include "sdbg/sdbg_def.h"
Expand Down
Loading

0 comments on commit 99bae17

Please sign in to comment.