From 542d8176880da7bacbfa1278d6b43901aeae2867 Mon Sep 17 00:00:00 2001 From: aaron Date: Tue, 15 Sep 2009 21:42:03 +0000 Subject: [PATCH] more cleanup git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1631 348d0f76-0448-11de-a6fe-93d51630548a --- .../varianteval/CallableBasesAnalysis.java | 8 ++-- .../varianteval/GenotypeConcordance.java | 5 +- .../sting/utils/genotype/BasicGenotype.java | 46 ++++++++++++------- .../sting/utils/genotype/BasicVariation.java | 34 +++++++++++--- .../sting/utils/genotype/DiploidGenotype.java | 2 +- .../utils/genotype/DiploidGenotypeTest.java | 8 ++-- 6 files changed, 67 insertions(+), 36 deletions(-) diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/varianteval/CallableBasesAnalysis.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/varianteval/CallableBasesAnalysis.java index aa6b7acdc..c11825254 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/varianteval/CallableBasesAnalysis.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/varianteval/CallableBasesAnalysis.java @@ -3,10 +3,9 @@ package org.broadinstitute.sting.playground.gatk.walkers.varianteval; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.utils.genotype.DiploidGenotype; +import org.broadinstitute.sting.utils.genotype.Genotype; import org.broadinstitute.sting.utils.genotype.VariantBackedByGenotype; import org.broadinstitute.sting.utils.genotype.Variation; -import org.broadinstitute.sting.utils.genotype.Genotype; -import org.broadinstitute.sting.utils.Utils; import java.util.ArrayList; import java.util.List; @@ -23,7 +22,6 @@ import java.util.List; public class CallableBasesAnalysis extends BasicVariantAnalysis implements GenotypeAnalysis { long all_bases = 0; long all_calls = 0; - //final static double[] Qthresholds = { 10, 20, 30, 40, 50, 100, 200, 500, 1000 }; final static double[] thresholds = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 50, 100}; long[] discoverable_bases = new long[thresholds.length]; long[] genotypable_bases = new long[thresholds.length]; @@ -64,14 +62,14 @@ public class CallableBasesAnalysis extends BasicVariantAnalysis implements Genot // we actually have a record here if (!(eval instanceof VariantBackedByGenotype)) { // evaluation record isn't a genotype, die! - throw new RuntimeException("Evaluation track isn't an Genotype!"); + throw new RuntimeException("Evaluation track isn't backed by a Genotype!"); } all_calls++; // For every threshold, updated discoverable and callable for (int i = 0; i < thresholds.length; i++) { double threshold = thresholds[i]; - DiploidGenotype g = DiploidGenotype.valueOf(Utils.dupString(ref, 2)); + DiploidGenotype g = DiploidGenotype.createHomGenotype(ref); Genotype genotype = ((VariantBackedByGenotype) eval).getGenotype(g); // update discoverable if (eval.isSNP() && eval.getNegLog10PError() >= threshold) diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/varianteval/GenotypeConcordance.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/varianteval/GenotypeConcordance.java index c1331a6ef..f33500acf 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/varianteval/GenotypeConcordance.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/varianteval/GenotypeConcordance.java @@ -2,9 +2,8 @@ package org.broadinstitute.sting.playground.gatk.walkers.varianteval; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; -import org.broadinstitute.sting.utils.genotype.DiploidGenotype; import org.broadinstitute.sting.utils.StingException; -import org.broadinstitute.sting.utils.Utils; +import org.broadinstitute.sting.utils.genotype.DiploidGenotype; import org.broadinstitute.sting.utils.genotype.VariantBackedByGenotype; import org.broadinstitute.sting.utils.genotype.Variation; @@ -50,7 +49,7 @@ public class GenotypeConcordance extends BasicVariantAnalysis implements Genotyp if ((chip != null && !(chip instanceof VariantBackedByGenotype) || (eval != null && !(eval instanceof VariantBackedByGenotype)))) throw new StingException("Failure: trying to analyze genotypes of non-genotype data"); - DiploidGenotype g = DiploidGenotype.valueOf(Utils.dupString(ref, 2)); + DiploidGenotype g = DiploidGenotype.createHomGenotype(ref); int truthIndex, callIndex; if (chip == null) truthIndex = UNKNOWN; diff --git a/java/src/org/broadinstitute/sting/utils/genotype/BasicGenotype.java b/java/src/org/broadinstitute/sting/utils/genotype/BasicGenotype.java index 7630acd6a..4e034626b 100644 --- a/java/src/org/broadinstitute/sting/utils/genotype/BasicGenotype.java +++ b/java/src/org/broadinstitute/sting/utils/genotype/BasicGenotype.java @@ -4,26 +4,38 @@ import org.broadinstitute.sting.utils.GenomeLoc; /** - * - * @author aaron - * - * Class BasicGenotype - * - * represents a basic genotype object + * @author aaron + *

+ * Class BasicGenotype + *

+ * represents a basic genotype object. That means that is + * an implementation for a basic genotype call, given the genotype + * string, the ref base, the confidence score, and the location. This + * class currently only represents point genotypes, not indels */ public class BasicGenotype implements Genotype { // the genotype string private String mGenotype; + + // our location private GenomeLoc mLocation; + + // the reference base. private char mRef; - private double mNetLog10PError; + + // the confidence score + private double mNegLog10PError; /** - * create a basic genotype - * @param genotype + * create a basic genotype, given the following fields + * + * @param location the genomic location + * @param genotype the genotype, as a string, where ploidy = string.length + * @param ref the reference base as a char + * @param negLog10PError the confidence score */ - public BasicGenotype(GenomeLoc location, String genotype, char ref, double netLog10PError) { - mNetLog10PError = netLog10PError; + public BasicGenotype(GenomeLoc location, String genotype, char ref, double negLog10PError) { + mNegLog10PError = negLog10PError; mGenotype = genotype; mLocation = location; mRef = ref; @@ -32,15 +44,15 @@ public class BasicGenotype implements Genotype { /** * get the -1 * (log 10 of the error value) * - * @return the log based error estimate + * @return the negitive log based error estimate */ @Override public double getNegLog10PError() { - return mNetLog10PError; + return mNegLog10PError; } /** - * get the bases that represent this + * get the bases that represent this genotype * * @return the bases, as a string */ @@ -60,7 +72,7 @@ public class BasicGenotype implements Genotype { } /** - * Returns true if both observed alleles are the same (regardless of whether they are ref or alt) + * Returns true if both observed allele bases are the same (regardless of whether they are ref or alt) * * @return true if we're homozygous, false otherwise */ @@ -79,7 +91,7 @@ public class BasicGenotype implements Genotype { } /** - * Returns true if observed alleles differ (regardless of whether they are ref or alt) + * Returns true if observed allele bases differ (regardless of whether they are ref or alt) * * @return true if we're het, false otherwise */ @@ -138,6 +150,6 @@ public class BasicGenotype implements Genotype { @Override public Variation toVariation() { if (!isVariant(this.mRef)) throw new IllegalStateException("this genotype is not a variant"); - return new BasicVariation(this.getBases(),String.valueOf(mRef),this.getBases().length(),mLocation,mNetLog10PError); + return new BasicVariation(this.getBases(), String.valueOf(mRef), this.getBases().length(), mLocation, mNegLog10PError); } } diff --git a/java/src/org/broadinstitute/sting/utils/genotype/BasicVariation.java b/java/src/org/broadinstitute/sting/utils/genotype/BasicVariation.java index 917788749..0f3f77967 100644 --- a/java/src/org/broadinstitute/sting/utils/genotype/BasicVariation.java +++ b/java/src/org/broadinstitute/sting/utils/genotype/BasicVariation.java @@ -3,23 +3,31 @@ package org.broadinstitute.sting.utils.genotype; import org.broadinstitute.sting.utils.GenomeLoc; /** - * Created by IntelliJ IDEA. - * User: aaronmckenna + * User: aaron * Date: Sep 9, 2009 * Time: 9:32:34 PM *

- * a basic implementation of variant + * a basic implementation of the Variation interface. */ public class BasicVariation implements Variation { + // the bases that make up this variant protected final String mBases; + + // the reference base protected final String mRef; + + // the length of the event, 0 for a SNP, negitive for deletions, positive for insertions protected final int mLength; + + // the location on the genome of the event protected final GenomeLoc mLocation; + + // our confidence in this event, and a -(log10(Error)) protected final double mConfidence; /** - * the constructor + * create a basic variation, given the following parameters: * * @param bases the bases that this variant represents * @param reference the reference bases @@ -34,11 +42,21 @@ public class BasicVariation implements Variation { mConfidence = confidence; } + /** + * we don't know the minor allele freq. is this implementation + * + * @return -1.0. If the freq is less than zero it means we don't know + */ @Override public double getNonRefAlleleFrequency() { return -1.0; } + /** + * get the type of variation we are + * + * @return VARIANT_TYPE + */ @Override public VARIANT_TYPE getType() { if (mLength > 0) return VARIANT_TYPE.INDEL; @@ -84,7 +102,7 @@ public class BasicVariation implements Variation { @Override public boolean isReference() { - if (mLength != 0) return true; + if (mLength != 0) return false; int refIndex = 0; for (char c : mBases.toCharArray()) { if (mRef.charAt(refIndex) != c) return false; @@ -93,7 +111,7 @@ public class BasicVariation implements Variation { } /** - * are we an insertion or a deletion? yes, then return true. No? Well, false it is. + * are we an insertion or a deletion? yes, then return true. * * @return true if we're an insertion or deletion */ @@ -111,6 +129,8 @@ public class BasicVariation implements Variation { @Override public char getAlternativeBaseForSNP() { if (!this.isSNP()) throw new IllegalStateException("we're not a SNP"); + + // we know that if we're a snp, the reference is a single base, so charAt(0) is safe if (getAlternateBases().charAt(0) == this.getReference().charAt(0)) return getAlternateBases().charAt(1); return getAlternateBases().charAt(0); @@ -124,6 +144,8 @@ public class BasicVariation implements Variation { @Override public char getReferenceForSNP() { if (!this.isSNP()) throw new IllegalStateException("we're not a SNP"); + + // we know that if we're a snp, the reference is a single base, so charAt(0) is safe if (getAlternateBases().charAt(0) == this.getReference().charAt(0)) return getAlternateBases().charAt(0); return getAlternateBases().charAt(1); diff --git a/java/src/org/broadinstitute/sting/utils/genotype/DiploidGenotype.java b/java/src/org/broadinstitute/sting/utils/genotype/DiploidGenotype.java index eb5b86ea5..9609af671 100755 --- a/java/src/org/broadinstitute/sting/utils/genotype/DiploidGenotype.java +++ b/java/src/org/broadinstitute/sting/utils/genotype/DiploidGenotype.java @@ -58,7 +58,7 @@ public enum DiploidGenotype { * @param hom the character to turn into a hom genotype, i.e. if it is A, then returned will be AA * @return the diploid genotype */ - public static DiploidGenotype createGenotype(char hom) { + public static DiploidGenotype createHomGenotype(char hom) { return DiploidGenotype.valueOf((String.valueOf(hom) + String.valueOf(hom)).toUpperCase()); } } \ No newline at end of file diff --git a/java/test/org/broadinstitute/sting/utils/genotype/DiploidGenotypeTest.java b/java/test/org/broadinstitute/sting/utils/genotype/DiploidGenotypeTest.java index 6297e6d5e..47ac9be52 100644 --- a/java/test/org/broadinstitute/sting/utils/genotype/DiploidGenotypeTest.java +++ b/java/test/org/broadinstitute/sting/utils/genotype/DiploidGenotypeTest.java @@ -83,19 +83,19 @@ public class DiploidGenotypeTest extends BaseTest { @Test public void testCreateGenotype() { char ref = 'A'; - DiploidGenotype g = DiploidGenotype.createGenotype(ref); + DiploidGenotype g = DiploidGenotype.createHomGenotype(ref); Assert.assertTrue("AA".equals(g.toString())); ref = 'a'; - g = DiploidGenotype.createGenotype(ref); + g = DiploidGenotype.createHomGenotype(ref); Assert.assertTrue("AA".equals(g.toString())); ref = 't'; - g = DiploidGenotype.createGenotype(ref); + g = DiploidGenotype.createHomGenotype(ref); Assert.assertTrue("TT".equals(g.toString())); ref = 'T'; - g = DiploidGenotype.createGenotype(ref); + g = DiploidGenotype.createHomGenotype(ref); Assert.assertTrue("TT".equals(g.toString())); }