Skip to content

Commit

Permalink
Try to pass query segment parameters in shopping carts
Browse files Browse the repository at this point in the history
  • Loading branch information
eaasna committed Aug 21, 2024
1 parent 5e89739 commit 0032913
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 79 deletions.
37 changes: 25 additions & 12 deletions include/dream_stellar/query_id_map.hpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
#pragma once

#include <dream_stellar/stellar_index.hpp>
#include <dream_stellar/stellar_query_segment.hpp>
#include <dream_stellar/stellar_types.hpp>

#include <valik/search/query_record.hpp>

namespace dream_stellar
{

template <typename alphabet_t, typename sequence_reference_t, typename TId = std::string>
struct QueryIDMap
template <typename alphabet_t, typename sequence_container_t = std::vector<alphabet_t>,
typename sequence_reference_t = std::span<const alphabet_t>>
class QueryIDMap
{
size_t recordID(sequence_reference_t const & query) const
{
sequence_reference_t const * begin = &queries[0];
sequence_reference_t const * current = std::addressof(query);
return current - begin;
}

std::vector<sequence_reference_t> const & queries;
std::vector<valik::shared_query_record<sequence_reference_t>> queries;

public:

QueryIDMap(std::vector<valik::shared_query_record<sequence_container_t>> const & records)
{
for (auto & record : records)
queries.emplace_back(record.id, record.get_start(), record.get_len(), record.underlyingData);
}

dream_stellar::StellarQuerySegment<sequence_reference_t> segment_from_id(unsigned const & query_id) const
{
if (query_id >= queries.size())
throw std::runtime_error("Query index " + std::to_string(query_id) + " is out of range [0, "
+ std::to_string(queries.size() - 1) + "]");
valik::shared_query_record<sequence_reference_t> & shared_rec = queries[query_id];

return shared_rec.get_seqan_segment();
}

};

} // namespace dream_stellar
9 changes: 5 additions & 4 deletions include/dream_stellar/stellar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <dream_stellar/stellar_types.hpp>
#include <dream_stellar/stellar_extension.hpp>
#include <dream_stellar/stellar_database_segment.hpp>
#include <dream_stellar/stellar_query_segment.tpp>
#include <dream_stellar/stellar_query_segment.hpp>
#include <dream_stellar/stellar_index.hpp>
#include <dream_stellar/utils/stellar_kernel_runtime.hpp>
#include <dream_stellar/verification/all_local.hpp>
Expand Down Expand Up @@ -195,6 +195,7 @@ template<typename alphabet_t, typename TTag, typename TIsPatternDisabledFn, type
StellarComputeStatistics
_stellarKernel(jst::contrib::stellar_matcher<std::span<const alphabet_t>> & matcher,
StellarDatabaseSegment<const alphabet_t> & database_segment,
QueryIDMap<alphabet_t> const & queryIDMap,
StellarOptions & localOptions,
SwiftHitVerifier<TTag> & swiftVerifier,
TIsPatternDisabledFn && isPatternDisabled,
Expand All @@ -213,11 +214,11 @@ _stellarKernel(jst::contrib::stellar_matcher<std::span<const alphabet_t>> & matc

if (!isPatternDisabled(matcher))
{
auto queryID = matcher.curSeqNo();
StellarQuerySegment<alphabet_t> querySegment = queryIDMap.segment_from_id(queryID);

//!TODO: adjust for alphabet_t
/*
StellarQuerySegment<alphabet_t> querySegment
= StellarQuerySegment<TAlphabet>::fromPatternMatch(pattern);
////Debug stuff:
//std::cout << beginPosition(infix(finder)) << ",";
//std::cout << endPosition(infix(finder)) << " ";
Expand Down
15 changes: 4 additions & 11 deletions include/dream_stellar/stellar_database_segment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace dream_stellar

using namespace seqan2;

//!TODO: remove obsolete functions
template <typename alphabet_t>
struct StellarDatabaseSegment : public StellarSequenceSegment<alphabet_t>
{
Expand All @@ -33,18 +34,10 @@ struct StellarDatabaseSegment : public StellarSequenceSegment<alphabet_t>
return this->underlyingSequence();
}

std::span<const alphabet_t> as_span(bool const reverse = false) const
std::span<const alphabet_t> as_span() const
{
if (reverse)
{
return underlyingDatabase().subspan(underlyingDatabase().size() - this->endPosition() /* offset */,
this->endPosition() - this->beginPosition() /* count */);
}
else
{
return underlyingDatabase().subspan(this->beginPosition() /* offset */,
this->endPosition() - this->beginPosition() /* count */);
}
return underlyingDatabase().subspan(this->beginPosition() /* offset */,
this->endPosition() - this->beginPosition() /* count */);
}

TNestedFinderSegment asFinderSegment() const
Expand Down
4 changes: 2 additions & 2 deletions include/dream_stellar/stellar_launcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct StellarLauncher
jst::contrib::stellar_matcher<sequence_reference_t> & matcher,
StellarDatabaseSegment<alphabet_t> database_segment,
id_t const & databaseID,
QueryIDMap<alphabet_t, sequence_reference_t> const & queryIDMap,
QueryIDMap<alphabet_t> const & queryIDMap,
bool const databaseStrand,
StellarOptions & localOptions, // localOptions.compactThresh is out-param
stellar_kernel_runtime & strand_runtime,
Expand Down Expand Up @@ -106,7 +106,7 @@ struct StellarLauncher
STELLAR_DESIGNATED_INITIALIZER(.verifier_options = , localOptions),
};

