已修复 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 {
|
type charset struct {
|
||||||
name string
|
Name string
|
||||||
from int
|
From int
|
||||||
to int
|
To int
|
||||||
}
|
}
|
||||||
|
|
||||||
type tmpl_data struct {
|
type tmpl_data struct {
|
||||||
ntax int
|
Ntax int
|
||||||
nchar int
|
Nchar int
|
||||||
matrix map[string]string
|
Matrix map[string]string
|
||||||
charset []charset
|
Charset []charset
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -34,7 +34,7 @@ func main() {
|
||||||
file_export := flag.String("o", "a.nex", "files name wait to out")
|
file_export := flag.String("o", "a.nex", "files name wait to out")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
file_names := flag.Args() // []string{"foo", "bar"}
|
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)
|
sum_nex := make([]dna, 0, 5)
|
||||||
|
@ -42,7 +42,7 @@ func main() {
|
||||||
i, j := fas_parser.Fas_parser(v)
|
i, j := fas_parser.Fas_parser(v)
|
||||||
new_nex := dna{v, i, j}
|
new_nex := dna{v, i, j}
|
||||||
sum_nex = append(sum_nex, new_nex)
|
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
|
n := v.name
|
||||||
f := 1
|
f := 1
|
||||||
if k != 0 {
|
if k != 0 {
|
||||||
f = sum_charset[k-1].to
|
f = sum_charset[k-1].To
|
||||||
}
|
}
|
||||||
t := f + v.count
|
t := f + v.count
|
||||||
new_charset := charset{n, f, t}
|
new_charset := charset{n, f, t}
|
||||||
|
@ -61,8 +61,8 @@ func main() {
|
||||||
|
|
||||||
// dna 的整合
|
// dna 的整合
|
||||||
seq := sum_nex[0].min_dna
|
seq := sum_nex[0].min_dna
|
||||||
ntax := 0
|
ntax := 0 // 待修补
|
||||||
nchar := sum_charset[len(sum_charset)-1].to
|
nchar := sum_charset[len(sum_charset)-1].To
|
||||||
for k, v := range sum_nex {
|
for k, v := range sum_nex {
|
||||||
if k == 0 {
|
if k == 0 {
|
||||||
continue
|
continue
|
||||||
|
@ -87,7 +87,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 覆盖创建要写入的 nex 文件
|
// 覆盖创建要写入的 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 {
|
if err != nil {
|
||||||
fmt.Println("[ create or open file error ]", err)
|
fmt.Println("[ create or open file error ]", err)
|
||||||
return
|
return
|
||||||
|
@ -95,7 +95,8 @@ func main() {
|
||||||
defer new_file.Close()
|
defer new_file.Close()
|
||||||
|
|
||||||
// 写入 nex 模板
|
// 写入 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)
|
fmt.Println("[ err at tmpl exec ]", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,14 +2,15 @@ package fas_parser
|
||||||
|
|
||||||
const Nex_tmpl = `#NEXUS
|
const Nex_tmpl = `#NEXUS
|
||||||
BEGIN DATA;
|
BEGIN DATA;
|
||||||
DIMENSIONS NTAX={{ .ntax }} NCHAR={{ .nchar }};
|
DIMENSIONS NTAX={{ .Ntax }} NCHAR={{ .Nchar }};
|
||||||
FORMAT DATATYPE=DNA GAP=- MISSING=? ; #DATATYPE={}`
|
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 }}
|
// 最后那个 $i 好像有问题
|
||||||
// '{{ $k }}' {{ $v }}{{ end }}
|
|
||||||
// ;
|
|
||||||
// END;`
|
|
||||||
// BEGIN SETS;{{ range $_, $i := .charset }}
|
|
||||||
// CHARSET {{ .name }} = {{ .from }}-{{ .to }};{{ end }}
|
|
||||||
// END;
|
|
||||||
// `
|
|
||||||
|
|
Loading…
Reference in a new issue