Skip to content

Commit

Permalink
Redux: logging of alt contigs
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesshale committed Jan 12, 2025
1 parent 5fad14d commit 6730cf3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,14 +30,15 @@
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;
import com.hartwig.hmftools.redux.consensus.ConsensusReads;
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
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -391,6 +396,9 @@ private void setUnmappedRegions()

private void perfCountersStart()
{
if(isAltContigRegion())
return;

if(mConfig.perfDebug())
mPcTotal.start(format("%s", mCurrentRegion));
else
Expand All @@ -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; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -111,7 +112,8 @@ else if(specificRegions.Regions.size() == 1 && threadCount > 1)

List<ChrBaseRegion> 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);
Expand All @@ -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;
}

Expand All @@ -147,20 +149,25 @@ else if(specificRegions.Regions.size() == 1 && threadCount > 1)
break;

nextRegionStart = regionEnd + 1;
remainingChromosomeLength = chromosomeLength - nextRegionStart + 1;
remainingChromosomeLength = regionLength - nextRegionStart + 1;
}

if(remainingChromosomeLength <= 0)
continue;

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<ChrBaseRegion> getRefGenomeRegions(
final SpecificRegions specificRegions, final RefGenomeVersion refGenomeVersion, @Nullable final RefGenomeInterface refGenome)
{
Expand Down Expand Up @@ -204,5 +211,4 @@ private static List<ChrBaseRegion> humanChromosomeRegions(final SpecificRegions

return inputRegions;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -215,8 +216,8 @@ private List<PartitionThread> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,7 +28,19 @@ public PartitionInfo(final int index, final List<ChrBaseRegion> 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<ChrBaseRegion> 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);
}
}

0 comments on commit 6730cf3

Please sign in to comment.