|
13 | 13 | #include <htslib/sam.h> |
14 | 14 |
|
15 | 15 | #include "util.h" |
| 16 | +#include "methyl.h" |
16 | 17 |
|
17 | 18 | namespace torali |
18 | 19 | { |
@@ -89,9 +90,9 @@ namespace torali |
89 | 90 | return -1; |
90 | 91 | } |
91 | 92 |
|
92 | | - template<typename TConfig, typename TJunctionMap, typename TReadCountMap> |
| 93 | + template<typename TConfig, typename TJunctionMap, typename TReadCountMap, typename TMethylMap> |
93 | 94 | inline void |
94 | | - genotypeLR(TConfig& c, std::vector<StructuralVariantRecord>& svs, TJunctionMap& jctMap, TReadCountMap& covMap) { |
| 95 | + genotypeLR(TConfig& c, std::vector<StructuralVariantRecord>& svs, TJunctionMap& jctMap, TReadCountMap& covMap, TMethylMap& methylMap) { |
95 | 96 | typedef std::vector<StructuralVariantRecord> TSVs; |
96 | 97 | if (svs.empty()) return; |
97 | 98 |
|
@@ -123,6 +124,12 @@ namespace torali |
123 | 124 | refAlignedReadCount[file_c].resize(svs.size(), 0); |
124 | 125 | } |
125 | 126 |
|
| 127 | + // Methylation |
| 128 | + typedef std::vector<MethylAccum> TSVMethylAccum; |
| 129 | + typedef std::vector<TSVMethylAccum> TFileMethylAccum; |
| 130 | + TFileMethylAccum methylAccum(c.files.size()); |
| 131 | + for (unsigned int file_c = 0; file_c < c.files.size(); ++file_c) methylAccum[file_c].resize(svs.size()); |
| 132 | + |
126 | 133 | // Dump file |
127 | 134 | boost::iostreams::filtering_ostream dumpOut; |
128 | 135 | if (c.hasDumpFile) { |
@@ -221,6 +228,9 @@ namespace torali |
221 | 228 | if (psTag) ps = bam_aux2i(psTag); |
222 | 229 | } |
223 | 230 | std::string sequence; |
| 231 | + std::vector<int8_t> methCall; |
| 232 | + bool methCallBuilt = false; |
| 233 | + bool hasMethyl = false; |
224 | 234 | for(typename TSVSet::const_iterator it = process.begin(); it != process.end(); ++it) { |
225 | 235 | int32_t svid = *it; |
226 | 236 | if ((jctMap[file_c][svid].ref.size() + jctMap[file_c][svid].alt.size()) >= c.maxGenoReadCount) continue; |
@@ -293,19 +303,33 @@ namespace torali |
293 | 303 | // Any confident alignment? |
294 | 304 | if ((scoreRef > 0.6) || (scoreAlt > 0.6)) { |
295 | 305 | if (scoreRef > scoreAlt) { |
296 | | - // Account for reference bias |
297 | | - if (++refAlignedReadCount[file_c][svid] % 2) { |
298 | | - uint32_t rq = scoreRef * 35; |
299 | | - if (rq >= c.minGenoQual) { |
| 306 | + uint32_t rq = scoreRef * 35; |
| 307 | + if (rq >= c.minGenoQual) { |
| 308 | + // Methylation for REF-supporting read |
| 309 | + if (!methCallBuilt) { |
| 310 | + methCallBuilt = true; |
| 311 | + hasMethyl = buildMethylCalls(rec, METHYL_PROB_THRESHOLD, methCall); |
| 312 | + } |
| 313 | + if (hasMethyl) accumulateMethyl(rec, methCall, svs[svid], refIndex, (int32_t)hdr[file_c]->target_len[refIndex], false, candidates, methylAccum[file_c][svid]); |
| 314 | + // Account for reference bias |
| 315 | + if (++refAlignedReadCount[file_c][svid] % 2) { |
300 | 316 | uint8_t qual = (uint8_t) std::min(rq, (uint32_t) rec->core.qual); |
301 | 317 | jctMap[file_c][svid].ref.push_back(qual); |
302 | 318 | if (hp == 1) jctMap[file_c][svid].hp1ref.push_back(qual); |
303 | 319 | else if (hp == 2) jctMap[file_c][svid].hp2ref.push_back(qual); |
304 | 320 | } |
305 | 321 | } |
306 | 322 | } else { |
| 323 | + // Record ALT support |
307 | 324 | uint32_t aq = scoreAlt * 35; |
308 | 325 | if (aq >= c.minGenoQual) { |
| 326 | + // Parse methylation for ALT-supporting read |
| 327 | + if (!methCallBuilt) { |
| 328 | + methCallBuilt = true; |
| 329 | + hasMethyl = buildMethylCalls(rec, METHYL_PROB_THRESHOLD, methCall); |
| 330 | + } |
| 331 | + if (hasMethyl) accumulateMethyl(rec, methCall, svs[svid], refIndex, (int32_t)hdr[file_c]->target_len[refIndex], true, candidates, methylAccum[file_c][svid]); |
| 332 | + // Record ALT support |
309 | 333 | uint8_t qual = (uint8_t) std::min(aq, (uint32_t) rec->core.qual); |
310 | 334 | if (c.hasDumpFile) { |
311 | 335 | std::string svidStr(_addID(svs[svid].svt)); |
@@ -367,6 +391,13 @@ namespace torali |
367 | 391 | // Clean-up chromosome sequence |
368 | 392 | if (seq != NULL) free(seq); |
369 | 393 | } |
| 394 | + // Finalize methylation fractions from accumulated read counts |
| 395 | + for (unsigned int fc = 0; fc < c.files.size(); ++fc) { |
| 396 | + for (uint32_t i = 0; i < svs.size(); ++i) { |
| 397 | + finalizeMethylInfo(methylAccum[fc][i], methylMap[fc][i]); |
| 398 | + } |
| 399 | + } |
| 400 | + |
370 | 401 | // Clean-up |
371 | 402 | fai_destroy(fai); |
372 | 403 | for(unsigned int file_c = 0; file_c < c.files.size(); ++file_c) { |
|
0 commit comments