mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-12-08 16:50:27 +00:00
Big change iin the data model, and a first version of obiuniq
This commit is contained in:
@@ -7,32 +7,32 @@ import (
|
||||
|
||||
// Returns a sub sequence start from position 'from' included,
|
||||
// to position 'to' excluded. Coordinates start at position 0.
|
||||
func (sequence BioSequence) Subsequence(from, to int, circular bool) (BioSequence, error) {
|
||||
func (sequence *BioSequence) Subsequence(from, to int, circular bool) (*BioSequence, error) {
|
||||
|
||||
if from >= to && !circular {
|
||||
return NilBioSequence, errors.New("from greater than to")
|
||||
return nil, errors.New("from greater than to")
|
||||
}
|
||||
|
||||
if from < 0 || from >= sequence.Length() {
|
||||
return NilBioSequence, errors.New("from out of bounds")
|
||||
return nil, errors.New("from out of bounds")
|
||||
}
|
||||
|
||||
if to <= 0 || to > sequence.Length() {
|
||||
return NilBioSequence, errors.New("to out of bounds")
|
||||
return nil, errors.New("to out of bounds")
|
||||
}
|
||||
|
||||
var newSeq BioSequence
|
||||
var newSeq *BioSequence
|
||||
|
||||
if from < to {
|
||||
newSeq = MakeEmptyBioSequence()
|
||||
newSeq = NewEmptyBioSequence()
|
||||
newSeq.Write(sequence.Sequence()[from:to])
|
||||
|
||||
if sequence.HasQualities() {
|
||||
newSeq.WriteQualities(sequence.Qualities()[from:to])
|
||||
}
|
||||
|
||||
newSeq.sequence.id = fmt.Sprintf("%s_sub[%d..%d]", sequence.Id(), from+1, to)
|
||||
newSeq.sequence.definition = sequence.sequence.definition
|
||||
newSeq.id = fmt.Sprintf("%s_sub[%d..%d]", sequence.Id(), from+1, to)
|
||||
newSeq.definition = sequence.definition
|
||||
} else {
|
||||
newSeq, _ = sequence.Subsequence(from, sequence.Length(), false)
|
||||
newSeq.Write(sequence.Sequence()[0:to])
|
||||
@@ -44,7 +44,7 @@ func (sequence BioSequence) Subsequence(from, to int, circular bool) (BioSequenc
|
||||
}
|
||||
|
||||
if len(sequence.Annotations()) > 0 {
|
||||
newSeq.sequence.annotations = GetAnnotation(sequence.Annotations())
|
||||
newSeq.annotations = GetAnnotation(sequence.Annotations())
|
||||
}
|
||||
|
||||
return newSeq, nil
|
||||
|
||||
Reference in New Issue
Block a user