-
Notifications
You must be signed in to change notification settings - Fork 0
/
dnatest.cpp
118 lines (99 loc) · 2.7 KB
/
dnatest.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//
// dnatest.cpp
// APOBECXP
//
// Created by Marat Kazanov on 04/04/2018.
// Copyright © 2018 Marat Kazanov. All rights reserved.
//
#include <iostream>
#include "dnatest.hpp"
#include <random>
#include "ghuman.hpp"
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include <iterator>
using namespace std;
using namespace std::chrono;
template<typename Out>
void split(const string &s, char delim, Out result) {
stringstream ss(s);
string item;
while (getline(ss, item, delim)) {
*(result++) = item;
}
}
vector<string> split(const string &s, char delim) {
vector<string> elems;
split(s, delim, back_inserter(elems));
return elems;
}
void GenerateRandomDNAPositions()
{
CHumanGenome g;
g.InitializeHuman("37", "/Users/mar/BIO/BIODATA/HUMAN/CH37/hs_ref_GRCh37.p5_chr", ".fa", "FASTA", 0);
random_device rd; // obtain a random number from hardware
mt19937 eng(rd()); // seed the generator
uniform_int_distribution<unsigned long> distr(1, 3095677412); // define the range
unsigned long num;
unsigned long curlen;
int chrLen;
int chr,pos;
ofstream f;
f.open("/Users/mar/4/dna_random_positions.txt");
for(int i=0; i<30000000; i++)
{
num = distr(eng);
curlen = 0;
for(int j=0;j<24;j++)
{
chrLen = g.chrLen[j];
if (num <= (curlen + chrLen))
{
pos = (int) (num - curlen);
chr = j+1;
f << chr << '\t' << pos << '\n';
break;
}
curlen = curlen + chrLen;
}
}
f.close();
}
void ReadRandomDNAPositions()
{
const int FILE_SIZE = 30000000;
vector<string> flds;
int i;
string line;
struct dnaPosType{
int chr;
int pos;
};
struct dnaPosType* poss;
CHumanGenome g;
g.InitializeHuman("37", "/Users/mar/BIO/BIODATA/HUMAN/CH37/hs_ref_GRCh37.p5_chr", ".fa", "FASTA");
ifstream f;
f.open("/Users/mar/BIO/PROJECTS/CACHE/DnaTestFiles/dna_random_positions_30M_3.txt");
poss = new dnaPosType[FILE_SIZE];
i = 0;
while(getline(f, line))
{
flds = split(line, '\t');
poss[i].chr = stoi(flds[0]);
poss[i].pos = stoi(flds[1]);
i++;
}
f.close();
printf("Start test\n");
char bs;
high_resolution_clock::time_point t1 = high_resolution_clock::now();
for(i=0;i<FILE_SIZE;i++)
{
bs = g.dna[poss[i].chr-1][poss[i].pos-1];
}
high_resolution_clock::time_point t2 = high_resolution_clock::now();
auto duration = duration_cast<microseconds>( t2 - t1 ).count();
printf("End test: %ll\n", duration);
}