-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSSEQ.go
52 lines (46 loc) · 885 Bytes
/
SSEQ.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
package main
import (
"bytes"
"fmt"
"io/ioutil"
"strings"
)
func main() {
fasta := readFile(`data\rosalind_sseq.txt`)
dna := getDna(fasta)
ind := subseq(dna[0], dna[1])
printsl(ind)
}
func subseq(dna string, key string) []int {
ind := []int{0}
for i, c := range key {
pos := strings.Index(dna, string(c))
if pos == -1 {
return nil
} else {
pos++
dna = dna[pos:]
ind = append(ind, ind[i]+pos)
continue
}
}
return ind[1:]
}
func printsl(slice []int) {
println(strings.Trim(fmt.Sprintf("%v", slice), "[]"))
}
func getDna(data []string) []string {
var buf bytes.Buffer
for _, line := range data {
if line == "" || line[0] == '>' {
buf.WriteString("\n")
} else {
buf.WriteString(line)
}
}
return strings.Fields(buf.String())
}
func readFile(file string) []string {
b, _ := ioutil.ReadFile(file)
return strings.Fields(string(b))
}