-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgffreader.go
More file actions
93 lines (76 loc) · 2.31 KB
/
gffreader.go
File metadata and controls
93 lines (76 loc) · 2.31 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"bufio"
"os"
"strings"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
func main() {
app := tview.NewApplication()
table := tview.NewTable().SetFixed(1, 1)
filePath := os.Args[1]
file, _ := os.Open(filePath)
defer file.Close()
scanner := bufio.NewScanner(file)
row := 0
headers := []string{"seqname", "source", "feature", "start", "end", "score", "strand", "frame", "attribute"}
for index, header := range headers {
table.SetCell(0, index, tview.NewTableCell(header).SetAlign(tview.AlignCenter).SetTextColor(tcell.ColorRed))
}
row++
lines := []string{}
for scanner.Scan() {
line := scanner.Text()
if strings.HasPrefix(line, "#") || strings.HasPrefix(line, "##") {
continue
}
lines = append(lines, line)
fields := strings.Split(line, "\t")
// Determine color
var color tcell.Color
if len(fields) > 2 && fields[2] == "CDS" {
color = tcell.ColorBlue
} else {
color = tcell.ColorWhite
}
// Apply color
for col, field := range fields {
table.SetCell(row, col, tview.NewTableCell(field).SetTextColor(color))
}
row++
}
// search
searchModal := tview.NewInputField().SetLabel("Search: ")
searchModal.SetDoneFunc(func(key tcell.Key) {
if key == tcell.KeyEnter {
searchTerm := searchModal.GetText()
// clear the table
for i := 1; i < row; i++ {
for j := 0; j < len(headers); j++ {
table.GetCell(i, j).SetText("")
}
}
// refill the table with the search result
row = 1
for _, line := range lines {
if strings.Contains(line, searchTerm) {
fields := strings.Split(line, "\t")
for col, field := range fields {
table.SetCell(row, col, tview.NewTableCell(field))
}
row++
}
}
app.SetRoot(table, true)
}
})
app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if event.Key() == tcell.KeyCtrlF {
// show search modal
app.SetRoot(searchModal, true)
}
return event
})
app.SetRoot(table, true).Run()
}