Correct a bug in the fastq reader affecting the quality of the last record of each chunk

Former-commit-id: b842d60af9c2f1f971946d99999d13cfc15793b3
This commit is contained in:
Eric Coissac
2024-06-04 11:57:16 +02:00
parent 411124d1b3
commit aa42df326a
6 changed files with 104 additions and 42 deletions

View File

@ -273,19 +273,19 @@ func (s *BioSequence) Qualities() Quality {
// Returns a string representing the qualities of the BioSequence after applying the shift.
func (s *BioSequence) QualitiesString() string {
quality_shift := obioptions.OutputQualityShift()
qual := s.Qualities()
qual_ascii := make([]byte, len(qual))
qual_ascii := GetSlice(len(qual))[0:len(qual)]
for i := 0; i < len(qual); i++ {
quality := qual[i]
if quality < 0 {
quality = 0
}
if quality > 93 {
quality = 93
}
qual_ascii[i] = quality + quality_shift
}
return string(qual_ascii)
qual_sting := string(qual_ascii)
RecycleSlice(&qual_ascii)
return qual_sting
}
// Features returns the feature string of the BioSequence.
@ -420,7 +420,8 @@ func (s *BioSequence) SetSequence(sequence []byte) {
if s.sequence != nil {
RecycleSlice(&s.sequence)
}
s.sequence = obiutils.InPlaceToLower(sequence)
s.sequence = GetSlice(len(sequence))[0:len(sequence)]
copy(s.sequence, obiutils.InPlaceToLower(sequence))
}
// Setting the qualities of the BioSequence.
@ -428,7 +429,8 @@ func (s *BioSequence) SetQualities(qualities Quality) {
if s.qualities != nil {
RecycleSlice(&s.qualities)
}
s.qualities = qualities
s.qualities = GetSlice(len(qualities))[0:len(qualities)]
copy(s.qualities, qualities)
}
// A method that appends a byte slice to the qualities of the BioSequence.

View File

@ -15,6 +15,17 @@ var _BioSequenceByteSlicePool = sync.Pool{
},
}
// RecycleSlice recycles a byte slice by clearing its contents and returning it
// to a pool if it is small enough.
//
// Parameters: - s: a pointer to a byte slice that will be recycled.
//
// This function first checks if the input slice is not nil and has a non-zero
// capacity. If so, it clears the contents of the slice by setting its length to
// 0. Then, it checks if the capacity of the slice is less than or equal to
// 1024. If it is, the function puts the slice into a pool for reuse. If the
// capacity is 0 or greater than 1024, the function does nothing. If the input
// slice is nil or has a zero capacity, the function logs a panic message.
func RecycleSlice(s *[]byte) {
if s != nil && cap(*s) > 0 {
*s = (*s)[:0]
@ -27,9 +38,22 @@ func RecycleSlice(s *[]byte) {
}
}
// It returns a slice of bytes from a pool of slices.
// GetSlice returns a byte slice with the specified capacity.
//
// the slice can be prefilled with the provided values
// The function first checks if the capacity is less than or equal to 1024. If it is,
// it retrieves a byte slice from the _BioSequenceByteSlicePool. If the retrieved
// slice is nil, has a nil underlying array, or has a capacity less than the
// specified capacity, a new byte slice is created with the specified capacity.
// If the capacity is greater than 1024, a new byte slice is created with the
// specified capacity.
//
// The function returns the byte slice.
//
// Parameters:
// - capacity: the desired capacity of the byte slice.
//
// Return type:
// - []byte: the byte slice with the specified capacity.
func GetSlice(capacity int) []byte {
p := (*[]byte)(nil)
if capacity <= 1024 {