use of com.github.lindenb.jvarkit.samtools.CoverageFactory in project jvarkit by lindenb.
the class BamXtremDepth method runLoop.
private void runLoop(final List<Path> bamPaths, final SamReaderFactory srf, final SAMSequenceRecord ssr, final SAMSequenceDictionary refDict, BitSet lowList, BitSet highList) throws IOException {
final CoverageFactory coverageFactory = new CoverageFactory().setMappingQuality(mapq);
for (final Path bamPath : bamPaths) {
try (SamReader samReader = srf.open(bamPath)) {
// check indexed
if (!samReader.hasIndex()) {
throw new JvarkitException.BamHasIndex(bamPath.toString());
}
final SAMFileHeader header = samReader.getFileHeader();
// check dictionary
final SAMSequenceDictionary dict = SequenceDictionaryUtils.extractRequired(header);
SequenceUtil.assertSequenceDictionariesEqual(dict, refDict);
// get the coverage in the low and high region.
final CoverageFactory.SimpleCoverage coverage;
if (this.alternative_algorithm) {
LOG.info(ssr.getContig() + " " + bamPath);
coverage = coverageFactory.getSimpleCoverage(samReader, ssr, null);
} else {
final List<Locatable> regions = bitSetToLocatables(ssr, lowList);
regions.addAll(bitSetToLocatables(ssr, highList));
if (regions.isEmpty())
break;
LOG.info(ssr.getContig() + " " + bamPath + " n-intervals:" + regions.size() + " size:" + regions.stream().mapToInt(R -> R.getLengthOnReference()).sum());
coverage = coverageFactory.getSimpleCoverage(samReader, regions, null);
}
// compute the new low and hight coverage
reduce(lowList, coverage, I -> I <= this.min_coverage);
reduce(highList, coverage, I -> I >= this.max_coverage);
}
System.gc();
}
}
Aggregations