Permalink
Browse files

Bug fix in reverse trim alleles for the case of mixed records.

  • Loading branch information...
1 parent 1bbb156 commit 2b5dd285503ffc3f4634ec97eb4d628a92a4a1da @rpoplin rpoplin committed Apr 27, 2012
@@ -642,7 +642,7 @@ public static int computeReverseClipping(final List<Allele> unclippedAlleles, fi
boolean stillClipping = true;
while ( stillClipping ) {
- for ( Allele a : unclippedAlleles ) {
+ for ( final Allele a : unclippedAlleles ) {
if ( a.isSymbolic() )
continue;
@@ -160,7 +160,7 @@
*
* @author depristo
*/
-public class VariantContext implements Feature { // to enable tribble intergration
+public class VariantContext implements Feature { // to enable tribble integration
protected CommonInfo commonInfo = null;
public final static double NO_LOG10_PERROR = CommonInfo.NO_LOG10_PERROR;
@@ -377,7 +377,7 @@ public VariantContext subContextFromSample(String sampleName) {
*
* Not currently supported:
*
- * Heterozygous sequencea
+ * Heterozygous sequence
* The term heterozygous is used to specify a region detected by certain methods that do not
* resolve the polymorphism into a specific sequence motif. In these cases, a unique flanking
* sequence must be provided to define a sequence context for the variation.
@@ -620,8 +620,8 @@ public static VariantContext simpleMerge(final GenomeLocParser genomeLocParser,
String key = p.getKey();
// if we don't like the key already, don't go anywhere
if ( ! inconsistentAttributes.contains(key) ) {
- boolean alreadyFound = attributes.containsKey(key);
- Object boundValue = attributes.get(key);
+ final boolean alreadyFound = attributes.containsKey(key);
+ final Object boundValue = attributes.get(key);
final boolean boundIsMissingValue = alreadyFound && boundValue.equals(VCFConstants.MISSING_VALUE_v4);
if ( alreadyFound && ! boundValue.equals(p.getValue()) && ! boundIsMissingValue ) {
@@ -802,36 +802,34 @@ else if (refAllele.isNull())
return inputVC;
}
- public static VariantContext reverseTrimAlleles(VariantContext inputVC) {
+ public static VariantContext reverseTrimAlleles( final VariantContext inputVC ) {
// see if we need to trim common reference base from all alleles
final int trimExtent = AbstractVCFCodec.computeReverseClipping(inputVC.getAlleles(), inputVC.getReference().getDisplayString().getBytes(), 0, true, -1);
- if ( trimExtent <= 0 )
- return inputVC;
+ if ( trimExtent <= 0 || inputVC.getAlleles().size() <= 1 )
+ return inputVC;
final List<Allele> alleles = new ArrayList<Allele>();
- GenotypesContext genotypes = GenotypesContext.create();
-
- Map<Allele, Allele> originalToTrimmedAlleleMap = new HashMap<Allele, Allele>();
+ final GenotypesContext genotypes = GenotypesContext.create();
+ final Map<Allele, Allele> originalToTrimmedAlleleMap = new HashMap<Allele, Allele>();
for (final Allele a : inputVC.getAlleles()) {
if (a.isSymbolic()) {
alleles.add(a);
originalToTrimmedAlleleMap.put(a, a);
} else {
// get bases for current allele and create a new one with trimmed bases
- byte[] newBases = Arrays.copyOfRange(a.getBases(), 0, a.length()-trimExtent);
- Allele trimmedAllele = Allele.create(newBases, a.isReference());
+ final byte[] newBases = Arrays.copyOfRange(a.getBases(), 0, a.length()-trimExtent);
+ final Allele trimmedAllele = Allele.create(newBases, a.isReference());
alleles.add(trimmedAllele);
originalToTrimmedAlleleMap.put(a, trimmedAllele);
}
}
// now we can recreate new genotypes with trimmed alleles
for ( final Genotype genotype : inputVC.getGenotypes() ) {
-
- List<Allele> originalAlleles = genotype.getAlleles();
- List<Allele> trimmedAlleles = new ArrayList<Allele>();
+ final List<Allele> originalAlleles = genotype.getAlleles();
+ final List<Allele> trimmedAlleles = new ArrayList<Allele>();
for ( final Allele a : originalAlleles ) {
if ( a.isCalled() )
trimmedAlleles.add(originalToTrimmedAlleleMap.get(a));
@@ -841,8 +839,7 @@ public static VariantContext reverseTrimAlleles(VariantContext inputVC) {
genotypes.add(Genotype.modifyAlleles(genotype, trimmedAlleles));
}
- final VariantContextBuilder builder = new VariantContextBuilder(inputVC).stop(inputVC.getStart() + alleles.get(0).length());
- return builder.alleles(alleles).genotypes(genotypes).make();
+ return new VariantContextBuilder(inputVC).stop(inputVC.getEnd() - trimExtent).alleles(alleles).genotypes(genotypes).make();
}
public static GenotypesContext stripPLs(GenotypesContext genotypes) {

0 comments on commit 2b5dd28

Please sign in to comment.