SeqCombGo/count.go

52 lines
1.0 KiB
Go
Raw Permalink Normal View History

2022-01-13 20:12:32 +08:00
package main
2022-01-15 17:01:37 +08:00
import (
"fmt"
2022-01-15 18:41:32 +08:00
"regexp"
2022-01-15 17:01:37 +08:00
)
2022-01-13 20:12:32 +08:00
type charset struct {
Name string
From int
To int
}
// 遍历文件得到基本数据
2022-01-15 19:49:39 +08:00
// get basic data
2022-01-13 20:12:32 +08:00
func fas_sum() []dna {
sum := []dna{}
for i, f := range file_input {
2022-01-18 21:57:52 +08:00
sum = append(sum, fas_parser(f)) // sum files
2022-01-15 19:21:40 +08:00
fmt.Println("[ Reading ]", i+1, f)
2022-01-13 20:12:32 +08:00
}
return sum
}
// 整合若干文件的统计
2022-01-15 19:49:39 +08:00
// combine the data from different files
2022-01-14 17:20:42 +08:00
func fas_count(sum_nex []dna) []charset {
2022-01-13 20:12:32 +08:00
fas_charset := []charset{}
for k, v := range sum_nex {
2022-01-15 17:01:37 +08:00
n := fas_name(v.name)
2022-01-13 20:12:32 +08:00
f := 1
if k != 0 {
f = fas_charset[k-1].To + 1
}
t := f + v.count - 1
2022-01-15 19:21:40 +08:00
fmt.Println("[ Combining ]", n, f, t)
2022-01-13 20:12:32 +08:00
new_charset := charset{n, f, t}
fas_charset = append(fas_charset, new_charset)
}
2022-01-14 17:20:42 +08:00
fmt.Println(fas_charset)
2022-01-13 20:12:32 +08:00
return fas_charset
}
2022-01-15 17:01:37 +08:00
func fas_name(old_name string) string {
2022-01-15 18:35:44 +08:00
//needed to import string
2022-01-15 18:56:29 +08:00
compileRegex := regexp.MustCompile(`(\w+)\.\w+`)
2022-01-15 18:37:57 +08:00
matchArr := compileRegex.FindStringSubmatch(old_name)
2022-01-15 18:35:44 +08:00
//needed to use the string get from the old string
2022-01-15 18:48:01 +08:00
new_name := matchArr[len(matchArr)-1]
return new_name
2022-01-15 17:01:37 +08:00
}