mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
96 lines
1.3 KiB
Go
96 lines
1.3 KiB
Go
|
package obiiter
|
||
|
|
||
|
import (
|
||
|
"log"
|
||
|
)
|
||
|
|
||
|
func (b BioSequenceBatch) IsPaired() bool {
|
||
|
return b.slice.IsPaired()
|
||
|
}
|
||
|
|
||
|
func (b BioSequenceBatch) PairedWith() BioSequenceBatch {
|
||
|
return MakeBioSequenceBatch(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()
|
||
|
p = p.SortBatches()
|
||
|
|
||
|
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
|
||
|
}
|