This repository has been archived by the owner on Aug 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SymbolRange, cyclic arithmetic, and more informative
show
method. (#…
…190) * add SymbolRange type * make symbol arithmetic cyclic * make show(nucleotide|amino acid) more informative * fix seq.md
- Loading branch information
1 parent
bc2fe43
commit 1688351
Showing
8 changed files
with
274 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# SymbolRange | ||
# =========== | ||
# | ||
# Range type of biological symbols. | ||
# | ||
# This file is a part of BioJulia. | ||
# License is MIT: https://github.com/BioJulia/Bio.jl/blob/master/LICENSE.md | ||
|
||
""" | ||
Range type of biological symbols (especially `DNANucleotide`, `RNANucleotide`, | ||
and `AminoAcid`). | ||
""" | ||
immutable SymbolRange{T} <: Range{T} | ||
start::UInt8 | ||
stop::UInt8 | ||
|
||
function SymbolRange(start::T, stop::T) | ||
if start > stop | ||
# normalize empty range | ||
start = convert(T, 0x01) | ||
stop = convert(T, 0x00) | ||
end | ||
return new(start, stop) | ||
end | ||
end | ||
|
||
function SymbolRange{T}(start::T, stop::T) | ||
return SymbolRange{T}(start, stop) | ||
end | ||
|
||
function Base.show(io::IO, r::SymbolRange) | ||
show(io, first(r)) | ||
write(io, ':') | ||
show(io, last(r)) | ||
end | ||
|
||
|
||
# Iterator | ||
# -------- | ||
|
||
Base.start(r::SymbolRange) = r.start | ||
Base.done(r::SymbolRange, i) = i > r.stop | ||
Base.next(r::SymbolRange, i) = reinterpret(eltype(r), i), i + 0x01 | ||
|
||
Base.size(r::SymbolRange) = (r.stop - r.start + 1,) | ||
Base.first(r::SymbolRange) = convert(eltype(r), r.start) | ||
Base.last(r::SymbolRange) = convert(eltype(r), r.stop) | ||
Base.in{T}(x::T, r::SymbolRange{T}) = first(r) ≤ x ≤ last(r) | ||
|
||
|
||
# Indexing | ||
# -------- | ||
|
||
function Base.getindex(r::SymbolRange, i::Integer) | ||
checkbounds(r, i) | ||
return convert(eltype(r), r.start + i - 1) | ||
end | ||
|
||
function Base.getindex{T}(r::SymbolRange{T}, ir::UnitRange) | ||
checkbounds(r, ir) | ||
if isempty(ir) | ||
return SymbolRange(T(0x01), T(0x00)) | ||
else | ||
return SymbolRange(r[first(ir)], r[last(ir)]) | ||
end | ||
end |
Oops, something went wrong.