Files
obitools4/pkg/obiiter/speed.go

60 lines
1.0 KiB
Go
Raw Normal View History

package obiiter
2022-02-18 22:53:09 +01:00
import (
"os"
"github.com/schollz/progressbar/v3"
)
2022-02-24 12:14:52 +01:00
func (iterator IBioSequenceBatch) Speed(message ...string) IBioSequenceBatch {
2022-02-18 22:53:09 +01:00
newIter := MakeIBioSequenceBatch()
newIter.Add(1)
go func() {
newIter.WaitAndClose()
}()
2022-02-24 12:14:52 +01:00
pbopt := make([]progressbar.Option, 0, 5)
pbopt = append(pbopt,
progressbar.OptionSetWriter(os.Stderr),
progressbar.OptionSetWidth(15),
progressbar.OptionShowCount(),
progressbar.OptionShowIts(),
2022-02-24 12:14:52 +01:00
)
if len(message) > 0 {
pbopt = append(pbopt,
progressbar.OptionSetDescription(message[0]),
)
} else {
pbopt = append(pbopt,
progressbar.OptionSetDescription("[Sequence Processing]"),
)
}
bar := progressbar.NewOptions(-1, pbopt...)
go func() {
for iterator.Next() {
batch := iterator.Get()
l := batch.Len()
newIter.Push(batch)
bar.Add(l)
}
newIter.Done()
}()
2022-02-18 22:53:09 +01:00
return newIter
}
2022-10-27 11:18:44 +02:00
func SpeedPipe(message ...string) Pipeable {
f := func(iterator IBioSequenceBatch) IBioSequenceBatch {
2022-10-27 11:18:44 +02:00
return iterator.Speed(message...)
}
return f
2022-02-24 12:14:52 +01:00
}