Merge branch 'master' of gsa2:/humgen/gsa-scr1/chartl/dev/unstable

This commit is contained in:
Chris Hartl 2013-01-02 11:39:53 -05:00
commit 7188a4a921
21 changed files with 317 additions and 3285 deletions

View File

@ -111,10 +111,9 @@
<!-- clover parameters -->
<property name="clover.jar" location="private/resources/clover/lib/clover.jar"/>
<property name="clover.instrument.level" location="method"/>
<property name="clover.instrument.level" value="method"/>
<taskdef resource="cloverlib.xml" classpath="${clover.jar}"/>
<!-- ******************************************************************************** -->
<!-- Filesets and paths -->
<!-- ******************************************************************************** -->
@ -273,19 +272,19 @@
<!-- Comment out the following lines to build the GATK without a network connection, assuming you have all of the libraries cached already -->
<!-- <get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/${ivy.jar.file}" -->
<!-- dest="${ivy.jar.dir}/${ivy.jar.file}" -->
<!-- usetimestamp="true"/> -->
<!-- <taskdef resource="org/apache/ivy/ant/antlib.xml" -->
<!-- uri="antlib:org.apache.ivy.ant" -->
<!-- classpath="${ivy.jar.dir}/${ivy.jar.file}"/> -->
<get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/${ivy.jar.file}"
dest="${ivy.jar.dir}/${ivy.jar.file}"
usetimestamp="true"/>
<taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant"
classpath="${ivy.jar.dir}/${ivy.jar.file}"/>
<!-- <get src="http://repo1.maven.org/maven2/org/apache/maven/maven-ant-tasks/${maven-ant-tasks.install.version}/${maven-ant-tasks.jar.file}" -->
<!-- dest="${ivy.jar.dir}/${maven-ant-tasks.jar.file}" -->
<!-- usetimestamp="true"/> -->
<!-- <taskdef resource="org/apache/maven/artifact/ant/antlib.xml" -->
<!-- uri="antlib:antlib:org.apache.maven.artifact.ant" -->
<!-- classpath="${ivy.jar.dir}/${maven-ant-tasks.jar.file}"/> -->
<get src="http://repo1.maven.org/maven2/org/apache/maven/maven-ant-tasks/${maven-ant-tasks.install.version}/${maven-ant-tasks.jar.file}"
dest="${ivy.jar.dir}/${maven-ant-tasks.jar.file}"
usetimestamp="true"/>
<taskdef resource="org/apache/maven/artifact/ant/antlib.xml"
uri="antlib:antlib:org.apache.maven.artifact.ant"
classpath="${ivy.jar.dir}/${maven-ant-tasks.jar.file}"/>
<!-- End network lines -->
@ -1031,6 +1030,14 @@
<delete dir="${scaladoc.dir}" />
</target>
<target name="-check.clover">
<available property="clover.installed" classname="com.cenqua.clover.CloverInstr" />
</target>
<target name="clean.clover" depends="-check.clover" if="clover.installed">
<clover-clean/>
</target>
<target name="clean.gsalib">
<!-- Currently not cleaning out the lib during 'ant clean' -->
<exec executable="R" failonerror="false">
@ -1038,7 +1045,7 @@
</exec>
</target>
<target name="clean" description="clean up" depends="clean.javadoc,clean.scaladoc,clean.gatkdocs">
<target name="clean" description="clean up" depends="clean.javadoc,clean.scaladoc,clean.gatkdocs,clean.clover">
<delete dir="${build.dir}"/>
<delete dir="${lib.dir}"/>
<delete dir="${contract.dump.dir}"/>
@ -1135,12 +1142,35 @@
<!-- Test targets -->
<target name="clover.clean">
<clover-clean/>
</target>
<target name="clover.report">
<clover-html-report outdir="clover_html" title="GATK Clover report"/>
<clover-report coverageCacheSize="nocache">
<current outfile="clover_html" title="GATK clover report" showUniqueCoverage="false" numThreads="4">
<format type="html" filter="catch,static,property"/>
<fileset dir="public">
<patternset id="clover.excludes">
<exclude name="**/*UnitTest.java"/>
<exclude name="**/*TestProvider*.java"/>
<exclude name="**/*PerformanceTest.java"/>
<exclude name="**/*Benchmark.java"/>
<exclude name="**/*LargeScaleTest.java"/>
<exclude name="**/*IntegrationTest.java"/>
<exclude name="**/jna/**/*.java"/>
<exclude name="**/queue/extensions/**/*.java"/>
<exclude name="**/sting/utils/help/*.java"/>
<exclude name="**/sting/tools/*.java"/>
<exclude name="**/datasources/reads/utilities/*.java"/>
<exclude name="**/sting/alignment/**/*.java"/>
<exclude name="**/examples/**/*.java"/>
</patternset>
</fileset>
<fileset dir="private">
<patternset refid="clover.excludes" />
</fileset>
<fileset dir="protected">
<patternset refid="clover.excludes" />
</fileset>
</current>
</clover-report>
</target>
<target name="with.clover">
@ -1148,6 +1178,7 @@
</clover-setup>
<property name="compile.scala" value="false" /> <!-- currently doesn't work with scala -->
<property name="test.maxmemory" value="32g"/> <!-- clover requires lots of memory -->
<echo message="Clover instrument level: ${clover.instrument.level}" />
</target>
<target name="test.init.compile">
@ -1247,7 +1278,7 @@
<jvmarg value="-Djava.awt.headless=true" />
<jvmarg value="-Dpipeline.run=${pipeline.run}" />
<jvmarg value="-Djava.io.tmpdir=${java.io.tmpdir}" />
<!-- <jvmarg line="${cofoja.jvm.args}"/> -->
<jvmarg line="${cofoja.jvm.args}"/>
<jvmarg line="${debug.jvm.args}"/>
<!-- NOTE: To run tests with debugging, use -Dtest.debug=true -Dtest.debug.port=XXXX on the command line -->

View File

