-
Notifications
You must be signed in to change notification settings - Fork 8
/
sequence.go
62 lines (53 loc) · 1.08 KB
/
sequence.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package align
import (
"errors"
"math/rand"
)
type Sequence interface {
Sequence() string
SequenceChar() []rune
Name() string
Comment() string
Length() int
}
type seq struct {
name string // Name of the sequence
sequence []rune // Sequence of nucleotides/aa
comment string // Comment if any
}
func NewSequence(name string, sequence []rune, comment string) *seq {
return &seq{
name,
sequence,
comment,
}
}
func (s *seq) Sequence() string {
return string(s.sequence)
}
func (s *seq) SequenceChar() []rune {
return s.sequence
}
func (s *seq) Name() string {
return s.name
}
func (s *seq) Comment() string {
return s.comment
}
func (s *seq) Length() int {
return len(s.sequence)
}
func RandomSequence(alphabet, length int) ([]rune, error) {
seq := make([]rune, length)
for i := 0; i < length; i++ {
switch alphabet {
case AMINOACIDS:
seq[i] = stdaminoacid[rand.Intn(len(stdaminoacid))]
case NUCLEOTIDS:
seq[i] = stdnucleotides[rand.Intn(len(stdnucleotides))]
default:
return nil, errors.New("Unexpected sequence alphabet type")
}
}
return seq, nil
}