mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-12-08 16:50:27 +00:00
Change the way sequence definition are managed. They are now when present stored as an attribute
Former-commit-id: 6e618377c05b42937d2eace3c9668390980ab68c
This commit is contained in:
@@ -55,8 +55,8 @@ type Annotation map[string]interface{}
|
||||
// A BioSequence is a sequence of bytes with an identifier, a definition, a sequence, qualities,
|
||||
// features and annotations. It aims to represent a biological sequence
|
||||
type BioSequence struct {
|
||||
id string // The identidier of the sequence (private accessible through the method Id)
|
||||
definition string // The documentation of the sequence (private accessible through the method Definition)
|
||||
id string // The identidier of the sequence (private accessible through the method Id)
|
||||
//definition string // The documentation of the sequence (private accessible through the method Definition)
|
||||
source string // The filename without directory name and extension from where the sequence was read.
|
||||
sequence []byte // The sequence itself, it is accessible by the methode Sequence
|
||||
qualities []byte // The quality scores of the sequence.
|
||||
@@ -80,8 +80,8 @@ func NewEmptyBioSequence(preallocate int) *BioSequence {
|
||||
}
|
||||
|
||||
return &BioSequence{
|
||||
id: "",
|
||||
definition: "",
|
||||
id: "",
|
||||
//definition: "",
|
||||
source: "",
|
||||
sequence: seq,
|
||||
qualities: nil,
|
||||
@@ -148,7 +148,7 @@ func (s *BioSequence) Copy() *BioSequence {
|
||||
newSeq := NewEmptyBioSequence(0)
|
||||
|
||||
newSeq.id = s.id
|
||||
newSeq.definition = s.definition
|
||||
//newSeq.definition = s.definition
|
||||
|
||||
newSeq.sequence = CopySlice(s.sequence)
|
||||
newSeq.qualities = CopySlice(s.qualities)
|
||||
@@ -176,7 +176,16 @@ func (s *BioSequence) Id() string {
|
||||
// No parameters.
|
||||
// Returns a string.
|
||||
func (s *BioSequence) Definition() string {
|
||||
return s.definition
|
||||
definition := ""
|
||||
var err error
|
||||
def, ok := s.GetAttribute("definition")
|
||||
if ok {
|
||||
definition, err = obiutils.InterfaceToString(def)
|
||||
if err != nil {
|
||||
definition = ""
|
||||
}
|
||||
}
|
||||
return definition
|
||||
}
|
||||
|
||||
// Sequence returns the sequence of the BioSequence.
|
||||
@@ -315,7 +324,7 @@ func (s *BioSequence) SetId(id string) {
|
||||
//
|
||||
// It takes a string parameter 'definition' and assigns it to the 'definition' field of the BioSequence struct.
|
||||
func (s *BioSequence) SetDefinition(definition string) {
|
||||
s.definition = definition
|
||||
s.SetAttribute("definition", definition)
|
||||
}
|
||||
|
||||
// SetSource sets the source of the BioSequence.
|
||||
|
||||
@@ -143,11 +143,10 @@ func TestBioSequence_Recycle(t *testing.T) {
|
||||
// Returns: None.
|
||||
func TestCopy(t *testing.T) {
|
||||
seq := &BioSequence{
|
||||
id: "test",
|
||||
definition: "test sequence",
|
||||
sequence: []byte("ATCG"),
|
||||
qualities: []byte("1234"),
|
||||
feature: []byte("feature1...feature2"),
|
||||
id: "test",
|
||||
sequence: []byte("ATCG"),
|
||||
qualities: []byte("1234"),
|
||||
feature: []byte("feature1...feature2"),
|
||||
annotations: Annotation{
|
||||
"annotation1": "value1",
|
||||
"annotation2": "value2",
|
||||
@@ -161,10 +160,6 @@ func TestCopy(t *testing.T) {
|
||||
if newSeq.id != seq.id {
|
||||
t.Errorf("Expected id to be %v, got %v", seq.id, newSeq.id)
|
||||
}
|
||||
if newSeq.definition != seq.definition {
|
||||
t.Errorf("Expected definition to be %v, got %v", seq.definition, newSeq.definition)
|
||||
}
|
||||
|
||||
// Test if the sequence, qualities, and feature fields are copied correctly
|
||||
if !reflect.DeepEqual(newSeq.sequence, seq.sequence) {
|
||||
t.Errorf("Expected sequence to be %v, got %v", seq.sequence, newSeq.sequence)
|
||||
|
||||
@@ -32,7 +32,7 @@ func (sequence *BioSequence) Subsequence(from, to int, circular bool) (*BioSeque
|
||||
}
|
||||
|
||||
newSeq.id = fmt.Sprintf("%s_sub[%d..%d]", sequence.Id(), from+1, to)
|
||||
newSeq.definition = sequence.definition
|
||||
// newSeq.definition = sequence.definition
|
||||
} else {
|
||||
newSeq, _ = sequence.Subsequence(from, sequence.Len(), false)
|
||||
newSeq.Write(sequence.Sequence()[0:to])
|
||||
|
||||
Reference in New Issue
Block a user