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
// -------------------------------------------------------------------- | |
// 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 | |
} |
Author
samuell
commented
Jun 21, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment