This repository has been archived by the owner on Dec 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestgen.py
executable file
·80 lines (61 loc) · 1.55 KB
/
testgen.py
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import sys
import math
import random
import time
from multiprocessing import Process, Queue
DEBUG = False
num_threads = 0
threads = []
queue = None
sequences = {}
def disco_shuffle(tid, size_vect, size_matt,
alphabet=["A","G","T","C"]):
tmp_results = []
size_thread = int(math.ceil(size_matt / num_threads))
start_time = time.time()
if DEBUG:
print("Thread : " + str(tid) + " : Started : " +
str(size_thread))
for i in range(size_thread):
str_seq = ""
for j in range(size_vect):
str_seq += random.choice(alphabet)
# try:
# tmp = sequences[str_seq]
# except:
# results[tid].append(str_seq)
# sequences[str_seq] = 1
tmp_results.append(str_seq)
queue.put(tmp_results)
end_time = time.time()
if DEBUG:
print("Thread : " + str(tid) + " : Ended : " +
str(end_time - start_time))
def main(argv):
global num_threads, threads, queue
num_threads = int(argv[0]) # number of threads
threads = [None] * num_threads
queue = Queue()
size_vect = int(argv[1]) # size of a single sequence
size_matt = int(argv[2]) # number of sequences
alphabet = [ "A", "G", "T", "C" ]
global sequences
sequences = {}
global DEBUG
try:
DEBUG = argv[3] # optional debug parameter
except: pass
for tid in range(num_threads):
threads[tid] = Process(target=disco_shuffle,
args=(tid, size_vect, size_matt),
kwargs=dict(alphabet=alphabet))
threads[tid].start()
# for thread in threads:
# thread.join()
for thread in threads:
res = queue.get()
for row in res:
print(">")
print(row)
if __name__ == "__main__":
main(sys.argv[1:])