mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
99 lines
1.5 KiB
Go
99 lines
1.5 KiB
Go
package obiiter
|
|
|
|
import (
|
|
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obidefault"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func (b BioSequenceBatch) IsPaired() bool {
|
|
return b.slice.IsPaired()
|
|
}
|
|
|
|
func (b BioSequenceBatch) PairedWith() BioSequenceBatch {
|
|
return MakeBioSequenceBatch(
|
|
b.Source(),
|
|
b.order,
|
|
*b.slice.PairedWith(),
|
|
)
|
|
}
|
|
|
|
func (b *BioSequenceBatch) PairTo(p *BioSequenceBatch) {
|
|
|
|
if b.order != p.order {
|
|
log.Fatalf("both batches are not synchronized : (%d,%d)",
|
|
b.order, p.order,
|
|
)
|
|
}
|
|
|
|
b.slice.PairTo(&p.slice)
|
|
|
|
}
|
|
|
|
func (b *BioSequenceBatch) UnPair() {
|
|
b.slice.UnPair()
|
|
}
|
|
|
|
func (iter IBioSequence) MarkAsPaired() {
|
|
iter.pointer.paired = true
|
|
}
|
|
|
|
func (iter IBioSequence) PairTo(p IBioSequence) IBioSequence {
|
|
|
|
newIter := MakeIBioSequence()
|
|
|
|
iter = iter.SortBatches().Rebatch(obidefault.BatchSize())
|
|
p = p.SortBatches().Rebatch(obidefault.BatchSize())
|
|
|
|
newIter.Add(1)
|
|
|
|
go func() {
|
|
newIter.WaitAndClose()
|
|
}()
|
|
|
|
go func() {
|
|
|
|
for iter.Next() {
|
|
p.Next()
|
|
batch := iter.Get()
|
|
pbatch := p.Get()
|
|
batch.PairTo(&pbatch)
|
|
newIter.Push(batch)
|
|
}
|
|
|
|
newIter.Done()
|
|
}()
|
|
|
|
newIter.MarkAsPaired()
|
|
return newIter
|
|
|
|
}
|
|
|
|
func (iter IBioSequence) PairedWith() IBioSequence {
|
|
|
|
newIter := MakeIBioSequence()
|
|
|
|
newIter.Add(1)
|
|
|
|
go func() {
|
|
newIter.WaitAndClose()
|
|
}()
|
|
|
|
go func() {
|
|
|
|
for iter.Next() {
|
|
batch := iter.Get().PairedWith()
|
|
newIter.Push(batch)
|
|
}
|
|
|
|
newIter.Done()
|
|
}()
|
|
|
|
newIter.MarkAsPaired()
|
|
return newIter
|
|
|
|
}
|
|
|
|
func (iter IBioSequence) IsPaired() bool {
|
|
return iter.pointer.paired
|
|
}
|