/
main.go
51 lines (43 loc) · 1.11 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main // import "moul.io/patfind"
import (
"bufio"
"fmt"
"log"
"math"
"os"
"strings"
"github.com/olekukonko/tablewriter"
"moul.io/patfind/score"
)
func main() {
data := [][]string{}
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
data = append(data, []string{sequence.String(), fmt.Sprintf("%v", roundedScore), strings.Join(comments, ";\n")})
}
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Sequence", "Score", "Comments"})
table.SetBorder(true)
table.SetRowLine(true)
table.SetColWidth(100)
table.AppendBulk(data)
table.Render()
}