-
Notifications
You must be signed in to change notification settings - Fork 0
/
clip.cpp
620 lines (515 loc) · 22.9 KB
/
clip.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
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
#include "clip.h"
#include "error.h"
#include "Helper.h"
#include <iterator>
#include <algorithm>
#include <sstream>
#include <utility>
using namespace std;
using namespace BamTools;
AbstractClip::AbstractClip(int referenceId, int mapPosition, int clipPosition, int matePosition, const string &sequence, const vector<CigarOp>& cigar)
: referenceId(referenceId),
mapPosition(mapPosition),
clipPosition(clipPosition),
matePosition(matePosition),
sequence(sequence),
cigar(cigar),
conflictFlag(false) {
}
int AbstractClip::length() const {
return sequence.length();
}
int AbstractClip::leftmostPosition() const {
if (cigar[0].Type == 'S') return mapPosition - cigar[0].Length;
return mapPosition;
}
AbstractClip::~AbstractClip() {
}
Deletion AbstractClip::call(BamReader &reader, FaidxWrapper &faidx, int insLength, int minOverlap, double minIdentity, int minMapQual)
{
string refName = Helper::getReferenceName(reader, referenceId);
vector<IRange> ranges;
fetchSpanningRanges(reader, insLength, ranges, minMapQual);
// vector<int> sizes;
// fecthSizesForSpanningPairs(reader, insLength, sizes);
if (ranges.empty()) error("No deletion is found");
vector<TargetRegion> regions;
toTargetRegions(refName, insLength, ranges, regions);
return call(faidx, regions, minOverlap, minIdentity);
}
bool AbstractClip::hasConflictWith(AbstractClip *other) {
if (getType() == other->getType()) return false;
return abs(clipPosition - other->clipPosition) < Helper::CONFLICT_THRESHOLD;
}
bool AbstractClip::getConflictFlag() const
{
return conflictFlag;
}
void AbstractClip::setConflictFlag(bool value)
{
conflictFlag = value;
}
int AbstractClip::maxEditDistanceForSoftclippedPart()
{
if (lengthOfSoftclippedPart() >= 20) return 2;
return 1;
}
ForwardBClip::ForwardBClip(int referenceId, int mapPosition, int clipPosition, int matePosition, const string &sequence, const vector<CigarOp>& cigar)
: AbstractClip(referenceId, mapPosition, clipPosition, matePosition, sequence, cigar) {
}
/*
Deletion ForwardBClip::call(FaidxWrapper &faidx, const std::vector<TargetRegion> ®ions, int minOverlap, double minIdentity) {
for (auto it = regions.rbegin(); it != regions.rend(); ++it) {
if ((*it).length() < lengthOfSoftclippedPart()) continue;
string s1 = (*it).sequence(faidx);
SequenceOverlap overlap = Overlapper::computeOverlapSG(s1, softclippedPart());
if (overlap.edit_distance > maxEditDistanceForSoftclippedPart()) continue;
int leftEnd = (*it).start + overlap.match[0].end;
int offsetToRight = offsetFromThatEnd((*it).referenceName, faidx, leftEnd);
int rightEnd = clipPosition;
int offsetToLeft = offsetFromThisEnd((*it).referenceName, faidx);
int start1 = leftEnd - offsetToLeft;
int start2 = leftEnd + offsetToRight;
int end1 = rightEnd - offsetToLeft;
int end2 = rightEnd + offsetToRight;
int len = start1 - end1 + 1;
if (len > Helper::SVLEN_THRESHOLD) continue;
return Deletion((*it).referenceName, start1, start2, end1, end2, len, getType());
}
error("No deletion is found.");
}
*/
Deletion ForwardBClip::call(FaidxWrapper &faidx, const std::vector<TargetRegion> ®ions, int minOverlap, double minIdentity)
{
// error("No deletion is found.");
ScoreParam score_param(1, -1, 2, 4);
for (auto it = regions.begin(); it != regions.end(); ++it) {
string s1 = (*it).sequence(faidx);
reverse(s1.begin(), s1.end());
string s2 = sequence;
reverse(s2.begin(), s2.end());
SequenceOverlap overlap;
try {
overlap = Overlapper::computeOverlapSW2(s1, s2, minOverlap, minIdentity, ungapped_params);
} catch (ErrorException& ex) {
continue;
}
for (size_t i = 0; i < 2; ++i)
overlap.match[i].flipStrand(overlap.length[i]);
// overlap = Overlapper::alignPrefix(s1, s2, ungapped_params);
// if (s2 == "GCCTACAGAGTGCAGAGCCAGCCCAGGACAGGGGACAATTACACAGGCGATGGTCCTAAGAACCGAACCTTCCAATCCCAAAACTCTAGACAGGTATCCAA")
// cout << s1 << endl;
// overlap = Overlapper::ageAlignPrefix(s1, s2, score_param);
// if (!overlap.isQualified(minOverlap, minIdentity))
// continue;
int delta = overlap.getOverlapLength() - lengthOfSoftclippedPart();
int offset = 0;
for (auto &ci: cigar) {
if (ci.Type == 'D') offset += ci.Length;
else if (ci.Type == 'I') offset -= ci.Length;
}
int rightBp = clipPosition + offset;
int leftBp = (*it).start + overlap.match[0].start + lengthOfSoftclippedPart() - 1;
// int delta = overlap.match[1].length() - lengthOfSoftclippedPart();
// int rightBp = clipPosition;
// // leftBp might need to be adjusted.
// int leftBp = (*it).start + overlap.match[0].start + lengthOfSoftclippedPart() - 1;
int len = leftBp - rightBp + 1;
int start1 = delta > 0 ? leftBp : leftBp + delta;
int start2 = delta > 0 ? leftBp + delta : leftBp;
int end1 = delta > 0 ? rightBp : rightBp + delta;
int end2 = delta > 0 ? rightBp + delta : rightBp;
// if (start2 == 23483811) {
// cout << overlap << endl;
// cout << s2 << endl;
// cout << s1 << endl;
// }
if (len > Helper::SVLEN_THRESHOLD) continue;
return Deletion((*it).referenceName, start1, start2, end1, end2, len, getType());
}
error("No deletion is found.");
}
string ForwardBClip::getType()
{
return "5F";
}
void ForwardBClip::fetchSpanningRanges(BamReader &reader, int insLength, std::vector<IRange> &ranges, int minMapQual)
{
// SVSeq2.length
// int start = leftmostPosition();
int start = clipPosition;
// int end = start + insLength + length();
int end = start + insLength - 2 * length();
if (start > end) error("the region is invalid.");
if (!reader.SetRegion(referenceId, start - 1, referenceId, end))
error("Could not set the region.");
BamAlignment al;
while(reader.GetNextAlignment(al)) {
// string xt;
// al.GetTag("XT", xt);
// xt = xt.substr(0,1);
if (al.IsReverseStrand() && !al.IsMateReverseStrand() && al.RefID == al.MateRefID
&& al.MapQuality >= minMapQual //&& xt == "U"
&& al.Position > al.MatePosition && al.MatePosition + length() - Helper::SVLEN_THRESHOLD <= clipPosition) {
ranges.push_back({al.MatePosition + 1, al.Position + 1});
}
}
}
void ForwardBClip::fecthSizesForSpanningPairs(BamReader &reader, int insLength, std::vector<int> &sizes)
{
int start = clipPosition;
int end = clipPosition + insLength + length();
if (!reader.SetRegion(referenceId, start - 1, referenceId, end))
error("Could not set the region.");
vector<pair<int, int> > records;
BamAlignment al;
while(reader.GetNextAlignment(al)) {
if (al.IsReverseStrand() && !al.IsMateReverseStrand() && al.RefID == al.MateRefID
&& al.MapQuality > 0 && al.Position > al.MatePosition) {
records.push_back(make_pair(abs(al.InsertSize), al.Position - clipPosition));
}
}
sort(records.begin(), records.end(), [](const pair<int,int>& r1, const pair<int,int>& r2){ return r1.first < r2.first; });
cout << ">" << clipPosition << "," << mapPosition << endl;
transform(records.begin(), records.end(), ostream_iterator<string>(cout, " "), [](const pair<int,int>& r){
stringstream ss;
ss << "(" << r.first << "," << r.second << ")";
return ss.str();
});
cout << endl;
}
void ForwardBClip::toTargetRegions(const string &referenceName, int insLength, std::vector<IRange> &ranges, std::vector<TargetRegion> ®ions)
{
int rightmostPos = clipPosition + length();
std::vector<IRange> newRanges(ranges.size());
// transform(ranges.begin(), ranges.end(), newRanges.begin(), [=](const IRange &ran) { IRange r = {ran.start, ran.start + insLength + length()}; return r; });
transform(ranges.begin(), ranges.end(), newRanges.begin(), [=](const IRange &ran) { IRange r = {ran.start, ran.start + insLength - length()}; return r; });
std::vector<IdCluster> idClusters;
clusterRanges(newRanges, idClusters);
// Replace with the merging method used by SVSeq2
// sort(std::begin(newRanges), std::end(newRanges));
// clusterRanges2(newRanges, idClusters);
for (auto &elt : idClusters) {
int s = newRanges[elt.front()].start;
if (s > rightmostPos) break;
int e = newRanges[elt.back()].end;
if (e > rightmostPos) e = rightmostPos;
if (s > e) break;
regions.push_back({referenceName, s, e});
}
}
/*
ForwardEClip::ForwardEClip(int referenceId, int mapPosition, int clipPosition, int matePosition, const string &sequence, const std::vector<CigarOp> &cigar)
: AbstractClip(referenceId, mapPosition, clipPosition, matePosition, sequence, cigar) {
}
void ForwardEClip::fetchSpanningRanges(BamReader &reader, int insLength, std::vector<IRange> &ranges)
{
ranges.push_back({clipPosition, matePosition});
}
void ForwardEClip::toTargetRegions(const string &referenceName, int insLength, std::vector<IRange> &ranges, std::vector<TargetRegion> ®ions)
{
int pe = ranges[0].end + length();
int leftmostPos = clipPosition;
int len1 = length() - cigar[cigar.size() - 1].Length;
int cPrime = ranges[0].end + len1 - insLength;
if (cPrime < leftmostPos) cPrime = leftmostPos;
regions.push_back({referenceName, cPrime, pe});
}
Deletion ForwardEClip::call(FaidxWrapper &faidx, const std::vector<TargetRegion> ®ions, int minOverlap, double minIdentity)
{
string s1 = regions[0].sequence(faidx);
SequenceOverlap overlap = Overlapper::computeOverlapSW(s1, sequence, minOverlap, minIdentity, ungapped_params);
if (overlap.getOverlapLength() >= minOverlap &&
overlap.getPercentIdentity() >= minIdentity * 100) {
int rightBp = regions[0].start + overlap.match[0].start - 1;
int leftBp = (overlap.getOverlapLength() > cigar[cigar.size() - 1].Length) ? clipPosition - overlap.getOverlapLength() + cigar[cigar.size() - 1].Length
: clipPosition;
leftBp--; // left breakpoint refers the position of the last base prior to the clipped part conforming to the VCF format.
int len = leftBp - rightBp;
if (overlap.getOverlapLength() < cigar[cigar.size() - 1].Length) len += cigar[cigar.size() - 1].Length - overlap.getOverlapLength();
if (len > Helper::SVLEN_THRESHOLD) error("No deletion was found.");
return Deletion(regions[0].referenceName, leftBp, leftBp, rightBp, rightBp, len);
}
error("No deletion was found.");
}
*/
ReverseEClip::ReverseEClip(int referenceId, int mapPosition, int clipPosition, int matePosition, const string &sequence, const std::vector<CigarOp> &cigar)
: AbstractClip(referenceId, mapPosition, clipPosition, matePosition, sequence, cigar) {
}
void ReverseEClip::fetchSpanningRanges(BamReader &reader, int insLength, std::vector<IRange> &ranges, int minMapQual)
{
// Experiment ID: SVSeq2.length
int start = clipPosition - insLength + length();
// int end = leftmostPosition() + length();
// int start = end - insLength - length();
if (start < 0) start = 0;
int end = clipPosition - length();
if (start > end) error("the region is invalid.");
if (!reader.SetRegion(referenceId, start - 1, referenceId, end))
error("Could not set the region.");
BamAlignment al;
while(reader.GetNextAlignment(al)) {
// string xt;
// al.GetTag("XT", xt);
// xt = xt.substr(0,1);
if (al.Position < start - 1) continue;
if (!al.IsReverseStrand() && al.IsMateReverseStrand() && al.RefID == al.MateRefID
&& al.MapQuality >= minMapQual //&& xt == "U"
&& al.Position < al.MatePosition && al.MatePosition >= clipPosition - Helper::SVLEN_THRESHOLD) {
ranges.push_back({al.Position + 1, al.MatePosition + 1});
}
}
}
void ReverseEClip::fecthSizesForSpanningPairs(BamReader &reader, int insLength, std::vector<int> &sizes)
{
}
void ReverseEClip::toTargetRegions(const string &referenceName, int insLength, std::vector<IRange> &ranges, std::vector<TargetRegion> ®ions)
{
int leftmostPos = clipPosition - length();
std::vector<IRange> newRanges(ranges.size());
// transform(ranges.begin(), ranges.end(), newRanges.begin(), [=](const IRange &ran) { IRange r = {ran.end - insLength - length(), ran.end}; return r; });
transform(ranges.begin(), ranges.end(), newRanges.begin(), [=](const IRange &ran) { IRange r = {ran.end - insLength + 2 * length(), ran.end + length()}; return r; });
std::vector<IdCluster> idClusters;
clusterRanges(newRanges, idClusters);
// Replace with the merging method used by SVSeq2
// sort(std::begin(newRanges), std::end(newRanges));
// clusterRanges2(newRanges, idClusters);
for (auto &elt : idClusters) {
int e = newRanges[elt.back()].end;
if (e < leftmostPos) continue;
int s = newRanges[elt.front()].start;
if (s < leftmostPos) s = leftmostPos;
if (s > e) continue;
regions.push_back({referenceName, s, e});
}
}
/*
Deletion ReverseEClip::call(FaidxWrapper &faidx, const std::vector<TargetRegion> ®ions, int minOverlap, double minIdentity) {
for (auto it = regions.rbegin(); it != regions.rend(); ++it) {
if ((*it).length() < lengthOfSoftclippedPart()) continue;
string s1 = (*it).sequence(faidx);
SequenceOverlap overlap = Overlapper::computeOverlapSG(s1, softclippedPart());
if (overlap.edit_distance > maxEditDistanceForSoftclippedPart()) continue;
int leftEnd = clipPosition - 1;
int offsetToRight = offsetFromThisEnd((*it).referenceName, faidx);
int rightEnd = (*it).start + overlap.match[0].start;
int offsetToLeft = offsetFromThatEnd((*it).referenceName, faidx, rightEnd);
int start1 = leftEnd - offsetToLeft;
int start2 = leftEnd + offsetToRight;
int end1 = rightEnd - offsetToLeft;
int end2 = rightEnd + offsetToRight;
int len = start1 - end1 + 1;
if (len > Helper::SVLEN_THRESHOLD) continue;
return Deletion((*it).referenceName, start1, start2, end1, end2, len, getType());
}
error("No deletion is found.");
}
*/
Deletion ReverseEClip::call(FaidxWrapper &faidx, const std::vector<TargetRegion> ®ions, int minOverlap, double minIdentity)
{
// error("No deletion is found.");
ScoreParam score_param(1, -1, 2, 4);
for (auto it = regions.rbegin(); it != regions.rend(); ++it) {
string s1 = (*it).sequence(faidx);
string s2 = sequence;
SequenceOverlap overlap;
try {
overlap = Overlapper::computeOverlapSW2(s1, s2, minOverlap, minIdentity, ungapped_params);
} catch (ErrorException& ex) {
continue;
}
// overlap = Overlapper::alignSuffix(s1, s2, ungapped_params);
// overlap = Overlapper::ageAlignSuffix(s1, s2, score_param);
// if (!overlap.isQualified(minOverlap, minIdentity))
// continue;
int delta = overlap.getOverlapLength() - lengthOfSoftclippedPart();
int offset = 0;
for (auto &ci: cigar) {
if (ci.Type == 'D') offset += ci.Length;
else if (ci.Type == 'I') offset -= ci.Length;
}
int leftBp = clipPosition - 1 - offset;
int rightBp = (*it).start + overlap.match[0].end - lengthOfSoftclippedPart() + 1;
// int delta = overlap.match[1].length() - lengthOfSoftclippedPart();
// int leftBp = clipPosition - 1;
// // rightBp might need to be adjusted
// int rightBp = (*it).start + overlap.match[0].end - lengthOfSoftclippedPart() + 1;
int len = leftBp - rightBp + 1;
int start1 = delta > 0 ? leftBp - delta : leftBp;
int start2 = delta > 0 ? leftBp : leftBp - delta;
int end1 = delta > 0 ? rightBp - delta : rightBp;
int end2 = delta > 0 ? rightBp : rightBp - delta;
// if (start2 == 54151129) {
// cout << overlap << endl;
// cout << s2 << endl;
// cout << s1 << endl;
// }
if (len > Helper::SVLEN_THRESHOLD) continue;
return Deletion((*it).referenceName, start1, start2, end1, end2, len, getType());
}
error("No deletion is found.");
}
string ReverseEClip::getType()
{
return "5R";
}
int ForwardBClip::offsetFromThisEnd(string referenceName, FaidxWrapper &faidx)
{
return numOfThelongestSuffix(softclippedPart(),
faidx.fetch(referenceName,
clipPosition - lengthOfSoftclippedPart(),
clipPosition - 1));
}
int ForwardBClip::offsetFromThatEnd(string referenceName, FaidxWrapper &faidx, int orignal)
{
return numOfTheLongestPrefix(mappedPart(),
faidx.fetch(referenceName,
orignal + 1,
orignal + lengthOfMappedPart()));
}
int ReverseEClip::offsetFromThisEnd(string referenceName, FaidxWrapper &faidx)
{
return numOfTheLongestPrefix(softclippedPart(),
faidx.fetch(referenceName,
clipPosition,
clipPosition + lengthOfSoftclippedPart() - 1));
}
int ReverseEClip::offsetFromThatEnd(string referenceName, FaidxWrapper &faidx, int orignal)
{
return numOfThelongestSuffix(mappedPart(),
faidx.fetch(referenceName,
orignal - lengthOfMappedPart(),
orignal - 1));
}
ReverseBClip::ReverseBClip(int referenceId, int mapPosition, int clipPosition, int matePosition, const string &sequence, const std::vector<CigarOp> &cigar)
: AbstractClip(referenceId, mapPosition, clipPosition, matePosition, sequence, cigar) {
}
string ReverseBClip::getType()
{
return "3R";
}
Deletion ReverseBClip::call(FaidxWrapper &faidx, const std::vector<TargetRegion> ®ions, int minOverlap, double minIdentity)
{
string s1 = regions[0].sequence(faidx);
reverse(s1.begin(), s1.end());
string s2 = sequence;
reverse(s2.begin(), s2.end());
SequenceOverlap overlap = Overlapper::computeOverlapSW2(s1, s2, minOverlap, minIdentity, ungapped_params);
for (size_t i = 0; i < 2; ++i)
overlap.match[i].flipStrand(overlap.length[i]);
int delta = overlap.getOverlapLength() - lengthOfSoftclippedPart();
int offset = 0;
for (auto &ci: cigar) {
if (ci.Type == 'D') offset += ci.Length;
else if (ci.Type == 'I') offset -= ci.Length;
}
int rightBp = clipPosition + offset;
int leftBp = regions[0].start + overlap.match[0].start + lengthOfSoftclippedPart() - 1;
int len = leftBp - rightBp + 1;
int start1 = delta > 0 ? leftBp : leftBp + delta;
int start2 = delta > 0 ? leftBp + delta : leftBp;
int end1 = delta > 0 ? rightBp : rightBp + delta;
int end2 = delta > 0 ? rightBp + delta : rightBp;
if (len > Helper::SVLEN_THRESHOLD) error("No deletion is found.");
return Deletion(regions[0].referenceName, start1, start2, end1, end2, len, getType());
error("No deletion is found.");
}
void ReverseBClip::fetchSpanningRanges(BamReader &reader, int insLength, std::vector<IRange> &ranges, int minMapQual)
{
ranges.push_back({matePosition + 1, clipPosition + 1});
}
void ReverseBClip::fecthSizesForSpanningPairs(BamReader &reader, int inslength, std::vector<int> &sizes)
{
}
void ReverseBClip::toTargetRegions(const string &referenceName, int insLength, std::vector<IRange> &ranges, std::vector<TargetRegion> ®ions)
{
// ran.start, ran.start + insLength - length()
int rightmostPos = clipPosition + length();
int s = ranges[0].start;
int e = s + insLength - length();
if (e > rightmostPos) e = rightmostPos;
if (s > e) return;
regions.push_back({referenceName, s, e});
}
int ReverseBClip::lengthOfSoftclippedPart()
{
return cigar[0].Length;
}
string ReverseBClip::softclippedPart()
{
return sequence.substr(0, lengthOfSoftclippedPart());
}
string ReverseBClip::mappedPart()
{
return sequence.substr(lengthOfSoftclippedPart());
}
int ReverseBClip::offsetFromThisEnd(string referenceName, FaidxWrapper &faidx)
{
}
int ReverseBClip::offsetFromThatEnd(string referenceName, FaidxWrapper &faidx, int orignal)
{
}
ForwardEClip::ForwardEClip(int referenceId, int mapPosition, int clipPosition, int matePosition, const string &sequence, const std::vector<CigarOp> &cigar)
: AbstractClip(referenceId, mapPosition, clipPosition, matePosition, sequence, cigar) {
}
string ForwardEClip::getType()
{
return "3F";
}
Deletion ForwardEClip::call(FaidxWrapper &faidx, const std::vector<TargetRegion> ®ions, int minOverlap, double minIdentity)
{
string s1 = regions[0].sequence(faidx);
SequenceOverlap overlap = Overlapper::computeOverlapSW2(s1, sequence, minOverlap, minIdentity, ungapped_params);
int delta = overlap.getOverlapLength() - lengthOfSoftclippedPart();
int offset = 0;
for (auto &ci: cigar) {
if (ci.Type == 'D') offset += ci.Length;
else if (ci.Type == 'I') offset -= ci.Length;
}
int leftBp = clipPosition - 1 - offset;
int rightBp = regions[0].start + overlap.match[0].end - lengthOfSoftclippedPart() + 1;
int len = leftBp - rightBp + 1;
int start1 = delta > 0 ? leftBp - delta : leftBp;
int start2 = delta > 0 ? leftBp : leftBp - delta;
int end1 = delta > 0 ? rightBp - delta : rightBp;
int end2 = delta > 0 ? rightBp : rightBp - delta;
if (len <= Helper::SVLEN_THRESHOLD) {
return Deletion(regions[0].referenceName, start1, start2, end1, end2, len, getType());
}
error("No deletion is found.");
}
void ForwardEClip::fetchSpanningRanges(BamReader &reader, int insLength, std::vector<IRange> &ranges, int minMapQual)
{
ranges.push_back({clipPosition + 1, matePosition + 1});
}
void ForwardEClip::fecthSizesForSpanningPairs(BamReader &reader, int inslength, std::vector<int> &sizes)
{
}
void ForwardEClip::toTargetRegions(const string &referenceName, int insLength, std::vector<IRange> &ranges, std::vector<TargetRegion> ®ions)
{
// ran.end - insLength + 2 * length(), ran.end + length()
int leftmostPos = clipPosition;
int s = ranges[0].end - insLength + 2 * length();
if (s < leftmostPos) s = leftmostPos;
int e = ranges[0].end + length();
if (s > e) return;
regions.push_back({referenceName, s, e});
}
int ForwardEClip::lengthOfSoftclippedPart()
{
return cigar[cigar.size() - 1].Length;
}
string ForwardEClip::softclippedPart()
{
return sequence.substr(lengthOfMappedPart());
}
string ForwardEClip::mappedPart()
{
return sequence.substr(0, lengthOfMappedPart());
}
int ForwardEClip::offsetFromThisEnd(string referenceName, FaidxWrapper &faidx)
{
}
int ForwardEClip::offsetFromThatEnd(string referenceName, FaidxWrapper &faidx, int orignal)
{
}