2022-02-24 07:08:40 +01:00
|
|
|
package obiiter
|
2022-02-18 22:53:09 +01:00
|
|
|
|
2022-02-21 19:00:23 +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()
|
2022-02-21 19:00:23 +01:00
|
|
|
|
|
|
|
newIter.Add(1)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
newIter.WaitAndClose()
|
|
|
|
}()
|
|
|
|
|
2022-02-24 12:14:52 +01:00
|
|
|
pbopt := make([]progressbar.Option, 0, 5)
|
|
|
|
pbopt = append(pbopt,
|
2022-02-21 19:00:23 +01:00
|
|
|
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...)
|
2022-02-21 19:00:23 +01:00
|
|
|
|
|
|
|
go func() {
|
|
|
|
|
|
|
|
for iterator.Next() {
|
|
|
|
batch := iterator.Get()
|
|
|
|
l := batch.Length()
|
|
|
|
newIter.Push(batch)
|
|
|
|
bar.Add(l)
|
|
|
|
}
|
|
|
|
|
|
|
|
newIter.Done()
|
|
|
|
}()
|
|
|
|
|
2022-02-18 22:53:09 +01:00
|
|
|
return newIter
|
|
|
|
}
|
2022-02-24 07:08:40 +01:00
|
|
|
|
|
|
|
func SpeedPipe() Pipeable {
|
|
|
|
f := func(iterator IBioSequenceBatch) IBioSequenceBatch {
|
|
|
|
return iterator.Speed()
|
|
|
|
}
|
|
|
|
|
|
|
|
return f
|
2022-02-24 12:14:52 +01:00
|
|
|
}
|