-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfqreader.hpp
124 lines (97 loc) · 2.79 KB
/
fqreader.hpp
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
118
119
120
121
122
123
#ifndef FQREADER_HPP_
#define FQREADER_HPP_
#include <string>
#include <experimental/string_view>
#include <vector>
#include <pthread.h>
#include "tbb/concurrent_vector.h"
#include "hash.hpp"
#include "read.hpp"
#include "compress.hpp"
class FastaReader {
private:
/* Parameters */
static int L;
static int K;
static int MAX_ERRORS;
/* Heuristic to correct read orientation */
static int heuristic;
public:
bool print_info = false;
/* If the suffix length of a read is less than S, then it will not be considered in addChildren. */
int S;
/* Whether post-process. */
int POST_PROCESS = 0;
/* Input and output file names */
std::string INFILE;
std::string OUTFILE;
/* Shared variables */
Hash *starts;
Hash *ends;
tbb::concurrent_vector<Read*> reads;
int sequences = 0;
int current_bucket = 0;
std::vector<std::experimental::string_view> htcReads;
std::vector<int> htcBits;
int test = 0;
/* Thread control */
int num_threads = 1;
pthread_mutex_t thread_lock;
pthread_spinlock_t read_access;
std::vector<std::string> bases_unsplit;
std::vector<std::vector<std::string>> bases_split;
long split_size;
std::vector<int> rc_indicator;
FastaReader(int, int, int, int, const std::string &ifn,
const std::string &ofn, int, int);
~FastaReader() {
delete starts;
delete ends;
for (size_t i = 0; i < reads.size(); i++)
if (reads[i])
delete reads[i];
}
/* For encoder. */
static int getL() {
return L;
}
/* Read in fastq files. */
void readFastaq(int);
void readFastaqRC(int);
/* Returns a new read with bases BASES and correct parent, or null if already exists. */
Read* addRead(std::experimental::string_view);
Read* addRead(std::experimental::string_view, int);
/* Attaches appropriate children to a newly-created read. */
void addChildren(Read*, std::experimental::string_view);
/* Postprocess reads such that the width of tries is reduced.*/
static bool suff_order(Read *r, Read *s) {
return (r->suffix > s->suffix);
}
void postProcess(Read*);
/* Adds a read to a sequence if not already in one, and dumps sequence to file. */
void addSequence(Read*, BitWriter*);
/* Returns base with the most votes. */
char vote(int*, int);
/* Returns the Hamming distance between two strings. */
int diff(std::experimental::string_view, std::experimental::string_view);
/* Returns the current time (in millisecond) */
unsigned long currentTimeMillis();
/* Compress the fasta(q) file */
void *_thread();
void *_thread_orcom();
void *_thread_shortsuf();
static void *thread(void *obj) {
switch (heuristic) {
case 0:
return ((FastaReader*) obj)->_thread();
case 1:
return ((FastaReader*) obj)->_thread_orcom();
case 2:
return ((FastaReader*) obj)->_thread_shortsuf();
default:
return ((FastaReader*) obj)->_thread();
}
}
void run(int);
};
#endif