-Added Per-Sample Contamination Removal to UnifiedGenotyper: Added an @Advanced option to the StandardCallerArgumentCollection, a file which should
contain two columns, Sample (String) and Fraction (Double) that form the Sample-Fraction map for the per-sample AlleleBiasedDownsampling. -Integration tests to UnifiedGenotyper (Using artificially contaminated BAMs created from a mixure of two broadly concented samples) were added -includes throwing an exception in HC if called using per-sample contamination file (not implemented); tested in a new integration test. -(Note: HaplotypeCaller already has "Flat" contamination--using the same fraction for all samples--what it doesn't have is _per-sample_ AlleleBiasedDownsampling, which is what has been added here to the UnifiedGenotyper. -New class: DefaultHashMap (a Defaulting HashMap...) and new function: loadContaminationFile (which reads a Sample-Fraction file and returns a map). -Unit tests to the new class and function are provided. -Added tests to see that malformed contamination files are found and that spaces and tabs are now read properly. -Merged the integration tests that pertain to biased downsampling, whether HaplotypeCaller or unifiedGenotyper, into a new IntegrationTest class.
This commit is contained in:
parent
70f3997a38
commit
de03f17be4
|
|
@ -50,10 +50,13 @@ import org.broadinstitute.sting.commandline.*;
|
|||
import org.broadinstitute.sting.gatk.walkers.genotyper.GenotypeLikelihoodsCalculationModel;
|
||||
import org.broadinstitute.sting.gatk.walkers.genotyper.UnifiedGenotyperEngine;
|
||||
import org.broadinstitute.sting.gatk.walkers.genotyper.afcalc.AFCalcFactory;
|
||||
import org.broadinstitute.sting.utils.collections.DefaultHashMap;
|
||||
import org.broadinstitute.variant.variantcontext.VariantContext;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintStream;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created with IntelliJ IDEA.
|
||||
|
|
@ -118,6 +121,33 @@ public class StandardCallerArgumentCollection {
|
|||
public double CONTAMINATION_FRACTION = DEFAULT_CONTAMINATION_FRACTION;
|
||||
public static final double DEFAULT_CONTAMINATION_FRACTION = 0.05;
|
||||
|
||||
/**
|
||||
* This argument specifies a file with two columns "sample" and "contamination" specifying the contamination level for those samples.
|
||||
* Samples that do not appear in this file will be processed with CONTAMINATION_FRACTION
|
||||
**/
|
||||
@Advanced
|
||||
@Argument(fullName = "contamination_fraction_per_sample_file", shortName = "contaminationFile", doc = "Tab-separated File containing fraction of contamination in sequencing data (per sample) to aggressively remove. Format should be \"<SampleID><TAB><Contamination>\" (Contamination is double) per line; No header.", required = false)
|
||||
public File CONTAMINATION_FRACTION_FILE = null;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return an _Immutable_ copy of the Sample-Contamination Map, defaulting to CONTAMINATION_FRACTION so that if the sample isn't in the map map(sample)==CONTAMINATION_FRACTION
|
||||
*/
|
||||
public Map<String,Double> getSampleContamination(){
|
||||
//make sure that the default value is set up right
|
||||
sampleContamination.setDefaultValue(CONTAMINATION_FRACTION);
|
||||
return Collections.unmodifiableMap(sampleContamination);
|
||||
}
|
||||
|
||||
public void setSampleContamination(DefaultHashMap<String, Double> sampleContamination) {
|
||||
this.sampleContamination.clear();
|
||||
this.sampleContamination.putAll(sampleContamination);
|
||||
this.sampleContamination.setDefaultValue(CONTAMINATION_FRACTION);
|
||||
}
|
||||
|
||||
//Needs to be here because it uses CONTAMINATION_FRACTION
|
||||
private DefaultHashMap<String,Double> sampleContamination = new DefaultHashMap<String,Double>(CONTAMINATION_FRACTION);
|
||||
|
||||
/**
|
||||
* Controls the model used to calculate the probability that a site is variant plus the various sample genotypes in the data at a given locus.
|
||||
*/
|
||||
|
|
@ -145,8 +175,10 @@ public class StandardCallerArgumentCollection {
|
|||
this.STANDARD_CONFIDENCE_FOR_CALLING = SCAC.STANDARD_CONFIDENCE_FOR_CALLING;
|
||||
this.STANDARD_CONFIDENCE_FOR_EMITTING = SCAC.STANDARD_CONFIDENCE_FOR_EMITTING;
|
||||
this.CONTAMINATION_FRACTION = SCAC.CONTAMINATION_FRACTION;
|
||||
this.CONTAMINATION_FRACTION_FILE=SCAC.CONTAMINATION_FRACTION_FILE;
|
||||
this.contaminationLog = SCAC.contaminationLog;
|
||||
this.exactCallsLog = SCAC.exactCallsLog;
|
||||
this.sampleContamination=SCAC.sampleContamination;
|
||||
this.AFmodel = SCAC.AFmodel;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ public class IndelGenotypeLikelihoodsCalculationModel extends GenotypeLikelihood
|
|||
final ReadBackedPileup pileup = context.getBasePileup();
|
||||
if (pileup != null) {
|
||||
final GenotypeBuilder b = new GenotypeBuilder(sample.getKey());
|
||||
final double[] genotypeLikelihoods = pairModel.computeDiploidReadHaplotypeLikelihoods(pileup, haplotypeMap, ref, eventLength, perReadAlleleLikelihoodMap.get(sample.getKey()), UAC.CONTAMINATION_FRACTION, UAC.contaminationLog);
|
||||
final double[] genotypeLikelihoods = pairModel.computeDiploidReadHaplotypeLikelihoods(pileup, haplotypeMap, ref, eventLength, perReadAlleleLikelihoodMap.get(sample.getKey()), UAC.getSampleContamination().get(sample.getKey()), UAC.contaminationLog);
|
||||
b.PL(genotypeLikelihoods);
|
||||
b.DP(getFilteredDepth(pileup));
|
||||
genotypes.add(b.make());
|
||||
|
|
@ -259,4 +259,4 @@ public class IndelGenotypeLikelihoodsCalculationModel extends GenotypeLikelihood
|
|||
return count;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,9 +101,11 @@ public class SNPGenotypeLikelihoodsCalculationModel extends GenotypeLikelihoodsC
|
|||
// calculate the GLs
|
||||
ArrayList<SampleGenotypeData> GLs = new ArrayList<SampleGenotypeData>(contexts.size());
|
||||
for ( Map.Entry<String, AlignmentContext> sample : contexts.entrySet() ) {
|
||||
// Down-sample with bias according to the contamination level (global or per file)
|
||||
ReadBackedPileup pileup = AlignmentContextUtils.stratify(sample.getValue(), contextType).getBasePileup();
|
||||
if ( UAC.CONTAMINATION_FRACTION > 0.0 )
|
||||
pileup = perReadAlleleLikelihoodMap.createPerAlleleDownsampledBasePileup(pileup, UAC.CONTAMINATION_FRACTION, UAC.contaminationLog);
|
||||
final Double contamination = UAC.getSampleContamination().get(sample.getKey());
|
||||
if( contamination > 0.0 ) //no need to enter if no contamination reduction
|
||||
pileup = perReadAlleleLikelihoodMap.createPerAlleleDownsampledBasePileup(pileup,contamination, UAC.contaminationLog);
|
||||
if ( useBAQedPileup )
|
||||
pileup = createBAQedPileup(pileup);
|
||||
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ import org.broadinstitute.sting.gatk.CommandLineGATK;
|
|||
import org.broadinstitute.sting.gatk.arguments.DbsnpArgumentCollection;
|
||||
import org.broadinstitute.sting.gatk.contexts.AlignmentContext;
|
||||
import org.broadinstitute.sting.gatk.contexts.ReferenceContext;
|
||||
import org.broadinstitute.sting.gatk.downsampling.AlleleBiasedDownsamplingUtils;
|
||||
import org.broadinstitute.sting.gatk.downsampling.DownsampleType;
|
||||
import org.broadinstitute.sting.gatk.filters.BadMateFilter;
|
||||
import org.broadinstitute.sting.gatk.filters.MappingQualityUnavailableFilter;
|
||||
|
|
@ -258,6 +259,8 @@ public class UnifiedGenotyper extends LocusWalker<List<VariantCallContext>, Unif
|
|||
if ( UAC.referenceSampleName != null )
|
||||
samples.remove(UAC.referenceSampleName);
|
||||
}
|
||||
if ( UAC.CONTAMINATION_FRACTION_FILE != null )
|
||||
UAC.setSampleContamination(AlleleBiasedDownsamplingUtils.loadContaminationFile(UAC.CONTAMINATION_FRACTION_FILE, UAC.CONTAMINATION_FRACTION, samples, logger));
|
||||
|
||||
// check for a bad max alleles value
|
||||
if ( UAC.MAX_ALTERNATE_ALLELES > GenotypeLikelihoods.MAX_ALT_ALLELES_THAT_CAN_BE_GENOTYPED)
|
||||
|
|
|
|||
|
|
@ -305,9 +305,18 @@ public class HaplotypeCaller extends ActiveRegionWalker<Integer, Integer> implem
|
|||
simpleUAC.STANDARD_CONFIDENCE_FOR_CALLING = Math.min( 4.0, UAC.STANDARD_CONFIDENCE_FOR_CALLING ); // low values used for isActive determination only, default/user-specified values used for actual calling
|
||||
simpleUAC.STANDARD_CONFIDENCE_FOR_EMITTING = Math.min( 4.0, UAC.STANDARD_CONFIDENCE_FOR_EMITTING ); // low values used for isActive determination only, default/user-specified values used for actual calling
|
||||
simpleUAC.CONTAMINATION_FRACTION = 0.0;
|
||||
simpleUAC.CONTAMINATION_FRACTION_FILE=null;
|
||||
simpleUAC.exactCallsLog = null;
|
||||
UG_engine_simple_genotyper = new UnifiedGenotyperEngine(getToolkit(), simpleUAC, logger, null, null, samples, GATKVariantContextUtils.DEFAULT_PLOIDY);
|
||||
|
||||
// Currently, per-sample contamination level is only implemented for UG
|
||||
if( UAC.CONTAMINATION_FRACTION_FILE !=null) {
|
||||
throw new UserException("Per-Sample contamination level not supported in Haplotype Caller at this point");
|
||||
}
|
||||
|
||||
// when we do implement per-sample contamination for HC, this will probably be needed.
|
||||
// UAC.setSampleContamination(AlleleBiasedDownsamplingUtils.loadContaminationFile(UAC.CONTAMINATION_FRACTION_FILE, samples, logger));
|
||||
|
||||
// initialize the output VCF header
|
||||
annotationEngine = new VariantAnnotatorEngine(Arrays.asList(annotationClassesToUse), annotationsToUse, annotationsToExclude, this, getToolkit());
|
||||
|
||||
|
|
|
|||
|
|
@ -46,10 +46,18 @@
|
|||
|
||||
package org.broadinstitute.sting.gatk.downsampling;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.broadinstitute.sting.BaseTest;
|
||||
import org.broadinstitute.sting.utils.exceptions.UserException;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
* Basic unit test for AlleleBiasedDownsamplingUtils
|
||||
|
|
@ -126,4 +134,75 @@ public class AlleleBiasedDownsamplingUtilsUnitTest extends BaseTest {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLoadContaminationFile1(){
|
||||
Logger logger=org.apache.log4j.Logger.getRootLogger();
|
||||
|
||||
final String ArtificalBAMLocation = privateTestDir + "ArtificallyContaminatedBams/";
|
||||
final File ContamFile1=new File(ArtificalBAMLocation+"contamination.case.1.txt");
|
||||
|
||||
Map<String,Double> Contam1=new HashMap<String,Double>();
|
||||
Set<String> Samples1=new HashSet<String>();
|
||||
|
||||
Contam1.put("NA11918",0.15);
|
||||
Samples1.addAll(Contam1.keySet());
|
||||
testLoadFile(ContamFile1,Samples1,Contam1,logger);
|
||||
|
||||
Contam1.put("NA12842",0.13);
|
||||
Samples1.addAll(Contam1.keySet());
|
||||
testLoadFile(ContamFile1,Samples1,Contam1,logger);
|
||||
|
||||
Samples1.add("DUMMY");
|
||||
testLoadFile(ContamFile1,Samples1,Contam1,logger);
|
||||
}
|
||||
|
||||
private static void testLoadFile(final File file, final Set<String> Samples, final Map<String,Double> map, Logger logger){
|
||||
Map<String,Double> loadedMap = AlleleBiasedDownsamplingUtils.loadContaminationFile(file,0.0,Samples,logger);
|
||||
Assert.assertTrue(loadedMap.equals(map));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadContaminationFiles(){
|
||||
Logger logger=org.apache.log4j.Logger.getRootLogger();
|
||||
final String ArtificalBAMLocation = privateTestDir + "ArtificallyContaminatedBams/";
|
||||
|
||||
for(int i=1; i<=5; i++){
|
||||
File ContamFile=new File(ArtificalBAMLocation+String.format("contamination.case.%d.txt",i));
|
||||
Assert.assertTrue(AlleleBiasedDownsamplingUtils.loadContaminationFile(ContamFile,0.0,null,logger).size()==2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = UserException.MalformedFile.class)
|
||||
public void testLoadBrokenContaminationFile1(){
|
||||
testLoadBrokenContaminationFile(1);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = UserException.MalformedFile.class)
|
||||
public void testLoadBrokenContaminationFile2(){
|
||||
testLoadBrokenContaminationFile(2);
|
||||
}
|
||||
@Test(expectedExceptions = UserException.MalformedFile.class)
|
||||
public void testLoadBrokenContaminationFile3(){
|
||||
testLoadBrokenContaminationFile(3);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = UserException.MalformedFile.class)
|
||||
public void testLoadBrokenContaminationFile4(){
|
||||
testLoadBrokenContaminationFile(4);
|
||||
}
|
||||
|
||||
|
||||
public void testLoadBrokenContaminationFile(final int i){
|
||||
Logger logger=org.apache.log4j.Logger.getRootLogger();
|
||||
final String ArtificalBAMLocation = privateTestDir + "ArtificallyContaminatedBams/";
|
||||
|
||||
File ContaminationFile=new File(ArtificalBAMLocation+String.format("contamination.case.broken.%d.txt",i));
|
||||
AlleleBiasedDownsamplingUtils.loadContaminationFile(ContaminationFile,0.0,null,logger);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,263 @@
|
|||
/*
|
||||
* By downloading the PROGRAM you agree to the following terms of use:
|
||||
*
|
||||
* BROAD INSTITUTE - SOFTWARE LICENSE AGREEMENT - FOR ACADEMIC NON-COMMERCIAL RESEARCH PURPOSES ONLY
|
||||
*
|
||||
* This Agreement is made between the Broad Institute, Inc. with a principal address at 7 Cambridge Center, Cambridge, MA 02142 (BROAD) and the LICENSEE and is effective at the date the downloading is completed (EFFECTIVE DATE).
|
||||
*
|
||||
* WHEREAS, LICENSEE desires to license the PROGRAM, as defined hereinafter, and BROAD wishes to have this PROGRAM utilized in the public interest, subject only to the royalty-free, nonexclusive, nontransferable license rights of the United States Government pursuant to 48 CFR 52.227-14; and
|
||||
* WHEREAS, LICENSEE desires to license the PROGRAM and BROAD desires to grant a license on the following terms and conditions.
|
||||
* NOW, THEREFORE, in consideration of the promises and covenants made herein, the parties hereto agree as follows:
|
||||
*
|
||||
* 1. DEFINITIONS
|
||||
* 1.1 PROGRAM shall mean copyright in the object code and source code known as GATK2 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute/GATK on the EFFECTIVE DATE.
|
||||
*
|
||||
* 2. LICENSE
|
||||
* 2.1 Grant. Subject to the terms of this Agreement, BROAD hereby grants to LICENSEE, solely for academic non-commercial research purposes, a non-exclusive, non-transferable license to: (a) download, execute and display the PROGRAM and (b) create bug fixes and modify the PROGRAM.
|
||||
* The LICENSEE may apply the PROGRAM in a pipeline to data owned by users other than the LICENSEE and provide these users the results of the PROGRAM provided LICENSEE does so for academic non-commercial purposes only. For clarification purposes, academic sponsored research is not a commercial use under the terms of this Agreement.
|
||||
* 2.2 No Sublicensing or Additional Rights. LICENSEE shall not sublicense or distribute the PROGRAM, in whole or in part, without prior written permission from BROAD. LICENSEE shall ensure that all of its users agree to the terms of this Agreement. LICENSEE further agrees that it shall not put the PROGRAM on a network, server, or other similar technology that may be accessed by anyone other than the LICENSEE and its employees and users who have agreed to the terms of this agreement.
|
||||
* 2.3 License Limitations. Nothing in this Agreement shall be construed to confer any rights upon LICENSEE by implication, estoppel, or otherwise to any computer software, trademark, intellectual property, or patent rights of BROAD, or of any other entity, except as expressly granted herein. LICENSEE agrees that the PROGRAM, in whole or part, shall not be used for any commercial purpose, including without limitation, as the basis of a commercial software or hardware product or to provide services. LICENSEE further agrees that the PROGRAM shall not be copied or otherwise adapted in order to circumvent the need for obtaining a license for use of the PROGRAM.
|
||||
*
|
||||
* 3. OWNERSHIP OF INTELLECTUAL PROPERTY
|
||||
* LICENSEE acknowledges that title to the PROGRAM shall remain with BROAD. The PROGRAM is marked with the following BROAD copyright notice and notice of attribution to contributors. LICENSEE shall retain such notice on all copies. LICENSEE agrees to include appropriate attribution if any results obtained from use of the PROGRAM are included in any publication.
|
||||
* Copyright 2012 Broad Institute, Inc.
|
||||
* Notice of attribution: The GATK2 program was made available through the generosity of Medical and Population Genetics program at the Broad Institute, Inc.
|
||||
* LICENSEE shall not use any trademark or trade name of BROAD, or any variation, adaptation, or abbreviation, of such marks or trade names, or any names of officers, faculty, students, employees, or agents of BROAD except as states above for attribution purposes.
|
||||
*
|
||||
* 4. INDEMNIFICATION
|
||||
* LICENSEE shall indemnify, defend, and hold harmless BROAD, and their respective officers, faculty, students, employees, associated investigators and agents, and their respective successors, heirs and assigns, (Indemnitees), against any liability, damage, loss, or expense (including reasonable attorneys fees and expenses) incurred by or imposed upon any of the Indemnitees in connection with any claims, suits, actions, demands or judgments arising out of any theory of liability (including, without limitation, actions in the form of tort, warranty, or strict liability and regardless of whether such action has any factual basis) pursuant to any right or license granted under this Agreement.
|
||||
*
|
||||
* 5. NO REPRESENTATIONS OR WARRANTIES
|
||||
* THE PROGRAM IS DELIVERED AS IS. BROAD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE PROGRAM OR THE COPYRIGHT, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER OR NOT DISCOVERABLE. BROAD EXTENDS NO WARRANTIES OF ANY KIND AS TO PROGRAM CONFORMITY WITH WHATEVER USER MANUALS OR OTHER LITERATURE MAY BE ISSUED FROM TIME TO TIME.
|
||||
* IN NO EVENT SHALL BROAD OR ITS RESPECTIVE DIRECTORS, OFFICERS, EMPLOYEES, AFFILIATED INVESTIGATORS AND AFFILIATES BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING, WITHOUT LIMITATION, ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER BROAD SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING.
|
||||
*
|
||||
* 6. ASSIGNMENT
|
||||
* This Agreement is personal to LICENSEE and any rights or obligations assigned by LICENSEE without the prior written consent of BROAD shall be null and void.
|
||||
*
|
||||
* 7. MISCELLANEOUS
|
||||
* 7.1 Export Control. LICENSEE gives assurance that it will comply with all United States export control laws and regulations controlling the export of the PROGRAM, including, without limitation, all Export Administration Regulations of the United States Department of Commerce. Among other things, these laws and regulations prohibit, or require a license for, the export of certain types of software to specified countries.
|
||||
* 7.2 Termination. LICENSEE shall have the right to terminate this Agreement for any reason upon prior written notice to BROAD. If LICENSEE breaches any provision hereunder, and fails to cure such breach within thirty (30) days, BROAD may terminate this Agreement immediately. Upon termination, LICENSEE shall provide BROAD with written assurance that the original and all copies of the PROGRAM have been destroyed, except that, upon prior written authorization from BROAD, LICENSEE may retain a copy for archive purposes.
|
||||
* 7.3 Survival. The following provisions shall survive the expiration or termination of this Agreement: Articles 1, 3, 4, 5 and Sections 2.2, 2.3, 7.3, and 7.4.
|
||||
* 7.4 Notice. Any notices under this Agreement shall be in writing, shall specifically refer to this Agreement, and shall be sent by hand, recognized national overnight courier, confirmed facsimile transmission, confirmed electronic mail, or registered or certified mail, postage prepaid, return receipt requested. All notices under this Agreement shall be deemed effective upon receipt.
|
||||
* 7.5 Amendment and Waiver; Entire Agreement. This Agreement may be amended, supplemented, or otherwise modified only by means of a written instrument signed by all parties. Any waiver of any rights or failure to act in a specific instance shall relate only to such instance and shall not be construed as an agreement to waive any rights or fail to act in any other instance, whether or not similar. This Agreement constitutes the entire agreement among the parties with respect to its subject matter and supersedes prior agreements or understandings between the parties relating to its subject matter.
|
||||
* 7.6 Binding Effect; Headings. This Agreement shall be binding upon and inure to the benefit of the parties and their respective permitted successors and assigns. All headings are for convenience only and shall not affect the meaning of any provision of this Agreement.
|
||||
* 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles.
|
||||
*/
|
||||
|
||||
package org.broadinstitute.sting.gatk.walkers.genotyper;
|
||||
|
||||
import org.broadinstitute.sting.WalkerTest;
|
||||
import org.broadinstitute.sting.utils.exceptions.UserException;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class BiasedDownsamplingIntegrationTest extends WalkerTest {
|
||||
|
||||
private final static String baseCommand1 = "-T UnifiedGenotyper -R " + b36KGReference + " --no_cmdline_in_header -glm BOTH -minIndelFrac 0.0 --dbsnp " + b36dbSNP129;
|
||||
private final static String baseCommand2 = "-T UnifiedGenotyper -R " + hg19Reference + " --no_cmdline_in_header -glm BOTH -L 20:1,000,000-5,000,000";
|
||||
private final String ArtificalBAMLocation = privateTestDir + "ArtificallyContaminatedBams/";
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// testing UnifiedGenotyper contamination down-sampling
|
||||
//
|
||||
// --------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void testContaminationDownsamplingFlat() {
|
||||
WalkerTestSpec spec = new WalkerTestSpec(
|
||||
baseCommand1 + " -I " + validationDataLocation + "NA12878.1kg.p2.chr1_10mb_11_mb.SLX.bam -o %s -L 1:10,000,000-10,010,000 -contamination 0.20", 1,
|
||||
Arrays.asList("1f9071466fc40f4c6a0f58ac8e9135fb"));
|
||||
executeTest("test contamination_percentage_to_filter 0.20", spec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContaminationDownsamplingFlatAndPerSample() {
|
||||
WalkerTestSpec spec = new WalkerTestSpec(
|
||||
baseCommand1 + " -I " + validationDataLocation + "NA12878.1kg.p2.chr1_10mb_11_mb.SLX.bam -o %s -L 1:10,000,000-10,010,000 --contamination_fraction_per_sample_file " + ArtificalBAMLocation + "NA12878.NA19240.contam.txt --contamination_fraction_to_filter 0.10", 1,
|
||||
Arrays.asList("53395814dd6990448a01a294ccd69bd2"));
|
||||
executeTest("test contamination_percentage_to_filter per-sample and .20 overall", spec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContaminationDownsamplingPerSampleOnly() {
|
||||
WalkerTestSpec spec = new WalkerTestSpec(
|
||||
baseCommand1 + " -I " + validationDataLocation + "NA12878.1kg.p2.chr1_10mb_11_mb.SLX.bam -o %s -L 1:10,000,000-10,010,000 -contaminationFile " + ArtificalBAMLocation + "NA19240.contam.txt", 1,
|
||||
Arrays.asList("4af83a883ecc03a23b0aa6dd4b8f1ceb"));
|
||||
executeTest("test contamination_percentage_to_filter per-sample", spec);
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// testing UnifiedGenotyper contamination down-sampling on BAMs with artificially created contaminated.
|
||||
//
|
||||
// --------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
private void testDefaultContamination() {
|
||||
final String bam1 = "NA11918.with.1.NA12842.reduced.bam";
|
||||
final String bam2 = "NA12842.with.1.NA11918.reduced.bam";
|
||||
|
||||
WalkerTestSpec spec = new WalkerTestSpec(
|
||||
baseCommand2 + " -I " + ArtificalBAMLocation + bam1 + " -I " + ArtificalBAMLocation + bam2 + " -o %s ", 1,
|
||||
Arrays.asList("e5fe7246526916af104a6f3e5dd67297"));
|
||||
executeTest("test contamination on Artificial Contamination (flat) on " + bam1 + " and " + bam2 + " with default downsampling.", spec);
|
||||
}
|
||||
|
||||
private void testFlatContamination(final String bam1, final String bam2, final Double downsampling, final String md5) {
|
||||
WalkerTestSpec spec = new WalkerTestSpec(
|
||||
baseCommand2 + " -I " + ArtificalBAMLocation + bam1 + " -I " + ArtificalBAMLocation + bam2 + " -o %s -contamination " + downsampling.toString(), 1,
|
||||
Arrays.asList(md5));
|
||||
executeTest("test contamination on Artificial Contamination (flat) on " + bam1 + " and " + bam2 + " downsampling " + downsampling.toString(), spec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlatContaminationCase1() {
|
||||
testFlatContamination("NA11918.with.1.NA12842.reduced.bam", "NA12842.with.1.NA11918.reduced.bam", 0.05, "e5fe7246526916af104a6f3e5dd67297");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlatContaminationCase2() {
|
||||
testFlatContamination("NA11918.with.1.NA12842.reduced.bam", "NA12842.with.1.NA11918.reduced.bam", 0.1, "ff490f52dc47ed54c5b9bffae73e819d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlatContaminationCase3() {
|
||||
testFlatContamination("NA11918.with.1.NA12842.reduced.bam", "NA12842.with.1.NA11918.reduced.bam", 0.2, "5efd81caff20fa39da4446ef854d81cc");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlatContaminationCase4() {
|
||||
testFlatContamination("NA11918.with.2.NA12842.reduced.bam", "NA12842.with.2.NA11918.reduced.bam", 0.1, "48e6da2d78caa693a177e38b6d35c63f");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlatContaminationCase5() {
|
||||
testFlatContamination("NA11918.with.2.NA12842.reduced.bam", "NA12842.with.2.NA11918.reduced.bam", 0.2, "02dd71427c2ead3c4444d00ad211a79d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlatContaminationCase6() {
|
||||
testFlatContamination("NA11918.with.2.NA12842.reduced.bam", "NA12842.with.2.NA11918.reduced.bam", 0.3, "b4271277813dc9146cb247d4495ee843");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlatContaminationCase7() {
|
||||
testFlatContamination("NA11918.with.2.NA12842.reduced.bam", "NA12842.with.1.NA11918.reduced.bam", 0.1, "acdf3c236a9d05885d4be890a39aa48d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlatContaminationCase8() {
|
||||
testFlatContamination("NA11918.with.2.NA12842.reduced.bam", "NA12842.with.1.NA11918.reduced.bam", 0.2, "8f16a8bd41a18e14e17710f3f1baaaf5");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlatContaminationCase9() {
|
||||
testFlatContamination("NA11918.with.2.NA12842.reduced.bam", "NA12842.with.1.NA11918.reduced.bam", 0.3, "06110b035fd3f1e87ea4f27b7500096d");
|
||||
}
|
||||
|
||||
private void testPerSampleContamination(String bam1, String bam2, String persampleFile, final String md5) {
|
||||
WalkerTestSpec spec = new WalkerTestSpec(
|
||||
baseCommand2 + " -I " + ArtificalBAMLocation + bam1 + " -I " + ArtificalBAMLocation + bam2 + " -o %s -contaminationFile " + persampleFile, 1,
|
||||
Arrays.asList(md5));
|
||||
executeTest("test contamination on Artificial Contamination (per-sample) on " + bam1 + " and " + bam2 + " with " + persampleFile, spec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPerSampleContaminationCase1() {
|
||||
testPerSampleContamination("NA11918.with.1.NA12842.reduced.bam", "NA12842.with.1.NA11918.reduced.bam", ArtificalBAMLocation + "contamination.case.1.txt", "4510dd668891ad378cd8b6f8da1dc35d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPerSampleContaminationCase2() {
|
||||
testPerSampleContamination("NA11918.with.1.NA12842.reduced.bam", "NA12842.with.1.NA11918.reduced.bam", ArtificalBAMLocation + "contamination.case.2.txt", "d8a0d0024574da7249d682e145f1c286");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPerSampleContaminationCase3() {
|
||||
testPerSampleContamination("NA11918.with.1.NA12842.reduced.bam", "NA12842.with.1.NA11918.reduced.bam", ArtificalBAMLocation + "contamination.case.3.txt", "2014464dbbaa62279fb79791a1a7ff6a");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPerSampleContaminationCase4() {
|
||||
testPerSampleContamination("NA11918.with.1.NA12842.reduced.bam", "NA12842.with.1.NA11918.reduced.bam", ArtificalBAMLocation + "contamination.case.4.txt", "26382eda9dddb910fc7e2bdf3b83f42e");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPerSampleContaminationCase5() {
|
||||
testPerSampleContamination("NA11918.with.2.NA12842.reduced.bam", "NA12842.with.1.NA11918.reduced.bam", ArtificalBAMLocation + "contamination.case.1.txt", "ca54f5c4f249d5e461b407696f3851d2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPerSampleContaminationCase6() {
|
||||
testPerSampleContamination("NA11918.with.2.NA12842.reduced.bam", "NA12842.with.1.NA11918.reduced.bam", ArtificalBAMLocation + "contamination.case.2.txt", "37c8cc33faec5324de6e007180186823");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPerSampleContaminationCase7() {
|
||||
testPerSampleContamination("NA11918.with.2.NA12842.reduced.bam", "NA12842.with.1.NA11918.reduced.bam", ArtificalBAMLocation + "contamination.case.3.txt", "57fa162f9d3487605997cdf6d11448b6");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPerSampleContaminationCase8() {
|
||||
testPerSampleContamination("NA11918.with.2.NA12842.reduced.bam", "NA12842.with.1.NA11918.reduced.bam", ArtificalBAMLocation + "contamination.case.4.txt", "4ee1bbf61c5e5c018cc78d521e3ed334");
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// testing HaplotypeCaller Contamination Removal
|
||||
//
|
||||
// --------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@Test
|
||||
public void testHCContaminationDownsamplingFlat() {
|
||||
final String baseCommand = "-T HaplotypeCaller -R " + b36KGReference + " --no_cmdline_in_header --dbsnp " + b36dbSNP129;
|
||||
WalkerTestSpec spec = new WalkerTestSpec(
|
||||
baseCommand + " -I " + validationDataLocation + "NA12878.1kg.p2.chr1_10mb_11_mb.SLX.bam -o %s -L 1:10,000,000-10,010,000 -contamination 0.20", 1,
|
||||
Arrays.asList("c23c69b3c5a337a818f963c87940b041"));
|
||||
executeTest("HC calling with contamination_percentage_to_filter 0.20", spec);
|
||||
}
|
||||
|
||||
// HaplotypeCaller can only (currently) use flat contamination reduction, not per-sample. Until that is implemented, this test
|
||||
@Test
|
||||
public void testHCCannotProcessPerSampleContamination() {
|
||||
final String baseCommand = "-T HaplotypeCaller -R " + hg19Reference + " --no_cmdline_in_header -L 20:3,000,000-5,000,000";
|
||||
final String bam1 = "NA11918.with.1.NA12842.reduced.bam";
|
||||
final String perSampleFile = ArtificalBAMLocation + "contamination.case.1.txt";
|
||||
WalkerTestSpec spec = new WalkerTestSpec(
|
||||
baseCommand + " -I " + ArtificalBAMLocation + bam1 + " -o %s -contaminationFile " + perSampleFile, 1,
|
||||
UserException.class);
|
||||
executeTest("HC should fail on per-Sample contamination removal.", spec);
|
||||
}
|
||||
|
||||
|
||||
private void testHCFlatContamination(final String bam1, final String bam2, final Double downsampling, final String md5) {
|
||||
final String baseCommand = "-T HaplotypeCaller -R " + hg19Reference + " --no_cmdline_in_header -L 20:3,000,000-5,000,000";
|
||||
|
||||
WalkerTestSpec spec = new WalkerTestSpec(
|
||||
baseCommand + " -I " + ArtificalBAMLocation + bam1 + " -I " + ArtificalBAMLocation + bam2 + " -o %s -contamination " + downsampling.toString(), 1,
|
||||
Arrays.asList(md5));
|
||||
executeTest("HC test contamination on Artificial Contamination (flat) on " + bam1 + " and " + bam2 + " downsampling " + downsampling.toString(), spec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHCFlatContaminationCase1() {
|
||||
testHCFlatContamination("NA11918.with.1.NA12842.reduced.bam", "NA12842.with.1.NA11918.reduced.bam", 0.05, "9fc24de333e8cba3f6b41ad8cc1362d8");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHCFlatContaminationCase2() {
|
||||
testHCFlatContamination("NA11918.with.1.NA12842.reduced.bam", "NA12842.with.1.NA11918.reduced.bam", 0.1, "57b5291ec216bf071b3c80b70f0f69bb");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHCFlatContaminationCase3() {
|
||||
testHCFlatContamination("NA11918.with.1.NA12842.reduced.bam", "NA12842.with.1.NA11918.reduced.bam", 0.2, "c875633954a299c9f082159b5b24aa57");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -519,19 +519,4 @@ public class UnifiedGenotyperIntegrationTest extends WalkerTest {
|
|||
executeTest("test calling on a ReducedRead BAM with " + model, spec);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// testing contamination down-sampling
|
||||
//
|
||||
// --------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void testContaminationDownsampling() {
|
||||
WalkerTest.WalkerTestSpec spec = new WalkerTest.WalkerTestSpec(
|
||||
baseCommand + " -I " + validationDataLocation + "NA12878.1kg.p2.chr1_10mb_11_mb.SLX.bam -o %s -L 1:10,000,000-10,010,000 --contamination_fraction_to_filter 0.20", 1,
|
||||
Arrays.asList("1f9071466fc40f4c6a0f58ac8e9135fb"));
|
||||
executeTest("test contamination_percentage_to_filter 0.20", spec);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,14 +27,22 @@ package org.broadinstitute.sting.gatk.downsampling;
|
|||
|
||||
import net.sf.samtools.SAMReadGroupRecord;
|
||||
import org.broadinstitute.sting.utils.*;
|
||||
import org.broadinstitute.sting.utils.collections.DefaultHashMap;
|
||||
import org.broadinstitute.sting.utils.exceptions.StingException;
|
||||
import org.broadinstitute.sting.utils.exceptions.UserException;
|
||||
import org.broadinstitute.sting.utils.pileup.*;
|
||||
import org.broadinstitute.sting.utils.sam.GATKSAMRecord;
|
||||
import org.broadinstitute.sting.utils.BaseUtils;
|
||||
import org.broadinstitute.sting.utils.text.XReadLines;
|
||||
import org.broadinstitute.variant.variantcontext.Allele;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class AlleleBiasedDownsamplingUtils {
|
||||
|
||||
/**
|
||||
|
|
@ -257,4 +265,90 @@ public class AlleleBiasedDownsamplingUtils {
|
|||
log.println(String.format("%s\t%s\t%s\t%s", read.getReadName(), readGroup.getSample(), readGroup.getLibrary(), readGroup.getPlatformUnit()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create sample-contamination maps from file
|
||||
*
|
||||
* @param ContaminationFractionFile Filename containing two columns: SampleID and Contamination
|
||||
* @param AvailableSampleIDs Set of Samples of interest (no reason to include every sample in file) or null to turn off checking
|
||||
* @param logger for logging output
|
||||
* @return sample-contamination Map
|
||||
*/
|
||||
|
||||
public static DefaultHashMap<String, Double> loadContaminationFile(File ContaminationFractionFile, final Double defaultContaminationFraction, final Set<String> AvailableSampleIDs, Logger logger) throws StingException {
|
||||
DefaultHashMap<String, Double> sampleContamination = new DefaultHashMap<String, Double>(defaultContaminationFraction);
|
||||
Set<String> nonSamplesInContaminationFile = new HashSet<String>(sampleContamination.keySet());
|
||||
try {
|
||||
|
||||
XReadLines reader = new XReadLines(ContaminationFractionFile, true);
|
||||
for (String line : reader) {
|
||||
|
||||
if (line.length() == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
StringTokenizer st = new StringTokenizer(line);
|
||||
|
||||
String fields[] = new String[2];
|
||||
try {
|
||||
fields[0] = st.nextToken();
|
||||
fields[1] = st.nextToken();
|
||||
} catch(NoSuchElementException e){
|
||||
throw new UserException.MalformedFile("Contamination file must have exactly two columns. Offending line:\n" + line);
|
||||
}
|
||||
if(st.hasMoreTokens()) {
|
||||
throw new UserException.MalformedFile("Contamination file must have exactly two columns. Offending line:\n" + line);
|
||||
}
|
||||
|
||||
if (fields[0].length() == 0 || fields[1].length() == 0) {
|
||||
throw new UserException.MalformedFile("Contamination file can not have empty strings in either column. Offending line:\n" + line);
|
||||
}
|
||||
|
||||
if (sampleContamination.containsKey(fields[0])) {
|
||||
throw new UserException.MalformedFile("Contamination file contains duplicate entries for input name " + fields[0]);
|
||||
}
|
||||
|
||||
try {
|
||||
final Double contamination = Double.valueOf(fields[1]);
|
||||
if (contamination < 0 || contamination > 1){
|
||||
throw new UserException.MalformedFile("Contamination file contains unacceptable contamination value (must be 0<=x<=1): " + line);
|
||||
}
|
||||
if (AvailableSampleIDs==null || AvailableSampleIDs.contains(fields[0])) {// only add samples if they are in the sampleSet (or if it is null)
|
||||
sampleContamination.put(fields[0], contamination);
|
||||
}
|
||||
else {
|
||||
nonSamplesInContaminationFile.add(fields[0]);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
throw new UserException.MalformedFile("Contamination file contains unparsable double in the second field. Offending line: " + line);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//output to the user info lines telling which samples are in the Contamination File
|
||||
if (sampleContamination.size() > 0) {
|
||||
logger.info(String.format("The following samples were found in the Contamination file and will be processed at the contamination level therein: %s", sampleContamination.keySet().toString()));
|
||||
|
||||
//output to the user info lines telling which samples are NOT in the Contamination File
|
||||
if(AvailableSampleIDs!=null){
|
||||
Set<String> samplesNotInContaminationFile = new HashSet<String>(AvailableSampleIDs);
|
||||
samplesNotInContaminationFile.removeAll(sampleContamination.keySet());
|
||||
if (samplesNotInContaminationFile.size() > 0)
|
||||
logger.info(String.format("The following samples were NOT found in the Contamination file and will be processed at the default contamination level: %s", samplesNotInContaminationFile.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
//output to the user Samples that do not have lines in the Contamination File
|
||||
if (nonSamplesInContaminationFile.size() > 0) {
|
||||
logger.info(String.format("The following entries were found in the Contamination file but were not SAMPLEIDs. They will be ignored: %s", nonSamplesInContaminationFile.toString()));
|
||||
}
|
||||
|
||||
return sampleContamination;
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new StingException("I/O Error while reading sample-contamination file " + ContaminationFractionFile.getName() + ": " + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (c) 2012 The Broad Institute
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.broadinstitute.sting.utils.collections;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Created with IntelliJ IDEA.
|
||||
* User: farjoun
|
||||
* Date: 10/30/12
|
||||
* Time: 3:20 PM
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
|
||||
//lifted from http://stackoverflow.com/questions/7519339
|
||||
//could also use org.apache.commons.collections.map.DefaultedMap http://commons.apache.org/collections/apidocs/org/apache/commons/collections/map/DefaultedMap.html
|
||||
public class DefaultHashMap<K,V> extends HashMap<K,V> {
|
||||
|
||||
public void setDefaultValue(V defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
protected V defaultValue;
|
||||
public DefaultHashMap(V defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
@Override
|
||||
public V get(Object k) {
|
||||
V v = super.get(k);
|
||||
return ((v == null) && !this.containsKey(k)) ? this.defaultValue : v;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
* Copyright (c) 2010 The Broad Institute
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.broadinstitute.sting.utils.collections;
|
||||
|
||||
|
||||
// the imports for unit testing.
|
||||
|
||||
import org.broadinstitute.sting.BaseTest;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
||||
/**
|
||||
* Basic unit test for DefaultHashMap
|
||||
*/
|
||||
public class DefaultHashMapUnitTest extends BaseTest {
|
||||
DefaultHashMap<String, Double> empty, hasOne, hasTen;
|
||||
Double initialDefault = 10.0;
|
||||
|
||||
@BeforeMethod
|
||||
public void before() {
|
||||
empty = new DefaultHashMap<String, Double>(initialDefault);
|
||||
|
||||
hasOne = new DefaultHashMap<String, Double>(initialDefault);
|
||||
hasOne.put("1", .1);
|
||||
|
||||
hasTen = new DefaultHashMap<String, Double>(initialDefault);
|
||||
for (Integer i = 1; i <= 10; i++) {
|
||||
hasTen.put(i.toString(), i.doubleValue() / 10);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicSizes() {
|
||||
logger.warn("Executing testBasicSizes");
|
||||
|
||||
Assert.assertEquals(0, empty.size());
|
||||
Assert.assertEquals(1, hasOne.size());
|
||||
Assert.assertEquals(10, hasTen.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTenElements() {
|
||||
logger.warn("Executing testTenElements");
|
||||
|
||||
for (Integer i = 1; i <= 10; i++) {
|
||||
Assert.assertEquals(i.doubleValue() / 10, hasTen.get(i.toString()));
|
||||
}
|
||||
Assert.assertEquals(initialDefault, hasTen.get("0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClear() {
|
||||
logger.warn("Executing testClear");
|
||||
|
||||
empty.clear();
|
||||
hasOne.clear();
|
||||
hasTen.clear();
|
||||
|
||||
Assert.assertEquals(0, empty.size());
|
||||
Assert.assertEquals(0, hasOne.size());
|
||||
Assert.assertEquals(0, hasTen.size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSettingTenElements() {
|
||||
logger.warn("Executing testSettingTenElements");
|
||||
|
||||
Assert.assertEquals(10, hasTen.size());
|
||||
for (Integer i = 1; i <= 10; i++) {
|
||||
hasTen.put(i.toString(), i.doubleValue());
|
||||
}
|
||||
|
||||
Assert.assertEquals(10, hasTen.size());
|
||||
for (Integer i = 1; i <= 10; i++) {
|
||||
Assert.assertEquals(i.doubleValue(), hasTen.get(i.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSettingDefault() {
|
||||
logger.warn("Executing testSettingDefault");
|
||||
|
||||
Assert.assertEquals(initialDefault, empty.get("0"));
|
||||
Assert.assertEquals(initialDefault, hasOne.get("0"));
|
||||
Assert.assertEquals(initialDefault, hasTen.get("0"));
|
||||
|
||||
empty.setDefaultValue(2 * initialDefault);
|
||||
hasOne.setDefaultValue(2 * initialDefault);
|
||||
hasTen.setDefaultValue(2 * initialDefault);
|
||||
|
||||
Assert.assertEquals(2 * initialDefault, empty.get("0"));
|
||||
Assert.assertEquals(2 * initialDefault, hasOne.get("0"));
|
||||
Assert.assertEquals(2 * initialDefault, hasTen.get("0"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdd() {
|
||||
logger.warn("Executing testAdd");
|
||||
|
||||
Assert.assertEquals(0, empty.size());
|
||||
|
||||
Double x = 1.0;
|
||||
empty.put(x.toString(), x / 10);
|
||||
Assert.assertEquals(1, empty.size());
|
||||
Assert.assertEquals(.1, empty.get(x.toString()));
|
||||
|
||||
x = 2.0;
|
||||
empty.put(x.toString(), x / 10);
|
||||
Assert.assertEquals(2, empty.size());
|
||||
Assert.assertEquals(.2, empty.get(x.toString()));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnset() {
|
||||
logger.warn("Executing testUnset1");
|
||||
|
||||
Assert.assertEquals(10, hasTen.size());
|
||||
Assert.assertEquals(.9, hasTen.get("9"));
|
||||
|
||||
hasTen.remove("9");
|
||||
|
||||
Assert.assertEquals(9, hasTen.size());
|
||||
Assert.assertEquals(initialDefault, hasTen.get("9"));
|
||||
|
||||
hasTen.remove("1");
|
||||
|
||||
Assert.assertEquals(8, hasTen.size());
|
||||
Assert.assertEquals(initialDefault, hasTen.get("1"));
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue