From 18307f0aec1030fc978efaa9f150b1a238e850a2 Mon Sep 17 00:00:00 2001 From: qaqland <62464571+qaqland@users.noreply.github.com> Date: Sat, 1 Jan 2022 16:21:41 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E4=BB=A3parser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/parser.go | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 data/parser.go diff --git a/data/parser.go b/data/parser.go new file mode 100644 index 0000000..188aac7 --- /dev/null +++ b/data/parser.go @@ -0,0 +1,62 @@ +package main + +import ( + "flag" + "fmt" + "io/ioutil" +) + +func main() { + file_flag := flag.String("o", "a.ast", "files name wait to out") + // 这里一定要是指针样子 + flag.Parse() + file_names := flag.Args() // []string{"foo", "bar"} + // file_out := "" + fmt.Println("输出在这里", *file_flag) + for _, v := range file_names { + // fmt.Println(k, v) + read(v) + } +} + +func read(file_name string) { + f, err := ioutil.ReadFile("./" + file_name) + if err != nil { + fmt.Println(err) + return + } + // fmt.Println(f) + + i := 0 // DNA行计数 + j := 0 // 非序列行计数 + seq := make(map[string]string) + section := "" + // fmt.Println('a', 'c', 'g', 't', '-', '\n', '\r') + for k, v := range f { + switch v { + case 'a', 'c', 'g', 't', '-': + if j != 0 { + continue + } + if i == 0 { + i = k + } + case '\n': + if i != 0 { + seq[section] = seq[section] + string(f[i:k]) + i = 0 + continue + } + section = string(f[j:k]) + j = 0 + default: + if j == 0 { + j = k + 1 + } + } + } + for k1, v1 := range seq { + fmt.Println(k1) + fmt.Println(v1) + } +}