-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathpadlock_search.cpp
More file actions
361 lines (282 loc) · 12 KB
/
padlock_search.cpp
File metadata and controls
361 lines (282 loc) · 12 KB
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#include "tntblast.h"
#include "throw.h"
using namespace std;
// Search for binding and ligation sites for Padlock probes / MOL-PCR / MIPS
// (all have the same assay geometry).
//
// Here are all of the possible binding configurations for primers P1 and P2
// against a target sequence (for now, we assume that all sequences have both a 5'-3'
// and a 3'-5' strand -- obviously not true for single stranded viruses):
//
// ************************************
// The P1 primer is 5' of the P2 primer
// That is, 5'-P1-3' 5'-P2-3'
// ************************************
//
// 3'-P1-5'3'-P2-5' (not allowed)
// 5'- =============================== -3'
// 3'- =============================== -5'
//
//
// 3'-P2-5'3'-P1-5'
// 5'- =============================== -3'
// 3'- =============================== -5'
//
//
// 5'- =============================== -3'
// 3'- =============================== -5'
// 5'-P1-3'5'-P2-3'
//
//
// 5'- =============================== -3'
// 3'- =============================== -5'
// 5'-P2-3'5'-P1-3' (not allowed)
//
/////////////////////////////////////////////////////////////////////////////////
// Note that single primer reactions have been removed for padlock probes
// (they are not allowed due to assay contraints).
//
// 3'-P1-5'3'-P1-5'
// 5'- =============================== -3' * single primer amplification
// 3'- =============================== -5'
//
//
// 3'-P2-5'3'-P2-5'
// 5'- =============================== -3' * single primer amplification
// 3'- =============================== -5'
//
//
//
// 5'- =============================== -3' * single primer amplification
// 3'- =============================== -5'
// 5'-P1-3'5'-P1-3
//
//
// 5'- =============================== -3' * single primer amplification
// 3'- =============================== -5'
// 5'-P2-3'5'-P2-3
//
list<hybrid_sig> padlock(DNAHash &m_hash, const pair<string, SEQPTR> &m_seq,
const hybrid_sig &m_sig, NucCruc &m_melt,
std::unordered_map<BindCacheKey, BindCacheValue> &m_plus_strand_melt_cache,
std::unordered_map<BindCacheKey, BindCacheValue> &m_minus_strand_melt_cache,
const float &m_forward_primer_strand,
const float &m_reverse_primer_strand,
const float &m_min_probe_tm, const float &m_max_probe_tm,
const float &m_min_probe_dg, const float &m_max_probe_dg,
const unsigned int &m_probe_clamp_5, const unsigned int &m_probe_clamp_3,
const unsigned int &m_max_gap, const unsigned int &m_max_mismatch,
const unsigned int &m_max_poly_degen,
const int &m_target_strand, const int &m_max_len,
const std::vector<std::string> &m_oligo_table,
std::unordered_map<std::string, size_t> &m_str_table)
{
const float forward_primer_strand = m_forward_primer_strand/m_sig.forward_degen;
const float reverse_primer_strand = m_reverse_primer_strand/m_sig.reverse_degen;
list<hybrid_sig> sig_list;
list<oligo_info> upstream_bind;
list<oligo_info> downstream_bind;
list<oligo_info>::const_iterator up_iter;
list<oligo_info>::const_iterator down_iter;
/////////////////////////////////////////////////////////////////////////////////////////////////////
// primer 2 upstream (5') and primer 1 downstream (3'): bind to minus strand
/////////////////////////////////////////////////////////////////////////////////////////////////////
// The upstream (5') primer has a 3' dangling base
m_melt.set_query( index_to_str(m_sig.reverse_oligo_str_index, m_oligo_table) );
// Assume that the primer oligos are in vast excess to the target strands
m_melt.strand(reverse_primer_strand, 0.0f);
if(m_target_strand & Seq_strand_minus){
bind_oligo_to_minus_strand(upstream_bind,
m_hash, m_seq.second,
index_to_str(m_sig.reverse_oligo_str_index, m_oligo_table),
m_melt, m_minus_strand_melt_cache,
m_min_probe_tm, m_max_probe_tm,
m_min_probe_dg, m_max_probe_dg,
m_probe_clamp_5, // Upstream primer has a 5' clamp,
0, // but no 3' clamp
m_max_gap,
m_max_mismatch,
m_max_poly_degen);
}
// Test primer 1 in the downstream position
m_melt.set_query( index_to_str(m_sig.forward_oligo_str_index, m_oligo_table) );
// Assume that the primer oligos are in vast excess to the target strands
m_melt.strand(forward_primer_strand, 0.0f);
if(m_target_strand & Seq_strand_minus){
bind_oligo_to_minus_strand(downstream_bind,
m_hash, m_seq.second,
index_to_str(m_sig.forward_oligo_str_index, m_oligo_table),
m_melt, m_minus_strand_melt_cache,
m_min_probe_tm, m_max_probe_tm,
m_min_probe_dg, m_max_probe_dg,
0, // Downstream primer does not have a 5' clamp,
m_probe_clamp_3, // but does have a 3' clamp
m_max_gap,
m_max_mismatch,
m_max_poly_degen);
}
// <---downstream upstream--->
//
// 5'-P1-3'5'-P2-3'
// 3'-======================================-5' minus strand
// 5'-======================================-3' plus strand
//
for(up_iter = upstream_bind.begin();up_iter != upstream_bind.end();up_iter++){
for(down_iter = downstream_bind.begin();down_iter != downstream_bind.end();down_iter++){
// DEBUG
//cerr << "\tdown = [" << down_iter->loc_5 << ", " << down_iter->loc_3 << "]" << endl;
//cerr << "\tup = [" << up_iter->loc_5 << ", " << up_iter->loc_3 << "]" << endl;
const int len = up_iter->loc_5 - down_iter->loc_3 - 1;
// loc coordinates are measured in the target plus strand
// Update May 31, 2024:
// - Padlock and MOL-PCR assays use m_max_len == 0
// - MIPS assays allow a user-specified m_max_len >= 0
if( (len >= 0) && (len <= m_max_len) ){
// DEBUG
//cerr << "\t21-" << endl;
const int start = down_iter->loc_5;
const int stop = up_iter->loc_3;
if(start > stop){
THROW(__FILE__ ":padlock: start > stop (4)");
}
const unsigned int len = stop - start + 1;
hybrid_sig tmp;
// Make a copy of the signature (including the id and the name)
tmp = m_sig;
// Downstream primer
tmp.forward_oligo_str_index = m_sig.forward_oligo_str_index;
// Upstream primer
tmp.reverse_oligo_str_index = m_sig.reverse_oligo_str_index;
tmp.primer_strand = hybrid_sig::MINUS;
tmp.amplicon_def_str_index = str_to_index(m_seq.first, m_str_table);
tmp.amplicon_range.first = start;
tmp.amplicon_range.second = stop;
tmp.forward_tm = down_iter->tm;
tmp.reverse_tm = up_iter->tm;
tmp.forward_dH = down_iter->dH;
tmp.reverse_dH = up_iter->dH;
tmp.forward_dS = down_iter->dS;
tmp.reverse_dS = up_iter->dS;
tmp.forward_mm = down_iter->num_mm;
tmp.reverse_mm = up_iter->num_mm;
tmp.forward_gap = down_iter->num_gap;
tmp.reverse_gap = up_iter->num_gap;
tmp.forward_align_str_index = str_to_index(deflate_dna_seq(down_iter->alignment), m_str_table);
tmp.reverse_align_str_index = str_to_index(deflate_dna_seq(up_iter->alignment), m_str_table);
tmp.forward_primer_clamp = down_iter->anchor_3;
tmp.reverse_primer_clamp = up_iter->anchor_5;
// Extract the match sequence in the same orientation as the primers
string tmp_amplicon(len, '-');
SEQPTR ptr = SEQ_START(m_seq.second) + max(0, start);
for(unsigned int i = max(0, 1 - start);i < len;i++, ptr++){
// Don't run past the end of the sequence
if( (ptr - SEQ_START(m_seq.second) ) >= (int)SEQ_SIZE(m_seq.second) ){
break;
}
tmp_amplicon[i] = hash_base_to_ascii(*ptr);
}
tmp.amplicon_str_index = str_to_index(deflate_dna_seq(tmp_amplicon), m_str_table);
sig_list.push_back(tmp);
}
}
}
downstream_bind.clear();
upstream_bind.clear();
/////////////////////////////////////////////////////////////////////////////////////////////////////
// primer 2 upstream (5') and primer 1 downstream (3'): bind to plus strand
/////////////////////////////////////////////////////////////////////////////////////////////////////
// The upstream (5') primer has a 3' dangling base
m_melt.set_query( index_to_str(m_sig.reverse_oligo_str_index, m_oligo_table) );
// Assume that the primer oligos are in vast excess to the target strands
m_melt.strand(reverse_primer_strand, 0.0f);
if(m_target_strand & Seq_strand_plus){
bind_oligo_to_plus_strand(upstream_bind,
m_hash, m_seq.second,
index_to_str(m_sig.reverse_oligo_str_index, m_oligo_table),
m_melt, m_plus_strand_melt_cache,
m_min_probe_tm, m_max_probe_tm,
m_min_probe_dg, m_max_probe_dg,
m_probe_clamp_5, // Upstream primer has a 5' clamp,
0, // but no 3' clamp
m_max_gap,
m_max_mismatch,
m_max_poly_degen);
}
// Test primer 1 in the downstream position
m_melt.set_query( index_to_str(m_sig.forward_oligo_str_index, m_oligo_table) );
// Assume that the primer oligos are in vast excess to the target strands
m_melt.strand(forward_primer_strand, 0.0f);
if(m_target_strand & Seq_strand_plus){
bind_oligo_to_plus_strand(downstream_bind,
m_hash, m_seq.second,
index_to_str(m_sig.forward_oligo_str_index, m_oligo_table),
m_melt, m_plus_strand_melt_cache,
m_min_probe_tm, m_max_probe_tm,
m_min_probe_dg, m_max_probe_dg,
0, // Downstream primer does not have a 5' clamp,
m_probe_clamp_3, // but does have a 5' clamp
m_max_gap,
m_max_mismatch,
m_max_poly_degen);
}
// <---upstream downstream--->
//
// 3'-P2-5'3'-P1-5'
// 5'-======================================-3' plus strand
//
for(up_iter = upstream_bind.begin();up_iter != upstream_bind.end();up_iter++){
for(down_iter = downstream_bind.begin();down_iter != downstream_bind.end();down_iter++){
const int len = down_iter->loc_5 - up_iter->loc_3 - 1;
// loc coordinates are measured in the target plus strand
// Update Aug 13, 2024 (should have been updated earlier, but I missed this code block!):
// - Padlock and MOL-PCR assays use m_max_len == 0
// - MIPS assays allow a user-specified m_max_len >= 0
if( (len >= 0) && (len <= m_max_len) ){
const int start = up_iter->loc_5;
const int stop = down_iter->loc_3;
if(start > stop){
THROW(__FILE__ ":padlock: start > stop (6)");
}
const unsigned int len = stop - start + 1;
hybrid_sig tmp;
// Make a copy of the signature (including the id and the name)
tmp = m_sig;
// Downstream primer
tmp.forward_oligo_str_index = m_sig.forward_oligo_str_index;
// Upstream primer
tmp.reverse_oligo_str_index = m_sig.reverse_oligo_str_index;
tmp.primer_strand = hybrid_sig::PLUS;
tmp.amplicon_def_str_index = str_to_index(m_seq.first, m_str_table);
tmp.amplicon_range.first = start;
tmp.amplicon_range.second = stop;
tmp.forward_tm = down_iter->tm;
tmp.reverse_tm = up_iter->tm;
tmp.forward_dH = down_iter->dH;
tmp.reverse_dH = up_iter->dH;
tmp.forward_dS = down_iter->dS;
tmp.reverse_dS = up_iter->dS;
tmp.forward_mm = down_iter->num_mm;
tmp.reverse_mm = up_iter->num_mm;
tmp.forward_gap = down_iter->num_gap;
tmp.reverse_gap = up_iter->num_gap;
tmp.forward_align_str_index = str_to_index(deflate_dna_seq(down_iter->alignment), m_str_table);
tmp.reverse_align_str_index = str_to_index(deflate_dna_seq(up_iter->alignment), m_str_table);
tmp.forward_primer_clamp = down_iter->anchor_3;
tmp.reverse_primer_clamp = up_iter->anchor_5;
// Extract the match sequence in the same orientation as the primers
string tmp_amplicon(len, '-');
SEQPTR ptr = SEQ_START(m_seq.second) + min( stop, (int)SEQ_SIZE(m_seq.second) - 1);
for(unsigned int i = max(0, stop - (int)SEQ_SIZE(m_seq.second) - 1);i < len;i++, ptr--){
// Don't run past the end of the sequence
if( ptr < SEQ_START(m_seq.second) ){
break;
}
tmp_amplicon[i] = hash_base_to_ascii_complement(*ptr);
}
tmp.amplicon_str_index = str_to_index(deflate_dna_seq(tmp_amplicon), m_str_table);
sig_list.push_back(tmp);
}
}
}
return sig_list;
}