diff --git a/redux/src/main/java/com/hartwig/hmftools/redux/PartitionReader.java b/redux/src/main/java/com/hartwig/hmftools/redux/PartitionReader.java index 89ad899343..8172f31cb8 100644 --- a/redux/src/main/java/com/hartwig/hmftools/redux/PartitionReader.java +++ b/redux/src/main/java/com/hartwig/hmftools/redux/PartitionReader.java @@ -16,6 +16,9 @@ import static com.hartwig.hmftools.redux.common.FilterReadsType.readOutsideSpecifiedRegions; import static com.hartwig.hmftools.redux.common.ReadInfo.readToString; +import static org.apache.logging.log4j.Level.DEBUG; +import static org.apache.logging.log4j.Level.TRACE; + import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -27,7 +30,6 @@ import com.hartwig.hmftools.redux.common.DuplicateGroup; import com.hartwig.hmftools.redux.common.DuplicateGroupBuilder; import com.hartwig.hmftools.redux.common.FragmentCoordReads; -import com.hartwig.hmftools.redux.common.FragmentStatus; import com.hartwig.hmftools.redux.common.Statistics; import com.hartwig.hmftools.redux.unmap.ReadUnmapper; import com.hartwig.hmftools.redux.unmap.UnmapRegionState; @@ -35,6 +37,8 @@ import com.hartwig.hmftools.redux.write.BamWriter; import com.hartwig.hmftools.redux.write.PartitionInfo; +import org.apache.logging.log4j.Level; + import htsjdk.samtools.SAMRecord; public class PartitionReader @@ -172,7 +176,8 @@ public void postProcessRegion() mBamWriter.onRegionComplete(); - RD_LOGGER.debug("region({}) complete, processed {} reads", mCurrentRegion, mProcessedReads); + Level logLevel = isAltContigRegion() ? TRACE : DEBUG; + RD_LOGGER.log(logLevel, "region({}) complete, processed {} reads", mCurrentRegion, mProcessedReads); perfCountersStop(); } @@ -391,6 +396,9 @@ private void setUnmappedRegions() private void perfCountersStart() { + if(isAltContigRegion()) + return; + if(mConfig.perfDebug()) mPcTotal.start(format("%s", mCurrentRegion)); else @@ -401,10 +409,15 @@ private void perfCountersStart() private void perfCountersStop() { + if(isAltContigRegion()) + return; + mPcTotal.stop(); mPcProcessDuplicates.stop(); } + private boolean isAltContigRegion() { return PartitionInfo.isAltRegionContig(mCurrentRegion.Chromosome); } + @VisibleForTesting public void setBamWriter(final BamWriter writer) { mBamWriter = writer; } diff --git a/redux/src/main/java/com/hartwig/hmftools/redux/PartitionThread.java b/redux/src/main/java/com/hartwig/hmftools/redux/PartitionThread.java index 2b3f7f8ca8..b95a1e4daf 100644 --- a/redux/src/main/java/com/hartwig/hmftools/redux/PartitionThread.java +++ b/redux/src/main/java/com/hartwig/hmftools/redux/PartitionThread.java @@ -6,6 +6,7 @@ import static com.hartwig.hmftools.common.genome.refgenome.RefGenomeCoordinates.refGenomeCoordinates; import static com.hartwig.hmftools.redux.ReduxConfig.RD_LOGGER; +import static com.hartwig.hmftools.redux.write.PartitionInfo.isAltRegionContig; import java.util.Collections; import java.util.List; @@ -111,7 +112,8 @@ else if(specificRegions.Regions.size() == 1 && threadCount > 1) List genomeRegions = getRefGenomeRegions(specificRegions, refGenomeVersion, refGenome); - long totalLength = genomeRegions.stream().mapToLong(x -> x.baseLength()).sum(); + // ignore lengths for alt-contigs so they don't impact the partitioning of actual chromosomes and reads + long totalLength = genomeRegions.stream().mapToLong(x -> regionIntervalLength(x)).sum(); long intervalLength = (int)ceil(totalLength / (double)threadCount); int chrEndBuffer = (int)round(intervalLength * 0.05); @@ -123,17 +125,17 @@ else if(specificRegions.Regions.size() == 1 && threadCount > 1) for(ChrBaseRegion genomeRegion : genomeRegions) { nextRegionStart = 1; - int chromosomeLength = genomeRegion.baseLength(); - int remainingChromosomeLength = chromosomeLength; + int regionLength = regionIntervalLength(genomeRegion); + int remainingChromosomeLength = regionLength; while(currentLength + remainingChromosomeLength >= intervalLength) { int remainingIntervalLength = (int)(intervalLength - currentLength); int regionEnd = nextRegionStart + remainingIntervalLength - 1; - if(chromosomeLength - regionEnd < chrEndBuffer) + if(regionLength - regionEnd < chrEndBuffer) { - regionEnd = chromosomeLength; + regionEnd = regionLength; remainingChromosomeLength = 0; } @@ -147,7 +149,7 @@ else if(specificRegions.Regions.size() == 1 && threadCount > 1) break; nextRegionStart = regionEnd + 1; - remainingChromosomeLength = chromosomeLength - nextRegionStart + 1; + remainingChromosomeLength = regionLength - nextRegionStart + 1; } if(remainingChromosomeLength <= 0) @@ -155,12 +157,17 @@ else if(specificRegions.Regions.size() == 1 && threadCount > 1) currentLength += remainingChromosomeLength; - currentRegions.add(new ChrBaseRegion(genomeRegion.Chromosome, nextRegionStart, chromosomeLength)); + currentRegions.add(new ChrBaseRegion(genomeRegion.Chromosome, nextRegionStart, regionLength)); } return partitionRegions.stream().filter(x -> !x.isEmpty()).collect(Collectors.toList()); } + private static int regionIntervalLength(final ChrBaseRegion region) + { + return isAltRegionContig(region.Chromosome) ? 1 : region.baseLength(); + } + private static List getRefGenomeRegions( final SpecificRegions specificRegions, final RefGenomeVersion refGenomeVersion, @Nullable final RefGenomeInterface refGenome) { @@ -204,5 +211,4 @@ private static List humanChromosomeRegions(final SpecificRegions return inputRegions; } - } diff --git a/redux/src/main/java/com/hartwig/hmftools/redux/ReduxApplication.java b/redux/src/main/java/com/hartwig/hmftools/redux/ReduxApplication.java index 63dff64f52..a34c70a50a 100644 --- a/redux/src/main/java/com/hartwig/hmftools/redux/ReduxApplication.java +++ b/redux/src/main/java/com/hartwig/hmftools/redux/ReduxApplication.java @@ -10,6 +10,7 @@ import static com.hartwig.hmftools.redux.ReduxConfig.registerConfig; import static com.hartwig.hmftools.redux.common.Constants.DEFAULT_READ_LENGTH; import static com.hartwig.hmftools.redux.unmap.RegionUnmapper.createThreadTasks; +import static com.hartwig.hmftools.redux.write.PartitionInfo.partitionInfoStr; import java.util.Collections; import java.util.List; @@ -215,8 +216,8 @@ private List createPartitionThreads(final FileWriterCache fileW break; long regionsLength = regions.stream().mapToLong(x -> x.baseLength()).sum(); - String regionsStr = regions.stream().map(x -> x.toString()).collect(Collectors.joining(";")); - RD_LOGGER.debug("adding partition regions({}) totalLength({}): {}}", regions.size(), regionsLength, regionsStr); + + RD_LOGGER.debug("adding partition regions({}) totalLength({}): {}", regions.size(), regionsLength, partitionInfoStr(regions)); fileWriterCache.addPartition(regions); } diff --git a/redux/src/main/java/com/hartwig/hmftools/redux/write/PartitionInfo.java b/redux/src/main/java/com/hartwig/hmftools/redux/write/PartitionInfo.java index 536c6603c8..15a0c756f0 100644 --- a/redux/src/main/java/com/hartwig/hmftools/redux/write/PartitionInfo.java +++ b/redux/src/main/java/com/hartwig/hmftools/redux/write/PartitionInfo.java @@ -2,11 +2,11 @@ import static java.lang.String.format; -import static com.hartwig.hmftools.common.utils.file.FileDelimiters.ITEM_DELIM; - import java.util.List; import java.util.stream.Collectors; +import com.hartwig.hmftools.common.genome.chromosome.HumanChromosome; +import com.hartwig.hmftools.common.genome.chromosome.MitochondrialChromosome; import com.hartwig.hmftools.common.region.ChrBaseRegion; public class PartitionInfo @@ -28,7 +28,19 @@ public PartitionInfo(final int index, final List regions, final B public String toString() { - String regionsStr = mRegions.stream().map(x -> x.toString()).collect(Collectors.joining(ITEM_DELIM)); - return format("%d: %d regions: %s", mRegionIndex, mRegions.size(), regionsStr); + return format("%d: %d regions: %s", mRegionIndex, mRegions.size(), partitionInfoStr(mRegions)); + } + + public static String partitionInfoStr(final List regions) + { + if(regions.size() <= 10) + return regions.stream().map(x -> x.toString()).collect(Collectors.joining(";")); + + return format("%s;%s;multiple", regions.get(0), regions.get(1)); + } + + public static boolean isAltRegionContig(final String regionContig) + { + return !HumanChromosome.contains(regionContig) && !MitochondrialChromosome.contains(regionContig); } }