Skip to content

Commit

Permalink
fix boost link issue
Browse files Browse the repository at this point in the history
format
  • Loading branch information
yangli committed Sep 16, 2022
1 parent fa64404 commit 0242eac
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 42 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ on:
branches:
- main
- release*
- master
pull_request:
branches:
- main
- master
- release*

env:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
[![License](https://img.shields.io/github/license/ylab-hi/BINARY)](https://github.com/cauliyang/boss/blob/main/LICENSE)
![compiler](https://img.shields.io/badge/Compiler-GCC10%20%7C%20GCC11%20%7C%20GCC12-green)

# BioinfOrmaticS toolboxeS aka BOSS
# **B**ioinf**O**rmatic**S** toolboxe**S** aka **BOSS**

## Current Tools

| Tool | Description | Status |
|-------------------------|-------------------------------------|----------------------------------------------------------------|
| [boss-fqsp](#boss-fqsp) | Fastq Splitter for Paried End Reads | ![boss-fqsp](https://img.shields.io/badge/Version-1.0.0-green) |
| [boss-fqsp](#boss-fqsp) | Fastq Splitter for Paired End Reads | ![boss-fqsp](https://img.shields.io/badge/Version-1.0.0-green) |

## Usage

Expand Down
13 changes: 5 additions & 8 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
)
endif()

option(BOSS_HAS_BOOST "Do not download Boost" OFF)

message(STATUS "Started CMake for ${PROJECT_NAME} v${PROJECT_VERSION}...")
message(STATUS "Compiler name: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
message(STATUS "Cmake Binary path: ${CMAKE_BINARY_DIR}")
message(STATUS "BOSS has boost: ${BOSS_HAS_BOOST}")

# ---- Add dependencies via CPM ----
# see https://github.com/TheLartians/CPM.cmake for more info
Expand All @@ -30,14 +33,8 @@ include(../cmake/CPM.cmake)
# PackageProject.cmake will be used to make our target installable
CPMAddPackage("gh:TheLartians/[email protected]")

CPMAddPackage(
NAME spdlog
GITHUB_REPOSITORY gabime/spdlog
VERSION 1.10.0
OPTIONS "SPDLOG_INSTALL YES"
)

find_package(Boost REQUIRED)

# ---- Add source files ----

# Note: globbing sources is considered bad practice as CMake's generators may not detect new files
Expand All @@ -56,7 +53,7 @@ set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 20)
target_compile_options(${PROJECT_NAME} PUBLIC "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/permissive->")

# Link dependencies
target_link_libraries(${PROJECT_NAME} PUBLIC spdlog::spdlog Boost::boost)
target_link_libraries(${PROJECT_NAME} PUBLIC spdlog::spdlog Boost::boost boost_iostreams)

target_include_directories(
${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/../include>
Expand Down
63 changes: 59 additions & 4 deletions include/boss/fq_utils.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
#ifndef FQ_UTILS_H
#define FQ_UTILS_H

#include <spdlog/spdlog.h>

#include <boost/iostreams/categories.hpp> // input_filter_tag
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/device/file.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/operations.hpp> // get, put, WOULD_BLOCK
#include <cstdio> // EOF.
#include <filesystem>

namespace boss {
namespace boss::fqsp {

namespace fs = std::filesystem;
enum class FqDirection;
class fq_filter;

enum class FqDirection { Forward, Reverse };

Expand Down Expand Up @@ -62,10 +71,56 @@ namespace boss {
int saved_line_count_{0};
};

//--------------Definitions of helper functions for splitting ncbi fq files----//
namespace details {

struct txt_tag {};
struct gzip_tag : txt_tag {};
struct bzip2_tag : txt_tag {};

txt_tag format_category(std::string_view path) {
if (path.ends_with(".gz")) {
return gzip_tag{};
} else if (path.ends_with(".bz2")) {
return bzip2_tag{};
} else {
return txt_tag{};
}
}

//----------------------------Define helper functions---------------------------//
void split_fq_impl(const fs::path& input, FqDirection direction, gzip_tag) {
boost::iostreams::filtering_istream in;
in.push(fq_filter(direction));
in.push(boost::iostreams::gzip_decompressor());
in.push(boost::iostreams::file_source(input, std::ios_base::in | std::ios_base::binary));

std::ofstream out{fmt::format("{}{}{}", input.stem().string(),
direction == FqDirection::Forward ? "1" : "2",
input.extension().string())};
boost::iostreams::copy(in, out);
out.close();
}

void split_fq_impl(const fs::path& input, FqDirection direction, txt_tag) {
boost::iostreams::filtering_istream in;
in.push(fq_filter(direction));
in.push(boost::iostreams::file_source(input, std::ios_base::in));
std::ofstream out{fmt::format("{}{}{}", input.stem().string(),
direction == FqDirection::Forward ? "1" : "2",
input.extension().string())};
boost::iostreams::copy(in, out);
out.close();
}

} // namespace details

//--------------Definitions of functions for splitting ncbi fq files----//

[[nodiscard]] bool is_gzip(std::string_view path);
void split_fq(const fs::path& input) {
details::split_fq_impl(input, FqDirection::Forward, details::format_category(input.string()));
details::split_fq_impl(input, FqDirection::Reverse, details::format_category(input.string()));
}

} // namespace boss
} // namespace boss::fqsp

#endif // FQ_UTILS_H
5 changes: 2 additions & 3 deletions source/fq_utils.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

#include <boss/fq_utils.hpp>
namespace boss {

bool is_gzip(std::string_view path) { return path.ends_with(".gz"); }
} // namespace boss
namespace boss::fqsp {} // namespace boss::fqsp
45 changes: 21 additions & 24 deletions standalone/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,37 @@ include(../cmake/tools.cmake)
include(../cmake/CPM.cmake)

CPMAddPackage(
GITHUB_REPOSITORY ylab-hi/BINARY
VERSION 1.1.0
OPTIONS "BINARY_BUILD_STANDALONE NO" "BINARY_BUILD_TESTS NO"
GITHUB_REPOSITORY ylab-hi/BINARY
VERSION 1.1.0
OPTIONS "BINARY_BUILD_STANDALONE NO" "BINARY_BUILD_TESTS NO"
)


CPMAddPackage(
GITHUB_REPOSITORY jarro2783/cxxopts
VERSION 3.0.0
OPTIONS "CXXOPTS_BUILD_EXAMPLES NO" "CXXOPTS_BUILD_TESTS NO" "CXXOPTS_ENABLE_INSTALL YES"
GITHUB_REPOSITORY jarro2783/cxxopts
VERSION 3.0.0
OPTIONS "CXXOPTS_BUILD_EXAMPLES NO" "CXXOPTS_BUILD_TESTS NO" "CXXOPTS_ENABLE_INSTALL YES"
)


CPMAddPackage(NAME BOSS SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../include)

# ---- Create standalone executable ----


function(add_standalone targetName)
message(STATUS "Adding standalone ${targetName}")
file(GLOB ${targetName}_source CONFIGURE_DEPENDS
${CMAKE_CURRENT_LIST_DIR}/${targetName}/source/*.cpp
)
add_executable(${targetName} ${${targetName}_source})
target_compile_features(${targetName} PRIVATE cxx_std_20)
target_link_libraries(${targetName} PRIVATE boss::boss binary cxxopts stdc++fs)
target_include_directories(
${targetName} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include
${CMAKE_CURRENT_LIST_DIR}/${targetName}/include
)
target_compile_options(${targetName} PRIVATE -Wall -Wextra -Wnon-virtual-dtor -pedantic -Werror)
set_target_properties(${targetName} PROPERTIES CXX_EXTENSIONS OFF OUTPUT_NAME boss-${targetName})
message(STATUS "Adding standalone ${targetName}")
file(GLOB ${targetName}_source CONFIGURE_DEPENDS
${CMAKE_CURRENT_LIST_DIR}/${targetName}/source/*.cpp
)
add_executable(${targetName} ${${targetName}_source})
target_compile_features(${targetName} PRIVATE cxx_std_20)
target_link_libraries(${targetName} PRIVATE boss::boss binary cxxopts stdc++fs)
target_include_directories(
${targetName} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include
${CMAKE_CURRENT_LIST_DIR}/${targetName}/include
)
target_compile_options(${targetName} PRIVATE -Wall -Wextra -Wnon-virtual-dtor -pedantic -Werror)
set_target_properties(${targetName} PROPERTIES CXX_EXTENSIONS OFF OUTPUT_NAME boss-${targetName})
endfunction()

#file(GLOB sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp)
# file(GLOB sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp)

add_standalone(fqsp)
add_standalone(fqsp)
4 changes: 3 additions & 1 deletion standalone/fqsp/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ auto main(int argc, char** argv) -> int {
std::exit(1);
}

boss::fqsp::split_fq(fs::path(input));

} catch (const cxxopts::OptionException& e) {
spdlog::error("{}", e.what());
spdlog::error("{}", e.what());
std::exit(1);
}

Expand Down

0 comments on commit 0242eac

Please sign in to comment.