From 5cdbdd9e5bfd60f3509a318ed5e2be75d1fb60f8 Mon Sep 17 00:00:00 2001 From: ebanks Date: Thu, 29 Oct 2009 13:27:37 +0000 Subject: [PATCH] now that the design is stable, pull the setReference and setLocation methods back out of Genotype and stick them into constructors of implementing classes git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1931 348d0f76-0448-11de-a6fe-93d51630548a --- .../genotyper/EMGenotypeCalculationModel.java | 6 +----- .../JointEstimateGenotypeCalculationModel.java | 5 +---- .../PointEstimateGenotypeCalculationModel.java | 4 +--- .../sting/utils/genotype/BasicGenotype.java | 10 ---------- .../sting/utils/genotype/Genotype.java | 12 ------------ .../utils/genotype/GenotypeWriterFactory.java | 9 +++++---- .../utils/genotype/geli/GeliGenotypeCall.java | 14 ++++---------- .../utils/genotype/glf/GLFGenotypeCall.java | 16 +++++----------- .../utils/genotype/vcf/VCFGenotypeCall.java | 14 ++++---------- .../sting/utils/genotype/glf/GLFWriterTest.java | 3 +-- 10 files changed, 22 insertions(+), 71 deletions(-) diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/EMGenotypeCalculationModel.java b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/EMGenotypeCalculationModel.java index 34b414f40..c91e78f70 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/EMGenotypeCalculationModel.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/EMGenotypeCalculationModel.java @@ -54,12 +54,8 @@ public abstract class EMGenotypeCalculationModel extends GenotypeCalculationMode for ( String sample : GLs.keySet() ) { // create the call - Genotype call = GenotypeWriterFactory.createSupportedCall(OUTPUT_FORMAT); - call.setReference(ref); - - // get the context AlignmentContext context = contexts.get(sample).getContext(StratifiedContext.OVERALL); - call.setLocation(context.getLocation()); + Genotype call = GenotypeWriterFactory.createSupportedCall(OUTPUT_FORMAT, ref, context.getLocation()); if ( call instanceof ReadBacked ) { ((ReadBacked)call).setReads(context.getReads()); diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/JointEstimateGenotypeCalculationModel.java b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/JointEstimateGenotypeCalculationModel.java index 40d68e3f1..b6427edb0 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/JointEstimateGenotypeCalculationModel.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/JointEstimateGenotypeCalculationModel.java @@ -321,11 +321,8 @@ public class JointEstimateGenotypeCalculationModel extends GenotypeCalculationMo for ( String sample : GLs.keySet() ) { // create the call - Genotype call = GenotypeWriterFactory.createSupportedCall(OUTPUT_FORMAT); - call.setReference(ref); - AlignmentContext context = contexts.get(sample).getContext(StratifiedContext.OVERALL); - call.setLocation(context.getLocation()); + Genotype call = GenotypeWriterFactory.createSupportedCall(OUTPUT_FORMAT, ref, context.getLocation()); if ( call instanceof ReadBacked ) { ((ReadBacked)call).setReads(context.getReads()); diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/PointEstimateGenotypeCalculationModel.java b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/PointEstimateGenotypeCalculationModel.java index 2953febbf..8be399acc 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/PointEstimateGenotypeCalculationModel.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/PointEstimateGenotypeCalculationModel.java @@ -44,9 +44,7 @@ public class PointEstimateGenotypeCalculationModel extends EMGenotypeCalculation // create the genotype call object // create the call - Genotype call = GenotypeWriterFactory.createSupportedCall(OUTPUT_FORMAT); - call.setReference(ref); - call.setLocation(context.getLocation()); + Genotype call = GenotypeWriterFactory.createSupportedCall(OUTPUT_FORMAT, ref, context.getLocation()); Pair discoveryGL = getSingleSampleLikelihoods(ref, sampleContext, priors, StratifiedContext.OVERALL); diff --git a/java/src/org/broadinstitute/sting/utils/genotype/BasicGenotype.java b/java/src/org/broadinstitute/sting/utils/genotype/BasicGenotype.java index f72076dee..2082d127a 100644 --- a/java/src/org/broadinstitute/sting/utils/genotype/BasicGenotype.java +++ b/java/src/org/broadinstitute/sting/utils/genotype/BasicGenotype.java @@ -113,11 +113,6 @@ public class BasicGenotype implements Genotype { return mLocation; } - // set the location - public void setLocation(GenomeLoc loc) { - mLocation = loc; - } - /** * returns true if the genotype is a point genotype, false if it's a indel / deletion * @@ -150,11 +145,6 @@ public class BasicGenotype implements Genotype { return mRef; } - // set the reference base - public void setReference(char refBase) { - mRef = Character.toUpperCase(refBase); - } - /** * return this genotype as a variant * diff --git a/java/src/org/broadinstitute/sting/utils/genotype/Genotype.java b/java/src/org/broadinstitute/sting/utils/genotype/Genotype.java index d7f6e8cd4..cc0ad15be 100644 --- a/java/src/org/broadinstitute/sting/utils/genotype/Genotype.java +++ b/java/src/org/broadinstitute/sting/utils/genotype/Genotype.java @@ -52,12 +52,6 @@ public interface Genotype { */ public GenomeLoc getLocation(); - /** - * set the location. - * @param loc the location - */ - public void setLocation(GenomeLoc loc); - /** * returns true if the genotype is a point genotype, false if it's a indel / deletion * @@ -80,12 +74,6 @@ public interface Genotype { */ public char getReference(); - /** - * set the reference base. - * @param ref the ref base - */ - public void setReference(char ref); - /** * return this genotype as a variant * diff --git a/java/src/org/broadinstitute/sting/utils/genotype/GenotypeWriterFactory.java b/java/src/org/broadinstitute/sting/utils/genotype/GenotypeWriterFactory.java index cf5668515..c46df69cc 100644 --- a/java/src/org/broadinstitute/sting/utils/genotype/GenotypeWriterFactory.java +++ b/java/src/org/broadinstitute/sting/utils/genotype/GenotypeWriterFactory.java @@ -1,6 +1,7 @@ package org.broadinstitute.sting.utils.genotype; import net.sf.samtools.SAMFileHeader; +import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.genotype.geli.*; import org.broadinstitute.sting.utils.genotype.glf.*; @@ -74,15 +75,15 @@ public class GenotypeWriterFactory { * @param format the format * @return an unpopulated genotype call object */ - public static Genotype createSupportedCall(GENOTYPE_FORMAT format) { + public static Genotype createSupportedCall(GENOTYPE_FORMAT format, char ref, GenomeLoc loc) { switch (format) { case VCF: - return new VCFGenotypeCall(); + return new VCFGenotypeCall(ref, loc); case GELI: case GELI_BINARY: - return new GeliGenotypeCall(); + return new GeliGenotypeCall(ref, loc); case GLF: - return new GLFGenotypeCall(); + return new GLFGenotypeCall(ref, loc); default: throw new StingException("Genotype format " + format.toString() + " is not implemented"); } diff --git a/java/src/org/broadinstitute/sting/utils/genotype/geli/GeliGenotypeCall.java b/java/src/org/broadinstitute/sting/utils/genotype/geli/GeliGenotypeCall.java index 52063ee9d..327eabea5 100755 --- a/java/src/org/broadinstitute/sting/utils/genotype/geli/GeliGenotypeCall.java +++ b/java/src/org/broadinstitute/sting/utils/genotype/geli/GeliGenotypeCall.java @@ -34,22 +34,16 @@ public class GeliGenotypeCall implements Genotype, ReadBacked, PosteriorsBacked * Generate a single sample genotype object * */ - public GeliGenotypeCall() { + public GeliGenotypeCall(char ref, GenomeLoc loc) { + mRefBase = ref; + mLocation = loc; + // fill in empty data - mRefBase = 'N'; mPosteriors = new double[10]; Arrays.fill(mPosteriors, Double.MIN_VALUE); mReads = new ArrayList(); } - public void setReference(char refBase) { - mRefBase = Character.toUpperCase(refBase); - } - - public void setLocation(GenomeLoc loc) { - mLocation = loc; - } - public void setReads(List reads) { mReads = new ArrayList(reads); } diff --git a/java/src/org/broadinstitute/sting/utils/genotype/glf/GLFGenotypeCall.java b/java/src/org/broadinstitute/sting/utils/genotype/glf/GLFGenotypeCall.java index e0dd8b733..5a76d9f3b 100755 --- a/java/src/org/broadinstitute/sting/utils/genotype/glf/GLFGenotypeCall.java +++ b/java/src/org/broadinstitute/sting/utils/genotype/glf/GLFGenotypeCall.java @@ -31,24 +31,18 @@ public class GLFGenotypeCall implements Genotype, ReadBacked, LikelihoodsBacked * Generate a single sample genotype object, containing everything we need to represent calls out of a genotyper object * */ - public GLFGenotypeCall() { + public GLFGenotypeCall(char ref, GenomeLoc loc) { + mRefBase = ref; + mGenotype = Utils.dupString(ref, 2); + // fill in empty data - mRefBase = 'N'; - mGenotype = "NN"; + mLocation = loc; mLikelihoods = new double[10]; Arrays.fill(mLikelihoods, Double.MIN_VALUE); mReads = new ArrayList(); mNegLog10PError = Double.MIN_VALUE; } - public void setReference(char refBase) { - mRefBase = Character.toUpperCase(refBase); - } - - public void setLocation(GenomeLoc loc) { - mLocation = loc; - } - public void setReads(List reads) { mReads = new ArrayList(reads); } diff --git a/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFGenotypeCall.java b/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFGenotypeCall.java index 339dc41da..46b8ab7fc 100755 --- a/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFGenotypeCall.java +++ b/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFGenotypeCall.java @@ -37,23 +37,17 @@ public class VCFGenotypeCall implements Genotype, ReadBacked, PosteriorsBacked, * Generate a single sample genotype object * */ - public VCFGenotypeCall() { + public VCFGenotypeCall(char ref, GenomeLoc loc) { + mRefBase = ref; + mLocation = loc; + // fill in empty data - mRefBase = 'N'; mPosteriors = new double[10]; Arrays.fill(mPosteriors, Double.MIN_VALUE); mSampleName = ""; mReads = new ArrayList(); } - public void setReference(char refBase) { - mRefBase = Character.toUpperCase(refBase); - } - - public void setLocation(GenomeLoc loc) { - mLocation = loc; - } - public void setReads(List reads) { mReads = new ArrayList(reads); } diff --git a/java/test/org/broadinstitute/sting/utils/genotype/glf/GLFWriterTest.java b/java/test/org/broadinstitute/sting/utils/genotype/glf/GLFWriterTest.java index aa042e3d2..3afb76fbe 100755 --- a/java/test/org/broadinstitute/sting/utils/genotype/glf/GLFWriterTest.java +++ b/java/test/org/broadinstitute/sting/utils/genotype/glf/GLFWriterTest.java @@ -145,8 +145,7 @@ class FakeGenotype extends GLFGenotypeCall implements Comparable { * @param negLog10PError the confidence score */ public FakeGenotype(GenomeLoc location, String genotype, char ref, double negLog10PError, double likelihoods[]) { - setLocation(location); - setReference(ref); + super(ref, location); setLikelihoods(likelihoods); setGenotype(genotype); setNegLog10PError(negLog10PError);