尝试输出到nex
This commit is contained in:
parent
9f1bd76e27
commit
fdd99fbb04
3 changed files with 55 additions and 9 deletions
3
go.mod
Normal file
3
go.mod
Normal file
|
@ -0,0 +1,3 @@
|
|||
module gocomb
|
||||
|
||||
go 1.17
|
46
parser.go
46
parser.go
|
@ -3,27 +3,54 @@ package main
|
|||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"gocomb/src"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
type Person struct {
|
||||
Name string
|
||||
DNA string
|
||||
}
|
||||
|
||||
func main() {
|
||||
file_flag := flag.String("o", "a.ast", "files name wait to out")
|
||||
|
||||
file_flag := flag.String("o", "a.nex", "files name wait to out")
|
||||
// 这里一定要是指针样子
|
||||
flag.Parse()
|
||||
file_names := flag.Args() // []string{"foo", "bar"}
|
||||
// file_out := ""
|
||||
fmt.Println("输出在这里", *file_flag)
|
||||
|
||||
nex_tmpl, err := template.New("nex").Parse(nex_tmpl.Nex_tmpl)
|
||||
if err != nil {
|
||||
panic("tmpl err")
|
||||
}
|
||||
|
||||
new_file, err := os.OpenFile("a.nex", os.O_CREATE|os.O_RDWR, 0666)
|
||||
if err != nil {
|
||||
fmt.Println("open file error :", err)
|
||||
return
|
||||
}
|
||||
defer new_file.Close()
|
||||
|
||||
|
||||
for _, v := range file_names {
|
||||
// fmt.Println(k, v)
|
||||
read(v)
|
||||
new_nex := read(v)
|
||||
err := nex_tmpl.Execute(new_file, new_nex)
|
||||
if err != nil {
|
||||
fmt.Println("err at tmpl exec", err)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func read(file_name string) {
|
||||
func read(file_name string) map[string]string {
|
||||
f, err := ioutil.ReadFile("./" + file_name)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
return nil
|
||||
}
|
||||
// fmt.Println(f)
|
||||
|
||||
|
@ -55,8 +82,9 @@ func read(file_name string) {
|
|||
}
|
||||
}
|
||||
}
|
||||
for k1, v1 := range seq {
|
||||
fmt.Println(k1)
|
||||
fmt.Println(v1)
|
||||
}
|
||||
// for k1, v1 := range seq {
|
||||
// fmt.Println(k1)
|
||||
// fmt.Println(v1)
|
||||
// }
|
||||
return seq
|
||||
}
|
||||
|
|
15
src/nex_tmpl.go
Normal file
15
src/nex_tmpl.go
Normal file
|
@ -0,0 +1,15 @@
|
|||
package nex_tmpl
|
||||
|
||||
const Nex_tmpl = `#NEXUS
|
||||
BEGIN DATA;
|
||||
DIMENSIONS NTAX={} NCHAR={};
|
||||
FORMAT DATATYPE=DNA GAP=- MISSING=? ; #DATATYPE={}
|
||||
MATRIX{{ range $k, $v := . }}
|
||||
'{{ $k }}' {{ $v }}{{ end }}
|
||||
;
|
||||
END;
|
||||
BEGIN SETS;
|
||||
CHARSET 16S = 1-811;
|
||||
CHARSET CO1 = 812-1421;
|
||||
END;
|
||||
`
|
Loading…
Reference in a new issue