2022-01-13 20:12:32 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"text/template"
|
|
|
|
)
|
|
|
|
|
2022-01-15 22:03:56 +08:00
|
|
|
const f string = `#NEXUS
|
|
|
|
BEGIN DATA;
|
|
|
|
DIMENSIONS NTAX={{ .Ntax }} NCHAR={{ .Nchar }};
|
|
|
|
FORMAT DATATYPE=DNA GAP=- MISSING=?;
|
|
|
|
MATRIX
|
|
|
|
{{- range $k, $v := .Matrix }}
|
|
|
|
'{{ $k }}' {{ $v }}
|
|
|
|
{{- end }}
|
|
|
|
;
|
|
|
|
END;
|
|
|
|
BEGIN SETS;
|
|
|
|
{{- range $_, $i := .Charset }}
|
|
|
|
CHARSET {{ $i.Name }} = {{ $i.From }}-{{ $i.To }};
|
|
|
|
{{- end }}
|
|
|
|
END;`
|
2022-01-13 20:12:32 +08:00
|
|
|
|
2022-01-15 22:03:56 +08:00
|
|
|
func do_impl(last_data tmpl_data) {
|
2022-01-13 20:12:32 +08:00
|
|
|
// 读取模板
|
2022-01-15 22:03:56 +08:00
|
|
|
// read the template
|
|
|
|
nex_tmpl, err := template.New("nex").Parse(f)
|
2022-01-13 20:12:32 +08:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println("[ tmpl err ]", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// 覆盖创建要写入的 nex 文件
|
2022-01-15 19:52:32 +08:00
|
|
|
// create the output nex file
|
2022-01-13 20:12:32 +08:00
|
|
|
new_file, err := os.OpenFile(file_output, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0666)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("[ create or open file error ]", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer new_file.Close()
|
|
|
|
|
|
|
|
// 写入 nex 模板
|
2022-01-15 19:52:32 +08:00
|
|
|
// write the nex data
|
2022-01-13 20:12:32 +08:00
|
|
|
err = nex_tmpl.Execute(new_file, last_data)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("[ err at tmpl exec ]", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|