Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protected (some) complex variants from left-trimming in normalize #75

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/normalize/01_IN.vcf
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
##INFO=<ID=refseq.positionType,Number=1,Type=String,Description="RefSeq genome type position">
##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">
#CHROM POS ID REF ALT QUAL FILTER INFO
20 61240 . CAT CG 1.01978e-13 . AC=0;AF=0;AN=3 GT:GQ:DP:DPR:RO:QR:AO:QA 0/0/0:136.293:639:639,27:612:24483:27:1091
20 421808 . A ACCA . PASS VC=INDEL;AC=24;AF=0.08;AN=316;refseq.name=NM_144628;refseq.positionType=intron
20 1292033 . C CTTGT . PASS VC=INDEL;AC=28;AF=0.1;AN=276;refseq.name=NM_080489;refseq.positionType=intron
20 1340527 . T TGTC . PASS VC=INDEL;AC=56;AF=0.18;AN=316
Expand Down
2 changes: 1 addition & 1 deletion test/normalize/01_OUT.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ stats: biallelic
total no. multiallelic normalized : 0

total no. variants normalized : 80
total no. variants observed : 194
total no. variants observed : 195
total no. reference observed : 0

Time elapsed <stripped>
Expand Down
1 change: 1 addition & 0 deletions test/normalize/01_OUT.vcf
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">
##INFO=<ID=OLD_VARIANT,Number=.,Type=String,Description="Original chr:pos:ref:alt encoding">
#CHROM POS ID REF ALT QUAL FILTER INFO
20 61240 . CAT CG 1.01978e-13 . AC=0;AF=0;AN=3
20 421805 . T TCCA . PASS VC=INDEL;AC=24;AF=0.08;AN=316;refseq.name=NM_144628;refseq.positionType=intron;OLD_VARIANT=20:421808:A/ACCA
20 1292033 . C CTTGT . PASS VC=INDEL;AC=28;AF=0.1;AN=276;refseq.name=NM_080489;refseq.positionType=intron
20 1340527 . T TGTC . PASS VC=INDEL;AC=56;AF=0.18;AN=316
Expand Down
63 changes: 35 additions & 28 deletions variant_manip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ int32_t VariantManip::is_not_ref_consistent(bcf_hdr_t *h, bcf1_t *v)
}
}
}

if (is_not_consistent)
{
fprintf(stderr, "[%s:%d %s] reference bases not consistent: %s:%d-%d %s(REF) vs %s(FASTA)\n", __FILE__, __LINE__, __FUNCTION__,
chrom, pos0, pos0+rlen-1, vcf_ref, ref);
}
fprintf(stderr, "[%s:%d %s] reference bases not consistent: %s:%d-%d %s(REF) vs %s(FASTA)\n", __FILE__, __LINE__, __FUNCTION__,
chrom, pos0, pos0+rlen-1, vcf_ref, ref);
}

if (ref_len) free(ref);

return is_not_consistent;
}

Expand Down Expand Up @@ -585,33 +585,40 @@ void VariantManip::right_trim_or_left_extend(std::vector<std::string>& alleles,
/**
* Left trims a variant.
*/
void VariantManip::left_trim(std::vector<std::string>& alleles, int32_t& pos1, int32_t& left_trimmed)
{
bool to_left_trim = true;
void VariantManip::left_trim(std::vector<std::string>& alleles, int32_t& pos1, int32_t& left_trimmed) {
bool to_left_trim = true;

while (to_left_trim) {
// Checks if left trimmable.
for (size_t i = 0; i < alleles.size(); ++i) {
if (alleles[i].size() == 1 || alleles[i].at(0) != alleles[0].at(0)) {
to_left_trim = false;
break;
}
}

while (to_left_trim)
{
//checks if left trimmable.
for (size_t i=0; i<alleles.size(); ++i)
{
if (alleles[i].size()==1 || alleles[i].at(0)!=alleles[0].at(0))
{
to_left_trim = false;
break;
}
// The above rule does not prevent the trimming of complex alleles, e.g., CAT -> CG.
// Correct that in the case of two alleles. If allele lengths are different, require that
// they share at least one common base.
if (alleles.size() == 2) {
for (size_t i = 0; i < alleles[0].length() and to_left_trim; ++i) {
for (size_t j = 0; j < alleles[1].length() and to_left_trim; ++j) {
if (alleles[0].at(i) == alleles[0].at(j)) {
to_left_trim = false;
}
}
}
}

if (to_left_trim)
{
for (size_t i=0; i<alleles.size(); ++i)
{
alleles[i].erase(0, 1);
}
if (to_left_trim) {
for (size_t i = 0; i < alleles.size(); ++i) {
alleles[i].erase(0, 1);
}

++pos1;
++left_trimmed;
}
++pos1;
++left_trimmed;
}
}
};

/**
Expand Down Expand Up @@ -769,4 +776,4 @@ void VariantManip::generate_probes(const char* chrom,
//std::cerr << probes[0] << "\n" << probes[1] << "\n";
generate_probes(chrom, pos1, flankLength, currentDiff, length, gald, diff, alleles, probes);
}
}
}