Skip to content

Instantly share code, notes, and snippets.

@smehringer
Created June 22, 2022 07:19
Show Gist options
  • Save smehringer/de2698f3ae6117ff851de1a240b31580 to your computer and use it in GitHub Desktop.
Save smehringer/de2698f3ae6117ff851de1a240b31580 to your computer and use it in GitHub Desktop.
I/O API design - Hannes vs. Current
// Standard example
===================
// current implementation:
seqan3::sequence_file_input in{"x.fasta"};
for (auto && rec : in)
seqan3::debug_stream << rec.sequence();
// -------------------------------------------------------------------------------------------------------------------------
// Hannes implementation:
seqan3::seq_io::reader in{"x.fasta"};
for (auto && rec : in)
seqan3::debug_stream << rec.sequence();
// Decomposition example
========================
// current implementation:
seqan3::sequence_file_input in{"x.fasta"};
for (auto & [ i, s, q ] : in)
seqan3::debug_stream << "ID: " << i << '\n';
// -------------------------------------------------------------------------------------------------------------------------
// Hannes implementation:
seqan3::seq_io::reader reader{"example.fasta"};
for (auto & [ i, s, q ] : reader)
seqan3::debug_stream << "ID: " << i << '\n';
// Simple options example
=========================
// current implementation:
seqan3::sequence_file_input in{"x.fasta"};
in.options.truncate_ids = true; // must (should?) be done before the first record is read
// -------------------------------------------------------------------------------------------------------------------------
// Hannes implementation:
seqan3::seq_io::reader reader{"example.fasta", seqan3::seq_io::reader_options{.truncate_ids = true }};
// Select different types
=========================
// current implementation:
struct my_traits : seqan3::sequence_file_input_default_traits_dna
{
using sequence_alphabet = char; // instead of dna5
template <typename alph>
using sequence_container = std::basic_string<alph>; // must be defined as a template! String_view is not possible
};
seqan3::sequence_file_input<my_traits> fin{"x.fasta"};
// -------------------------------------------------------------------------------------------------------------------------
// Hannes implementation:
seqan3::seq_io::reader reader{"example.fasta",
seqan3::seq_io::reader_options{
.field_types = seqan3::ttag<std::string_view, std::string, std::string>};
// Select different fields
=========================
// current implementation:
seqan3::sequence_file_input fin{"x.fasta", seqan3::fields<seqan3::field::id, seqan3::field::qual>()};
// -------------------------------------------------------------------------------------------------------------------------
// Hannes implementation:
seqan3::seq_io::reader reader{"example.fasta",
seqan3::seq_io::reader_options{
.field_ids = bio::vtag<seqan3::field::id, seqan3::field::qual>,
.field_types = seqan3::ttag<std::string_view, std::vector<seqan3::phred62>>}; // tyoes have to be also given
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment