/
main.go
132 lines (119 loc) · 2.86 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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package main
import (
"flag"
"fmt"
"github.com/liserjrqlxue/goUtil/osUtil"
"github.com/liserjrqlxue/goUtil/simpleUtil"
"github.com/tealeg/xlsx/v2"
"os"
"path/filepath"
"strings"
"github.com/liserjrqlxue/anno2xlsx/v2/anno"
"github.com/liserjrqlxue/goUtil/textUtil"
"github.com/liserjrqlxue/simple-util"
"github.com/pelletier/go-toml"
)
// os
var (
ex, _ = os.Executable()
exPath = filepath.Dir(ex)
etcPath = filepath.Join(exPath, "..", "..", "etc")
)
var (
input = flag.String(
"xlsx",
"",
"input xlsx",
)
prefix = flag.String(
"prefix",
"",
"output to prefix.result.tsv, default is -xlsx",
)
sheetName = flag.String(
"sheetName",
"filter_variants",
"sheetName of input",
)
cfg = flag.String(
"cfg",
filepath.Join(etcPath, "config.toml"),
"default config file, config will be overwrite by flag",
)
trio = flag.Bool(
"trio",
false,
"if trio",
)
top = flag.Int(
"top",
20,
"output only top -top item (exclude acmgSFGene)",
)
)
// TomlTree Global toml config
var TomlTree *toml.Tree
var acmgSFGene = make(map[string]bool)
var resultColumn []string
func main() {
flag.Parse()
if *input == "" {
flag.Usage()
os.Exit(1)
}
if *prefix == "" {
*prefix = *input
}
TomlTree = simpleUtil.HandleError(toml.LoadFile(*cfg)).(*toml.Tree)
for _, gene := range textUtil.File2Array(anno.GuessPath(TomlTree.Get("acmg.SF").(string), etcPath)) {
acmgSFGene[gene] = true
}
resultColumn = TomlTree.GetArray("wesim.resultColumn").([]string)
if *trio {
resultColumn = append(resultColumn, "Genotype of Family Member 1", "Genotype of Family Member 2")
}
var xlF, err = xlsx.OpenFile(*input)
simple_util.CheckErr(err)
var resultFile = osUtil.Create(*prefix + ".result.tsv")
defer simple_util.DeferClose(resultFile)
simpleUtil.HandleError(fmt.Fprintln(resultFile, strings.Join(resultColumn, "\t")))
var title []string
var count = 0
for i, row := range xlF.Sheet[*sheetName].Rows {
if i == 0 {
for _, cell := range row.Cells {
title = append(title, cell.Value)
}
} else {
var item = make(map[string]string)
for j, cell := range row.Cells {
if j < len(title) && title != nil {
item[title[j]] = cell.Value
}
}
item["IsACMG59"] = "N"
if acmgSFGene[item["Gene Symbol"]] {
item["IsACMG59"] = "Y"
} else {
item["IsACMG59"] = "N"
count++
}
if item["IsACMG59"] == "N" && count > *top {
continue
}
if *trio {
zygosity := strings.Split(item["Zygosity"], ";")
zygosity = append(zygosity, "NA", "NA")
item["Zygosity"] = zygosity[0]
item["Genotype of Family Member 1"] = zygosity[1]
item["Genotype of Family Member 2"] = zygosity[2]
}
var resultArray []string
for _, key := range resultColumn {
resultArray = append(resultArray, item[key])
}
_, err = fmt.Fprintln(resultFile, strings.Join(resultArray, "\t"))
simple_util.CheckErr(err)
}
}
}