Patch a bug in obimultiplex loosing sequence with primer dimer

Former-commit-id: ea14e1aa2e4670c19fe8ee7ec61565bd21cc25b0
This commit is contained in:
Eric Coissac
2024-06-30 17:42:28 +02:00
parent 154753de90
commit 0187a82c5f
2 changed files with 33 additions and 22 deletions

View File

@ -686,28 +686,27 @@ func (library *NGSLibrary) ExtractMultiBarcode(sequence *obiseq.BioSequence) (ob
barcode, err := sequence.Subsequence(from.End, match.Begin, false)
if err != nil {
return nil, fmt.Errorf("%s [%s] : Cannot extract barcode %d : %v", sequence.Id(), sequence.Source(), q, err)
if err == nil {
annotations["obimultiplex_direction"] = map[bool]string{true: "forward", false: "reverse"}[from.Forward]
if !match.Forward {
barcode = barcode.ReverseComplement(true)
}
if tags != nil {
library.SampleIdentifier(primerseqs[from.Marker], tags, annotations)
}
barcode.AnnotationsLock()
obiutils.MustFillMap(barcode.Annotations(), annotations)
barcode.AnnotationsUnlock()
if barcode.Len() > 0 {
results = append(results, barcode)
q++
}
}
annotations["obimultiplex_direction"] = map[bool]string{true: "forward", false: "reverse"}[from.Forward]
if !match.Forward {
barcode = barcode.ReverseComplement(true)
}
if tags != nil {
library.SampleIdentifier(primerseqs[from.Marker], tags, annotations)
}
barcode.AnnotationsLock()
obiutils.MustFillMap(barcode.Annotations(), annotations)
barcode.AnnotationsUnlock()
if barcode.Len() > 0 {
results = append(results, barcode)
q++
}
}
state = 0
@ -731,6 +730,10 @@ func (library *NGSLibrary) ExtractMultiBarcode(sequence *obiseq.BioSequence) (ob
}
}
if len(results) == 0 {
log.Fatalf("ExtractMultiBarcode: No barcode found in sequence %s", sequence.Id())
}
return results, nil
}
@ -748,7 +751,15 @@ func (library *NGSLibrary) ExtractMultiBarcodeSliceWorker(options ...WithOption)
library.Compile2()
worker := func(sequence *obiseq.BioSequence) (obiseq.BioSequenceSlice, error) {
return library.ExtractMultiBarcode(sequence)
res, err := library.ExtractMultiBarcode(sequence)
if err != nil {
log.Panic(err)
}
if res.Len() == 0 {
log.Panicf("No barcode found in sequence %s", sequence.Id())
}
return res, err
}
return obiseq.SeqToSliceWorker(worker, true)

View File

@ -7,7 +7,7 @@ import (
// TODO: The version number is extracted from git. This induces that the version
// corresponds to the last commit, and not the one when the file will be
// commited
var _Commit = "d208ff8"
var _Commit = "86d208f"
var _Version = "Release 4.2.0"
// Version returns the version of the obitools package.