Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
yangli committed Sep 16, 2022
1 parent fce7c31 commit 3d088cc
Show file tree
Hide file tree
Showing 13 changed files with 260 additions and 187 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@
/cpm_modules
.DS_Store
.idea
cmake-*

test/data
cmake-*
54 changes: 31 additions & 23 deletions library/CMakeLists.txt → include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ cmake_minimum_required(VERSION 3.14...3.22)

# Note: update this to your new project's name and version
project(
boss
VERSION 1.0.0
LANGUAGES CXX
boss
VERSION 1.0.0
LANGUAGES CXX
)

# ---- Include guards ----

if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(
FATAL_ERROR
"In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there."
)
endif()
if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(
FATAL_ERROR
"In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there."
)
endif ()

option(BOSS_HAS_BOOST "Do not download Boost" OFF)

Expand All @@ -33,31 +33,39 @@ include(../cmake/CPM.cmake)
# PackageProject.cmake will be used to make our target installable
CPMAddPackage("gh:TheLartians/[email protected]")

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


find_package(Boost REQUIRED COMPONENTS system iostreams)

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

# Note: globbing sources is considered bad practice as CMake's generators may not detect new files
# automatically. Keep that in mind when changing files, or explicitly mention them here.
file(GLOB_RECURSE headers CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp")
file(GLOB_RECURSE sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp")
file(GLOB_RECURSE headers CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/boss/*.hpp")
file(GLOB_RECURSE sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../source/*.cpp")

# ---- Create library ----

# Note: for header-only libraries change all PUBLIC flags to INTERFACE and create an interface
# target: add_library(${PROJECT_NAME} INTERFACE)
add_library(${PROJECT_NAME} ${headers} ${sources})

set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 20)

# being a cross-platform target, we enforce standards conformance on MSVC
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 Boost::iostreams)
target_link_libraries(${PROJECT_NAME} PUBLIC spdlog::spdlog Boost::boost Boost::iostreams binary::binary)

target_include_directories(
${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/../include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
)

# ---- Create an installable target ----
Expand All @@ -68,13 +76,13 @@ target_include_directories(
string(TOLOWER ${PROJECT_NAME}/version.h VERSION_HEADER_LOCATION)

packageProject(
NAME ${PROJECT_NAME}
VERSION ${PROJECT_VERSION}
NAMESPACE ${PROJECT_NAME}
BINARY_DIR ${PROJECT_BINARY_DIR}
INCLUDE_DIR include
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
VERSION_HEADER "${VERSION_HEADER_LOCATION}"
COMPATIBILITY SameMajorVersion
DEPENDENCIES "spdlog 1.10.0"
NAME ${PROJECT_NAME}
VERSION ${PROJECT_VERSION}
NAMESPACE ${PROJECT_NAME}
BINARY_DIR ${PROJECT_BINARY_DIR}
INCLUDE_DIR .
INCLUDE_DESTINATION ../include/${PROJECT_NAME}-${PROJECT_VERSION}
VERSION_HEADER "${VERSION_HEADER_LOCATION}"
COMPATIBILITY SameMajorVersion
DEPENDENCIES "spdlog 1.10.0"
)
83 changes: 83 additions & 0 deletions include/boss/fq_utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#ifndef FQ_UTILS_H
#define FQ_UTILS_H

#include <spdlog/spdlog.h>

#include <boost/iostreams/categories.hpp> // input_filter_tag
#include <boost/iostreams/operations.hpp> // get, put, WOULD_BLOCK
#include <cstdio> // EOF.
#include <filesystem>

namespace boss::fqsp {

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

enum class FqDirection { Forward, Reverse };

//--------------Definitions of fq input filter for splitting ncbi fq files----//
class fq_filter {
public:
using char_type = char;
using category = boost::iostreams::input_filter_tag;

explicit constexpr fq_filter(FqDirection direction) : direction_(direction) {}

template <typename Source> int get(Source& src) {
int c;
while ((c = boost::iostreams::get(src)) != EOF && c != boost::iostreams::WOULD_BLOCK
&& is_skip(c))
;

return get_char(c);
}

private:
int get_char(int c) {
++saved_line_count_;
return c;
}

[[nodiscard]] bool is_skip(int c) {
if (c == '\n') {
++line_count_; // count lines 0-based index
if(saved_line_count_ == 0) return true;
}

if (FqDirection::Forward == direction_) {
// forward reads : first 4 lines block start
return 1 == ((line_count_ >> 2) & 1);
} else {
// reverse reads : second 4 lines block start
return 0 == ((line_count_ >> 2) & 1);
}
}

FqDirection direction_;
// line_count_ starts at 1 b
// Max line_count_ is 2^64 - 1 = 18,446,744,073,709,551,615
uint64_t line_count_{0};
uint64_t saved_line_count_{0};
};

namespace details {

//----------------------------Define helper functions---------------------------//
[[nodiscard]] bool is_gzip(const fs::path& input);

void split_fq_impl_gz(const fs::path& input, FqDirection direction);

void split_fq_impl_txt(const fs::path& input, FqDirection direction);

} // namespace details

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

void split_fq(const fs::path& input);
void test_gz_read(const fs::path& path);
void test_gz_write(const fs::path& path);

} // namespace boss::fqsp

#endif // FQ_UTILS_H
126 changes: 0 additions & 126 deletions library/include/boss/fq_utils.hpp

This file was deleted.

4 changes: 0 additions & 4 deletions library/source/fq_utils.cpp

This file was deleted.

Loading

0 comments on commit 3d088cc

Please sign in to comment.