Create a gist now

Instantly share code, notes, and snippets.

@samuell /gc.go
Created May 16, 2013

What would you like to do?
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func main() {
var gc int = 0
var at int = 0
var line string
var err error
file, err := os.Open("Homo_sapiens.GRCh37.67.dna_rm.chromosome.Y.fa")
var fileReader *bufio.Reader = bufio.NewReader(file)
for err == nil {
line, err = fileReader.ReadString('\n')
if !strings.HasPrefix(line, ">") {
var curChar byte
for i := 0; i < len(line); i++ {
curChar = line[i]
if curChar == 'G' || curChar == 'C' {
gc++
} else if curChar == 'T' || curChar == 'A' {
at++
}
}
}
}
var gcFraction float32 = 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