已修复 tmpl
This commit is contained in:
parent
cf7dfccc77
commit
20c23128ee
2 changed files with 26 additions and 24 deletions
29
parser.go
29
parser.go
|
@ -16,16 +16,16 @@ type dna struct {
|
|||
}
|
||||
|
||||
type charset struct {
|
||||
name string
|
||||
from int
|
||||
to int
|
||||
Name string
|
||||
From int
|
||||
To int
|
||||
}
|
||||
|
||||
type tmpl_data struct {
|
||||
ntax int
|
||||
nchar int
|
||||
matrix map[string]string
|
||||
charset []charset
|
||||
Ntax int
|
||||
Nchar int
|
||||
Matrix map[string]string
|
||||
Charset []charset
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -34,7 +34,7 @@ func main() {
|
|||
file_export := flag.String("o", "a.nex", "files name wait to out")
|
||||
flag.Parse()
|
||||
file_names := flag.Args() // []string{"foo", "bar"}
|
||||
fmt.Println("export here", *file_export)
|
||||
fmt.Println("[ export here ]", *file_export)
|
||||
|
||||
// 遍历文件
|
||||
sum_nex := make([]dna, 0, 5)
|
||||
|
@ -42,7 +42,7 @@ func main() {
|
|||
i, j := fas_parser.Fas_parser(v)
|
||||
new_nex := dna{v, i, j}
|
||||
sum_nex = append(sum_nex, new_nex)
|
||||
fmt.Println("working", k+1, v)
|
||||
fmt.Println("[ working ]", k+1, v)
|
||||
}
|
||||
|
||||
// 整合若干文件的统计
|
||||
|
@ -51,7 +51,7 @@ func main() {
|
|||
n := v.name
|
||||
f := 1
|
||||
if k != 0 {
|
||||
f = sum_charset[k-1].to
|
||||
f = sum_charset[k-1].To
|
||||
}
|
||||
t := f + v.count
|
||||
new_charset := charset{n, f, t}
|
||||
|
@ -61,8 +61,8 @@ func main() {
|
|||
|
||||
// dna 的整合
|
||||
seq := sum_nex[0].min_dna
|
||||
ntax := 0
|
||||
nchar := sum_charset[len(sum_charset)-1].to
|
||||
ntax := 0 // 待修补
|
||||
nchar := sum_charset[len(sum_charset)-1].To
|
||||
for k, v := range sum_nex {
|
||||
if k == 0 {
|
||||
continue
|
||||
|
@ -87,7 +87,7 @@ func main() {
|
|||
}
|
||||
|
||||
// 覆盖创建要写入的 nex 文件
|
||||
new_file, err := os.OpenFile(*file_export, os.O_CREATE|os.O_RDWR, 0666)
|
||||
new_file, err := os.OpenFile(*file_export, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0666)
|
||||
if err != nil {
|
||||
fmt.Println("[ create or open file error ]", err)
|
||||
return
|
||||
|
@ -95,7 +95,8 @@ func main() {
|
|||
defer new_file.Close()
|
||||
|
||||
// 写入 nex 模板
|
||||
if nex_tmpl.Execute(new_file, last_data) != nil {
|
||||
err = nex_tmpl.Execute(new_file, last_data)
|
||||
if err!= nil {
|
||||
fmt.Println("[ err at tmpl exec ]", err)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -2,14 +2,15 @@ package fas_parser
|
|||
|
||||
const Nex_tmpl = `#NEXUS
|
||||
BEGIN DATA;
|
||||
DIMENSIONS NTAX={{ .ntax }} NCHAR={{ .nchar }};
|
||||
FORMAT DATATYPE=DNA GAP=- MISSING=? ; #DATATYPE={}`
|
||||
DIMENSIONS NTAX={{ .Ntax }} NCHAR={{ .Nchar }};
|
||||
FORMAT DATATYPE=DNA GAP=- MISSING=? ; #DATATYPE={}
|
||||
MATRIX{{ range $k, $v := .Matrix }}
|
||||
'{{ $k }}' {{ $v }}{{ end }}
|
||||
;
|
||||
END;
|
||||
BEGIN SETS;{{ range $_, $i := .Charset }}
|
||||
CHARSET {{ .Name }} = {{ .From }}-{{ .To }};{{ end }}
|
||||
END;
|
||||
`
|
||||
|
||||
// MATRIX{{ range $k, $v := .matrix }}
|
||||
// '{{ $k }}' {{ $v }}{{ end }}
|
||||
// ;
|
||||
// END;`
|
||||
// BEGIN SETS;{{ range $_, $i := .charset }}
|
||||
// CHARSET {{ .name }} = {{ .from }}-{{ .to }};{{ end }}
|
||||
// END;
|
||||
// `
|
||||
// 最后那个 $i 好像有问题
|
||||
|
|
Loading…
Reference in a new issue