@ -120,6 +120,11 @@ public class LikelihoodCalculationEngine {
for( int jjj = 0; jjj < numHaplotypes; jjj++ ) {
final Haplotype haplotype = haplotypes.get(jjj);
// TODO -- need to test against a reference/position with non-standard bases
if ( !Allele.acceptableAlleleBases(haplotype.getBases(), false) )
continue;
final int haplotypeStart = ( previousHaplotypeSeen == null ? 0 : computeFirstDifferingPosition(haplotype.getBases(), previousHaplotypeSeen.getBases()) );
previousHaplotypeSeen = haplotype;

View File

@ -284,7 +284,7 @@ public abstract class MicroScheduler implements MicroSchedulerMBean {
protected boolean abortExecution() {
final boolean abort = engine.exceedsRuntimeLimit(progressMeter.getRuntimeInNanoseconds(), TimeUnit.NANOSECONDS);
if ( abort ) {
final AutoFormattingTime aft = new AutoFormattingTime(TimeUnit.SECONDS.convert(engine.getRuntimeLimitInNanoseconds(), TimeUnit.NANOSECONDS), 1, 4);
final AutoFormattingTime aft = new AutoFormattingTime(engine.getRuntimeLimitInNanoseconds(), -1, 4);
logger.info("Aborting execution (cleanly) because the runtime has exceeded the requested maximum " + aft);
}
return abort;

View File

@ -50,7 +50,7 @@ public class ExactCallLogger implements Cloneable {
return String.format("ExactCall %s:%d alleles=%s nSamples=%s orig.pNonRef=%.2f orig.runtime=%s",
vc.getChr(), vc.getStart(), vc.getAlleles(), vc.getNSamples(),
originalCall.getLog10PosteriorOfAFGT0(),
new AutoFormattingTime(runtime / 1e9).toString());
new AutoFormattingTime(runtime).toString());
}
}

View File

@ -1,60 +0,0 @@
/*
* The MIT License
*
* Copyright (c) 2009 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.gatk.walkers.indels;
import net.sf.samtools.SAMRecord;
import net.sf.samtools.SAMRecordCoordinateComparator;
/**
* Extends Picard's Comparator for sorting SAMRecords by coordinate. This one actually deals with unmapped reads
* (among other things) sitting at the same position as their mates (so that they both can be put into the same set).
*/
public class SAMRecordCoordinateComparatorWithUnmappedReads extends SAMRecordCoordinateComparator {
public int compare(final SAMRecord samRecord1, final SAMRecord samRecord2) {
int cmp = fileOrderCompare(samRecord1, samRecord2);
if ( cmp != 0 )
return cmp;
// deal with unmapped reads
if ( samRecord1.getReadUnmappedFlag() != samRecord2.getReadUnmappedFlag() )
return (samRecord1.getReadUnmappedFlag()? 1: -1);
if ( samRecord1.getReadNegativeStrandFlag() != samRecord2.getReadNegativeStrandFlag() )
return (samRecord1.getReadNegativeStrandFlag()? 1: -1);
// even the names can be the same
cmp = samRecord1.getReadName().compareTo(samRecord2.getReadName());
if ( cmp != 0 )
return cmp;
if ( samRecord1.getDuplicateReadFlag() != samRecord2.getDuplicateReadFlag() )
return (samRecord1.getDuplicateReadFlag()? -1: 1);
if ( samRecord1.getReadPairedFlag() && samRecord2.getReadPairedFlag() && samRecord1.getFirstOfPairFlag() != samRecord2.getFirstOfPairFlag() )
return (samRecord1.getFirstOfPairFlag()? -1: 1);
// such a case was actually observed
return samRecord1.getMappingQuality() - samRecord2.getMappingQuality();
}
}

View File

@ -1,93 +0,0 @@
/*
* 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;
/**
* Represents a single amino acid.
*/
public class AminoAcid {
private String name;
private String threeLetterCode;
private String letter;
/**
* Constructor.
*
* @param letter The 1 letter code. (eg. I). This is '*' for the stop codon.
* @param name The full name of the AA (eg. Isoleucine).
* @param code The 3 letter code. (eg. Ile).
*/
public AminoAcid( String letter, String name, String code) {
this.name = name;
this.threeLetterCode = code;
this.letter = letter;
}
/** Equality based on the amino acid code. */
public boolean equals(Object o) {
if (this == o) { return true; }
if (o == null || !(o instanceof AminoAcid)) { return false; }
final AminoAcid aminoAcid = (AminoAcid) o;
return !(getCode() != null ? !getCode().equals(aminoAcid.getCode()) : aminoAcid.getCode() != null);
}
/** Hashes the three letter code. */
public int hashCode() {
return (getCode() != null ? getCode().hashCode() : 0);
}
/**
* Returns the full name of this AA.
*/
public String getName() { return name; }
/**
* Returns the 1 letter code for this AA.
*/
public String getLetter() { return letter; }
/**
* Returns the 3 letter code.
*/
public String getCode() { return threeLetterCode; }
/** Returns true if the amino acid is really just a stop codon. */
public boolean isStop() {
return "*".equals(getLetter());
}
/** Returns true if the amino acid is really just a stop codon. */
public boolean isUnknown() {
return "X".equals(getLetter());
}
public String toString() {
return name;
}
}

View File

@ -1,214 +0,0 @@
/*
* 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;
import java.util.HashMap;
/**
* A simple {codon -> amino acid name} lookup table.
* Handles differences between mitochondrial and nuclear genes.
*/
public class AminoAcidTable {
protected static final AminoAcid UNKNOWN = new AminoAcid("X" , "Unknown", "Unk");
protected static final AminoAcid ISOLEUCINE = new AminoAcid("I" , "Isoleucine", "Ile");
protected static final AminoAcid LEUCINE = new AminoAcid("L" , "Leucine", "Leu");
protected static final AminoAcid VALINE = new AminoAcid("V" , "Valine", "Val");
protected static final AminoAcid PHENYLALANINE = new AminoAcid("F" , "Phenylalanine", "Phe");
protected static final AminoAcid METHIONINE = new AminoAcid("M" , "Methionine", "Met");
protected static final AminoAcid CYSTEINE = new AminoAcid("C" , "Cysteine", "Cys");
protected static final AminoAcid ALANINE = new AminoAcid("A" , "Alanine", "Ala");
protected static final AminoAcid STOP_CODON = new AminoAcid("*" , "Stop Codon", "Stop");
protected static final AminoAcid GLYCINE = new AminoAcid("G" , "Glycine", "Gly");
protected static final AminoAcid PROLINE = new AminoAcid("P" , "Proline", "Pro");
protected static final AminoAcid THEONINE = new AminoAcid("T" , "Threonine", "Thr");
protected static final AminoAcid SERINE = new AminoAcid("S" , "Serine", "Ser");
protected static final AminoAcid TYROSINE = new AminoAcid("Y" , "Tyrosine", "Tyr");
protected static final AminoAcid TRYPTOPHAN = new AminoAcid("W" , "Tryptophan", "Trp");
protected static final AminoAcid GLUTAMINE = new AminoAcid("Q" , "Glutamine", "Gln");
protected static final AminoAcid ASPARAGINE = new AminoAcid("N" , "Asparagine", "Asn");
protected static final AminoAcid HISTIDINE = new AminoAcid("H" , "Histidine", "His");
protected static final AminoAcid GLUTAMIC_ACID = new AminoAcid("E" , "Glutamic acid", "Glu");
protected static final AminoAcid ASPARTIC_ACID = new AminoAcid("D" , "Aspartic acid", "Asp");
protected static final AminoAcid LYSINE = new AminoAcid("K" , "Lysine", "Lys");
protected static final AminoAcid ARGININE = new AminoAcid("R" , "Arginine", "Arg");
protected static HashMap<String, AminoAcid> aminoAcidTable = new HashMap<String, AminoAcid>();
protected static HashMap<String, AminoAcid> mitochondrialAminoAcidTable = new HashMap<String, AminoAcid>();
static {
//populate the tables
aminoAcidTable.put("ATT", ISOLEUCINE);
aminoAcidTable.put("ATC", ISOLEUCINE);
aminoAcidTable.put("ATA", ISOLEUCINE);
aminoAcidTable.put("CTT", LEUCINE);
aminoAcidTable.put("CTC", LEUCINE);
aminoAcidTable.put("CTA", LEUCINE);
aminoAcidTable.put("CTG", LEUCINE);
aminoAcidTable.put("TTA", LEUCINE);
aminoAcidTable.put("TTG", LEUCINE);
aminoAcidTable.put("GTT", VALINE);
aminoAcidTable.put("GTC", VALINE);
aminoAcidTable.put("GTA", VALINE);
aminoAcidTable.put("GTG", VALINE);
aminoAcidTable.put("TTT", PHENYLALANINE);
aminoAcidTable.put("TTC", PHENYLALANINE);
aminoAcidTable.put("ATG", METHIONINE);
aminoAcidTable.put("TGT", CYSTEINE);
aminoAcidTable.put("TGC", CYSTEINE);
aminoAcidTable.put("GCT", ALANINE);
aminoAcidTable.put("GCC", ALANINE);
aminoAcidTable.put("GCA", ALANINE);
aminoAcidTable.put("GCG", ALANINE);
aminoAcidTable.put("GGT", GLYCINE);
aminoAcidTable.put("GGC", GLYCINE);
aminoAcidTable.put("GGA", GLYCINE);
aminoAcidTable.put("GGG", GLYCINE);
aminoAcidTable.put("CCT", PROLINE);
aminoAcidTable.put("CCC", PROLINE);
aminoAcidTable.put("CCA", PROLINE);
aminoAcidTable.put("CCG", PROLINE);
aminoAcidTable.put("ACT", THEONINE);
aminoAcidTable.put("ACC", THEONINE);
aminoAcidTable.put("ACA", THEONINE);
aminoAcidTable.put("ACG", THEONINE);
aminoAcidTable.put("TCT", SERINE);
aminoAcidTable.put("TCC", SERINE);
aminoAcidTable.put("TCA", SERINE);
aminoAcidTable.put("TCG", SERINE);
aminoAcidTable.put("AGT", SERINE);
aminoAcidTable.put("AGC", SERINE);
aminoAcidTable.put("TAT", TYROSINE);
aminoAcidTable.put("TAC", TYROSINE);
aminoAcidTable.put("TGG", TRYPTOPHAN);
aminoAcidTable.put("CAA", GLUTAMINE);
aminoAcidTable.put("CAG", GLUTAMINE);
aminoAcidTable.put("AAT", ASPARAGINE);
aminoAcidTable.put("AAC", ASPARAGINE);
aminoAcidTable.put("CAT", HISTIDINE);
aminoAcidTable.put("CAC", HISTIDINE);
aminoAcidTable.put("GAA", GLUTAMIC_ACID);
aminoAcidTable.put("GAG", GLUTAMIC_ACID);
aminoAcidTable.put("GAT", ASPARTIC_ACID);
aminoAcidTable.put("GAC", ASPARTIC_ACID);
aminoAcidTable.put("AAA", LYSINE);
aminoAcidTable.put("AAG", LYSINE);
aminoAcidTable.put("CGT", ARGININE);
aminoAcidTable.put("CGC", ARGININE);
aminoAcidTable.put("CGA", ARGININE);
aminoAcidTable.put("CGG", ARGININE);
aminoAcidTable.put("AGA", ARGININE);
aminoAcidTable.put("AGG", ARGININE);
aminoAcidTable.put("TAA", STOP_CODON );
aminoAcidTable.put("TAG", STOP_CODON);
aminoAcidTable.put("TGA", STOP_CODON);
//populate the mitochondrial AA table
mitochondrialAminoAcidTable.putAll(aminoAcidTable);
mitochondrialAminoAcidTable.put("AGA", STOP_CODON);
mitochondrialAminoAcidTable.put("AGG", STOP_CODON);
mitochondrialAminoAcidTable.put("ATA", METHIONINE);
mitochondrialAminoAcidTable.put("TGA", TRYPTOPHAN);
}
/**
* Returns the amino acid encoded by the given codon in a eukaryotic genome.
*
* @param codon The 3-letter mRNA nucleotide codon 5' to 3'. Expects T's instead of U's. Not case sensitive.
*
* @return The amino acid matching the given codon, or the UNKNOWN amino acid if the codon string doesn't match anything
*/
public static AminoAcid getEukaryoticAA(String codon) {
codon = codon.toUpperCase();
final AminoAcid aa = aminoAcidTable.get(codon);
return aa == null ? UNKNOWN : aa;
}
/**
* Returns the amino acid encoded by the given codon in a mitochondrial genome.
*
* @param codon The 3-letter mRNA nucleotide codon 5' to 3'. Expects T's instead of U's. Not case sensitive.
* @param isFirstCodon If this is the 1st codon in the gene, then "ATT" encodes Methyonine
*
* @return The amino acid matching the given codon in mitochondrial genes, or the UNKNOWN amino acid if the codon string doesn't match anything
*/
public static AminoAcid getMitochondrialAA(String codon, boolean isFirstCodon) {
codon = codon.toUpperCase();
final AminoAcid aa = mitochondrialAminoAcidTable.get(codon);
if(aa == null) {
return UNKNOWN;
} else if(isFirstCodon && codon.equals("ATT")) {
return METHIONINE; //special case - 'ATT' in the first codon of a mitochondrial gene codes for methionine instead of isoleucine
} else {
return aa;
}
}
}

View File

@ -1,32 +1,104 @@
package org.broadinstitute.sting.utils;
import java.util.concurrent.TimeUnit;
/**
* Simple utility class that makes it convenient to print unit adjusted times
* Conveniently print a time with an automatically determined time unit
*
* For example, if the amount of time is 10^6 seconds, instead of printing
* out 10^6 seconds, prints out 11.57 days instead.
*
* Dynamically uses time units:
*
* - seconds: s
* - minutes: m
* - hours : h
* - days : d
* - weeks : w
*
* @author depristo
* @since 2009
*/
public class AutoFormattingTime {
private static final double NANOSECONDS_PER_SECOND = 1e9;
/**
* Width a la format's %WIDTH.PERCISIONf
*/
private final int width; // for format
/**
* Precision a la format's %WIDTH.PERCISIONf
*/
private final int precision; // for format
double timeInSeconds; // in Seconds
private final String formatString;
/**
* The elapsed time in nanoseconds
*/
private final long nanoTime;
/**
* Create a new autoformatting time with elapsed time nanoTime in nanoseconds
* @param nanoTime the elapsed time in nanoseconds
* @param width the width >= 0 (a la format's %WIDTH.PERCISIONf) to use to display the format, or -1 if none is required
* @param precision the precision to display the time at. Must be >= 0;
*/
public AutoFormattingTime(final long nanoTime, final int width, int precision) {
if ( width < -1 ) throw new IllegalArgumentException("Width " + width + " must be >= -1");
if ( precision < 0 ) throw new IllegalArgumentException("Precision " + precision + " must be >= 0");
public AutoFormattingTime(double timeInSeconds, final int width, int precision) {
this.width = width;
this.timeInSeconds = timeInSeconds;
this.nanoTime = nanoTime;
this.precision = precision;
this.formatString = "%" + width + "." + precision + "f %s";
}
public AutoFormattingTime(double timeInSeconds, int precision) {
this(timeInSeconds, 6, precision);
/**
* @see #AutoFormattingTime(long, int, int) but with default width and precision
* @param nanoTime
*/
public AutoFormattingTime(final long nanoTime) {
this(nanoTime, 6, 1);
}
/**
* @see #AutoFormattingTime(long, int, int) but with time specificied as a double in seconds
*/
public AutoFormattingTime(final double timeInSeconds, final int width, final int precision) {
this(secondsToNano(timeInSeconds), width, precision);
}
/**
* @see #AutoFormattingTime(long) but with time specificied as a double in seconds
*/
public AutoFormattingTime(double timeInSeconds) {
this(timeInSeconds, 1);
this(timeInSeconds, 6, 1);
}
/**
* Precomputed format string suitable for string.format with the required width and precision
*/
private String getFormatString() {
final StringBuilder b = new StringBuilder("%");
if ( width != -1 )
b.append(width);
b.append(".").append(precision).append("f %s");
return b.toString();
}
/**
* Get the time associated with this object in nanoseconds
* @return the time in nanoseconds
*/
public long getTimeInNanoSeconds() {
return nanoTime;
}
/**
* Get the time associated with this object in seconds, as a double
* @return time in seconds as a double
*/
public double getTimeInSeconds() {
return timeInSeconds;
return TimeUnit.NANOSECONDS.toSeconds(getTimeInNanoSeconds());
}
/**
@ -44,15 +116,16 @@ public class AutoFormattingTime {
}
/**
* Instead of 10000 s, returns 2.8 hours
* @return
* Get a string representation of this time, automatically converting the time
* to a human readable unit with width and precision provided during construction
* @return a non-null string
*/
public String toString() {
double unitTime = timeInSeconds;
double unitTime = getTimeInSeconds();
String unit = "s";
if ( timeInSeconds > 120 ) {
unitTime = timeInSeconds / 60; // minutes
if ( unitTime > 120 ) {
unitTime /= 60; // minutes
unit = "m";
if ( unitTime > 120 ) {
@ -64,13 +137,24 @@ public class AutoFormattingTime {
unit = "d";
if ( unitTime > 20 ) {
unitTime /= 7; // days
unitTime /= 7; // weeks
unit = "w";
}
}
}
}
return String.format(formatString, unitTime, unit);
return String.format(getFormatString(), unitTime, unit);
}
/**
* Convert a time in seconds as a double into nanoseconds as a long
* @param timeInSeconds an elapsed time in seconds, as a double
* @return an equivalent value in nanoseconds as a long
*/
private static long secondsToNano(final double timeInSeconds) {
return (long)(NANOSECONDS_PER_SECOND * timeInSeconds);
}
}

View File

@ -1,231 +0,0 @@
/*
* 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;
import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
/** This class, closely resembling a deque (except that it is not dynamically grown),
* provides an object with array-like interface and efficient
* implementation of shift operation. Use this class when some kind of sliding window is required:
* e.g. an array (window) is populated from some stream of data, and then the window is shifted.
* If most of the data in the window remains the same so that only a few old elements sjould be popped from
* and a few new elements pushed onto the array, both re-populating the whole array from the data and
* shifting a regular array would be grossly inefficient. Instead, shiftData(int N) method of circular array
* efficiently pops out N first elements and makes last N elements available.
*
* Consider an example of reading a character stream A,B,C,D,....,Z into an array with requirement of keeping
* last 5 letters. First, we would read first 5 letters same way as we would with a regular array:<br><br>
*
* <code>
* CircularArray a(5);<br>
* for ( int i = 0; i < 5; i++ ) a.set(i, readChar());<br>
* </code>
* <br>
* and then on the arrival of each next character we shift the array:<br><br>
*
* <code>
* a.shiftData(1); a.set(4, readChar() );<br>
* </code>
* <br>
* After the lines from the above example are executed, the array will <i>logically</i> look as:<br>
*
* B,C,D,E,F,<br><br>
*
* e.g. as if we had a regular array, shifted it one element down and added new element on the top.
*
*
* @author asivache
*
*/
public class CircularArray <T> {
private Object[] data ;
private int offset;
/** Creates an array of fixed length */
public CircularArray(int length) {
if ( length <= 0 ) throw new ReviewedStingException("CircularArray length must be positive. Passed: "+length);
data = new Object[length];
offset = 0;
}
/** Returns length of the array */
public int length() {
return data.length;
}
/** Gets i-th element of the array
*
* @throws IndexOutOfBoundsException if value of i is illegal
*/
@SuppressWarnings("unchecked")
public T get(int i) {
if ( i < 0 || i >= data.length )
throw new IndexOutOfBoundsException("Length of CircularArray: "+data.length+"; element requested: "+i);
return (T)(data [ ( offset + i ) % data.length ]);
}
/** Sets i-th element of the array to the specified value.
*
* @throws IndexOutOfBoundsException if value of i is illegal
*/
public void set(int i, T value) {
if ( i < 0 || i >= data.length )
throw new IndexOutOfBoundsException("Length of CircularArray: "+data.length+"; set element request at: "+i);
data [ ( offset + i ) % data.length ] = value;
}
/** Set all elements to null.
*
*/
public void clear() {
for ( int i = 0 ; i < data.length ; i++ ) data[i] = null;
offset = 0;
}
/** Efficient shift-down of the array data. After this operation, array.get(0), array.get(1), etc will
* be returning what array.get(shift), array.get(shift+1),... were returning before the shift was performed,
* and last shift elements of the array will be reset to 0.
* @param shift
*/
public void shiftData(int shift) {
if ( shift >= data.length ) {
// if we shift by more than the length of stored data, we lose
// all that data completely, so we just re-initialize the array.
// This is not the operating mode CircularArray is intended for
// but we can handle it, just in case.
for ( int i = 0 ; i < data.length ; i++ ) data[i] = null;
offset = 0;
return;
}
// shift < data.length, so at least some data should be preserved
final int newOffset = ( offset+shift ) % data.length;
if ( newOffset < offset ) {
// wrap-around!
for ( int i = offset ; i < data.length ; i++ ) data[i] = null;
for ( int i = 0; i < newOffset ; i++ ) data[i] = null;
} else {
for ( int i = offset ; i < newOffset ; i++ ) data[i] = null;
}
offset = newOffset;
}
/** Implements primitive int type-based circular array. See CircularArray for details.
*
* @author asivache
*
*/
public static class Int {
private int [] data ;
private int offset;
/** Creates an array of fixed length */
public Int(int length) {
if ( length <= 0 ) throw new ReviewedStingException("CircularArray length must be positive. Passed: "+length);
data = new int[length]; // automaticaly initialized to zeros
offset = 0;
}
/** Returns length of the array */
public int length() {
return data.length;
}
/** Gets i-th element of the array
*
* @throws IndexOutOfBoundsException if value of i is illegal
*/
public int get(int i) {
if ( i < 0 || i >= data.length )
throw new IndexOutOfBoundsException("Length of CircularArray: "+data.length+"; element requested: "+i);
return data [ ( offset + i ) % data.length ];
}
/** Sets i-th element of the array to the specified value.
*
* @throws IndexOutOfBoundsException if value of i is illegal
*/
public void set(int i, int value) {
if ( i < 0 || i >= data.length )
throw new IndexOutOfBoundsException("Length of CircularArray: "+data.length+"; set element request at: "+i);
data [ ( offset + i ) % data.length ] = value;
}
/** Increments i-th element of the array by the specified value (value can be negative).
*
* @throws IndexOutOfBoundsException if i is illegal
*/
public void increment(int i, int value) {
if ( i < 0 || i >= data.length )
throw new IndexOutOfBoundsException("Length of CircularArray: "+data.length+"; increment element request at: "+i);
data [ ( offset + i ) % data.length ] += value;
}
/** Set all elements to 0.
*
*/
public void clear() {
for ( int i = 0 ; i < data.length ; i++ ) data[i] = 0;
offset = 0;
}
/** Efficient shift-down of the array data. After this operation, array.get(0), array.get(1), etc will
* be returning what array.get(shift), array.get(shift+1),... were returning before the shift was performed,
* and last shift elements of the array will be reset to 0.
* @param shift
*/
public void shiftData(int shift) {
if ( shift >= data.length ) {
// if we shift by more than the length of stored data, we lose
// all that data completely, so we just re-initialize the array.
// This is not the operating mode CircularArray is intended for
// but we can handle it, just in case.
for ( int i = 0 ; i < data.length ; i++ ) data[i] = 0;
offset = 0;
return;
}
// shift < data.length, so at least some data should be preserved
final int newOffset = ( offset+shift ) % data.length;
if ( newOffset < offset ) {
// wrap-around!
for ( int i = offset ; i < data.length ; i++ ) data[i] = 0;
for ( int i = 0; i < newOffset ; i++ ) data[i] = 0;
} else {
for ( int i = offset ; i < newOffset ; i++ ) data[i] = 0;
}
offset = newOffset;
}
}
}

View File

@ -1,195 +0,0 @@
/*
* 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.interval;
import org.broadinstitute.sting.gatk.iterators.PushbackIterator;
import org.broadinstitute.sting.utils.GenomeLoc;
import java.util.Iterator;
/**
* Created by IntelliJ IDEA.
* User: asivache
* Date: Oct 7, 2010
* Time: 2:40:02 PM
* To change this template use File | Settings | File Templates.
*/
/** This class provides an adapter to Iterator<GenomeLoc> that returns only (parts of) underlying iterator's
* intervals overlapping with specified "master set" of bounding intervals. The underlying iterator must return
* NON-overlapping intervals in coordinate-sorted order, otherwise the behavior is unspecified. If the master set is represented by
* another interval iterator, it should return sorted and NON-overlapping intervals.
*
*/
public class OverlappingIntervalIterator implements Iterator<GenomeLoc> {
PushbackIterator<GenomeLoc> iter = null;
PushbackIterator<GenomeLoc> boundBy = null;
GenomeLoc prefetchedOverlap = null;
GenomeLoc currentBound = null;
GenomeLoc currentInterval = null;
/** Creates new overlapping iterator that will internally traverse <code>intervals</code> and return only
* overlaps of those with set of intervals returned by <code>boundBy</code>.
* @param intervals
* @param boundBy
*/
public OverlappingIntervalIterator(Iterator<GenomeLoc> intervals, Iterator<GenomeLoc> boundBy) {
this.iter = new PushbackIterator<GenomeLoc>(intervals);
this.boundBy = new PushbackIterator<GenomeLoc>(boundBy);
if ( iter.hasNext() && boundBy.hasNext() ) {
currentInterval = iter.next(); // load first interval
currentBound = boundBy.next(); // load first bounding interval
fetchNextOverlap();
}
}
/** Traverses both iterators in sync, until the first overlap between the two is reached. If no overlap is found
* until the end of the either of the two streams, leaves prefetchedOverlap set to null
*/
private void fetchNextOverlap() {
prefetchedOverlap = null;
// System.out.println("Fetching... (interval="+currentInterval+"; bound="+currentBound+")");
while ( currentInterval != null && currentBound != null ) {
if ( currentInterval.isBefore(currentBound) ) {
// System.out.println(currentInterval +" is before "+currentBound );
if ( ! iter.hasNext() ) currentInterval = null;
else currentInterval = iter.next();
continue;
}
if ( currentInterval.isPast(currentBound) ) {
// System.out.println(currentInterval +" is past "+currentBound );
if ( ! boundBy.hasNext() ) currentBound = null;
else currentBound = boundBy.next();
continue;
}
// we are at this point only if currentInterval overlaps with currentBound
prefetchedOverlap = currentInterval.intersect(currentBound);
// System.out.println("Fetched next overlap: "+prefetchedOverlap);
// now we need to advance at least one of the iterators, so that we would not
// call the same overlap again
// however we still do not know if we are done with either current interval or current bound, because
// two special situations are possible:
//
// 1) next interval overlaps with 2) current interval also overlaps with
// the same bounding interval; next bounding interval; note that
// note that in this case next in this case next bound necessarily
// interval necessarily starts before starts before the next interval
// the next bound
//
// curr. int next int. curr. int
// ----- ------ --------------------------
// ------------------- --------- -------------
// curr. bound curr. bound next bound
// To solve this issue we update either only currentInterval or only currentBound to their next value,
// whichever of those next values (intervals) comes first on the reference genome;
// the rest of the traversal to the next overlap will be performed on the next invocation of
// fetchNextOverlap().
advanceToNearest();
break; // now that we computed the overlap and advanced (at least one of) the intervals/bounds to
// the next location, we are done - bail out from the loop.
}
}
private void advanceToNearest() {
if ( ! iter.hasNext() ) {
currentBound = boundBy.hasNext() ? boundBy.next() : null;
} else {
if ( ! boundBy.hasNext() ) currentInterval = iter.hasNext() ? iter.next() : null;
else {
// both intervals and bounds have next value available; let's check which comes first:
GenomeLoc nextInterval = iter.next();
GenomeLoc nextBound = boundBy.next();
if ( nextInterval.compareTo(nextBound) < 0 ) {
currentInterval = nextInterval;
boundBy.pushback(nextBound);
} else {
currentBound = nextBound;
iter.pushback(nextInterval);
}
}
}
}
/**
* Returns <tt>true</tt> if the iteration has more elements. (In other
* words, returns <tt>true</tt> if <tt>next</tt> would return an element
* rather than throwing an exception.)
*
* @return <tt>true</tt> if the iterator has more elements.
*/
public boolean hasNext() {
return prefetchedOverlap != null;
}
/**
* Returns the next element in the iteration.
*
* @return the next element in the iteration.
* @throws java.util.NoSuchElementException
* iteration has no more elements.
*/
public GenomeLoc next() {
if ( prefetchedOverlap == null )
throw new java.util.NoSuchElementException("Illegal call to next(): Overlapping iterator has no more overlaps");
GenomeLoc ret = prefetchedOverlap; // cache current prefetched overlap
fetchNextOverlap(); // prefetch next overlap
return ret ;
}
/**
* Removes from the underlying collection the last element returned by the
* iterator (optional operation). This method can be called only once per
* call to <tt>next</tt>. The behavior of an iterator is unspecified if
* the underlying collection is modified while the iteration is in
* progress in any way other than by calling this method.
*
* @throws UnsupportedOperationException if the <tt>remove</tt>
* operation is not supported by this Iterator.
* @throws IllegalStateException if the <tt>next</tt> method has not
* yet been called, or the <tt>remove</tt> method has already
* been called after the last call to the <tt>next</tt>
* method.
*/
public void remove() {
throw new UnsupportedOperationException("remove() method is not supported by OverlappingIntervalIterator");
//To change body of implemented methods use File | Settings | File Templates.
}
}

View File

@ -69,12 +69,12 @@ public class RecalibrationReport {
}
protected RecalibrationReport(final QuantizationInfo quantizationInfo, final RecalibrationTables recalibrationTables, final GATKReportTable argumentTable, final RecalibrationArgumentCollection RAC) {
protected RecalibrationReport(final QuantizationInfo quantizationInfo, final RecalibrationTables recalibrationTables, final Covariate[] requestedCovariates, final GATKReportTable argumentTable, final RecalibrationArgumentCollection RAC) {
this.quantizationInfo = quantizationInfo;
this.recalibrationTables = recalibrationTables;
this.requestedCovariates = requestedCovariates;
this.argumentTable = argumentTable;
this.RAC = RAC;
this.requestedCovariates = null;
this.optionalCovariateIndexes = null;
}

View File

@ -50,7 +50,7 @@ import java.util.EnumSet;
public class CycleCovariate implements StandardCovariate {
private int MAXIMUM_CYCLE_VALUE;
private static final int CUSHION_FOR_INDELS = 4;
public static final int CUSHION_FOR_INDELS = 4;
private String default_platform = null;
private static final EnumSet<NGSPlatform> DISCRETE_CYCLE_PLATFORMS = EnumSet.of(NGSPlatform.ILLUMINA, NGSPlatform.SOLID, NGSPlatform.PACBIO, NGSPlatform.COMPLETE_GENOMICS);

View File

@ -236,18 +236,6 @@ public class AlignmentUtils {
return n;
}
public static int getNumAlignedBases(final SAMRecord r) {
int n = 0;
final Cigar cigar = r.getCigar();
if (cigar == null) return 0;
for (final CigarElement e : cigar.getCigarElements())
if (e.getOperator() == CigarOperator.M)
n += e.getLength();
return n;
}
public static int getNumAlignedBasesCountingSoftClips(final SAMRecord r) {
int n = 0;
final Cigar cigar = r.getCigar();
@ -512,47 +500,6 @@ public class AlignmentUtils {
return true;
}
/**
* Returns true is read is mapped and mapped uniquely (Q>0).
*
* @param read
* @return
*/
public static boolean isReadUniquelyMapped(SAMRecord read) {
return (!AlignmentUtils.isReadUnmapped(read)) && read.getMappingQuality() > 0;
}
/**
* Returns the array of base qualitites in the order the bases were read on the machine (i.e. always starting from
* cycle 1). In other words, if the read is unmapped or aligned in the forward direction, the read's own base
* qualities are returned as stored in the SAM record; if the read is aligned in the reverse direction, the array
* of read's base qualitites is inverted (in this case new array is allocated and returned).
*
* @param read
* @return
*/
public static byte[] getQualsInCycleOrder(SAMRecord read) {
if (isReadUnmapped(read) || !read.getReadNegativeStrandFlag()) return read.getBaseQualities();
return Utils.reverse(read.getBaseQualities());
}
/**
* Returns the array of original base qualitites (before recalibration) in the order the bases were read on the machine (i.e. always starting from
* cycle 1). In other words, if the read is unmapped or aligned in the forward direction, the read's own base
* qualities are returned as stored in the SAM record; if the read is aligned in the reverse direction, the array
* of read's base qualitites is inverted (in this case new array is allocated and returned). If no original base qualities
* are available this method will throw a runtime exception.
*
* @param read
* @return
*/
public static byte[] getOriginalQualsInCycleOrder(SAMRecord read) {
if (isReadUnmapped(read) || !read.getReadNegativeStrandFlag()) return read.getOriginalBaseQualities();
return Utils.reverse(read.getOriginalBaseQualities());
}
/**
* Takes the alignment of the read sequence <code>readSeq</code> to the reference sequence <code>refSeq</code>
* starting at 0-based position <code>refIndex</code> on the <code>refSeq</code> and specified by its <code>cigar</code>.

View File

@ -1,68 +0,0 @@
/*
* 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.sam;
import net.sf.samtools.SAMRecord;
public class ComparableSAMRecord implements Comparable<ComparableSAMRecord> {
private SAMRecord record;
public ComparableSAMRecord(SAMRecord record) {
this.record = record;
}
public SAMRecord getRecord() {
return record;
}
public int compareTo(ComparableSAMRecord o) {
// first sort by start position -- with not coverflow because both are guaranteed to be positive.
int comparison = record.getAlignmentStart() - o.record.getAlignmentStart();
// if the reads have the same start position, we must give a non-zero comparison
// (because java Sets often require "consistency with equals")
if ( comparison == 0 )
comparison = record.getReadName().compareTo(o.getRecord().getReadName());
// if the read names are the same, use the first of the pair if appropriate
if ( comparison == 0 && record.getReadPairedFlag() )
comparison = ( record.getFirstOfPairFlag() ? -1 : 1);
return comparison;
}
public boolean equals(Object obj) {
if ( !(obj instanceof ComparableSAMRecord) )
return false;
if ( this == obj )
return true;
ComparableSAMRecord csr = (ComparableSAMRecord)obj;
if(record.getAlignmentStart() != csr.record.getAlignmentStart())
return false;
if ( !record.getReadName().equals(csr.getRecord().getReadName()) )
return false;
return ( record.getFirstOfPairFlag() == csr.record.getFirstOfPairFlag() );
}
}

View File

@ -47,6 +47,8 @@ public class MisencodedBaseQualityReadTransformer extends ReadTransformer {
final byte[] quals = read.getBaseQualities();
for ( int i = 0; i < quals.length; i++ ) {
quals[i] -= encodingFixValue;
if ( quals[i] < 0 )
throw new UserException.BadInput("while fixing mis-encoded base qualities we encountered a read that was correctly encoded; we cannot handle such a mixture of reads so unfortunately the BAM must be fixed with some other tool");
}
read.setBaseQualities(quals);
return read;

View File

@ -133,7 +133,7 @@ public class ThreadEfficiencyMonitor {
*/
public synchronized void printUsageInformation(final Logger logger, final Priority priority) {
logger.debug("Number of threads monitored: " + getnThreadsAnalyzed());
logger.debug("Total runtime " + new AutoFormattingTime(TimeUnit.MILLISECONDS.toSeconds(getTotalTime())));
logger.debug("Total runtime " + new AutoFormattingTime(TimeUnit.MILLISECONDS.toNanos(getTotalTime())));
for ( final State state : State.values() ) {
logger.debug(String.format("\tPercent of time spent %s is %.2f", state.getUserFriendlyName(), getStatePercent(state)));
}

View File

@ -0,0 +1,117 @@
/*
* 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;
import org.broadinstitute.sting.utils.AutoFormattingTime;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* UnitTests for the AutoFormatting
*
* User: depristo
* Date: 8/24/12
* Time: 11:25 AM
* To change this template use File | Settings | File Templates.
*/
public class AutoFormattingTimeUnitTest extends BaseTest {
@DataProvider(name = "AutoFormattingTimeUnitSelection")
public Object[][] makeTimeData() {
List<Object[]> tests = new ArrayList<Object[]>();
tests.add(new Object[]{TimeUnit.SECONDS.toNanos(10), "s"});
tests.add(new Object[]{TimeUnit.MINUTES.toNanos(10), "m"});
tests.add(new Object[]{TimeUnit.HOURS.toNanos(10), "h"});
tests.add(new Object[]{TimeUnit.DAYS.toNanos(10), "d"});
tests.add(new Object[]{TimeUnit.DAYS.toNanos(1000), "w"});
return tests.toArray(new Object[][]{});
}
@Test(dataProvider = "AutoFormattingTimeUnitSelection")
public void testUnitSelection(final long nano, final String expectedUnit) throws InterruptedException {
final AutoFormattingTime time = new AutoFormattingTime(nano);
testBasic(time, nano, time.getWidth(), time.getPrecision());
Assert.assertTrue(time.toString().endsWith(expectedUnit), "TimeUnit " + time.toString() + " didn't contain expected time unit " + expectedUnit);
}
@Test(dataProvider = "AutoFormattingTimeUnitSelection")
public void testSecondsAsDouble(final long nano, final String expectedUnit) throws InterruptedException {
final double inSeconds = nano * 1e-9;
final long nanoFromSeconds = (long)(inSeconds * 1e9);
final AutoFormattingTime time = new AutoFormattingTime(inSeconds);
testBasic(time, nanoFromSeconds, time.getWidth(), time.getPrecision());
}
@DataProvider(name = "AutoFormattingTimeWidthAndPrecision")
public Object[][] makeTimeWidthAndPrecision() {
List<Object[]> tests = new ArrayList<Object[]>();
for ( final int width : Arrays.asList(-1, 1, 2, 6, 20) ) {
for ( final int precision : Arrays.asList(1, 2) ) {
tests.add(new Object[]{100.123456 * 1e9, width, precision});
tests.add(new Object[]{0.123456 * 1e9, width, precision});
}
}
return tests.toArray(new Object[][]{});
}
@Test(dataProvider = "AutoFormattingTimeWidthAndPrecision")
public void testWidthAndPrecision(final double inSeconds, final int width, final int precision) throws InterruptedException {
final AutoFormattingTime time = new AutoFormattingTime(inSeconds, width, precision);
final long nanoFromSeconds = (long)(inSeconds * 1e9);
testBasic(time, nanoFromSeconds, width, precision);
final Matcher match = matchToString(time);
match.matches();
final String widthString = match.group(1);
final String precisionString = match.group(2);
if ( width != -1 ) {
final int actualWidth = widthString.length() + 1 + precisionString.length();
Assert.assertTrue(actualWidth >= width, "width string '" + widthString + "' not >= the expected width " + width);
}
Assert.assertEquals(precisionString.length(), precision, "precision string '" + precisionString + "' not the expected precision " + precision);
}
private static Matcher matchToString(final AutoFormattingTime time) {
Pattern pattern = Pattern.compile("(\\s*\\d*)\\.(\\d*) \\w");
return pattern.matcher(time.toString());
}
private static void testBasic(final AutoFormattingTime aft, final long nano, final int expectedWidth, final int expectedPrecision) {
Assert.assertEquals(aft.getTimeInNanoSeconds(), nano);
assertEqualsDoubleSmart(aft.getTimeInSeconds(), nano * 1e-9, 1e-3, "Time in seconds not within tolerance of nanoSeconds");
Assert.assertEquals(aft.getWidth(), expectedWidth);
Assert.assertEquals(aft.getPrecision(), expectedPrecision);
Assert.assertNotNull(aft.toString(), "TimeUnit toString returned null");
final Matcher match = matchToString(aft);
Assert.assertTrue(match.matches(), "toString " + aft.toString() + " doesn't match our expected format");
}
}

View File

@ -301,7 +301,11 @@ public abstract class BaseTest {
Assert.assertTrue(actualSet.equals(expectedSet), info); // note this is necessary due to testng bug for set comps
}
public static final void assertEqualsDoubleSmart(final double actual, final double expected, final double tolerance) {
public static void assertEqualsDoubleSmart(final double actual, final double expected, final double tolerance) {
assertEqualsDoubleSmart(actual, expected, tolerance, null);
}
public static void assertEqualsDoubleSmart(final double actual, final double expected, final double tolerance, final String message) {
if ( Double.isNaN(expected) ) // NaN == NaN => false unfortunately
Assert.assertTrue(Double.isNaN(actual), "expected is nan, actual is not");
else if ( Double.isInfinite(expected) ) // NaN == NaN => false unfortunately
@ -309,7 +313,9 @@ public abstract class BaseTest {
else {
final double delta = Math.abs(actual - expected);
final double ratio = Math.abs(actual / expected - 1.0);
Assert.assertTrue(delta < tolerance || ratio < tolerance, "expected = " + expected + " actual = " + actual + " not within tolerance " + tolerance);
Assert.assertTrue(delta < tolerance || ratio < tolerance, "expected = " + expected + " actual = " + actual
+ " not within tolerance " + tolerance
+ (message == null ? "" : "message: " + message));
}
}
}

View File

@ -45,7 +45,7 @@ import java.util.*;
* Test the Active Region Traversal Contract
* http://iwww.broadinstitute.org/gsa/wiki/index.php/Active_Region_Traversal_Contract
*/
public class TraverseActiveRegionsTest extends BaseTest {
public class TraverseActiveRegionsUnitTest extends BaseTest {
private class DummyActiveRegionWalker extends ActiveRegionWalker<Integer, Integer> {
private final double prob;
@ -103,7 +103,8 @@ public class TraverseActiveRegionsTest extends BaseTest {
private List<GenomeLoc> intervals;
private static final String testBAM = "TraverseActiveRegionsTest.bam";
private static final String testBAM = "TraverseActiveRegionsUnitTest.bam";
private static final String testBAI = "TraverseActiveRegionsUnitTest.bai";
@BeforeClass
private void init() throws FileNotFoundException {
@ -117,7 +118,8 @@ public class TraverseActiveRegionsTest extends BaseTest {
// TODO: reads which are partially between intervals (in/outside extension)
// TODO: duplicate reads
// TODO: should we assign reads which are completely outside intervals but within extension?
// TODO: reads which are completely outside intervals but within extension
// TODO: test the extension itself
intervals = new ArrayList<GenomeLoc>();
@ -148,6 +150,8 @@ public class TraverseActiveRegionsTest extends BaseTest {
private void createBAM(List<GATKSAMRecord> reads) {
File outFile = new File(testBAM);
outFile.deleteOnExit();
File indexFile = new File(testBAI);
indexFile.deleteOnExit();
SAMFileWriter out = new SAMFileWriterFactory().makeBAMWriter(reads.get(0).getHeader(), true, outFile);
for (GATKSAMRecord read : ReadUtils.sortReadsByCoordinate(reads)) {
@ -175,13 +179,15 @@ public class TraverseActiveRegionsTest extends BaseTest {
return activeIntervals;
}
@Test (expectedExceptions = PreconditionError.class)
// TODO: fix this contracts issue and re-enable
@Test (enabled = false, expectedExceptions = PreconditionError.class)
public void testIsActiveRangeLow () {
DummyActiveRegionWalker walker = new DummyActiveRegionWalker(-0.1);
getActiveRegions(walker, intervals).values();
}
@Test (expectedExceptions = PreconditionError.class)
// TODO: fix this contracts issue and re-enable
@Test (enabled = false, expectedExceptions = PreconditionError.class)
public void testIsActiveRangeHigh () {
DummyActiveRegionWalker walker = new DummyActiveRegionWalker(1.1);
getActiveRegions(walker, intervals).values();

View File

@ -4,16 +4,12 @@ import org.broadinstitute.sting.gatk.walkers.bqsr.RecalibrationArgumentCollectio
import org.broadinstitute.sting.utils.recalibration.covariates.*;
import org.broadinstitute.sting.utils.QualityUtils;
import org.broadinstitute.sting.utils.collections.NestedIntegerArray;
import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
import org.broadinstitute.sting.utils.sam.GATKSAMReadGroupRecord;
import org.broadinstitute.sting.utils.sam.GATKSAMRecord;
import org.broadinstitute.sting.utils.sam.ReadUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.*;
/**
@ -29,7 +25,7 @@ public class RecalibrationReportUnitTest {
return new RecalDatum(nObservations, nErrors, (byte)qual);
}
@Test(enabled = false)
@Test(enabled = true)
public void testOutput() {
final int length = 100;
@ -79,7 +75,7 @@ public class RecalibrationReportUnitTest {
readQuals[i] = 20;
read.setBaseQualities(readQuals);
final int expectedKeys = expectedNumberOfKeys(4, length, RAC.INDELS_CONTEXT_SIZE, RAC.MISMATCHES_CONTEXT_SIZE);
final int expectedKeys = expectedNumberOfKeys(length, RAC.INDELS_CONTEXT_SIZE, RAC.MISMATCHES_CONTEXT_SIZE);
int nKeys = 0; // keep track of how many keys were produced
final ReadCovariates rc = RecalUtils.computeCovariates(read, requestedCovariates);
@ -99,35 +95,25 @@ public class RecalibrationReportUnitTest {
nKeys += 2;
for (int j = 0; j < optionalCovariates.size(); j++) {
final NestedIntegerArray<RecalDatum> covTable = recalibrationTables.getTable(RecalibrationTables.TableType.OPTIONAL_COVARIATE_TABLES_START.index + j);
covTable.put(createRandomRecalDatum(randomMax, 10), covariates[0], covariates[1], j, covariates[RecalibrationTables.TableType.OPTIONAL_COVARIATE_TABLES_START.index + j], errorMode.index);
nKeys++;
final int covValue = covariates[RecalibrationTables.TableType.OPTIONAL_COVARIATE_TABLES_START.index + j];
if ( covValue >= 0 ) {
covTable.put(createRandomRecalDatum(randomMax, 10), covariates[0], covariates[1], covValue, errorMode.index);
nKeys++;
}
}
}
}
Assert.assertEquals(nKeys, expectedKeys);
final RecalibrationReport report = new RecalibrationReport(quantizationInfo, recalibrationTables, RAC.generateReportTable("ignore"), RAC);
File output = new File("RecalibrationReportUnitTestOutuput.grp");
PrintStream out;
try {
out = new PrintStream(output);
} catch (FileNotFoundException e) {
throw new ReviewedStingException("couldn't create the file " + output, e);
}
report.output(out);
RecalibrationReport loadedReport = new RecalibrationReport(output);
Assert.assertTrue(report.equals(loadedReport));
if (!output.delete())
throw new ReviewedStingException("File could not be deleted " + output);
}
private static int expectedNumberOfKeys (int nCovariates, int readLength, int indelContextSize, int mismatchesContextSize) {
int nommcs = readLength >= mismatchesContextSize ? mismatchesContextSize-1 : readLength;
int noincs = readLength >= indelContextSize ? 2*(indelContextSize-1) : 2*readLength;
return (nCovariates * readLength * 3) - nommcs - noincs;
private static int expectedNumberOfKeys (int readLength, int indelContextSize, int mismatchesContextSize) {
final int numCovariates = 4;
final int numTables = 3;
final int mismatchContextPadding = mismatchesContextSize - 1;
final int indelContextPadding = 2 * (indelContextSize - 1);
final int indelCyclePadding = 2 * (2 * CycleCovariate.CUSHION_FOR_INDELS);
return (numCovariates * numTables * readLength) - mismatchContextPadding - indelContextPadding - indelCyclePadding;
}
}