Permalink
Browse files

Merge /share/home/erik/vcflib

  • Loading branch information...
2 parents 0c80617 + 52f455e commit 1f5eced47a2522a6a62e41f259caadbb8568db47 @ekg ekg committed Mar 23, 2012
Showing with 35 additions and 14 deletions.
  1. +31 −11 Variant.cpp
  2. +1 −1 Variant.h
  3. +3 −2 vcfallelicprimitives.cpp
View
@@ -1332,7 +1332,7 @@ int ploidy(map<int, int>& genotype) {
return i;
}
-map<string, vector<VariantAllele> > Variant::parsedAlternates(bool includePreviousBaseForIndels) {
+map<string, vector<VariantAllele> > Variant::parsedAlternates(bool includePreviousBaseForIndels, bool useMNPs) {
map<string, vector<VariantAllele> > variantAlleles;
@@ -1435,12 +1435,23 @@ map<string, vector<VariantAllele> > Variant::parsedAlternates(bool includePrevio
int mismatchStart = 0;
for (int i = 0; i < refmatch.size(); ++i) {
if (refmatch.at(i) == altmatch.at(i)) {
- if (inmismatch) {
- variants.push_back(VariantAllele(
- refmatch.substr(mismatchStart, i - mismatchStart),
- altmatch.substr(mismatchStart, i - mismatchStart),
- mismatchRefPosStart - paddingLen + position));
- }
+
+ if (inmismatch) {
+ if (refmatch.size() - mismatchStart > 1 && !useMNPs) {
+ for (int j = 0; j < refmatch.size() - mismatchStart; ++j) {
+ variants.push_back(VariantAllele(
+ refmatch.substr(mismatchStart + j, 1),
+ altmatch.substr(mismatchStart + j, 1),
+ mismatchRefPosStart - paddingLen + position + j));
+ }
+ } else {
+ variants.push_back(VariantAllele(
+ refmatch.substr(mismatchStart, refmatch.size() - mismatchStart),
+ altmatch.substr(mismatchStart, refmatch.size() - mismatchStart),
+ mismatchRefPosStart - paddingLen + position));
+ }
+ }
+
inmismatch = false;
} else {
if (!inmismatch) {
@@ -1453,10 +1464,19 @@ map<string, vector<VariantAllele> > Variant::parsedAlternates(bool includePrevio
++altpos;
}
if (inmismatch) {
- variants.push_back(VariantAllele(
- refmatch.substr(mismatchStart, refmatch.size() - mismatchStart),
- altmatch.substr(mismatchStart, refmatch.size() - mismatchStart),
- mismatchRefPosStart - paddingLen + position));
+ if (refmatch.size() - mismatchStart > 1 && !useMNPs) {
+ for (int j = 0; j < refmatch.size() - mismatchStart; ++j) {
+ variants.push_back(VariantAllele(
+ refmatch.substr(mismatchStart + j, 1),
+ altmatch.substr(mismatchStart + j, 1),
+ mismatchRefPosStart - paddingLen + position + j));
+ }
+ } else {
+ variants.push_back(VariantAllele(
+ refmatch.substr(mismatchStart, refmatch.size() - mismatchStart),
+ altmatch.substr(mismatchStart, refmatch.size() - mismatchStart),
+ mismatchRefPosStart - paddingLen + position));
+ }
}
}
View
@@ -179,7 +179,7 @@ class Variant {
// correspond to the correct offest into the allelese vector.
// that is, alleles[0] = ref, alleles[1] = first alternate allele, etc.
map<string, int> altAlleleIndexes; // reverse lookup for alleles
- map<string, vector<VariantAllele> > parsedAlternates(bool includePreviousBaseForIndels = false);
+ map<string, vector<VariantAllele> > parsedAlternates(bool includePreviousBaseForIndels = false, bool useMNPs = false);
map<string, string> extendedAlternates(long int newPosition, long int length);
@@ -25,7 +25,7 @@ int main(int argc, char** argv) {
<< endl
<< "If multiple alleleic primitives (gaps or mismatches) are specified in" << endl
<< "a single VCF record, split the record into multiple lines, but drop all" << endl
- << "INFO fields. Does not handle genotypes (yet)." << endl;
+ << "INFO fields. Does not handle genotypes (yet). MNPs are split into multiple SNPs." << endl;
exit(1);
}
variantFile.open(filename);
@@ -51,7 +51,8 @@ int main(int argc, char** argv) {
// unless we are already at the position !
// take everything which is unique to that allele (records) and append it to the new record
bool includePreviousBaseForIndels = true;
- map<string, vector<VariantAllele> > varAlleles = var.parsedAlternates(includePreviousBaseForIndels);
+ bool useMNPs = false;
+ map<string, vector<VariantAllele> > varAlleles = var.parsedAlternates(includePreviousBaseForIndels, useMNPs);
set<VariantAllele> alleles;
for (map<string, vector<VariantAllele> >::iterator a = varAlleles.begin(); a != varAlleles.end(); ++a) {

0 comments on commit 1f5eced

Please sign in to comment.