return _stellarKernel(matcher, database_segment, localOptions, swiftVerifier, isPatternDisabled, onAlignmentResult, strand_runtime);
return _stellarKernel(matcher, database_segment, queryIDMap, localOptions, swiftVerifier, isPatternDisabled, onAlignmentResult, strand_runtime);
});
return statistics;
}
Expand Down
13 changes: 5 additions & 8 deletions include/dream_stellar/stellar_query_segment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,24 @@
namespace dream_stellar
{

template <typename TAlphabet>
struct StellarQuerySegment : public StellarSequenceSegment<TAlphabet>
template <typename alphabet_t>
struct StellarQuerySegment : public StellarSequenceSegment<alphabet_t>
{
using TBase = StellarSequenceSegment<TAlphabet>;
using TBase = StellarSequenceSegment<alphabet_t>;

using typename TBase::TInfixSegment;
using TNestedPatternSegment = seqan2::Segment<TInfixSegment, seqan2::InfixSegment>;

using TBase::TBase; // import constructor

template <typename TSwiftPattern>
static StellarQuerySegment<TAlphabet> fromPatternMatch(TSwiftPattern const & swiftPattern);

seqan2::String<TAlphabet> const & underlyingQuery() const &
std::span<alphabet_t> const & underlyingQuery() const &
{
return this->underlyingSequence();
}

TNestedPatternSegment asPatternSegment() const
{
seqan2::String<TAlphabet> const & _query = underlyingQuery();
std::span<alphabet_t> const & _query = underlyingQuery();
auto patternInfix = this->asInfixSegment();

TInfixSegment const patternInfixSeq = infix(_query, 0, length(_query));
Expand Down
27 changes: 0 additions & 27 deletions include/dream_stellar/stellar_query_segment.tpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ namespace jst::contrib
// seqan3::debug_stream << "Appending fibre \n" << needle << '\n';
}


// like line 108 in stellar_index.hpp
resize(indexShape(_needle_index), _kmer_size);
cargo(_needle_index).abundanceCut = _kmer_abundance_cut;
Expand Down
53 changes: 42 additions & 11 deletions include/valik/search/query_record.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <sstream>

#include <valik/split/metadata.hpp>
#include <dream_stellar/stellar_query_segment.hpp>

#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan/sequence.h>
Expand Down Expand Up @@ -32,18 +33,48 @@ struct shared_query_record
std::string sequence_id;
seq_t sequence;
std::shared_ptr<seq_t> underlyingData;

private:
uint64_t start{0};
uint64_t len;

shared_query_record(std::string id, std::shared_ptr<seq_t> query_ptr) :
sequence_id(std::move(id)), underlyingData(query_ptr)
{
sequence = seq_t((*query_ptr).begin(), (*query_ptr).end());
}

shared_query_record(std::string id, metadata::segment_stats const & seg, std::shared_ptr<seq_t> query_ptr) :
sequence_id(std::move(id)), underlyingData(query_ptr)
{
sequence = seq_t((*query_ptr).begin() + seg.start, (*query_ptr).begin() + seg.start + seg.len);
}
public:
shared_query_record(std::string id, std::shared_ptr<seq_t> query_ptr) :
sequence_id(std::move(id)), underlyingData(query_ptr)
{
sequence = seq_t((*query_ptr).begin(), (*query_ptr).end());
len = (*query_ptr).size();
}

shared_query_record(std::string id, metadata::segment_stats const & seg, std::shared_ptr<seq_t> query_ptr) :
sequence_id(std::move(id)), underlyingData(query_ptr), start(seg.start), len(seg.len)
{
sequence = seq_t((*query_ptr).begin() + seg.start, (*query_ptr).begin() + seg.start + seg.len);
}

shared_query_record(std::string id, uint64_t const other_start, uint64_t const other_len, std::shared_ptr<seq_t> query_ptr) :
sequence_id(std::move(id)), underlyingData(query_ptr), start(other_start), len(other_len)
{
if ((*query_ptr).size() < (start + len))
throw std::runtime_error("Incorrect segment definition. Out of range.");

sequence = seq_t((*query_ptr).begin() + start, len);
}

dream_stellar::StellarQuerySegment<seq_t> get_seqan_segment() const
{
return {*(underlyingData), start, start + len};
}

uint64_t get_start() const
{
return start;
}

uint64_t get_len() const
{
return len;
}
};

} // namespace valik
5 changes: 2 additions & 3 deletions include/valik/search/search_local.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ bool search_local(search_arguments & arguments, search_time_statistics & time_st

auto cart_input_queries_time = stellarThreadTime.input_queries_time.now();
get_cart_queries(records, queries, queryIDs, thread_meta.text_out, thread_meta.text_out);
dream_stellar::QueryIDMap<alphabet_t> queryIDMap{records};

stellarThreadTime.input_queries_time.manual_timing(cart_input_queries_time);

/* Debug
Expand Down Expand Up @@ -295,7 +297,6 @@ bool search_local(search_arguments & arguments, search_time_statistics & time_st
forward_matches.resize(queries.size());

constexpr bool databaseStrand = true;
dream_stellar::QueryIDMap<const alphabet_t, sequence_reference_t> queryIDMap{queries};

dream_stellar::StellarComputeStatistics statistics = dream_stellar::StellarLauncher<const alphabet_t>::search_and_verify
(
Expand Down Expand Up @@ -360,8 +361,6 @@ bool search_local(search_arguments & arguments, search_time_statistics & time_st
reverse_matches.resize(queries.size());

constexpr bool databaseStrand = false;
dream_stellar::QueryIDMap<const alphabet_t, sequence_reference_t> queryIDMap{queries};


dream_stellar::StellarComputeStatistics statistics = dream_stellar::StellarLauncher<const alphabet_t>::search_and_verify
(
Expand Down

0 comments on commit 0032913

Please sign in to comment.