Skip to content

Instantly share code, notes, and snippets.

@samuell
Last active July 4, 2018 12:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save samuell/5590005 to your computer and use it in GitHub Desktop.
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