Skip to content

Commit 8d78cb7

Browse files
committed
seqan3 → biocpp step1
1 parent 6803641 commit 8d78cb7

20 files changed

Lines changed: 299 additions & 591 deletions

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@
1010
[submodule "submodules/sharg-parser"]
1111
path = submodules/sharg-parser
1212
url = ../../seqan/sharg-parser
13+
[submodule "submodules/biocpp-core"]
14+
path = submodules/biocpp-core
15+
url = ../../biocpp/biocpp-core
16+
[submodule "submodules/biocpp-io"]
17+
path = submodules/biocpp-io
18+
url = ../../biocpp/biocpp-io

src/CMakeLists.txt

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,21 @@ find_package(BZip2 QUIET)
7070
find_package(SeqAn QUIET REQUIRED CONFIG)
7171
find_package(SeqAn3 QUIET REQUIRED CONFIG)
7272

73+
# BIO
74+
find_package (biocpp COMPONENTS core io QUIET REQUIRED HINTS "${CMAKE_SOURCE_DIR}/submodules/biocpp-core/build_system")
75+
7376
# SHARG
7477
find_package (sharg QUIET REQUIRED HINTS "${CMAKE_SOURCE_DIR}/submodules/sharg-parser/build_system")
7578

7679
message(STATUS "These dependencies were found:")
77-
message( " OPENMP ${OPENMP_FOUND} ${OpenMP_CXX_FLAGS}")
78-
message( " ZLIB ${ZLIB_FOUND} ${ZLIB_VERSION_STRING}")
79-
message( " BZIP2 ${BZIP2_FOUND} ${BZIP2_VERSION_STRING}")
80-
message( " SEQAN ${SEQAN_FOUND} ${SEQAN_VERSION_STRING}")
81-
message( " SEQAN3 ${SEQAN3_FOUND} ${SEQAN3_VERSION}")
82-
message( " SHARG ${SHARG_FOUND} ${SHARG_VERSION}")
80+
message( " BIOCPP-CORE ${BIOCPP_CORE_FOUND} ${BIOCPP_CORE_VERSION}")
81+
message( " BIOCPP-IO ${BIOCPP_IO_FOUND} ${BIOCPP_IO_VERSION}")
82+
message( " OPENMP ${OPENMP_FOUND} ${OpenMP_CXX_FLAGS}")
83+
message( " ZLIB ${ZLIB_FOUND} ${ZLIB_VERSION_STRING}")
84+
message( " BZIP2 ${BZIP2_FOUND} ${BZIP2_VERSION_STRING}")
85+
message( " SEQAN ${SEQAN_FOUND} ${SEQAN_VERSION_STRING}")
86+
message( " SEQAN3 ${SEQAN3_FOUND} ${SEQAN3_VERSION}")
87+
message( " SHARG ${SHARG_FOUND} ${SHARG_VERSION}")
8388

8489
# Warn if Zlib was not found.
8590
if (NOT ZLIB_FOUND)
@@ -123,9 +128,12 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
123128
include(ProcessorCount)
124129
ProcessorCount(LAMBDA_COMPILE_THREADS)
125130
endif ()
126-
if (LAMBDA_COMPILE_THREADS GREATER 1)
127-
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto=${LAMBDA_COMPILE_THREADS}")
128-
endif()
131+
# if (LAMBDA_COMPILE_THREADS GREATER 4)
132+
# set (LAMBDA_COMPILE_THREADS 4)
133+
# endif ()
134+
# if (LAMBDA_COMPILE_THREADS GREATER 1)
135+
# set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto=${LAMBDA_COMPILE_THREADS}")
136+
# endif()
129137

130138
# strip binaries to make them smaller
131139
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s")
@@ -160,7 +168,7 @@ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SEQAN_CXX_FLAGS} -Wall -pedantic")
160168
set (LAMBDA_SOURCE_FILES lambda.cpp search.cpp mkindex.cpp)
161169

162170
add_executable (lambda3 ${LAMBDA_SOURCE_FILES})
163-
target_link_libraries (lambda3 ${SEQAN_LIBRARIES} seqan3::seqan3 fmindex-collection)
171+
target_link_libraries (lambda3 ${SEQAN_LIBRARIES} seqan3::seqan3 fmindex-collection sharg::sharg biocpp::core biocpp::io)
164172
set_target_properties (lambda3 PROPERTIES COMPILE_FLAGS "-mmmx -msse -msse2 -msse3 -mssse3 -msse4 -mpopcnt")
165173

166174
# ----------------------------------------------------------------------------

src/bisulfite_scoring.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
#include <seqan/sequence.h>
2626

2727
#include <algorithm>
28+
#include <bio/alphabet/nucleotide/dna5.hpp>
2829
#include <seqan3/alignment/scoring/scoring_scheme_base.hpp>
29-
#include <seqan3/alphabet/nucleotide/dna5.hpp>
3030

