mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-12-08 16:50:27 +00:00
change the model for representing paired reads and extend its usage to other commands
This commit is contained in:
95
pkg/obiiter/paired.go
Normal file
95
pkg/obiiter/paired.go
Normal file
@@ -0,0 +1,95 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user