diff --git a/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/genotyper/GenotypingEngine.java b/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/genotyper/GenotypingEngine.java index ce616377d..6f11fe949 100644 --- a/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/genotyper/GenotypingEngine.java +++ b/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/genotyper/GenotypingEngine.java @@ -87,7 +87,7 @@ public abstract class GenotypingEngine resolveSampleNamesFromToolkit(final GenomeAnalysisEngine toolkit) { + if (toolkit == null) + throw new IllegalArgumentException("the toolkit cannot be null"); + return new LinkedHashSet<>(toolkit.getSampleDB().getSampleNames()); + } + + /** + * Construct a new genotyper engine, on a specific subset of samples. + * + * @param toolkit reference to the genome-analysis toolkit. + * @param configuration engine configuration object. * @param sampleNames subset of sample to work on identified by their names. If {@code null}, the full toolkit * sample set will be used instead. * * @throws IllegalArgumentException if either {@code toolkit} or {@code configuration} is {@code null}. */ - public GenotypingEngine(final GenomeAnalysisEngine toolkit, final Config configuration, - final VariantAnnotatorEngine annotationEngine, final Set sampleNames) { + protected GenotypingEngine(final GenomeAnalysisEngine toolkit, final Config configuration,final Set sampleNames) { if (toolkit == null) throw new IllegalArgumentException("the toolkit cannot be null"); if (configuration == null) throw new IllegalArgumentException("the configuration cannot be null"); this.configuration = configuration; - this.annotationEngine = annotationEngine; logger = Logger.getLogger(getClass()); this.toolkit = toolkit; this.sampleNames = sampleNames != null ? sampleNames : toolkit.getSampleDB().getSampleNames(); @@ -152,6 +175,15 @@ public abstract class GenotypingEngine= configuration.STANDARD_CONFIDENCE_FOR_CALLING || diff --git a/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyper.java b/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyper.java index 2bdeff5db..91b78daaf 100644 --- a/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyper.java +++ b/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyper.java @@ -283,7 +283,9 @@ public class UnifiedGenotyper extends LocusWalker, Unif verboseWriter.println("AFINFO\tLOC\tREF\tALT\tMAF\tF\tAFprior\tMLE\tMAP"); annotationEngine = new VariantAnnotatorEngine(Arrays.asList(annotationClassesToUse), annotationsToUse, annotationsToExclude, this, getToolkit()); - genotypingEngine = new UnifiedGenotypingEngine(getToolkit(), UAC, annotationEngine,samples, verboseWriter); + genotypingEngine = new UnifiedGenotypingEngine(getToolkit(), UAC, samples); + genotypingEngine.setVerboseWriter(verboseWriter); + genotypingEngine.setAnnotationEngine(annotationEngine); // initialize the header Set headerInfo = getHeaderInfo(UAC, annotationEngine, dbsnp); diff --git a/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotypingEngine.java b/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotypingEngine.java index ba7b76e8e..81eebb6fd 100644 --- a/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotypingEngine.java +++ b/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotypingEngine.java @@ -51,7 +51,6 @@ import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.AlignmentContextUtils; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; -import org.broadinstitute.sting.gatk.walkers.annotator.VariantAnnotatorEngine; import org.broadinstitute.sting.gatk.walkers.genotyper.afcalc.AFCalcResult; import org.broadinstitute.sting.utils.BaseUtils; import org.broadinstitute.sting.utils.GenomeLocParser; @@ -76,7 +75,6 @@ import java.util.*; public class UnifiedGenotypingEngine extends GenotypingEngine { public static final String LOW_QUAL_FILTER_NAME = "LowQual"; - private static final String GPSTRING = "GENERALPLOIDY"; public static final String NUMBER_OF_DISCOVERED_ALLELES_KEY = "NDA"; public static final String PL_FOR_ALL_SNP_ALLELES_KEY = "APL"; @@ -90,7 +88,7 @@ public class UnifiedGenotypingEngine extends GenotypingEngine sampleNames, final PrintStream verboseWriter) { + final Set sampleNames) { - super(toolkit,configuration,annotationEngine,sampleNames); + super(toolkit,configuration,sampleNames); this.BAQEnabledOnCMDLine = toolkit.getArguments().BAQMode != BAQ.CalculationMode.OFF; genomeLocParser = toolkit.getGenomeLocParser(); - this.verboseWriter = verboseWriter; - determineGLModelsToUse(); initializeGenotypeLikelihoodsCalculationModels(); } + /** + * Changes the verbose output writer for this engine. + * + * @param writer the new writer; it can be {@code null}. + */ + public void setVerboseWriter(final PrintStream writer) { + verboseWriter = writer; + } + /** * Initialize {@link #glcm}. */ diff --git a/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/haplotypecaller/HaplotypeCaller.java b/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/haplotypecaller/HaplotypeCaller.java index 3e3b76d71..7a25e8bc8 100644 --- a/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/haplotypecaller/HaplotypeCaller.java +++ b/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/haplotypecaller/HaplotypeCaller.java @@ -569,7 +569,7 @@ public class HaplotypeCaller extends ActiveRegionWalker, In simpleUAC.CONTAMINATION_FRACTION = 0.0; simpleUAC.CONTAMINATION_FRACTION_FILE = null; simpleUAC.exactCallsLog = null; - activeRegionEvaluationGenotyperEngine = new UnifiedGenotypingEngine(getToolkit(), simpleUAC, null, samplesSet, null); + activeRegionEvaluationGenotyperEngine = new UnifiedGenotypingEngine(getToolkit(), simpleUAC, samplesSet); activeRegionEvaluationGenotyperEngine.setLogger(logger); if( SCAC.CONTAMINATION_FRACTION_FILE != null ) @@ -644,7 +644,10 @@ public class HaplotypeCaller extends ActiveRegionWalker, In final MergeVariantsAcrossHaplotypes variantMerger = mergeVariantsViaLD ? new LDMerger(SCAC.DEBUG, 10, 1) : new MergeVariantsAcrossHaplotypes(); - genotypingEngine = new HaplotypeCallerGenotypingEngine( getToolkit(),SCAC, annotationEngine, null, variantMerger ); + genotypingEngine = new HaplotypeCallerGenotypingEngine( getToolkit(),SCAC); + genotypingEngine.setCrossHaplotypeEventMerger(variantMerger); + + genotypingEngine.setAnnotationEngine(annotationEngine); if ( bamWriter != null ) { // we currently do not support multi-threaded BAM writing, so exception out diff --git a/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/haplotypecaller/HaplotypeCallerGenotypingEngine.java b/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/haplotypecaller/HaplotypeCallerGenotypingEngine.java index fa743813a..907e8a07e 100644 --- a/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/haplotypecaller/HaplotypeCallerGenotypingEngine.java +++ b/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/haplotypecaller/HaplotypeCallerGenotypingEngine.java @@ -48,10 +48,8 @@ package org.broadinstitute.sting.gatk.walkers.haplotypecaller; import com.google.java.contract.Ensures; import com.google.java.contract.Requires; -import org.apache.log4j.Logger; import org.broadinstitute.sting.gatk.GenomeAnalysisEngine; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; -import org.broadinstitute.sting.gatk.walkers.annotator.VariantAnnotatorEngine; import org.broadinstitute.sting.gatk.walkers.genotyper.GenotypeLikelihoodsCalculationModel; import org.broadinstitute.sting.gatk.walkers.genotyper.GenotypingEngine; import org.broadinstitute.sting.gatk.walkers.genotyper.GenotypingOutputMode; @@ -75,16 +73,36 @@ import java.util.*; */ public class HaplotypeCallerGenotypingEngine extends GenotypingEngine { - private final static Logger logger = Logger.getLogger(HaplotypeCallerGenotypingEngine.class); - private final static List NO_CALL = Collections.singletonList(Allele.NO_CALL); - private final MergeVariantsAcrossHaplotypes crossHaplotypeEventMerger; + private MergeVariantsAcrossHaplotypes crossHaplotypeEventMerger; - public HaplotypeCallerGenotypingEngine(final GenomeAnalysisEngine toolkit, final HaplotypeCallerArgumentCollection configuration, - final VariantAnnotatorEngine annotationEngine, final Set sampleNames, - final MergeVariantsAcrossHaplotypes crossHaplotypeEventMerger) { - super(toolkit,configuration,annotationEngine,sampleNames); + /** + * {@inheritDoc} + * @param toolkit {@inheritDoc} + * @param configuration {@inheritDoc} + */ + public HaplotypeCallerGenotypingEngine(final GenomeAnalysisEngine toolkit, final HaplotypeCallerArgumentCollection configuration) { + super(toolkit,configuration); + } + + /** + * {@inheritDoc} + * @param toolkit {@inheritDoc} + * @param configuration {@inheritDoc} + * @param sampleNames {@inheritDoc} + */ + public HaplotypeCallerGenotypingEngine(final GenomeAnalysisEngine toolkit, final HaplotypeCallerArgumentCollection configuration, final Set sampleNames) { + super(toolkit,configuration,sampleNames); + } + + + /** + * Change the merge variant across haplotypes for this engine. + * + * @param crossHaplotypeEventMerger new merger, can be {@code null}. + */ + public void setCrossHaplotypeEventMerger(final MergeVariantsAcrossHaplotypes crossHaplotypeEventMerger) { this.crossHaplotypeEventMerger = crossHaplotypeEventMerger; } @@ -227,8 +245,8 @@ public class HaplotypeCallerGenotypingEngine extends GenotypingEngine> alleleMapper = createAlleleMapper(mergeMap, eventMapper); - if( configuration.DEBUG ) { - logger.info("Genotyping event at " + loc + " with alleles = " + mergedVC.getAlleles()); + if( configuration.DEBUG && logger != null ) { + if (logger != null) logger.info("Genotyping event at " + loc + " with alleles = " + mergedVC.getAlleles()); } final Map alleleReadMap = convertHaplotypeReadMapToAlleleReadMap(haplotypeReadMap, alleleMapper, configuration.getSampleContamination()); @@ -314,6 +332,8 @@ public class HaplotypeCallerGenotypingEngine extends GenotypingEngine variantCollection : variantCollections ) diff --git a/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/variantutils/RegenotypeVariants.java b/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/variantutils/RegenotypeVariants.java index 2cb12878b..97bb8166a 100644 --- a/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/variantutils/RegenotypeVariants.java +++ b/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/variantutils/RegenotypeVariants.java @@ -121,7 +121,7 @@ public class RegenotypeVariants extends RodWalker implements T String trackName = variantCollection.variants.getName(); Set samples = SampleUtils.getSampleListWithVCFHeader(getToolkit(), Arrays.asList(trackName)); - UG_engine = new UnifiedGenotypingEngine(getToolkit(), UAC, null, samples, null); + UG_engine = new UnifiedGenotypingEngine(getToolkit(), UAC, samples); final Set hInfo = new HashSet(); hInfo.addAll(GATKVCFUtils.getHeaderFields(getToolkit(), Arrays.asList(trackName))); diff --git a/protected/gatk-protected/src/test/java/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyperEngineUnitTest.java b/protected/gatk-protected/src/test/java/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyperEngineUnitTest.java index 54b5637de..e05cb89cc 100644 --- a/protected/gatk-protected/src/test/java/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyperEngineUnitTest.java +++ b/protected/gatk-protected/src/test/java/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyperEngineUnitTest.java @@ -78,7 +78,7 @@ public class UnifiedGenotyperEngineUnitTest extends BaseTest { final UnifiedArgumentCollection args = new UnifiedArgumentCollection(); final Set fakeSamples = Collections.singleton("fake"); - ugEngine = new UnifiedGenotypingEngine(engine, args, null, fakeSamples, null); + ugEngine = new UnifiedGenotypingEngine(engine, args,fakeSamples); } private UnifiedGenotypingEngine getEngine() {