Skip to content

Commit

Permalink
rosa: Optimize RevComp.
Browse files Browse the repository at this point in the history
  • Loading branch information
mewmew committed Jul 26, 2014
1 parent ccdacc4 commit ea3df8d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 2 additions & 0 deletions rosalind/cmd/cons/cons.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ func main() {
log.Fatalln(err)
}

// Create a profile of the provided DNA-sequences and use it to calculate the
// consensus sequence.
var seqs []string
for _, seq := range fas.Seqs {
seqs = append(seqs, seq)
Expand Down
3 changes: 3 additions & 0 deletions rosalind/cmd/cons/cons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var seqs = []string{
}

func ExampleNewProfile() {
// Create a profile of the provided DNA-sequences.
profile, err := NewProfile(seqs, true)
if err != nil {
log.Fatalln(err)
Expand All @@ -29,6 +30,8 @@ func ExampleNewProfile() {
}

func ExampleProfile_Cons() {
// Create a profile of the provided DNA-sequences and use it to calculate the
// consensus sequence.
profile, err := NewProfile(seqs, true)
if err != nil {
log.Fatalln(err)
Expand Down
18 changes: 8 additions & 10 deletions rosalind/rosa/rosa.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package rosa

import (
"bytes"
"fmt"
"strings"
)
Expand All @@ -13,35 +14,32 @@ func Trans(dna string) (rna string) {
return strings.Replace(dna, "T", "U", -1)
}

// TODO(u): The limited scope of revc should make it possible for future
// compiler optimizations to remove redundant string allocations in RevComp.
// Only the final string value will be accessed from other parts of the code.

// RevComp returns the reverse complement of the provided DNA sequence. The
// bases are complemented as follows:
// A: T
// C: G
// G: C
// T: A
func RevComp(dna string) (revc string) {
buf := new(bytes.Buffer)
for i := len(dna) - 1; i >= 0; i-- {
switch dna[i] {
case 'A':
revc += "T"
fmt.Fprint(buf, "T")
case 'C':
revc += "G"
fmt.Fprint(buf, "G")
case 'G':
revc += "C"
fmt.Fprint(buf, "C")
case 'T':
revc += "A"
fmt.Fprint(buf, "A")
}
}
return revc
return buf.String()
}

const (
// Stop indicates the stop of amino acid translation.
Stop = 0
Stop byte = 0
)

// aminos is a map from codons to amino acids.
Expand Down

0 comments on commit ea3df8d

Please sign in to comment.