From 6846a04eda7b44ce09d45df18df0dcb7933def21 Mon Sep 17 00:00:00 2001 From: Jakob Nybo Nissen Date: Fri, 22 Oct 2021 14:21:56 +0200 Subject: [PATCH] Fix REPL blocks in docs (#197) * Fix REPL blocks in docs * Fix ambiguities in doctests --- docs/src/composition.md | 5 ++++- docs/src/random.md | 3 ++- src/longsequences/indexing.jl | 12 +++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/docs/src/composition.md b/docs/src/composition.md index f475c8a8c..bd6051cfc 100644 --- a/docs/src/composition.md +++ b/docs/src/composition.md @@ -53,16 +53,19 @@ But there are a few differences: `merge!` is used to accumulate composition statistics of multiple sequences: ```@repl +using BioSequences # hide # initiaize an empty composition counter comp = composition(dna""); # iterate over sequences and accumulate composition statistics into `comp` +seqs = [randdnaseq(10) for i in 1:5] + for seq in seqs merge!(comp, composition(seq)) end # or functional programming style in one line -foldl((x, y) -> merge(x, composition(y)), composition(dna""), seqs) +foldl((x, y) -> merge(x, composition(y)), seqs, init=composition("")) ``` `composition` is also applicable to a *k*-mer iterator: diff --git a/docs/src/random.md b/docs/src/random.md index 9b99f3a7f..01c58c32d 100644 --- a/docs/src/random.md +++ b/docs/src/random.md @@ -25,7 +25,8 @@ SamplerWeighted You can make random `Mer` quite simply using `Base.rand`: ```@repl +using BioSequences # hide rand(DNAMer{7}) rand(RNAMer{8}) rand(BigDNAMer{63}) -``` \ No newline at end of file +``` diff --git a/src/longsequences/indexing.jl b/src/longsequences/indexing.jl index 0e1d3f765..a260f660d 100644 --- a/src/longsequences/indexing.jl +++ b/src/longsequences/indexing.jl @@ -45,6 +45,10 @@ function Base.setindex!(seq::SeqOrView, x, locs::AbstractVector{<:Integer}) unsafe_setindex!(seq, x, locs) end +function Base.setindex!(seq::SeqOrView, x::BioSequence, locs::AbstractVector{<:Integer}) + @boundscheck checkbounds(seq, locs) + unsafe_setindex!(seq, x, locs) +end @inline function unsafe_setindex!(seq::SeqOrView, x, locs::AbstractVector{<:Integer}) bin = encode(Alphabet(seq), convert(eltype(seq), x)) @@ -84,10 +88,16 @@ end # To avoid ambiguity errors function Base.setindex!(seq::SeqOrView{A}, - other::SeqOrView{A}, + other::BioSequence{A}, locs::AbstractVector{<:Integer}) where {A <: Alphabet} @boundscheck checkbounds(seq, locs) checkdimension(other, locs) + unsafe_setindex!(seq, other, locs) +end + +function unsafe_setindex!(seq::SeqOrView{A}, + other::BioSequence, + locs::AbstractVector{<:Integer}) where {A <: Alphabet} @inbounds for (i, n) in zip(locs, other) seq[i] = n end