-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathProcess_sam_out.h
267 lines (191 loc) · 6.18 KB
/
Process_sam_out.h
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/*
Authors:
Haoyu Cheng
*/
#ifndef __OUTPUT__
#define __OUTPUT__
#define FORWARD 0
#define REVERSE 1
#include "Schema.h"
typedef struct
{
char *tag;
char type;
char cVal;
int iVal;
float fVal;
char *sVal;
} OPT_FIELDS;
typedef struct
{
char *QNAME;
short FLAG;
char *RNAME;
unsigned int POS;
unsigned char MAPQ;
char *CIGAR;
char *CIGAR_CHAR;
int *CIGAR_SIZE;
char *MRNAME;
int MPOS;
int ISIZE;
char *SEQ;
char *QUAL;
int optSize;
OPT_FIELDS *optFields;
} SAM;
int Output_gene(char *fileName);
///void (*finalizeOutput)();
void finalizeOutput();
void multi_outputQ(SAM map, int thread_id);
FILE* get_Ouput_Dec();
void OutPutSAM_Nounheader(_rg_name_l *_ih_refGenName, int refChromeCont, int argc, char *argv[]);
///是双端的read
#define IS_PAIRED 1
///双端read符合要求的比对上(满足一定距离)
#define MATE_MAPPED 2
///read本身没有比对上
#define SINGLE_UNMAPPED 4
///双端read没有符合要求的比对上(满足一定距离)
#define MATE_UNMAPPED 8
///read本身比对到反向互补链
#define RC_MAPPED 16 ///OX10
///双端read的另一条比对到反向互补链,也就是该read本身比对到正向链了
#define RC_MATE_MAPPED 32 ///OX20
///双端read中的read1
#define READ1 64
///双端read中的read2
#define READ2 128
///有mutiple mapping
#define MUTIREAD 128
typedef struct Output_buffer
{
Output_buffer_sub_block* sub_buffer;
///这两个单位是subblock
long long sub_block_size;
long long sub_block_number;
///int all_buffer_end = 0;
int all_buffer_end;
Output_buffer() :all_buffer_end(0)
{};
} Output_buffer;
typedef struct Output_methy_buffer
{
Methylation* sub_buffer;
///这两个单位是subblock
long long sub_block_size;
long long sub_block_number;
///int all_buffer_end = 0;
int all_buffer_end;
Output_methy_buffer() :all_buffer_end(0)
{};
} Output_methy_buffer;
typedef struct Output_methy_buffer_pair
{
Pair_Methylation* sub_buffer;
///这两个单位是subblock
long long sub_block_size;
long long sub_block_number;
///int all_buffer_end = 0;
int all_buffer_end;
Output_methy_buffer_pair() :all_buffer_end(0)
{};
} Output_methy_buffer_pair;
void init_buffer_sub_block(Output_buffer_sub_block* sub_block);
void init_output_buffer(int thread_number);
void* pop_buffer(void*);
void push_results_to_buffer(Output_buffer_sub_block* sub_block);
void finish_output_buffer();
void init_output_methy_buffer(int thread_number);
void init_output_methy_buffer_pair(int thread_number);
void* pop_methy_buffer(void*);
void* pop_methy_buffer_pair(void*);
void push_methy_to_buffer(Methylation* methy);
void push_methy_to_buffer_pair(Pair_Methylation* methy);
void finish_output_buffer_pair();
#define OFFSET 32
#define INT_LENGTH 20 //2^64 -1 = 18446744073709551615, 占了20位
///扩大空间留的都有余量,所以向后加一点\t之类的不需要再检查了
///如果输入变量是char*,且长度不知
inline void output_to_buffer_char_no_length(Output_buffer_sub_block* sub_block, char* input)
{
int input_length = strlen(input);
///更新了length
sub_block->length = sub_block->length + input_length;
///如果空间足够的,则size不用更新
if (sub_block->length + OFFSET< sub_block->size)
{
memcpy(sub_block->buffer + sub_block->length - input_length, input, input_length);
///sub_block->buffer[sub_block->length] = '\0';
}
else
{
///空间不够,size需要扩大
sub_block->size = (sub_block->length + OFFSET)* 2 + 1;
char* tmp = (char*)malloc(sub_block->size);
memcpy(tmp, sub_block->buffer, sub_block->length - input_length);
free(sub_block->buffer);
sub_block->buffer = tmp;
memcpy(sub_block->buffer + sub_block->length - input_length, input, input_length);
///sub_block->buffer[sub_block->length] = '\0';
}
}
///扩大空间留的都有余量,所以向后加一点\t之类的不需要再检查了
///如果输入变量是char*,且长度已知
inline void output_to_buffer_char_length(Output_buffer_sub_block* sub_block, char* input, int input_length)
{
///更新了length
sub_block->length = sub_block->length + input_length;
///如果空间足够的,则size不用更新
if (sub_block->length + OFFSET< sub_block->size)
{
memcpy(sub_block->buffer + sub_block->length - input_length, input, input_length);
///sub_block->buffer[sub_block->length] = '\0';
}
else
{
///空间不够,size需要扩大
sub_block->size = (sub_block->length + OFFSET) * 2 + 1;
char* tmp = (char*)malloc(sub_block->size);
memcpy(tmp, sub_block->buffer, sub_block->length - input_length);
free(sub_block->buffer);
sub_block->buffer = tmp;
memcpy(sub_block->buffer + sub_block->length - input_length, input, input_length);
///sub_block->buffer[sub_block->length] = '\0';
}
}
///扩大空间留的都有余量,所以向后加一点\t之类的不需要再检查了
///注意这个数是
inline void output_to_buffer_int(Output_buffer_sub_block* sub_block, bitmapper_bs_iter input)
{
int input_int_length;
//2^64 -1 = 18446744073709551615, 占了20位
///如果空间足够的,则size不用更新
if (sub_block->length + INT_LENGTH + OFFSET< sub_block->size)
{
sprintf(sub_block->buffer + sub_block->length, "%llu", input);
input_int_length = strlen(sub_block->buffer + sub_block->length);
sub_block->length = sub_block->length + input_int_length;
}
else
{
///空间不够,size需要扩大
sub_block->size = (sub_block->length + INT_LENGTH + OFFSET) * 2 + 1;
char* tmp = (char*)malloc(sub_block->size);
memcpy(tmp, sub_block->buffer, sub_block->length);
free(sub_block->buffer);
sub_block->buffer = tmp;
sprintf(sub_block->buffer + sub_block->length, "%llu", input);
input_int_length = strlen(sub_block->buffer + sub_block->length);
sub_block->length = sub_block->length + input_int_length;
}
}
int init_output_methy(char *fileName, int* need_context);
void output_single_methy_CpG(bitmapper_bs_iter tmp_pos, char* chrome_name, int nmethyl, int total);
void output_single_methy_CHG(bitmapper_bs_iter tmp_pos, char* chrome_name, int nmethyl, int total);
void output_single_methy_CHH(bitmapper_bs_iter tmp_pos, char* chrome_name, int nmethyl, int total);
void output_single_methy_multiple_thread
(bitmapper_bs_iter tmp_pos, char* chrome_name, int nmethyl, int total, Output_buffer_sub_block* buffer);
void output_methy_directly(Output_buffer_sub_block* CpG_buffer, Output_buffer_sub_block* CHG_buffer, Output_buffer_sub_block* CHH_buffer);
#endif