Fix 3rd-party library dependency issues in the HC/PairHMM tests

In general, test classes cannot use 3rd-party libraries that are not
also dependencies of the GATK proper without causing problems when,
at release time, we test that the GATK jar has been packaged correctly
with all required dependencies.

If a test class needs to use a 3rd-party library that is not a GATK
dependency, write wrapper methods in the GATK utils/* classes, and
invoke those wrapper methods from the test class.
This commit is contained in:
David Roazen 2013-12-06 13:16:55 -05:00
parent 70e2d21e12
commit 932cd3ada7
5 changed files with 24 additions and 16 deletions

View File

@ -47,7 +47,8 @@
package org.broadinstitute.sting.gatk.walkers.haplotypecaller;
import com.google.caliper.Param;
import org.apache.commons.codec.digest.DigestUtils;
import org.broadinstitute.sting.BaseTest;
import org.broadinstitute.sting.utils.Utils;
import org.broadinstitute.sting.utils.haplotype.Haplotype;
import org.broadinstitute.sting.utils.pairhmm.ActiveRegionTestDataSet;
import org.broadinstitute.sting.utils.sam.GATKSAMRecord;
@ -64,7 +65,7 @@ import java.util.*;
* Time: 2:48 PM
* To change this template use File | Settings | File Templates.
*/
public class ActiveRegionTestDataSetUnitTest {
public class ActiveRegionTestDataSetUnitTest extends BaseTest {
@ -419,6 +420,6 @@ public class ActiveRegionTestDataSetUnitTest {
"CTGGGAGCCTAAGGCATCACTCAAGATACAGGCTCGGTAACGTACGCTCTAGCCATCTAA" +
"CTATCCCCTATGTCTTATAGGGACCTACGTTATCTGCCTG";
protected final static String REF_MD5 = new String(DigestUtils.md5(REF));
protected final static String REF_MD5 = Utils.calcMD5(REF);
}

View File

@ -46,7 +46,6 @@
package org.broadinstitute.sting.gatk.walkers.haplotypecaller.graphs;
import org.apache.commons.lang.ArrayUtils;
import org.broadinstitute.sting.BaseTest;
import org.broadinstitute.sting.utils.MathUtils;
import org.broadinstitute.sting.utils.Utils;

View File

@ -49,14 +49,13 @@ package org.broadinstitute.sting.utils.pairhmm;
import net.sf.samtools.SAMFileHeader;
import net.sf.samtools.SAMSequenceDictionary;
import net.sf.samtools.SAMSequenceRecord;
import org.apache.commons.math.MathException;
import org.apache.commons.math.distribution.ExponentialDistribution;
import org.apache.commons.math.distribution.ExponentialDistributionImpl;
import org.broadinstitute.sting.gatk.walkers.haplotypecaller.AssemblyResult;
import org.broadinstitute.sting.gatk.walkers.haplotypecaller.AssemblyResultSet;
import org.broadinstitute.sting.gatk.walkers.haplotypecaller.Civar;
import org.broadinstitute.sting.gatk.walkers.haplotypecaller.readthreading.ReadThreadingGraph;
import org.broadinstitute.sting.utils.GenomeLocParser;
import org.broadinstitute.sting.utils.MathUtils;
import org.broadinstitute.sting.utils.QualityUtils;
import org.broadinstitute.sting.utils.haplotype.Haplotype;
import org.broadinstitute.sting.utils.sam.ArtificialSAMUtils;
@ -325,7 +324,7 @@ public class ActiveRegionTestDataSet {
this.setReadName(r.getReadName());
}
ExponentialDistribution indelLengthDist = new ExponentialDistributionImpl(1.0/0.9);
ExponentialDistribution indelLengthDist = MathUtils.exponentialDistribution(1.0 / 0.9);
public MyGATKSAMRecord(final GATKSAMRecord r, final Random rnd) {
super(r.getHeader(), r.getReferenceIndex(), r.getAlignmentStart(), (short) r.getReadNameLength(),
@ -390,7 +389,7 @@ public class ActiveRegionTestDataSet {
final int length;
try {
length = (int) Math.round(indelLengthDist.inverseCumulativeProbability(rnd.nextDouble()) + 1);
} catch (MathException e) {
} catch (Exception e) {
throw new RuntimeException(e);
}
return length;

View File

@ -27,6 +27,8 @@ package org.broadinstitute.sting.utils;
import com.google.java.contract.Ensures;
import com.google.java.contract.Requires;
import org.apache.commons.math.distribution.ExponentialDistribution;
import org.apache.commons.math.distribution.ExponentialDistributionImpl;
import org.broadinstitute.sting.gatk.GenomeAnalysisEngine;
import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
@ -1510,4 +1512,7 @@ public class MathUtils {
return dirichletMultinomial(params,sum(params),counts,(int) sum(counts));
}
public static ExponentialDistribution exponentialDistribution( final double mean ) {
return new ExponentialDistributionImpl(mean);
}
}

View File

@ -744,7 +744,7 @@ public class Utils {
/**
* @see #calcMD5(byte[])
*/
public static String calcMD5(final String s) throws NoSuchAlgorithmException {
public static String calcMD5(final String s) {
return calcMD5(s.getBytes());
}
@ -753,17 +753,21 @@ public class Utils {
*
* @param bytes the bytes to calculate the md5 of
* @return the md5 of bytes, as a 32-character long string
* @throws NoSuchAlgorithmException
*/
@Ensures({"result != null", "result.length() == 32"})
public static String calcMD5(final byte[] bytes) throws NoSuchAlgorithmException {
public static String calcMD5(final byte[] bytes) {
if ( bytes == null ) throw new IllegalArgumentException("bytes cannot be null");
final byte[] thedigest = MessageDigest.getInstance("MD5").digest(bytes);
final BigInteger bigInt = new BigInteger(1, thedigest);
try {
final byte[] thedigest = MessageDigest.getInstance("MD5").digest(bytes);
final BigInteger bigInt = new BigInteger(1, thedigest);
String md5String = bigInt.toString(16);
while (md5String.length() < 32) md5String = "0" + md5String; // pad to length 32
return md5String;
String md5String = bigInt.toString(16);
while (md5String.length() < 32) md5String = "0" + md5String; // pad to length 32
return md5String;
}
catch ( NoSuchAlgorithmException e ) {
throw new IllegalStateException("MD5 digest algorithm not present");
}
}
/**