Skip to content

Instantly share code, notes, and snippets.

@samuell
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samuell/c6a20869d954f0729070 to your computer and use it in GitHub Desktop.
Save samuell/c6a20869d954f0729070 to your computer and use it in GitHub Desktop.
Improved version of https://gist.github.com/samuell/5591369 , removing the pointer dereference, on tip from @dgryski : https://twitter.com/dgryski/status/471045782117056512
package main
import (
"bufio"
"fmt"
"log"
"os"
)
func main() {
var at, gc int
counters := [256]int{
'A': 0,
'T': 0,
'G': 0,
'C': 0,
}
file, err := os.Open("Homo_sapiens.GRCh37.67.dna_rm.chromosome.Y.fa")
if err != nil {
log.Fatal(err)
}
scan := bufio.NewScanner(file)
for scan.Scan() {
line := scan.Bytes()
if len(line) == 0 || line[0] == '>' {
continue
}
for _, c := range line {
counters[c]++
}
}
at = counters['A'] + counters['T']
gc = counters['G'] + counters['C']
gcFraction := float32(gc) / float32(at+gc)
fmt.Println(gcFraction * 100)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment