From a814aade31166f3c09020fcab894b84ecb5cde91 Mon Sep 17 00:00:00 2001 From: "seqan-actions[bot]" Date: Tue, 29 Nov 2022 12:50:42 +0100 Subject: [PATCH] [MISC] clang-format --- include/seqan3/io/sam_file/format_bam.hpp | 38 +++++++++++-------- .../detail/fast_istreambuf_iterator.hpp | 9 +++-- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/include/seqan3/io/sam_file/format_bam.hpp b/include/seqan3/io/sam_file/format_bam.hpp index 14c292c471..bab4b26abd 100644 --- a/include/seqan3/io/sam_file/format_bam.hpp +++ b/include/seqan3/io/sam_file/format_bam.hpp @@ -442,7 +442,8 @@ format_bam::read_alignment_record(stream_type & stream, if constexpr (!detail::decays_to_ignore_v) { int32_t seq_length{}; - std::tie(cigar_vector, ref_length, seq_length) = parse_binary_cigar(record_str.substr(considered_bytes, core.n_cigar_op * 4), core.n_cigar_op); + std::tie(cigar_vector, ref_length, seq_length) = + parse_binary_cigar(record_str.substr(considered_bytes, core.n_cigar_op * 4), core.n_cigar_op); } considered_bytes += core.n_cigar_op * 4; @@ -454,15 +455,18 @@ format_bam::read_alignment_record(stream_type & stream, size_t const number_of_bytes = (core.l_seq + 1) / 2; std::string_view const seq_str = record_str.substr(considered_bytes, number_of_bytes); - seq.resize(core.l_seq + 1/* reserve one more in case size is uneven. will be corrected */); // TODO: .resize() is not generic + seq.resize( + core.l_seq + + 1 /* reserve one more in case size is uneven. will be corrected */); // TODO: .resize() is not generic using alph_t = std::ranges::range_value_t; constexpr auto from_dna16 = detail::convert_through_char_representation; - for (size_t i = 0,j = 0; i < number_of_bytes; ++i, j+=2) + for (size_t i = 0, j = 0; i < number_of_bytes; ++i, j += 2) { seq[j] = from_dna16[to_rank(dna16sam{}.assign_rank(std::min(15, static_cast(seq_str[i]) >> 4)))]; - seq[j + 1] = from_dna16[to_rank(dna16sam{}.assign_rank(std::min(15, static_cast(seq_str[i]) & 0x0f)))]; + seq[j + 1] = + from_dna16[to_rank(dna16sam{}.assign_rank(std::min(15, static_cast(seq_str[i]) & 0x0f)))]; } seq.resize(core.l_seq); // remove extra letter @@ -488,7 +492,8 @@ format_bam::read_alignment_record(stream_type & stream, int32_t remaining_bytes = core.block_size - (sizeof(alignment_record_core) - 4 /*block_size excluded*/) - core.l_read_name - core.n_cigar_op * 4 - (core.l_seq + 1) / 2 - core.l_seq; assert(remaining_bytes >= 0); - assert(static_cast(remaining_bytes) == core.block_size - (sizeof(alignment_record_core) - 4) - considered_bytes); + assert(static_cast(remaining_bytes) + == core.block_size - (sizeof(alignment_record_core) - 4) - considered_bytes); if constexpr (!detail::decays_to_ignore_v) read_sam_dict(record_str.substr(considered_bytes), tag_dict); @@ -1203,14 +1208,14 @@ inline void format_bam::read_sam_dict(std::string_view const tag_str, sam_tag_di } case 'Z': // string { - std::string_view v = std::string_view{static_cast(it)}; // parses until '\0' + std::string_view v = std::string_view{static_cast(it)}; // parses until '\0' target[tag] = std::string{v}; it += v.size() + 1; break; } case 'H': // byte array, represented as null-terminated string; specification requires even number of bytes { - std::string_view str = std::string_view{static_cast(it)}; // parses until '\0' + std::string_view str = std::string_view{static_cast(it)}; // parses until '\0' std::vector tmp_vector; // std::from_chars cannot directly parse into a std::byte @@ -1219,17 +1224,18 @@ inline void format_bam::read_sam_dict(std::string_view const tag_str, sam_tag_di if (str.size() % 2 != 0) throw format_error{"[CORRUPTED BAM FILE] Hexadecimal tag must have even number of digits."}; - for (size_t i = 0; i < str.size(); i+=2) + for (size_t i = 0; i < str.size(); i += 2) { auto res = std::from_chars(str.begin() + i, str.begin() + i + 2, dummy_byte, 16); if (res.ec == std::errc::invalid_argument) throw format_error{std::string("[CORRUPTED BAM FILE] The string '") - + std::string(str.begin() + i, str.begin() + i + 2) + "' could not be cast into type uint8_t."}; + + std::string(str.begin() + i, str.begin() + i + 2) + + "' could not be cast into type uint8_t."}; if (res.ec == std::errc::result_out_of_range) throw format_error{std::string("[CORRUPTED BAM FILE] Casting '") + std::string(str) - + "' into type uint8_t would cause an overflow."}; + + "' into type uint8_t would cause an overflow."}; tmp_vector.push_back(std::byte{dummy_byte}); } @@ -1278,17 +1284,17 @@ inline void format_bam::read_sam_dict(std::string_view const tag_str, sam_tag_di break; default: throw format_error{detail::to_string("The first character in the numerical id of a SAM tag ", - "must be one of [cCsSiIf] but '", - array_value_type_id, - "' was given.")}; + "must be one of [cCsSiIf] but '", + array_value_type_id, + "' was given.")}; } break; } default: throw format_error{detail::to_string("The second character in the numerical id of a " - "SAM tag must be one of [A,i,Z,H,B,f] but '", - type_id, - "' was given.")}; + "SAM tag must be one of [A,i,Z,H,B,f] but '", + type_id, + "' was given.")}; } } } diff --git a/include/seqan3/io/stream/detail/fast_istreambuf_iterator.hpp b/include/seqan3/io/stream/detail/fast_istreambuf_iterator.hpp index 829cfb7c78..5f8220a112 100644 --- a/include/seqan3/io/stream/detail/fast_istreambuf_iterator.hpp +++ b/include/seqan3/io/stream/detail/fast_istreambuf_iterator.hpp @@ -166,7 +166,6 @@ class fast_istreambuf_iterator raw_record[i] = std::string_view{data_begin + field_positions[i - 1] + 1, data_begin + field_positions[i]}; } - std::string_view cache_bytes(int32_t const size) { std::string_view result; @@ -186,14 +185,18 @@ class fast_istreambuf_iterator { if (stream_buf->egptr() - stream_buf->gptr() < remaining_bytes) // still not fully in buffer { - std::ranges::copy(stream_buf->gptr(), stream_buf->egptr(), overflow_buffer.data() + size - remaining_bytes); + std::ranges::copy(stream_buf->gptr(), + stream_buf->egptr(), + overflow_buffer.data() + size - remaining_bytes); size_t const number_of_copied_bytes = stream_buf->egptr() - stream_buf->gptr(); remaining_bytes -= number_of_copied_bytes; stream_buf->gbump(number_of_copied_bytes); stream_buf->underflow(); } } - std::ranges::copy(stream_buf->gptr(), stream_buf->gptr() + remaining_bytes, overflow_buffer.data() + size - remaining_bytes); + std::ranges::copy(stream_buf->gptr(), + stream_buf->gptr() + remaining_bytes, + overflow_buffer.data() + size - remaining_bytes); result = {overflow_buffer.begin(), overflow_buffer.end()}; }