@@ -387,34 +387,43 @@ function hastemplength(record::Record)
387387end
388388
389389"""
390- sequence(record::Record)::BioSequences.LongDNASeq
391-
392- Get the segment sequence of `record`.
393- """
394- function sequence (record:: Record )
395- checkfilled (record)
396- if ismissing (record, record. seq)
397- # missingerror(:sequence)
398- return nothing
399- end
400- seqlen = length (record. seq)
401- ret = BioSequences. LongDNASeq (seqlen)
402- copyto! (ret, 1 , record. data, first (record. seq), seqlen)
403- return ret
390+ sequence(::Type{S}, record::Record, [part::UnitRange{Int}])::S
391+
392+ Get the sequence of `record`.
393+ `S` can be either a subtype of `BioSequences.BioSequence` or `String`.
394+ If `part` argument is given, it returns the specified part of the sequence.
395+ !!! note
396+ This method makes a new sequence object every time.
397+ If you have a sequence already and want to fill it with the sequence
398+ data contained in a fasta record, you can use `Base.copyto!`.
399+ """
400+ function sequence (:: Type{S} , record:: Record , part:: UnitRange{Int} = 1 : lastindex (record. seq)) where S <: BioSequences.LongSequence
401+ checkfilled (record)
402+ if ismissing (record, record. seq)
403+ # missingerror(:sequence)
404+ return nothing
405+ end
406+ seqpart = record. seq[part]
407+ return S (@view (record. data[seqpart]))
408+ end
409+
410+ function sequence (:: Type{String} , record:: Record , part:: UnitRange{Int} = 1 : lastindex (record. seq))
411+ checkfilled (record)
412+ return String (record. data[record. seq[part]])
413+ end
414+
415+ """
416+ sequence(record::Record)::BioSequences.LongDNA{4}
417+
418+ Get the segment sequence of `record`.
419+ """
420+ function sequence (record:: Record , part:: UnitRange{Int} = 1 : lastindex (record. seq))
421+ return sequence (BioSequences. LongDNA{4 }, record, part)
404422end
405423
406424function hassequence (record:: Record )
407425 return isfilled (record) && ! ismissing (record, record. seq)
408426end
409- """
410- sequence(::Type{String}, record::Record)::String
411-
412- Get the segment sequence of `record` as `String`.
413- """
414- function sequence (:: Type{String} , record:: Record ):: String
415- checkfilled (record)
416- return String (record. data[record. seq])
417- end
418427
419428"""
420429 seqlength(record::Record)::Int
0 commit comments