A few more char -> byte cleanups

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@3398 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
depristo 2010-05-20 00:02:06 +00:00
parent 8a725b6c93
commit 5abac5c057
9 changed files with 47 additions and 36 deletions

View File

@ -53,6 +53,9 @@ public class ReferenceContext {
*/ */
private byte[] bases; private byte[] bases;
/**
* A cache of the bases converted to characters for walkers not yet using byte[] interface
*/
private char[] basesAsCharCached = null; private char[] basesAsCharCached = null;
/** /**
@ -64,6 +67,7 @@ public class ReferenceContext {
this( locus, locus, new byte[] { base } ); this( locus, locus, new byte[] { base } );
} }
// todo -- this really should take the referenceview as an option and only grab the bases if necessary
public ReferenceContext( GenomeLoc locus, GenomeLoc window, byte[] bases ) { public ReferenceContext( GenomeLoc locus, GenomeLoc window, byte[] bases ) {
// if( !window.containsP(locus) ) // if( !window.containsP(locus) )
// throw new StingException("Invalid locus or window; window does not contain locus"); // throw new StingException("Invalid locus or window; window does not contain locus");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2010. * Copyright (c) 2010, The Broad Institute
* *
* Permission is hereby granted, free of charge, to any person * Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation * obtaining a copy of this software and associated documentation
@ -12,15 +12,14 @@
* *
* The above copyright notice and this permission notice shall be * The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software. * included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. * OTHER DEALINGS IN THE SOFTWARE.
*/ */
package org.broadinstitute.sting.gatk.walkers.genotyper; package org.broadinstitute.sting.gatk.walkers.genotyper;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2010. * Copyright (c) 2010, The Broad Institute
* *
* Permission is hereby granted, free of charge, to any person * Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation * obtaining a copy of this software and associated documentation
@ -12,15 +12,14 @@
* *
* The above copyright notice and this permission notice shall be * The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software. * included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. * OTHER DEALINGS IN THE SOFTWARE.
*/ */
package org.broadinstitute.sting.gatk.walkers.genotyper; package org.broadinstitute.sting.gatk.walkers.genotyper;

View File

@ -73,7 +73,7 @@ public class DiploidGenotypePriors {
* @param ref * @param ref
* @param heterozygosity * @param heterozygosity
*/ */
public DiploidGenotypePriors(char ref, double heterozygosity, boolean dontPolarize) { public DiploidGenotypePriors(byte ref, double heterozygosity, boolean dontPolarize) {
if ( dontPolarize ) { if ( dontPolarize ) {
double[] vals = heterozygosity2DiploidProbabilities(heterozygosity); double[] vals = heterozygosity2DiploidProbabilities(heterozygosity);
priors = getReferenceIndependentPriors(ref, vals[0], vals[1], vals[2]); priors = getReferenceIndependentPriors(ref, vals[0], vals[1], vals[2]);
@ -90,7 +90,7 @@ public class DiploidGenotypePriors {
* @param heterozygosity * @param heterozygosity
* @param probOfTriStateGenotype The prob of seeing a true B/C het when the reference is A * @param probOfTriStateGenotype The prob of seeing a true B/C het when the reference is A
*/ */
public DiploidGenotypePriors(char ref, double heterozygosity, double probOfTriStateGenotype) { public DiploidGenotypePriors(byte ref, double heterozygosity, double probOfTriStateGenotype) {
priors = getReferencePolarizedPriors(ref, heterozygosity, probOfTriStateGenotype); priors = getReferencePolarizedPriors(ref, heterozygosity, probOfTriStateGenotype);
} }
@ -226,7 +226,7 @@ public class DiploidGenotypePriors {
* @param heterozyosity * @param heterozyosity
* @param pRefError * @param pRefError
*/ */
public static double[] getReferencePolarizedPriors(char ref, double heterozyosity, double pRefError ) { public static double[] getReferencePolarizedPriors(byte ref, double heterozyosity, double pRefError ) {
if ( ! MathUtils.isBounded(pRefError, 0.0, 0.01) ) { if ( ! MathUtils.isBounded(pRefError, 0.0, 0.01) ) {
throw new RuntimeException(String.format("BUG: p Reference error is out of bounds (0.0 - 0.01) is allow range %f", pRefError)); throw new RuntimeException(String.format("BUG: p Reference error is out of bounds (0.0 - 0.01) is allow range %f", pRefError));
} }
@ -276,7 +276,7 @@ public class DiploidGenotypePriors {
* @param priorHomVar * @param priorHomVar
*/ */
@Deprecated @Deprecated
public static double[] getReferenceIndependentPriors(char ref, double priorHomRef, double priorHet, double priorHomVar ) { public static double[] getReferenceIndependentPriors(byte ref, double priorHomRef, double priorHet, double priorHomVar ) {
if ((priorHomRef + priorHet + priorHomVar) != 1) { if ((priorHomRef + priorHet + priorHomVar) != 1) {
throw new RuntimeException(String.format("Prior probabilities don't sum to one => %f, %f, %f", priorHomRef, priorHet, priorHomVar)); throw new RuntimeException(String.format("Prior probabilities don't sum to one => %f, %f, %f", priorHomRef, priorHet, priorHomVar));
} }
@ -284,7 +284,7 @@ public class DiploidGenotypePriors {
double[] priors = new double[DiploidGenotype.values().length]; double[] priors = new double[DiploidGenotype.values().length];
for ( DiploidGenotype g : DiploidGenotype.values() ) { for ( DiploidGenotype g : DiploidGenotype.values() ) {
int nRefBases = MathUtils.countOccurrences(ref, g.toString()); int nRefBases = MathUtils.countOccurrences((char)ref, g.toString()); // todo -- fixme
double log10POfG = 0.0; double log10POfG = 0.0;
switch ( nRefBases ) { switch ( nRefBases ) {

View File

@ -215,7 +215,7 @@ public class UnifiedGenotyperEngine {
if ( stratifiedContexts == null ) if ( stratifiedContexts == null )
return null; return null;
DiploidGenotypePriors priors = new DiploidGenotypePriors(ref, UAC.heterozygosity, DiploidGenotypePriors.PROB_OF_REFERENCE_ERROR); DiploidGenotypePriors priors = new DiploidGenotypePriors((byte)ref, UAC.heterozygosity, DiploidGenotypePriors.PROB_OF_REFERENCE_ERROR);
call = gcm.get().callLocus(tracker, ref, rawContext.getLocation(), stratifiedContexts, priors); call = gcm.get().callLocus(tracker, ref, rawContext.getLocation(), stratifiedContexts, priors);
// annotate the call, if possible // annotate the call, if possible

View File

@ -638,19 +638,19 @@ public class VariantEvalWalker extends RodWalker<Integer, Integer> {
} }
} }
private String formatKeyword(String keyWord) { // private String formatKeyword(String keyWord) {
//System.out.printf("keyword %s%n", keyWord); // //System.out.printf("keyword %s%n", keyWord);
//
StringBuilder s = new StringBuilder(); // StringBuilder s = new StringBuilder();
int i = 0; // int i = 0;
for ( String part : keyWord.split("\\.") ) { // for ( String part : keyWord.split("\\.") ) {
//System.out.printf("part %s %d%n", part, nameSizes[i]); // //System.out.printf("part %s %d%n", part, nameSizes[i]);
s.append(String.format("%" + nameSizes[i] + "s ", part)); // s.append(String.format("%" + nameSizes[i] + "s ", part));
i++; // i++;
} // }
//
return s.toString(); // return s.toString();
} // }
public void onTraversalDone(Integer result) { public void onTraversalDone(Integer result) {
// our report mashaller // our report mashaller

View File

@ -68,7 +68,7 @@ public class GATKPaperGenotyper extends LocusWalker<SimpleCall, Integer> impleme
if (ref.getBase() == 'N' || ref.getBase() == 'n') return null; // we don't deal with the N ref base case if (ref.getBase() == 'N' || ref.getBase() == 'n') return null; // we don't deal with the N ref base case
ReadBackedPileup pileup = context.getPileup(); ReadBackedPileup pileup = context.getPileup();
double likelihoods[] = DiploidGenotypePriors.getReferencePolarizedPriors(ref.getBaseAsChar(), double likelihoods[] = DiploidGenotypePriors.getReferencePolarizedPriors(ref.getBase(),
DiploidGenotypePriors.HUMAN_HETEROZYGOSITY, DiploidGenotypePriors.HUMAN_HETEROZYGOSITY,
0.01); 0.01);
// get the bases and qualities from the pileup // get the bases and qualities from the pileup

View File

@ -47,22 +47,31 @@ public enum DiploidGenotype {
GT ('G', 'T'), GT ('G', 'T'),
TT ('T', 'T'); TT ('T', 'T');
public char base1, base2; public byte base1, base2;
private DiploidGenotype(char base1, char base2) { private DiploidGenotype(char base1, char base2) {
this((byte)base1, (byte)base2);
}
private DiploidGenotype(byte base1, byte base2) {
this.base1 = base1; this.base1 = base1;
this.base2 = base2; this.base2 = base2;
} }
public boolean isHomRef(char r) { public boolean isHomRef(byte r) {
return isHom() && r == base1; return isHom() && r == base1;
} }
public boolean isHomVar(char r) { public boolean isHomVar(byte r) {
return isHom() && r != base1; return isHom() && r != base1;
} }
public boolean isHetRef(char r) { public boolean isHetRef(byte r) {
return MathUtils.countOccurrences(r, this.toString()) == 1; if ( base1 == r )
return r != base2;
else
return base2 == r;
//return MathUtils.countOccurrences(r, this.toString()) == 1;
} }
public boolean isHom() { public boolean isHom() {

View File

@ -70,9 +70,9 @@ public class GenotypeLikelihoodsUnitTest extends BaseTest {
private void testGenotypePriors(char ref, double h, double[] array) { private void testGenotypePriors(char ref, double h, double[] array) {
for ( DiploidGenotype g : DiploidGenotype.values() ) { for ( DiploidGenotype g : DiploidGenotype.values() ) {
double val = 0.0; double val = 0.0;
if ( g.isHomRef(ref) ) val = DiploidGenotypePriors.heterozygosity2HomRefProbability(h); if ( g.isHomRef((byte)ref) ) val = DiploidGenotypePriors.heterozygosity2HomRefProbability(h);
if ( g.isHet() ) val = DiploidGenotypePriors.heterozygosity2HetProbability(h); if ( g.isHet() ) val = DiploidGenotypePriors.heterozygosity2HetProbability(h);
if ( g.isHomVar(ref) ) val = DiploidGenotypePriors.heterozygosity2HomVarProbability(h); if ( g.isHomVar((byte)ref) ) val = DiploidGenotypePriors.heterozygosity2HomVarProbability(h);
val = log10(val); val = log10(val);
double e = array[g.ordinal()]; double e = array[g.ordinal()];
@ -99,7 +99,7 @@ public class GenotypeLikelihoodsUnitTest extends BaseTest {
} }
private void testPolarizedGenotypePriors(char ref, double h, double pRefError, double[] array) { private void testPolarizedGenotypePriors(char ref, double h, double pRefError, double[] array) {
DiploidGenotypePriors priors = new DiploidGenotypePriors(ref, h, pRefError); DiploidGenotypePriors priors = new DiploidGenotypePriors((byte)ref, h, pRefError);
for ( DiploidGenotype g : DiploidGenotype.values() ) { for ( DiploidGenotype g : DiploidGenotype.values() ) {
double val = Math.pow(10, priors.getPrior(g)); double val = Math.pow(10, priors.getPrior(g));
double e = array[g.ordinal()]; double e = array[g.ordinal()];