forked from enormandeau/Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfasta_random_length.py
More file actions
executable file
·37 lines (29 loc) · 874 Bytes
/
fasta_random_length.py
File metadata and controls
executable file
·37 lines (29 loc) · 874 Bytes
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Create random fasta sequences.
Usage:
%program <length> <variance> <number> <output_file>"""
import sys
import re
import random
try:
seq_len = int(sys.argv[1]) # Length of sequences
seq_var = int(sys.argv[2]) # Variance of length
num_seq = int(sys.argv[3]) # Number of sequences
result_file = sys.argv[4] # Output fasta file
except:
print __doc__
sys.exit(0)
stub = "seq_"
num = 0
def out_name(stub, num):
return ">" + stub + str("%i" % num) + "\n"
with open(result_file, "w") as f:
for i in xrange(num_seq):
num += 1
seq = []
variance = random.randint(-seq_var, seq_var)
for j in xrange(seq_len + variance):
seq.append(random.choice(["A", "C", "G", "T"]))
f.write(out_name(stub, num))
f.write("".join(seq) + "\n")