Skip to content

Commit

Permalink
Fix REPL blocks in docs (#197)
Browse files Browse the repository at this point in the history
* Fix REPL blocks in docs
* Fix ambiguities in doctests
  • Loading branch information
jakobnissen authored Oct 22, 2021
1 parent 08a67d7 commit 6846a04
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 4 additions & 1 deletion docs/src/composition.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion docs/src/random.md
Original file line number Diff line number Diff line change
Expand Up @@ -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})
```
```
12 changes: 11 additions & 1 deletion src/longsequences/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6846a04

Please sign in to comment.