3131
enum class bsDirection
3232
{
@@ -36,17 +36,17 @@ enum class bsDirection
3636

3737
template <seqan3::arithmetic score_type = int8_t>
3838
class bisulfite_scoring_scheme :
39-
public seqan3::scoring_scheme_base<bisulfite_scoring_scheme<score_type>, seqan3::dna5, score_type>
39+
public seqan3::scoring_scheme_base<bisulfite_scoring_scheme<score_type>, bio::alphabet::dna5, score_type>
4040
{
4141
private:
42-
using base_t = seqan3::scoring_scheme_base<bisulfite_scoring_scheme<score_type>, seqan3::dna5, score_type>;
42+
using base_t = seqan3::scoring_scheme_base<bisulfite_scoring_scheme<score_type>, bio::alphabet::dna5, score_type>;
4343
using base_t::matrix;
4444

4545
public:
4646
using base_t::base_t;
4747
using typename base_t::matrix_type;
48-
using matrix_size_type = std::remove_const_t<decltype(seqan3::alphabet_size<seqan3::dna5>)>;
49-
static constexpr matrix_size_type matrix_size = seqan3::alphabet_size<seqan3::dna5>;
48+
using matrix_size_type = std::remove_const_t<decltype(bio::alphabet::size<bio::alphabet::dna5>)>;
49+
static constexpr matrix_size_type matrix_size = bio::alphabet::size<bio::alphabet::dna5>;
5050

5151
constexpr bisulfite_scoring_scheme() noexcept {}
5252

src/holder_tristate_overload.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@
3737
#pragma once
3838

3939
#include <seqan/basic.h>
40+
#include <bio/ranges/views/slice.hpp>
41+
#include <bio/ranges/views/translate_single.hpp>
4042

41-
using overload_t = std::ranges::take_view<std::ranges::drop_view<seqan3::detail::view_translate_single<std::ranges::ref_view<std::vector<seqan3::dna5>>>>>;
43+
using overload_t = decltype(std::declval<std::vector<bio::alphabet::dna5> &>() | bio::views::translate_single | bio::views::slice(0,1));
44+
// std::ranges::take_view<std::ranges::drop_view<bio::ranges::detail::view_translate_single<std::ranges::ref_view<std::vector<bio::alphabet::dna5>>>>>;
4245

4346
template <typename t>
4447
concept overload_c = std::same_as<std::remove_cvref_t<t>, overload_t>;

src/mkindex_algo.hpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@
2727
#include <fmindex-collection/fmindex-collection.h>
2828
#include <fmindex-collection/occtable/all.h>
2929

30-
#include <seqan3/alphabet/views/to_rank.hpp>
31-
#include <seqan3/alphabet/views/translate.hpp>
32-
#include <seqan3/alphabet/views/translate_join.hpp>
30+
#include <bio/io/seq/reader.hpp>
31+
#include <bio/ranges/to.hpp>
32+
#include <bio/ranges/views/convert.hpp>
33+
#include <bio/ranges/views/to_rank.hpp>
34+
#include <bio/ranges/views/translate.hpp>
35+
#include <bio/ranges/views/translate_join.hpp>
3336
#include <seqan3/io/detail/misc_input.hpp>
34-
#include <seqan3/io/sequence_file/input.hpp>
35-
#include <seqan3/utility/views/convert.hpp>
3637

3738
#include "mkindex_misc.hpp"
3839
// #include "mkindex_saca.hpp"
@@ -119,24 +120,23 @@ auto loadSubjSeqsAndIds(LambdaIndexerOptions const & options)
119120
double start = sysTime();
120121
myPrint(options, 1, "Loading Subject Sequences and Ids...");
121122

122-
using seq_traits = std::conditional_t<seqan3::nucleotide_alphabet<TOrigAlph>,
123-
seqan3::sequence_file_input_default_traits_dna,
124-
seqan3::sequence_file_input_default_traits_aa>;
125-
seqan3::sequence_file_input<seq_traits, seqan3::fields<seqan3::field::id, seqan3::field::seq>> infile{
126-
options.dbFile};
123+
bio::io::seq::record r{.id = std::string_view{},
124+
.seq = bio::ranges::views::char_conversion_view_t<TOrigAlph>{},
125+
.qual = std::ignore};
126+
bio::io::seq::reader reader{
127+
options.dbFile,
128+
bio::io::seq::reader_options{.record = r, .truncate_ids = options.truncateIDs}
129+
};
127130

128131
size_t count = 0;
129-
for (auto & [id, seq] : infile)
132+
for (auto & [id, seq, qual] : reader)
130133
{
131134
if (options.hasSTaxIds)
132135
extractAccIds(id, count);
133136

134-
if (options.truncateIDs)
135-
ids.push_back(id | seqan3::detail::take_until(seqan3::is_space) | seqan3::ranges::to<std::string>());
136-
else
137-
ids.push_back(std::move(id));
137+
ids.push_back(id);
138138

139-
originalSeqs.push_back(std::move(seq));
139+
originalSeqs.push_back(seq);
140140
++count;
141141
}
142142

@@ -301,7 +301,7 @@ auto mapTaxIDs(std::unordered_map<std::string, uint64_t> const & accToIdRank,
301301
// transparent decompressor
302302
auto vstream = seqan3::detail::make_secondary_istream(fin);
303303

304-
// TODO: use seqan3::views::istreambuf instead, it's faster
304+
// TODO: use bio::views::istreambuf instead, it's faster
305305
auto file_view = std::ranges::subrange<std::istreambuf_iterator<char>, std::istreambuf_iterator<char>>{
306306
std::istreambuf_iterator<char>{*vstream},
307307
std::istreambuf_iterator<char>{}};
@@ -397,7 +397,7 @@ auto parseAndStoreTaxTree(std::vector<bool> & taxIdIsPresent, LambdaIndexerOptio
397397
// transparent decompressor
398398
auto vstream = seqan3::detail::make_secondary_istream(fin);
399399

400-
// TODO: use seqan3::views::istreambuf instead, it's faster
400+
// TODO: use bio::views::istreambuf instead, it's faster
401401
auto file_view = std::ranges::subrange<std::istreambuf_iterator<char>, std::istreambuf_iterator<char>>{
402402
std::istreambuf_iterator<char>{*vstream},
403403
std::istreambuf_iterator<char>{}};
@@ -412,7 +412,7 @@ auto parseAndStoreTaxTree(std::vector<bool> & taxIdIsPresent, LambdaIndexerOptio
412412
while (std::ranges::begin(file_view) != std::ranges::end(file_view))
413413
{
414414
// read line
415-
buf = file_view | std::views::take_while(not_eol) | seqan3::ranges::to<std::string>();
415+
buf = file_view | std::views::take_while(not_eol) | bio::ranges::to<std::string>();
416416

417417
uint32_t n = 0;
418418
uint32_t parent = 0;
@@ -603,7 +603,7 @@ auto parseAndStoreTaxTree(std::vector<bool> & taxIdIsPresent, LambdaIndexerOptio
603603
while (std::ranges::begin(file_view2) != std::ranges::end(file_view2))
604604
{
605605
// read line
606-
buf = file_view2 | std::views::take_while(not_eol) | seqan3::ranges::to<std::string>();
606+
buf = file_view2 | std::views::take_while(not_eol) | bio::ranges::to<std::string>();
607607

608608
uint32_t taxId = 0;
609609

@@ -668,15 +668,15 @@ auto parseAndStoreTaxTree(std::vector<bool> & taxIdIsPresent, LambdaIndexerOptio
668668
template <bool is_bi, typename TStringSet>
669669
auto generateIndex(TStringSet & seqs, LambdaIndexerOptions const & options)
670670
{
671-
using TRedAlph = seqan3::range_innermost_value_t<TStringSet>;
672-
using TIndexSpec = IndexSpec<seqan3::alphabet_size<TRedAlph>>;
671+
using TRedAlph = bio::ranges::range_innermost_value_t<TStringSet>;
672+
using TIndexSpec = IndexSpec<bio::alphabet::size<TRedAlph>>;
673673
using TIndex = std::
674674
conditional_t<is_bi, fmindex_collection::BiFMIndex<TIndexSpec>, fmindex_collection::ReverseFMIndex<TIndexSpec>>;
675675

676676
myPrint(options, 1, "Generating Index...");
677677
double s = sysTime();
678678

679-
TIndex index{seqs | seqan3::views::to_rank | fmindex_collection::add_sentinels, 5};
679+
TIndex index{seqs | bio::views::to_rank | fmindex_collection::add_sentinels, 5};
680680

681681
double e = sysTime() - s;
682682
myPrint(options, 1, " done.\n");

src/mkindex_misc.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121

2222
#pragma once
2323

24+
#include <bio/ranges/to.hpp>
2425
#include <seqan3/core/range/detail/misc.hpp> // seqan3::detail::consume
2526
#include <seqan3/utility/char_operations/predicate.hpp>
2627

27-
inline constexpr auto not_eol = !(seqan3::is_char<'\r'> || seqan3::is_char<'\n'>);
28+
inline constexpr auto not_eol = !(bio::io::is_char<'\r'> || bio::io::is_char<'\n'>);
2829

2930
bool setEnv(std::string const & key, std::string const & value)
3031
{
@@ -55,21 +56,21 @@ void _readMappingFileUniProt(TInputView & f
5556
while (std::ranges::begin(fiv) != std::ranges::end(fiv))
5657
{
5758
// read accession number
58-
acc = fiv | std::views::take_while(!seqan3::is_blank) | seqan3::ranges::to<std::string>(); //TODO and_consume
59+
acc = fiv | std::views::take_while(!bio::io::is_blank) | bio::ranges::to<std::string>(); //TODO and_consume
5960
// skip whitespace
60-
seqan3::detail::consume(fiv | std::views::take_while(!seqan3::is_alnum));
61+
seqan3::detail::consume(fiv | std::views::take_while(!bio::io::is_alnum));
6162
// read accession number
6263
nextColumn =
63-
fiv | std::views::take_while(!seqan3::is_blank) | seqan3::ranges::to<std::string>(); //TODO and_consume
64+
fiv | std::views::take_while(!bio::io::is_blank) | bio::ranges::to<std::string>(); //TODO and_consume
6465

6566
if ((nextColumn == "NCBI_TaxID") && (accToIdRank.count(acc) == 1))
6667
{
6768
auto & sTaxIdV = sTaxIds[accToIdRank.at(acc)];
6869
// skip whitespace
69-
seqan3::detail::consume(fiv | std::views::take_while(!seqan3::is_alnum));
70+
seqan3::detail::consume(fiv | std::views::take_while(!bio::io::is_alnum));
7071
// read tax id
7172
nextColumn =
72-
fiv | std::views::take_while(!seqan3::is_space) | seqan3::ranges::to<std::string>(); //TODO and_consume
73+
fiv | std::views::take_while(!bio::io::is_space) | bio::ranges::to<std::string>(); //TODO and_consume
7374

7475
uint32_t idNum = 0;
7576
auto [p, ec] = std::from_chars(nextColumn.data(), nextColumn.data() + nextColumn.size(), idNum);
@@ -105,20 +106,19 @@ void _readMappingFileNCBI(TInputView & fiv,
105106
while (std::ranges::begin(fiv) != std::ranges::end(fiv))
106107
{
107108
// read accession number
108-
buf = fiv | std::views::take_while(!seqan3::is_blank) | seqan3::ranges::to<std::string>(); //TODO and_consume
109+
buf = fiv | std::views::take_while(!bio::io::is_blank) | bio::ranges::to<std::string>(); //TODO and_consume
109110
// we have a sequence with this ID in our database
110111
if (accToIdRank.count(buf) == 1)
111112
{
112113
auto & sTaxIdV = sTaxIds[accToIdRank.at(buf)];
113114
// skip whitespace
114-
seqan3::detail::consume(fiv | std::views::take_while(!seqan3::is_alnum));
115+
seqan3::detail::consume(fiv | std::views::take_while(!bio::io::is_alnum));
115116
// skip versioned acc
116-
seqan3::detail::consume(fiv | std::views::take_while(!seqan3::is_blank));
117+
seqan3::detail::consume(fiv | std::views::take_while(!bio::io::is_blank));
117118
// skip whitespace
118-
seqan3::detail::consume(fiv | std::views::take_while(!seqan3::is_alnum));
119+
seqan3::detail::consume(fiv | std::views::take_while(!bio::io::is_alnum));
119120
// read tax id
120-
buf =
121-
fiv | std::views::take_while(!seqan3::is_blank) | seqan3::ranges::to<std::string>(); //TODO and_consume
121+
buf = fiv | std::views::take_while(!bio::io::is_blank) | bio::ranges::to<std::string>(); //TODO and_consume
122122

123123
uint32_t idNum = 0;
124124
auto [p, ec] = std::from_chars(buf.data(), buf.data() + buf.size(), idNum);

src/search.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,12 @@ void realMain(LambdaOptions const & options)
351351

352352
uint64_t lastPercent = 0;
353353

354-
typename TGlobalHolder::TQueryFile infile{options.queryFile};
355-
auto file_view = infile | seqan3::views::async_input_buffer(globalHolder.records_per_batch * options.threads);
354+
bio::io::seq::record r{.id = std::string{},
355+
.seq = std::vector<typename TGlobalHolder::TOrigQryAlph>{},
356+
.qual = std::ignore};
357+
bio::io::seq::reader reader{options.queryFile, bio::io::seq::reader_options{.record = r}};
358+
359+
auto file_view = reader | seqan3::views::async_input_buffer(globalHolder.records_per_batch * options.threads);
356360

357361
SEQAN_OMP_PRAGMA(parallel)
358362
{
@@ -365,7 +369,7 @@ void realMain(LambdaOptions const & options)
365369
localHolder.reset();
366370

367371
// load records until batch is full or file at end
368-
for (auto & [id, seq] : file_view)
372+
for (auto & [id, seq, qual] : file_view)
369373
{
370374
localHolder.qryIds.push_back(std::move(id));
371375
localHolder.qrySeqs.push_back(std::move(seq));

0 commit comments

Comments
 (0)