Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package main
import (
"bufio"
"fmt"
"log"
"os"
)
const (
G = rune('G')
C = rune('C')
A = rune('A')
T = rune('T')
)
type Pair struct {
gc int
at int
}
func main() {
file, err := os.Open("./Homo_sapiens.GRCh37.67.dna_rm.chromosome.Y.fa")
if err != nil {
log.Fatal(err)
}
gc_frac := countFile(false, file)
fmt.Printf("GC count: %v\n", gc_frac)
}
func countFile(async bool, file *os.File) float64 {
at := 0
gc := 0
scanner := bufio.NewScanner(file)
for scanner.Scan() {
tmpAt, tmpGc := count(scanner.Text())
at += tmpAt
gc += tmpGc
}
return float64(gc) / float64((gc + at))
}
func count(line string) (int, int) {
at := 0
gc := 0
for _, c := range line {
if c == G || c == C {
gc++
}
if c == A || c == T {
at++
}
}
return at, gc
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.