Skip to content

Commit

Permalink
[FIX] Add size function to kmer_hash view
Browse files Browse the repository at this point in the history
  • Loading branch information
MitraDarja committed Apr 28, 2020
1 parent 60fc743 commit 142f05b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ Note that 3.1.0 will be the first API stable release and interfaces in this rele
([\#1410](https://github.com/seqan/seqan3/pull/1410)).
* Renamed `seqan3::views::all` to `seqan3::views::type_reduce`
([\#1410](https://github.com/seqan/seqan3/pull/1410)).
* Added size() function to `seqan3::views::kmer_hash`
([\#1722](https://github.com/seqan/seqan3/pull/1722)).

#### Search

Expand Down
11 changes: 11 additions & 0 deletions include/seqan3/range/views/kmer_hash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,17 @@ class kmer_hash_view : public std::ranges::view_interface<kmer_hash_view<urng_t>
return end();
}
//!\}

/*!\brief Returns the size of the range, if the underlying range is a std::ranges::sized_range.
* \returns Size of range.
*/
uint64_t size()
requires std::ranges::sized_range<urng_t>
{
if (std::ranges::size(urange) >= shape_.size())
return std::ranges::size(urange) - shape_.size() + 1;
return 0;
}
};

/*!\brief Iterator for calculating hash values via a given seqan3::shape.
Expand Down
13 changes: 13 additions & 0 deletions test/unit/range/views/view_kmer_hash_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,16 @@ TEST_F(kmer_hash_test, issue1643)
auto k_mer_size_25_view = text_23_elements | seqan3::views::kmer_hash(seqan3::ungapped{25u});
EXPECT_TRUE(k_mer_size_25_view.empty());
}

// https://github.com/seqan/seqan3/issues/1719
TEST_F(kmer_hash_test, issue1719)
{
uint64_t const expected = 0;
std::vector<seqan3::dna5> sequence{""_dna5};
auto v = sequence | seqan3::views::kmer_hash(seqan3::ungapped{25});
EXPECT_EQ(expected, v.size());

std::vector<seqan3::dna5> sequence2{"ACGATCGATCGTAGCTACTGAGC"_dna5};
auto v2 = sequence2 | seqan3::views::kmer_hash(seqan3::ungapped{25});
EXPECT_EQ(expected, v2.size());
}

0 comments on commit 142f05b

Please sign in to comment.