Optimization: look up diploid genotypes from a static matrix instead of creating them on the fly (with String.format); bases no longer need to be ordered appropriately
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2448 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
57516582c2
commit
b1ac4b81d5
|
|
@ -46,7 +46,7 @@ public class DiploidGenotypeCalculationModel extends JointEstimateGenotypeCalcul
|
||||||
DiploidGenotype refGenotype = DiploidGenotype.createHomGenotype(ref);
|
DiploidGenotype refGenotype = DiploidGenotype.createHomGenotype(ref);
|
||||||
for ( char alt : BaseUtils.BASES ) {
|
for ( char alt : BaseUtils.BASES ) {
|
||||||
if ( alt != ref ) {
|
if ( alt != ref ) {
|
||||||
DiploidGenotype hetGenotype = DiploidGenotype.unorderedValueOf(ref, alt);
|
DiploidGenotype hetGenotype = DiploidGenotype.createDiploidGenotype(ref, alt);
|
||||||
DiploidGenotype homGenotype = DiploidGenotype.createHomGenotype(alt);
|
DiploidGenotype homGenotype = DiploidGenotype.createHomGenotype(alt);
|
||||||
AFMatrixMap.get(alt).setLikelihoods(posteriors[refGenotype.ordinal()], posteriors[hetGenotype.ordinal()], posteriors[homGenotype.ordinal()], sample);
|
AFMatrixMap.get(alt).setLikelihoods(posteriors[refGenotype.ordinal()], posteriors[hetGenotype.ordinal()], posteriors[homGenotype.ordinal()], sample);
|
||||||
}
|
}
|
||||||
|
|
@ -78,7 +78,7 @@ public class DiploidGenotypeCalculationModel extends JointEstimateGenotypeCalcul
|
||||||
// set up some variables we'll need in the loop
|
// set up some variables we'll need in the loop
|
||||||
AlleleFrequencyMatrix matrix = AFMatrixMap.get(alt);
|
AlleleFrequencyMatrix matrix = AFMatrixMap.get(alt);
|
||||||
DiploidGenotype refGenotype = DiploidGenotype.createHomGenotype(ref);
|
DiploidGenotype refGenotype = DiploidGenotype.createHomGenotype(ref);
|
||||||
DiploidGenotype hetGenotype = DiploidGenotype.unorderedValueOf(ref, alt);
|
DiploidGenotype hetGenotype = DiploidGenotype.createDiploidGenotype(ref, alt);
|
||||||
DiploidGenotype homGenotype = DiploidGenotype.createHomGenotype(alt);
|
DiploidGenotype homGenotype = DiploidGenotype.createHomGenotype(alt);
|
||||||
|
|
||||||
for ( String sample : GLs.keySet() ) {
|
for ( String sample : GLs.keySet() ) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package org.broadinstitute.sting.utils.genotype;
|
package org.broadinstitute.sting.utils.genotype;
|
||||||
|
|
||||||
import org.broadinstitute.sting.utils.Utils;
|
import org.broadinstitute.sting.utils.Utils;
|
||||||
|
import org.broadinstitute.sting.utils.BaseUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by IntelliJ IDEA.
|
* Created by IntelliJ IDEA.
|
||||||
|
|
@ -53,28 +54,32 @@ public enum DiploidGenotype {
|
||||||
* @return the diploid genotype
|
* @return the diploid genotype
|
||||||
*/
|
*/
|
||||||
public static DiploidGenotype createHomGenotype(char hom) {
|
public static DiploidGenotype createHomGenotype(char hom) {
|
||||||
hom = Character.toUpperCase(hom);
|
int index = BaseUtils.simpleBaseToBaseIndex(hom);
|
||||||
switch (hom) {
|
if ( index == -1 )
|
||||||
case 'A': return DiploidGenotype.AA;
|
throw new IllegalArgumentException(hom + " is not a valid base character");
|
||||||
case 'C': return DiploidGenotype.CC;
|
return conversionMatrix[index][index];
|
||||||
case 'G': return DiploidGenotype.GG;
|
|
||||||
case 'T': return DiploidGenotype.TT;
|
|
||||||
}
|
|
||||||
throw new IllegalArgumentException(hom + " is not a valid base character");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the genotype, given a string of 2 chars which may not necessarily be ordered correctly
|
* create a diploid genotype, given 2 chars which may not necessarily be ordered correctly
|
||||||
* @param base1 base1
|
* @param base1 base1
|
||||||
* @param base2 base2
|
* @param base2 base2
|
||||||
* @return the diploid genotype
|
* @return the diploid genotype
|
||||||
*/
|
*/
|
||||||
public static DiploidGenotype unorderedValueOf(char base1, char base2) {
|
public static DiploidGenotype createDiploidGenotype(char base1, char base2) {
|
||||||
if ( base1 > base2 ) {
|
int index1 = BaseUtils.simpleBaseToBaseIndex(base1);
|
||||||
char temp = base1;
|
if ( index1 == -1 )
|
||||||
base1 = base2;
|
throw new IllegalArgumentException(base1 + " is not a valid base character");
|
||||||
base2 = temp;
|
int index2 = BaseUtils.simpleBaseToBaseIndex(base2);
|
||||||
}
|
if ( index2 == -1 )
|
||||||
return valueOf(String.format("%c%c", base1, base2));
|
throw new IllegalArgumentException(base2 + " is not a valid base character");
|
||||||
|
return conversionMatrix[index1][index2];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final DiploidGenotype[][] conversionMatrix = {
|
||||||
|
{ DiploidGenotype.AA, DiploidGenotype.AC, DiploidGenotype.AG, DiploidGenotype.AT },
|
||||||
|
{ DiploidGenotype.AC, DiploidGenotype.CC, DiploidGenotype.CG, DiploidGenotype.CT },
|
||||||
|
{ DiploidGenotype.AG, DiploidGenotype.CG, DiploidGenotype.GG, DiploidGenotype.GT },
|
||||||
|
{ DiploidGenotype.AT, DiploidGenotype.CT, DiploidGenotype.GT, DiploidGenotype.TT }
|
||||||
|
};
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue