-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrand_fasta.go
47 lines (38 loc) · 871 Bytes
/
rand_fasta.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
// Author: Hengyi Jiang <[email protected]>
package main
import(
"fmt"
"os"
"strconv"
"bytes"
"math/rand"
)
func main(){
bases :="ATCG"
alphabet :="ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
n, _err := strconv.ParseInt(os.Args[1],10,0)
if _err !=nil{
fmt.Println("sequence count should be number")
os.Exit(1)
}
size, _err := strconv.ParseInt(os.Args[2],10,0)
if _err !=nil{
fmt.Println("sequence size should be number")
os.Exit(1)
}
base_len :=4
alphabet_len:=len(alphabet)
for j:=0; j<int(n); j++{
var buf bytes.Buffer
var fasta_name bytes.Buffer
for i:=0;i<20;i++{
rand_i:=rand.Intn(alphabet_len)
fasta_name.WriteString(alphabet[rand_i:rand_i+1])
}
for i:=0;i<int(size);i++{
rand_i:=rand.Intn(base_len)
buf.WriteString(bases[rand_i:rand_i+1])
}
fmt.Printf(">%s\n%s\n",fasta_name.String(),buf.String())
}
}