Skip to content

Commit 31936ce

Browse files
authored
Cosmetic changes in constructors (#240)
Small fixes and simplifications
1 parent 625ab2f commit 31936ce

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

src/longsequences/constructors.jl

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function LongSequence{A}(it) where {A <: Alphabet}
2727
data = Vector{UInt64}(undef, seq_data_len(A, len))
2828
bits = zero(UInt)
2929
bitind = bitindex(BitsPerSymbol(A()), encoded_data_eltype(LongSequence{A}), 1)
30-
@inbounds for (i, x) in enumerate(it)
30+
@inbounds for x in it
3131
xT = convert(eltype(A), x)
3232
enc = encode(A(), xT)
3333
bits |= enc << offset(bitind)
@@ -44,6 +44,22 @@ end
4444
Base.empty(::Type{T}) where {T <: LongSequence} = T(UInt[], UInt(0))
4545
(::Type{T})() where {T <: LongSequence} = empty(T)
4646

47+
# Constructors from other sequences
48+
# TODO: Remove this method, since the user can just slice
49+
LongSequence(s::LongSequence, xs::AbstractUnitRange{<:Integer}) = s[xs]
50+
51+
function LongSequence(seq::BioSequence{A}) where {A <: Alphabet}
52+
return LongSequence{A}(seq)
53+
end
54+
55+
LongSequence{A}(seq::LongSequence{A}) where {A <: Alphabet} = copy(seq)
56+
57+
function (::Type{T})(seq::LongSequence{<:NucleicAcidAlphabet{N}}) where
58+
{N, T<:LongSequence{<:NucleicAcidAlphabet{N}}}
59+
return T(copy(seq.data), seq.len)
60+
end
61+
62+
# Constructors from strings
4763
function LongSequence{A}(s::Union{String, SubString{String}}) where {A<:Alphabet}
4864
return LongSequence{A}(s, codetype(A()))
4965
end
@@ -69,21 +85,4 @@ function LongSequence{A}(
6985
return copyto!(seq, 1, src, first(part), len)
7086
end
7187

72-
# create a subsequence
73-
function LongSequence(other::LongSequence, part::AbstractUnitRange{<:Integer})
74-
checkbounds(other, part)
75-
subseq = typeof(other)(undef, length(part))
76-
copyto!(subseq, 1, other, first(part), length(part))
77-
return subseq
78-
end
79-
80-
function LongSequence(seq::BioSequence{A}) where {A <: Alphabet}
81-
return LongSequence{A}(seq)
82-
end
83-
84-
LongSequence{A}(seq::LongSequence{A}) where {A <: Alphabet} = copy(seq)
85-
86-
function (::Type{T})(seq::LongSequence{<:NucleicAcidAlphabet{N}}) where
87-
{N, T<:LongSequence{<:NucleicAcidAlphabet{N}}}
88-
return T(copy(seq.data), seq.len)
89-
end
88+
Base.parse(::Type{LongSequence{A}}, seq::AbstractString) where A = LongSequence{A}(seq)

src/longsequences/conversion.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,3 @@ function Base.convert(::Type{T}, seq::LongSequence{<:NucleicAcidAlphabet}) where
2626
{T<:LongSequence{<:NucleicAcidAlphabet}}
2727
return T(seq)
2828
end
29-
30-
Base.parse(::Type{LongSequence{A}}, seq::AbstractString) where A = LongSequence{A}(seq)

0 commit comments

Comments
 (0)