Created
May 16, 2013 12:26
-
-
Save samuell/5591369 to your computer and use it in GitHub Desktop.
Original: http://play.golang.org/p/UE9vxrztHO
See: http://saml.rilspace.org/moar-languagez-gc-content-in-python-d-fpc-c-and-c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"log" | |
"os" | |
) | |
func main() { | |
var at, gc, other int | |
counters := [256]*int{ | |
'A': &at, | |
'T': &at, | |
'G': &gc, | |
'C': &gc, | |
} | |
for i, counter := range counters { | |
if counter == nil { | |
counters[i] = &other | |
} | |
} | |
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])++ | |
} | |
} | |
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