Skip to content

Commit

Permalink
[DOC] update sequence_file tutorial snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
marehr committed Apr 28, 2021
1 parent 2d56d3a commit e7c00d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
2 changes: 1 addition & 1 deletion doc/tutorial/sequence_file/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ that have a length of at least 5.

Hints:
* You can use `std::ranges::size` to retrieve the size of a range.
* You need the following includes for std::views::filter and std::take
* You need the following includes for std::views::filter and std::views::take
\snippet doc/tutorial/sequence_file/sequence_file_snippets.cpp include_ranges


Expand Down
27 changes: 6 additions & 21 deletions doc/tutorial/sequence_file/sequence_file_solution3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ write_file_dummy_struct go{};

#include <seqan3/core/debug_stream.hpp>
#include <seqan3/io/sequence_file/all.hpp>
#include <seqan3/range/views/move.hpp>

int main()
{
Expand All @@ -70,26 +69,12 @@ int main()
return std::ranges::size(rec.sequence()) >= 5;
});

// you can use a for loop

// for (auto & rec : fin | length_filter | std::views::take(2))
// {
// seqan3::debug_stream << "ID: " << rec.id() << '\n';
// }

// But you can also do this to retrieve all IDs into a vector:
std::vector<std::string> ids = fin
| length_filter // apply length filter
| std::views::take(2) // take first two records
| std::views::transform(&decltype(fin)::record_type::id) // select only ID from record
// this is the same as writing:
// | std::views::transform([](auto && record)
// {
// return record.id();
// })
| seqan3::views::move // mark ID to be moved out of record
| seqan3::views::to<std::vector<std::string>>; // convert to container
// Note that you need to know the type of id (std::string)
// Store all IDs into a vector:
std::vector<std::string> ids{};
for (auto & rec : fin | length_filter | std::views::take(2))
{
ids.push_back(std::move(rec.id()));
}

seqan3::debug_stream << ids << '\n';
}
Expand Down

0 comments on commit e7c00d1

Please sign in to comment.