Created
October 24, 2014 18:03
-
-
Save briandowns/11b40213f5f4f9c46eb2 to your computer and use it in GitHub Desktop.
RNA_Transcription
This file contains hidden or 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 ( | |
"log" | |
"bytes" | |
"errors" | |
) | |
var compliment = map[string]string{"G": "C", "C": "G", "T": "A", "A": "U"} | |
func transcribe(dna string) (string, error) { | |
var buffer bytes.Buffer | |
for _, n := range dna { | |
if val, ok := compliment[string(n)]; ok { | |
buffer.WriteString(val) | |
} else { | |
return "", errors.New("Error: Unrecognized nucleotide") | |
} | |
} | |
return buffer.String(), nil | |
} | |
func main() { | |
result, err := transcribe("GAGCCTACTAACGGGAT") | |
if err != nil { | |
log.Fatalln(err) | |
} | |
log.Println(result) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment