Skip to content

Commit 03904b4

Browse files
committed
Move constructors around
1 parent 942728a commit 03904b4

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

src/longsequences/constructors.jl

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,27 @@ 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+
function LongSequence(other::LongSequence, part::AbstractUnitRange{<:Integer})
50+
checkbounds(other, part)
51+
subseq = typeof(other)(undef, length(part))
52+
copyto!(subseq, 1, other, first(part), length(part))
53+
return subseq
54+
end
55+
56+
function LongSequence(seq::BioSequence{A}) where {A <: Alphabet}
57+
return LongSequence{A}(seq)
58+
end
59+
60+
LongSequence{A}(seq::LongSequence{A}) where {A <: Alphabet} = copy(seq)
61+
62+
function (::Type{T})(seq::LongSequence{<:NucleicAcidAlphabet{N}}) where
63+
{N, T<:LongSequence{<:NucleicAcidAlphabet{N}}}
64+
return T(copy(seq.data), seq.len)
65+
end
66+
67+
# Constructors from strings
4768
function LongSequence{A}(s::Union{String, SubString{String}}) where {A<:Alphabet}
4869
return LongSequence{A}(s, codetype(A()))
4970
end
@@ -69,21 +90,4 @@ function LongSequence{A}(
6990
return copyto!(seq, 1, src, first(part), len)
7091
end
7192

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
93+
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)