forked from samuell/gccontent-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gc.go
53 lines (46 loc) · 865 Bytes
/
gc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"bufio"
"fmt"
"log"
"os"
)
func main() {
counters := [8][256]int64{}
// Open file
file, err := os.Open("chry_multiplied.fa")
if err != nil {
log.Fatal(err)
}
scan := bufio.NewScanner(file)
for scan.Scan() {
line := scan.Bytes()
if line[0] == '>' {
continue
}
for len(line) >= 8 {
counters[0][line[0]]++
counters[1][line[1]]++
counters[2][line[2]]++
counters[3][line[3]]++
counters[4][line[4]]++
counters[5][line[5]]++
counters[6][line[6]]++
counters[7][line[7]]++
line = line[8:]
}
for _, c := range line {
counters[0][c]++
}
}
total := [256]int64{}
for i := range counters {
for k, v := range counters[i] {
total[k] += v
}
}
gc := total['G'] + total['C']
at := total['A'] + total['T']
gcFraction := float32(gc) / float32(at+gc)
fmt.Println(gcFraction * 100)
}