@@ -22,8 +22,10 @@ struct BiFMIndex {
2222 using NoDelim = BiFMIndex<TSigma, String, SparseArray, false , TReuseRev>;
2323 using ReuseRev = BiFMIndex<TSigma, String, SparseArray, TDelim, true >;
2424
25- static size_t constexpr Sigma = TSigma;
26- static size_t constexpr FirstSymb = TDelim?1 :0 ;
25+ static size_t constexpr Sigma = TSigma;
26+ static size_t constexpr FirstSymb = TDelim?1 :0 ;
27+ static size_t constexpr Delim_v = TDelim;
28+ static size_t constexpr ReuseRev_v = TReuseRev;
2729
2830 // Set RevBwtType to std::nullptr_t to indicate that it should not be used
2931 using RevBwtType = std::conditional_t <TReuseRev, std::nullptr_t , String<Sigma>>;
@@ -56,15 +58,18 @@ struct BiFMIndex {
5658 {}
5759
5860
59- BiFMIndex (Sequence auto const & _sequence, SparseArray const & _annotatedSequence, size_t _threadNbr, bool mirrorInput = false ) {
61+ /*
62+ * \param includeReversedInput assumes that the input data also has the reversed input data
63+ */
64+ BiFMIndex (Sequence auto const & _sequence, SparseArray const & _annotatedSequence, size_t _threadNbr, bool includeReversedInput = false ) {
6065 if (_sequence.size () >= std::numeric_limits<size_t >::max ()/2 ) {
6166 throw std::runtime_error{" sequence is longer than what this system is capable of handling" };
6267 }
6368
6469 bool omegaSorting = !TDelim; // Use omega sorting if no delimiter is being used
6570
6671 // copy text into custom buffer
67- auto inputText = createInputText (_sequence, omegaSorting, mirrorInput );
72+ auto inputText = createInputText (_sequence, omegaSorting, includeReversedInput );
6873
6974 // create bwt, bwtRev and annotatedArray
7075 auto [_bwt, _annotatedArray] = createBWTAndAnnotatedArray (inputText, _annotatedSequence, _threadNbr, omegaSorting);
@@ -97,15 +102,10 @@ struct BiFMIndex {
97102 *
98103 * \param _input a list of sequences
99104 * \param samplingRate rate of the sampling
105+ * \param includeReversedInput also adds all input and their reversed text
100106 */
101- BiFMIndex (Sequences auto const & _input, size_t samplingRate, size_t threadNbr, size_t seqOffset = 0 , bool mirrorInput = false ) {
102- auto [totalSize, inputText, inputSizes] = [&]() {
103- if (TDelim) {
104- return createSequences (_input);
105- } else {
106- return createSequencesWithoutDelimiter (_input);
107- }
108- }();
107+ BiFMIndex (Sequences auto const & _input, size_t samplingRate, size_t threadNbr, size_t seqOffset = 0 , bool includeReversedInput = false ) {
108+ auto [totalSize, inputText, inputSizes] = createSequences (_input, /* ._addReversed=*/ includeReversedInput, /* ._useDelimiters=*/ TDelim);
109109
110110 size_t refId{0 };
111111 size_t pos{0 };
@@ -116,13 +116,10 @@ struct BiFMIndex {
116116 assert (inputSizes.size () < refId);
117117 }
118118
119- auto size = totalSize;
120- if (mirrorInput) size = size*2 ;
121-
122119
123120 auto annotatedSequence = SparseArray {
124- std::views::iota (size_t {0 }, size ) | std::views::transform ([&](size_t phase) -> std::optional<ADEntry> {
125- if (phase < totalSize) { // going forward
121+ std::views::iota (size_t {0 }, totalSize ) | std::views::transform ([&](size_t phase) -> std::optional<ADEntry> {
122+ if (!includeReversedInput || phase* 2 < totalSize) { // going forward
126123 assert (refId < inputSizes.size ());
127124 assert (pos < inputSizes[refId]);
128125
@@ -139,22 +136,20 @@ struct BiFMIndex {
139136 }
140137 return ret;
141138 } else { // going backwards
142- if (phase == totalSize) { // reset values
143- pos = 0 ;
144- refId = 0 ;
145- }
146-
147139 assert (refId < inputSizes.size ());
148- assert (pos < inputSizes[inputSizes. size () - refId - 1 ]);
140+ assert (pos < inputSizes[refId]);
149141
150142 auto ret = std::optional<ADEntry>{std::nullopt };
151143
152144 if (pos % samplingRate == 0 ) {
153- ret = std::make_tuple (inputSizes.size ()*2 - refId+seqOffset-1 , inputSizes[refId] - pos-1 );
145+ auto _refId = _input.size () + inputSizes.size () - refId-1 +seqOffset;
146+ size_t extra = TDelim?1 :0 ;
147+ auto _pos = (inputSizes[refId] - pos + inputSizes[refId] - 1 - extra) % inputSizes[refId];
148+ ret = std::make_tuple (_refId, _pos);
154149 }
155150
156151 ++pos;
157- if (inputSizes[inputSizes. size () - refId - 1 ] == pos) {
152+ if (inputSizes[refId] == pos) {
158153 refId += 1 ;
159154 pos = 0 ;
160155 }
@@ -163,7 +158,7 @@ struct BiFMIndex {
163158 })
164159 };
165160
166- *this = BiFMIndex{inputText, annotatedSequence, threadNbr, mirrorInput };
161+ *this = BiFMIndex{inputText, annotatedSequence, threadNbr, /* includeReversedInput= */ false };
167162 }
168163
169164 auto operator =(BiFMIndex const &) -> BiFMIndex& = delete ;
0 commit comments