Skip to content

Commit

Permalink
feat: support reading sequences from stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Jan 11, 2019
1 parent d974cce commit 6b80d53
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions main.go
@@ -1,7 +1,9 @@
package main // import "moul.io/patfind"

import (
"bufio"
"fmt"
"log"
"math"
"os"
"strings"
Expand All @@ -14,8 +16,25 @@ import (
func main() {
data := [][]string{}

for _, arg := range os.Args[1:] {
sequence := score.New(arg)
sequences := []score.Sequence{}

if len(os.Args) < 2 { // stdin
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
if err := scanner.Err(); err != nil {
log.Printf("error: failed to read line from stdin: %v", err)
break
} else {
sequences = append(sequences, score.New(scanner.Text()))
}
}
} else {
for _, arg := range os.Args[1:] {
sequences = append(sequences, score.New(arg))
}
}

for _, sequence := range sequences {
score, comments := sequence.Score()
shift := math.Pow(10, float64(5))
roundedScore := math.Floor(score*shift+.5) / shift
Expand All @@ -26,7 +45,7 @@ func main() {
table.SetHeader([]string{"Sequence", "Score", "Comments"})
table.SetBorder(true)
table.SetRowLine(true)
table.SetColWidth(50)
table.SetColWidth(100)
table.AppendBulk(data)
table.Render()
}

0 comments on commit 6b80d53

Please sign in to comment.