Small refactoring: make Haplotype a public class since it will be soon extended and shared with other callers.

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@4100 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
delangel 2010-08-24 17:52:36 +00:00
parent 43f1fb2380
commit f2b138d975
2 changed files with 82 additions and 40 deletions

View File

@ -34,6 +34,7 @@ import org.broadinstitute.sting.gatk.contexts.variantcontext.*;
import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
import org.broadinstitute.sting.gatk.walkers.annotator.interfaces.*;
import org.broadinstitute.sting.utils.*;
import org.broadinstitute.sting.utils.genotype.Haplotype;
import org.broadinstitute.sting.utils.pileup.*;
import java.util.*;
@ -154,7 +155,7 @@ public class HaplotypeScore implements InfoFieldAnnotation, StandardAnnotation {
// Temp hack to match old implementation's scaling, TBD better behavior
return Arrays.asList(new Haplotype(haplotypeR.bases, 60), new Haplotype(haplotypeA.bases, contextSize));
return Arrays.asList(new Haplotype(haplotypeR.getBasesAsBytes(), 60), new Haplotype(haplotypeA.getBasesAsBytes(), contextSize));
}
else
return null;
@ -218,14 +219,14 @@ public class HaplotypeScore implements InfoFieldAnnotation, StandardAnnotation {
}
else if ((chA == wc)) {
consensusChars[i] = chB;
consensusQuals[i] = haplotypeB.quals[i];
consensusQuals[i] = haplotypeB.getQuals()[i];
}
else if ((chB == wc)){
consensusChars[i] = chA;
consensusQuals[i] = haplotypeA.quals[i];
consensusQuals[i] = haplotypeA.getQuals()[i];
} else {
consensusChars[i] = chA;
consensusQuals[i] = haplotypeA.quals[i]+haplotypeB.quals[i];
consensusQuals[i] = haplotypeA.getQuals()[i]+haplotypeB.getQuals()[i];
}
@ -289,7 +290,7 @@ public class HaplotypeScore implements InfoFieldAnnotation, StandardAnnotation {
if ( baseOffset >= read.getReadLength() )
break;
byte haplotypeBase = haplotype.bases[i];
byte haplotypeBase = haplotype.getBasesAsBytes()[i];
byte readBase = read.getReadBases()[baseOffset];
boolean matched = BaseUtils.basesAreEqual(readBase, haplotypeBase );
@ -314,41 +315,6 @@ public class HaplotypeScore implements InfoFieldAnnotation, StandardAnnotation {
FLAT_BASE_PRIORS[i] = Math.log10(1.0 / BaseUtils.Base.values().length);
}
private class Haplotype {
byte[] bases = null;
double[] quals = null;
/**
* Create a simple consensus sequence with provided bases and a uniform quality over all bases of qual
*
* @param bases bases
* @param qual qual
*/
Haplotype(byte[] bases, int qual) {
this.bases = bases;
quals = new double[bases.length];
Arrays.fill(quals, (double)qual);
}
Haplotype(byte[] bases, double[] quals) {
this.bases = bases;
this.quals = quals;
}
Haplotype(String bases, double[] quals) {
this.bases = bases.getBytes();
this.quals = quals;
}
public String toString() { return new String(this.bases); }
double getQualitySum() {
double s = 0;
for (int k=0; k < bases.length; k++) {
s += quals[k];
}
return s;
}
}
public List<String> getKeyNames() { return Arrays.asList("HaplotypeScore"); }
public List<VCFInfoHeaderLine> getDescriptions() { return Arrays.asList(new VCFInfoHeaderLine("HaplotypeScore", 1, VCFHeaderLineType.Float, "Consistency of the site with two (and only two) segregating haplotypes")); }

View File

@ -0,0 +1,76 @@
/*
* Copyright (c) 2010, The Broad Institute
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
package org.broadinstitute.sting.utils.genotype;
import java.util.Arrays;
public class Haplotype {
protected byte[] bases = null;
protected double[] quals = null;
/**
* Create a simple consensus sequence with provided bases and a uniform quality over all bases of qual
*
* @param bases bases
* @param qual qual
*/
public Haplotype(byte[] bases, int qual) {
this.bases = bases;
quals = new double[bases.length];
Arrays.fill(quals, (double)qual);
}
public Haplotype(byte[] bases, double[] quals) {
this.bases = bases;
this.quals = quals;
}
public Haplotype(String bases, double[] quals) {
this.bases = bases.getBytes();
this.quals = quals;
}
public Haplotype(byte[] bases) {
this(bases, 0);
}
public String toString() { return new String(this.bases); }
public double getQualitySum() {
double s = 0;
for (int k=0; k < bases.length; k++) {
s += quals[k];
}
return s;
}
public double[] getQuals() {
return quals;
}
public byte[] getBasesAsBytes() {
return bases;
}
}