-
Notifications
You must be signed in to change notification settings - Fork 0
/
clip.h
executable file
·204 lines (161 loc) · 7.4 KB
/
clip.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
#ifndef CLIP_H
#define CLIP_H
#include "api/BamAux.h"
#include "api/BamReader.h"
#include "Deletion.h"
#include "FaidxWrapper.h"
#include "range.h"
#include "Thirdparty/overlapper.h"
#include "realignmentcaller.h"
#include <string>
#include <vector>
#include <sstream>
struct TargetRegion
{
std::string referenceName;
int start;
int end;
std::string sequence(FaidxWrapper &faidx) const {
return faidx.fetch(referenceName, start, end);
}
int length() const {
return end - start + 1;
}
};
class AbstractClip {
public:
AbstractClip(int referenceId, int mapPosition, int clipPosition,
int matePosition, const std::string& sequence,
const std::vector<BamTools::CigarOp>& cigar, int endPosition);
int length() const;
int leftmostPosition() const;
int getClipPosition() const {
return clipPosition;
}
virtual ~AbstractClip();
Deletion call(BamTools::BamReader& reader, FaidxWrapper &faidx, int insLength, int minOverlap,
double minIdentity, int minMapQual, IRealignmentCaller *pRealnCaller);
bool hasConflictWith(AbstractClip *other);
virtual std::string getType() = 0;
bool getConflictFlag() const;
void setConflictFlag(bool value);
std::string toString() {
std::stringstream ss;
ss << getClipPosition() << "\t" << getType();
return ss.str();
}
protected:
virtual Deletion call(FaidxWrapper &faidx, const std::vector<TargetRegion>& regions, int minOverlap,
double minIdentity, IRealignmentCaller *pRealnCaller) = 0;
virtual void fetchSpanningRanges(BamTools::BamReader &reader, int insLength, std::vector<IRange> &ranges, int minMapQual) = 0;
virtual void fecthSizesForSpanningPairs(BamTools::BamReader &reader, int inslength, std::vector<int>& sizes) = 0;
virtual void toTargetRegions(const std::string &referenceName, int insLength, std::vector<IRange> &ranges, std::vector<TargetRegion> ®ions) = 0;
virtual int lengthOfSoftclippedPart() = 0;
int lengthOfMappedPart() {
return sequence.size() - lengthOfSoftclippedPart();
}
int maxEditDistanceForSoftclippedPart();
virtual std::string softclippedPart() = 0;
virtual std::string mappedPart() = 0;
virtual int offsetFromThisEnd(std::string referenceName, FaidxWrapper& faidx) = 0;
virtual int offsetFromThatEnd(std::string referenceName, FaidxWrapper& faidx, int orignal) = 0;
int referenceId;
int mapPosition;
int clipPosition;
int matePosition;
std::string sequence;
std::vector<BamTools::CigarOp> cigar;
int endPosition;
bool conflictFlag;
};
class ForwardBClip : public AbstractClip {
public:
ForwardBClip(int referenceId, int mapPosition, int clipPosition, int matePosition,
const std::string& sequence, const std::vector<BamTools::CigarOp>& cigar, int endPosition);
private:
virtual void fetchSpanningRanges(BamTools::BamReader &reader, int insLength, std::vector<IRange> &ranges, int minMapQual);
virtual void fecthSizesForSpanningPairs(BamTools::BamReader& reader, int insLength, std::vector<int>& sizes);
virtual void toTargetRegions(const std::string &referenceName, int insLength, std::vector<IRange> &ranges, std::vector<TargetRegion> ®ions);
virtual Deletion call(FaidxWrapper &faidx, const std::vector<TargetRegion>& regions, int minOverlap,
double minIdentity, IRealignmentCaller *pRealnCaller);
// AbstractClip interface
public:
std::string getType();
// AbstractClip interface
protected:
int lengthOfSoftclippedPart() {
return cigar[0].Length;
}
std::string softclippedPart() {
return sequence.substr(0, lengthOfSoftclippedPart());
}
std::string mappedPart() {
return sequence.substr(lengthOfSoftclippedPart());
}
int offsetFromThisEnd(std::string referenceName, FaidxWrapper &faidx);
int offsetFromThatEnd(std::string referenceName, FaidxWrapper &faidx, int orignal);
};
class ReverseBClip : public AbstractClip {
// AbstractClip interface
public:
ReverseBClip(int referenceId, int mapPosition, int clipPosition, int matePosition,
const std::string& sequence, const std::vector<BamTools::CigarOp>& cigar, int endPosition);
std::string getType();
protected:
Deletion call(FaidxWrapper &faidx, const std::vector<TargetRegion> ®ions, int minOverlap,
double minIdentity, IRealignmentCaller *pRealnCaller);
void fetchSpanningRanges(BamTools::BamReader &reader, int insLength, std::vector<IRange> &ranges, int minMapQual);
void fecthSizesForSpanningPairs(BamTools::BamReader &reader, int inslength, std::vector<int> &sizes);
void toTargetRegions(const std::string &referenceName, int insLength, std::vector<IRange> &ranges, std::vector<TargetRegion> ®ions);
int lengthOfSoftclippedPart();
std::string softclippedPart();
std::string mappedPart();
int offsetFromThisEnd(std::string referenceName, FaidxWrapper &faidx);
int offsetFromThatEnd(std::string referenceName, FaidxWrapper &faidx, int orignal);
};
class ForwardEClip : public AbstractClip {
// AbstractClip interface
public:
ForwardEClip(int referenceId, int mapPosition, int clipPosition, int matePosition,
const std::string& sequence, const std::vector<BamTools::CigarOp>& cigar, int endPosition);
std::string getType();
protected:
Deletion call(FaidxWrapper &faidx, const std::vector<TargetRegion> ®ions, int minOverlap,
double minIdentity, IRealignmentCaller *pRealnCaller);
void fetchSpanningRanges(BamTools::BamReader &reader, int insLength, std::vector<IRange> &ranges, int minMapQual);
void fecthSizesForSpanningPairs(BamTools::BamReader &reader, int inslength, std::vector<int> &sizes);
void toTargetRegions(const std::string &referenceName, int insLength, std::vector<IRange> &ranges, std::vector<TargetRegion> ®ions);
int lengthOfSoftclippedPart();
std::string softclippedPart();
std::string mappedPart();
int offsetFromThisEnd(std::string referenceName, FaidxWrapper &faidx);
int offsetFromThatEnd(std::string referenceName, FaidxWrapper &faidx, int orignal);
};
class ReverseEClip : public AbstractClip {
public:
ReverseEClip(int referenceId, int mapPosition, int clipPosition, int matePosition,
const std::string& sequence, const std::vector<BamTools::CigarOp>& cigar, int endPosition);
private:
virtual void fetchSpanningRanges(BamTools::BamReader &reader, int insLength, std::vector<IRange> &ranges, int minMapQual);
virtual void fecthSizesForSpanningPairs(BamTools::BamReader& reader, int insLength, std::vector<int>& sizes);
virtual void toTargetRegions(const std::string &referenceName, int insLength, std::vector<IRange> &ranges, std::vector<TargetRegion> ®ions);
virtual Deletion call(FaidxWrapper &faidx, const std::vector<TargetRegion>& regions, int minOverlap,
double minIdentity, IRealignmentCaller *pRealnCaller);
// AbstractClip interface
public:
std::string getType();
// AbstractClip interface
protected:
int lengthOfSoftclippedPart() {
return cigar[cigar.size() - 1].Length;
}
std::string softclippedPart() {
return sequence.substr(lengthOfMappedPart());
}
std::string mappedPart() {
return sequence.substr(0, lengthOfMappedPart());
}
int offsetFromThisEnd(std::string referenceName, FaidxWrapper &faidx);
int offsetFromThatEnd(std::string referenceName, FaidxWrapper &faidx, int orignal);
};
#endif // CLIP_H