Created
March 30, 2014 05:48
-
-
Save mduvall/9868221 to your computer and use it in GitHub Desktop.
Quick example of using FASTA file to compute consensus strings
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 ( | |
"fasta" | |
"fmt" | |
) | |
func main() { | |
fastaFile := fasta.NewFastaFile("cons.txt") | |
var dnaLength int | |
for _, dna := range fastaFile.DnaSeqs { | |
dnaLength = len(dna.Sequence) | |
break | |
} | |
profileMatrix := map[byte][]float64{ | |
'A': make([]float64, dnaLength), | |
'T': make([]float64, dnaLength), | |
'C': make([]float64, dnaLength), | |
'G': make([]float64, dnaLength), | |
} | |
for _, dna := range fastaFile.DnaSeqs { | |
for index, nucleobase := range dna.Sequence { | |
profileMatrix[nucleobase][index] += 1.0 | |
} | |
} | |
fmt.Println("A: ", profileMatrix['A']) | |
fmt.Println("C: ", profileMatrix['C']) | |
fmt.Println("G: ", profileMatrix['G']) | |
fmt.Println("T: ", profileMatrix['T']) | |
consensusString := make([]byte, dnaLength) | |
var ( | |
dominantKeyAT byte | |
dominantKeyGC byte | |
dominantKey byte | |
) | |
for i, _ := range profileMatrix['A'] { | |
if profileMatrix['A'][i] > profileMatrix['T'][i] { | |
dominantKeyAT = 'A' | |
} else { | |
dominantKeyAT = 'T' | |
} | |
if profileMatrix['G'][i] > profileMatrix['C'][i] { | |
dominantKeyGC = 'G' | |
} else { | |
dominantKeyGC = 'C' | |
} | |
if profileMatrix[dominantKeyAT][i] > profileMatrix[dominantKeyGC][i] { | |
dominantKey = dominantKeyAT | |
} else { | |
dominantKey = dominantKeyGC | |
} | |
consensusString[i] = dominantKey | |
} | |
fmt.Println("Consensus string: ", string(consensusString)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment