mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
patch the Taxid method
This commit is contained in:
@ -1,3 +1,13 @@
|
|||||||
|
// A package that defines a BioSequence struct.
|
||||||
|
//
|
||||||
|
// BioSequence are used to représente biological DNA sequences.
|
||||||
|
// The structure stores not only the sequence itself, but also some
|
||||||
|
// complementaty information. Among them:
|
||||||
|
// - an identifier
|
||||||
|
// - a definition
|
||||||
|
// - the sequence quality scores
|
||||||
|
// - the features
|
||||||
|
// - the annotations
|
||||||
package obiseq
|
package obiseq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -260,7 +270,7 @@ func (s *BioSequence) Count() int {
|
|||||||
|
|
||||||
// Returning the taxid of the sequence.
|
// Returning the taxid of the sequence.
|
||||||
func (s *BioSequence) Taxid() int {
|
func (s *BioSequence) Taxid() int {
|
||||||
taxid, ok := s.GetInt("count")
|
taxid, ok := s.GetInt("taxid")
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
taxid = 1
|
taxid = 1
|
||||||
@ -269,6 +279,11 @@ func (s *BioSequence) Taxid() int {
|
|||||||
return taxid
|
return taxid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *BioSequence) SetTaxid(taxid int) {
|
||||||
|
annot := s.Annotations()
|
||||||
|
annot["taxid"] = taxid
|
||||||
|
}
|
||||||
|
|
||||||
// Setting the id of the BioSequence.
|
// Setting the id of the BioSequence.
|
||||||
func (s *BioSequence) SetId(id string) {
|
func (s *BioSequence) SetId(id string) {
|
||||||
s.id = id
|
s.id = id
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
package obiseq
|
package obiseq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// BioSequenceSlice represents a collection or a set of BioSequence.
|
||||||
|
//
|
||||||
|
// BioSequenceSlice is used to define BioSequenceBatch
|
||||||
|
// a memory pool of BioSequenceSlice is managed to limit allocations.
|
||||||
type BioSequenceSlice []*BioSequence
|
type BioSequenceSlice []*BioSequence
|
||||||
|
|
||||||
var _BioSequenceSlicePool = sync.Pool{
|
var _BioSequenceSlicePool = sync.Pool{
|
||||||
@ -13,32 +18,54 @@ var _BioSequenceSlicePool = sync.Pool{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// > This function returns a pointer to a new `BioSequenceSlice` object
|
||||||
func NewBioSequenceSlice() *BioSequenceSlice {
|
func NewBioSequenceSlice() *BioSequenceSlice {
|
||||||
return _BioSequenceSlicePool.Get().(*BioSequenceSlice)
|
return _BioSequenceSlicePool.Get().(*BioSequenceSlice)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// `MakeBioSequenceSlice()` returns a pointer to a new `BioSequenceSlice` struct
|
||||||
func MakeBioSequenceSlice() BioSequenceSlice {
|
func MakeBioSequenceSlice() BioSequenceSlice {
|
||||||
return *NewBioSequenceSlice()
|
return *NewBioSequenceSlice()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *BioSequenceSlice) Recycle() {
|
func (s *BioSequenceSlice) Recycle() {
|
||||||
// if s == nil {
|
if s == nil {
|
||||||
// log.Panicln("Trying too recycle a nil pointer")
|
log.Panicln("Trying too recycle a nil pointer")
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // Code added to potentially limit memory leaks
|
// Code added to potentially limit memory leaks
|
||||||
// for i := range *s {
|
for i := range *s {
|
||||||
// (*s)[i] = nil
|
(*s)[i] = nil
|
||||||
// }
|
}
|
||||||
|
|
||||||
// *s = (*s)[:0]
|
*s = (*s)[:0]
|
||||||
// _BioSequenceSlicePool.Put(s)
|
_BioSequenceSlicePool.Put(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Making sure that the slice has enough capacity to hold the number of elements that are being added
|
||||||
|
// to it.
|
||||||
|
func (s *BioSequenceSlice) InsureCapacity(capacity int) *BioSequenceSlice {
|
||||||
|
var c int
|
||||||
|
if s != nil {
|
||||||
|
c = cap(*s)
|
||||||
|
} else {
|
||||||
|
c = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if c < capacity {
|
||||||
|
sl := make(BioSequenceSlice, 0,capacity)
|
||||||
|
s = &sl
|
||||||
|
}
|
||||||
|
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Appending the sequence to the slice.
|
||||||
func (s *BioSequenceSlice) Push(sequence *BioSequence) {
|
func (s *BioSequenceSlice) Push(sequence *BioSequence) {
|
||||||
*s = append(*s, sequence)
|
*s = append(*s, sequence)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returning the last element of the slice and removing it from the slice.
|
||||||
func (s *BioSequenceSlice) Pop() *BioSequence {
|
func (s *BioSequenceSlice) Pop() *BioSequence {
|
||||||
_s := (*s)[len(*s)-1]
|
_s := (*s)[len(*s)-1]
|
||||||
(*s)[len(*s)-1] = nil
|
(*s)[len(*s)-1] = nil
|
||||||
@ -46,6 +73,7 @@ func (s *BioSequenceSlice) Pop() *BioSequence {
|
|||||||
return _s
|
return _s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returning the first element of the slice and removing it from the slice.
|
||||||
func (s *BioSequenceSlice) Pop0() *BioSequence {
|
func (s *BioSequenceSlice) Pop0() *BioSequence {
|
||||||
_s := (*s)[0]
|
_s := (*s)[0]
|
||||||
(*s)[0] = nil
|
(*s)[0] = nil
|
||||||
@ -53,6 +81,7 @@ func (s *BioSequenceSlice) Pop0() *BioSequence {
|
|||||||
return _s
|
return _s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test that a slice of sequences contains at least a sequence.
|
||||||
func (s BioSequenceSlice) NotEmpty() bool {
|
func (s BioSequenceSlice) NotEmpty() bool {
|
||||||
return len(s) > 0
|
return len(s) > 0
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user