diff --git a/ivy.xml b/ivy.xml
index 4bd6ad7b8..ed13af1c2 100644
--- a/ivy.xml
+++ b/ivy.xml
@@ -41,6 +41,8 @@
+
+
diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/CompressionStash.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/CompressionStash.java
index bd7bdfe89..22ea78521 100644
--- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/CompressionStash.java
+++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/CompressionStash.java
@@ -46,10 +46,12 @@
package org.broadinstitute.sting.gatk.walkers.compression.reducereads;
+import it.unimi.dsi.fastutil.objects.ObjectAVLTreeSet;
+import it.unimi.dsi.fastutil.objects.ObjectSortedSet;
import org.broadinstitute.sting.utils.*;
import java.util.Collection;
-import java.util.TreeSet;
+
/**
* A stash of regions that must be kept uncompressed in all samples
@@ -61,7 +63,7 @@ import java.util.TreeSet;
* Date: 10/15/12
* Time: 4:08 PM
*/
-public class CompressionStash extends TreeSet {
+public class CompressionStash extends ObjectAVLTreeSet {
public CompressionStash() {
super();
}
@@ -75,7 +77,7 @@ public class CompressionStash extends TreeSet {
*/
@Override
public boolean add(final FinishedGenomeLoc insertLoc) {
- TreeSet removedLocs = new TreeSet();
+ ObjectSortedSet removedLocs = new ObjectAVLTreeSet();
for (FinishedGenomeLoc existingLoc : this) {
if (existingLoc.isPast(insertLoc)) {
break; // if we're past the loc we're done looking for overlaps.
diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/HeaderElement.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/HeaderElement.java
index 83efaa254..1cd9c1bc0 100644
--- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/HeaderElement.java
+++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/HeaderElement.java
@@ -46,10 +46,10 @@
package org.broadinstitute.sting.gatk.walkers.compression.reducereads;
+import it.unimi.dsi.fastutil.ints.IntArrayList;
import org.broadinstitute.sting.utils.MathUtils;
import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
-import java.util.LinkedList;
/**
* The element that describes the header of the sliding window.
@@ -64,7 +64,7 @@ public class HeaderElement {
private int insertionsToTheRight; // How many reads in this site had insertions to the immediate right
private int nSoftClippedBases; // How many bases in this site came from soft clipped bases
private int location; // Genome location of this site (the sliding window knows which contig we're at
- private LinkedList mappingQuality; // keeps the mapping quality of each read that contributed to this element (site)
+ private IntArrayList mappingQuality; // keeps the mapping quality of each read that contributed to this element (site)
public int getLocation() {
return location;
@@ -85,7 +85,7 @@ public class HeaderElement {
* @param location the reference location for the new element
*/
public HeaderElement(final int location) {
- this(new BaseAndQualsCounts(), new BaseAndQualsCounts(), 0, 0, location, new LinkedList());
+ this(new BaseAndQualsCounts(), new BaseAndQualsCounts(), 0, 0, location, new IntArrayList());
}
/**
@@ -95,7 +95,7 @@ public class HeaderElement {
* @param location the reference location for the new element
*/
public HeaderElement(final int location, final int insertionsToTheRight) {
- this(new BaseAndQualsCounts(), new BaseAndQualsCounts(), insertionsToTheRight, 0, location, new LinkedList());
+ this(new BaseAndQualsCounts(), new BaseAndQualsCounts(), insertionsToTheRight, 0, location, new IntArrayList());
}
/**
@@ -109,7 +109,7 @@ public class HeaderElement {
* @param mappingQuality the list of mapping quality values of all reads that contributed to this
* HeaderElement
*/
- public HeaderElement(BaseAndQualsCounts consensusBaseCounts, BaseAndQualsCounts filteredBaseCounts, int insertionsToTheRight, int nSoftClippedBases, int location, LinkedList mappingQuality) {
+ public HeaderElement(BaseAndQualsCounts consensusBaseCounts, BaseAndQualsCounts filteredBaseCounts, int insertionsToTheRight, int nSoftClippedBases, int location, IntArrayList mappingQuality) {
this.consensusBaseCounts = consensusBaseCounts;
this.filteredBaseCounts = filteredBaseCounts;
this.insertionsToTheRight = insertionsToTheRight;
diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/MultiSampleCompressor.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/MultiSampleCompressor.java
index d45efeb65..2f377bee8 100644
--- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/MultiSampleCompressor.java
+++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/MultiSampleCompressor.java
@@ -46,6 +46,7 @@
package org.broadinstitute.sting.gatk.walkers.compression.reducereads;
+import it.unimi.dsi.fastutil.objects.*;
import net.sf.samtools.SAMFileHeader;
import org.apache.log4j.Logger;
import org.broadinstitute.sting.utils.SampleUtils;
@@ -54,10 +55,6 @@ import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
import org.broadinstitute.sting.utils.sam.AlignmentStartWithNoTiesComparator;
import org.broadinstitute.sting.utils.sam.GATKSAMRecord;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
/*
* Copyright (c) 2009 The Broad Institute
@@ -91,7 +88,7 @@ import java.util.TreeSet;
public class MultiSampleCompressor {
protected static final Logger logger = Logger.getLogger(MultiSampleCompressor.class);
- protected Map compressorsPerSample = new HashMap();
+ protected Object2ObjectMap compressorsPerSample = new Object2ObjectOpenHashMap();
public MultiSampleCompressor(SAMFileHeader header,
final int contextSize,
@@ -109,13 +106,13 @@ public class MultiSampleCompressor {
}
}
- public Set addAlignment(GATKSAMRecord read) {
+ public ObjectSet addAlignment(GATKSAMRecord read) {
String sampleName = read.getReadGroup().getSample();
SingleSampleCompressor compressor = compressorsPerSample.get(sampleName);
if ( compressor == null )
throw new ReviewedStingException("No compressor for sample " + sampleName);
- Pair, CompressionStash> readsAndStash = compressor.addAlignment(read);
- Set reads = readsAndStash.getFirst();
+ Pair, CompressionStash> readsAndStash = compressor.addAlignment(read);
+ ObjectSet reads = readsAndStash.getFirst();
CompressionStash regions = readsAndStash.getSecond();
reads.addAll(closeVariantRegionsInAllSamples(regions));
@@ -123,17 +120,17 @@ public class MultiSampleCompressor {
return reads;
}
- public Set close() {
- Set reads = new TreeSet(new AlignmentStartWithNoTiesComparator());
+ public ObjectSet close() {
+ ObjectSet reads = new ObjectAVLTreeSet(new AlignmentStartWithNoTiesComparator());
for ( SingleSampleCompressor sample : compressorsPerSample.values() ) {
- Pair, CompressionStash> readsAndStash = sample.close();
+ Pair, CompressionStash> readsAndStash = sample.close();
reads = readsAndStash.getFirst();
}
return reads;
}
- private Set closeVariantRegionsInAllSamples(CompressionStash regions) {
- Set reads = new TreeSet(new AlignmentStartWithNoTiesComparator());
+ private ObjectSet closeVariantRegionsInAllSamples(CompressionStash regions) {
+ ObjectSet reads = new ObjectAVLTreeSet(new AlignmentStartWithNoTiesComparator());
if (!regions.isEmpty()) {
for (SingleSampleCompressor sample : compressorsPerSample.values()) {
reads.addAll(sample.closeVariantRegions(regions));
diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/ReduceReads.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/ReduceReads.java
index 8e45f6db1..7f39452c4 100644
--- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/ReduceReads.java
+++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/ReduceReads.java
@@ -46,6 +46,10 @@
package org.broadinstitute.sting.gatk.walkers.compression.reducereads;
+import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
+import it.unimi.dsi.fastutil.objects.ObjectAVLTreeSet;
+import it.unimi.dsi.fastutil.objects.ObjectArrayList;
+import it.unimi.dsi.fastutil.objects.ObjectSortedSet;
import net.sf.samtools.SAMFileHeader;
import net.sf.samtools.SAMFileWriter;
import net.sf.samtools.SAMProgramRecord;
@@ -71,7 +75,6 @@ import org.broadinstitute.sting.utils.sam.BySampleSAMFileWriter;
import org.broadinstitute.sting.utils.sam.GATKSAMRecord;
import org.broadinstitute.sting.utils.sam.ReadUtils;
-import java.util.*;
/**
* Reduces the BAM file using read based compression that keeps only essential information for variant calling
@@ -107,7 +110,7 @@ import java.util.*;
@PartitionBy(PartitionType.CONTIG)
@ReadFilters({UnmappedReadFilter.class, NotPrimaryAlignmentFilter.class, DuplicateReadFilter.class, FailsVendorQualityCheckFilter.class, BadCigarFilter.class})
@Downsample(by=DownsampleType.BY_SAMPLE, toCoverage=40)
-public class ReduceReads extends ReadWalker, ReduceReadsStash> {
+public class ReduceReads extends ReadWalker, ReduceReadsStash> {
@Output
private StingSAMFileWriter out = null;
@@ -240,10 +243,10 @@ public class ReduceReads extends ReadWalker, ReduceRea
int nCompressedReads = 0;
- HashMap readNameHash; // This hash will keep the name of the original read the new compressed name (a number).
+ Object2LongOpenHashMap readNameHash; // This hash will keep the name of the original read the new compressed name (a number).
Long nextReadNumber = 1L; // The next number to use for the compressed read name.
- SortedSet intervalList;
+ ObjectSortedSet intervalList;
// IMPORTANT: DO NOT CHANGE THE VALUE OF THIS CONSTANT VARIABLE; IT IS NOW PERMANENTLY THE @PG NAME THAT EXTERNAL TOOLS LOOK FOR IN THE BAM HEADER
public static final String PROGRAM_RECORD_NAME = "GATK ReduceReads"; // The name that will go in the @PG tag
@@ -257,8 +260,8 @@ public class ReduceReads extends ReadWalker, ReduceRea
public void initialize() {
super.initialize();
GenomeAnalysisEngine toolkit = getToolkit();
- readNameHash = new HashMap(); // prepare the read name hash to keep track of what reads have had their read names compressed
- intervalList = new TreeSet(); // get the interval list from the engine. If no interval list was provided, the walker will work in WGS mode
+ readNameHash = new Object2LongOpenHashMap(100000); // prepare the read name hash to keep track of what reads have had their read names compressed
+ intervalList = new ObjectAVLTreeSet(); // get the interval list from the engine. If no interval list was provided, the walker will work in WGS mode
if (toolkit.getIntervals() != null)
intervalList.addAll(toolkit.getIntervals());
@@ -295,8 +298,8 @@ public class ReduceReads extends ReadWalker, ReduceRea
* @return a linked list with all the reads produced by the clipping operations
*/
@Override
- public LinkedList map(ReferenceContext ref, GATKSAMRecord read, RefMetaDataTracker metaDataTracker) {
- LinkedList mappedReads;
+ public ObjectArrayList map(ReferenceContext ref, GATKSAMRecord read, RefMetaDataTracker metaDataTracker) {
+ ObjectArrayList mappedReads;
if (!debugRead.isEmpty() && read.getReadName().contains(debugRead))
System.out.println("Found debug read!");
@@ -325,18 +328,18 @@ public class ReduceReads extends ReadWalker, ReduceRea
if (HARD_CLIP_TO_INTERVAL)
mappedReads = hardClipReadToInterval(read); // Hard clip the remainder of the read to the desired interval
else {
- mappedReads = new LinkedList();
+ mappedReads = new ObjectArrayList();
mappedReads.add(read);
}
}
else {
- mappedReads = new LinkedList();
+ mappedReads = new ObjectArrayList();
if (!read.isEmpty())
mappedReads.add(read);
}
if (!mappedReads.isEmpty() && !DONT_USE_SOFTCLIPPED_BASES) {
- LinkedList tempList = new LinkedList();
+ ObjectArrayList tempList = new ObjectArrayList();
for (GATKSAMRecord mRead : mappedReads) {
GATKSAMRecord clippedRead = ReadClipper.hardClipLowQualitySoftClips(mRead, minBaseQual);
if (!clippedRead.isEmpty())
@@ -375,7 +378,7 @@ public class ReduceReads extends ReadWalker, ReduceRea
* @param stash the stash that keeps the reads in order for processing
* @return the stash with all reads that have not been processed yet
*/
- public ReduceReadsStash reduce(LinkedList mappedReads, ReduceReadsStash stash) {
+ public ReduceReadsStash reduce(ObjectArrayList mappedReads, ReduceReadsStash stash) {
if (debugLevel == 1)
stash.print();
@@ -387,7 +390,7 @@ public class ReduceReads extends ReadWalker, ReduceRea
throw new ReviewedStingException("Empty read sent to reduce, this should never happen! " + read.getReadName() + " -- " + read.getCigar() + " -- " + read.getReferenceName() + ":" + read.getAlignmentStart() + "-" + read.getAlignmentEnd());
if (originalRead) {
- List readsReady = new LinkedList();
+ ObjectArrayList readsReady = new ObjectArrayList();
readsReady.addAll(stash.getAllReadsBefore(read));
readsReady.add(read);
@@ -433,8 +436,8 @@ public class ReduceReads extends ReadWalker, ReduceRea
* @param read the read to be hard clipped to the interval.
* @return a shallow copy of the read hard clipped to the interval
*/
- private LinkedList hardClipReadToInterval(GATKSAMRecord read) {
- LinkedList clippedReads = new LinkedList();
+ private ObjectArrayList hardClipReadToInterval(GATKSAMRecord read) {
+ ObjectArrayList clippedReads = new ObjectArrayList();
GenomeLoc intervalOverlapped = null; // marks the interval to which the original read overlapped (so we can cut all previous intervals from the list)
@@ -588,7 +591,7 @@ public class ReduceReads extends ReadWalker, ReduceRea
System.out.println("BAM: " + read.getCigar() + " " + read.getAlignmentStart() + " " + read.getAlignmentEnd());
if (!DONT_COMPRESS_READ_NAMES)
- compressReadName(read);
+ nextReadNumber = compressReadName(readNameHash, read, nextReadNumber);
writerToUse.addAlignment(read);
}
@@ -625,19 +628,20 @@ public class ReduceReads extends ReadWalker, ReduceRea
*
* @param read any read
*/
- private void compressReadName(GATKSAMRecord read) {
- String name = read.getReadName();
+ protected static long compressReadName(Object2LongOpenHashMap hash, GATKSAMRecord read, long nextReadNumber) {
+ final String name = read.getReadName();
+ long result = nextReadNumber;
String compressedName = read.isReducedRead() ? "C" : "";
- final Long readNumber = readNameHash.get(name);
+ final Long readNumber = hash.get(name);
if (readNumber != null) {
compressedName += readNumber.toString();
} else {
- readNameHash.put(name, nextReadNumber);
- compressedName += nextReadNumber.toString();
- nextReadNumber++;
+ hash.put(name, nextReadNumber);
+ compressedName += "" + nextReadNumber;
+ result++;
}
-
read.setReadName(compressedName);
+ return result;
}
/**
@@ -649,8 +653,8 @@ public class ReduceReads extends ReadWalker, ReduceRea
* @param read the read
* @return Returns true if the read is the original read that went through map().
*/
- private boolean isOriginalRead(LinkedList list, GATKSAMRecord read) {
- return isWholeGenome() || list.getFirst().equals(read);
+ private boolean isOriginalRead(ObjectArrayList list, GATKSAMRecord read) {
+ return isWholeGenome() || list.get(0).equals(read);
}
/**
diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SingleSampleCompressor.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SingleSampleCompressor.java
index b4de1f0cb..42db83c04 100644
--- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SingleSampleCompressor.java
+++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SingleSampleCompressor.java
@@ -46,14 +46,11 @@
package org.broadinstitute.sting.gatk.walkers.compression.reducereads;
+import it.unimi.dsi.fastutil.objects.*;
import org.broadinstitute.sting.utils.collections.Pair;
import org.broadinstitute.sting.utils.sam.AlignmentStartWithNoTiesComparator;
import org.broadinstitute.sting.utils.sam.GATKSAMRecord;
-import java.util.Collections;
-import java.util.Set;
-import java.util.TreeSet;
-
/**
*
* @author carneiro, depristo
@@ -72,7 +69,7 @@ public class SingleSampleCompressor {
private SlidingWindow slidingWindow;
private int slidingWindowCounter;
- public static Pair, CompressionStash> emptyPair = new Pair,CompressionStash>(new TreeSet(), new CompressionStash());
+ public static Pair, CompressionStash> emptyPair = new Pair,CompressionStash>(new ObjectAVLTreeSet(), new CompressionStash());
public SingleSampleCompressor(final int contextSize,
final int downsampleCoverage,
@@ -93,8 +90,8 @@ public class SingleSampleCompressor {
this.allowPolyploidReduction = allowPolyploidReduction;
}
- public Pair, CompressionStash> addAlignment( GATKSAMRecord read ) {
- Set reads = new TreeSet(new AlignmentStartWithNoTiesComparator());
+ public Pair, CompressionStash> addAlignment( GATKSAMRecord read ) {
+ ObjectSet reads = new ObjectAVLTreeSet(new AlignmentStartWithNoTiesComparator());
CompressionStash stash = new CompressionStash();
int readOriginalStart = read.getUnclippedStart();
@@ -104,7 +101,7 @@ public class SingleSampleCompressor {
(readOriginalStart - contextSize > slidingWindow.getStopLocation()))) { // this read is too far away from the end of the current sliding window
// close the current sliding window
- Pair, CompressionStash> readsAndStash = slidingWindow.close();
+ Pair, CompressionStash> readsAndStash = slidingWindow.close();
reads = readsAndStash.getFirst();
stash = readsAndStash.getSecond();
slidingWindow = null; // so we create a new one on the next if
@@ -116,15 +113,15 @@ public class SingleSampleCompressor {
}
stash.addAll(slidingWindow.addRead(read));
- return new Pair, CompressionStash>(reads, stash);
+ return new Pair, CompressionStash>(reads, stash);
}
- public Pair, CompressionStash> close() {
+ public Pair, CompressionStash> close() {
return (slidingWindow != null) ? slidingWindow.close() : emptyPair;
}
- public Set closeVariantRegions(CompressionStash regions) {
- return slidingWindow == null ? Collections.emptySet() : slidingWindow.closeVariantRegions(regions);
+ public ObjectSet closeVariantRegions(CompressionStash regions) {
+ return slidingWindow == null ? ObjectSets.EMPTY_SET : slidingWindow.closeVariantRegions(regions);
}
}
diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SlidingWindow.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SlidingWindow.java
index 680489042..7124b4772 100644
--- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SlidingWindow.java
+++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SlidingWindow.java
@@ -48,6 +48,10 @@ package org.broadinstitute.sting.gatk.walkers.compression.reducereads;
import com.google.java.contract.Ensures;
import com.google.java.contract.Requires;
+import it.unimi.dsi.fastutil.bytes.Byte2IntArrayMap;
+import it.unimi.dsi.fastutil.bytes.Byte2IntMap;
+import it.unimi.dsi.fastutil.bytes.Byte2IntOpenHashMap;
+import it.unimi.dsi.fastutil.objects.*;
import net.sf.samtools.Cigar;
import net.sf.samtools.CigarElement;
import net.sf.samtools.CigarOperator;
@@ -62,7 +66,11 @@ import org.broadinstitute.sting.utils.sam.GATKSAMReadGroupRecord;
import org.broadinstitute.sting.utils.sam.GATKSAMRecord;
import org.broadinstitute.sting.utils.sam.ReadUtils;
-import java.util.*;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.ListIterator;
+
/**
* Created by IntelliJ IDEA.
@@ -73,7 +81,7 @@ import java.util.*;
public class SlidingWindow {
// Sliding Window data
- final private TreeSet readsInWindow;
+ final private ObjectAVLTreeSet readsInWindow;
final private LinkedList windowHeader;
protected int contextSize; // the largest context size (between mismatches and indels)
protected String contig;
@@ -144,7 +152,7 @@ public class SlidingWindow {
this.windowHeader = new LinkedList();
windowHeader.addFirst(new HeaderElement(startLocation));
- this.readsInWindow = new TreeSet();
+ this.readsInWindow = new ObjectAVLTreeSet();
}
public SlidingWindow(String contig, int contigIndex, int contextSize, SAMFileHeader samHeader, GATKSAMReadGroupRecord readGroupAttribute, int windowNumber, final double minAltProportionToTriggerVariant, final double minIndelProportionToTriggerVariant, int minBaseQual, int minMappingQuality, int downsampleCoverage, final ReduceReads.DownsampleStrategy downsampleStrategy, boolean hasIndelQualities, boolean allowPolyploidReduction) {
@@ -157,7 +165,7 @@ public class SlidingWindow {
this.MIN_MAPPING_QUALITY = minMappingQuality;
this.windowHeader = new LinkedList();
- this.readsInWindow = new TreeSet(new Comparator() {
+ this.readsInWindow = new ObjectAVLTreeSet(new Comparator() {
@Override
public int compare(GATKSAMRecord read1, GATKSAMRecord read2) {
final int difference = read1.getSoftEnd() - read2.getSoftEnd();
@@ -287,7 +295,7 @@ public class SlidingWindow {
}
while (!readsInWindow.isEmpty() && readsInWindow.first().getSoftEnd() < windowHeaderStartLocation) {
- readsInWindow.pollFirst();
+ readsInWindow.remove(readsInWindow.first());
}
return regions;
@@ -401,8 +409,8 @@ public class SlidingWindow {
*/
@Requires({"start >= 0 && (end >= start || end == 0)"})
@Ensures("result != null")
- protected List addToSyntheticReads(LinkedList header, int start, int end, boolean isNegativeStrand) {
- LinkedList reads = new LinkedList();
+ protected ObjectArrayList addToSyntheticReads(LinkedList header, int start, int end, boolean isNegativeStrand) {
+ ObjectArrayList reads = new ObjectArrayList();
if (start < end) {
ListIterator headerElementIterator = header.listIterator(start);
@@ -454,9 +462,9 @@ public class SlidingWindow {
* @param type the synthetic reads you want to close
* @return a possibly null list of GATKSAMRecords generated by finalizing the synthetic reads
*/
- private List finalizeAndAdd(ConsensusType type) {
+ private ObjectArrayList finalizeAndAdd(ConsensusType type) {
GATKSAMRecord read = null;
- List list = new LinkedList();
+ ObjectArrayList list = new ObjectArrayList();
switch (type) {
case CONSENSUS:
@@ -556,8 +564,8 @@ public class SlidingWindow {
*/
@Requires({"start >= 0 && (end >= start || end == 0)"})
@Ensures("result != null")
- private List addToFilteredData(LinkedList header, int start, int end, boolean isNegativeStrand) {
- List result = new ArrayList(0);
+ private ObjectArrayList addToFilteredData(LinkedList header, int start, int end, boolean isNegativeStrand) {
+ ObjectArrayList result = new ObjectArrayList();
if (filteredDataConsensus == null)
filteredDataConsensus = new SyntheticRead(samHeader, readGroupAttribute, contig, contigIndex, filteredDataReadName + filteredDataConsensusCounter++, header.get(start).getLocation(), GATKSAMRecord.REDUCED_READ_CONSENSUS_TAG, hasIndelQualities, isNegativeStrand);
@@ -640,8 +648,8 @@ public class SlidingWindow {
*/
@Requires({"start >= 0 && (stop >= start || stop == 0)"})
@Ensures("result != null")
- protected List compressVariantRegion(final int start, final int stop, final boolean disallowPolyploidReductionAtThisPosition) {
- List allReads = new LinkedList();
+ protected ObjectList compressVariantRegion(final int start, final int stop, final boolean disallowPolyploidReductionAtThisPosition) {
+ ObjectList allReads = new ObjectArrayList();
// Try to compress into a polyploid consensus
int nVariantPositions = 0;
@@ -685,7 +693,7 @@ public class SlidingWindow {
final int refStart = windowHeader.get(start).getLocation();
final int refStop = windowHeader.get(stop).getLocation();
- LinkedList toRemove = new LinkedList();
+ ObjectList toRemove = new ObjectArrayList();
for (GATKSAMRecord read : readsInWindow) {
if (read.getSoftStart() <= refStop) {
if (read.getAlignmentEnd() >= refStart) {
@@ -710,24 +718,24 @@ public class SlidingWindow {
*/
@Requires({"start >= 0 && (stop >= start || stop == 0)"})
@Ensures("result != null")
- protected List closeVariantRegion(final int start, final int stop, final boolean disallowPolyploidReductionAtThisPosition) {
- List allReads = compressVariantRegion(start, stop, disallowPolyploidReductionAtThisPosition);
+ protected ObjectList closeVariantRegion(final int start, final int stop, final boolean disallowPolyploidReductionAtThisPosition) {
+ ObjectList allReads = compressVariantRegion(start, stop, disallowPolyploidReductionAtThisPosition);
- List result = (downsampleCoverage > 0) ? downsampleVariantRegion(allReads) : allReads;
+ ObjectList result = (downsampleCoverage > 0) ? downsampleVariantRegion(allReads) : allReads;
result.addAll(addToSyntheticReads(windowHeader, 0, stop, false));
result.addAll(finalizeAndAdd(ConsensusType.BOTH));
return result; // finalized reads will be downsampled if necessary
}
- public Set closeVariantRegions(CompressionStash regions) {
- TreeSet allReads = new TreeSet(new AlignmentStartWithNoTiesComparator());
+ public ObjectSet closeVariantRegions(CompressionStash regions) {
+ ObjectAVLTreeSet allReads = new ObjectAVLTreeSet(new AlignmentStartWithNoTiesComparator());
if (!regions.isEmpty()) {
int lastStop = -1;
int windowHeaderStart = getStartLocation(windowHeader);
for (GenomeLoc region : regions) {
- if (((FinishedGenomeLoc)region).isFinished() && region.getContig() == contig && region.getStart() >= windowHeaderStart && region.getStop() < windowHeaderStart + windowHeader.size()) {
+ if (((FinishedGenomeLoc)region).isFinished() && region.getContig().equals(contig) && region.getStart() >= windowHeaderStart && region.getStop() < windowHeaderStart + windowHeader.size()) {
int start = region.getStart() - windowHeaderStart;
int stop = region.getStop() - windowHeaderStart;
@@ -759,7 +767,7 @@ public class SlidingWindow {
*/
@Requires({"allReads != null"})
@Ensures("result != null")
- protected List downsampleVariantRegion(final List allReads) {
+ protected ObjectList downsampleVariantRegion(final ObjectList allReads) {
int nReads = allReads.size();
if (nReads == 0)
return allReads;
@@ -769,7 +777,7 @@ public class SlidingWindow {
ReservoirDownsampler downsampler = new ReservoirDownsampler(downsampleCoverage);
downsampler.submit(allReads);
- return downsampler.consumeFinalizedItems();
+ return new ObjectArrayList(downsampler.consumeFinalizedItems());
}
@@ -781,9 +789,9 @@ public class SlidingWindow {
* @return A non-null set/list of all reads generated
*/
@Ensures("result != null")
- public Pair, CompressionStash> close() {
+ public Pair, CompressionStash> close() {
// mark variant regions
- Set finalizedReads = new TreeSet(new AlignmentStartWithNoTiesComparator());
+ ObjectSet finalizedReads = new ObjectAVLTreeSet(new AlignmentStartWithNoTiesComparator());
CompressionStash regions = new CompressionStash();
boolean forceCloseUnfinishedRegions = true;
@@ -798,7 +806,7 @@ public class SlidingWindow {
}
}
- return new Pair, CompressionStash>(finalizedReads, regions);
+ return new Pair, CompressionStash>(finalizedReads, regions);
}
/**
@@ -847,16 +855,16 @@ public class SlidingWindow {
*/
@Requires({"start >= 0 && (stop >= start || stop == 0)"})
@Ensures("result != null")
- private List createPolyploidConsensus(final int start, final int stop, final int hetRefPosition) {
+ private ObjectList createPolyploidConsensus(final int start, final int stop, final int hetRefPosition) {
// we will create two (positive strand, negative strand) headers for each contig
- List> headersPosStrand = new ArrayList>();
- List> headersNegStrand = new ArrayList>();
- List hetReads = new LinkedList();
- Map haplotypeHeaderMap = new HashMap(2);
+ ObjectList> headersPosStrand = new ObjectArrayList>();
+ ObjectList> headersNegStrand = new ObjectArrayList>();
+ ObjectList hetReads = new ObjectArrayList();
+ Byte2IntMap haplotypeHeaderMap = new Byte2IntArrayMap(2);
int currentHaplotype = 0;
int refStart = windowHeader.get(start).getLocation();
int refStop = windowHeader.get(stop).getLocation();
- List toRemove = new LinkedList();
+ ObjectList toRemove = new ObjectArrayList();
for (GATKSAMRecord read : readsInWindow) {
int haplotype;
@@ -1031,7 +1039,7 @@ public class SlidingWindow {
}
}
- private void removeReadsFromWindow (List readsToRemove) {
+ private void removeReadsFromWindow (ObjectList readsToRemove) {
for (GATKSAMRecord read : readsToRemove) {
readsInWindow.remove(read);
}
diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SyntheticRead.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SyntheticRead.java
index 631e099a9..72fd52ebe 100644
--- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SyntheticRead.java
+++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SyntheticRead.java
@@ -47,6 +47,8 @@
package org.broadinstitute.sting.gatk.walkers.compression.reducereads;
import com.google.java.contract.Requires;
+import it.unimi.dsi.fastutil.bytes.ByteArrayList;
+import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.sf.samtools.Cigar;
import net.sf.samtools.CigarElement;
import net.sf.samtools.CigarOperator;
@@ -57,10 +59,8 @@ import org.broadinstitute.sting.utils.recalibration.EventType;
import org.broadinstitute.sting.utils.sam.GATKSAMReadGroupRecord;
import org.broadinstitute.sting.utils.sam.GATKSAMRecord;
-import java.util.ArrayList;
import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
+
/**
* Running Consensus is a read that is compressed as a sliding window travels over the reads
@@ -123,7 +123,7 @@ public class SyntheticRead {
}
- private final List basesCountsQuals;
+ private final ObjectArrayList basesCountsQuals;
private double mappingQuality; // the average of the rms of the mapping qualities of all the reads that contributed to this consensus
private String readTag;
@@ -151,7 +151,7 @@ public class SyntheticRead {
*/
public SyntheticRead(SAMFileHeader header, GATKSAMReadGroupRecord readGroupRecord, String contig, int contigIndex, String readName, int refStart, String readTag, boolean hasIndelQualities, boolean isNegativeRead) {
final int initialCapacity = 10000;
- basesCountsQuals = new ArrayList(initialCapacity);
+ basesCountsQuals = new ObjectArrayList(initialCapacity);
mappingQuality = 0.0;
this.readTag = readTag;
@@ -165,8 +165,8 @@ public class SyntheticRead {
this.isNegativeStrand = isNegativeRead;
}
- public SyntheticRead(List bases, List counts, List quals, List insertionQuals, List deletionQuals, double mappingQuality, String readTag, SAMFileHeader header, GATKSAMReadGroupRecord readGroupRecord, String contig, int contigIndex, String readName, int refStart, boolean hasIndelQualities, boolean isNegativeRead) {
- basesCountsQuals = new ArrayList(bases.size());
+ public SyntheticRead(ObjectArrayList bases, ByteArrayList counts, ByteArrayList quals, ByteArrayList insertionQuals, ByteArrayList deletionQuals, double mappingQuality, String readTag, SAMFileHeader header, GATKSAMReadGroupRecord readGroupRecord, String contig, int contigIndex, String readName, int refStart, boolean hasIndelQualities, boolean isNegativeRead) {
+ basesCountsQuals = new ObjectArrayList(bases.size());
for (int i = 0; i < bases.size(); ++i) {
basesCountsQuals.add(new SingleBaseInfo(bases.get(i).getOrdinalByte(), counts.get(i), quals.get(i), insertionQuals.get(i), deletionQuals.get(i)));
}
@@ -316,7 +316,7 @@ public class SyntheticRead {
* @return the cigar string for the synthetic read
*/
private Cigar buildCigar() {
- LinkedList cigarElements = new LinkedList();
+ ObjectArrayList cigarElements = new ObjectArrayList();
CigarOperator cigarOperator = null;
int length = 0;
for (final SingleBaseInfo singleBaseInfo : basesCountsQuals) {
diff --git a/protected/java/test/org/broadinstitute/sting/gatk/walkers/compression/reducereads/ReduceReadsUnitTest.java b/protected/java/test/org/broadinstitute/sting/gatk/walkers/compression/reducereads/ReduceReadsUnitTest.java
new file mode 100644
index 000000000..b9399bb1b
--- /dev/null
+++ b/protected/java/test/org/broadinstitute/sting/gatk/walkers/compression/reducereads/ReduceReadsUnitTest.java
@@ -0,0 +1,111 @@
+/*
+* 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.compression.reducereads;
+
+import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
+import it.unimi.dsi.fastutil.objects.ObjectArrayList;
+import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
+import org.broadinstitute.sting.BaseTest;
+import org.broadinstitute.sting.utils.sam.GATKSAMRecord;
+import org.testng.Assert;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.util.Random;
+
+
+public class ReduceReadsUnitTest extends BaseTest {
+
+ Random random = new Random(987743);
+ Object2LongOpenHashMap hash = new Object2LongOpenHashMap();
+ long nextNumber = 0L;
+
+ /**
+ * Combinatorial unit test data provider example.
+ *
+ * Creates data for testMyData test function, containing two arguments, start and size at each value
+ *
+ * @return Object[][] for testng DataProvider
+ */
+ @DataProvider(name = "ReadNameProvider")
+ public Object[][] readNameProvider() {
+ final int readNameLength = 4;
+ final int nReads = 100000;
+ final int charVariety = 20;
+ ObjectArrayList