Create a gist now

Instantly share code, notes, and snippets.

package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func main() {
var countat[256] int;
var countgc[256] int;
countat['A'] = 1;
countat['T'] = 1;
countgc['G'] = 1;
countgc['C'] = 1;
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 c byte
for i := 0; i < len(line); i++ {
c = line[i]
gc += countgc[c];
at += countat[c];
}
}
}
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