-
Notifications
You must be signed in to change notification settings - Fork 0
/
FiveEndForwardSCRead.cpp
executable file
·221 lines (177 loc) · 6.54 KB
/
FiveEndForwardSCRead.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
#include "FiveEndForwardSCRead.h"
#include "Deletion.h"
FiveEndForwardSCRead::FiveEndForwardSCRead(const std::string &name,
const ChromosomeRegion &alignedRegion,
const std::string &sequence,
int mapQuality,
int clippedLength,
int smallDelSize,
int smallInsSize)
: ISoftClippedRead(name,
alignedRegion,
sequence,
mapQuality,
clippedLength,
smallDelSize,
smallInsSize)
{
}
GenomePosition FiveEndForwardSCRead::GetClipPosition()
{
return alignedRegion.GetStart();
}
std::string FiveEndForwardSCRead::GetType()
{
return "5F";
}
std::string FiveEndForwardSCRead::GetClippedPart()
{
return sequence.substr(0, clippedLength);
}
ChromoFragment FiveEndForwardSCRead::CutFragment(const ChromoFragment &cFragment)
{
if (GetReferenceId() != cFragment.GetReferenceId())
{
error("This fragment cannot be cut because the fragment and the read are not on the same chromosome.");
}
int pos1 = cFragment.GetEndPos();
int pos2 = GetClipPosition().GetPosition();
if (pos2 <= pos1)
{
int removedLen = pos1 - pos2 + 1;
return ChromoFragment(cFragment.GetStart(), cFragment.GetSequence().substr(0, cFragment.GetLength() - removedLen));
}
return cFragment;
}
ChromoFragment FiveEndForwardSCRead::ExtendFragment(const ChromoFragment &cFragment, ISequenceFetcher *pSeqFetcher)
{
int t1 = cFragment.GetEndPos();
int c0 = alignedRegion.GetStartPosition();
int c1 = alignedRegion.GetEndPosition();
int cx = c0 - clippedLength;
if (t1 >= c1)
{
return cFragment;
}
std::string extSeq = (t1 < cx) ?
pSeqFetcher->Fetch(ChromosomeRegion(GetReferenceId(), GetReferenceName(), cx, c1)).GetSequence() :
pSeqFetcher->Fetch(ChromosomeRegion(GetReferenceId(), GetReferenceName(), t1 + 1, c1)).GetSequence();
ChromoFragment newFrag = cFragment;
newFrag.SetSequence(newFrag.GetSequence() + extSeq);
return newFrag;
}
//ChromosomeRegionWithCi FiveEndForwardSCRead::ToRegionWithCi(const AlignmentResult &aResult, int refStartPos)
//{
// GenomePosition clipPosition = GetClipPosition();
// int nHom = aResult.NumOfHomToRight();
// int delta = clippedLength - aResult.GetAlignmentFragment1().GetMatch2().GetEnd() -nHom - 1;
// int endPos = clipPosition.GetPosition();
// int startPos = aResult.GetAlignmentFragment1().GetMatch1().GetEnd() + nHom + refStartPos;
// Interval cInterval;
// if (delta < 0)
// {
// startPos += delta;
// cInterval = Interval(0, abs(delta));
// }
// if (!aResult.HasSingleFragment())
// {
// int f2_l1 = aResult.GetAlignmentFragment2().GetMatch1().Length();
// int f2_d = refSeqPart.length() - f2_l1;
// if (f2_d > 0)
// endPos += f2_d;
// }
// return ChromosomeRegionWithCi(GetReferenceId(),
// GetReferenceName(),
// startPos,
// cInterval,
// endPos,
// cInterval);
//}
bool FiveEndForwardSCRead::IsAlnResultQualified(DoubleFragsAlnResult *pAlnResult, const CallParams &cParams)
{
return IsQualified(pAlnResult->GetAlnFrag1LengthW(), pAlnResult->GetAlnFrag1PercentIdentity(), cParams);
}
CallResult *FiveEndForwardSCRead::ToCallResult(int refStartPos, DoubleFragsAlnResult *pAlnResult)
{
int f1_e_v = pAlnResult->GetAlnFrag1EndV();
int f2_s_v = pAlnResult->GetAlnFrag2StartV();
int startPos = refStartPos + f1_e_v;
int endPos = GetClipPosition().GetPosition();
int f2_l1 = pAlnResult->GetAlnFrag2LengthV();
int f2_d = alignedRegion.GetLength() - f2_l1;
endPos += f2_d;
Interval cInterval;
std::string microIns = "";
int n_bases = pAlnResult->NumOfWBasesBetweenTwoFrags();
if (n_bases >= pAlnResult->NumOfVBasesBetweenTwoFrags())
{
return NULL;
}
std::string v = pAlnResult->GetV();
std::cout << ">>>>>>>>>>>>> " << GetType() << std::endl;
std::cout << "v.length(): " << v.length() << std::endl;
if (n_bases > 0)
{
if (f2_s_v < n_bases)
{
return NULL;
}
std::cout << "f2_s_v - n_bases: " << f2_s_v - n_bases << std::endl;
std::string v1 = v.substr(f2_s_v - n_bases, n_bases);
std::string w = pAlnResult->WBasesBetweenTwoFrags();
int n_mismatch1 = n_bases - NumOfIdenticalChars(v1, w);
std::cout << "f1_e_v + 1: " << f1_e_v + 1 << std::endl;
std::string v2 = v.substr(f1_e_v + 1, n_bases);
if (v2.length() < n_bases)
{
return NULL;
}
//if (w == "TGAGAATTAAATGAAGTCATGTATGGG")
// pAlnResult->PrintAlignment();
int n_mismatch2 = n_bases - NumOfIdenticalChars(v2, w);
if (n_mismatch1 <= 1)
{
endPos -= n_bases;
f2_s_v -= n_bases;
}
else if (n_mismatch2 <= 1)
{
startPos += n_bases;
f1_e_v += n_bases;
}
else
{
microIns = v;
}
if (n_mismatch1 <= 1 && n_mismatch2 <= 1)
{
cInterval.SetEnd(n_bases);
}
}
if (startPos >= endPos)
{
return NULL;
}
std::cout << "f2_s_v: " << f2_s_v << std::endl;
std::string s1 = v.substr(f2_s_v);
std::cout << "f1_e_v + 1: " << f1_e_v + 1 << std::endl;
std::string t1 = v.substr(f1_e_v + 1, s1.length());
int nr = NumOfLongestCommonPrefix(s1, t1);
std::string micro_hom_r = v.substr(f2_s_v, nr);
std::string s2 = v.substr(0, f1_e_v);
std::cout << "f2_s_v - s2.length(): " << f1_e_v + 1 << std::endl;
std::string t2 = v.substr(f2_s_v - s2.length(), s2.length());
int nl = NumOfLongestCommonSuffix(s2, t2);
std::cout << "f1_e_v - nl: " << f1_e_v - nl << std::endl;
std::string micro_hom_l = v.substr(f1_e_v - nl, nl);
//std::cout << -nl << "\t" << nr << std::endl;
cInterval = cInterval.merge(Interval(-nl, nr));
return new CallResult(ChromosomeRegion(GetReferenceId(),
GetReferenceName(),
startPos,
endPos),
cInterval,
cInterval,
microIns,
micro_hom_l + micro_hom_r);
}