/** enqueue a set of variants */ void VariantAlleleNormalizer::add(Variants const & vs) { bool all_homref = true; for(Call const & c : vs.calls) { if(!(c.isHomref() || c.isNocall())) { all_homref = false; break; } } for(auto const & x : vs.ambiguous_alleles) { if(!x.empty()) { all_homref = false; break; } } if (all_homref && !_impl->homref) { #ifdef DEBUG_VARIANTNORMALIZER std::cerr << "Skipping homref variant: " << vs << "\n"; #endif return; } // don't touch import fails if (vs.getInfoFlag("IMPORT_FAIL")) { _impl->buffered_variants.push(vs); return; } Variants nv(vs); size_t tmp = 0; _impl->current_maxpos.resize(std::max(_impl->current_maxpos.size(), nv.calls.size()), tmp); #ifdef DEBUG_VARIANTNORMALIZER std::cerr << "before: " << nv << "\n"; #endif if(_impl->ref_fasta) { int64_t new_start = -1; int64_t new_end = -1; int64_t leftshift_limit = -1; if(_impl->limit >= 0) { leftshift_limit = nv.pos - _impl->limit; } for (size_t rvc = 0; rvc < nv.variation.size(); ++rvc) { int64_t this_leftshift_limit = leftshift_limit; if(nv.chr == _impl->maxpos_chr) { for(size_t j = 0; j < nv.calls.size(); ++j) { for(size_t c = 0; c < nv.calls[j].ngt; ++c) { if(nv.calls[j].gt[c] - 1 == (int)rvc) { this_leftshift_limit = std::max(this_leftshift_limit, _impl->current_maxpos[j]); } } } } #ifdef DEBUG_VARIANTNORMALIZER std::cerr << "leftshift limit for " << nv.variation[rvc] << " is " << this_leftshift_limit << "\n"; #endif leftShift(*(_impl->ref_fasta), nv.chr.c_str(), nv.variation[rvc], this_leftshift_limit); trimLeft(*(_impl->ref_fasta), nv.chr.c_str(), nv.variation[rvc], _impl->refpadding); trimRight(*(_impl->ref_fasta), nv.chr.c_str(), nv.variation[rvc], _impl->refpadding); if(new_start < 0 || new_start > nv.variation[rvc].start) { new_start = nv.variation[rvc].start; } if(new_end < 0 || new_end > nv.variation[rvc].end) { new_end = nv.variation[rvc].end; } } if (new_start > 0 && new_end > 0) { nv.pos = new_start; nv.len = new_end - new_start + 1; // handle insertions if (nv.len == 0) { --nv.pos; nv.len = 1; } } } #ifdef DEBUG_VARIANTNORMALIZER std::cerr << "after: " << nv << "\n"; #endif if(_impl->maxpos_chr != nv.chr) { for(size_t j = 0; j < nv.calls.size(); ++j) { if(!nv.calls[j].isNocall() && !nv.calls[j].isHomref()) { _impl->current_maxpos[j] = nv.pos + nv.len - 1; } } } else { for(size_t j = 0; j < nv.calls.size(); ++j) { if(!nv.calls[j].isNocall() && !nv.calls[j].isHomref()) { _impl->current_maxpos[j] = std::max(nv.pos + nv.len - 1, _impl->current_maxpos[j]); } } } _impl->maxpos_chr = nv.chr; #ifdef DEBUG_VARIANTNORMALIZER std::cerr << "new max-shifting pos on " << _impl->maxpos_chr << " : "; for(size_t s = 0; s < _impl->current_maxpos.size(); ++s) { std::cerr << " s" << s << ": " << _impl->current_maxpos[s] << " "; } std::cerr << "\n"; #endif _impl->buffered_variants.push(nv); }
/** enqueue a set of variants */ void VariantCallsOnly::add(Variants const & v) { if (_impl->buffered_variants.size() > 0 && v.chr == _impl->buffered_variants.back().chr && v.pos < _impl->buffered_variants.back().pos) { error("Variant added out of order at %s:%i / %i", v.chr.c_str(), v.pos, _impl->buffered_variants.back().pos); } // // keep fails if(v.getInfoFlag("IMPORT_FAIL")) { #ifdef DEBUG_VARIANTCALLSONLY std::cerr << "fail-pass-on: " << v << "\n"; #endif _impl->buffered_variants.push_back(v); return; } #ifdef DEBUG_VARIANTCALLSONLY std::cerr << "Variants added: " << v << "\n"; #endif if (v.anyHomref()) { Variants non_hr = v; int n_non_hr = (int) v.calls.size(); for (size_t q = 0; q < v.calls.size(); ++q) { if(v.calls[q].isHomref()) { non_hr.calls[q] = Call(); _impl->homref_ivs.addInterval(v.pos, v.pos + v.len - 1, q); // remember dp if(q >= _impl->homref_dp.size()) { _impl->homref_dp.resize(q+1); } _impl->homref_dp[q].set(v.calls[q].dp, v.pos, v.pos + v.len - 1); --n_non_hr; } else if(v.calls[q].isNocall()) { --n_non_hr; } } if (n_non_hr || non_hr.anyAmbiguous()) { #ifdef DEBUG_VARIANTCALLSONLY std::cerr << "non-hr-add: " << v << "\n"; #endif _impl->buffered_variants.push_back(non_hr); } } else { #ifdef DEBUG_VARIANTCALLSONLY std::cerr << "non-hr-pass-on: " << v << "\n"; #endif _impl->buffered_variants.push_back(v); } }