Skip to content

Instantly share code, notes, and snippets.

@samuell
Created May 16, 2013 07:29
Show Gist options
  • Save samuell/5590019 to your computer and use it in GitHub Desktop.
Save samuell/5590019 to your computer and use it in GitHub Desktop.
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