Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// --------------------------------------------------------------------
// Dummy processing DNA code (by taking base complement)
// Sequential version
// Author: Samuel Lampa, samuel.lampa@gmail.com
// Date: 2013-06-21
// --------------------------------------------------------------------
package main
import (
"fmt"
"bufio"
"os"
"log"
)
func main() {
// Read file with DNA of Human Chromosome Y
file, err := os.Open("Homo_sapiens.GRCh37.67.dna_rm.chromosome.Y.fa")
if err != nil {
log.Fatal(err)
} else {
scan := bufio.NewScanner(file)
for scan.Scan() {
line := scan.Bytes()
// Set up a pipeline of sequential "dummy processing"
// (Taking the base complement back and forth a few
// times).
lineNew1 := complement(line)
lineNew2 := complement(lineNew1)
lineNew3 := complement(lineNew2)
lineNew4 := complement(lineNew3)
fmt.Println(string(lineNew4))
}
}
}
func complement(line []byte) []byte {
// Ugly and naive code to compute the DNA base complement
for pos := range line {
if line[pos] == 'A' {
line[pos] = 'T'
} else if line[pos] == 'T' {
line[pos] = 'A'
} else if line[pos] == 'C' {
line[pos] = 'G'
} else if line[pos] == 'G' {
line[pos] = 'C'
}
}
return line
}
@samuell

This comment has been minimized.

Copy link
Owner Author

commented Jun 21, 2013

[samuel gotest]$ go build -o basecompl basecompl.go 
[samuel gotest]$ for i in $(seq 1 1 3); do echo "---"; time ./basecompl > out.tmp; done;

---

real    0m5.845s
user    0m4.088s
sys 0m1.824s

---

real    0m5.919s
user    0m3.920s
sys 0m1.880s

---

real    0m5.763s
user    0m4.068s
sys 0m1.748s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.