Skip to content

Instantly share code, notes, and snippets.

@mys721tx
Created August 24, 2018 17:07
Show Gist options
  • Save mys721tx/6274d853298d70100502f3135e1e9c18 to your computer and use it in GitHub Desktop.
Save mys721tx/6274d853298d70100502f3135e1e9c18 to your computer and use it in GitHub Desktop.
Test Sequence Generator
package main
import (
"bufio"
"math/rand"
"os"
"github.com/biogo/biogo/alphabet"
"github.com/biogo/biogo/io/seqio/fasta"
"github.com/biogo/biogo/seq/linear"
)
const alpbh = "ACGT"
func RandStringBytes(n int) string {
b := make([]byte, n)
for i := range b {
b[i] = alpbh[rand.Intn(len(alpbh))]
}
return string(b)
}
func main() {
seq := RandStringBytes(200)
c := linear.NewSeq(
"foo;size=100",
[]alphabet.Letter(seq),
alphabet.DNA,
)
f, _ := os.Create("test-identical.fasta")
b := bufio.NewWriter(f)
w := fasta.NewWriter(b, 80)
for i := 0; i < 2000000; i++ {
w.Write(c)
}
}
package main
import (
"bufio"
"os"
"github.com/biogo/biogo/alphabet"
"github.com/biogo/biogo/io/seqio/fasta"
"github.com/biogo/biogo/seq/linear"
)
const alpbh = "ACGT"
func combrep(n int, lst string) []string {
if n == 0 {
return []string{""}
}
if len(lst) == 0 {
return nil
}
r := combrep(n, lst[1:])
for _, x := range combrep(n-1, lst) {
r = append(r, x+string(lst[0]))
}
return r
}
func main() {
f, _ := os.Create("test-unique.fasta")
b := bufio.NewWriter(f)
w := fasta.NewWriter(b, 80)
for _, s := range combrep(200, alpbh) {
c := linear.NewSeq(
"foo;size=100",
[]alphabet.Letter(s),
alphabet.DNA,
)
w.Write(c)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment