Original: http://play.golang.org/p/dmh1FkGNO- See: http://saml.rilspace.org/moar-languagez-gc-content-in-python-d-fpc-c-and-c
package main | |
import ( | |
"bufio" | |
"fmt" | |
"log" | |
"os" | |
) | |
func main() { | |
countat := [256]int{ | |
'A': 1, | |
'T': 1, | |
} | |
countgc := [256]int{ | |
'G': 1, | |
'C': 1, | |
} | |
gc := 0 | |
at := 0 | |
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 { | |
gc += countgc[c] | |
at += countat[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