mirror of
https://github.com/metabarcoding/obitools4.git
synced 2026-03-25 13:30:52 +00:00
Use NewBioSequenceOwning to avoid unnecessary sequence copying
Replace NewBioSequence with NewBioSequenceOwning in genbank_read.go to take ownership of sequence slices without copying, improving performance. Update biosequence.go to add the new TakeSequence method and NewBioSequenceOwning constructor.
This commit is contained in:
@@ -120,6 +120,19 @@ func NewBioSequence(id string,
|
||||
return bs
|
||||
}
|
||||
|
||||
// NewBioSequenceOwning creates a BioSequence taking ownership of the sequence
|
||||
// slice without copying it. The caller must not use the slice after this call.
|
||||
// Use this when the slice was allocated specifically for this sequence.
|
||||
func NewBioSequenceOwning(id string,
|
||||
sequence []byte,
|
||||
definition string) *BioSequence {
|
||||
bs := NewEmptyBioSequence(0)
|
||||
bs.SetId(id)
|
||||
bs.TakeSequence(sequence)
|
||||
bs.SetDefinition(definition)
|
||||
return bs
|
||||
}
|
||||
|
||||
// NewBioSequenceWithQualities creates a new BioSequence object with the given id, sequence, definition, and qualities.
|
||||
//
|
||||
// Parameters:
|
||||
@@ -444,6 +457,12 @@ func (s *BioSequence) SetSequence(sequence []byte) {
|
||||
s.sequence = obiutils.InPlaceToLower(CopySlice(sequence))
|
||||
}
|
||||
|
||||
// TakeSequence stores the slice directly without copying, then lowercases in-place.
|
||||
// The caller must not use the slice after this call.
|
||||
func (s *BioSequence) TakeSequence(sequence []byte) {
|
||||
s.sequence = obiutils.InPlaceToLower(sequence)
|
||||
}
|
||||
|
||||
func (s *BioSequence) HasValidSequence() bool {
|
||||
for _, c := range s.sequence {
|
||||
if !((c >= 'a' && c <= 'z') || c == '-' || c == '.' || c == '[' || c == ']') {
|
||||
|
||||
Reference in New Issue
Block a user