From 797b2b390b945b589a226fd37283795d163e2875 Mon Sep 17 00:00:00 2001 From: Evelin Aasna Date: Mon, 15 May 2023 13:26:44 +0200 Subject: [PATCH 01/20] Sequence import header --- include/stellar/app/stellar.main.tpp | 153 +---------------- include/stellar/io/import_sequence.hpp | 161 ++++++++++++++++++ .../stellar/stellar_import_sequence_test.cpp | 10 +- 3 files changed, 167 insertions(+), 157 deletions(-) create mode 100644 include/stellar/io/import_sequence.hpp diff --git a/include/stellar/app/stellar.main.tpp b/include/stellar/app/stellar.main.tpp index d786ec905..4222cf30e 100644 --- a/include/stellar/app/stellar.main.tpp +++ b/include/stellar/app/stellar.main.tpp @@ -31,6 +31,7 @@ #include +#include #include #include #include @@ -376,158 +377,6 @@ _stellarMain( return true; } -template -inline bool -_checkUniqueId(std::set & uniqueIds, TId const & id) -{ - TId shortId; - typedef typename Iterator::Type TIterator; - - TIterator it = begin(id); - TIterator itEnd = end(id); - - // (cut at first whitespace) - while (it != itEnd && *it > ' ') - { - appendValue(shortId, *it); - ++it; - } - - if (uniqueIds.count(shortId) == 0) - { - uniqueIds.insert(shortId); - return 1; - } - - return 0; -} - -/////////////////////////////////////////////////////////////////////////////// -// Imports sequences from a file, -// stores them in the StringSet seqs and their identifiers in the StringSet ids -template -inline bool -_importAllSequences(char const * fileName, - CharString const & name, - StringSet & seqs, - StringSet & ids, - TLen & seqLen) -{ - SeqFileIn inSeqs; - if (!open(inSeqs, fileName)) - { - std::cerr << "Failed to open " << name << " file." << std::endl; - return false; - } - - std::set uniqueIds; // set of short IDs (cut at first whitespace) - bool idsUnique = true; - - TSequence seq; - TId id; - size_t seqCount{0}; - for (; !atEnd(inSeqs); ++seqCount) - { - readRecord(id, seq, inSeqs); - - if (name == "database") - seqLen += length(seq); - - idsUnique &= _checkUniqueId(uniqueIds, id); - - appendValue(seqs, seq, Generous()); - appendValue(ids, id, Generous()); - } - - std::cout << "Loaded " << seqCount << " " << name << " sequence" << ((seqCount > 1) ? "s." : ".") << std::endl; - if (!idsUnique) - std::cerr << "WARNING: Non-unique " << name << " ids. Output can be ambiguous.\n"; - return true; -} - -/////////////////////////////////////////////////////////////////////////////// -// Imports the sequence of interest from a file, -// stores it in the StringSet seqs and their identifiers in the StringSet ids -template -inline bool -_importSequencesOfInterest(char const * fileName, - std::vector const & binSequences, - StringSet & seqs, - StringSet & ids, - TLen & seqLen) -{ - SeqFileIn inSeqs; - if (!open(inSeqs, fileName)) - { - std::cerr << "Failed to open database file.\n"; - return false; - } - - TSequence seq; - TId id; - size_t seqCount{0}; - size_t foundSeqOfInterest{0}; - for (; !atEnd(inSeqs); ++seqCount) - { - readRecord(id, seq, inSeqs); - seqLen += length(seq); - - if (std::find(binSequences.begin(), binSequences.end(), seqCount) != binSequences.end()) - { - appendValue(seqs, seq, Generous()); - appendValue(ids, id, Generous()); - foundSeqOfInterest++; - std::cout << "Loaded sequence " << id << ".\n"; - } - } - - if (foundSeqOfInterest == binSequences.size()) - return true; - - std::cerr << "ERROR: Found " + std::to_string(foundSeqOfInterest) + " out of " + std::to_string(binSequences.size()) + " reference sequences.\n"; - return false; -} - -/////////////////////////////////////////////////////////////////////////////// -// Imports the sequence of interest from a file, -// stores it in the StringSet seqs and their identifiers in the StringSet ids -template -inline bool -_importSequencesOfInterest(const char * fileName, - std::vector const & binSequences, - StringSet & seqs, - StringSet & ids) -{ - SeqFileIn inSeqs; - if (!open(inSeqs, fileName)) - { - std::cerr << "Failed to open database file.\n"; - return false; - } - - TSequence seq; - TId id; - size_t seqCount{0}; - size_t foundSeqOfInterest{0}; - for (; !atEnd(inSeqs); ++seqCount) - { - readRecord(id, seq, inSeqs); - if (std::find(binSequences.begin(), binSequences.end(), seqCount) != binSequences.end()) - { - appendValue(seqs, seq, Generous()); - appendValue(ids, id, Generous()); - std::cout << "Loaded sequence " << id << ".\n"; - foundSeqOfInterest++; - if (foundSeqOfInterest == binSequences.size()) - return true; - } - } - - std::cerr << "ERROR: Found " + std::to_string(foundSeqOfInterest) + " out of " + std::to_string(binSequences.size()) + " reference sequences.\n"; - return false; -} - - /////////////////////////////////////////////////////////////////////////////// // Parses and outputs parameters, calls _stellarMain(). template diff --git a/include/stellar/io/import_sequence.hpp b/include/stellar/io/import_sequence.hpp new file mode 100644 index 000000000..b2f857ddf --- /dev/null +++ b/include/stellar/io/import_sequence.hpp @@ -0,0 +1,161 @@ +#pragma once + +#include + +namespace stellar +{ + +using namespace seqan; + +template +inline bool +_checkUniqueId(std::set & uniqueIds, TId const & id) +{ + TId shortId; + typedef typename Iterator::Type TIterator; + + TIterator it = begin(id); + TIterator itEnd = end(id); + + // (cut at first whitespace) + while (it != itEnd && *it > ' ') + { + appendValue(shortId, *it); + ++it; + } + + if (uniqueIds.count(shortId) == 0) + { + uniqueIds.insert(shortId); + return 1; + } + + return 0; +} + +/////////////////////////////////////////////////////////////////////////////// +// Imports sequences from a file, +// stores them in the StringSet seqs and their identifiers in the StringSet ids +template +inline bool +_importAllSequences(char const * fileName, + CharString const & name, + StringSet & seqs, + StringSet & ids, + TLen & seqLen) +{ + SeqFileIn inSeqs; + if (!open(inSeqs, fileName)) + { + std::cerr << "Failed to open " << name << " file." << std::endl; + return false; + } + + std::set uniqueIds; // set of short IDs (cut at first whitespace) + bool idsUnique = true; + + TSequence seq; + TId id; + size_t seqCount{0}; + for (; !atEnd(inSeqs); ++seqCount) + { + readRecord(id, seq, inSeqs); + + if (name == "database") + seqLen += length(seq); + + idsUnique &= _checkUniqueId(uniqueIds, id); + + appendValue(seqs, seq, Generous()); + appendValue(ids, id, Generous()); + } + + std::cout << "Loaded " << seqCount << " " << name << " sequence" << ((seqCount > 1) ? "s." : ".") << std::endl; + if (!idsUnique) + std::cerr << "WARNING: Non-unique " << name << " ids. Output can be ambiguous.\n"; + return true; +} + +/////////////////////////////////////////////////////////////////////////////// +// Imports the sequence of interest from a file, +// stores it in the StringSet seqs and their identifiers in the StringSet ids +template +inline bool +_importSequencesOfInterest(char const * fileName, + std::vector const & binSequences, + StringSet & seqs, + StringSet & ids, + TLen & seqLen) +{ + SeqFileIn inSeqs; + if (!open(inSeqs, fileName)) + { + std::cerr << "Failed to open database file.\n"; + return false; + } + + TSequence seq; + TId id; + size_t seqCount{0}; + size_t foundSeqOfInterest{0}; + for (; !atEnd(inSeqs); ++seqCount) + { + readRecord(id, seq, inSeqs); + seqLen += length(seq); + + if (std::find(binSequences.begin(), binSequences.end(), seqCount) != binSequences.end()) + { + appendValue(seqs, seq, Generous()); + appendValue(ids, id, Generous()); + foundSeqOfInterest++; + std::cout << "Loaded sequence " << id << ".\n"; + } + } + + if (foundSeqOfInterest == binSequences.size()) + return true; + + std::cerr << "ERROR: Found " + std::to_string(foundSeqOfInterest) + " out of " + std::to_string(binSequences.size()) + " reference sequences.\n"; + return false; +} + +/////////////////////////////////////////////////////////////////////////////// +// Imports the sequence of interest from a file, +// stores it in the StringSet seqs and their identifiers in the StringSet ids +template +inline bool +_importSequencesOfInterest(const char * fileName, + std::vector const & binSequences, + StringSet & seqs, + StringSet & ids) +{ + SeqFileIn inSeqs; + if (!open(inSeqs, fileName)) + { + std::cerr << "Failed to open database file.\n"; + return false; + } + + TSequence seq; + TId id; + size_t seqCount{0}; + size_t foundSeqOfInterest{0}; + for (; !atEnd(inSeqs); ++seqCount) + { + readRecord(id, seq, inSeqs); + if (std::find(binSequences.begin(), binSequences.end(), seqCount) != binSequences.end()) + { + appendValue(seqs, seq, Generous()); + appendValue(ids, id, Generous()); + std::cout << "Loaded sequence " << id << ".\n"; + foundSeqOfInterest++; + if (foundSeqOfInterest == binSequences.size()) + return true; + } + } + + std::cerr << "ERROR: Found " + std::to_string(foundSeqOfInterest) + " out of " + std::to_string(binSequences.size()) + " reference sequences.\n"; + return false; +} + +} // namespace stellar diff --git a/test/api/stellar/stellar_import_sequence_test.cpp b/test/api/stellar/stellar_import_sequence_test.cpp index 480235f30..74c30535c 100644 --- a/test/api/stellar/stellar_import_sequence_test.cpp +++ b/test/api/stellar/stellar_import_sequence_test.cpp @@ -2,7 +2,7 @@ #include -#include +#include using TAlphabet = seqan::Dna5; std::string databaseFile = std::string{DATADIR} + "/multi_seq_ref.fasta"; @@ -13,7 +13,7 @@ TEST(import_sequences, all_sequences) seqan::StringSet databaseIDs; uint64_t refLen{0}; - stellar::app::_importAllSequences(databaseFile.c_str(), "database", databases, databaseIDs, refLen); + stellar::_importAllSequences(databaseFile.c_str(), "database", databases, databaseIDs, refLen); EXPECT_EQ(length(databases), 3u); EXPECT_EQ(databases[0], (seqan::String) {"GATGACTCAGTCTTGTTGATTAGGCACCTCGGTATGTGGGCATTAGGCACATTGCTCTGTTTCTTGAAGT" @@ -49,7 +49,7 @@ TEST(import_sequence_of_interest, first) seqan::StringSet databaseIDs; uint64_t refLen{0}; - stellar::app::_importSequencesOfInterest(databaseFile.c_str(), std::vector{0}, databases, databaseIDs, refLen); + stellar::_importSequencesOfInterest(databaseFile.c_str(), std::vector{0}, databases, databaseIDs, refLen); EXPECT_EQ(length(databases), 1u); EXPECT_EQ(databases[0], (seqan::String) {"GATGACTCAGTCTTGTTGATTAGGCACCTCGGTATGTGGGCATTAGGCACATTGCTCTGTTTCTTGAAGT" @@ -70,7 +70,7 @@ TEST(import_sequence_of_interest, last_two) seqan::StringSet databaseIDs; uint64_t refLen{0}; - stellar::app::_importSequencesOfInterest(databaseFile.c_str(), std::vector{1, 2}, databases, databaseIDs, refLen); + stellar::_importSequencesOfInterest(databaseFile.c_str(), std::vector{1, 2}, databases, databaseIDs, refLen); EXPECT_EQ(length(databases), 2u); EXPECT_EQ(databases[0], (seqan::String) {"ATCTGCCTGGGTGGGGAATTGGGACAACCCTTGGGTTATAGACGTGCTCGTCAAAGGACAAGAGGAAATA" @@ -98,7 +98,7 @@ TEST(import_sequence_of_interest, out_of_range) testing::internal::CaptureStderr(); uint64_t refLen{0}; - stellar::app::_importSequencesOfInterest(databaseFile.c_str(), sequenceIndex, databases, databaseIDs, refLen); + stellar::_importSequencesOfInterest(databaseFile.c_str(), sequenceIndex, databases, databaseIDs, refLen); std::string err = testing::internal::GetCapturedStderr(); EXPECT_EQ(err,std::string("ERROR: Found 0 out of " + std::to_string(sequenceIndex.size()) + " reference sequences.\n")); From 7e9030e23fdfec2035728f13046fba152380b4a8 Mon Sep 17 00:00:00 2001 From: Evelin Aasna Date: Wed, 17 May 2023 11:14:21 +0200 Subject: [PATCH 02/20] Update lib/seqan (seqan2 namespace) --- include/stellar/app/stellar.main.tpp | 6 +- include/stellar/database_id_map.hpp | 14 +-- .../extension/align_banded_nw_best_ends.hpp | 2 +- .../extension_banded_trace_matrix.hpp | 10 +- .../extension/extension_end_position.hpp | 2 +- .../stellar/extension/longest_eps_match.hpp | 2 +- include/stellar/io/import_sequence.hpp | 2 +- include/stellar/options/verifier_options.hpp | 8 +- include/stellar/stellar.hpp | 2 +- include/stellar/stellar_database_segment.hpp | 40 +++++-- include/stellar/stellar_extension.hpp | 2 +- include/stellar/stellar_index.hpp | 16 +-- include/stellar/stellar_output.hpp | 2 +- include/stellar/stellar_query_segment.hpp | 10 +- include/stellar/stellar_query_segment.tpp | 10 +- include/stellar/stellar_sequence_segment.hpp | 10 +- include/stellar/stellar_types.hpp | 4 +- .../verification/detail/all_or_best_local.hpp | 2 +- include/stellar3.arg_parser.hpp | 2 +- include/{shared.hpp => stellar3.shared.hpp} | 0 lib/seqan | 2 +- src/stellar3.arg_parser.cpp | 12 +- .../align_banded_nw_best_ends_test.cpp | 24 ++-- .../extension_banded_trace_matrix_test.cpp | 6 +- .../extension/longest_eps_match_test.cpp | 22 ++-- .../stellar/stellar_database_segment_test.cpp | 108 +++++++++--------- .../stellar/stellar_import_sequence_test.cpp | 30 ++--- test/api/stellar/stellar_index_test.cpp | 66 +++++------ .../stellar/test/alignment_fragment_test.cpp | 16 +-- .../stellar/verification/all_local_test.cpp | 30 ++--- .../stellar/verification/best_local_test.cpp | 30 ++--- .../stellar/test/alignment_fragment.hpp | 4 +- test/include/stellar/test/error_rate.hpp | 2 +- .../stellar/test/fixture/512_simSeq_5e-2.hpp | 2 +- .../stellar/test/prefilter/expect_storage.hpp | 4 +- 35 files changed, 265 insertions(+), 239 deletions(-) rename include/{shared.hpp => stellar3.shared.hpp} (100%) diff --git a/include/stellar/app/stellar.main.tpp b/include/stellar/app/stellar.main.tpp index 4222cf30e..7b277f553 100644 --- a/include/stellar/app/stellar.main.tpp +++ b/include/stellar/app/stellar.main.tpp @@ -46,11 +46,11 @@ namespace stellar { -using namespace seqan; +using namespace seqan2; } // namespace stellar ////////////////////////////////////////////////////////////////////////////// -namespace seqan { +namespace seqan2 { template <> struct FunctorComplement: @@ -63,7 +63,7 @@ struct FunctorComplement: }; -} // namespace seqan +} // namespace seqan2 namespace stellar { diff --git a/include/stellar/database_id_map.hpp b/include/stellar/database_id_map.hpp index a7e2b64ac..8b38ea6db 100644 --- a/include/stellar/database_id_map.hpp +++ b/include/stellar/database_id_map.hpp @@ -6,7 +6,7 @@ namespace stellar { -template +template struct DatabaseIDMap { size_t recordID(StellarDatabaseSegment const & databaseSegment) const @@ -14,10 +14,10 @@ struct DatabaseIDMap return recordID(databaseSegment.underlyingDatabase()); } - size_t recordID(seqan::String const & database) const + size_t recordID(seqan2::String const & database) const { - seqan::String const * begin = &databases[0]; - seqan::String const * current = std::addressof(database); + seqan2::String const * begin = &databases[0]; + seqan2::String const * current = std::addressof(database); return current - begin; } @@ -26,13 +26,13 @@ struct DatabaseIDMap return databaseIDs[recordID]; } - TId const & databaseID(seqan::String const & database) const + TId const & databaseID(seqan2::String const & database) const { return databaseIDs[recordID(database)]; } - seqan::StringSet > const & databases; - seqan::StringSet const & databaseIDs; + seqan2::StringSet > const & databases; + seqan2::StringSet const & databaseIDs; }; } // namespace stellar diff --git a/include/stellar/extension/align_banded_nw_best_ends.hpp b/include/stellar/extension/align_banded_nw_best_ends.hpp index 13e65ace9..e154918b5 100644 --- a/include/stellar/extension/align_banded_nw_best_ends.hpp +++ b/include/stellar/extension/align_banded_nw_best_ends.hpp @@ -5,7 +5,7 @@ namespace stellar { -using namespace seqan; +using namespace seqan2; /////////////////////////////////////////////////////////////////////////////// // Computes the banded alignment matrix and additionally a string with the best diff --git a/include/stellar/extension/extension_banded_trace_matrix.hpp b/include/stellar/extension/extension_banded_trace_matrix.hpp index 1bd75d640..d04d6ce56 100644 --- a/include/stellar/extension/extension_banded_trace_matrix.hpp +++ b/include/stellar/extension/extension_banded_trace_matrix.hpp @@ -56,7 +56,7 @@ struct extension_banded_trace_matrix } // memory region for active row - std::span rowSpan(size_t const row) + std::span rowSpan(size_t const row) { auto [beginRow, endRow] = rowInterval(); if (!(beginRow <= row && row <= endRow)) @@ -73,13 +73,13 @@ struct extension_banded_trace_matrix } // complete underlying data - std::span data() + std::span data() { - seqan::TraceBack & firstValue = *begin(_traceMatrix); + seqan2::TraceBack & firstValue = *begin(_traceMatrix); return {&firstValue, dataSize()}; } - seqan::String & underlyingTraceMatrix() + seqan2::String & underlyingTraceMatrix() { return _traceMatrix; } @@ -151,7 +151,7 @@ struct extension_banded_trace_matrix diagonal_t _lowerDiagonal; diagonal_t _upperDiagonal; - seqan::String _traceMatrix; + seqan2::String _traceMatrix; }; } diff --git a/include/stellar/extension/extension_end_position.hpp b/include/stellar/extension/extension_end_position.hpp index ac0c29256..4d464790b 100644 --- a/include/stellar/extension/extension_end_position.hpp +++ b/include/stellar/extension/extension_end_position.hpp @@ -5,7 +5,7 @@ namespace stellar { -using namespace seqan; +using namespace seqan2; /////////////////////////////////////////////////////////////////////////////// // Container for storing possible end positions in extension of eps-core diff --git a/include/stellar/extension/longest_eps_match.hpp b/include/stellar/extension/longest_eps_match.hpp index 8f907795f..8711f8797 100644 --- a/include/stellar/extension/longest_eps_match.hpp +++ b/include/stellar/extension/longest_eps_match.hpp @@ -7,7 +7,7 @@ namespace stellar { -using namespace seqan; +using namespace seqan2; /////////////////////////////////////////////////////////////////////////////// // Identifies the longest epsilon match in align from possEndsLeft and possEndsRight and sets the view positions of diff --git a/include/stellar/io/import_sequence.hpp b/include/stellar/io/import_sequence.hpp index b2f857ddf..af0401cb9 100644 --- a/include/stellar/io/import_sequence.hpp +++ b/include/stellar/io/import_sequence.hpp @@ -5,7 +5,7 @@ namespace stellar { -using namespace seqan; +using namespace seqan2; template inline bool diff --git a/include/stellar/options/verifier_options.hpp b/include/stellar/options/verifier_options.hpp index 5158f2b1b..29deb48b4 100644 --- a/include/stellar/options/verifier_options.hpp +++ b/include/stellar/options/verifier_options.hpp @@ -8,16 +8,16 @@ namespace stellar { struct VerifyAllLocal_; -using AllLocal = seqan::Tag const; +using AllLocal = seqan2::Tag const; struct VerifyBestLocal_; -using BestLocal = seqan::Tag const; +using BestLocal = seqan2::Tag const; struct VerifyBandedGlobal_; -using BandedGlobal = seqan::Tag const; +using BandedGlobal = seqan2::Tag const; struct VerifyBandedGlobalExtend_; -using BandedGlobalExtend = seqan::Tag const; +using BandedGlobalExtend = seqan2::Tag const; // basically a std::variant struct StellarVerificationMethod diff --git a/include/stellar/stellar.hpp b/include/stellar/stellar.hpp index 135e8b0ce..993d37bc7 100755 --- a/include/stellar/stellar.hpp +++ b/include/stellar/stellar.hpp @@ -45,7 +45,7 @@ namespace stellar { -using namespace seqan; +using namespace seqan2; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/include/stellar/stellar_database_segment.hpp b/include/stellar/stellar_database_segment.hpp index ac21c0706..8d5a47dee 100644 --- a/include/stellar/stellar_database_segment.hpp +++ b/include/stellar/stellar_database_segment.hpp @@ -15,30 +15,30 @@ struct StellarDatabaseSegment : public StellarSequenceSegment using TBase = StellarSequenceSegment; using typename TBase::TInfixSegment; - using TNestedFinderSegment = seqan::Segment; + using TNestedFinderSegment = seqan2::Segment; using TBase::TBase; // import constructor static StellarDatabaseSegment fromFinderMatch(TInfixSegment const & finderMatch) { - seqan::String const & underlyingDatabase = host(finderMatch); - return {underlyingDatabase, seqan::beginPosition(finderMatch), seqan::endPosition(finderMatch)}; + seqan2::String const & underlyingDatabase = host(finderMatch); + return {underlyingDatabase, seqan2::beginPosition(finderMatch), seqan2::endPosition(finderMatch)}; } - seqan::String const & underlyingDatabase() const & + seqan2::String const & underlyingDatabase() const & { return this->underlyingSequence(); } TNestedFinderSegment asFinderSegment() const { - seqan::String const & _database = underlyingDatabase(); + seqan2::String const & _database = underlyingDatabase(); auto finderInfix = this->asInfixSegment(); TInfixSegment const finderInfixSeq = infix(_database, 0, length(_database)); TNestedFinderSegment finderSegment(finderInfixSeq, - seqan::beginPosition(finderInfix) - seqan::beginPosition(_database), - seqan::endPosition(finderInfix) - seqan::beginPosition(_database)); + seqan2::beginPosition(finderInfix) - seqan2::beginPosition(_database), + seqan2::endPosition(finderInfix) - seqan2::beginPosition(_database)); return finderSegment; } }; @@ -79,4 +79,30 @@ TStorage _getDatabaseSegments(StringSet> & databases, StellarO return databaseSegments; } +template +TStorage _getDatabaseSegmentForValik(String const & sequenceOfInterest, + StellarOptions const & options, + bool const reverse = false) +{ + TStorage databaseSegments{}; + if (length(sequenceOfInterest) < options.segmentEnd) + throw std::runtime_error{"Segment end out of range"}; + + if (options.segmentEnd <= options.segmentBegin) + throw std::runtime_error{"Incorrect segment definition"}; + + if (options.segmentEnd < options.minLength + options.segmentBegin) + throw std::runtime_error{"Segment shorter than minimum match length"}; + + if (reverse) + { + reverseComplement(sequenceOfInterest); + databaseSegments.emplace_back(sequenceOfInterest, length(sequenceOfInterest) - options.segmentEnd, length(sequenceOfInterest) - options.segmentBegin); + } + else + databaseSegments.emplace_back(sequenceOfInterest, options.segmentBegin, options.segmentEnd); + + return databaseSegments; +} + } // namespace stellar diff --git a/include/stellar/stellar_extension.hpp b/include/stellar/stellar_extension.hpp index c1b4ad8c9..aec51ae15 100644 --- a/include/stellar/stellar_extension.hpp +++ b/include/stellar/stellar_extension.hpp @@ -33,7 +33,7 @@ namespace stellar { -using namespace seqan; +using namespace seqan2; /////////////////////////////////////////////////////////////////////////////// // returns true if align has a match at pos, otherwise false diff --git a/include/stellar/stellar_index.hpp b/include/stellar/stellar_index.hpp index 9dd509f73..fa2777f33 100644 --- a/include/stellar/stellar_index.hpp +++ b/include/stellar/stellar_index.hpp @@ -32,9 +32,9 @@ namespace stellar { -using namespace seqan; +using namespace seqan2; -template , typename TInfixSegment = seqan::Segment> +template , typename TInfixSegment = seqan2::Segment> using StellarQGramStringSet = StringSet >; template @@ -49,8 +49,8 @@ using StellarSwiftFinder = Finder const, InfixSegment> template struct StellarIndex { - using TSequence = seqan::String; - using TInfixSegment = seqan::Segment const, seqan::InfixSegment>; + using TSequence = seqan2::String; + using TInfixSegment = seqan2::Segment const, seqan2::InfixSegment>; using TQGramStringSet = StellarQGramStringSet; template @@ -110,7 +110,7 @@ struct StellarIndex { StellarQGramStringSet dependentQueries; for (TSequence const & query: queries) - seqan::appendValue(dependentQueries, seqan::infix(query, 0, seqan::length(query))); + seqan2::appendValue(dependentQueries, seqan2::infix(query, 0, seqan2::length(query))); return dependentQueries; } @@ -119,7 +119,7 @@ struct StellarIndex { StellarQGramStringSet dependentQueries; for (TInfixSegment const & query: queries) - seqan::appendValue(dependentQueries, query); + seqan2::appendValue(dependentQueries, query); return dependentQueries; } @@ -128,7 +128,7 @@ struct StellarIndex } // namespace stellar -namespace seqan { +namespace seqan2 { template struct Cargo<::stellar::StellarQGramIndex> @@ -172,6 +172,6 @@ inline bool _qgramDisableBuckets(::stellar::StellarQGramIndex & index return result; } -} // namespace seqan +} // namespace seqan2 #endif diff --git a/include/stellar/stellar_output.hpp b/include/stellar/stellar_output.hpp index 0080f7ac7..da0fc945f 100755 --- a/include/stellar/stellar_output.hpp +++ b/include/stellar/stellar_output.hpp @@ -32,7 +32,7 @@ namespace stellar { -using namespace seqan; +using namespace seqan2; /////////////////////////////////////////////////////////////////////////////// // Computes the length adjustment for E-value computation diff --git a/include/stellar/stellar_query_segment.hpp b/include/stellar/stellar_query_segment.hpp index 950019a0a..011aa6d09 100644 --- a/include/stellar/stellar_query_segment.hpp +++ b/include/stellar/stellar_query_segment.hpp @@ -12,28 +12,28 @@ struct StellarQuerySegment : public StellarSequenceSegment using TBase = StellarSequenceSegment; using typename TBase::TInfixSegment; - using TNestedPatternSegment = seqan::Segment; + using TNestedPatternSegment = seqan2::Segment; using TBase::TBase; // import constructor template static StellarQuerySegment fromPatternMatch(TSwiftPattern const & swiftPattern); - seqan::String const & underlyingQuery() const & + seqan2::String const & underlyingQuery() const & { return this->underlyingSequence(); } TNestedPatternSegment asPatternSegment() const { - seqan::String const & _query = underlyingQuery(); + seqan2::String const & _query = underlyingQuery(); auto patternInfix = this->asInfixSegment(); TInfixSegment const patternInfixSeq = infix(_query, 0, length(_query)); return { patternInfixSeq, - seqan::beginPosition(patternInfix) - seqan::beginPosition(patternInfixSeq), - seqan::endPosition(patternInfix) - seqan::beginPosition(patternInfixSeq) + seqan2::beginPosition(patternInfix) - seqan2::beginPosition(patternInfixSeq), + seqan2::endPosition(patternInfix) - seqan2::beginPosition(patternInfixSeq) }; } }; diff --git a/include/stellar/stellar_query_segment.tpp b/include/stellar/stellar_query_segment.tpp index d4b3e58f8..e99e19bed 100644 --- a/include/stellar/stellar_query_segment.tpp +++ b/include/stellar/stellar_query_segment.tpp @@ -2,7 +2,7 @@ #pragma once // can we replace this include by some forwards? -// needed for seqan::indexText, seqan::needle +// needed for seqan2::indexText, seqan2::needle #include #include @@ -16,13 +16,13 @@ StellarQuerySegment StellarQuerySegment::fromPatternMatch(TSwiftPattern const & swiftPattern) { size_t const queryID = swiftPattern.curSeqNo; - auto const & queryInfix = seqan::getSequenceByNo(queryID, seqan::indexText(seqan::needle(swiftPattern))); + auto const & queryInfix = seqan2::getSequenceByNo(queryID, seqan2::indexText(seqan2::needle(swiftPattern))); static_assert(std::is_same_v); auto const & underlyingQuery = host(queryInfix); - static_assert(std::is_same_v const &>); - auto const queryInfixInfix = seqan::infix(swiftPattern, queryInfix); + static_assert(std::is_same_v const &>); + auto const queryInfixInfix = seqan2::infix(swiftPattern, queryInfix); - return {underlyingQuery, seqan::beginPosition(queryInfixInfix), seqan::endPosition(queryInfixInfix)}; + return {underlyingQuery, seqan2::beginPosition(queryInfixInfix), seqan2::endPosition(queryInfixInfix)}; } } // namespace stellar diff --git a/include/stellar/stellar_sequence_segment.hpp b/include/stellar/stellar_sequence_segment.hpp index d30810ff1..e784ce6fb 100644 --- a/include/stellar/stellar_sequence_segment.hpp +++ b/include/stellar/stellar_sequence_segment.hpp @@ -9,8 +9,8 @@ namespace stellar template struct StellarSequenceSegment { - using TString = seqan::String; - using TInfixSegment = seqan::Segment; + using TString = seqan2::String; + using TInfixSegment = seqan2::Segment; StellarSequenceSegment() = default; @@ -22,19 +22,19 @@ struct StellarSequenceSegment : _sequenceSegment{sequence, beginPosition, endPosition} {} - seqan::String const & underlyingSequence() const & + seqan2::String const & underlyingSequence() const & { return host(_sequenceSegment); } size_t beginPosition() const { - return seqan::beginPosition(_sequenceSegment); + return seqan2::beginPosition(_sequenceSegment); } size_t endPosition() const { - return seqan::endPosition(_sequenceSegment); + return seqan2::endPosition(_sequenceSegment); } std::pair interval() const diff --git a/include/stellar/stellar_types.hpp b/include/stellar/stellar_types.hpp index 17d6e0968..41ca21adb 100755 --- a/include/stellar/stellar_types.hpp +++ b/include/stellar/stellar_types.hpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include #if __cpp_designated_initializers || __GNUC__ >= 8 # define STELLAR_DESIGNATED_INITIALIZER(designator, value) designator value @@ -41,7 +41,7 @@ namespace stellar { -using namespace seqan; +using namespace seqan2; struct StellarStatistics { diff --git a/include/stellar/verification/detail/all_or_best_local.hpp b/include/stellar/verification/detail/all_or_best_local.hpp index 827602c6f..09fd9a1a9 100644 --- a/include/stellar/verification/detail/all_or_best_local.hpp +++ b/include/stellar/verification/detail/all_or_best_local.hpp @@ -192,7 +192,7 @@ allOrBestLocal(Segment, InfixSegment> con std::integral_constant) { using TInfix = Segment; typedef Segment TSegment; - typedef typename StellarMatch::TAlign TAlign; + typedef typename StellarMatch::TAlign TAlign; TSize maxLength = 1000000000; if ((TSize)length(infH) > maxLength) { diff --git a/include/stellar3.arg_parser.hpp b/include/stellar3.arg_parser.hpp index ef47956df..a6c3e3b5d 100644 --- a/include/stellar3.arg_parser.hpp +++ b/include/stellar3.arg_parser.hpp @@ -5,7 +5,7 @@ #include #include -#include +#include namespace stellar::app { diff --git a/include/shared.hpp b/include/stellar3.shared.hpp similarity index 100% rename from include/shared.hpp rename to include/stellar3.shared.hpp diff --git a/lib/seqan b/lib/seqan index a41c0d89b..8ce355dd9 160000 --- a/lib/seqan +++ b/lib/seqan @@ -1 +1 @@ -Subproject commit a41c0d89bb295a53e269932c0e163ad005958ffe +Subproject commit 8ce355dd960bbf7a5fa0292b49f7342f7e456da6 diff --git a/src/stellar3.arg_parser.cpp b/src/stellar3.arg_parser.cpp index 3a7f886dc..70c176095 100644 --- a/src/stellar3.arg_parser.cpp +++ b/src/stellar3.arg_parser.cpp @@ -244,17 +244,17 @@ void run_stellar(sharg::parser & parser) throw sharg::parser_error{"Invalid parameter values: Please choose numMatches <= sortThresh.\n"}; if (options.alphabet == "dna") - stellar::app::mainWithOptions(options, seqan::String()); + stellar::app::mainWithOptions(options, seqan2::String()); else if (options.alphabet == "dna5") - stellar::app::mainWithOptions(options, seqan::String()); + stellar::app::mainWithOptions(options, seqan2::String()); else if (options.alphabet == "rna") - stellar::app::mainWithOptions(options, seqan::String()); + stellar::app::mainWithOptions(options, seqan2::String()); else if (options.alphabet == "rna5") - stellar::app::mainWithOptions(options, seqan::String()); + stellar::app::mainWithOptions(options, seqan2::String()); else if (options.alphabet == "protein") - stellar::app::mainWithOptions(options, seqan::String()); + stellar::app::mainWithOptions(options, seqan2::String()); else if (options.alphabet == "char") - stellar::app::mainWithOptions(options, seqan::String()); + stellar::app::mainWithOptions(options, seqan2::String()); } } // namespace stellar::app diff --git a/test/api/stellar/extension/align_banded_nw_best_ends_test.cpp b/test/api/stellar/extension/align_banded_nw_best_ends_test.cpp index 97b60bcb1..d5713a442 100644 --- a/test/api/stellar/extension/align_banded_nw_best_ends_test.cpp +++ b/test/api/stellar/extension/align_banded_nw_best_ends_test.cpp @@ -34,10 +34,10 @@ void expect_same_matrix(TTraceBackMatrix & traceBackMatrix1, TTraceBackMatrix & TEST(align_banded_nw_best_ends, identicalAlignment) { - seqan::String sequence1 = "TGTC"; - seqan::String sequence2 = "GCCT"; + seqan2::String sequence1 = "TGTC"; + seqan2::String sequence2 = "GCCT"; - seqan::StringSet> sequences; + seqan2::StringSet> sequences; appendValue(sequences, sequence1); appendValue(sequences, sequence2); @@ -47,9 +47,9 @@ TEST(align_banded_nw_best_ends, identicalAlignment) size_t const columnCount = length(sequence1) + 1; TTraceBackMatrix traceBackMatrix1(rowCount, columnCount, diagL, diagU); TTraceBackMatrix traceBackMatrix2(rowCount, columnCount, diagL, diagU); - seqan::String possibleEnds1, possibleEnds2; + seqan2::String possibleEnds1, possibleEnds2; - seqan::Score scoringScheme1(1, -1, -1); + seqan2::Score scoringScheme1(1, -1, -1); _align_banded_nw_best_ends ( traceBackMatrix1.underlyingTraceMatrix(), possibleEnds1, @@ -59,7 +59,7 @@ TEST(align_banded_nw_best_ends, identicalAlignment) diagU ); - seqan::Score scoringScheme2(1, -1, -1); + seqan2::Score scoringScheme2(1, -1, -1); _align_banded_nw_best_ends ( traceBackMatrix2.underlyingTraceMatrix(), possibleEnds2, @@ -74,18 +74,18 @@ TEST(align_banded_nw_best_ends, identicalAlignment) TEST(align_banded_nw_best_ends, sameTraceMatrixButDifferentParameters) { - seqan::String sequence1 = + seqan2::String sequence1 = "TGTCAGCGGATGGGATGGTTCGTAATGGTAGTGGATTGCCCTTTGGAGTTAAATTACTTCTGCTCTGACACAATAGATCGGTTTAATGACCATTCTCCGCTCACGCTAGA" "GTGAGCCAGAGTGTGTTTGGTGCAGTTCATACGGTCCATTGCGTGAACTGTGCGGGCTAGTAGAGGTTTAACACGGACATGGCCTTGATGGGCGCACTTAAACAGTCCGA" "GTAATTGGTTGGATTAGCCAGAAATAGCATCAACTAGAGGCCCTATGTGGTGACTGACCTCGCTGACTTACATCTTGGCGTTGTCTGTCATAAAGCTCGCGTTCGCCAGC" "TGTCTCTAAGCGTATAATCGCACACCGCTTAAGGGGGTAGAACTCAGTCACTGTTTTTTTAGTGC"; - seqan::String sequence2 = + seqan2::String sequence2 = "ATCTTAATTCATGTGCACGCTACTTACAGGCTAGTGGCACGGCTGGCTGGCCTGTGAGATCTGTCGACAGACTGACTGTAGGGTGTATCGGCGTTGTTTGAACGGTTGCG" "AACGGGTCGCCGTGCCAAAGCATTACGGTTGTTCGTGGGGGATTATCGCGCTGGGTCCCGATATCGTTCTGGAGCGAGCTAAAAATATTACTTGGGACAAAGGTCTGAAG" "ATAGTAAATATGAGAAGTTCATCTATTAAGGCTCACACTACTGGTAAGTGGGGTGGGTCATGCGATAATCCGAGGTGTCATCATCGAGATGAAATATATAACCGCAAAGG" "GCCTCCCGATTTCCCAATAATCTGCCTTAGAGC"; - seqan::StringSet> sequences; + seqan2::StringSet> sequences; appendValue(sequences, sequence1); appendValue(sequences, sequence2); @@ -101,9 +101,9 @@ TEST(align_banded_nw_best_ends, sameTraceMatrixButDifferentParameters) TTraceBackMatrix traceBackMatrix1(rowCount, columnCount, diagL, diagU); TTraceBackMatrix traceBackMatrix2(rowCount, columnCount, diagL, diagU); - seqan::String possibleEnds1, possibleEnds2; + seqan2::String possibleEnds1, possibleEnds2; - seqan::Score scoringScheme1(1, -99998, -99998); + seqan2::Score scoringScheme1(1, -99998, -99998); _align_banded_nw_best_ends ( traceBackMatrix1.underlyingTraceMatrix(), possibleEnds1, @@ -113,7 +113,7 @@ TEST(align_banded_nw_best_ends, sameTraceMatrixButDifferentParameters) diagU ); - seqan::Score scoringScheme2(1, -11, -11); + seqan2::Score scoringScheme2(1, -11, -11); _align_banded_nw_best_ends ( traceBackMatrix2.underlyingTraceMatrix(), possibleEnds2, diff --git a/test/api/stellar/extension/extension_banded_trace_matrix_test.cpp b/test/api/stellar/extension/extension_banded_trace_matrix_test.cpp index 81d70414b..34e208b80 100644 --- a/test/api/stellar/extension/extension_banded_trace_matrix_test.cpp +++ b/test/api/stellar/extension/extension_banded_trace_matrix_test.cpp @@ -171,7 +171,7 @@ TEST(extension_banded_trace_matrix, rowSpan) { stellar::extension_banded_trace_matrix matrix{/*rows*/ 5u, /*columns*/ 5u, -2, +2}; - std::iota(matrix.data().begin(), matrix.data().end(), seqan::TraceBack{}); + std::iota(matrix.data().begin(), matrix.data().end(), seqan2::TraceBack{}); // ||e|A|B|C|D|| // e|0|1||2|3|4|x|x|| @@ -188,7 +188,7 @@ TEST(extension_banded_trace_matrix, rowSpan) { stellar::extension_banded_trace_matrix matrix{/*rows*/ 8u, /*columns*/ 5u, -2, -1}; - std::iota(matrix.data().begin(), matrix.data().end(), seqan::TraceBack{}); + std::iota(matrix.data().begin(), matrix.data().end(), seqan2::TraceBack{}); // ||e|A|B|C|D|| // e ||x|x|x|x|x|| @@ -213,7 +213,7 @@ TEST(extension_banded_trace_matrix, rowSpan) { stellar::extension_banded_trace_matrix matrix{/*rows*/ 5u, /*columns*/ 5u, +1, +2}; - std::iota(matrix.data().begin(), matrix.data().end(), seqan::TraceBack{}); + std::iota(matrix.data().begin(), matrix.data().end(), seqan2::TraceBack{}); // |e|A|B|C|D|| // e|x|0|1|x|x|| diff --git a/test/api/stellar/extension/longest_eps_match_test.cpp b/test/api/stellar/extension/longest_eps_match_test.cpp index 732a6cfdf..70aec1d60 100644 --- a/test/api/stellar/extension/longest_eps_match_test.cpp +++ b/test/api/stellar/extension/longest_eps_match_test.cpp @@ -3,12 +3,12 @@ #include using TExtensionEndPosition = stellar::ExtensionEndPosition; -using TPair = seqan::Pair const>::Type>; +using TPair = seqan2::Pair const>::Type>; TEST(longestEpsMatch, minLengthNotReached1) { - seqan::String leftExtensions{}; - seqan::String rightExtensions{}; + seqan2::String leftExtensions{}; + seqan2::String rightExtensions{}; appendValue(leftExtensions, TExtensionEndPosition{20, 100, 200}); // error: 0 appendValue(rightExtensions, TExtensionEndPosition{20, 100, 200}); // error: 0 @@ -27,8 +27,8 @@ TEST(longestEpsMatch, minLengthNotReached1) TEST(longestEpsMatch, minLengthNotReached2) { - seqan::String leftExtensions{}; - seqan::String rightExtensions{}; + seqan2::String leftExtensions{}; + seqan2::String rightExtensions{}; // matrix: 30 x 20 of extension lengths // 0| 1| ⋯ |18|19 @@ -62,8 +62,8 @@ TEST(longestEpsMatch, minLengthNotReached2) TEST(longestEpsMatch, epsilonNotReached1) { - seqan::String leftExtensions{}; - seqan::String rightExtensions{}; + seqan2::String leftExtensions{}; + seqan2::String rightExtensions{}; // matrix: 1 x 1 of extension lengths // 30 @@ -91,8 +91,8 @@ TEST(longestEpsMatch, epsilonNotReached1) TEST(longestEpsMatch, epsilonNotReached2) { - seqan::String leftExtensions{}; - seqan::String rightExtensions{}; + seqan2::String leftExtensions{}; + seqan2::String rightExtensions{}; // matrix: 5 x 3 of extension lengths // 10| 25| 30 @@ -137,8 +137,8 @@ TEST(longestEpsMatch, epsilonNotReached2) TEST(longestEpsMatch, multipleValidEpsMatches) { - seqan::String > leftExtensions{}; - seqan::String > rightExtensions{}; + seqan2::String > leftExtensions{}; + seqan2::String > rightExtensions{}; appendValue(leftExtensions, TExtensionEndPosition{5, 0, 0}); // error: 0 appendValue(leftExtensions, TExtensionEndPosition{9, 1, 1}); // error: 1 diff --git a/test/api/stellar/stellar_database_segment_test.cpp b/test/api/stellar/stellar_database_segment_test.cpp index 383e7ab91..9add691c0 100644 --- a/test/api/stellar/stellar_database_segment_test.cpp +++ b/test/api/stellar/stellar_database_segment_test.cpp @@ -2,7 +2,7 @@ #include -using TAlphabet = seqan::Dna5; +using TAlphabet = seqan2::Dna5; using TDatabaseSegment = stellar::StellarDatabaseSegment; using TStorage = std::vector; @@ -11,17 +11,17 @@ using TStorage = std::vector; //////////////////////////////////////////////// TEST(StellarDatabaseSegment, underlyingDatabase) { - seqan::String database{"ACG""TACGTA""CGT"}; + seqan2::String database{"ACG""TACGTA""CGT"}; stellar::StellarDatabaseSegment segment{database, 3u, length(database) - 3}; - seqan::String const & resultDatabase = database; + seqan2::String const & resultDatabase = database; EXPECT_EQ(resultDatabase, database); EXPECT_EQ(std::addressof(resultDatabase), std::addressof(database)); } TEST(StellarDatabaseSegment, beginPosition) { - seqan::String database{"ACG""TACGTA""CGT"}; + seqan2::String database{"ACG""TACGTA""CGT"}; stellar::StellarDatabaseSegment segment{database, 3u, length(database) - 3}; EXPECT_EQ(segment.beginPosition(), 3u); @@ -29,7 +29,7 @@ TEST(StellarDatabaseSegment, beginPosition) TEST(StellarDatabaseSegment, endPosition) { - seqan::String database{"ACG""TACGTA""CGT"}; + seqan2::String database{"ACG""TACGTA""CGT"}; stellar::StellarDatabaseSegment segment{database, 3u, length(database) - 3}; EXPECT_EQ(segment.endPosition(), length(database) - 3); @@ -37,7 +37,7 @@ TEST(StellarDatabaseSegment, endPosition) TEST(StellarDatabaseSegment, interval) { - seqan::String database{"ACG""TACGTA""CGT"}; + seqan2::String database{"ACG""TACGTA""CGT"}; stellar::StellarDatabaseSegment segment{database, 3u, length(database) - 3}; EXPECT_EQ(segment.interval(), (std::pair{3u, length(database) - 3})); @@ -45,7 +45,7 @@ TEST(StellarDatabaseSegment, interval) TEST(StellarDatabaseSegment, size) { - seqan::String database{"ACG""TACGTA""CGT"}; + seqan2::String database{"ACG""TACGTA""CGT"}; stellar::StellarDatabaseSegment segment{database, 3u, length(database) - 3}; EXPECT_EQ(length(segment.asInfixSegment()), 6u); @@ -54,18 +54,18 @@ TEST(StellarDatabaseSegment, size) TEST(StellarDatabaseSegment, asInfixSegment) { - seqan::String database{"ACG""TACGTA""CGT"}; + seqan2::String database{"ACG""TACGTA""CGT"}; stellar::StellarDatabaseSegment segment{database, 3u, length(database) - 3}; EXPECT_EQ(segment.asInfixSegment(), "TACGTA"); - EXPECT_EQ(segment.asInfixSegment(), seqan::infix(database, 3u, length(database) - 3)); + EXPECT_EQ(segment.asInfixSegment(), seqan2::infix(database, 3u, length(database) - 3)); } TEST(StellarDatabaseSegment, fromFinderMatch) { - using TFinderSegment = seqan::Segment const, seqan::InfixSegment>, seqan::InfixSegment>; + using TFinderSegment = seqan2::Segment const, seqan2::InfixSegment>, seqan2::InfixSegment>; - seqan::String database{}; + seqan2::String database{}; resize(database, 1'000'000u); // 1Mb std::generate(begin(database), end(database), [i = 0u]() mutable { @@ -82,50 +82,50 @@ TEST(StellarDatabaseSegment, fromFinderMatch) { auto const databaseInfixSequence = "ACGTACGTACGTACGTACGTACGTACGTACGTACGT"; - auto const finderMatch = seqan::infix(database, 111'948u, 111'984u); + auto const finderMatch = seqan2::infix(database, 111'948u, 111'984u); stellar::StellarDatabaseSegment segment = stellar::StellarDatabaseSegment::fromFinderMatch(finderMatch); EXPECT_EQ(segment.asInfixSegment(), databaseInfixSequence); TFinderSegment finderSegment = segment.asFinderSegment(); - EXPECT_EQ(seqan::beginPosition(finderSegment), 111'948u); - EXPECT_EQ(seqan::endPosition(finderSegment), 111'984u); - EXPECT_EQ(seqan::infix(segment.underlyingDatabase(), - seqan::beginPosition(finderSegment), - seqan::endPosition(finderSegment)), + EXPECT_EQ(seqan2::beginPosition(finderSegment), 111'948u); + EXPECT_EQ(seqan2::endPosition(finderSegment), 111'984u); + EXPECT_EQ(seqan2::infix(segment.underlyingDatabase(), + seqan2::beginPosition(finderSegment), + seqan2::endPosition(finderSegment)), databaseInfixSequence); - EXPECT_EQ(seqan::beginPosition(host(finderSegment)), 0u); - EXPECT_EQ(seqan::endPosition(host(finderSegment)), 1'000'000u); + EXPECT_EQ(seqan2::beginPosition(host(finderSegment)), 0u); + EXPECT_EQ(seqan2::endPosition(host(finderSegment)), 1'000'000u); EXPECT_EQ(std::addressof(host(host(finderSegment))), std::addressof(database)); } { auto const databaseInfixSequence = "TACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTA"; - auto const finderMatch = seqan::infix(database, 230'711u, 230'781u); + auto const finderMatch = seqan2::infix(database, 230'711u, 230'781u); stellar::StellarDatabaseSegment segment = stellar::StellarDatabaseSegment::fromFinderMatch(finderMatch); EXPECT_EQ(segment.asInfixSegment(), databaseInfixSequence); TFinderSegment finderSegment = segment.asFinderSegment(); - EXPECT_EQ(seqan::beginPosition(finderSegment), 230'711u); - EXPECT_EQ(seqan::endPosition(finderSegment), 230'781u); - EXPECT_EQ(seqan::infix(segment.underlyingDatabase(), - seqan::beginPosition(finderSegment), - seqan::endPosition(finderSegment)), + EXPECT_EQ(seqan2::beginPosition(finderSegment), 230'711u); + EXPECT_EQ(seqan2::endPosition(finderSegment), 230'781u); + EXPECT_EQ(seqan2::infix(segment.underlyingDatabase(), + seqan2::beginPosition(finderSegment), + seqan2::endPosition(finderSegment)), databaseInfixSequence); - EXPECT_EQ(seqan::beginPosition(host(finderSegment)), 0u); - EXPECT_EQ(seqan::endPosition(host(finderSegment)), 1'000'000u); + EXPECT_EQ(seqan2::beginPosition(host(finderSegment)), 0u); + EXPECT_EQ(seqan2::endPosition(host(finderSegment)), 1'000'000u); EXPECT_EQ(std::addressof(host(host(finderSegment))), std::addressof(database)); } } TEST(StellarDatabaseSegment, comparison) { - std::vector> sequences{"ACGTACGTACGT", "TGCATGCATGCATGCA"}; + std::vector> sequences{"ACGTACGTACGT", "TGCATGCATGCATGCA"}; stellar::StellarDatabaseSegment segment1, segment2; @@ -227,12 +227,12 @@ TEST(StellarDatabaseSegment, comparison) //////////////////////////////////////////////// // TStorage _getDatabaseSegments() //////////////////////////////////////////////// -seqan::StringSet> getDatabases() +seqan2::StringSet> getDatabases() { - seqan::StringSet> databases; - seqan::appendValue(databases, (seqan::String) {"AACAGTC"}); - seqan::appendValue(databases, (seqan::String) {"ACGTCG"}); - seqan::appendValue(databases, (seqan::String) {"CCGCTGC"}); + seqan2::StringSet> databases; + seqan2::appendValue(databases, (seqan2::String) {"AACAGTC"}); + seqan2::appendValue(databases, (seqan2::String) {"ACGTCG"}); + seqan2::appendValue(databases, (seqan2::String) {"CCGCTGC"}); return databases; } @@ -248,20 +248,20 @@ stellar::StellarOptions getPrefilteringOptions(std::vector const seqInt, TEST(getDatabaseSegment, all_sequences) { - seqan::StringSet> databases = getDatabases(); + seqan2::StringSet> databases = getDatabases(); auto options = getPrefilteringOptions(std::vector{1}, 0u, 2u); TStorage databaseSegments = stellar::_getDatabaseSegments(databases, options); EXPECT_EQ(length(databaseSegments), 3u); - EXPECT_EQ(databaseSegments[0].asInfixSegment(), (seqan::String) {"AACAGTC"}); - EXPECT_EQ(databaseSegments[1].asInfixSegment(), (seqan::String) {"ACGTCG"}); - EXPECT_EQ(databaseSegments[2].asInfixSegment(), (seqan::String) {"CCGCTGC"}); + EXPECT_EQ(databaseSegments[0].asInfixSegment(), (seqan2::String) {"AACAGTC"}); + EXPECT_EQ(databaseSegments[1].asInfixSegment(), (seqan2::String) {"ACGTCG"}); + EXPECT_EQ(databaseSegments[2].asInfixSegment(), (seqan2::String) {"CCGCTGC"}); } TEST(getDatabaseSegment, last_two) { - seqan::StringSet> databases = getDatabases(); + seqan2::StringSet> databases = getDatabases(); auto options = getPrefilteringOptions(std::vector{1, 2}, 0u, 2u); options.prefilteredSearch = true; @@ -270,15 +270,15 @@ TEST(getDatabaseSegment, last_two) // each database sequence is made into a segment if options.searchSegment == false // a subset of sequences may be extracted with _importSequencesOfInterest if options.prefilteredSearch == true EXPECT_EQ(length(databaseSegments), 3u); - EXPECT_EQ(databaseSegments[0].asInfixSegment(), (seqan::String) {"AACAGTC"}); - EXPECT_EQ(databaseSegments[1].asInfixSegment(), (seqan::String) {"ACGTCG"}); - EXPECT_EQ(databaseSegments[2].asInfixSegment(), (seqan::String) {"CCGCTGC"}); + EXPECT_EQ(databaseSegments[0].asInfixSegment(), (seqan2::String) {"AACAGTC"}); + EXPECT_EQ(databaseSegments[1].asInfixSegment(), (seqan2::String) {"ACGTCG"}); + EXPECT_EQ(databaseSegments[2].asInfixSegment(), (seqan2::String) {"CCGCTGC"}); } TEST(getDatabaseSegment, from_begin) { - seqan::StringSet> databases; - seqan::appendValue(databases, (seqan::String) {"ACGTCG"}); + seqan2::StringSet> databases; + seqan2::appendValue(databases, (seqan2::String) {"ACGTCG"}); auto options = getPrefilteringOptions(std::vector{1}, 0u, 2u); options.prefilteredSearch = true; @@ -289,13 +289,13 @@ TEST(getDatabaseSegment, from_begin) EXPECT_EQ(length(databaseSegments), 1u); EXPECT_EQ(length(databaseSegments[0].asInfixSegment()), 2u); EXPECT_EQ(databaseSegments[0].size(), 2u); - EXPECT_EQ(databaseSegments[0].asInfixSegment(), (seqan::String) {"AC"}); + EXPECT_EQ(databaseSegments[0].asInfixSegment(), (seqan2::String) {"AC"}); } TEST(getDatabaseSegment, whole_sequence) { - seqan::StringSet> databases; - seqan::appendValue(databases, (seqan::String) {"AACAGTC"}); + seqan2::StringSet> databases; + seqan2::appendValue(databases, (seqan2::String) {"AACAGTC"}); auto options = getPrefilteringOptions(std::vector{0}, 0u, 7u); options.prefilteredSearch = true; options.searchSegment = true; @@ -305,13 +305,13 @@ TEST(getDatabaseSegment, whole_sequence) EXPECT_EQ(length(databaseSegments), 1u); EXPECT_EQ(length(databaseSegments[0].asInfixSegment()), 7u); EXPECT_EQ(databaseSegments[0].size(), 7u); - EXPECT_EQ(databaseSegments[0].asInfixSegment(), (seqan::String) {"AACAGTC"}); + EXPECT_EQ(databaseSegments[0].asInfixSegment(), (seqan2::String) {"AACAGTC"}); } /* TEST(getDatabaseSegment, seq_out_of_range) { - seqan::StringSet> databases = getDatabases(); + seqan2::StringSet> databases = getDatabases(); auto options = getPrefilteringOptions(3u, 0u, 2u); options.prefilteredSearch = true; options.searchSegment = true; @@ -332,8 +332,8 @@ TEST(getDatabaseSegment, seq_out_of_range) TEST(getDatabaseSegment, index_out_of_range) { - seqan::StringSet> databases; - seqan::appendValue(databases, (seqan::String) {"ACGTCG"}); + seqan2::StringSet> databases; + seqan2::appendValue(databases, (seqan2::String) {"ACGTCG"}); auto options = getPrefilteringOptions(std::vector{1}, 0u, 8u); options.prefilteredSearch = true; options.searchSegment = true; @@ -359,8 +359,8 @@ TEST(getDatabaseSegment, index_out_of_range) TEST(getDatabaseSegment, too_short) { - seqan::StringSet> databases; - seqan::appendValue(databases, (seqan::String) {"ACGTCG"}); + seqan2::StringSet> databases; + seqan2::appendValue(databases, (seqan2::String) {"ACGTCG"}); auto options = getPrefilteringOptions(std::vector{1}, 0u, 1u); options.prefilteredSearch = true; options.searchSegment = true; @@ -379,8 +379,8 @@ TEST(getDatabaseSegment, too_short) TEST(getDatabaseSegment, incorrect_indices) { - seqan::StringSet> databases; - seqan::appendValue(databases, (seqan::String) {"ACGTCG"}); + seqan2::StringSet> databases; + seqan2::appendValue(databases, (seqan2::String) {"ACGTCG"}); auto options = getPrefilteringOptions(std::vector{1}, 2u, 0u); options.prefilteredSearch = true; options.searchSegment = true; diff --git a/test/api/stellar/stellar_import_sequence_test.cpp b/test/api/stellar/stellar_import_sequence_test.cpp index 74c30535c..6c4b9d3c1 100644 --- a/test/api/stellar/stellar_import_sequence_test.cpp +++ b/test/api/stellar/stellar_import_sequence_test.cpp @@ -4,19 +4,19 @@ #include -using TAlphabet = seqan::Dna5; +using TAlphabet = seqan2::Dna5; std::string databaseFile = std::string{DATADIR} + "/multi_seq_ref.fasta"; TEST(import_sequences, all_sequences) { - seqan::StringSet> databases; - seqan::StringSet databaseIDs; + seqan2::StringSet> databases; + seqan2::StringSet databaseIDs; uint64_t refLen{0}; stellar::_importAllSequences(databaseFile.c_str(), "database", databases, databaseIDs, refLen); EXPECT_EQ(length(databases), 3u); - EXPECT_EQ(databases[0], (seqan::String) {"GATGACTCAGTCTTGTTGATTAGGCACCTCGGTATGTGGGCATTAGGCACATTGCTCTGTTTCTTGAAGT" + EXPECT_EQ(databases[0], (seqan2::String) {"GATGACTCAGTCTTGTTGATTAGGCACCTCGGTATGTGGGCATTAGGCACATTGCTCTGTTTCTTGAAGT" "CTGGTATGAGCACAAGGTGTGTCCCAACCGACAACTGGTTCAATGGCCACCCCGACCTAAAGGACGTTTC" "CGCTTCGATTGTGAGGACTTTAACAGGTTTTCGTCTGGCAGAATCATGTCCTTACTGCTTATCCAGGTCT" "TTTAAAGTTCGTTTCAGACTTTGGTCCCAAGCGACTCCAAACGGAGAACCGTACGAATATCTACCCAGTC" @@ -26,7 +26,7 @@ TEST(import_sequences, all_sequences) "GGCGTTACACCCATAGGGGAATAACGCCGAAATTGGTGGTTCTCGATAATTGCCAGTAATGCATCACAGC"}); EXPECT_EQ(databaseIDs[0], "1"); - EXPECT_EQ(databases[1], (seqan::String) {"ATCTGCCTGGGTGGGGAATTGGGACAACCCTTGGGTTATAGACGTGCTCGTCAAAGGACAAGAGGAAATA" + EXPECT_EQ(databases[1], (seqan2::String) {"ATCTGCCTGGGTGGGGAATTGGGACAACCCTTGGGTTATAGACGTGCTCGTCAAAGGACAAGAGGAAATA" "CCCATCTGGTCATCGGGGATCCGATGGCATCGCCAGGTATTACGCCCCTCCATGAGAACAAAACAGCTCG" "GATAACGGTCAAACCGGCAGATGGTTAATGATCATGAGAATCCTTTGCTACGGTTAAAATACCCTGTAAG" "GACCGAATGTACCCAAATAAGGCAAGCAACGGAGTATACACCGGAGTCTCCAGTGTTCGGACTGACTCGC" @@ -35,7 +35,7 @@ TEST(import_sequences, all_sequences) "TGACGGTTAATTCGAACAAATTTAGATGATTATTCCGTATTAGA"}); EXPECT_EQ(databaseIDs[1], "2"); - EXPECT_EQ(databases[2], (seqan::String) {"GACCGAATGTACCCAAATAAGGCAAGCAACGGAGTATACACCGGAGTCTCCAGTGTTCGGACTGACTCGC" + EXPECT_EQ(databases[2], (seqan2::String) {"GACCGAATGTACCCAAATAAGGCAAGCAACGGAGTATACACCGGAGTCTCCAGTGTTCGGACTGACTCGC" "TGGGATAAGCTGACAGACGACTTATTGCCAATTGCGTTGATGTCTAAGAAGGCGAGCTTCCCCTCTCCTA" "GGTGCTGGTGGTGGCTCCGAACAAGGGGCTGACCTGCTCACCAGGTATTGTAGAGATCTGGCCATGGGTT"}); EXPECT_EQ(databaseIDs[2], "3"); @@ -45,14 +45,14 @@ TEST(import_sequences, all_sequences) TEST(import_sequence_of_interest, first) { - seqan::StringSet> databases; - seqan::StringSet databaseIDs; + seqan2::StringSet> databases; + seqan2::StringSet databaseIDs; uint64_t refLen{0}; stellar::_importSequencesOfInterest(databaseFile.c_str(), std::vector{0}, databases, databaseIDs, refLen); EXPECT_EQ(length(databases), 1u); - EXPECT_EQ(databases[0], (seqan::String) {"GATGACTCAGTCTTGTTGATTAGGCACCTCGGTATGTGGGCATTAGGCACATTGCTCTGTTTCTTGAAGT" + EXPECT_EQ(databases[0], (seqan2::String) {"GATGACTCAGTCTTGTTGATTAGGCACCTCGGTATGTGGGCATTAGGCACATTGCTCTGTTTCTTGAAGT" "CTGGTATGAGCACAAGGTGTGTCCCAACCGACAACTGGTTCAATGGCCACCCCGACCTAAAGGACGTTTC" "CGCTTCGATTGTGAGGACTTTAACAGGTTTTCGTCTGGCAGAATCATGTCCTTACTGCTTATCCAGGTCT" "TTTAAAGTTCGTTTCAGACTTTGGTCCCAAGCGACTCCAAACGGAGAACCGTACGAATATCTACCCAGTC" @@ -66,14 +66,14 @@ TEST(import_sequence_of_interest, first) TEST(import_sequence_of_interest, last_two) { - seqan::StringSet> databases; - seqan::StringSet databaseIDs; + seqan2::StringSet> databases; + seqan2::StringSet databaseIDs; uint64_t refLen{0}; stellar::_importSequencesOfInterest(databaseFile.c_str(), std::vector{1, 2}, databases, databaseIDs, refLen); EXPECT_EQ(length(databases), 2u); - EXPECT_EQ(databases[0], (seqan::String) {"ATCTGCCTGGGTGGGGAATTGGGACAACCCTTGGGTTATAGACGTGCTCGTCAAAGGACAAGAGGAAATA" + EXPECT_EQ(databases[0], (seqan2::String) {"ATCTGCCTGGGTGGGGAATTGGGACAACCCTTGGGTTATAGACGTGCTCGTCAAAGGACAAGAGGAAATA" "CCCATCTGGTCATCGGGGATCCGATGGCATCGCCAGGTATTACGCCCCTCCATGAGAACAAAACAGCTCG" "GATAACGGTCAAACCGGCAGATGGTTAATGATCATGAGAATCCTTTGCTACGGTTAAAATACCCTGTAAG" "GACCGAATGTACCCAAATAAGGCAAGCAACGGAGTATACACCGGAGTCTCCAGTGTTCGGACTGACTCGC" @@ -82,7 +82,7 @@ TEST(import_sequence_of_interest, last_two) "TGACGGTTAATTCGAACAAATTTAGATGATTATTCCGTATTAGA"}); EXPECT_EQ(databaseIDs[0], "2"); - EXPECT_EQ(databases[1], (seqan::String) {"GACCGAATGTACCCAAATAAGGCAAGCAACGGAGTATACACCGGAGTCTCCAGTGTTCGGACTGACTCGC" + EXPECT_EQ(databases[1], (seqan2::String) {"GACCGAATGTACCCAAATAAGGCAAGCAACGGAGTATACACCGGAGTCTCCAGTGTTCGGACTGACTCGC" "TGGGATAAGCTGACAGACGACTTATTGCCAATTGCGTTGATGTCTAAGAAGGCGAGCTTCCCCTCTCCTA" "GGTGCTGGTGGTGGCTCCGAACAAGGGGCTGACCTGCTCACCAGGTATTGTAGAGATCTGGCCATGGGTT"}); EXPECT_EQ(databaseIDs[1], "3"); @@ -91,8 +91,8 @@ TEST(import_sequence_of_interest, last_two) TEST(import_sequence_of_interest, out_of_range) { - seqan::StringSet> databases; - seqan::StringSet databaseIDs; + seqan2::StringSet> databases; + seqan2::StringSet databaseIDs; std::vector sequenceIndex{3}; diff --git a/test/api/stellar/stellar_index_test.cpp b/test/api/stellar/stellar_index_test.cpp index 5c50fc436..ec129d04e 100644 --- a/test/api/stellar/stellar_index_test.cpp +++ b/test/api/stellar/stellar_index_test.cpp @@ -6,13 +6,13 @@ struct StringSetOwnerFactory { template static decltype(auto) - dependentQueries(seqan::StringSet, seqan::Owner<> > const & sequences) + dependentQueries(seqan2::StringSet, seqan2::Owner<> > const & sequences) { return sequences; // pass as is } template - static decltype(auto) underlyingSequence(seqan::String const & sequence) + static decltype(auto) underlyingSequence(seqan2::String const & sequence) { return sequence; // pass as is } @@ -21,14 +21,14 @@ struct StringSetOwnerFactory struct StringSetDependentFactory { template - static seqan::StringSet, seqan::Dependent<>> - dependentQueries(seqan::StringSet> const & sequences) + static seqan2::StringSet, seqan2::Dependent<>> + dependentQueries(seqan2::StringSet> const & sequences) { return sequences; // convert } template - static decltype(auto) underlyingSequence(seqan::String const & sequence) + static decltype(auto) underlyingSequence(seqan2::String const & sequence) { return sequence; // pass as is } @@ -37,15 +37,15 @@ struct StringSetDependentFactory struct InfixSegmentVectorFactory { template - using TInfixSequence = seqan::Segment const, seqan::InfixSegment>; + using TInfixSequence = seqan2::Segment const, seqan2::InfixSegment>; template static auto - dependentQueries(seqan::StringSet> const & sequences) + dependentQueries(seqan2::StringSet> const & sequences) { std::vector> infixSequences{}; for (auto const & sequence : sequences) - infixSequences.emplace_back(sequence, 0u, seqan::length(sequence)); + infixSequences.emplace_back(sequence, 0u, seqan2::length(sequence)); return infixSequences; // convert } @@ -142,21 +142,21 @@ struct SwiftHitVerifier template results stellar_kernel_swift_seeds( StellarIndexTest const & self, - seqan::String const & database, - seqan::StringSet> const & queries, + seqan2::String const & database, + seqan2::StringSet> const & queries, stellar::StellarOptions const & options) { - using TSequence = seqan::String; - using TInfixSequence = seqan::Segment; + using TSequence = seqan2::String; + using TInfixSequence = seqan2::Segment; decltype(auto) dependentQueries = self.factory.dependentQueries(queries); if constexpr (std::is_same::value) { - EXPECT_TRUE((std::is_same const &, decltype(dependentQueries)>::value)); + EXPECT_TRUE((std::is_same const &, decltype(dependentQueries)>::value)); } else if constexpr (std::is_same::value) { - EXPECT_TRUE((std::is_same>, decltype(dependentQueries)>::value)); + EXPECT_TRUE((std::is_same>, decltype(dependentQueries)>::value)); } else if constexpr (std::is_same::value) { EXPECT_TRUE((std::is_same, decltype(dependentQueries)>::value)); @@ -179,7 +179,7 @@ results stellar_kernel_swift_seeds( stellar::StellarSwiftPattern swiftPattern = index.createSwiftPattern(); stellar::StellarSwiftFinder swiftFinder { - seqan::infix(database, 0u, seqan::length(database)), + seqan2::infix(database, 0u, seqan2::length(database)), options.minRepeatLength, options.maxRepeatPeriod }; @@ -242,23 +242,23 @@ results stellar_kernel_swift_seeds( TYPED_TEST(StellarIndexTest, validSeedWithExactMatches) { - using TAlphabet = seqan::Dna5; - using TSequence = seqan::String; + using TAlphabet = seqan2::Dna5; + using TSequence = seqan2::String; TSequence database{"CAACGGACTGCTGTCTAGAC" "TAACCGCAGAACACG" "ACTCCTCTACCTTACCGCGT"}; - seqan::StringSet queries{}; + seqan2::StringSet queries{}; // original - seqan::appendValue(queries, "CTCGAGGGTTTACGCATATCTGG" "TAACCG" "C"/**/ "AGAACACG" "A" "AGAGCCTGAGA"); + seqan2::appendValue(queries, "CTCGAGGGTTTACGCATATCTGG" "TAACCG" "C"/**/ "AGAACACG" "A" "AGAGCCTGAGA"); // 1 error, insert in query sequence - seqan::appendValue(queries, "CTCGAGGGTTTACGCATATCTGG" "TAACCG" "C" "A" "AGAACACG" "A" "AGAGCCTGAGA"); + seqan2::appendValue(queries, "CTCGAGGGTTTACGCATATCTGG" "TAACCG" "C" "A" "AGAACACG" "A" "AGAGCCTGAGA"); // 1 error, delete in query sequence - seqan::appendValue(queries, "CTCGAGGGTTTACGCATATCTGG" "TAACCG"/*C */ "AGAACACG" "A" "AGAGCCTGAGA"); + seqan2::appendValue(queries, "CTCGAGGGTTTACGCATATCTGG" "TAACCG"/*C */ "AGAACACG" "A" "AGAGCCTGAGA"); // 1 error, substitution in query sequence - seqan::appendValue(queries, "CTCGAGGGTTTACGCATATCTGG" "TAACCG" "G"/**/ "AGAACACG" "A" "AGAGCCTGAGA"); + seqan2::appendValue(queries, "CTCGAGGGTTTACGCATATCTGG" "TAACCG" "G"/**/ "AGAACACG" "A" "AGAGCCTGAGA"); // another sequence - seqan::appendValue(queries, "CCGACTACCCACTTACTTATTAGCCG" "TAACCGCAGAACACG" "GACCAATCAGGCCC"); + seqan2::appendValue(queries, "CCGACTACCCACTTACTTATTAGCCG" "TAACCGCAGAACACG" "GACCAATCAGGCCC"); // another smaller sequence - seqan::appendValue(queries, "TAGCCAGTTTA" "GCAGAACAC" "CAAGA"); + seqan2::appendValue(queries, "TAGCCAGTTTA" "GCAGAACAC" "CAAGA"); size_t const kmerSize = 7u; stellar::StellarOptions options{}; @@ -317,23 +317,23 @@ TYPED_TEST(StellarIndexTest, validSeedWithExactMatches) TYPED_TEST(StellarIndexTest, validSeedWithOneErrorMatches) { - using TAlphabet = seqan::Dna5; - using TSequence = seqan::String; + using TAlphabet = seqan2::Dna5; + using TSequence = seqan2::String; TSequence database{"CAACGGACTGCTGTCTAGAC" "TAACCGCAGAACACG" "ACTCCTCTACCTTACCGCGT"}; - seqan::StringSet queries{}; + seqan2::StringSet queries{}; // original - seqan::appendValue(queries, "CTCGAGGGTTTACGCATATCTGG" "TAACCG" "C"/**/ "AGAACACG" "A" "AGAGCCTGAGA"); + seqan2::appendValue(queries, "CTCGAGGGTTTACGCATATCTGG" "TAACCG" "C"/**/ "AGAACACG" "A" "AGAGCCTGAGA"); // 1 error, insert in query sequence - seqan::appendValue(queries, "CTCGAGGGTTTACGCATATCTGG" "TAACCG" "C" "A" "AGAACACG" "A" "AGAGCCTGAGA"); + seqan2::appendValue(queries, "CTCGAGGGTTTACGCATATCTGG" "TAACCG" "C" "A" "AGAACACG" "A" "AGAGCCTGAGA"); // 1 error, delete in query sequence - seqan::appendValue(queries, "CTCGAGGGTTTACGCATATCTGG" "TAACCG"/*C */ "AGAACACG" "A" "AGAGCCTGAGA"); + seqan2::appendValue(queries, "CTCGAGGGTTTACGCATATCTGG" "TAACCG"/*C */ "AGAACACG" "A" "AGAGCCTGAGA"); // 1 error, substitution in query sequence - seqan::appendValue(queries, "CTCGAGGGTTTACGCATATCTGG" "TAACCG" "G"/**/ "AGAACACG" "A" "AGAGCCTGAGA"); + seqan2::appendValue(queries, "CTCGAGGGTTTACGCATATCTGG" "TAACCG" "G"/**/ "AGAACACG" "A" "AGAGCCTGAGA"); // another sequence - seqan::appendValue(queries, "CCGACTACCCACTTACTTATTAGCCG" "TAACCGCAGAACACG" "GACCAATCAGGCCC"); + seqan2::appendValue(queries, "CCGACTACCCACTTACTTATTAGCCG" "TAACCGCAGAACACG" "GACCAATCAGGCCC"); // another smaller sequence - seqan::appendValue(queries, "TAGCCAGTTTA" "GCAGAACAC" "CAAGA"); + seqan2::appendValue(queries, "TAGCCAGTTTA" "GCAGAACAC" "CAAGA"); size_t const kmerSize = 7u; stellar::StellarOptions options{}; diff --git a/test/api/stellar/test/alignment_fragment_test.cpp b/test/api/stellar/test/alignment_fragment_test.cpp index e50a5bf10..1a087a776 100644 --- a/test/api/stellar/test/alignment_fragment_test.cpp +++ b/test/api/stellar/test/alignment_fragment_test.cpp @@ -6,7 +6,7 @@ TEST(alignment, empty) { - using TAlphabet = seqan::Dna5; + using TAlphabet = seqan2::Dna5; stellar::test::alignment_fragment fragment{"[]", "[]"}; EXPECT_EQ(fragment.sequence1, ""); @@ -21,7 +21,7 @@ TEST(alignment, empty) TEST(alignment, empty2) { - using TAlphabet = seqan::Dna5; + using TAlphabet = seqan2::Dna5; stellar::test::alignment_fragment fragment { "ACGTAC[]GT", @@ -40,7 +40,7 @@ TEST(alignment, empty2) TEST(alignment, singleChar) { - using TAlphabet = seqan::Dna5; + using TAlphabet = seqan2::Dna5; stellar::test::alignment_fragment fragment { "ACGT[A]CGT", @@ -59,7 +59,7 @@ TEST(alignment, singleChar) TEST(alignment, ungappedSequence) { - using TAlphabet = seqan::Dna5; + using TAlphabet = seqan2::Dna5; stellar::test::alignment_fragment fragment { "ACGT[ACG]T", @@ -78,7 +78,7 @@ TEST(alignment, ungappedSequence) TEST(alignment, gappedSequence) { - using TAlphabet = seqan::Dna5; + using TAlphabet = seqan2::Dna5; stellar::test::alignment_fragment fragment { "ACGT[-ACGT]", @@ -95,7 +95,7 @@ TEST(alignment, gappedSequence) EXPECT_EQ(row(fragment.alignment, 1), "CATG-"); } -static stellar::test::alignment_fragment const globalFragment +static stellar::test::alignment_fragment const globalFragment { "[AAAAACCCCC]GGGGGTTTTT", "AA[--AAACCC--]CCGGGGGTTTTT", @@ -117,7 +117,7 @@ TEST(alignment, gappedSequenceWithGlobalFragment) TEST(alignment, gappedSequenceWithWhitespace) { - using TAlphabet = seqan::Dna5; + using TAlphabet = seqan2::Dna5; stellar::test::alignment_fragment fragment { " [ AAAAA CCCCC ] GGGGG TTTTT ", @@ -136,7 +136,7 @@ TEST(alignment, gappedSequenceWithWhitespace) TEST(alignment, gappedSequenceWithMultipleSequenceLines) { - using TAlphabet = seqan::Dna5; + using TAlphabet = seqan2::Dna5; stellar::test::alignment_fragment const & fragment = stellar::test::fixture::a512_simSeq_0dot05::forward::fragment0; diff --git a/test/api/stellar/verification/all_local_test.cpp b/test/api/stellar/verification/all_local_test.cpp index bde0ac2af..664ca6c72 100644 --- a/test/api/stellar/verification/all_local_test.cpp +++ b/test/api/stellar/verification/all_local_test.cpp @@ -9,9 +9,9 @@ TEST(AllLocal, empty) { - using TAlphabet = seqan::Dna5; - seqan::String database{}; - seqan::String query{}; + using TAlphabet = seqan2::Dna5; + seqan2::String database{}; + seqan2::String query{}; stellar::stellar_verification_time verification_runtime{}; stellar::StellarDatabaseSegment databaseSegment{database, 0u, 0u}; @@ -44,8 +44,8 @@ TEST(AllLocal, empty) TEST(AllLocal, validSeedWithExactMatches) { - using TAlphabet = seqan::Dna5; - using TSequence = seqan::String; + using TAlphabet = seqan2::Dna5; + using TSequence = seqan2::String; TSequence database{"CAACGGACTGCTGTCTAGAC" "TAACCGCAGAACACG" "A" "CTCCTCTACCTTACCGCGT"}; // original TSequence query{"CTCGAGGGTTTACGCATATCTGG" "TAACCGCAGAACACG" "A" "AGAGCCTGAGA"}; @@ -61,7 +61,7 @@ TEST(AllLocal, validSeedWithExactMatches) EXPECT_EQ(stellar::StellarOptions{}.xDrop, xDrop); // default xDrop is 5 - using TAlignment = seqan::Align; + using TAlignment = seqan2::Align; std::vector alignments; stellar::verifySwiftHit( @@ -97,8 +97,8 @@ TEST(AllLocal, validSeedWithExactMatches) TEST(AllLocal, oneErrorInsertion) { - using TAlphabet = seqan::Dna5; - using TSequence = seqan::String; + using TAlphabet = seqan2::Dna5; + using TSequence = seqan2::String; TSequence database{"CAACGGACTGCTGTCTAGAC" "TAACCGC"/* */"AGAACACG" "A" "CTCCTCTACCTTACCGCGT"}; // 1 error, insert in query sequence TSequence query{"CTCGAGGGTTTACGCATATCTGG" "TAACCGC" "A" "AGAACACG" "A" "AGAGCCTGAGA"}; @@ -114,7 +114,7 @@ TEST(AllLocal, oneErrorInsertion) EXPECT_EQ(stellar::StellarOptions{}.xDrop, xDrop); // default xDrop is 5 - using TAlignment = seqan::Align; + using TAlignment = seqan2::Align; std::vector alignments; stellar::verifySwiftHit( @@ -163,8 +163,8 @@ TEST(AllLocal, oneErrorInsertion) TEST(AllLocal, oneErrorDeletion) { - using TAlphabet = seqan::Dna5; - using TSequence = seqan::String; + using TAlphabet = seqan2::Dna5; + using TSequence = seqan2::String; TSequence database{"CAACGGACTGCTGTCTAGAC" "TAACCG" "C" "AGAACACG" "A" "CTCCTCTACCTTACCGCGT"}; // 1 error, delete in query sequence TSequence query{"CTCGAGGGTTTACGCATATCTGG" "TAACCG"/*C*/"AGAACACG" "A" "AGAGCCTGAGA"}; @@ -180,7 +180,7 @@ TEST(AllLocal, oneErrorDeletion) EXPECT_EQ(stellar::StellarOptions{}.xDrop, xDrop); // default xDrop is 5 - using TAlignment = seqan::Align; + using TAlignment = seqan2::Align; std::vector alignments; stellar::verifySwiftHit( @@ -216,8 +216,8 @@ TEST(AllLocal, oneErrorDeletion) TEST(AllLocal, oneErrorSubstitution) { - using TAlphabet = seqan::Dna5; - using TSequence = seqan::String; + using TAlphabet = seqan2::Dna5; + using TSequence = seqan2::String; TSequence database{"CAACGGACTGCTGTCTAGAC" "TAACCG" "C" "AGAACACG" "A" "CTCCTCTACCTTACCGCGT"}; // 1 error, substitution in query sequence TSequence query{"CTCGAGGGTTTACGCATATCTGG" "TAACCG" "G" "AGAACACG" "A" "AGAGCCTGAGA"}; @@ -233,7 +233,7 @@ TEST(AllLocal, oneErrorSubstitution) EXPECT_EQ(stellar::StellarOptions{}.xDrop, xDrop); // default xDrop is 5 - using TAlignment = seqan::Align; + using TAlignment = seqan2::Align; std::vector alignments; stellar::verifySwiftHit( diff --git a/test/api/stellar/verification/best_local_test.cpp b/test/api/stellar/verification/best_local_test.cpp index d81b715eb..a4b65d7a6 100644 --- a/test/api/stellar/verification/best_local_test.cpp +++ b/test/api/stellar/verification/best_local_test.cpp @@ -9,9 +9,9 @@ TEST(BestLocal, empty) { - using TAlphabet = seqan::Dna5; - seqan::String database{}; - seqan::String query{}; + using TAlphabet = seqan2::Dna5; + seqan2::String database{}; + seqan2::String query{}; stellar::stellar_verification_time verification_runtime{}; stellar::StellarDatabaseSegment databaseSegment{database, 0u, 0u}; @@ -44,8 +44,8 @@ TEST(BestLocal, empty) TEST(BestLocal, validSeedWithExactMatches) { - using TAlphabet = seqan::Dna5; - using TSequence = seqan::String; + using TAlphabet = seqan2::Dna5; + using TSequence = seqan2::String; TSequence database{"CAACGGACTGCTGTCTAGAC" "TAACCGCAGAACACG" "A" "CTCCTCTACCTTACCGCGT"}; // original TSequence query{"CTCGAGGGTTTACGCATATCTGG" "TAACCGCAGAACACG" "A" "AGAGCCTGAGA"}; @@ -61,7 +61,7 @@ TEST(BestLocal, validSeedWithExactMatches) EXPECT_EQ(stellar::StellarOptions{}.xDrop, xDrop); // default xDrop is 5 - using TAlignment = seqan::Align; + using TAlignment = seqan2::Align; std::vector alignments; stellar::verifySwiftHit( @@ -97,8 +97,8 @@ TEST(BestLocal, validSeedWithExactMatches) TEST(BestLocal, oneErrorInsertion) { - using TAlphabet = seqan::Dna5; - using TSequence = seqan::String; + using TAlphabet = seqan2::Dna5; + using TSequence = seqan2::String; TSequence database{"CAACGGACTGCTGTCTAGAC" "TAACCGC"/* */"AGAACACG" "A" "CTCCTCTACCTTACCGCGT"}; // 1 error, insert in query sequence TSequence query{"CTCGAGGGTTTACGCATATCTGG" "TAACCGC" "A" "AGAACACG" "A" "AGAGCCTGAGA"}; @@ -114,7 +114,7 @@ TEST(BestLocal, oneErrorInsertion) EXPECT_EQ(stellar::StellarOptions{}.xDrop, xDrop); // default xDrop is 5 - using TAlignment = seqan::Align; + using TAlignment = seqan2::Align; std::vector alignments; stellar::verifySwiftHit( @@ -150,8 +150,8 @@ TEST(BestLocal, oneErrorInsertion) TEST(BestLocal, oneErrorDeletion) { - using TAlphabet = seqan::Dna5; - using TSequence = seqan::String; + using TAlphabet = seqan2::Dna5; + using TSequence = seqan2::String; TSequence database{"CAACGGACTGCTGTCTAGAC" "TAACCG" "C" "AGAACACG" "A" "CTCCTCTACCTTACCGCGT"}; // 1 error, delete in query sequence TSequence query{"CTCGAGGGTTTACGCATATCTGG" "TAACCG"/*C*/"AGAACACG" "A" "AGAGCCTGAGA"}; @@ -167,7 +167,7 @@ TEST(BestLocal, oneErrorDeletion) EXPECT_EQ(stellar::StellarOptions{}.xDrop, xDrop); // default xDrop is 5 - using TAlignment = seqan::Align; + using TAlignment = seqan2::Align; std::vector alignments; stellar::verifySwiftHit( @@ -203,8 +203,8 @@ TEST(BestLocal, oneErrorDeletion) TEST(BestLocal, oneErrorSubstitution) { - using TAlphabet = seqan::Dna5; - using TSequence = seqan::String; + using TAlphabet = seqan2::Dna5; + using TSequence = seqan2::String; TSequence database{"CAACGGACTGCTGTCTAGAC" "TAACCG" "C" "AGAACACG" "A" "CTCCTCTACCTTACCGCGT"}; // 1 error, substitution in query sequence TSequence query{"CTCGAGGGTTTACGCATATCTGG" "TAACCG" "G" "AGAACACG" "A" "AGAGCCTGAGA"}; @@ -220,7 +220,7 @@ TEST(BestLocal, oneErrorSubstitution) EXPECT_EQ(stellar::StellarOptions{}.xDrop, xDrop); // default xDrop is 5 - using TAlignment = seqan::Align; + using TAlignment = seqan2::Align; std::vector alignments; stellar::verifySwiftHit( diff --git a/test/include/stellar/test/alignment_fragment.hpp b/test/include/stellar/test/alignment_fragment.hpp index df5f6f4ac..8460ae9bb 100644 --- a/test/include/stellar/test/alignment_fragment.hpp +++ b/test/include/stellar/test/alignment_fragment.hpp @@ -43,8 +43,8 @@ struct alignment_fragment sequence2, beginPosition2, endPosition2, row(alignment, 1)); } - using TSequence = seqan::String; - using TAlign = seqan::Align; + using TSequence = seqan2::String; + using TAlign = seqan2::Align; TSequence sequence1{}; TSequence sequence2{}; diff --git a/test/include/stellar/test/error_rate.hpp b/test/include/stellar/test/error_rate.hpp index c6a8ca6b5..f82a62d75 100644 --- a/test/include/stellar/test/error_rate.hpp +++ b/test/include/stellar/test/error_rate.hpp @@ -17,7 +17,7 @@ struct error_rate_t }; template -error_rate_t error_rate(seqan::Align const & alignment) +error_rate_t error_rate(seqan2::Align const & alignment) { auto const & gappedSequence1 = row(alignment, 0); auto const & gappedSequence2 = row(alignment, 1); diff --git a/test/include/stellar/test/fixture/512_simSeq_5e-2.hpp b/test/include/stellar/test/fixture/512_simSeq_5e-2.hpp index 3eec8afc8..12cb69084 100644 --- a/test/include/stellar/test/fixture/512_simSeq_5e-2.hpp +++ b/test/include/stellar/test/fixture/512_simSeq_5e-2.hpp @@ -16,7 +16,7 @@ namespace stellar::test::fixture::a512_simSeq_0dot05::forward // best match // seq1 Stellar eps-matches 203842 204051 95.3051 + . seq2;seq2Range=797542,797749;cigar=41M1D48M1D39M1I49M1D5M1I17M1D1M1D3M1I2M;mutations=27A,129A,148T,184C,206A -static stellar::test::alignment_fragment const fragment0 +static stellar::test::alignment_fragment const fragment0 { "TTTGAAAAAACTTACTTGTCAATTT[", "AACGGGGTTGAACCAATTATTCATC[", diff --git a/test/include/stellar/test/prefilter/expect_storage.hpp b/test/include/stellar/test/prefilter/expect_storage.hpp index 53561be70..4027cb7fb 100644 --- a/test/include/stellar/test/prefilter/expect_storage.hpp +++ b/test/include/stellar/test/prefilter/expect_storage.hpp @@ -37,7 +37,7 @@ bool expectStorage(std::vector> stora // do all segments cover the complete sequence? { - using TKey = seqan::String const *; + using TKey = seqan2::String const *; using TInterval = std::pair; std::unordered_map intervalMap{}; @@ -61,7 +61,7 @@ bool expectStorage(std::vector> stora for (auto && [key, interval] : intervalMap) { - seqan::String const & database = *key; + seqan2::String const & database = *key; noErrors = noErrors && (interval.first == 0u); EXPECT_EQ(interval.first, 0u); From 7d423b91dd2739769eaae79c936703ba5f990a54 Mon Sep 17 00:00:00 2001 From: Evelin Aasna Date: Mon, 22 May 2023 13:35:10 +0200 Subject: [PATCH 03/20] Get segment from const database --- include/stellar/stellar_database_segment.hpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/include/stellar/stellar_database_segment.hpp b/include/stellar/stellar_database_segment.hpp index 8d5a47dee..0d2c97893 100644 --- a/include/stellar/stellar_database_segment.hpp +++ b/include/stellar/stellar_database_segment.hpp @@ -79,12 +79,10 @@ TStorage _getDatabaseSegments(StringSet> & databases, StellarO return databaseSegments; } -template -TStorage _getDatabaseSegmentForValik(String const & sequenceOfInterest, - StellarOptions const & options, - bool const reverse = false) +template +TDatabaseSegment _getDREAMDatabaseSegment(String const & sequenceOfInterest, + StellarOptions const & options) { - TStorage databaseSegments{}; if (length(sequenceOfInterest) < options.segmentEnd) throw std::runtime_error{"Segment end out of range"}; @@ -94,15 +92,9 @@ TStorage _getDatabaseSegmentForValik(String const & sequenceOfInteres if (options.segmentEnd < options.minLength + options.segmentBegin) throw std::runtime_error{"Segment shorter than minimum match length"}; - if (reverse) - { - reverseComplement(sequenceOfInterest); - databaseSegments.emplace_back(sequenceOfInterest, length(sequenceOfInterest) - options.segmentEnd, length(sequenceOfInterest) - options.segmentBegin); - } - else - databaseSegments.emplace_back(sequenceOfInterest, options.segmentBegin, options.segmentEnd); + TDatabaseSegment databaseSegment(sequenceOfInterest, options.segmentBegin, options.segmentEnd); - return databaseSegments; + return databaseSegment; } } // namespace stellar From 814cd0896a24bf1ab0d9ba6384af404e5f019e9d Mon Sep 17 00:00:00 2001 From: Evelin Aasna Date: Wed, 14 Jun 2023 15:12:21 +0200 Subject: [PATCH 04/20] expose _writeCalculatedParams function --- include/stellar/app/stellar.diagnostics.hpp | 1 + include/stellar/app/stellar.diagnostics.tpp | 22 +++++++++++++++++++++ src/stellar/stellar.diagnostics.cpp | 22 --------------------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/include/stellar/app/stellar.diagnostics.hpp b/include/stellar/app/stellar.diagnostics.hpp index 923084c86..27eafbc69 100644 --- a/include/stellar/app/stellar.diagnostics.hpp +++ b/include/stellar/app/stellar.diagnostics.hpp @@ -11,6 +11,7 @@ namespace app /////////////////////////////////////////////////////////////////////////////// // Calculates parameters from parameters in options object and writes them to std::cout +// Sets options.qGram if not set by user input void _writeCalculatedParams(StellarOptions & options); /////////////////////////////////////////////////////////////////////////////// diff --git a/include/stellar/app/stellar.diagnostics.tpp b/include/stellar/app/stellar.diagnostics.tpp index ca97f02d9..4a32b3f79 100644 --- a/include/stellar/app/stellar.diagnostics.tpp +++ b/include/stellar/app/stellar.diagnostics.tpp @@ -8,6 +8,28 @@ namespace stellar namespace app { +/////////////////////////////////////////////////////////////////////////////// +// Calculates parameters from parameters in options object and writes them to std::cout +void _writeCalculatedParams(StellarOptions & options) +{ +//IOREV _notio_ + StellarStatistics statistics{options}; + + std::cout << "Calculated parameters:" << std::endl; + if (statistics.kMerComputed) + { + options.qGram = (unsigned)statistics.kMerLength; + std::cout << " k-mer length : " << statistics.kMerLength << std::endl; + } + + std::cout << " s^min : " << statistics.smin << std::endl; + std::cout << " threshold : " << statistics.threshold << std::endl; + std::cout << " distance cut : " << statistics.distanceCut << std::endl; + std::cout << " delta : " << statistics.delta << std::endl; + std::cout << " overlap : " << statistics.overlap << std::endl; + std::cout << std::endl; +} + /////////////////////////////////////////////////////////////////////////////// // Calculates parameters from parameters in options object and from sequences and writes them to std::cout template diff --git a/src/stellar/stellar.diagnostics.cpp b/src/stellar/stellar.diagnostics.cpp index 952824507..520966833 100644 --- a/src/stellar/stellar.diagnostics.cpp +++ b/src/stellar/stellar.diagnostics.cpp @@ -6,28 +6,6 @@ namespace stellar namespace app { -/////////////////////////////////////////////////////////////////////////////// -// Calculates parameters from parameters in options object and writes them to std::cout -void _writeCalculatedParams(StellarOptions & options) -{ -//IOREV _notio_ - StellarStatistics statistics{options}; - - std::cout << "Calculated parameters:" << std::endl; - if (statistics.kMerComputed) - { - options.qGram = (unsigned)statistics.kMerLength; - std::cout << " k-mer length : " << statistics.kMerLength << std::endl; - } - - std::cout << " s^min : " << statistics.smin << std::endl; - std::cout << " threshold : " << statistics.threshold << std::endl; - std::cout << " distance cut : " << statistics.distanceCut << std::endl; - std::cout << " delta : " << statistics.delta << std::endl; - std::cout << " overlap : " << statistics.overlap << std::endl; - std::cout << std::endl; -} - /////////////////////////////////////////////////////////////////////////////// // Writes user specified parameters from options object to std::cout void _writeSpecifiedParams(StellarOptions const & options) From a1985b7364be50328f2bc4e0e3c7818404b9ba72 Mon Sep 17 00:00:00 2001 From: Evelin Aasna Date: Fri, 26 May 2023 15:27:16 +0200 Subject: [PATCH 05/20] Extract diagnostics and stellar launcher from app namespace --- include/stellar/app/stellar.main.tpp | 149 ++---------------- .../print.hpp} | 5 - .../print.tpp} | 7 +- include/stellar/stellar.hpp | 2 +- include/stellar/stellar_launcher.hpp | 136 ++++++++++++++++ src/stellar.cpp | 2 +- src/stellar/stellar.diagnostics.cpp | 7 +- 7 files changed, 150 insertions(+), 158 deletions(-) rename include/stellar/{app/stellar.diagnostics.hpp => diagnostics/print.hpp} (97%) rename include/stellar/{app/stellar.diagnostics.tpp => diagnostics/print.tpp} (97%) create mode 100644 include/stellar/stellar_launcher.hpp diff --git a/include/stellar/app/stellar.main.tpp b/include/stellar/app/stellar.main.tpp index 7b277f553..9278e39c2 100644 --- a/include/stellar/app/stellar.main.tpp +++ b/include/stellar/app/stellar.main.tpp @@ -31,18 +31,16 @@ #include +#include #include #include +#include #include +#include #include -#include -#include -#include #include -#include - -#include +#include namespace stellar { @@ -71,133 +69,6 @@ namespace stellar namespace app { -template -bool _shouldWriteOutputFile(bool const databaseStrand, StringSet const, TId> > > const & matches) -{ - // if databaseStrand == true always outputs - // if databaseStrand == false only outputs if TAlphabet == Dna5 or TAlphabet == Rna5 - return databaseStrand || IsSameType::VALUE || IsSameType::VALUE; -} - -template -void _postproccessQueryMatches(bool const databaseStrand, uint64_t const & refLen, - StellarOptions const & options, - StringSet const, TId> > > & matches, - std::vector & disabledQueryIDs) -{ - using TSequence = String; - - for (size_t queryID = 0; queryID < length(matches); ++queryID) - { - QueryMatches> & queryMatches = value(matches, queryID); - - queryMatches.removeOverlapsAndCompactMatches(options.disableThresh, - /*compactThresh*/ 0, - options.minLength, - options.numMatches); - - if (queryMatches.disabled) - disabledQueryIDs.push_back(queryID); - } - - // adjust length for each matches of a single query (only for dna5 and rna5) - // TODO: WHY? This seems like an arbitrary restriction - if (_shouldWriteOutputFile(databaseStrand, matches)) - _postproccessLengthAdjustment(refLen, matches); -} - -template -struct StellarApp -{ - template - static constexpr StellarComputeStatistics _verificationMethodVisit( - StellarVerificationMethod verificationMethod, - visitor_fn_t && visitor_fn - ) - { - if (verificationMethod == StellarVerificationMethod{AllLocal{}}) - return visitor_fn(AllLocal()); - else if (verificationMethod == StellarVerificationMethod{BestLocal{}}) - return visitor_fn(BestLocal()); - else if (verificationMethod == StellarVerificationMethod{BandedGlobal{}}) - return visitor_fn(BandedGlobal()); - else if (verificationMethod == StellarVerificationMethod{BandedGlobalExtend{}}) - return visitor_fn(BandedGlobalExtend()); - return StellarComputeStatistics{}; - } - - static StellarComputeStatistics - search_and_verify( - StellarDatabaseSegment const databaseSegment, - TId const & databaseID, - QueryIDMap const & queryIDMap, - bool const databaseStrand, - StellarOptions & localOptions, // localOptions.compactThresh is out-param - StellarSwiftPattern & localSwiftPattern, - stellar::stellar_kernel_runtime & strand_runtime, - StringSet const, TId> > > & localMatches - ) - { - using TSequence = String; - - auto getQueryMatches = [&](auto const & pattern) -> QueryMatches > & - { - // Note: Index is normally build over all queries [query0, query1, query2, ...], - // but in LocalQueryPrefilter case it can just be build over [query0]. - // We need to translate that position to a "record" ID - //!TODO: this shouldn't be necessary - // each Stellar instance should be given a set of bin query, all of which should be indexed - size_t const queryRecordID = queryIDMap.recordID(pattern); - return value(localMatches, queryRecordID); - }; - - auto isPatternDisabled = [&](StellarSwiftPattern & pattern) -> bool { - QueryMatches > & queryMatches = getQueryMatches(pattern); - return queryMatches.disabled; - }; - - auto onAlignmentResult = [&](auto & alignment) -> bool { - QueryMatches > & queryMatches = getQueryMatches(localSwiftPattern); - - StellarMatch match(alignment, databaseID, databaseStrand); - length(match); // DEBUG: Contains assertion on clipping. - - // success - return _insertMatch( - queryMatches, - match, - localOptions.minLength, - localOptions.disableThresh, - // compactThresh is basically an output-parameter; will be updated in kernel and propagated back - // outside of this function, the reason why StellarOptions can't be passed as const to this function. - // TODO: We might want to make this tied to the QueryMatches itself, as it should know then to consolidate - // the matches - localOptions.compactThresh, - localOptions.numMatches - ); - }; - - // finder - StellarSwiftFinder swiftFinder(databaseSegment.asInfixSegment(), localOptions.minRepeatLength, localOptions.maxRepeatPeriod); - - StellarComputeStatistics statistics = _verificationMethodVisit( - localOptions.verificationMethod, - [&](auto tag) -> StellarComputeStatistics - { - using TTag = decltype(tag); - SwiftHitVerifier swiftVerifier - { - STELLAR_DESIGNATED_INITIALIZER(.eps_match_options = , localOptions), - STELLAR_DESIGNATED_INITIALIZER(.verifier_options = , localOptions), - }; - - return _stellarKernel(swiftFinder, localSwiftPattern, swiftVerifier, isPatternDisabled, onAlignmentResult, strand_runtime); - }); - - return statistics; - } -}; - /////////////////////////////////////////////////////////////////////////////// // Creates database segments and calls search_and_verify on each of them template @@ -260,7 +131,7 @@ _stellarMain( size_t const databaseRecordID = databaseIDMap.recordID(databaseSegment); TId const & databaseID = databaseIDMap.databaseID(databaseRecordID); - StellarComputeStatistics statistics = StellarApp::search_and_verify + StellarComputeStatistics statistics = StellarLauncher::search_and_verify ( databaseSegment, databaseID, @@ -326,7 +197,7 @@ _stellarMain( size_t const databaseRecordID = databaseIDMap.recordID(databaseSegment); TId const & databaseID = databaseIDMap.databaseID(databaseRecordID); - StellarComputeStatistics statistics = StellarApp::search_and_verify + StellarComputeStatistics statistics = StellarLauncher::search_and_verify ( databaseSegment, databaseID, @@ -388,11 +259,11 @@ int mainWithOptions(StellarOptions & options, String) auto current_time = stellar_time.now(); // output file names - stellar::app::_writeFileNames(options); + stellar::_writeFileNames(options); // output parameters - stellar::app::_writeSpecifiedParams(options); - stellar::app::_writeCalculatedParams(options); + stellar::_writeSpecifiedParams(options); + stellar::_writeCalculatedParams(options); // import query sequences StringSet queries; @@ -434,7 +305,7 @@ int mainWithOptions(StellarOptions & options, String) return 1; std::cout << std::endl; - stellar::app::_writeMoreCalculatedParams(options, refLen, queries); + stellar::_writeMoreCalculatedParams(options, refLen, queries); // open output files std::ofstream outputFile(options.outputFile.c_str(), ::std::ios_base::out | ::std::ios_base::app); diff --git a/include/stellar/app/stellar.diagnostics.hpp b/include/stellar/diagnostics/print.hpp similarity index 97% rename from include/stellar/app/stellar.diagnostics.hpp rename to include/stellar/diagnostics/print.hpp index 27eafbc69..b945066d6 100644 --- a/include/stellar/app/stellar.diagnostics.hpp +++ b/include/stellar/diagnostics/print.hpp @@ -6,9 +6,6 @@ namespace stellar { -namespace app -{ - /////////////////////////////////////////////////////////////////////////////// // Calculates parameters from parameters in options object and writes them to std::cout // Sets options.qGram if not set by user input @@ -43,6 +40,4 @@ void _printStellarStatistics( StringSet const & databaseIDs, StellarComputeStatisticsCollection const & computeStatistics); -} // namespace stellar::app - } // namespace stellar diff --git a/include/stellar/app/stellar.diagnostics.tpp b/include/stellar/diagnostics/print.tpp similarity index 97% rename from include/stellar/app/stellar.diagnostics.tpp rename to include/stellar/diagnostics/print.tpp index 4a32b3f79..d7bd8b488 100644 --- a/include/stellar/app/stellar.diagnostics.tpp +++ b/include/stellar/diagnostics/print.tpp @@ -1,13 +1,10 @@ #pragma once -#include +#include namespace stellar { -namespace app -{ - /////////////////////////////////////////////////////////////////////////////// // Calculates parameters from parameters in options object and writes them to std::cout void _writeCalculatedParams(StellarOptions & options) @@ -81,6 +78,4 @@ void _writeMoreCalculatedParams(StellarOptions const & options, TSize const & re } } -} // namespace stellar::app - } // namespace stellar diff --git a/include/stellar/stellar.hpp b/include/stellar/stellar.hpp index 993d37bc7..947baf61f 100755 --- a/include/stellar/stellar.hpp +++ b/include/stellar/stellar.hpp @@ -40,7 +40,7 @@ #include #include -#include +#include namespace stellar { diff --git a/include/stellar/stellar_launcher.hpp b/include/stellar/stellar_launcher.hpp new file mode 100644 index 000000000..49408656e --- /dev/null +++ b/include/stellar/stellar_launcher.hpp @@ -0,0 +1,136 @@ +#pragma once + +#include +#include + +namespace stellar +{ + +template +bool _shouldWriteOutputFile(bool const databaseStrand, StringSet const, TId> > > const & matches) +{ + // if databaseStrand == true always outputs + // if databaseStrand == false only outputs if TAlphabet == Dna5 or TAlphabet == Rna5 + return databaseStrand || IsSameType::VALUE || IsSameType::VALUE; +} + +template +void _postproccessQueryMatches(bool const databaseStrand, uint64_t const & refLen, + StellarOptions const & options, + StringSet const, TId> > > & matches, + std::vector & disabledQueryIDs) +{ + using TSequence = String; + + for (size_t queryID = 0; queryID < length(matches); ++queryID) + { + QueryMatches> & queryMatches = value(matches, queryID); + + queryMatches.removeOverlapsAndCompactMatches(options.disableThresh, + /*compactThresh*/ 0, + options.minLength, + options.numMatches); + + if (queryMatches.disabled) + disabledQueryIDs.push_back(queryID); + } + + // adjust length for each matches of a single query (only for dna5 and rna5) + // TODO: WHY? This seems like an arbitrary restriction + if (_shouldWriteOutputFile(databaseStrand, matches)) + _postproccessLengthAdjustment(refLen, matches); +} + +template +struct StellarLauncher +{ + template + static constexpr StellarComputeStatistics _verificationMethodVisit( + StellarVerificationMethod verificationMethod, + visitor_fn_t && visitor_fn + ) + { + if (verificationMethod == StellarVerificationMethod{AllLocal{}}) + return visitor_fn(AllLocal()); + else if (verificationMethod == StellarVerificationMethod{BestLocal{}}) + return visitor_fn(BestLocal()); + else if (verificationMethod == StellarVerificationMethod{BandedGlobal{}}) + return visitor_fn(BandedGlobal()); + else if (verificationMethod == StellarVerificationMethod{BandedGlobalExtend{}}) + return visitor_fn(BandedGlobalExtend()); + return StellarComputeStatistics{}; + } + + static StellarComputeStatistics + search_and_verify( + StellarDatabaseSegment const databaseSegment, + TId const & databaseID, + QueryIDMap const & queryIDMap, + bool const databaseStrand, + StellarOptions & localOptions, // localOptions.compactThresh is out-param + StellarSwiftPattern & localSwiftPattern, + stellar::stellar_kernel_runtime & strand_runtime, + StringSet const, TId> > > & localMatches + ) + { + using TSequence = String; + + auto getQueryMatches = [&](auto const & pattern) -> QueryMatches > & + { + // Note: Index is normally build over all queries [query0, query1, query2, ...], + // but in LocalQueryPrefilter case it can just be build over [query0]. + // We need to translate that position to a "record" ID + //!TODO: this shouldn't be necessary + // each Stellar instance should be given a set of bin query, all of which should be indexed + size_t const queryRecordID = queryIDMap.recordID(pattern); + return value(localMatches, queryRecordID); + }; + + auto isPatternDisabled = [&](StellarSwiftPattern & pattern) -> bool { + QueryMatches > & queryMatches = getQueryMatches(pattern); + return queryMatches.disabled; + }; + + auto onAlignmentResult = [&](auto & alignment) -> bool { + QueryMatches > & queryMatches = getQueryMatches(localSwiftPattern); + + StellarMatch match(alignment, databaseID, databaseStrand); + length(match); // DEBUG: Contains assertion on clipping. + + // success + return _insertMatch( + queryMatches, + match, + localOptions.minLength, + localOptions.disableThresh, + // compactThresh is basically an output-parameter; will be updated in kernel and propagated back + // outside of this function, the reason why StellarOptions can't be passed as const to this function. + // TODO: We might want to make this tied to the QueryMatches itself, as it should know then to consolidate + // the matches + localOptions.compactThresh, + localOptions.numMatches + ); + }; + + // finder + StellarSwiftFinder swiftFinder(databaseSegment.asInfixSegment(), localOptions.minRepeatLength, localOptions.maxRepeatPeriod); + + StellarComputeStatistics statistics = _verificationMethodVisit( + localOptions.verificationMethod, + [&](auto tag) -> StellarComputeStatistics + { + using TTag = decltype(tag); + SwiftHitVerifier swiftVerifier + { + STELLAR_DESIGNATED_INITIALIZER(.eps_match_options = , localOptions), + STELLAR_DESIGNATED_INITIALIZER(.verifier_options = , localOptions), + }; + + return _stellarKernel(swiftFinder, localSwiftPattern, swiftVerifier, isPatternDisabled, onAlignmentResult, strand_runtime); + }); + + return statistics; + } +}; + +} // namespace stellar diff --git a/src/stellar.cpp b/src/stellar.cpp index d9cd6de5a..467d4d3e7 100644 --- a/src/stellar.cpp +++ b/src/stellar.cpp @@ -30,7 +30,7 @@ #include #include -#include +#include #include #include diff --git a/src/stellar/stellar.diagnostics.cpp b/src/stellar/stellar.diagnostics.cpp index 520966833..19b785f29 100644 --- a/src/stellar/stellar.diagnostics.cpp +++ b/src/stellar/stellar.diagnostics.cpp @@ -1,11 +1,8 @@ -#include +#include namespace stellar { -namespace app -{ - /////////////////////////////////////////////////////////////////////////////// // Writes user specified parameters from options object to std::cout void _writeSpecifiedParams(StellarOptions const & options) @@ -116,6 +113,4 @@ void _printStellarStatistics( } } -} // namespace stellar::app - } // namespace stellar From 4778d40937a6931eb32e1f3b1a03f02334cc3e40 Mon Sep 17 00:00:00 2001 From: Evelin Aasna Date: Thu, 15 Jun 2023 10:02:53 +0200 Subject: [PATCH 06/20] Fix linker error --- include/stellar/diagnostics/print.hpp | 5 +++-- include/stellar/diagnostics/print.tpp | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/stellar/diagnostics/print.hpp b/include/stellar/diagnostics/print.hpp index b945066d6..8b9d01226 100644 --- a/include/stellar/diagnostics/print.hpp +++ b/include/stellar/diagnostics/print.hpp @@ -6,10 +6,11 @@ namespace stellar { -/////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// // Calculates parameters from parameters in options object and writes them to std::cout // Sets options.qGram if not set by user input -void _writeCalculatedParams(StellarOptions & options); +template +void _writeCalculatedParams(TOptions & options); /////////////////////////////////////////////////////////////////////////////// // Writes user specified parameters from options object to std::cout diff --git a/include/stellar/diagnostics/print.tpp b/include/stellar/diagnostics/print.tpp index d7bd8b488..84c372e9f 100644 --- a/include/stellar/diagnostics/print.tpp +++ b/include/stellar/diagnostics/print.tpp @@ -7,7 +7,9 @@ namespace stellar /////////////////////////////////////////////////////////////////////////////// // Calculates parameters from parameters in options object and writes them to std::cout -void _writeCalculatedParams(StellarOptions & options) +// Sets options.qGram if not set by user input +template +void _writeCalculatedParams(TOptions & options) { //IOREV _notio_ StellarStatistics statistics{options}; From a6520c3466b4211b0f80384b087f209234f97069 Mon Sep 17 00:00:00 2001 From: Evelin Aasna Date: Thu, 15 Jun 2023 16:25:32 +0200 Subject: [PATCH 07/20] Revert stellar diagnostics (compiled lib) --- include/stellar/diagnostics/print.hpp | 3 +-- include/stellar/diagnostics/print.tpp | 24 ------------------------ src/stellar/stellar.diagnostics.cpp | 23 +++++++++++++++++++++++ 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/include/stellar/diagnostics/print.hpp b/include/stellar/diagnostics/print.hpp index 8b9d01226..1f5472528 100644 --- a/include/stellar/diagnostics/print.hpp +++ b/include/stellar/diagnostics/print.hpp @@ -9,8 +9,7 @@ namespace stellar ////////////////////////////////////////////////////////////////////////////// // Calculates parameters from parameters in options object and writes them to std::cout // Sets options.qGram if not set by user input -template -void _writeCalculatedParams(TOptions & options); +void _writeCalculatedParams(StellarOptions & options); /////////////////////////////////////////////////////////////////////////////// // Writes user specified parameters from options object to std::cout diff --git a/include/stellar/diagnostics/print.tpp b/include/stellar/diagnostics/print.tpp index 84c372e9f..9b6b88177 100644 --- a/include/stellar/diagnostics/print.tpp +++ b/include/stellar/diagnostics/print.tpp @@ -5,30 +5,6 @@ namespace stellar { -/////////////////////////////////////////////////////////////////////////////// -// Calculates parameters from parameters in options object and writes them to std::cout -// Sets options.qGram if not set by user input -template -void _writeCalculatedParams(TOptions & options) -{ -//IOREV _notio_ - StellarStatistics statistics{options}; - - std::cout << "Calculated parameters:" << std::endl; - if (statistics.kMerComputed) - { - options.qGram = (unsigned)statistics.kMerLength; - std::cout << " k-mer length : " << statistics.kMerLength << std::endl; - } - - std::cout << " s^min : " << statistics.smin << std::endl; - std::cout << " threshold : " << statistics.threshold << std::endl; - std::cout << " distance cut : " << statistics.distanceCut << std::endl; - std::cout << " delta : " << statistics.delta << std::endl; - std::cout << " overlap : " << statistics.overlap << std::endl; - std::cout << std::endl; -} - /////////////////////////////////////////////////////////////////////////////// // Calculates parameters from parameters in options object and from sequences and writes them to std::cout template diff --git a/src/stellar/stellar.diagnostics.cpp b/src/stellar/stellar.diagnostics.cpp index 19b785f29..0630289f7 100644 --- a/src/stellar/stellar.diagnostics.cpp +++ b/src/stellar/stellar.diagnostics.cpp @@ -3,6 +3,29 @@ namespace stellar { +/////////////////////////////////////////////////////////////////////////////// +// Calculates parameters from parameters in options object and writes them to std::cout +// Sets options.qGram if not set by user input +void _writeCalculatedParams(StellarOptions & options) +{ +//IOREV _notio_ + StellarStatistics statistics{options}; + + std::cout << "Calculated parameters:" << std::endl; + if (statistics.kMerComputed) + { + options.qGram = (unsigned)statistics.kMerLength; + std::cout << " k-mer length : " << statistics.kMerLength << std::endl; + } + + std::cout << " s^min : " << statistics.smin << std::endl; + std::cout << " threshold : " << statistics.threshold << std::endl; + std::cout << " distance cut : " << statistics.distanceCut << std::endl; + std::cout << " delta : " << statistics.delta << std::endl; + std::cout << " overlap : " << statistics.overlap << std::endl; + std::cout << std::endl; +} + /////////////////////////////////////////////////////////////////////////////// // Writes user specified parameters from options object to std::cout void _writeSpecifiedParams(StellarOptions const & options) From 7e534762af1eaa464b12ba5577f0b375384ba0ca Mon Sep 17 00:00:00 2001 From: Evelin Aasna Date: Fri, 16 Jun 2023 09:59:54 +0200 Subject: [PATCH 08/20] Try outstream template parameter --- include/stellar/app/stellar.main.tpp | 2 +- include/stellar/diagnostics/print.hpp | 3 ++- include/stellar/diagnostics/print.tpp | 19 +++++++++++++++++++ src/stellar/stellar.diagnostics.cpp | 18 ------------------ 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/include/stellar/app/stellar.main.tpp b/include/stellar/app/stellar.main.tpp index 9278e39c2..547902072 100644 --- a/include/stellar/app/stellar.main.tpp +++ b/include/stellar/app/stellar.main.tpp @@ -259,7 +259,7 @@ int mainWithOptions(StellarOptions & options, String) auto current_time = stellar_time.now(); // output file names - stellar::_writeFileNames(options); + stellar::_writeFileNames(options, std::cout); // output parameters stellar::_writeSpecifiedParams(options); diff --git a/include/stellar/diagnostics/print.hpp b/include/stellar/diagnostics/print.hpp index 1f5472528..140288b3d 100644 --- a/include/stellar/diagnostics/print.hpp +++ b/include/stellar/diagnostics/print.hpp @@ -17,7 +17,8 @@ void _writeSpecifiedParams(StellarOptions const & options); /////////////////////////////////////////////////////////////////////////////// // Writes file name from options object to std::cout -void _writeFileNames(StellarOptions const & options); +template +void _writeFileNames(StellarOptions const & options, TStream & outStr); /////////////////////////////////////////////////////////////////////////////// // Calculates parameters from parameters in options object and from sequences and writes them to std::cout diff --git a/include/stellar/diagnostics/print.tpp b/include/stellar/diagnostics/print.tpp index 9b6b88177..00e917616 100644 --- a/include/stellar/diagnostics/print.tpp +++ b/include/stellar/diagnostics/print.tpp @@ -5,6 +5,25 @@ namespace stellar { +/////////////////////////////////////////////////////////////////////////////// +// Writes file name from options object to std::cout +template +void _writeFileNames(StellarOptions const & options, TStream & outStr) +{ +//IOREV _notio_ + outStr << "I/O options:" << std::endl; + outStr << " database file : " << options.databaseFile << std::endl; + outStr << " query file : " << options.queryFile << std::endl; + outStr << " alphabet : " << options.alphabet << std::endl; + outStr << " output file : " << options.outputFile << std::endl; + outStr << " output format : " << options.outputFormat << std::endl; + if (options.disableThresh != std::numeric_limits::max()) + { + outStr << " disabled queries: " << options.disabledQueriesFile << std::endl; + } + outStr << std::endl; +} + /////////////////////////////////////////////////////////////////////////////// // Calculates parameters from parameters in options object and from sequences and writes them to std::cout template diff --git a/src/stellar/stellar.diagnostics.cpp b/src/stellar/stellar.diagnostics.cpp index 0630289f7..3734669ac 100644 --- a/src/stellar/stellar.diagnostics.cpp +++ b/src/stellar/stellar.diagnostics.cpp @@ -62,24 +62,6 @@ void _writeSpecifiedParams(StellarOptions const & options) std::cout << std::endl; } -/////////////////////////////////////////////////////////////////////////////// -// Writes file name from options object to std::cout -void _writeFileNames(StellarOptions const & options) -{ -//IOREV _notio_ - std::cout << "I/O options:" << std::endl; - std::cout << " database file : " << options.databaseFile << std::endl; - std::cout << " query file : " << options.queryFile << std::endl; - std::cout << " alphabet : " << options.alphabet << std::endl; - std::cout << " output file : " << options.outputFile << std::endl; - std::cout << " output format : " << options.outputFormat << std::endl; - if (options.disableThresh != std::numeric_limits::max()) - { - std::cout << " disabled queries: " << options.disabledQueriesFile << std::endl; - } - std::cout << std::endl; -} - void _writeOutputStatistics(StellarOutputStatistics const & statistics, bool const verbose, bool const writeDisabledQueriesFile) { std::cout << "# Eps-matches : " << statistics.numMatches << std::endl; From d85e9b612b1b11bf73ff2dac2b353fe60fc01c19 Mon Sep 17 00:00:00 2001 From: Evelin Aasna Date: Fri, 16 Jun 2023 11:55:00 +0200 Subject: [PATCH 09/20] Make header only --- include/stellar/app/stellar.main.tpp | 16 +- include/stellar/diagnostics/print.hpp | 41 +++-- include/stellar/diagnostics/print.tpp | 157 ++++++++++++++++-- include/stellar/io/import_sequence.hpp | 12 +- src/CMakeLists.txt | 5 +- src/stellar.cpp | 1 - src/stellar/stellar.diagnostics.cpp | 121 -------------- .../stellar/stellar_import_sequence_test.cpp | 2 +- 8 files changed, 189 insertions(+), 166 deletions(-) delete mode 100644 src/stellar/stellar.diagnostics.cpp diff --git a/include/stellar/app/stellar.main.tpp b/include/stellar/app/stellar.main.tpp index 547902072..9d6ff1c13 100644 --- a/include/stellar/app/stellar.main.tpp +++ b/include/stellar/app/stellar.main.tpp @@ -146,7 +146,7 @@ _stellarMain( computeStatistics.addStatistics(statistics); } - _printStellarStatistics(options.verbose, databaseStrand, databaseIDs, computeStatistics); + _printStellarStatistics(options.verbose, databaseStrand, databaseIDs, computeStatistics, std::cout); stellar_runtime.forward_strand_stellar_time.post_process_eps_matches_time.measure_time([&]() { @@ -212,7 +212,7 @@ _stellarMain( computeStatistics.addStatistics(statistics); } - _printStellarStatistics(options.verbose, databaseStrand, databaseIDs, computeStatistics); + _printStellarStatistics(options.verbose, databaseStrand, databaseIDs, computeStatistics, std::cout); stellar_runtime.reverse_strand_stellar_time.post_process_eps_matches_time.measure_time([&]() { @@ -243,7 +243,7 @@ _stellarMain( }); // measure_time } - _writeOutputStatistics(outputStatistics, options.verbose, disabledQueriesFile.is_open()); + _writeOutputStatistics(outputStatistics, options.verbose, disabledQueriesFile.is_open(), std::cout); return true; } @@ -262,8 +262,8 @@ int mainWithOptions(StellarOptions & options, String) stellar::_writeFileNames(options, std::cout); // output parameters - stellar::_writeSpecifiedParams(options); - stellar::_writeCalculatedParams(options); + stellar::_writeSpecifiedParams(options, std::cout); + stellar::_writeCalculatedParams(options, std::cout); // import query sequences StringSet queries; @@ -274,7 +274,7 @@ int mainWithOptions(StellarOptions & options, String) //!TODO: split query sequence bool const queriesSuccess = stellar_time.input_queries_time.measure_time([&]() { - return _importAllSequences(options.queryFile.c_str(), "query", queries, queryIDs, queryLen); + return _importAllSequences(options.queryFile.c_str(), "query", queries, queryIDs, queryLen, std::cout, std::cerr); }); if (!queriesSuccess) return 1; @@ -287,7 +287,7 @@ int mainWithOptions(StellarOptions & options, String) bool const databasesSuccess = stellar_time.input_databases_time.measure_time([&]() { if (!options.prefilteredSearch) - return _importAllSequences(options.databaseFile.c_str(), "database", databases, databaseIDs, refLen); + return _importAllSequences(options.databaseFile.c_str(), "database", databases, databaseIDs, refLen, std::cout, std::cerr); else { if (options.referenceLength > 0) @@ -305,7 +305,7 @@ int mainWithOptions(StellarOptions & options, String) return 1; std::cout << std::endl; - stellar::_writeMoreCalculatedParams(options, refLen, queries); + stellar::_writeMoreCalculatedParams(options, refLen, queries, std::cout); // open output files std::ofstream outputFile(options.outputFile.c_str(), ::std::ios_base::out | ::std::ios_base::app); diff --git a/include/stellar/diagnostics/print.hpp b/include/stellar/diagnostics/print.hpp index 140288b3d..2d922fc93 100644 --- a/include/stellar/diagnostics/print.hpp +++ b/include/stellar/diagnostics/print.hpp @@ -2,43 +2,60 @@ #pragma once #include +#include namespace stellar { -////////////////////////////////////////////////////////////////////////////// -// Calculates parameters from parameters in options object and writes them to std::cout +/////////////////////////////////////////////////////////////////////////////// +// Calculates parameters from parameters in options object and writes them to outStr // Sets options.qGram if not set by user input -void _writeCalculatedParams(StellarOptions & options); +template +void _writeCalculatedParams(StellarOptions & options, TStream & outStr); /////////////////////////////////////////////////////////////////////////////// -// Writes user specified parameters from options object to std::cout -void _writeSpecifiedParams(StellarOptions const & options); +// Writes user specified parameters from options object to outStr +template +void _writeSpecifiedParams(StellarOptions const & options, TStream & outStr); /////////////////////////////////////////////////////////////////////////////// -// Writes file name from options object to std::cout +// Writes file name from options object to outStr template void _writeFileNames(StellarOptions const & options, TStream & outStr); /////////////////////////////////////////////////////////////////////////////// -// Calculates parameters from parameters in options object and from sequences and writes them to std::cout -template -void _writeMoreCalculatedParams(StellarOptions const & options, TStringSet const & databases, TStringSet const & queries); +// Calculates parameters from parameters in options object and from sequences and writes them to outStr +template +void _writeMoreCalculatedParams(StellarOptions const & options, + TSize const & refLen, + TStringSet const & queries, + TStream & outStr); void _writeOutputStatistics(StellarOutputStatistics const & statistics, bool const verbose, bool const writeDisabledQueriesFile); -void _printStellarKernelStatistics(StellarComputeStatistics const & statistics); +template +void _printStellarKernelStatistics(StellarComputeStatistics const & statistics, TStream & outStr); +template void _printDatabaseIdAndStellarKernelStatistics( bool const verbose, bool const databaseStrand, CharString const & databaseID, - StellarComputeStatistics const & statistics); + StellarComputeStatistics const & statistics, + TStream & outStr); +template void _printStellarStatistics( bool const verbose, bool const databaseStrand, StringSet const & databaseIDs, - StellarComputeStatisticsCollection const & computeStatistics); + StellarComputeStatisticsCollection const & computeStatistics, + TStream & outStr); + +template +void _writeOutputStatistics(StellarOutputStatistics const & statistics, + bool const verbose, + bool const writeDisabledQueriesFile, + TStream & outStr); } // namespace stellar diff --git a/include/stellar/diagnostics/print.tpp b/include/stellar/diagnostics/print.tpp index 00e917616..435c40f20 100644 --- a/include/stellar/diagnostics/print.tpp +++ b/include/stellar/diagnostics/print.tpp @@ -6,7 +6,68 @@ namespace stellar { /////////////////////////////////////////////////////////////////////////////// -// Writes file name from options object to std::cout +// Writes user specified parameters from options object to outStr +template +void _writeSpecifiedParams(StellarOptions const & options, TStream & outStr) +{ +//IOREV _notio_ + // Output user specified parameters + outStr << "User specified parameters:" << std::endl; + outStr << " minimal match length : " << options.minLength << std::endl; + outStr << " maximal error rate (epsilon) : " << options.epsilon << std::endl; + outStr << " maximal x-drop : " << options.xDrop << std::endl; + if (options.qGram != std::numeric_limits::max()) + outStr << " k-mer (q-gram) length : " << options.qGram << std::endl; + outStr << " search forward strand : " << ((options.forward) ? "yes" : "no") << std::endl; + outStr << " search reverse complement : " << ((options.reverse) ? "yes" : "no") << std::endl; + outStr << std::endl; + + outStr << " verification strategy : " << to_string(options.verificationMethod) << std::endl; + if (options.disableThresh != std::numeric_limits::max()) + { + outStr << " disable queries with more than : " << options.disableThresh << " matches" << std::endl; + } + outStr << " maximal number of matches : " << options.numMatches << std::endl; + outStr << " duplicate removal every : " << options.compactThresh << std::endl; + if (options.maxRepeatPeriod != 1 || options.minRepeatLength != 1000) + { + outStr << " max low complexity repeat period : " << options.maxRepeatPeriod << std::endl; + outStr << " min low complexity repeat length : " << options.minRepeatLength << std::endl; + } + if (options.qgramAbundanceCut != 1) + { + outStr << " q-gram abundance cut ratio : " << options.qgramAbundanceCut << std::endl; + } + + outStr << std::endl; +} + +/////////////////////////////////////////////////////////////////////////////// +// Calculates parameters from parameters in options object and writes them to outStr +// Sets options.qGram if not set by user input +template +void _writeCalculatedParams(StellarOptions & options, TStream & outStr) +{ +//IOREV _notio_ + StellarStatistics statistics{options}; + + outStr << "Calculated parameters:" << std::endl; + if (statistics.kMerComputed) + { + options.qGram = (unsigned)statistics.kMerLength; + outStr << " k-mer length : " << statistics.kMerLength << std::endl; + } + + outStr << " s^min : " << statistics.smin << std::endl; + outStr << " threshold : " << statistics.threshold << std::endl; + outStr << " distance cut : " << statistics.distanceCut << std::endl; + outStr << " delta : " << statistics.delta << std::endl; + outStr << " overlap : " << statistics.overlap << std::endl; + outStr << std::endl; +} + +/////////////////////////////////////////////////////////////////////////////// +// Writes file name from options object to outStr template void _writeFileNames(StellarOptions const & options, TStream & outStr) { @@ -25,26 +86,29 @@ void _writeFileNames(StellarOptions const & options, TStream & outStr) } /////////////////////////////////////////////////////////////////////////////// -// Calculates parameters from parameters in options object and from sequences and writes them to std::cout -template -void _writeMoreCalculatedParams(StellarOptions const & options, TSize const & refLen, TStringSet const & queries) +// Calculates parameters from parameters in options object and from sequences and writes them to outStr +template +void _writeMoreCalculatedParams(StellarOptions const & options, + TSize const & refLen, + TStringSet const & queries, + TStream & outStr) { //IOREV _notio_ typedef typename Value::Type>::Type TAlphabet; if (options.qgramAbundanceCut != 1) { - std::cout << "Calculated parameters:" << std::endl; + outStr << "Calculated parameters:" << std::endl; } TSize queryLength = length(concat(queries)); if (options.qgramAbundanceCut != 1) { - std::cout << " q-gram expected abundance : "; - std::cout << queryLength / (double)((long)1 << (options.qGram << 1)) << std::endl; - std::cout << " q-gram abundance threshold: "; - std::cout << _max(100, (int)(queryLength * options.qgramAbundanceCut)) << std::endl; - std::cout << std::endl; + outStr << " q-gram expected abundance : "; + outStr << queryLength / (double)((long)1 << (options.qGram << 1)) << std::endl; + outStr << " q-gram abundance threshold: "; + outStr << _max(100, (int)(queryLength * options.qgramAbundanceCut)) << std::endl; + outStr << std::endl; } if (IsSameType::VALUE || IsSameType::VALUE) @@ -67,11 +131,76 @@ void _writeMoreCalculatedParams(StellarOptions const & options, TSize const & re TSize errors = static_cast(options.minLength * options.epsilon); TSize minScore = options.minLength - 3 * errors; // #matches - 2*#errors // #matches = minLenght - errors, - std::cout << "All matches resulting from your search have an E-value of: " << std::endl; - std::cout << " " << _computeEValue(minScore, maxLengthQueries, refLen) << " or smaller"; - std::cout << " (match score = 1, error penalty = -2)" << std::endl; + outStr << "All matches resulting from your search have an E-value of: " << std::endl; + outStr << " " << _computeEValue(minScore, maxLengthQueries, refLen) << " or smaller"; + outStr << " (match score = 1, error penalty = -2)" << std::endl; + + outStr << std::endl; + } +} + +template +void _printStellarKernelStatistics(StellarComputeStatistics const & statistics, TStream & outStr) +{ + if (statistics.numSwiftHits == 0) + return; + + outStr << std::endl << " # SWIFT hits : " << statistics.numSwiftHits; + outStr << std::endl << " Longest hit : " << statistics.maxLength; + outStr << std::endl << " Avg hit length : " << statistics.totalLength/statistics.numSwiftHits; +} - std::cout << std::endl; +template +void _printDatabaseIdAndStellarKernelStatistics( + bool const verbose, + bool const databaseStrand, + CharString const & databaseID, + StellarComputeStatistics const & statistics, + TStream & outStr) +{ + outStr << " " << databaseID; + if (!databaseStrand) + outStr << ", complement"; + outStr << std::flush; + + if (verbose) + { + _printStellarKernelStatistics(statistics, outStr); + } + outStr << std::endl; +} + +template +void _printStellarStatistics( + bool const verbose, + bool const databaseStrand, + StringSet const & databaseIDs, + StellarComputeStatisticsCollection const & computeStatistics, + TStream & outStr) +{ + std::cerr << std::endl; // swift filter output is on same line + for (size_t i = 0; i < length(databaseIDs); ++i) + { + CharString const & databaseID = databaseIDs[i]; + StellarComputeStatistics const & statistics = computeStatistics[i]; + _printDatabaseIdAndStellarKernelStatistics(verbose, databaseStrand, databaseID, statistics, outStr); + } +} + +template +void _writeOutputStatistics(StellarOutputStatistics const & statistics, + bool const verbose, + bool const writeDisabledQueriesFile, + TStream & outStr) +{ + outStr << "# Eps-matches : " << statistics.numMatches << std::endl; + if (verbose) { + if (statistics.numMatches > 0) { + outStr << "Longest eps-match : " << statistics.maxLength << std::endl; + outStr << "Avg match length : " << statistics.totalLength / statistics.numMatches << std::endl; + } + if (writeDisabledQueriesFile) + outStr << "# Disabled queries: " << statistics.numDisabled << std::endl; } } diff --git a/include/stellar/io/import_sequence.hpp b/include/stellar/io/import_sequence.hpp index af0401cb9..374353fbd 100644 --- a/include/stellar/io/import_sequence.hpp +++ b/include/stellar/io/import_sequence.hpp @@ -36,18 +36,20 @@ _checkUniqueId(std::set & uniqueIds, TId const & id) /////////////////////////////////////////////////////////////////////////////// // Imports sequences from a file, // stores them in the StringSet seqs and their identifiers in the StringSet ids -template +template inline bool _importAllSequences(char const * fileName, CharString const & name, StringSet & seqs, StringSet & ids, - TLen & seqLen) + TLen & seqLen, + TStream & strOut, + TStream & strErr) { SeqFileIn inSeqs; if (!open(inSeqs, fileName)) { - std::cerr << "Failed to open " << name << " file." << std::endl; + strErr << "Failed to open " << name << " file." << std::endl; return false; } @@ -70,9 +72,9 @@ _importAllSequences(char const * fileName, appendValue(ids, id, Generous()); } - std::cout << "Loaded " << seqCount << " " << name << " sequence" << ((seqCount > 1) ? "s." : ".") << std::endl; + strOut << "Loaded " << seqCount << " " << name << " sequence" << ((seqCount > 1) ? "s." : ".") << std::endl; if (!idsUnique) - std::cerr << "WARNING: Non-unique " << name << " ids. Output can be ambiguous.\n"; + strErr << "WARNING: Non-unique " << name << " ids. Output can be ambiguous.\n"; return true; } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bfba099ac..06ed20804 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -133,16 +133,13 @@ target_link_libraries (stellar_main PUBLIC "${PROJECT_NAME}_interface") add_library (stellar_arg_parser STATIC stellar3.arg_parser.cpp) target_link_libraries (stellar_arg_parser PUBLIC "stellar_main") -add_library (stellar_diagnostics STATIC stellar/stellar.diagnostics.cpp) -target_link_libraries (stellar_diagnostics PUBLIC "stellar_main") - if (STELLAR_PRECOMPILED_HEADER_BUILD) target_precompile_headers (stellar_main PRIVATE ../include/stellar/app/stellar.main.tpp) endif () # Update the list of file names below if you add source files to your application. add_executable (stellar stellar.cpp) -target_link_libraries (stellar PRIVATE stellar_main stellar_arg_parser stellar_diagnostics) +target_link_libraries (stellar PRIVATE stellar_main stellar_arg_parser) # Add dependencies found by find_package (SeqAn). target_link_libraries (stellar PUBLIC "${PROJECT_NAME}_interface" ${SEQAN_LIBRARIES}) diff --git a/src/stellar.cpp b/src/stellar.cpp index 467d4d3e7..4cbc42eb7 100644 --- a/src/stellar.cpp +++ b/src/stellar.cpp @@ -34,7 +34,6 @@ #include #include -#include "stellar/stellar.diagnostics.cpp" // TODO(holtgrew): Move this into a SeqAn misc module. diff --git a/src/stellar/stellar.diagnostics.cpp b/src/stellar/stellar.diagnostics.cpp deleted file mode 100644 index 3734669ac..000000000 --- a/src/stellar/stellar.diagnostics.cpp +++ /dev/null @@ -1,121 +0,0 @@ -#include - -namespace stellar -{ - -/////////////////////////////////////////////////////////////////////////////// -// Calculates parameters from parameters in options object and writes them to std::cout -// Sets options.qGram if not set by user input -void _writeCalculatedParams(StellarOptions & options) -{ -//IOREV _notio_ - StellarStatistics statistics{options}; - - std::cout << "Calculated parameters:" << std::endl; - if (statistics.kMerComputed) - { - options.qGram = (unsigned)statistics.kMerLength; - std::cout << " k-mer length : " << statistics.kMerLength << std::endl; - } - - std::cout << " s^min : " << statistics.smin << std::endl; - std::cout << " threshold : " << statistics.threshold << std::endl; - std::cout << " distance cut : " << statistics.distanceCut << std::endl; - std::cout << " delta : " << statistics.delta << std::endl; - std::cout << " overlap : " << statistics.overlap << std::endl; - std::cout << std::endl; -} - -/////////////////////////////////////////////////////////////////////////////// -// Writes user specified parameters from options object to std::cout -void _writeSpecifiedParams(StellarOptions const & options) -{ -//IOREV _notio_ - // Output user specified parameters - std::cout << "User specified parameters:" << std::endl; - std::cout << " minimal match length : " << options.minLength << std::endl; - std::cout << " maximal error rate (epsilon) : " << options.epsilon << std::endl; - std::cout << " maximal x-drop : " << options.xDrop << std::endl; - if (options.qGram != std::numeric_limits::max()) - std::cout << " k-mer (q-gram) length : " << options.qGram << std::endl; - std::cout << " search forward strand : " << ((options.forward) ? "yes" : "no") << std::endl; - std::cout << " search reverse complement : " << ((options.reverse) ? "yes" : "no") << std::endl; - std::cout << std::endl; - - std::cout << " verification strategy : " << to_string(options.verificationMethod) << std::endl; - if (options.disableThresh != std::numeric_limits::max()) - { - std::cout << " disable queries with more than : " << options.disableThresh << " matches" << std::endl; - } - std::cout << " maximal number of matches : " << options.numMatches << std::endl; - std::cout << " duplicate removal every : " << options.compactThresh << std::endl; - if (options.maxRepeatPeriod != 1 || options.minRepeatLength != 1000) - { - std::cout << " max low complexity repeat period : " << options.maxRepeatPeriod << std::endl; - std::cout << " min low complexity repeat length : " << options.minRepeatLength << std::endl; - } - if (options.qgramAbundanceCut != 1) - { - std::cout << " q-gram abundance cut ratio : " << options.qgramAbundanceCut << std::endl; - } - - std::cout << std::endl; -} - -void _writeOutputStatistics(StellarOutputStatistics const & statistics, bool const verbose, bool const writeDisabledQueriesFile) -{ - std::cout << "# Eps-matches : " << statistics.numMatches << std::endl; - if (verbose) { - if (statistics.numMatches > 0) { - std::cout << "Longest eps-match : " << statistics.maxLength << std::endl; - std::cout << "Avg match length : " << statistics.totalLength / statistics.numMatches << std::endl; - } - if (writeDisabledQueriesFile) - std::cout << "# Disabled queries: " << statistics.numDisabled << std::endl; - } -} - -void _printStellarKernelStatistics(StellarComputeStatistics const & statistics) -{ - if (statistics.numSwiftHits == 0) - return; - - std::cout << std::endl << " # SWIFT hits : " << statistics.numSwiftHits; - std::cout << std::endl << " Longest hit : " << statistics.maxLength; - std::cout << std::endl << " Avg hit length : " << statistics.totalLength/statistics.numSwiftHits; -} - -void _printDatabaseIdAndStellarKernelStatistics( - bool const verbose, - bool const databaseStrand, - CharString const & databaseID, - StellarComputeStatistics const & statistics) -{ - std::cout << " " << databaseID; - if (!databaseStrand) - std::cout << ", complement"; - std::cout << std::flush; - - if (verbose) - { - _printStellarKernelStatistics(statistics); - } - std::cout << std::endl; -} - -void _printStellarStatistics( - bool const verbose, - bool const databaseStrand, - StringSet const & databaseIDs, - StellarComputeStatisticsCollection const & computeStatistics) -{ - std::cerr << std::endl; // swift filter output is on same line - for (size_t i = 0; i < length(databaseIDs); ++i) - { - CharString const & databaseID = databaseIDs[i]; - StellarComputeStatistics const & statistics = computeStatistics[i]; - _printDatabaseIdAndStellarKernelStatistics(verbose, databaseStrand, databaseID, statistics); - } -} - -} // namespace stellar diff --git a/test/api/stellar/stellar_import_sequence_test.cpp b/test/api/stellar/stellar_import_sequence_test.cpp index 6c4b9d3c1..36e6bf4d6 100644 --- a/test/api/stellar/stellar_import_sequence_test.cpp +++ b/test/api/stellar/stellar_import_sequence_test.cpp @@ -13,7 +13,7 @@ TEST(import_sequences, all_sequences) seqan2::StringSet databaseIDs; uint64_t refLen{0}; - stellar::_importAllSequences(databaseFile.c_str(), "database", databases, databaseIDs, refLen); + stellar::_importAllSequences(databaseFile.c_str(), "database", databases, databaseIDs, refLen, std::cout, std::cerr); EXPECT_EQ(length(databases), 3u); EXPECT_EQ(databases[0], (seqan2::String) {"GATGACTCAGTCTTGTTGATTAGGCACCTCGGTATGTGGGCATTAGGCACATTGCTCTGTTTCTTGAAGT" From 0150b52431f27dd027c1c10f02256c90272125ff Mon Sep 17 00:00:00 2001 From: Evelin Aasna Date: Fri, 16 Jun 2023 14:13:38 +0200 Subject: [PATCH 10/20] Refactor runtime printing --- include/stellar/app/stellar.main.tpp | 49 +---------------- include/stellar/utils/stellar_app_runtime.hpp | 52 +++++++++++++++++++ include/stellar3.shared.hpp | 2 +- src/stellar3.arg_parser.cpp | 7 ++- test/cli/gold_standard_for.sh | 8 +-- test/cli/run_tests.py | 7 --- test/cli/stellar_test.cpp | 2 - 7 files changed, 62 insertions(+), 65 deletions(-) diff --git a/include/stellar/app/stellar.main.tpp b/include/stellar/app/stellar.main.tpp index 9d6ff1c13..5e75a2d1d 100644 --- a/include/stellar/app/stellar.main.tpp +++ b/include/stellar/app/stellar.main.tpp @@ -330,55 +330,10 @@ int mainWithOptions(StellarOptions & options, String) if (!_stellarMain(databases, databaseIDs, refLen, queries, queryIDs, options, outputFile, disabledQueriesFile, stellar_time)) return 1; - if (options.verbose && options.noRT == false) + if (options.write_time) { stellar_time.manual_timing(current_time); - - auto _print_stellar_strand_time = [](stellar_strand_time const & strand_runtime, std::string strandDirection) - { - stellar_kernel_runtime const & prefiltered_stellar_time - = strand_runtime.prefiltered_stellar_time; - stellar_verification_time const & verification_time - = strand_runtime.prefiltered_stellar_time.verification_time; - stellar_extension_time const & extension_time - = verification_time.extension_time; - stellar_best_extension_time const & best_extension_time - = extension_time.best_extension_time; - - std::cout << " + Prefiltered Stellar Time (" << strandDirection << "): " << prefiltered_stellar_time.milliseconds() << "ms" << std::endl; - std::cout << " + Swift Filter Time (" << strandDirection << "): " << prefiltered_stellar_time.swift_filter_time.milliseconds() << "ms" << std::endl; - std::cout << " + Seed Verification Time (" << strandDirection << "): " << verification_time.milliseconds() << "ms" << std::endl; - std::cout << " + Find Next Local Alignment Time (" << strandDirection << "): " << verification_time.next_local_alignment_time.milliseconds() << "ms" << std::endl; - std::cout << " + Split At X-Drops Time (" << strandDirection << "): " << verification_time.split_at_x_drops_time.milliseconds() << "ms" << std::endl; - std::cout << " + Extension Time (" << strandDirection << "): " << extension_time.milliseconds() << "ms" << std::endl; - std::cout << " + Extend Seed Time (" << strandDirection << "): " << extension_time.extend_seed_time.milliseconds() << "ms" << std::endl; - std::cout << " + Best Extension Time (" << strandDirection << "): " << best_extension_time.milliseconds() << "ms" << std::endl; - std::cout << " + Banded Needleman-Wunsch Time (" << strandDirection << "): " << best_extension_time.banded_needleman_wunsch_time.milliseconds() << "ms" << std::endl; - std::cout << " + Banded Needleman-Wunsch (Left Extension) Time (" << strandDirection << "): " << best_extension_time.banded_needleman_wunsch_left_time.milliseconds() << "ms" << std::endl; - std::cout << " + Banded Needleman-Wunsch (Right Extension) Time (" << strandDirection << "): " << best_extension_time.banded_needleman_wunsch_right_time.milliseconds() << "ms" << std::endl; - std::cout << " + Longest EPS Match Time (" << strandDirection << "): " << best_extension_time.longest_eps_match_time.milliseconds() << "ms" << std::endl; - std::cout << " + Construct Alignment Time (" << strandDirection << "): " << best_extension_time.construct_seed_alignment_time.milliseconds() << "ms" << std::endl; - std::cout << " = total time: " << best_extension_time.total_time().milliseconds() << "ms" << std::endl; - std::cout << " = total time: " << extension_time.total_time().milliseconds() << "ms" << std::endl; - std::cout << " = total time: " << verification_time.total_time().milliseconds() << "ms" << std::endl; - std::cout << " = total time: " << prefiltered_stellar_time.total_time().milliseconds() << "ms" << std::endl; - std::cout << " + Post-Process Eps-Matches Time (" << strandDirection << "): " << strand_runtime.post_process_eps_matches_time.milliseconds() << "ms" << std::endl; - std::cout << " + File Output Eps-Matches Time (" << strandDirection << "): " << strand_runtime.output_eps_matches_time.milliseconds() << "ms" << std::endl; - std::cout << " = total time: " << strand_runtime.total_time().milliseconds() << "ms" << std::endl; - }; - - std::cout << "Running time: " << stellar_time.milliseconds() << "ms" << std::endl; - std::cout << " * Stellar Application Time: " << stellar_time.milliseconds() << "ms" << std::endl; - std::cout << " + File Input Queries Time: " << stellar_time.input_queries_time.milliseconds() << "ms" << std::endl; - std::cout << " + File Input Databases Time: " << stellar_time.input_databases_time.milliseconds() << "ms" << std::endl; - std::cout << " + SwiftFilter Construction Time: " << stellar_time.swift_index_construction_time.milliseconds() << "ms" << std::endl; - std::cout << " + Stellar Forward Strand Time: " << stellar_time.forward_strand_stellar_time.milliseconds() << "ms" << std::endl; - _print_stellar_strand_time(stellar_time.forward_strand_stellar_time, "Forward"); - std::cout << " + Database Reverse Complement Time: " << stellar_time.reverse_complement_database_time.milliseconds() << "ms" << std::endl; - std::cout << " + Stellar Reverse Strand Time: " << stellar_time.reverse_strand_stellar_time.milliseconds() << "ms" << std::endl; - _print_stellar_strand_time(stellar_time.reverse_strand_stellar_time, "Reverse"); - std::cout << " + File Output Disabled Queries Time: " << stellar_time.output_disabled_queries_time.milliseconds() << "ms" << std::endl; - std::cout << " = total time: " << stellar_time.total_time().milliseconds() << "ms" << std::endl; + _print_stellar_app_time(stellar_time, std::cout); } return 0; diff --git a/include/stellar/utils/stellar_app_runtime.hpp b/include/stellar/utils/stellar_app_runtime.hpp index 2bbfa431b..a8c4127ec 100644 --- a/include/stellar/utils/stellar_app_runtime.hpp +++ b/include/stellar/utils/stellar_app_runtime.hpp @@ -25,6 +25,41 @@ struct stellar_strand_time : public stellar_runtime } }; +template +void _print_stellar_strand_time(stellar_strand_time const & strand_runtime, std::string strandDirection, TStream & outStr) +{ + stellar_kernel_runtime const & prefiltered_stellar_time + = strand_runtime.prefiltered_stellar_time; + stellar_verification_time const & verification_time + = strand_runtime.prefiltered_stellar_time.verification_time; + stellar_extension_time const & extension_time + = verification_time.extension_time; + stellar_best_extension_time const & best_extension_time + = extension_time.best_extension_time; + + outStr << " + Prefiltered Stellar Time (" << strandDirection << "): " << prefiltered_stellar_time.milliseconds() << "ms" << std::endl; + outStr << " + Swift Filter Time (" << strandDirection << "): " << prefiltered_stellar_time.swift_filter_time.milliseconds() << "ms" << std::endl; + outStr << " + Seed Verification Time (" << strandDirection << "): " << verification_time.milliseconds() << "ms" << std::endl; + outStr << " + Find Next Local Alignment Time (" << strandDirection << "): " << verification_time.next_local_alignment_time.milliseconds() << "ms" << std::endl; + outStr << " + Split At X-Drops Time (" << strandDirection << "): " << verification_time.split_at_x_drops_time.milliseconds() << "ms" << std::endl; + outStr << " + Extension Time (" << strandDirection << "): " << extension_time.milliseconds() << "ms" << std::endl; + outStr << " + Extend Seed Time (" << strandDirection << "): " << extension_time.extend_seed_time.milliseconds() << "ms" << std::endl; + outStr << " + Best Extension Time (" << strandDirection << "): " << best_extension_time.milliseconds() << "ms" << std::endl; + outStr << " + Banded Needleman-Wunsch Time (" << strandDirection << "): " << best_extension_time.banded_needleman_wunsch_time.milliseconds() << "ms" << std::endl; + outStr << " + Banded Needleman-Wunsch (Left Extension) Time (" << strandDirection << "): " << best_extension_time.banded_needleman_wunsch_left_time.milliseconds() << "ms" << std::endl; + outStr << " + Banded Needleman-Wunsch (Right Extension) Time (" << strandDirection << "): " << best_extension_time.banded_needleman_wunsch_right_time.milliseconds() << "ms" << std::endl; + outStr << " + Longest EPS Match Time (" << strandDirection << "): " << best_extension_time.longest_eps_match_time.milliseconds() << "ms" << std::endl; + outStr << " + Construct Alignment Time (" << strandDirection << "): " << best_extension_time.construct_seed_alignment_time.milliseconds() << "ms" << std::endl; + outStr << " = total time: " << best_extension_time.total_time().milliseconds() << "ms" << std::endl; + outStr << " = total time: " << extension_time.total_time().milliseconds() << "ms" << std::endl; + outStr << " = total time: " << verification_time.total_time().milliseconds() << "ms" << std::endl; + outStr << " = total time: " << prefiltered_stellar_time.total_time().milliseconds() << "ms" << std::endl; + outStr << " + Post-Process Eps-Matches Time (" << strandDirection << "): " << strand_runtime.post_process_eps_matches_time.milliseconds() << "ms" << std::endl; + outStr << " + File Output Eps-Matches Time (" << strandDirection << "): " << strand_runtime.output_eps_matches_time.milliseconds() << "ms" << std::endl; + outStr << " = total time: " << strand_runtime.total_time().milliseconds() << "ms" << std::endl; +}; + + struct stellar_app_runtime : public stellar_runtime { stellar_runtime input_queries_time{}; @@ -51,4 +86,21 @@ struct stellar_app_runtime : public stellar_runtime } }; +template +void _print_stellar_app_time(stellar_app_runtime const & stellar_time, TStream & strOut) +{ + strOut << "Running time: " << stellar_time.milliseconds() << "ms" << std::endl; + strOut << " * Stellar Application Time: " << stellar_time.milliseconds() << "ms" << std::endl; + strOut << " + File Input Queries Time: " << stellar_time.input_queries_time.milliseconds() << "ms" << std::endl; + strOut << " + File Input Databases Time: " << stellar_time.input_databases_time.milliseconds() << "ms" << std::endl; + strOut << " + SwiftFilter Construction Time: " << stellar_time.swift_index_construction_time.milliseconds() << "ms" << std::endl; + strOut << " + Stellar Forward Strand Time: " << stellar_time.forward_strand_stellar_time.milliseconds() << "ms" << std::endl; + _print_stellar_strand_time(stellar_time.forward_strand_stellar_time, "Forward", strOut); + strOut << " + Database Reverse Complement Time: " << stellar_time.reverse_complement_database_time.milliseconds() << "ms" << std::endl; + strOut << " + Stellar Reverse Strand Time: " << stellar_time.reverse_strand_stellar_time.milliseconds() << "ms" << std::endl; + _print_stellar_strand_time(stellar_time.reverse_strand_stellar_time, "Reverse", strOut); + strOut << " + File Output Disabled Queries Time: " << stellar_time.output_disabled_queries_time.milliseconds() << "ms" << std::endl; + strOut << " = total time: " << stellar_time.total_time().milliseconds() << "ms" << std::endl; +} + } // namespace stellar diff --git a/include/stellar3.shared.hpp b/include/stellar3.shared.hpp index cc0ad9c6d..1f6ea3784 100644 --- a/include/stellar3.shared.hpp +++ b/include/stellar3.shared.hpp @@ -25,7 +25,7 @@ struct StellarOptions : public EPSMatchOptions, public IndexOptions, public Veri std::string disabledQueriesFile{"stellar.disabled.fasta"}; // name of result file containing disabled queries std::string outputFormat{"gff"}; // Possible formats: gff, text std::string alphabet{"dna5"}; // Possible values: dna, rna, protein, char - bool noRT; // suppress printing of running time if set to true + bool write_time; // more options bool forward{true}; // compute matches to forward strand of database diff --git a/src/stellar3.arg_parser.cpp b/src/stellar3.arg_parser.cpp index 70c176095..8fdf81e30 100644 --- a/src/stellar3.arg_parser.cpp +++ b/src/stellar3.arg_parser.cpp @@ -194,11 +194,10 @@ void init_parser(sharg::parser & parser, StellarOptions & options) .long_id = "disabledQueriesFile", .description = "Name of output file for disabled query sequences.", .validator = sharg::output_file_validator{sharg::output_file_open_options::open_or_create, {"fa", "fasta"}}}); - parser.add_flag(options.noRT, + parser.add_flag(options.write_time, sharg::config{.short_id = '\0', - .long_id = "suppress-runtime-printing", - .description = "Suppress printing running time.", - .advanced = true}); + .long_id = "time", + .description = "Write running time."}); } void run_stellar(sharg::parser & parser) diff --git a/test/cli/gold_standard_for.sh b/test/cli/gold_standard_for.sh index 3252439b3..a0cc52f1b 100755 --- a/test/cli/gold_standard_for.sh +++ b/test/cli/gold_standard_for.sh @@ -37,9 +37,9 @@ call_stellar() query_file=512_simSeq2_$2.fa echo -e $ref_file "\t" $query_file ${STELLAR} -e $1 -l 50 -x 10 -k 7 -n 5000 -s 10000 $strand -v -a $alphabet -o $dir/$2.gff \ - $ref_file $query_file --suppress-runtime-printing > $dir/$2.gff.stdout + $ref_file $query_file > $dir/$2.gff.stdout ${STELLAR} -e $1 -l 50 -x 10 -k 7 -n 5000 -s 10000 $strand -v -a $alphabet -o $dir/$2.txt \ - $ref_file $query_file --suppress-runtime-printing > $dir/$2.txt.stdout + $ref_file $query_file > $dir/$2.txt.stdout } eps="e-1" @@ -69,9 +69,9 @@ call_stellar $errRate $eps call_stellar_minlen() { ${STELLAR} -e 0.05 -l $1 -x 10 -k 7 -n 5000 -s 10000 $strand -v -a $alphabet -o $dir/minLen$1.gff \ - 512_simSeq1_5e-2.fa 512_simSeq2_5e-2.fa --suppress-runtime-printing > $dir/minLen$1.gff.stdout + 512_simSeq1_5e-2.fa 512_simSeq2_5e-2.fa > $dir/minLen$1.gff.stdout ${STELLAR} -e 0.05 -l $1 -x 10 -k 7 -n 5000 -s 10000 $strand -v -a $alphabet -o $dir/minLen$1.txt \ - 512_simSeq1_5e-2.fa 512_simSeq2_5e-2.fa --suppress-runtime-printing > $dir/minLen$1.txt.stdout + 512_simSeq1_5e-2.fa 512_simSeq2_5e-2.fa > $dir/minLen$1.txt.stdout } minLen="20" diff --git a/test/cli/run_tests.py b/test/cli/run_tests.py index c0e5145c1..ed4e8b61e 100755 --- a/test/cli/run_tests.py +++ b/test/cli/run_tests.py @@ -30,7 +30,6 @@ '-n', '5000', # --numMatches '-s', '10000', # --sortThresh '-v', # --verbose - '--suppress-runtime-printing', # for stable output ], '5e-2' : [ '--epsilon', '0.05', @@ -40,7 +39,6 @@ '--numMatches', '5000', '--sortThresh', '10000', '--verbose', - '--suppress-runtime-printing', # for stable output ], '25e-3' : [ '--epsilon', '0.025', @@ -50,7 +48,6 @@ '--numMatches', '5000', '--sortThresh', '10000', '--verbose', - '--suppress-runtime-printing', # for stable output ], '75e-3': [ '--epsilon', '0.075', @@ -60,7 +57,6 @@ '--numMatches', '5000', '--sortThresh', '10000', '--verbose', - '--suppress-runtime-printing', # for stable output ], 'e-4' : [ '--epsilon', '0.0001', @@ -70,7 +66,6 @@ '--numMatches', '5000', '--sortThresh', '10000', '--verbose', - '--suppress-runtime-printing', # for stable output ], 'minLen20' : [ '--epsilon', '0.05', @@ -80,7 +75,6 @@ '--numMatches', '5000', '--sortThresh', '10000', '--verbose', - '--suppress-runtime-printing', # for stable output ], 'minLen150' : [ '--epsilon', '0.05', @@ -90,7 +84,6 @@ '--numMatches', '5000', '--sortThresh', '10000', '--verbose', - '--suppress-runtime-printing', # for stable output ] } diff --git a/test/cli/stellar_test.cpp b/test/cli/stellar_test.cpp index da05c8b54..aec162095 100644 --- a/test/cli/stellar_test.cpp +++ b/test/cli/stellar_test.cpp @@ -25,7 +25,6 @@ TEST_P(search_subset, stellar_search_subset) "--minLength 50", "-k 15", "--verbose", - "--suppress-runtime-printing", segments); EXPECT_EQ(result.exit_code, 0); @@ -74,7 +73,6 @@ TEST_P(search_segment, stellar_search_segment) "--minLength 50", "-k 15", "--verbose", - "--suppress-runtime-printing", "> segment_out.stdout"); EXPECT_EQ(result.exit_code, 0); EXPECT_EQ(result.err, std::string{"\n\n"}); From 14d0128c2a62487139b5d22015176cc9d254a3d5 Mon Sep 17 00:00:00 2001 From: Evelin Aasna Date: Mon, 19 Jun 2023 11:17:09 +0200 Subject: [PATCH 11/20] Get DREAM segment from reverse strand --- include/stellar/stellar_database_segment.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/stellar/stellar_database_segment.hpp b/include/stellar/stellar_database_segment.hpp index 0d2c97893..342df5db6 100644 --- a/include/stellar/stellar_database_segment.hpp +++ b/include/stellar/stellar_database_segment.hpp @@ -81,7 +81,8 @@ TStorage _getDatabaseSegments(StringSet> & databases, StellarO template TDatabaseSegment _getDREAMDatabaseSegment(String const & sequenceOfInterest, - StellarOptions const & options) + StellarOptions const & options, + bool const reverse = false) { if (length(sequenceOfInterest) < options.segmentEnd) throw std::runtime_error{"Segment end out of range"}; @@ -92,9 +93,11 @@ TDatabaseSegment _getDREAMDatabaseSegment(String const & sequenceOfIn if (options.segmentEnd < options.minLength + options.segmentBegin) throw std::runtime_error{"Segment shorter than minimum match length"}; - TDatabaseSegment databaseSegment(sequenceOfInterest, options.segmentBegin, options.segmentEnd); + if (reverse) + return TDatabaseSegment(sequenceOfInterest, length(sequenceOfInterest) - options.segmentEnd, length(sequenceOfInterest) - options.segmentBegin); + + return TDatabaseSegment(sequenceOfInterest, options.segmentBegin, options.segmentEnd); - return databaseSegment; } } // namespace stellar From 753b55da9a0a85b46c838b7c048f451c649bbcff Mon Sep 17 00:00:00 2001 From: Evelin Aasna Date: Mon, 19 Jun 2023 16:15:54 +0200 Subject: [PATCH 12/20] API test _getDREAMDatabaseSegment --- .../stellar/stellar_database_segment_test.cpp | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/test/api/stellar/stellar_database_segment_test.cpp b/test/api/stellar/stellar_database_segment_test.cpp index 9add691c0..932cebed9 100644 --- a/test/api/stellar/stellar_database_segment_test.cpp +++ b/test/api/stellar/stellar_database_segment_test.cpp @@ -396,3 +396,91 @@ TEST(getDatabaseSegment, incorrect_indices) FAIL() << "Expected std::runtime_error"; } } + +//////////////////////////////////////////////// +// TDatabaseSegment _getDREAMDatabaseSegment +//////////////////////////////////////////////// +TEST(_getDREAMDatabaseSegment, from_begin) +{ + seqan2::String sequence = "ACGTCG"; + auto options = getPrefilteringOptions(std::vector{1}, 0u, 2u); + + TDatabaseSegment segment = stellar::_getDREAMDatabaseSegment(sequence, options); + + EXPECT_EQ(segment.size(), 2u); + EXPECT_EQ(segment.asInfixSegment(), (seqan2::String) {"AC"}); +} + +TEST(_getDREAMDatabaseSegment, reverse_complement) +{ + seqan2::String sequence = "ACGTCG"; + reverseComplement(sequence); + auto options = getPrefilteringOptions(std::vector{1}, 0u, 2u); + + TDatabaseSegment segment = stellar::_getDREAMDatabaseSegment(sequence, options, true); + + EXPECT_EQ(segment.size(), 2u); + EXPECT_EQ(segment.asInfixSegment(), (seqan2::String) {"GT"}); +} + +TEST(_getDREAMDatabaseSegment, whole_sequence) +{ + seqan2::String sequence = "ACGTCG"; + auto options = getPrefilteringOptions(std::vector{1}, 0u, 6u); + + TDatabaseSegment segment = stellar::_getDREAMDatabaseSegment(sequence, options); + + EXPECT_EQ(segment.size(), 6u); + EXPECT_EQ(segment.asInfixSegment(), (seqan2::String) {"ACGTCG"}); +} + +TEST(_getDREAMDatabaseSegment, index_out_of_range) +{ + seqan2::String sequence = "ACGTCG"; + auto options = getPrefilteringOptions(std::vector{1}, 0u, 8u); + + try { + TDatabaseSegment databaseSegments = stellar::_getDREAMDatabaseSegment(sequence, options); + FAIL() << "Expected std::runtime_error"; + } + catch(std::runtime_error const & err) { + EXPECT_EQ(err.what(),std::string("Segment end out of range")); + } + catch(...) { + FAIL() << "Expected std::runtime_error"; + } +} + +TEST(_getDREAMDatabaseSegment, too_short) +{ + seqan2::String sequence = "ACGTCG"; + auto options = getPrefilteringOptions(std::vector{1}, 0u, 1u); + + try { + TDatabaseSegment databaseSegments = stellar::_getDREAMDatabaseSegment(sequence, options); + FAIL() << "Expected std::runtime_error"; + } + catch(std::runtime_error const & err) { + EXPECT_EQ(err.what(),std::string("Segment shorter than minimum match length")); + } + catch(...) { + FAIL() << "Expected std::runtime_error"; + } +} + +TEST(_getDREAMDatabaseSegment, incorrect_indices) +{ + seqan2::String sequence = "ACGTCG"; + auto options = getPrefilteringOptions(std::vector{1}, 2u, 0u); + + try { + TDatabaseSegment segment = stellar::_getDREAMDatabaseSegment(sequence, options); + FAIL() << "Expected std::runtime_error"; + } + catch(std::runtime_error const & err) { + EXPECT_EQ(err.what(),std::string("Incorrect segment definition")); + } + catch(...) { + FAIL() << "Expected std::runtime_error"; + } +} \ No newline at end of file From e0fd8957f7ce175ae5f83c8791841170dd1e0cda Mon Sep 17 00:00:00 2001 From: Evelin Aasna Date: Mon, 3 Jul 2023 08:09:51 +0200 Subject: [PATCH 13/20] Update include/stellar/io/import_sequence.hpp Co-authored-by: Simon Gene Gottlieb --- include/stellar/io/import_sequence.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/stellar/io/import_sequence.hpp b/include/stellar/io/import_sequence.hpp index 374353fbd..5f55254fc 100644 --- a/include/stellar/io/import_sequence.hpp +++ b/include/stellar/io/import_sequence.hpp @@ -12,7 +12,7 @@ inline bool _checkUniqueId(std::set & uniqueIds, TId const & id) { TId shortId; - typedef typename Iterator::Type TIterator; + using TIterator = typename Iterator::Type; TIterator it = begin(id); TIterator itEnd = end(id); From e7563d2f99fc0ba5a6011b23706d900b0f024547 Mon Sep 17 00:00:00 2001 From: Evelin Aasna Date: Mon, 3 Jul 2023 08:10:36 +0200 Subject: [PATCH 14/20] Update include/stellar/io/import_sequence.hpp Co-authored-by: Simon Gene Gottlieb --- include/stellar/io/import_sequence.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/stellar/io/import_sequence.hpp b/include/stellar/io/import_sequence.hpp index 5f55254fc..76b56b779 100644 --- a/include/stellar/io/import_sequence.hpp +++ b/include/stellar/io/import_sequence.hpp @@ -24,7 +24,7 @@ _checkUniqueId(std::set & uniqueIds, TId const & id) ++it; } - if (uniqueIds.count(shortId) == 0) + if (!uniqueIds.contains(shortId)) { uniqueIds.insert(shortId); return 1; From a45063292f1cfe8f806f171d1907045fe1e79c9a Mon Sep 17 00:00:00 2001 From: Evelin Aasna Date: Mon, 3 Jul 2023 09:20:44 +0200 Subject: [PATCH 15/20] Update include/stellar/io/import_sequence.hpp Co-authored-by: Simon Gene Gottlieb --- include/stellar/io/import_sequence.hpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/include/stellar/io/import_sequence.hpp b/include/stellar/io/import_sequence.hpp index 76b56b779..a9d546008 100644 --- a/include/stellar/io/import_sequence.hpp +++ b/include/stellar/io/import_sequence.hpp @@ -14,14 +14,11 @@ _checkUniqueId(std::set & uniqueIds, TId const & id) TId shortId; using TIterator = typename Iterator::Type; - TIterator it = begin(id); - TIterator itEnd = end(id); // (cut at first whitespace) - while (it != itEnd && *it > ' ') + for (auto it = begin(id); it != itEnd && *it > ' '; ++it) { appendValue(shortId, *it); - ++it; } if (!uniqueIds.contains(shortId)) From dd671820eb8a7c9f83ab738fbd1bafa4f3b8f9fe Mon Sep 17 00:00:00 2001 From: Evelin Aasna Date: Mon, 3 Jul 2023 09:21:55 +0200 Subject: [PATCH 16/20] Update import_sequence.hpp --- include/stellar/io/import_sequence.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/stellar/io/import_sequence.hpp b/include/stellar/io/import_sequence.hpp index a9d546008..c70fef117 100644 --- a/include/stellar/io/import_sequence.hpp +++ b/include/stellar/io/import_sequence.hpp @@ -12,8 +12,6 @@ inline bool _checkUniqueId(std::set & uniqueIds, TId const & id) { TId shortId; - using TIterator = typename Iterator::Type; - // (cut at first whitespace) for (auto it = begin(id); it != itEnd && *it > ' '; ++it) From bf350718273c2b6c733384106d61f75f78223c6a Mon Sep 17 00:00:00 2001 From: Evelin Aasna Date: Mon, 3 Jul 2023 09:28:42 +0200 Subject: [PATCH 17/20] Update stellar3.shared.hpp --- include/stellar3.shared.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/stellar3.shared.hpp b/include/stellar3.shared.hpp index 1f6ea3784..a40f9e7e3 100644 --- a/include/stellar3.shared.hpp +++ b/include/stellar3.shared.hpp @@ -25,7 +25,7 @@ struct StellarOptions : public EPSMatchOptions, public IndexOptions, public Veri std::string disabledQueriesFile{"stellar.disabled.fasta"}; // name of result file containing disabled queries std::string outputFormat{"gff"}; // Possible formats: gff, text std::string alphabet{"dna5"}; // Possible values: dna, rna, protein, char - bool write_time; + bool write_time; // write running time to standard output // more options bool forward{true}; // compute matches to forward strand of database From d855bd4d05776d3e20b4325278a87f1a0febc5d1 Mon Sep 17 00:00:00 2001 From: Evelin Aasna Date: Mon, 3 Jul 2023 09:30:13 +0200 Subject: [PATCH 18/20] Update import_sequence.hpp --- include/stellar/io/import_sequence.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/stellar/io/import_sequence.hpp b/include/stellar/io/import_sequence.hpp index c70fef117..3c238ae34 100644 --- a/include/stellar/io/import_sequence.hpp +++ b/include/stellar/io/import_sequence.hpp @@ -14,7 +14,7 @@ _checkUniqueId(std::set & uniqueIds, TId const & id) TId shortId; // (cut at first whitespace) - for (auto it = begin(id); it != itEnd && *it > ' '; ++it) + for (auto it = begin(id); it != end(id) && *it > ' '; ++it) { appendValue(shortId, *it); } From faf1e31aff839181760984437e2cf4c3a66ff208 Mon Sep 17 00:00:00 2001 From: Evelin Aasna Date: Mon, 3 Jul 2023 09:31:16 +0200 Subject: [PATCH 19/20] Update include/stellar/stellar_launcher.hpp Co-authored-by: Simon Gene Gottlieb --- include/stellar/stellar_launcher.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/stellar/stellar_launcher.hpp b/include/stellar/stellar_launcher.hpp index 49408656e..3780acd4a 100644 --- a/include/stellar/stellar_launcher.hpp +++ b/include/stellar/stellar_launcher.hpp @@ -117,9 +117,8 @@ struct StellarLauncher StellarComputeStatistics statistics = _verificationMethodVisit( localOptions.verificationMethod, - [&](auto tag) -> StellarComputeStatistics + [&](TTag tag) -> StellarComputeStatistics { - using TTag = decltype(tag); SwiftHitVerifier swiftVerifier { STELLAR_DESIGNATED_INITIALIZER(.eps_match_options = , localOptions), From ad091c3ca7ed0cdf43ef9aa8b2ba34bf5ddfa088 Mon Sep 17 00:00:00 2001 From: Evelin Aasna Date: Mon, 3 Jul 2023 09:33:29 +0200 Subject: [PATCH 20/20] Update import_sequence.hpp --- include/stellar/io/import_sequence.hpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/include/stellar/io/import_sequence.hpp b/include/stellar/io/import_sequence.hpp index 3c238ae34..c973d0adf 100644 --- a/include/stellar/io/import_sequence.hpp +++ b/include/stellar/io/import_sequence.hpp @@ -19,13 +19,9 @@ _checkUniqueId(std::set & uniqueIds, TId const & id) appendValue(shortId, *it); } - if (!uniqueIds.contains(shortId)) - { - uniqueIds.insert(shortId); - return 1; - } + auto [it, added] = uniqueIds.insert(shortId); - return 0; + return added; } ///////////////////////////////////////////////////////////////////////////////