Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] cigar.assign_string from char pointers. #2966

Merged
merged 1 commit into from
Jun 7, 2022

Conversation

smehringer
Copy link
Member

@smehringer smehringer commented Apr 22, 2022

My use case is the following:

From an input file stream (a SAM file) I want to construct a std::vector<seqan3::cigar> from a given cigar string e.g. 3M. The current overload seqan3::cigar::assign_string(seqan3::small_string s) would copy the string into a small_string before reading it and converting it to a respective letter of seqan3::cigar. This is an unnecessary copy. We can avoid this by providing an overload with const char *.

@vercel
Copy link

vercel bot commented Apr 22, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
seqan3 ✅ Ready (Inspect) Visit Preview Jun 7, 2022 at 10:07AM (UTC)

@codecov
Copy link

codecov bot commented Apr 22, 2022

Codecov Report

Merging #2966 (173a41b) into master (df3f29a) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #2966   +/-   ##
=======================================
  Coverage   98.20%   98.21%           
=======================================
  Files         274      274           
  Lines       12216    12216           
=======================================
+ Hits        11997    11998    +1     
+ Misses        219      218    -1     
Impacted Files Coverage Δ
include/seqan3/alphabet/cigar/cigar.hpp 90.90% <100.00%> (ø)
include/seqan3/io/sam_file/detail/cigar.hpp 98.03% <100.00%> (ø)
include/seqan3/utility/container/small_string.hpp 98.66% <100.00%> (+0.03%) ⬆️
include/seqan3/utility/container/small_vector.hpp 99.32% <0.00%> (-0.01%) ⬇️
include/seqan3/utility/views/zip.hpp 100.00% <0.00%> (ø)
include/seqan3/core/detail/persist_view.hpp 100.00% <0.00%> (ø)
include/seqan3/utility/views/interleave.hpp 100.00% <0.00%> (ø)
include/seqan3/io/views/async_input_buffer.hpp 98.18% <0.00%> (ø)
include/seqan3/utility/views/single_pass_input.hpp 100.00% <0.00%> (ø)
...lude/seqan3/io/sam_file/detail/format_sam_base.hpp 97.97% <0.00%> (ø)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update df3f29a...173a41b. Read the comment docs.

@h-2
Copy link
Member

h-2 commented Apr 22, 2022

In C++23 we could do with a single overload that accepts std::string_view. Right now I would recommend:

cigar & assign_string(std::string_view const s) // not noexcept, should throw on problem
{
    // implementation
}

template <std::ranges::contiguous_range rng_t>
    requires (std::ranges::sized_range<rng_t> && std::same_as<char, std::ranges::range_value_t<rng_t>>)
cigar & assign_string(rng_t && s)
{
    return assign_string(std::string_view{std::ranges::data(s), std::ranges::size(s)});
}

I don't know why there should be an overload for small_string.

@marehr
Copy link
Member

marehr commented May 23, 2022 via email

Comment on lines 162 to 170
/*!\brief Assign from a contigous char array.
* \details
* \experimentalapi{Experimental since version 3.1.}
*
* In order to avoid unnecessary copies, you can initialise a seqan3::cigar from two char pointers that point to a
* contigous char array that stores the cigar string.
*
* \include test/snippet/alphabet/cigar/cigar_assign_string.cpp
*
* \attention If the cigar count cannot be correctly read, `0P` is added instead to the cigar string.
* Adding 0 padding is not impacting the alignment that the cigar string represents but
* keeps the number of cigar elements consistent with the input.
*
* \experimentalapi{Experimental since version 3.2.}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs an update (still refers to two char const *)

@eseiler eseiler marked this pull request as ready for review May 31, 2022 14:08
@seqan-actions seqan-actions added lint [INTERNAL] signal for linting and removed lint [INTERNAL] signal for linting labels May 31, 2022
@smehringer smehringer requested a review from eseiler June 3, 2022 10:42
@seqan-actions seqan-actions added lint [INTERNAL] signal for linting and removed lint [INTERNAL] signal for linting labels Jun 3, 2022
@seqan-actions seqan-actions added lint [INTERNAL] signal for linting and removed lint [INTERNAL] signal for linting labels Jun 3, 2022
@eseiler eseiler enabled auto-merge June 7, 2022 09:49
@seqan-actions seqan-actions added lint [INTERNAL] signal for linting and removed lint [INTERNAL] signal for linting labels Jun 7, 2022
@eseiler eseiler merged commit 0ac4aa2 into seqan:master Jun 7, 2022
@smehringer smehringer deleted the cigar_string branch November 27, 2023 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants