-
Notifications
You must be signed in to change notification settings - Fork 4
/
randomCollection.cpp
80 lines (58 loc) · 1.27 KB
/
randomCollection.cpp
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
#include "strict_fstream.hpp"
#include "zstr.hpp"
#include <fstream>
#include <cstring>
#include <string>
#include <iostream>
#include <cstdint>
using namespace std;
uint32_t xs(uint32_t& y){
y^=(y<<13); y^=(y>>17);y=(y^=(y<<15)); return y;
}
__uint128_t xs(__uint128_t& g_lehmer64_state) {
g_lehmer64_state *= 0xda942042e4dd58b5;
return g_lehmer64_state >> 64;
}
char randNuc(__uint128_t& seed){
switch (xs(seed)%4){
case 0:
return 'A';
case 1:
return 'C';
case 2:
return 'G';
case 3:
return 'T';
}
return 'A';
}
string random_sequence(uint64_t basesnumber,string& res,__uint128_t& seed){
res.clear();
for(unsigned int i(0);i<basesnumber;++i){
res.push_back(randNuc(seed));
}
return res;
}
int main(int argc, char ** argv){
if(argc<3){
cout<<"[#Genome] [#size] [prefix]"<<endl;
exit(0);
}
uint64_t genomes(stoll(argv[1]));
uint64_t size(stoll(argv[2]));
string prefix((argv[3]));
srand (time(NULL));
unsigned int i(0);
#pragma omp parallel for
for(i=0;i<genomes;++i){
zstr::ofstream out(prefix+to_string(i)+".fa.gz");
#pragma omp critical
{
cout<<prefix+to_string(i)+".fa.gz"<<endl;
}
string rs;
__uint128_t seed=(rand());
rs=random_sequence(size,rs,seed);
out<<">1\n"<<rs<<'\n';
}
}